From 08e26fcb909de96b5f6476ae606149e618f75036 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:54:19 +1000 Subject: [PATCH] New newmouse driver for MCU touch --- drivers/ginput/touch/MCU/driver.mk | 5 +- drivers/ginput/touch/MCU/ginput_lld_mouse.c | 80 ------------------- .../MCU/ginput_lld_mouse_board_template.h | 41 ---------- .../MCU/ginput_lld_mouse_config_template.h | 21 ----- drivers/ginput/touch/MCU/gmouse_lld_MCU.c | 50 ++++++++++++ .../touch/MCU/gmouse_lld_MCU_board_template.h | 38 +++++++++ .../MCU/gmouse_lld_MCU_config_template.h | 18 +++++ 7 files changed, 107 insertions(+), 146 deletions(-) delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU.c create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h diff --git a/drivers/ginput/touch/MCU/driver.mk b/drivers/ginput/touch/MCU/driver.mk index e771236a..c8c792b2 100644 --- a/drivers/ginput/touch/MCU/driver.mk +++ b/drivers/ginput/touch/MCU/driver.mk @@ -1,5 +1,2 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/ginput_lld_mouse.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/MCU +GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/gmouse_lld_MCU.c diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse.c b/drivers/ginput/touch/MCU/ginput_lld_mouse.c deleted file mode 100644 index ad2519e4..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse.c +++ /dev/null @@ -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 */ diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h deleted file mode 100644 index e213bcb9..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h +++ /dev/null @@ -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 */ diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h deleted file mode 100644 index 328e6337..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h +++ /dev/null @@ -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 */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c new file mode 100644 index 00000000..87b39ae4 --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c @@ -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 */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h new file mode 100644 index 00000000..5366b16c --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h @@ -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 */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h new file mode 100644 index 00000000..303557b4 --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h @@ -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 */