Conversion of some addon board files to newmouse

ugfx_release_2.6
inmarket 2014-11-10 14:39:59 +10:00
parent 069c791fc1
commit 2904cd326b
3 changed files with 124 additions and 145 deletions

View File

@ -16,6 +16,14 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H #ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H
// Resolution and Accuracy Settings
#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8
#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6
#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4
#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14
#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18
#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14
static const SPIConfig spicfg = { static const SPIConfig spicfg = {
0, 0,
GPIOG, GPIOG,
@ -23,67 +31,49 @@ static const SPIConfig spicfg = {
/* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
}; };
/** // How much extra data to allocate at the end of the GMouse structure for the board's use
* @brief Initialise the board for the touch. #define GMOUSE_ADS7843_BOARD_DATA_SIZE 0
*
* @notapi static bool_t init_board(GMouse* m, unsigned driverinstance) {
*/ (void) m;
static inline void init_board(void) {
if (driverinstance)
return FALSE;
spiStart(&SPID2, &spicfg); spiStart(&SPID2, &spicfg);
return TRUE;
} }
/** static inline bool_t getpin_pressed(GMouse* m) {
* @brief Check whether the surface is currently touched (void) m;
* @return TRUE if the surface is currently touched
*
* @notapi
*/
static inline bool_t getpin_pressed(void) {
return (!palReadPad(GPIOG, 0)); return (!palReadPad(GPIOG, 0));
} }
/**
* @brief Aquire the bus ready for readings static inline void aquire_bus(GMouse* m) {
* (void) m;
* @notapi
*/
static inline void aquire_bus(void) {
spiAcquireBus(&SPID2); spiAcquireBus(&SPID2);
//TOUCHSCREEN_SPI_PROLOGUE(); //TOUCHSCREEN_SPI_PROLOGUE();
palClearPad(GPIOG, 10); palClearPad(GPIOG, 10);
} }
/** static inline void release_bus(GMouse* m) {
* @brief Release the bus after readings (void) m;
*
* @notapi
*/
static inline void release_bus(void) {
palSetPad(GPIOG, 10); palSetPad(GPIOG, 10);
spiReleaseBus(&SPID2); spiReleaseBus(&SPID2);
//TOUCHSCREEN_SPI_EPILOGUE(); //TOUCHSCREEN_SPI_EPILOGUE();
} }
/** static inline uint16_t read_value(GMouse* m, uint16_t port) {
* @brief Read a value from touch controller
* @return The value read from the controller
*
* params[in] port The controller port to read.
*
* @notapi
*/
static inline uint16_t read_value(uint16_t port) {
static uint8_t txbuf[3] = {0}; static uint8_t txbuf[3] = {0};
static uint8_t rxbuf[3] = {0}; static uint8_t rxbuf[3] = {0};
uint16_t ret; (void) m;
txbuf[0] = port; txbuf[0] = port;
spiExchange(&SPID2, 3, txbuf, rxbuf); spiExchange(&SPID2, 3, txbuf, rxbuf);
return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3);
ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3);
return ret;
} }
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ #endif /* _GINPUT_LLD_MOUSE_BOARD_H */

View File

@ -34,41 +34,61 @@ static const SPIConfig spicfg = {
/* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
}; };
static inline void init_board(void) { // Resolution and Accuracy Settings
#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8
#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6
#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4
#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14
#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18
#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14
// How much extra data to allocate at the end of the GMouse structure for the board's use
#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0
static bool_t init_board(GMouse* m, unsigned driverinstance) {
(void) m;
if (driverinstance)
return FALSE;
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) ); /* SCK */ palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) ); /* SCK */
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) ); /* MISO */ palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) ); /* MISO */
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) ); /* MOSI */ palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) ); /* MOSI */
palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL); /* CS */ palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL); /* CS */
spiStart(&SPID2, &spicfg); spiStart(&SPID2, &spicfg);
return TRUE;
} }
static inline bool_t getpin_pressed(void) { static inline bool_t getpin_pressed(GMouse* m) {
(void) m;
return (!palReadPad(GPIOC, 5)); return (!palReadPad(GPIOC, 5));
} }
static inline void aquire_bus(void) { static inline void aquire_bus(GMouse* m) {
(void) m;
spiAcquireBus(&SPID2); spiAcquireBus(&SPID2);
palClearPad(GPIOC, 4); palClearPad(GPIOC, 4);
} }
static inline void release_bus(void) { static inline void release_bus(GMouse* m) {
(void) m;
palSetPad(GPIOC, 4); palSetPad(GPIOC, 4);
spiReleaseBus(&SPID2); spiReleaseBus(&SPID2);
} }
static inline uint16_t read_value(uint16_t port) { static inline uint16_t read_value(GMouse* m, uint16_t port) {
static uint8_t txbuf[3] = {0}; static uint8_t txbuf[3] = {0};
static uint8_t rxbuf[3] = {0}; static uint8_t rxbuf[3] = {0};
uint16_t ret; (void) m;
txbuf[0] = port; txbuf[0] = port;
spiExchange(&SPID2, 3, txbuf, rxbuf); spiExchange(&SPID2, 3, txbuf, rxbuf);
ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3);
return ret;
} }
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ #endif /* _GINPUT_LLD_MOUSE_BOARD_H */

View File

