Rewrite of the MCU driver. This is now much more reliable.
This commit is contained in:
parent
e87ba59d8d
commit
361136d7ca
1 changed files with 39 additions and 39 deletions
|
@ -24,7 +24,6 @@
|
||||||
#include "ginput_lld_mouse_board.h"
|
#include "ginput_lld_mouse_board.h"
|
||||||
|
|
||||||
static uint16_t sampleBuf[7];
|
static uint16_t sampleBuf[7];
|
||||||
static coord_t lastx, lasty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 7-point median filtering code for touchscreen samples
|
* @brief 7-point median filtering code for touchscreen samples
|
||||||
|
@ -63,56 +62,57 @@ void ginput_lld_mouse_init(void) {
|
||||||
*
|
*
|
||||||
* @param[in] pt A pointer to the structure to fill
|
* @param[in] pt A pointer to the structure to fill
|
||||||
*
|
*
|
||||||
* @note For drivers that don't support returning a position
|
* @note We use a 7 sample medium filter on each coordinate to remove analogue noise.
|
||||||
* when the touch is up (most touch devices), it should
|
* @note During touch transition the ADC can return some very strange
|
||||||
* return the previous position with the new Z value.
|
* results. To fix this behaviour we don't return until
|
||||||
* The z value is the pressure for those touch devices
|
* we have tested the touch is in the same state at both the beginning
|
||||||
* that support it (-100 to 100 where > 0 is touched)
|
* and the end of the reading.
|
||||||
* or, 0 or 100 for those drivers that don't.
|
* @note Whilst x and y can return readings in any range so long as it fits in 16 bits,
|
||||||
|
* the z value must be ranged by the board file to be a rough percentage. Anything
|
||||||
|
* greater than 80% pressure is a touch.
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void ginput_lld_mouse_get_reading(MouseReading *pt) {
|
void ginput_lld_mouse_get_reading(MouseReading *pt) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
// If touch-off return the previous results
|
// Obtain access to the bus
|
||||||
if (!getpin_pressed()) {
|
|
||||||
pt->x = lastx;
|
|
||||||
pt->y = lasty;
|
|
||||||
pt->z = 0;
|
|
||||||
pt->buttons = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the port to get the touch settings
|
|
||||||
aquire_bus();
|
aquire_bus();
|
||||||
|
|
||||||
/* Get the X value
|
// Read the ADC for z, x, y and then z again
|
||||||
* Discard the first conversion - very noisy and keep the ADC on hereafter
|
while(1) {
|
||||||
* till we are done with the sampling.
|
setup_z();
|
||||||
* Once we have the readings, find the medium using our filter function
|
|
||||||
*/
|
|
||||||
read_x_value();
|
|
||||||
for(i = 0; i < 7; i++)
|
for(i = 0; i < 7; i++)
|
||||||
sampleBuf[i] = read_x_value();
|
sampleBuf[i] = read_z();
|
||||||
filter();
|
filter();
|
||||||
lastx = (coord_t)sampleBuf[3];
|
pt->z = (coord_t)sampleBuf[3];
|
||||||
|
|
||||||
/* Get the Y value using the same process as above */
|
setup_x();
|
||||||
read_y_value();
|
|
||||||
for(i = 0; i < 7; i++)
|
for(i = 0; i < 7; i++)
|
||||||
sampleBuf[i] = read_y_value();
|
sampleBuf[i] = read_x();
|
||||||
filter();
|
filter();
|
||||||
lasty = (coord_t)sampleBuf[3];
|
pt->x = (coord_t)sampleBuf[3];
|
||||||
|
|
||||||
|
setup_y();
|
||||||
|
for(i = 0; i < 7; i++)
|
||||||
|
sampleBuf[i] = read_y();
|
||||||
|
filter();
|
||||||
|
pt->y = (coord_t)sampleBuf[3];
|
||||||
|
|
||||||
|
pt->buttons = pt->z >= 80 ? GINPUT_TOUCH_PRESSED : 0;
|
||||||
|
|
||||||
|
setup_z();
|
||||||
|
for(i = 0; i < 7; i++)
|
||||||
|
sampleBuf[i] = read_z();
|
||||||
|
filter();
|
||||||
|
i = (coord_t)sampleBuf[3] >= 80 ? GINPUT_TOUCH_PRESSED : 0;
|
||||||
|
|
||||||
|
if (pt->buttons == i)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Release the bus
|
// Release the bus
|
||||||
release_bus();
|
release_bus();
|
||||||
|
|
||||||
// Return the results
|
|
||||||
pt->x = lastx;
|
|
||||||
pt->y = lasty;
|
|
||||||
pt->z = 100;
|
|
||||||
pt->buttons = GINPUT_TOUCH_PRESSED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
|
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
|
||||||
|
|
Loading…
Add table
Reference in a new issue