I've a four wire resistive touchscreen foil connected to GPIOC 0 to 3 (ADC channel 10 to 14) on an STM32F103.
I have it working using the normal stm standard lib without ChibiOS/RT. Here's how it works to read out both coordinates:
Code: Select all
/*
* YD=0 YU=1, measure XL and XR
* YD=1 YU=0, measure XL and XR
* The average of the previous four samples is the X value.
*
* XL=0 XR=1, measure YD and YU
* XL=1 XR=0, measure YD and YU
* The average of the previous four samples is the Y value.
*
* A total of 8 ADC measurements are needed!
*/
u32 val1, val2, y_coordinate, x_coordinate
GPIO_SetAnalog(TS_PIN_XL | TS_PIN_XR);
GPIO_SetOutput(TS_PIN_YD, 0);
GPIO_SetOutput(TS_PIN_YU, 1);
delay(100);
val1 = (ADC_Measure(TS_ADCCH_XL) + ADC_Measure(TS_ADCCH_XR))/2;
GPIO_SetOutput(TS_PIN_YD, 1);
GPIO_SetOutput(TS_PIN_YU, 0);
delay(100);
val2 = (ADC_Measure(TS_ADCCH_XL) + ADC_Measure(TS_ADCCH_XR))/2;
y_coordinate = (val1+((1<<12)-val2))/4;
GPIO_SetAnalog(TS_PIN_YD | TS_PIN_YU);
GPIO_SetOutput(TS_PIN_XL, 0);
GPIO_SetOutput(TS_PIN_XR, 1);
delay(100);
val1 = (ADC_Measure(TS_ADCCH_YD) + ADC_Measure(TS_ADCCH_YU))/2;
GPIO_SetOutput(TS_PIN_XL, 1);
GPIO_SetOutput(TS_PIN_XR, 0);
delay(100);
val2 = (ADC_Measure(TS_ADCCH_YD) + ADC_Measure(TS_ADCCH_YU))/2;
y_coordinate = (val1+((1<<12)-val2))/4;
What I would like to do now is doing the same thing but using the ADC driver of ChibiOS/RT. The problem is that I kinda fail at figuring out how to make only one measurement, change the two GPIO states and make another measurement in another buffer. Then, do the same but with the two other ADC pins. Can anyone help here?
Thanks in advance.
~ Tectu