@ -16,6 +16,24 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H #ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H
#define ADC_MAX 1023
// Resolution and Accuracy Settings
#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8
#define GMOUSE_MCU_PEN_CLICK_ERROR 6
#define GMOUSE_MCU_PEN_MOVE_ERROR 4
#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14
#define GMOUSE_MCU_FINGER_CLICK_ERROR 18
#define GMOUSE_MCU_FINGER_MOVE_ERROR 14
#define GMOUSE_MCU_Z_MIN 0 // The minimum Z reading
#define GMOUSE_MCU_Z_MAX ADC_MAX // The maximum Z reading
#define GMOUSE_MCU_Z_TOUCHON 60 // Values between this and Z_MAX are definitely pressed
#define GMOUSE_MCU_Z_TOUCHOFF 30 // Values between this and Z_MIN are definitely not pressed
// How much extra data to allocate at the end of the GMouse structure for the board's use
#define GMOUSE_MCU_BOARD_DATA_SIZE 0
static const ADCConfig ADCC = { static const ADCConfig ADCC = {
.vref = ADC_VREF_CFG_AVDD_AVSS, .vref = ADC_VREF_CFG_AVDD_AVSS,
.stime = 15, .stime = 15,
@ -29,10 +47,6 @@ static struct ADCDriver ADCD;
#define XPOS 12 // L #define XPOS 12 // L
#define YPOS 11 // D #define YPOS 11 // D
#define ADC_MAX 1023
#define TOUCH_THRESHOULD 50
static const ADCConversionGroup ADC_X_CG = { static const ADCConversionGroup ADC_X_CG = {
.circular = FALSE, .circular = FALSE,
.num_channels = 1, .num_channels = 1,
@ -45,104 +59,59 @@ static const ADCConversionGroup ADC_Y_CG = {
.channels = 1 << YPOS, .channels = 1 << YPOS,
}; };
/** static bool_t init_board(GMouse *m, unsigned driverinstance) {
* @brief Initialise the board for the touch. (void) m;
*
* @notapi if (driverinstance)
*/ return FALSE;
static inline void init_board(void) {
adcObjectInit(&ADCD); adcObjectInit(&ADCD);
adcStart(&ADCD, &ADCC); adcStart(&ADCD, &ADCC);
return TRUE;
} }
/** static bool_t read_xyz(GMouse *m, GMouseReading *prd) {
* @brief Check whether the surface is currently touched adcsample_t samples[2];
* @return TRUE if the surface is currently touched
*
* @notapi
*/
static inline bool_t getpin_pressed(void) {
adcsample_t samples[2] = {0, };
// Set X+ to ground prd->buttons = 0;
palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, XPOS);
// Set Y- to VCC // Read the z value first.
palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT); // Set X+ to ground and Y- to VCC
palSetPad(IOPORTB, YNEG); palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, XPOS);
palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT);
palSetPad(IOPORTB, YNEG);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG);
palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG);
adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1);
adcConvert(&ADCD, &ADC_Y_CG, &samples[1], 1);
pdr->z = ADC_MAX - (samples[1] - samples[0]);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG); // Shortcut - no need to read X or Y if the touch is off.
palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG); if (pdr->z < GMOUSE_MCU_Z_TOUCHON)
return TRUE;
adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1); // Read X
adcConvert(&ADCD, &ADC_Y_CG, &samples[1], 1); palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
palSetPad(IOPORTB, XPOS);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, XNEG);
palSetPadMode(IOPORTB, YNEG, PAL_MODE_INPUT);
palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG);
adcConvert(&ADCD, &ADC_Y_CG, &samples[0], 1);
pdr->x = ADC_MAX - samples[0];
return (ADC_MAX - (samples[1] - samples[0])) > TOUCH_THRESHOULD; // Read Y
} palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, YNEG);
palSetPadMode(IOPORTB, YPOS, PAL_MODE_OUTPUT);
palSetPad(IOPORTB, YPOS);
palSetPadMode(IOPORTB, XPOS, PAL_MODE_INPUT);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG);
adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1);
pdr->y = ADC_MAX - samples[0];
/** return TRUE;
* @brief Aquire the bus ready for readings
*
* @notapi
*/
static inline void aquire_bus(void) {
}
/**
* @brief Release the bus after readings
*
* @notapi
*/
static inline void release_bus(void) {
}
/**
* @brief Read an x value from touch controller
* @return The value read from the controller
*
* @notapi
*/
static inline uint16_t read_x_value(void) {
adcsample_t sample;
palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
palSetPad(IOPORTB, XPOS);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, XNEG);
palSetPadMode(IOPORTB, YNEG, PAL_MODE_INPUT);
palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG);
adcConvert(&ADCD, &ADC_Y_CG, &sample, 1);
return ADC_MAX - sample;
}
/**
* @brief Read an y value from touch controller
* @return The value read from the controller
*
* @notapi
*/
static inline uint16_t read_y_value(void) {
adcsample_t sample;
palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT);
palClearPad(IOPORTB, YNEG);
palSetPadMode(IOPORTB, YPOS, PAL_MODE_OUTPUT);
palSetPad(IOPORTB, YPOS);
palSetPadMode(IOPORTB, XPOS, PAL_MODE_INPUT);
palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG);
adcConvert(&ADCD, &ADC_X_CG, &sample, 1);
return ADC_MAX - sample;
} }
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ #endif /* _GINPUT_LLD_MOUSE_BOARD_H */