diff options
Diffstat (limited to 'boards')
22 files changed, 780 insertions, 738 deletions
diff --git a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h index f17d6e8e..af5f1282 100644 --- a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h +++ b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h @@ -16,6 +16,14 @@ #ifndef _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 = { 0, GPIOG, @@ -23,67 +31,49 @@ static const SPIConfig spicfg = { /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, }; -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static inline void init_board(void) { +// 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; + spiStart(&SPID2, &spicfg); + return TRUE; } -/** - * @brief Check whether the surface is currently touched - * @return TRUE if the surface is currently touched - * - * @notapi - */ -static inline bool_t getpin_pressed(void) { +static inline bool_t getpin_pressed(GMouse* m) { + (void) m; + return (!palReadPad(GPIOG, 0)); } -/** - * @brief Aquire the bus ready for readings - * - * @notapi - */ -static inline void aquire_bus(void) { + +static inline void aquire_bus(GMouse* m) { + (void) m; + spiAcquireBus(&SPID2); //TOUCHSCREEN_SPI_PROLOGUE(); palClearPad(GPIOG, 10); } -/** - * @brief Release the bus after readings - * - * @notapi - */ -static inline void release_bus(void) { +static inline void release_bus(GMouse* m) { + (void) m; + palSetPad(GPIOG, 10); spiReleaseBus(&SPID2); //TOUCHSCREEN_SPI_EPILOGUE(); } -/** - * @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 inline uint16_t read_value(GMouse* m, uint16_t port) { static uint8_t txbuf[3] = {0}; static uint8_t rxbuf[3] = {0}; - uint16_t ret; + (void) m; txbuf[0] = port; - spiExchange(&SPID2, 3, txbuf, rxbuf); - - ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); - - return ret; + return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3); } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h index 6c3e2124..b4478d2b 100644 --- a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h +++ b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h @@ -34,41 +34,61 @@ static const SPIConfig spicfg = { /* 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, 14, PAL_MODE_ALTERNATE(5) ); /* MISO */ palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) ); /* MOSI */ palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL); /* CS */ 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)); } -static inline void aquire_bus(void) { +static inline void aquire_bus(GMouse* m) { + (void) m; + spiAcquireBus(&SPID2); palClearPad(GPIOC, 4); } -static inline void release_bus(void) { +static inline void release_bus(GMouse* m) { + (void) m; + palSetPad(GPIOC, 4); 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 rxbuf[3] = {0}; - uint16_t ret; + (void) m; txbuf[0] = port; - spiExchange(&SPID2, 3, txbuf, rxbuf); - ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); - - return ret; + return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3); } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h b/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h index 87e2a93c..391eba9c 100644 --- a/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h +++ b/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h @@ -16,6 +16,24 @@ #ifndef _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 = { .vref = ADC_VREF_CFG_AVDD_AVSS, .stime = 15, @@ -29,10 +47,6 @@ static struct ADCDriver ADCD; #define XPOS 12 // L #define YPOS 11 // D -#define ADC_MAX 1023 - -#define TOUCH_THRESHOULD 50 - static const ADCConversionGroup ADC_X_CG = { .circular = FALSE, .num_channels = 1, @@ -45,104 +59,59 @@ static const ADCConversionGroup ADC_Y_CG = { .channels = 1 << YPOS, }; -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static inline void init_board(void) { - adcObjectInit(&ADCD); - adcStart(&ADCD, &ADCC); -} +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; -/** - * @brief Check whether the surface is currently touched - * @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 - palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT); - palClearPad(IOPORTB, XPOS); - - // Set Y- to VCC - 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); + if (driverinstance) + return FALSE; - return (ADC_MAX - (samples[1] - samples[0])) > TOUCH_THRESHOULD; + adcObjectInit(&ADCD); + adcStart(&ADCD, &ADCC); + 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; +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[2]; + + prd->buttons = 0; + + // Read the z value first. + // Set X+ to ground and Y- to VCC + 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]); + + // Shortcut - no need to read X or Y if the touch is off. + if (pdr->z < GMOUSE_MCU_Z_TOUCHON) + return TRUE; + + // Read X + 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]; + + // 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; } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h deleted file mode 100644 index d525e268..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static const I2CConfig i2ccfg = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_2, -}; - -static void init_board(void) -{ - palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ - palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ - palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ - - i2cStart(&I2CD1, &i2ccfg); -} - -static inline bool_t getpin_irq(void) -{ - return (!(palReadPad(GPIOC, 13))); -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) -{ - uint8_t txbuf[3]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - - if (n == 1) { - txbuf[1] = val; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } else if (n == 2) { - txbuf[1] = ((val & 0xFF00) >> 8); - txbuf[2] = (val & 0x00FF); - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 3, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } - - i2cReleaseBus(&I2CD1); -} - -static uint16_t read_reg(uint8_t reg, uint8_t n) -{ - uint8_t txbuf[1], rxbuf[2]; - uint16_t ret; - - rxbuf[0] = 0; - rxbuf[1] = 0; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - if (n == 1) { - ret = rxbuf[0]; - } else if (n == 2) { - ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); - } - - i2cReleaseBus(&I2CD1); - - return ret; -} - -static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) -{ - uint8_t txbuf[1]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - i2cReleaseBus(&I2CD1); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h deleted file mode 100644 index f3a89208..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 3 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h new file mode 100644 index 00000000..bbb17010 --- /dev/null +++ b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h @@ -0,0 +1,119 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 + +// Options - Leave these commented to make it user configurable in the gfxconf.h +//#define GMOUSE_STMPE811_READ_PRESSURE FALSE +//#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +//#define GMOUSE_STMPE811_TEST_MODE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +// Note: Although this board has such a pin its reliability has not been tested on this board!!!!! +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +// Slave address +#define STMPE811_ADDR (0x82 >> 1) + +// Maximum timeout +#define STMPE811_TIMEOUT 0x3000 + +static const I2CConfig i2ccfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // This board only supports one touch panel + if (driverinstance) + return FALSE; + + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ + palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ + palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + + i2cStart(&I2CD1, &i2ccfg); + + return TRUE; +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + (void) m; + + return !palReadPad(GPIOC, 13); + } +#endif + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h b/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h deleted file mode 100644 index 6ca1a897..00000000 --- a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static const SPIConfig spicfg = { - 0, - GPIOC, - 6, - /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, -}; - -static inline void init_board(void) -{ - spiStart(&SPID1, &spicfg); -} - -static inline bool_t getpin_pressed(void) -{ - return (!palReadPad(GPIOC, 4)); -} - -static inline void aquire_bus(void) -{ - spiAcquireBus(&SPID1); - palClearPad(GPIOC, 6); -} - -static inline void release_bus(void) -{ - palSetPad(GPIOC, 6); - spiReleaseBus(&SPID1); -} - -static inline uint16_t read_value(uint16_t port) -{ - static uint8_t txbuf[3] = {0}; - static uint8_t rxbuf[3] = {0}; - uint16_t ret; - - txbuf[0] = port; - - spiExchange(&SPID1, 3, txbuf, rxbuf); - - ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); - - return ret; -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h b/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h deleted file mode 100644 index f3a89208..00000000 --- a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 3 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h new file mode 100644 index 00000000..b202dd85 --- /dev/null +++ b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h @@ -0,0 +1,86 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 20 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 + +// 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 const SPIConfig spicfg = { + 0, + GPIOC, + 6, + /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) +{ + (void)m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + // Set the GPIO modes + palSetPadMode(GPIOC, 4, PAL_MODE_INPUT_PULLUP); + + // Start the SPI peripheral + spiStart(&SPID1, &spicfg); + + return TRUE; +} + +static inline bool_t getpin_pressed(GMouse* m) +{ + (void) m; + + return (!palReadPad(GPIOC, 4)); +} + +static inline void aquire_bus(GMouse* m) +{ + (void) m; + + spiAcquireBus(&SPID1); + palClearPad(GPIOC, 6); +} + +static inline void release_bus(GMouse* m) +{ + (void) m; + + palSetPad(GPIOC, 6); + spiReleaseBus(&SPID1); +} + +static inline uint16_t read_value(GMouse* m, uint16_t port) +{ + static uint8_t txbuf[3] = {0}; + static uint8_t rxbuf[3] = {0}; + uint16_t ret; + (void) m; + + txbuf[0] = port; + + spiExchange(&SPID1, 3, txbuf, rxbuf); + + ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); + + return ret; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ + diff --git a/boards/base/Marlin/ginput_lld_mouse_board.h b/boards/base/Marlin/ginput_lld_mouse_board.h deleted file mode 100644 index d787d224..00000000 --- a/boards/base/Marlin/ginput_lld_mouse_board.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h - * @brief GINPUT Touch low level driver source for the FT5x06. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * @{ - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -/* I2C interface #2 - Touchscreen controller */ -static const I2CConfig i2ccfg2 = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_2, -}; - -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static void init_board(void) { - -} - - -/** - * @brief Write a value into a certain register - * - * @param[in] reg The register address - * @param[in] n The amount of bytes (one or two) - * @param[in] val The value - * - * @notapi - */ -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - uint8_t txbuf[3]; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - - if (n == 1) { - txbuf[1] = val; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, 0, 0, MS2ST(FT5x06_TIMEOUT)); - } else if (n == 2) { - txbuf[1] = ((val & 0xFF00) >> 8); - txbuf[2] = (val & 0x00FF); - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 3, 0, 0, MS2ST(FT5x06_TIMEOUT)); - } - - i2cReleaseBus(&I2CD2); -} - -/** - * @brief Read the value of a certain register - * - * @param[in] reg The register address - * @param[in] n The amount of bytes (one or two) - * - * @return Data read from device (one byte or two depending on n param) - * - * @notapi - */ -static uint16_t read_reg(uint8_t reg, uint8_t n) { - uint8_t txbuf[1], rxbuf[2]; - uint16_t ret; - - rxbuf[0] = 0; - rxbuf[1] = 0; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); - - if (n == 1) { - ret = rxbuf[0]; - } else if (n == 2) { - ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); - } - - i2cReleaseBus(&I2CD2); - - return ret; -} - -static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) { - uint8_t txbuf[1]; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); - - i2cReleaseBus(&I2CD2); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ -/** @} */ - diff --git a/boards/base/Marlin/ginput_lld_mouse_config.h b/boards/base/Marlin/ginput_lld_mouse_config.h deleted file mode 100644 index 57d3f135..00000000 --- a/boards/base/Marlin/ginput_lld_mouse_config.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h - * @brief GINPUT LLD header file for mouse/touch driver. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * - * @{ - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 15 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 -#define GINPUT_MOUSE_CLICK_TIME 450 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ -/** @} */ diff --git a/boards/base/Marlin/gmouse_lld_FT5x06_board.h b/boards/base/Marlin/gmouse_lld_FT5x06_board.h new file mode 100644 index 00000000..ac961d0e --- /dev/null +++ b/boards/base/Marlin/gmouse_lld_FT5x06_board.h @@ -0,0 +1,93 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_FT5x06_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_FT5x06_PEN_CLICK_ERROR 6 +#define GMOUSE_FT5x06_PEN_MOVE_ERROR 4 +#define GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_FT5x06_FINGER_CLICK_ERROR 18 +#define GMOUSE_FT5x06_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_FT5x06_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_FT5x06_SELF_CALIBRATE FALSE + +/* I2C interface #2 - Touchscreen controller */ +static const I2CConfig i2ccfg2 = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // We only support one of these on this board + if (driverinstance) + return FALSE; + return TRUE; +} + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, 0, 0, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, ®, 1, rxbuf, 1, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, ®, 1, rxbuf, 2, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h deleted file mode 100644 index 75db2c62..00000000 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -#define ADC_NUM_CHANNELS 2 -#define ADC_BUF_DEPTH 1 - -static const ADCConversionGroup adcgrpcfg = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - /* HW dependent part.*/ - 0, - ADC_CR2_SWSTART, - 0, - 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) -}; - -static inline void init_board(void) { - adcStart(&ADCD1, 0); -} - -static inline void aquire_bus(void) { - -} - -static inline void release_bus(void) { -} - -static inline void setup_x(void) { - palSetPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline void setup_y(void) { - palClearPad(GPIOB, GPIOB_DRIVEA); - palSetPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline void setup_z(void) { - palClearPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline uint16_t read_x(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - return samples[1]; -} - -static inline uint16_t read_y(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - return samples[0]; -} - -static inline uint16_t read_z(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - // z will go from ~200 to ~4000 when pressed - // auto range this back to 0 to 100 - if (samples[0] > 4000) - return 100; - if (samples[0] < 400) - return 0; - return (samples[0] - 400) / ((4000-400)/100); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h deleted file mode 100644 index 328e6337..00000000 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h new file mode 100644 index 00000000..bad8b9ab --- /dev/null +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h @@ -0,0 +1,95 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_BOARD_H +#define _LLD_GMOUSE_MCU_BOARD_H + +// 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 +#define GMOUSE_MCU_Z_MAX 4095 +#define GMOUSE_MCU_Z_TOUCHON 3090 +#define GMOUSE_MCU_Z_TOUCHOFF 400 + +// 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 + +#define ADC_NUM_CHANNELS 2 +#define ADC_BUF_DEPTH 1 + +static const ADCConversionGroup adcgrpcfg = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + /* HW dependent part.*/ + 0, + ADC_CR2_SWSTART, + 0, + 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) +}; + +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + adcStart(&ADCD1, 0); + + // Set up for reading Z + palClearPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(1); // Settling time + return TRUE; +} + +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; + (void) m; + + // No buttons + prd->buttons = 0; + + // Get the z reading (assumes we are ready to read z) + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->z = samples[0]; + + // Take a shortcut and don't read x, y if we know we are definitely not touched. + if (prd->z >= GMOUSE_MCU_Z_TOUCHOFF) { + + // Get the x reading + palSetPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(2); + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->x = samples[1]; + + // Get the y reading + palClearPad(GPIOB, GPIOB_DRIVEA); + palSetPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(2); + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->y = samples[0]; + + // Set up for reading z again. We know it will be 20ms before we get called again so don't worry about settling time + palClearPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + } + return TRUE; +} + +#endif /* _LLD_GMOUSE_MCU_BOARD_H */ diff --git a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h b/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h deleted file mode 100644 index 91575527..00000000 --- a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -#define ADC_NUM_CHANNELS 2 -#define ADC_BUF_DEPTH 1 - -static const ADCConversionGroup adc_y_config = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - 0, 0, - 0, 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13) -}; - -static const ADCConversionGroup adc_x_config = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - 0, 0, - 0, 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) -}; - -static inline void init_board(void) { - adcStart(&ADCD1, 0); -} - -static inline void aquire_bus(void) { - -} - -static inline void release_bus(void) { - -} - -static inline void setup_x(void) { - palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); - - palSetPad(GPIOC, 2); - palClearPad(GPIOC, 3); - gfxSleepMilliseconds(1); -} - -static inline void setup_y(void) { - palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); - - palSetPad(GPIOC, 1); - palClearPad(GPIOC, 0); - gfxSleepMilliseconds(1); -} - -static inline void setup_z(void) { - palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOC, 1, PAL_MODE_INPUT); - palSetPadMode(GPIOC, 2, PAL_MODE_INPUT); - palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); - palSetPad(GPIOC, 3); -} - -static inline uint16_t read_x(void) { - uint16_t val1, val2; - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - palSetPad(GPIOC, 2); - palClearPad(GPIOC, 3); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); - val1 = ((samples[0] + samples[1])/2); - - palClearPad(GPIOC, 2); - palSetPad(GPIOC, 3); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); - val2 = ((samples[0] + samples[1])/2); - - return ((val1+((1<<12)-val2))/4); -} - -static inline uint16_t read_y(void) { - uint16_t val1, val2; - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - palSetPad(GPIOC, 1); - palClearPad(GPIOC, 0); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); - val1 = ((samples[0] + samples[1])/2); - - palClearPad(GPIOC, 1); - palSetPad(GPIOC, 0); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); - val2 = ((samples[0] + samples[1])/2); - - return ((val1+((1<<12)-val2))/4); -} - -static inline uint16_t read_z(void) { - if (palReadPad(GPIOC, 0)) - return 100; - else - return 0; -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h b/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h deleted file mode 100644 index e8362219..00000000 --- a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h new file mode 100644 index 00000000..414587cf --- /dev/null +++ b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h @@ -0,0 +1,136 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_BOARD_H +#define _LLD_GMOUSE_MCU_BOARD_H + +// 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 +#define GMOUSE_MCU_Z_MAX 1 +#define GMOUSE_MCU_Z_TOUCHON 1 +#define GMOUSE_MCU_Z_TOUCHOFF 0 + +// 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 + +#define ADC_NUM_CHANNELS 2 +#define ADC_BUF_DEPTH 1 + +static const ADCConversionGroup adc_y_config = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + 0, 0, + 0, 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13) +}; + +static const ADCConversionGroup adc_x_config = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + 0, 0, + 0, 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) +}; + +static inline void setup_z(void) { + palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 1, PAL_MODE_INPUT); + palSetPadMode(GPIOC, 2, PAL_MODE_INPUT); + palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPad(GPIOC, 3); +} + +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + adcStart(&ADCD1, 0); + + // Set up for reading Z + setup_z(); + chThdSleepMilliseconds(1); // Settling time + return TRUE; +} + +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; + uint16_t val1, val2; + (void) m; + + // No buttons and assume touch off + prd->buttons = 0; + prd->z = 0; + + // Get the z reading (assumes we are ready to read z) + // Take a shortcut and don't read x, y if we know we are definitely not touched. + if (palReadPad(GPIOC, 0)) { + prd->z = 1; + + // Get the x reading - Weird but it works. Optimize later. + palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPad(GPIOC, 2); + palClearPad(GPIOC, 3); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); + val1 = ((samples[0] + samples[1])/2); + + palClearPad(GPIOC, 2); + palSetPad(GPIOC, 3); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); + val2 = ((samples[0] + samples[1])/2); + + prd->x = ((val1+((1<<12)-val2))/4); + + // Get the y reading - Weird but it works. Optimize later. + palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPad(GPIOC, 1); + palClearPad(GPIOC, 0); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); + val1 = ((samples[0] + samples[1])/2); + + palClearPad(GPIOC, 1); + palSetPad(GPIOC, 0); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); + val2 = ((samples[0] + samples[1])/2); + + prd->y = ((val1+((1<<12)-val2))/4); + + // Set up for reading z again. We know it will be 20ms before we get called again so don't worry about settling time + setup_z(); + } + return TRUE; +} + +#endif /* _LLD_GMOUSE_MCU_BOARD_H */ diff --git a/boards/base/STM32F429i-Discovery/board.mk b/boards/base/STM32F429i-Discovery/board.mk index c8dc7117..09116393 100644 --- a/boards/base/STM32F429i-Discovery/board.mk +++ b/boards/base/STM32F429i-Discovery/board.mk @@ -4,5 +4,4 @@ GFXSRC += $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram GFXDEFS += -DGFX_USE_OS_CHIBIOS=TRUE include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk -#include $(GFXLIB)/drivers/ginput/touch/MCU/driver.mk -#include $(GFXLIB)/drivers/gaudio/vs1053/driver.mk +include $(GFXLIB)/drivers/ginput/touch/STMPE811/driver.mk diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h index e0ef55fe..8c45a63b 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h @@ -76,7 +76,7 @@ * @brief Enables the I2C subsystem. */ #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE +#define HAL_USE_I2C TRUE #endif /** diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h index d0b1d6a4..222958fe 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h @@ -138,7 +138,7 @@ */ #define STM32_I2C_USE_I2C1 FALSE #define STM32_I2C_USE_I2C2 FALSE -#define STM32_I2C_USE_I2C3 FALSE +#define STM32_I2C_USE_I2C3 TRUE #define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) #define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) #define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) diff --git a/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h new file mode 100644 index 00000000..f5bab2b9 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h @@ -0,0 +1,120 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 + +// Options - Leave these commented to make it user configurable in the gfxconf.h +//#define GMOUSE_STMPE811_READ_PRESSURE FALSE +//#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +//#define GMOUSE_STMPE811_TEST_MODE FALSE + +// Set to FALSE because it does not work properly on this board even though the pin exists. +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +// Slave address +#define STMPE811_ADDR 0x41 + +// Maximum timeout +#define STMPE811_TIMEOUT 0x3000 + +static const I2CConfig i2ccfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // This board only supports one touch panel + if (driverinstance) + return FALSE; + + // Set pin modes + palSetPadMode(GPIOA, 15, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ + palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ + palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + + // Start the I2C + i2cStart(&I2CD3, &i2ccfg); + + return TRUE; +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + (void) m; + + return !palReadPad(GPIOA, 15); + } +#endif + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, ®, 1, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, ®, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ |
