aboutsummaryrefslogtreecommitdiffstats
path: root/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h
diff options
context:
space:
mode:
Diffstat (limited to 'boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h')
-rw-r--r--boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h127
1 files changed, 40 insertions, 87 deletions
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) {
+}
+static inline void setup_x(void) {
+ palSetPad(GPIOB, GPIOB_DRIVEA);
+ palClearPad(GPIOB, GPIOB_DRIVEB);
+ chThdSleepMilliseconds(2);
}
-/**
- * @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_y(void) {
+ palClearPad(GPIOB, GPIOB_DRIVEA);
+ palSetPad(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_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 */