From 299311b4809f225f2757d5f687c48e9667ea34d7 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 24 Nov 2013 02:24:03 +1000 Subject: [PATCH] Updates to mouse and makefile for Mikromedia STM32-M4 board. --- .../example/Makefile | 2 +- .../ginput_lld_mouse_board.h | 129 ++++++------------ .../ginput_lld_mouse_config.h | 4 +- 3 files changed, 44 insertions(+), 91 deletions(-) diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example/Makefile index 6fca731e..c5f88f61 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example/Makefile @@ -77,9 +77,9 @@ LDSCRIPT= $(PORTLD)/STM32F407xG.ld # Imported source files and paths for uGFX GFXLIB = ../uGFX -include $(GFXLIB)/gfx.mk include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/board.mk include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk # The replacement ChibiOS board files +include $(GFXLIB)/gfx.mk # Where is our source code - alter these for your project. MYFILES = $(GFXLIB)/demos/modules/gdisp/basics 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 index 373a2474..9c659e66 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h @@ -13,9 +13,6 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H -/* read ADC if more than this many ticks since last read */ -#define ADC_UPDATE_INTERVAL 3 - #define ADC_NUM_CHANNELS 2 #define ADC_BUF_DEPTH 1 @@ -34,55 +31,6 @@ static const ADCConversionGroup adcgrpcfg = { ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) }; -static systime_t last_update; -static volatile uint16_t tpx, tpy, detect; - -static inline void delay(uint16_t dly) { - static uint16_t i; - for(i = 0; i < dly; i++) - asm("nop"); -} - - -void read_mikro_tp(void) { - systime_t now = chTimeNow(); - - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - uint16_t _detect, _tpx, _tpy; - - if(now < last_update || ((now - last_update) > ADC_UPDATE_INTERVAL)) { - // detect button press - // sample[0] will go from ~200 to ~4000 when pressed - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - _detect = samples[0]; - - // read x channel - palSetPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(1); - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - _tpx = samples[1]; - - // read y channel (invert) - palClearPad(GPIOB, GPIOB_DRIVEA); - palSetPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(1); - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - _tpy = samples[0]; - - // ready for next read - palClearPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - - chSysLock(); - tpx = _tpx; - tpy = _tpy; - detect = _detect; - last_update = now; - chSysUnlock(); - } -} - /** * @brief Initialise the board for the touch. * @@ -90,23 +38,6 @@ void read_mikro_tp(void) { */ static inline void init_board(void) { adcStart(&ADCD1, NULL); - last_update = chTimeNow(); - - // leave DRIVEA & DRIVEB ready for next read - palClearPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(1); -} - -/** - * @brief Check whether the surface is currently touched - * @return TRUE if the surface is currently touched - * - * @notapi - */ -static inline bool_t getpin_pressed(void) { - read_mikro_tp(); - return (detect > 2000) ? true : false; } /** @@ -124,29 +55,51 @@ static inline void aquire_bus(void) { * @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) { - read_mikro_tp(); - return tpx; +static inline void setup_x(void) { + palSetPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(2); } -/** - * @brief Read an y value from touch controller - * @return The value read from the controller - * - * @notapi - */ -static inline uint16_t read_y_value(void) { - read_mikro_tp(); - return tpy; +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 index 0c0ff482..8fb29ffc 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h @@ -22,8 +22,8 @@ #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_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