implemented MCU touchscreen driver

ugfx_release_2.6
Joel Bodenmann 2012-11-25 23:33:10 +01:00
parent b724f40c3f
commit 9c74a08131
3 changed files with 98 additions and 42 deletions

View File

@ -32,16 +32,38 @@
#if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/ #if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/
#define ADC_NUM_CHANNELS 2
#define ADC_BUF_DEPTH 1
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
#if !defined(__DOXYGEN__) static const TouchscreenDriver *ts;
/* Local copy of the current touchpad driver */
static const TouchscreenDriver *tsDriver;
#endif 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. * @brief Low level Touchscreen driver initialization.
@ -50,31 +72,10 @@
* *
* @notapi * @notapi
*/ */
void ts_lld_init(const TouchscreenDriver *ts) { void ts_lld_init(const TouchscreenDriver *ts_init) {
tsDriver = ts; ts = ts_init;
/* set pins to analog input */ adcStart(ts->adc_driver, NULL);
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);
}
/**
* @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;
} }
/** /**
@ -85,6 +86,7 @@ uint16_t ts_lld_read_value(uint8_t cmd) {
* @notapi * @notapi
*/ */
static void ts_lld_filter(void) { static void ts_lld_filter(void) {
return 0; return 0;
} }
@ -96,7 +98,27 @@ static void ts_lld_filter(void) {
* @notapi * @notapi
*/ */
uint16_t ts_lld_read_x(void) { 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 * @notapi
*/ */
uint16_t ts_lld_read_y(void) { 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 * @notapi
*/ */
uint8_t ts_lld_pressed(void) { 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 */ #endif /* GFX_USE_TOUCHSCREEN */
/** @} */ /** @} */

View File

@ -38,15 +38,20 @@
#define TOUCHSCREEN_HAS_PRESSED TRUE #define TOUCHSCREEN_HAS_PRESSED TRUE
#define TOUCHSCREEN_HAS_PRESSURE FALSE #define TOUCHSCREEN_HAS_PRESSURE FALSE
/**
* @brief The touchscreen driver struct
* @details Pointer to this will be passed to tsInit()
*/
struct TouchscreenDriver { struct TouchscreenDriver {
ioportid_t ts_yd_port; ADCDriver *adc_driver;
ioportmask_t ts_yd_pin; ioportid_t yd_port;
ioportid_t ts_yu_port; ioportmask_t yd_pin;
ioportmask_t ts_yu_pin; ioportid_t yu_port;
ioportid_t ts_xl_port; ioportmask_t yu_pin;
ioportmask_t ts_xl_pin; ioportid_t xl_port;
ioportid_t ts_xr_port; ioportmask_t xl_pin;
ioportmask_t ts_xr_pin; ioportid_t xr_port;
ioportmask_t xr_pin;
}; };
#endif /* GFX_USE_TOUCHSCREEN */ #endif /* GFX_USE_TOUCHSCREEN */

View File

@ -184,7 +184,7 @@ coord_t tsReadX(void) {
y = _tsReadRealY(); y = _tsReadRealY();
#endif #endif
_tsTransform(&x, &y); //_tsTransform(&x, &y);
switch(gdispGetOrientation()) { switch(gdispGetOrientation()) {
case GDISP_ROTATE_0: case GDISP_ROTATE_0:
@ -218,7 +218,7 @@ coord_t tsReadY(void) {
y = _tsReadRealY(); y = _tsReadRealY();
#endif #endif
_tsTransform(&x, &y); //_tsTransform(&x, &y);
switch(gdispGetOrientation()) { switch(gdispGetOrientation()) {
case GDISP_ROTATE_0: case GDISP_ROTATE_0:
@ -276,6 +276,9 @@ coord_t tsReadY(void) {
* @api * @api
*/ */
void tsCalibrate(void) { void tsCalibrate(void) {
#if 0
const uint16_t height = gdispGetHeight(); const uint16_t height = gdispGetHeight();
const uint16_t width = gdispGetWidth(); const uint16_t width = gdispGetWidth();
const coord_t cross[][2] = {{(width / 4), (height / 4)}, const coord_t cross[][2] = {{(width / 4), (height / 4)},
@ -362,6 +365,7 @@ calibrate:
#if TOUCHSCREEN_STORE_CALIBRATION #if TOUCHSCREEN_STORE_CALIBRATION
ts_store_calibration_lld(cal); ts_store_calibration_lld(cal);
#endif #endif
#endif
} }
#endif /* GFX_USE_TOUCHSCREEN */ #endif /* GFX_USE_TOUCHSCREEN */