aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2012-11-25 23:33:10 +0100
committerJoel Bodenmann <joel@unormal.org>2012-11-25 23:33:10 +0100
commit9c74a081313a8681d2a47a15b9a0e228289a5c25 (patch)
tree5f7e5b04aef87e153c9c9668c7620634cd838060 /drivers
parentb724f40c3fc04a8887bfc5d8ea31e6f27823d319 (diff)
downloaduGFX-9c74a081313a8681d2a47a15b9a0e228289a5c25.tar.gz
uGFX-9c74a081313a8681d2a47a15b9a0e228289a5c25.tar.bz2
uGFX-9c74a081313a8681d2a47a15b9a0e228289a5c25.zip
implemented MCU touchscreen driver
Diffstat (limited to 'drivers')
-rw-r--r--drivers/touchscreen/MCU/touchscreen_lld.c113
-rw-r--r--drivers/touchscreen/MCU/touchscreen_lld_config.h21
2 files changed, 93 insertions, 41 deletions
diff --git a/drivers/touchscreen/MCU/touchscreen_lld.c b/drivers/touchscreen/MCU/touchscreen_lld.c
index 46db4fa0..f8c32ffd 100644
--- a/drivers/touchscreen/MCU/touchscreen_lld.c
+++ b/drivers/touchscreen/MCU/touchscreen_lld.c
@@ -32,16 +32,38 @@
#if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/
+#define ADC_NUM_CHANNELS 2
+#define ADC_BUF_DEPTH 1
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
-#if !defined(__DOXYGEN__)
- /* Local copy of the current touchpad driver */
- static const TouchscreenDriver *tsDriver;
-
-#endif
+static const TouchscreenDriver *ts;
+
+static const ADCConversionGroup adc_y_config = {
+ FALSE,
+ ADC_NUM_CHANNELS,
+ NULL,
+ NULL,
+ 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,
+ NULL,
+ NULL,
+ 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)
+};
/**
* @brief Low level Touchscreen driver initialization.
@@ -50,31 +72,10 @@
*
* @notapi
*/
-void ts_lld_init(const TouchscreenDriver *ts) {
- tsDriver = ts;
-
- /* set pins to analog input */
- palSetPadMode(ts->ts_yd_port, ts->ts_yd_pin, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(ts->ts_yu_port, ts->ts_yu_pin, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(ts->ts_xl_port, ts->ts_xl_pin, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(ts->ts_xr_port, ts->ts_xr_pin, PAL_MODE_INPUT_ANALOG);
-}
-
+void ts_lld_init(const TouchscreenDriver *ts_init) {
+ ts = ts_init;
-/**
- * @brief Reads a conversion from the touchscreen
- *
- * @param[in] cmd The command bits to send to the touchscreen
- *
- * @return The read value 12-bit right-justified
- *
- * @note This function only reads data, it is assumed that the pins are
- * configured properly and the bus has been acquired beforehand
- *
- * @notapi
- */
-uint16_t ts_lld_read_value(uint8_t cmd) {
- return 0;
+ adcStart(ts->adc_driver, NULL);
}
/**
@@ -85,6 +86,7 @@ uint16_t ts_lld_read_value(uint8_t cmd) {
* @notapi
*/
static void ts_lld_filter(void) {
+
return 0;
}
@@ -96,7 +98,27 @@ static void ts_lld_filter(void) {
* @notapi
*/
uint16_t ts_lld_read_x(void) {
- return 0;
+ uint16_t val1, val2;
+ adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
+
+ palSetPadMode(ts->yd_port, ts->yd_pin, PAL_MODE_INPUT_ANALOG);
+ palSetPadMode(ts->yu_port, ts->yu_pin, PAL_MODE_INPUT_ANALOG);
+ palSetPadMode(ts->xl_port, ts->xl_pin, PAL_MODE_OUTPUT_PUSHPULL);
+ palSetPadMode(ts->xr_port, ts->xr_pin, PAL_MODE_OUTPUT_PUSHPULL);
+
+ palSetPad(ts->xl_port, ts->xl_pin);
+ palClearPad(ts->xr_port, ts->xr_pin);
+ chThdSleepMilliseconds(1);
+ adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
+ val1 = ((samples[0] + samples[1])/2);
+
+ palClearPad(ts->xr_port, ts->xr_pin);
+ palSetPad(ts->xl_port, ts->xl_pin);
+ chThdSleepMilliseconds(1);
+ adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
+ val2 = ((samples[0] + samples[1])/2);
+
+ return ((val1+((1<<12)-val2))/4);
}
/**
@@ -105,7 +127,27 @@ uint16_t ts_lld_read_x(void) {
* @notapi
*/
uint16_t ts_lld_read_y(void) {
- return 0;
+ uint16_t val1, val2;
+ adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
+
+ palSetPadMode(ts->xl_port, ts->xl_pin, PAL_MODE_INPUT_ANALOG);
+ palSetPadMode(ts->xr_port, ts->xr_pin, PAL_MODE_INPUT_ANALOG);
+ palSetPadMode(ts->yd_port, ts->yd_pin, PAL_MODE_OUTPUT_PUSHPULL);
+ palSetPadMode(ts->yu_port, ts->yu_pin, PAL_MODE_OUTPUT_PUSHPULL);
+
+ palSetPad(ts->yu_port, ts->yu_pin);
+ palClearPad(ts->yd_port, ts->yd_pin);
+ chThdSleepMilliseconds(1);
+ adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
+ val1 = ((samples[0] + samples[1])/2);
+
+ palClearPad(ts->yu_port, ts->yu_pin);
+ palSetPad(ts->yd_port, ts->yd_pin);
+ chThdSleepMilliseconds(1);
+ adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
+ val2 = ((samples[0] + samples[1])/2);
+
+ return ((val1+((1<<12)-val2))/4);
}
/*
@@ -116,9 +158,14 @@ uint16_t ts_lld_read_y(void) {
* @notapi
*/
uint8_t ts_lld_pressed(void) {
- return 0;
-}
+ palSetPadMode(ts->yd_port, ts->yd_pin, PAL_MODE_INPUT_PULLDOWN);
+ palSetPadMode(ts->yu_port, ts->yu_pin, PAL_MODE_INPUT);
+ palSetPadMode(ts->xl_port, ts->xl_pin, PAL_MODE_INPUT);
+ palSetPadMode(ts->xr_port, ts->xr_pin, PAL_MODE_OUTPUT_PUSHPULL);
+ palSetPad(ts->xr_port, ts->xr_pin);
+ return palReadPad(ts->yd_port, ts->yd_pin);
+}
#endif /* GFX_USE_TOUCHSCREEN */
/** @} */
diff --git a/drivers/touchscreen/MCU/touchscreen_lld_config.h b/drivers/touchscreen/MCU/touchscreen_lld_config.h
index e57d5723..800518ae 100644
--- a/drivers/touchscreen/MCU/touchscreen_lld_config.h
+++ b/drivers/touchscreen/MCU/touchscreen_lld_config.h
@@ -38,15 +38,20 @@
#define TOUCHSCREEN_HAS_PRESSED TRUE
#define TOUCHSCREEN_HAS_PRESSURE FALSE
+/**
+ * @brief The touchscreen driver struct
+ * @details Pointer to this will be passed to tsInit()
+ */
struct TouchscreenDriver {
- ioportid_t ts_yd_port;
- ioportmask_t ts_yd_pin;
- ioportid_t ts_yu_port;
- ioportmask_t ts_yu_pin;
- ioportid_t ts_xl_port;
- ioportmask_t ts_xl_pin;
- ioportid_t ts_xr_port;
- ioportmask_t ts_xr_pin;
+ ADCDriver *adc_driver;
+ ioportid_t yd_port;
+ ioportmask_t yd_pin;
+ ioportid_t yu_port;
+ ioportmask_t yu_pin;
+ ioportid_t xl_port;
+ ioportmask_t xl_pin;
+ ioportid_t xr_port;
+ ioportmask_t xr_pin;
};
#endif /* GFX_USE_TOUCHSCREEN */