aboutsummaryrefslogtreecommitdiffstats
path: root/boards/addons
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-11-10 14:39:59 +1000
committerinmarket <andrewh@inmarket.com.au>2014-11-10 14:39:59 +1000
commit2904cd326bd8996b2c9781bbc636dac57a602c31 (patch)
tree5bc0c27c498b1d93d55fb70f8e1a80dacb065f50 /boards/addons
parent069c791fc1be91464154327718bbd3a36d09661c (diff)
downloaduGFX-2904cd326bd8996b2c9781bbc636dac57a602c31.tar.gz
uGFX-2904cd326bd8996b2c9781bbc636dac57a602c31.tar.bz2
uGFX-2904cd326bd8996b2c9781bbc636dac57a602c31.zip
Conversion of some addon board files to newmouse
Diffstat (limited to 'boards/addons')
-rw-r--r--boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h72
-rw-r--r--boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h40
-rw-r--r--boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h165
3 files changed, 128 insertions, 149 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 */