touchpad calibration storage update
This commit is contained in:
parent
34a64b13c4
commit
9379d17303
1 changed files with 32 additions and 20 deletions
|
@ -33,8 +33,8 @@
|
||||||
#if GFX_USE_TOUCHPAD || defined(__DOXYGEN__)
|
#if GFX_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||||
|
|
||||||
#if TOUCHPAD_STORE_CALIBRATION
|
#if TOUCHPAD_STORE_CALIBRATION
|
||||||
extern void lld_tpWriteCalibration(struct cal_t cal);
|
extern void lld_tpWriteCalibration(struct cal_t *cal);
|
||||||
extern struct cal_t lld_tpReadCalibration(void);
|
extern struct cal_t *lld_tpReadCalibration(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -48,9 +48,11 @@ extern struct cal_t lld_tpReadCalibration(void);
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver local variables. */
|
/* Driver local variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
static volatile struct cal_t cal = {
|
static struct cal_t *cal;
|
||||||
1, 1, 0, 0
|
|
||||||
};
|
#if TOUCHPAD_STORE_CALIBRATION
|
||||||
|
static bool_t calibration_failed = FALSE;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver local functions. */
|
/* Driver local functions. */
|
||||||
|
@ -132,6 +134,10 @@ static void _tpDrawCross(uint16_t x, uint16_t y) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void tpInit(const TOUCHPADDriver *tp) {
|
void tpInit(const TOUCHPADDriver *tp) {
|
||||||
|
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
|
||||||
|
if(cal == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Initialise Mutex */
|
/* Initialise Mutex */
|
||||||
//MUTEX_INIT
|
//MUTEX_INIT
|
||||||
|
|
||||||
|
@ -142,6 +148,11 @@ void tpInit(const TOUCHPADDriver *tp) {
|
||||||
|
|
||||||
#if TOUCHPAD_STORE_CALIBRATION
|
#if TOUCHPAD_STORE_CALIBRATION
|
||||||
cal = lld_tpReadCalibration();
|
cal = lld_tpReadCalibration();
|
||||||
|
if(cal == NULL) {
|
||||||
|
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
|
||||||
|
calibration_failed = TRUE;
|
||||||
|
tpCalibrate();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,11 +167,11 @@ uint16_t tpReadX(void) {
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
||||||
#if TOUCHPAD_XY_INVERTED == TRUE
|
#if TOUCHPAD_XY_INVERTED == TRUE
|
||||||
x = cal.xm * _tpReadRealY() + cal.xn;
|
x = cal->xm * _tpReadRealY() + cal->xn;
|
||||||
y = cal.ym * _tpReadRealX() + cal.yn;
|
y = cal->ym * _tpReadRealX() + cal->yn;
|
||||||
#else
|
#else
|
||||||
x = cal.xm * _tpReadRealX() + cal.xn;
|
x = cal->xm * _tpReadRealX() + cal->xn;
|
||||||
y = cal.ym * _tpReadRealY() + cal.yn;
|
y = cal->ym * _tpReadRealY() + cal->yn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(gdispGetOrientation()) {
|
switch(gdispGetOrientation()) {
|
||||||
|
@ -188,11 +199,11 @@ uint16_t tpReadY(void) {
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
||||||
#if TOUCHPAD_XY_INVERTED == TRUE
|
#if TOUCHPAD_XY_INVERTED == TRUE
|
||||||
x = cal.xm * _tpReadRealY() + cal.xn;
|
x = cal->xm * _tpReadRealY() + cal->xn;
|
||||||
y = cal.ym * _tpReadRealX() + cal.yn;
|
y = cal->ym * _tpReadRealX() + cal->yn;
|
||||||
#else
|
#else
|
||||||
x = cal.xm * _tpReadRealX() + cal.xn;
|
x = cal->xm * _tpReadRealX() + cal->xn;
|
||||||
y = cal.ym * _tpReadRealY() + cal.yn;
|
y = cal->ym * _tpReadRealY() + cal->yn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(gdispGetOrientation()) {
|
switch(gdispGetOrientation()) {
|
||||||
|
@ -230,13 +241,14 @@ void tpCalibrate(void) {
|
||||||
gdispFillArea(cross[i][0]-15, cross[i][1]-15, 42, 42, Red);
|
gdispFillArea(cross[i][0]-15, cross[i][1]-15, 42, 42, Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
cal.xm = ((float)cross[1][0] - (float)cross[0][0]) / ((float)points[1][0] - (float)points[0][0]);
|
cal->xm = ((float)cross[1][0] - (float)cross[0][0]) / ((float)points[1][0] - (float)points[0][0]);
|
||||||
cal.ym = ((float)cross[1][1] - (float)cross[0][1]) / ((float)points[1][1] - (float)points[0][1]);
|
cal->ym = ((float)cross[1][1] - (float)cross[0][1]) / ((float)points[1][1] - (float)points[0][1]);
|
||||||
|
|
||||||
cal.xn = (float)cross[0][0] - cal.xm * (float)points[0][0];
|
cal->xn = (float)cross[0][0] - cal->xm * (float)points[0][0];
|
||||||
cal.yn = (float)cross[0][1] - cal.ym * (float)points[0][1];
|
cal->yn = (float)cross[0][1] - cal->ym * (float)points[0][1];
|
||||||
|
|
||||||
#if TOUCHPAD_STORE_CALIBRATION
|
#if TOUCHPAD_STORE_CALIBRATION
|
||||||
|
if(!calibration_failed)
|
||||||
lld_tpWriteCalibration(cal);
|
lld_tpWriteCalibration(cal);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue