New newmouse driver for MCU touch
This commit is contained in:
parent
5497bf82b3
commit
08e26fcb90
7 changed files with 107 additions and 146 deletions
|
@ -1,5 +1,2 @@
|
||||||
# List the required driver.
|
# List the required driver.
|
||||||
GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/ginput_lld_mouse.c
|
GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/gmouse_lld_MCU.c
|
||||||
|
|
||||||
# Required include directories
|
|
||||||
GFXINC += $(GFXLIB)/drivers/ginput/touch/MCU
|
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is subject to the terms of the GFX License. If a copy of
|
|
||||||
* the license was not distributed with this file, you can obtain one at:
|
|
||||||
*
|
|
||||||
* http://ugfx.org/license.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "gfx.h"
|
|
||||||
|
|
||||||
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/
|
|
||||||
|
|
||||||
#include "src/ginput/driver_mouse.h"
|
|
||||||
|
|
||||||
#include "ginput_lld_mouse_board.h"
|
|
||||||
|
|
||||||
static uint16_t sampleBuf[7];
|
|
||||||
|
|
||||||
static void filter(void) {
|
|
||||||
uint16_t temp;
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
for(i = 0; i < 4; i++) {
|
|
||||||
for(j = i; j < 7; j++) {
|
|
||||||
if(sampleBuf[i] > sampleBuf[j]) {
|
|
||||||
/* Swap the values */
|
|
||||||
temp = sampleBuf[i];
|
|
||||||
sampleBuf[i] = sampleBuf[j];
|
|
||||||
sampleBuf[j] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ginput_lld_mouse_init(void) {
|
|
||||||
init_board();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ginput_lld_mouse_get_reading(MouseReading *pt) {
|
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
// Obtain access to the bus
|
|
||||||
aquire_bus();
|
|
||||||
|
|
||||||
// Read the ADC for z, x, y and then z again
|
|
||||||
while(1) {
|
|
||||||
setup_z();
|
|
||||||
for(i = 0; i < 7; i++)
|
|
||||||
sampleBuf[i] = read_z();
|
|
||||||
filter();
|
|
||||||
pt->z = (coord_t)sampleBuf[3];
|
|
||||||
|
|
||||||
setup_x();
|
|
||||||
for(i = 0; i < 7; i++)
|
|
||||||
sampleBuf[i] = read_x();
|
|
||||||
filter();
|
|
||||||
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_bus();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is subject to the terms of the GFX License. If a copy of
|
|
||||||
* the license was not distributed with this file, you can obtain one at:
|
|
||||||
*
|
|
||||||
* http://ugfx.org/license.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _GINPUT_LLD_MOUSE_BOARD_H
|
|
||||||
#define _GINPUT_LLD_MOUSE_BOARD_H
|
|
||||||
|
|
||||||
static inline void init_board(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void aquire_bus(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void release_bus(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void setup_x(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void setup_y(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void setup_z(void) {
|
|
||||||
palClearPad(GPIOB, GPIOB_DRIVEA);
|
|
||||||
palClearPad(GPIOB, GPIOB_DRIVEB);
|
|
||||||
chThdSleepMilliseconds(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t read_x(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t read_y(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t read_z(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is subject to the terms of the GFX License. If a copy of
|
|
||||||
* the license was not distributed with this file, you can obtain one at:
|
|
||||||
*
|
|
||||||
* http://ugfx.org/license.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LLD_GINPUT_MOUSE_CONFIG_H
|
|
||||||
#define _LLD_GINPUT_MOUSE_CONFIG_H
|
|
||||||
|
|
||||||
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
|
|
||||||
#define GINPUT_MOUSE_NEED_CALIBRATION TRUE
|
|
||||||
#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
|
|
||||||
#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12
|
|
||||||
#define GINPUT_MOUSE_READ_CYCLES 1
|
|
||||||
#define GINPUT_MOUSE_POLL_PERIOD 25
|
|
||||||
#define GINPUT_MOUSE_MAX_CLICK_JITTER 2
|
|
||||||
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
|
|
||||||
#define GINPUT_MOUSE_CLICK_TIME 500
|
|
||||||
|
|
||||||
#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
|
|
50
drivers/ginput/touch/MCU/gmouse_lld_MCU.c
Normal file
50
drivers/ginput/touch/MCU/gmouse_lld_MCU.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
|
*
|
||||||
|
* http://ugfx.org/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gfx.h"
|
||||||
|
|
||||||
|
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
|
||||||
|
|
||||||
|
#define GMOUSE_DRIVER_VMT GMOUSEVMT_MCU
|
||||||
|
#include "src/ginput/driver_mouse.h"
|
||||||
|
|
||||||
|
// Get the hardware interface
|
||||||
|
#include "gmouse_lld_MCU_board.h"
|
||||||
|
|
||||||
|
const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
|
||||||
|
{
|
||||||
|
GDRIVER_TYPE_TOUCH,
|
||||||
|
GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_TEST
|
||||||
|
|GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN,
|
||||||
|
// Extra flags for testing only
|
||||||
|
//GMOUSE_VFLG_DEFAULTFINGER|GMOUSE_VFLG_CAL_EXTREMES - Possible
|
||||||
|
//GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_CAL_LOADFREE - unlikely
|
||||||
|
sizeof(GMouse),
|
||||||
|
_gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
|
||||||
|
},
|
||||||
|
Z_MAX, // z_max
|
||||||
|
Z_MIN, // z_min
|
||||||
|
Z_TOUCHON, // z_touchon
|
||||||
|
Z_TOUCHOFF, // z_touchoff
|
||||||
|
{ // pen_jitter
|
||||||
|
GMOUSE_MCU_PEN_CALIBRATE_ERROR, // calibrate
|
||||||
|
GMOUSE_MCU_PEN_CLICK_ERROR, // click
|
||||||
|
GMOUSE_MCU_PEN_MOVE_ERROR // move
|
||||||
|
},
|
||||||
|
{ // finger_jitter
|
||||||
|
GMOUSE_MCU_FINGER_CALIBRATE_ERROR, // calibrate
|
||||||
|
GMOUSE_MCU_FINGER_CLICK_ERROR, // click
|
||||||
|
GMOUSE_MCU_FINGER_MOVE_ERROR // move
|
||||||
|
},
|
||||||
|
init_board, // init
|
||||||
|
0, // deinit
|
||||||
|
read_xyz, // get
|
||||||
|
0, // calsave
|
||||||
|
0 // calload
|
||||||
|
}};
|
||||||
|
|
||||||
|
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
|
38
drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h
Normal file
38
drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
|
*
|
||||||
|
* http://ugfx.org/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LLD_GMOUSE_MCU_BOARD_H
|
||||||
|
#define _LLD_GMOUSE_MCU_BOARD_H
|
||||||
|
|
||||||
|
// Either define your jitter settings here or define them in the config include file
|
||||||
|
#if 0
|
||||||
|
#include "gmouse_lld_MCU_config.h"
|
||||||
|
#else
|
||||||
|
#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2
|
||||||
|
#define GMOUSE_MCU_PEN_CLICK_ERROR 2
|
||||||
|
#define GMOUSE_MCU_PEN_MOVE_ERROR 2
|
||||||
|
#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4
|
||||||
|
#define GMOUSE_MCU_FINGER_CLICK_ERROR 4
|
||||||
|
#define GMOUSE_MCU_FINGER_MOVE_ERROR 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Now board specific settings...
|
||||||
|
|
||||||
|
#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use
|
||||||
|
|
||||||
|
#define Z_MIN 0 // The minimum Z reading
|
||||||
|
#define Z_MAX 100 // The maximum Z reading
|
||||||
|
#define Z_TOUCHON 80 // Values between this and Z_MAX are definitely pressed
|
||||||
|
#define Z_TOUCHOFF 70 // Values between this and Z_MIN are definitely not pressed
|
||||||
|
|
||||||
|
static bool_t init_board(GMouse *m, unsigned driverinstance) {
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_xyz(GMouse *m, GMouseReading *prd) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _LLD_GMOUSE_MCU_BOARD_H */
|
18
drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h
Normal file
18
drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
|
*
|
||||||
|
* http://ugfx.org/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LLD_GMOUSE_MCU_CONFIG_H
|
||||||
|
#define _LLD_GMOUSE_MCU_CONFIG_H
|
||||||
|
|
||||||
|
#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2
|
||||||
|
#define GMOUSE_MCU_PEN_CLICK_ERROR 2
|
||||||
|
#define GMOUSE_MCU_PEN_MOVE_ERROR 2
|
||||||
|
#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4
|
||||||
|
#define GMOUSE_MCU_FINGER_CLICK_ERROR 4
|
||||||
|
#define GMOUSE_MCU_FINGER_MOVE_ERROR 4
|
||||||
|
|
||||||
|
#endif /* _LLD_GMOUSE_MCU_CONFIG_H */
|
Loading…
Add table
Reference in a new issue