aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ginput/touch/ADS7843/driver.mk5
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse.c94
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h31
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h21
-rw-r--r--drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c79
-rw-r--r--drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h42
-rw-r--r--drivers/ginput/touch/FT5x06/driver.mk5
-rw-r--r--drivers/ginput/touch/FT5x06/ginput_lld_mouse.c88
-rw-r--r--drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h27
-rw-r--r--drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h21
-rw-r--r--drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c120
-rw-r--r--drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h46
-rw-r--r--drivers/ginput/touch/MCU/driver.mk5
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse.c80
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h41
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h21
-rw-r--r--drivers/ginput/touch/MCU/gmouse_lld_MCU.c50
-rw-r--r--drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h32
-rw-r--r--drivers/ginput/touch/STMPE811/driver.mk5
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse.c132
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h27
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h25
-rw-r--r--drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c164
-rw-r--r--drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h58
-rw-r--r--drivers/ginput/touch/STMPE811/stmpe811.h3
-rw-r--r--drivers/multiple/Win32/gdisp_lld_Win32.c133
-rw-r--r--drivers/multiple/Win32/ginput_lld_mouse_config.h38
-rw-r--r--drivers/multiple/X/gdisp_lld_X.c117
-rw-r--r--drivers/multiple/X/ginput_lld_mouse_config.h38
-rw-r--r--drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c373
30 files changed, 965 insertions, 956 deletions
diff --git a/drivers/ginput/touch/ADS7843/driver.mk b/drivers/ginput/touch/ADS7843/driver.mk
index 31e9ab2c..1a0eaf8e 100644
--- a/drivers/ginput/touch/ADS7843/driver.mk
+++ b/drivers/ginput/touch/ADS7843/driver.mk
@@ -1,5 +1,2 @@
# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
-
-# Required include directories
-GFXINC += $(GFXLIB)/drivers/ginput/touch/ADS7843
+GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c b/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
deleted file mode 100644
index cb9b6f4e..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
+++ /dev/null
@@ -1,94 +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"
-
-#if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED
- #define CMD_X 0x91
- #define CMD_Y 0xD1
-#else
- #define CMD_X 0xD1
- #define CMD_Y 0x91
-#endif
-
-
-static uint16_t sampleBuf[7];
-static coord_t lastx, lasty;
-
-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;
-
- // If touch-off return the previous results
- 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();
-
- /* Get the X value
- * Discard the first conversion - very noisy and keep the ADC on hereafter
- * till we are done with the sampling. Note that PENIRQ is disabled while reading.
- * Finally switch on PENIRQ once again - perform a dummy read.
- * Once we have the readings, find the medium using our filter function
- */
- read_value(CMD_X);
- for(i = 0; i < 7; i++)
- sampleBuf[i] = read_value(CMD_X);
- read_value(CMD_X-1);
- filter();
- lastx = (coord_t)sampleBuf[3];
-
- /* Get the Y value using the same process as above */
- read_value(CMD_Y);
- for(i = 0; i < 7; i++)
- sampleBuf[i] = read_value(CMD_Y);
- read_value(CMD_Y-1);
- filter();
- lasty = (coord_t)sampleBuf[3];
-
- // Release the 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 */
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h
deleted file mode 100644
index 09783adf..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h
+++ /dev/null
@@ -1,31 +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 bool_t getpin_pressed(void) {
-
-}
-
-static inline void aquire_bus(void) {
-
-}
-
-static inline void release_bus(void) {
-
-}
-
-static inline uint16_t read_value(uint16_t port) {
-
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h
deleted file mode 100644
index 31840a51..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.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 5
-#define GINPUT_MOUSE_READ_CYCLES 4
-#define GINPUT_MOUSE_POLL_PERIOD 25
-#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
-#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/ADS7843/gmouse_lld_ADS7843.c b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c
new file mode 100644
index 00000000..ac315262
--- /dev/null
+++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c
@@ -0,0 +1,79 @@
+/*
+ * 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_ADS7843
+#include "src/ginput/driver_mouse.h"
+
+// Get the hardware interface
+#include "gmouse_lld_ADS7843_board.h"
+
+#define CMD_X 0xD1
+#define CMD_Y 0x91
+#define CMD_ENABLE_IRQ 0x80
+
+static void MouseXYZ(GMouse* m, GMouseReading* pdr)
+{
+ (void)m;
+
+ // No buttons
+ pdr->buttons = 0;
+ pdr->z = 0;
+
+ if (getpin_pressed(m)) {
+ pdr->z = 1; // Set to Z_MAX as we are pressed
+
+ aquire_bus(m);
+
+ read_value(m, CMD_X); // Dummy read - disable PenIRQ
+ pdr->x = read_value(m, CMD_X); // Read X-Value
+
+ read_value(m, CMD_Y); // Dummy read - disable PenIRQ
+ pdr->y = read_value(m, CMD_Y); // Read Y-Value
+
+ read_value(m, CMD_ENABLE_IRQ); // Enable IRQ
+
+ release_bus(m);
+ }
+}
+
+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,
+ sizeof(GMouse)+BOARD_DATA_SIZE,
+ _gmouseInitDriver,
+ _gmousePostInitDriver,
+ _gmouseDeInitDriver
+ },
+ 1, // z_max - (currently?) not supported
+ 0, // z_min - (currently?) not supported
+ 1, // z_touchon
+ 0, // z_touchoff
+ { // pen_jitter
+ GMOUSE_ADS7843_PEN_CALIBRATE_ERROR, // calibrate
+ GMOUSE_ADS7843_PEN_CLICK_ERROR, // click
+ GMOUSE_ADS7843_PEN_MOVE_ERROR // move
+ },
+ { // finger_jitter
+ GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR, // calibrate
+ GMOUSE_ADS7843_FINGER_CLICK_ERROR, // click
+ GMOUSE_ADS7843_FINGER_MOVE_ERROR // move
+ },
+ init_board, // init
+ 0, // deinit
+ MouseXYZ, // get
+ 0, // calsave
+ 0 // calload
+}};
+
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
+
diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h
new file mode 100644
index 00000000..5a09b5bd
--- /dev/null
+++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h
@@ -0,0 +1,42 @@
+/*
+ * 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
+
+// Resolution and Accuracy Settings
+#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2
+#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2
+#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2
+#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4
+#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4
+#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4
+
+// How much extra data to allocate at the end of the GMouse structure for the board's use
+#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0
+
+static bool_t init_board(GMouse* m, unsigned driverinstance) {
+
+}
+
+static inline bool_t getpin_pressed(GMouse* m) {
+
+}
+
+static inline void aquire_bus(GMouse* m) {
+
+}
+
+static inline void release_bus(GMouse* m) {
+
+}
+
+static inline uint16_t read_value(GMouse* m, uint16_t port) {
+
+}
+
+#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
diff --git a/drivers/ginput/touch/FT5x06/driver.mk b/drivers/ginput/touch/FT5x06/driver.mk
index 17d38c61..741464e8 100644
--- a/drivers/ginput/touch/FT5x06/driver.mk
+++ b/drivers/ginput/touch/FT5x06/driver.mk
@@ -1,5 +1,2 @@
# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c
-
-# Required include directories
-GFXINC += $(GFXLIB)/drivers/ginput/touch/FT5x06
+GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c
diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c b/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c
deleted file mode 100644
index 7a50c5f6..00000000
--- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c
+++ /dev/null
@@ -1,88 +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 "drivers/ginput/touch/FT5x06/ft5x06.h"
-
-// include board abstraction
-#include "ginput_lld_mouse_board.h"
-
-static coord_t x, y, z;
-static uint8_t touched;
-
-void ginput_lld_mouse_init(void) {
- init_board();
-
- // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet)
- // Valid touching detect threshold
- write_reg(FT5x06_ID_G_THGROUP, 1, 0x16);
-
- // valid touching peak detect threshold
- write_reg(FT5x06_ID_G_THPEAK, 1, 0x3C);
-
- // Touch focus threshold
- write_reg(FT5x06_ID_G_THCAL, 1, 0xE9);
-
- // threshold when there is surface water
- write_reg(FT5x06_ID_G_THWATER, 1, 0x01);
-
- // threshold of temperature compensation
- write_reg(FT5x06_ID_G_THTEMP, 1, 0x01);
-
- // Touch difference threshold
- write_reg(FT5x06_ID_G_THDIFF, 1, 0xA0);
-
- // Delay to enter 'Monitor' status (s)
- write_reg(FT5x06_ID_G_TIME_ENTER_MONITOR, 1, 0x0A);
-
- // Period of 'Active' status (ms)
- write_reg(FT5x06_ID_G_PERIODACTIVE, 1, 0x06);
-
- // Timer to enter ÔidleÕ when in 'Monitor' (ms)
- write_reg(FT5x06_ID_G_PERIODMONITOR, 1, 0x28);
-}
-
-void ginput_lld_mouse_get_reading(MouseReading *pt) {
- // Poll to get the touched status
- uint8_t last_touched;
-
- last_touched = touched;
- touched = (uint8_t)read_reg(FT5x06_TOUCH_POINTS, 1) & 0x07;
-
- // If not touched, return the previous results
- if (touched == 0) {
- pt->x = x;
- pt->y = y;
- pt->z = 0;
- pt->buttons = 0;
- return;
- }
-
- /* Get the X, Y, Z values */
- x = (coord_t)(read_reg(FT5x06_TOUCH1_XH, 2) & 0x0fff);
- y = (coord_t)read_reg(FT5x06_TOUCH1_YH, 2);
- z = 100;
-
- // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration!
-#if !GINPUT_MOUSE_NEED_CALIBRATION
- x = gdispGetWidth() - x / (4096/gdispGetWidth());
- y = y / (4096/gdispGetHeight());
-#endif
-
- // Return the results. ADC gives values from 0 to 2^12 (4096)
- pt->x = x;
- pt->y = y;
- pt->z = z;
- pt->buttons = GINPUT_TOUCH_PRESSED;
-}
-
-#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h
deleted file mode 100644
index b7744a49..00000000
--- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h
+++ /dev/null
@@ -1,27 +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 void init_board(void) {
-
-}
-
-static inline bool_t getpin_irq(void) {
-
-}
-
-static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {
-
-}
-
-static uint16_t read_reg(uint8_t reg, uint8_t n) {
-
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h
deleted file mode 100644
index 24335a0a..00000000
--- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.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 15
-#define GINPUT_MOUSE_READ_CYCLES 1
-#define GINPUT_MOUSE_POLL_PERIOD 25
-#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
-#define GINPUT_MOUSE_MAX_MOVE_JITTER 5
-#define GINPUT_MOUSE_CLICK_TIME 450
-
-#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c
new file mode 100644
index 00000000..ed2e68fa
--- /dev/null
+++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c
@@ -0,0 +1,120 @@
+/*
+ * 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_FT5x06
+#include "src/ginput/driver_mouse.h"
+
+// Get the hardware interface
+#include "gmouse_lld_FT5x06_board.h"
+
+// Hardware definitions
+#include "drivers/ginput/touch/FT5x06/ft5x06.h"
+
+static bool_t MouseInit(GMouse* m, unsigned driverinstance) {
+ if (!init_board(m, driverinstance))
+ return FALSE;
+
+ aquire_bus(m);
+
+ // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet)
+ // Valid touching detect threshold
+ write_reg(m, FT5x06_ID_G_THGROUP, 0x16);
+
+ // valid touching peak detect threshold
+ write_reg(m, FT5x06_ID_G_THPEAK, 0x3C);
+
+ // Touch focus threshold
+ write_reg(m, FT5x06_ID_G_THCAL, 0xE9);
+
+ // threshold when there is surface water
+ write_reg(m, FT5x06_ID_G_THWATER, 0x01);
+
+ // threshold of temperature compensation
+ write_reg(m, FT5x06_ID_G_THTEMP, 0x01);
+
+ // Touch difference threshold
+ write_reg(m, FT5x06_ID_G_THDIFF, 0xA0);
+
+ // Delay to enter 'Monitor' status (s)
+ write_reg(m, FT5x06_ID_G_TIME_ENTER_MONITOR, 0x0A);
+
+ // Period of 'Active' status (ms)
+ write_reg(m, FT5x06_ID_G_PERIODACTIVE, 0x06);
+
+ // Timer to enter 'idle' when in 'Monitor' (ms)
+ write_reg(m, FT5x06_ID_G_PERIODMONITOR, 0x28);
+
+ release_bus(m);
+ return TRUE;
+}
+
+static void MouseXYZ(GMouse* m, GMouseReading* pdr)
+{
+ // Assume not touched.
+ pdr->buttons = 0;
+ pdr->z = 0;
+
+ aquire_bus(m);
+
+ // Only take a reading if we are touched.
+ if ((read_byte(m, FT5x06_TOUCH_POINTS) & 0x07)) {
+
+ /* Get the X, Y, Z values */
+ pdr->x = (coord_t)(read_word(m, FT5x06_TOUCH1_XH) & 0x0fff);
+ pdr->y = (coord_t)read_word(m, FT5x06_TOUCH1_YH);
+ pdr->z = 1;
+
+ #if GMOUSE_FT5x06_SELF_CALIBRATE
+ // Rescale X,Y,Z - If we are using self-calibration
+ pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display));
+ pdr->y = pdr->y / (4096/gdispGGetHeight(m->display));
+ #endif
+ }
+
+ release_bus(m);
+}
+
+const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
+ {
+ GDRIVER_TYPE_TOUCH,
+ #if GMOUSE_FT5x06_SELF_CALIBRATE
+ GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN,
+ #else
+ GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST,
+ #endif
+ sizeof(GMouse) + GMOUSE_FT5x06_BOARD_DATA_SIZE,
+ _gmouseInitDriver,
+ _gmousePostInitDriver,
+ _gmouseDeInitDriver
+ },
+ 1, // z_max - (currently?) not supported
+ 0, // z_min - (currently?) not supported
+ 1, // z_touchon
+ 0, // z_touchoff
+ { // pen_jitter
+ GMOUSE_FT5x06_PEN_CALIBRATE_ERROR, // calibrate
+ GMOUSE_FT5x06_PEN_CLICK_ERROR, // click
+ GMOUSE_FT5x06_PEN_MOVE_ERROR // move
+ },
+ { // finger_jitter
+ GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR, // calibrate
+ GMOUSE_FT5x06_FINGER_CLICK_ERROR, // click
+ GMOUSE_FT5x06_FINGER_MOVE_ERROR // move
+ },
+ MouseInit, // init
+ 0, // deinit
+ read_xyz, // get
+ 0, // calsave
+ 0 // calload
+}};
+
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
+
diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h
new file mode 100644
index 00000000..46680a16
--- /dev/null
+++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h
@@ -0,0 +1,46 @@
+/*
+ * 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
+
+// Resolution and Accuracy Settings
+#define GMOUSE_FT5x06_PEN_CALIBRATE_ERROR 8
+#define GMOUSE_FT5x06_PEN_CLICK_ERROR 6
+#define GMOUSE_FT5x06_PEN_MOVE_ERROR 4
+#define GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR 14
+#define GMOUSE_FT5x06_FINGER_CLICK_ERROR 18
+#define GMOUSE_FT5x06_FINGER_MOVE_ERROR 14
+
+// How much extra data to allocate at the end of the GMouse structure for the board's use
+#define GMOUSE_FT5x06_BOARD_DATA_SIZE 0
+
+// Set this to TRUE if you want self-calibration.
+// NOTE: This is not as accurate as real calibration.
+// It requires the orientation of the touch panel to match the display.
+// It requires the active area of the touch panel to exactly match the display size.
+#define GMOUSE_FT5x06_SELF_CALIBRATE FALSE
+
+static bool_t init_board(GMouse* m, unsigned driverinstance) {
+}
+
+static inline void aquire_bus(GMouse* m) {
+}
+
+static inline void release_bus(GMouse* m) {
+}
+
+static void write_reg(GMouse* m, uint8_t reg, uint8_t val) {
+}
+
+static uint8_t read_byte(GMouse* m, uint8_t reg) {
+}
+
+static uint16_t read_word(GMouse* m, uint8_t reg) {
+}
+
+#endif /* _GINPUT_LLD_MOUSE_BOARD_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..babf8bc3
--- /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) + GMOUSE_MCU_BOARD_DATA_SIZE,
+ _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
+ },
+ GMOUSE_MCU_Z_MAX, // z_max
+ GMOUSE_MCU_Z_MIN, // z_min
+ GMOUSE_MCU_Z_TOUCHON, // z_touchon
+ GMOUSE_MCU_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..07583fa9
--- /dev/null
+++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h
@@ -0,0 +1,32 @@
+/*
+ * 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
+
+// Resolution and Accuracy Settings
+#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8
+#define GMOUSE_MCU_PEN_CLICK_ERROR 6
+#define GMOUSE_MCU_PEN_MOVE_ERROR 4
+#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14
+#define GMOUSE_MCU_FINGER_CLICK_ERROR 18
+#define GMOUSE_MCU_FINGER_MOVE_ERROR 14
+#define GMOUSE_MCU_Z_MIN 0 // The minimum Z reading
+#define GMOUSE_MCU_Z_MAX 100 // The maximum Z reading
+#define GMOUSE_MCU_Z_TOUCHON 80 // Values between this and Z_MAX are definitely pressed
+#define GMOUSE_MCU_Z_TOUCHOFF 70 // Values between this and Z_MIN are definitely not pressed
+
+// How much extra data to allocate at the end of the GMouse structure for the board's use
+#define GMOUSE_MCU_BOARD_DATA_SIZE 0
+
+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/STMPE811/driver.mk b/drivers/ginput/touch/STMPE811/driver.mk
index 5147e989..cf12507b 100644
--- a/drivers/ginput/touch/STMPE811/driver.mk
+++ b/drivers/ginput/touch/STMPE811/driver.mk
@@ -1,5 +1,2 @@
# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
-
-# Required include directories
-GFXINC += $(GFXLIB)/drivers/ginput/touch/STMPE811
+GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
deleted file mode 100644
index e658fae2..00000000
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
+++ /dev/null
@@ -1,132 +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 "drivers/ginput/touch/STMPE811/stmpe811.h"
-
-#include "ginput_lld_mouse_board.h"
-
-#ifndef STMP811_NO_GPIO_IRQPIN
- #define STMP811_NO_GPIO_IRQPIN FALSE
-#endif
-#ifndef STMP811_SLOW_CPU
- #define STMP811_SLOW_CPU FALSE
-#endif
-
-static coord_t x, y, z;
-static uint8_t touched;
-
-/* set the active window of the stmpe811. bl is bottom left, tr is top right */
-static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_t tr_y)
-{
- write_reg(STMPE811_REG_WDW_TR_X, 2, tr_x);
- write_reg(STMPE811_REG_WDW_TR_Y, 2, tr_y);
- write_reg(STMPE811_REG_WDW_BL_X, 2, bl_x);
- write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y);
-}
-
-void ginput_lld_mouse_init(void)
-{
- init_board();
-
- write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset
- gfxSleepMilliseconds(10);
-
- write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on
-#if STMP811_NO_GPIO_IRQPIN
- write_reg(STMPE811_REG_INT_EN, 1, 0x00); // Interrupt on INT pin when touch is detected
-#else
- write_reg(STMPE811_REG_INT_EN, 1, 0x01); // Interrupt on INT pin when touch is detected
-#endif
- write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
- gfxSleepMilliseconds(2);
-
- write_reg(STMPE811_REG_ADC_CTRL2, 1, 0x01); // ADC speed 3.25MHz
- write_reg(STMPE811_REG_GPIO_AF, 1, 0x00); // GPIO alternate function - OFF
- write_reg(STMPE811_REG_TSC_CFG, 1, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us
- write_reg(STMPE811_REG_FIFO_TH, 1, 0x40); // FIFO threshold = 64
- write_reg(STMPE811_REG_FIFO_STA, 1, 0x01); // FIFO reset enable
- write_reg(STMPE811_REG_FIFO_STA, 1, 0x00); // FIFO reset disable
- write_reg(STMPE811_REG_TSC_FRACT_XYZ, 1, 0x07); // Z axis data format
- write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current
- write_reg(STMPE811_REG_TSC_CTRL, 1, 0x00); // X&Y&Z
- write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable
- write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts
-#if !STMP811_NO_GPIO_IRQPIN
- touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80;
-#endif
- write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts
-}
-
-void ginput_lld_mouse_get_reading(MouseReading *pt)
-{
- bool_t clearfifo; // Do we need to clear the FIFO
-
-#if STMP811_NO_GPIO_IRQPIN
- // Poll to get the touched status
- uint8_t last_touched;
-
- last_touched = touched;
- touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80;
- clearfifo = (touched != last_touched);
-#else
- // Check if the touch controller IRQ pin has gone off
- clearfifo = false;
- if(getpin_irq()) { // please rename this to getpin_irq
- write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // clear all interrupts
- touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; // set the new touched status
- clearfifo = true; // only take the last FIFO reading
- }
-#endif
-
- // If not touched, return the previous results
- if (!touched) {
- pt->x = x;
- pt->y = y;
- pt->z = 0;
- pt->buttons = 0;
- return;
- }
-
-#if !STMP811_SLOW_CPU
- if (!clearfifo && (read_reg(STMPE811_REG_FIFO_STA, 1) & 0xD0))
-#endif
- clearfifo = true;
-
- do {
- /* Get the X, Y, Z values */
- /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */
- x = (coord_t)read_reg(STMPE811_REG_TSC_DATA_X, 2);
- y = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Y, 2);
- z = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Z, 1);
- } while(clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20));
-
- // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration!
-#if !GINPUT_MOUSE_NEED_CALIBRATION
- x = gdispGetWidth() - x / (4096/gdispGetWidth());
- y = y / (4096/gdispGetHeight());
-#endif
- z = (((z&0xFF) * 100)>>8) + 1;
-
- // Return the results. ADC gives values from 0 to 2^12 (4096)
- pt->x = x;
- pt->y = y;
- pt->z = z;
- pt->buttons = GINPUT_TOUCH_PRESSED;
-
- /* Force another read if we have more results */
- if (!clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20))
- ginputMouseWakeup();
-
-}
-
-#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h
deleted file mode 100644
index b7744a49..00000000
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h
+++ /dev/null
@@ -1,27 +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 void init_board(void) {
-
-}
-
-static inline bool_t getpin_irq(void) {
-
-}
-
-static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {
-
-}
-
-static uint16_t read_reg(uint8_t reg, uint8_t n) {
-
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h
deleted file mode 100644
index 5cd512eb..00000000
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h
+++ /dev/null
@@ -1,25 +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 5
-#define GINPUT_MOUSE_READ_CYCLES 1
-#define GINPUT_MOUSE_POLL_PERIOD 25
-#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
-#define GINPUT_MOUSE_MAX_MOVE_JITTER 5
-#define GINPUT_MOUSE_CLICK_TIME 450
-
-/* default values - over write these in your boad files */
-#define STMP811_SLOWER_RESPONSE FALSE
-#define STMP811_NO_GPIO_IRQPIN FALSE
-
-#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c
new file mode 100644
index 00000000..6951f3ab
--- /dev/null
+++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c
@@ -0,0 +1,164 @@
+/*
+ * 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_STMPE811
+#include "src/ginput/driver_mouse.h"
+
+#define GMOUSE_STMPE811_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST<<0)
+
+// Hardware definitions
+#include "drivers/ginput/touch/STMPE811/stmpe811.h"
+
+// Get the hardware interface
+#include "gmouse_lld_STMPE811_board.h"
+
+static bool_t MouseInit(GMouse* m, unsigned driverinstance) {
+ if (!init_board(m, driverinstance))
+ return FALSE;
+
+ aquire_bus(m);
+
+ write_reg(m, STMPE811_REG_SYS_CTRL1, 0x02); // Software chip reset
+ gfxSleepMilliseconds(10);
+
+ write_reg(m, STMPE811_REG_SYS_CTRL2, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on
+
+ #if GMOUSE_STMPE811_GPIO_IRQPIN
+ write_reg(m, STMPE811_REG_INT_EN, 0x01); // Interrupt on INT pin when touch is detected
+ #else
+ write_reg(m, STMPE811_REG_INT_EN, 0x00); // Don't Interrupt on INT pin when touch is detected
+ #endif
+
+ write_reg(m, STMPE811_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
+ gfxSleepMilliseconds(2);
+
+ write_reg(m, STMPE811_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz
+ write_reg(m, STMPE811_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF
+ write_reg(m, STMPE811_REG_TSC_CFG, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us
+ write_reg(m, STMPE811_REG_FIFO_TH, 0x40); // FIFO threshold = 64
+ write_reg(m, STMPE811_REG_FIFO_STA, 0x01); // FIFO reset enable
+ write_reg(m, STMPE811_REG_FIFO_STA, 0x00); // FIFO reset disable
+ write_reg(m, STMPE811_REG_TSC_FRACT_XYZ, 0x07); // Z axis data format
+ write_reg(m, STMPE811_REG_TSC_I_DRIVE, 0x01); // 50mA touchscreen line current
+ write_reg(m, STMPE811_REG_TSC_CTRL, 0x00); // X&Y&Z
+ write_reg(m, STMPE811_REG_TSC_CTRL, 0x01); // X&Y&Z, TSC enable
+ write_reg(m, STMPE811_REG_INT_STA, 0xFF); // Clear all interrupts
+ #if GMOUSE_STMPE811_GPIO_IRQPIN
+ if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80)
+ m->flags |= GMOUSE_STMPE811_FLG_TOUCHED;
+ #endif
+ write_reg(m, STMPE811_REG_INT_CTRL, 0x01); // Level interrupt, enable interrupts
+
+ release_bus(m);
+ return TRUE;
+}
+
+static void read_xyz(GMouse* m, GMouseReading* pdr)
+{
+ bool_t clearfifo; // Do we need to clear the FIFO
+
+ // Assume not touched.
+ pdr->buttons = 0;
+ pdr->z = 0;
+
+ aquire_bus(m);
+
+ #if GMOUSE_STMPE811_GPIO_IRQPIN
+ // Check if the touch controller IRQ pin has gone off
+ clearfifo = false;
+ if(getpin_irq(m)) {
+ write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts
+ if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status
+ m->flags |= GMOUSE_STMPE811_FLG_TOUCHED;
+ else
+ m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED;
+ clearfifo = TRUE; // only take the last FIFO reading
+ }
+
+ #else
+ // Poll to get the touched status
+ uint16_t last_touched;
+
+ last_touched = m->flags;
+ if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status
+ m->flags |= GMOUSE_STMPE811_FLG_TOUCHED;
+ else
+ m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED;
+ clearfifo = ((m->flags ^ last_touched) & GMOUSE_STMPE811_FLG_TOUCHED) ? TRUE : FALSE;
+ #endif
+
+ // If not touched don't do any more
+ if ((m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED)) {
+
+ // Clear the fifo if it is too full
+ #if !GMOUSE_STMPE811_SLOW_CPU
+ if (!clearfifo && (read_byte(m, STMPE811_REG_FIFO_STA) & 0xD0))
+ #endif
+ clearfifo = true;
+
+ do {
+ /* Get the X, Y, Z values */
+ /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */
+ pdr->x = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_X);
+ pdr->y = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_Y);
+ pdr->z = (coord_t)read_byte(m, STMPE811_REG_TSC_DATA_Z);
+ } while(clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20));
+
+ #if GMOUSE_STMPE811_SELF_CALIBRATE
+ // Rescale X,Y,Z - If we are using self-calibration
+ pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display));
+ pdr->y = pdr->y / (4096/gdispGGetHeight(m->display));
+ #endif
+
+ /* Force another read if we have more results */
+ if (!clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20))
+ _gmouseWakeup(m);
+ }
+
+ release_bus(m);
+}
+
+const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
+ {
+ GDRIVER_TYPE_TOUCH,
+ #if GMOUSE_STMPE811_SELF_CALIBRATE
+ GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN,
+ #else
+ GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST,
+ #endif
+ sizeof(GMouse) + GMOUSE_STMPE811_BOARD_DATA_SIZE,
+ _gmouseInitDriver,
+ _gmousePostInitDriver,
+ _gmouseDeInitDriver
+ },
+ 255, // z_max
+ 0, // z_min
+ 200, // z_touchon
+ 20, // z_touchoff
+ { // pen_jitter
+ GMOUSE_STMPE811_PEN_CALIBRATE_ERROR, // calibrate
+ GMOUSE_STMPE811_PEN_CLICK_ERROR, // click
+ GMOUSE_STMPE811_PEN_MOVE_ERROR // move
+ },
+ { // finger_jitter
+ GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR, // calibrate
+ GMOUSE_STMPE811_FINGER_CLICK_ERROR, // click
+ GMOUSE_STMPE811_FINGER_MOVE_ERROR // move
+ },
+ MouseInit, // init
+ 0, // deinit
+ read_xyz, // get
+ 0, // calsave
+ 0 // calload
+}};
+
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
+
diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h
new file mode 100644
index 00000000..437abc09
--- /dev/null
+++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h
@@ -0,0 +1,58 @@
+/*
+ * 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
+
+// Resolution and Accuracy Settings
+#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8
+#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6
+#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4
+#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14
+#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18
+#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14
+
+// How much extra data to allocate at the end of the GMouse structure for the board's use
+#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0
+
+// Set this to TRUE if you want self-calibration.
+// NOTE: This is not as accurate as real calibration.
+// It requires the orientation of the touch panel to match the display.
+// It requires the active area of the touch panel to exactly match the display size.
+#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE
+
+// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO.
+#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE
+
+// If TRUE this is a really slow CPU and we should always clear the FIFO between reads.
+#define GMOUSE_STMPE811_SLOW_CPU FALSE
+
+static bool_t init_board(GMouse* m, unsigned driverinstance) {
+}
+
+#if GMOUSE_STMPE811_GPIO_IRQPIN
+ static bool_t getpin_irq(GMouse* m) {
+
+ }
+#endif
+
+static inline void aquire_bus(GMouse* m) {
+}
+
+static inline void release_bus(GMouse* m) {
+}
+
+static void write_reg(GMouse* m, uint8_t reg, uint8_t val) {
+}
+
+static uint8_t read_byte(GMouse* m, uint8_t reg) {
+}
+
+static uint16_t read_word(GMouse* m, uint8_t reg) {
+}
+
+#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h
index 1ee9c211..f0d2df42 100644
--- a/drivers/ginput/touch/STMPE811/stmpe811.h
+++ b/drivers/ginput/touch/STMPE811/stmpe811.h
@@ -11,9 +11,6 @@
// Slave address
#define STMPE811_ADDR (0x82 >> 1)
-// Maximum timeout
-#define STMPE811_TIMEOUT 0x3000
-
// Identification registers
#define STMPE811_REG_CHP_ID 0x00 // 16-bit
#define STMPE811_REG_ID_VER 0x02
diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c
index 3643d727..ecb100f6 100644
--- a/drivers/multiple/Win32/gdisp_lld_Win32.c
+++ b/drivers/multiple/Win32/gdisp_lld_Win32.c
@@ -10,7 +10,7 @@
#if GFX_USE_GDISP
#define GDISP_DRIVER_VMT GDISPVMT_Win32
-#include "drivers/multiple/Win32/gdisp_lld_config.h"
+#include "gdisp_lld_config.h"
#include "src/gdisp/driver.h"
#ifndef GDISP_SCREEN_WIDTH
@@ -52,7 +52,6 @@
#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
#define GDISP_FLG_HASTOGGLE (GDISP_FLG_DRIVER<<1)
-#define GDISP_FLG_HASMOUSE (GDISP_FLG_DRIVER<<2)
#if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
#define GDISP_FLG_WSTREAM (GDISP_FLG_DRIVER<<3)
#define GDISP_FLG_WRAPPED (GDISP_FLG_DRIVER<<4)
@@ -64,16 +63,50 @@
#endif
#if GINPUT_NEED_MOUSE
- /* Include mouse support code */
+ // Include mouse support code
+ #define GMOUSE_DRIVER_VMT GMOUSEVMT_Win32
#include "src/ginput/driver_mouse.h"
+
+ // Forward definitions
+ static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance);
+ static void Win32MouseRead(GMouse *m, GMouseReading *prd);
+
+ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
+ {
+ GDRIVER_TYPE_MOUSE,
+ GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY,
+ // Extra flags for testing only
+ //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER
+ //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE
+ //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN
+ sizeof(GMouse),
+ _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
+ },
+ 1, // z_max
+ 0, // z_min
+ 1, // z_touchon
+ 0, // z_touchoff
+ { // pen_jitter
+ 0, // calibrate
+ 0, // click
+ 0 // move
+ },
+ { // finger_jitter
+ 0, // calibrate
+ 2, // click
+ 2 // move
+ },
+ Win32MouseInit, // init
+ 0, // deinit
+ Win32MouseRead, // get
+ 0, // calsave
+ 0 // calload
+ }};
#endif
static DWORD winThreadId;
static volatile bool_t QReady;
static HANDLE drawMutex;
-#if GINPUT_NEED_MOUSE
- static GDisplay * mouseDisplay;
-#endif
/*===========================================================================*/
/* Driver local routines . */
@@ -95,6 +128,7 @@ typedef struct winPriv {
#if GINPUT_NEED_MOUSE
coord_t mousex, mousey;
uint16_t mousebuttons;
+ GMouse *mouse;
#endif
#if GINPUT_NEED_TOGGLE
uint8_t toggles;
@@ -149,7 +183,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
// Handle mouse down on the window
#if GINPUT_NEED_MOUSE
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons |= GINPUT_MOUSE_BTN_LEFT;
goto mousemove;
}
@@ -198,7 +232,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
// Handle mouse up on the window
#if GINPUT_NEED_MOUSE
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT;
goto mousemove;
}
@@ -210,7 +244,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
case WM_MBUTTONDOWN:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE;
goto mousemove;
}
@@ -218,7 +252,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
case WM_MBUTTONUP:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE;
goto mousemove;
}
@@ -226,7 +260,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONDOWN:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons |= GINPUT_MOUSE_BTN_RIGHT;
goto mousemove;
}
@@ -234,7 +268,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONUP:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
- if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) {
priv->mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT;
goto mousemove;
}
@@ -242,14 +276,13 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE:
g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
priv = (winPriv *)g->priv;
- if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT || !(g->flags & GDISP_FLG_HASMOUSE))
+ if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT)
break;
mousemove:
priv->mousex = (coord_t)LOWORD(lParam);
priv->mousey = (coord_t)HIWORD(lParam);
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
+ if ((gmvmt(priv->mouse)->d.flags & GMOUSE_VFLG_NOPOLL)) // For normal setup this is always TRUE
+ _gmouseWakeup(priv->mouse);
break;
#endif
@@ -445,14 +478,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
g->flags |= GDISP_FLG_HASTOGGLE;
#endif
- // Only turn on mouse on the first window for now
- #if GINPUT_NEED_MOUSE
- if (!g->controllerdisplay) {
- mouseDisplay = g;
- g->flags |= GDISP_FLG_HASMOUSE;
- }
- #endif
-
// Create a private area for this window
priv = gfxAlloc(sizeof(winPriv));
assert(priv != 0);
@@ -471,6 +496,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
Sleep(1);
+ // Create the associated mouse
+ #if GINPUT_NEED_MOUSE
+ priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
+ #endif
+
sprintf(buf, APP_NAME " - %u", g->systemdisplay+1);
SetWindowText(priv->hwnd, buf);
ShowWindow(priv->hwnd, SW_SHOW);
@@ -686,10 +716,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
winPriv * priv;
int x, y;
COLORREF color;
-
+
priv = g->priv;
color = gdispColor2Native(g->p.color);
-
+
#if GDISP_NEED_CONTROL
switch(g->g.Orientation) {
case GDISP_ROTATE_0:
@@ -818,7 +848,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
sz = (size_t)g->p.cx * (size_t)g->p.cy;
if (!(dstbuf = (pixel_t *)malloc(sz * sizeof(pixel_t))))
return 0;
-
+
// Copy the bits we need
switch(g->g.Orientation) {
case GDISP_ROTATE_0:
@@ -847,7 +877,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
return dstbuf;
}
#endif
-
+
#if GDISP_HARDWARE_BITFILLS
#if COLOR_SYSTEM != GDISP_COLORSYSTEM_TRUECOLOR || COLOR_TYPE_BITS <= 8
#error "GDISP Win32: This driver's bitblit currently only supports true-color with bit depths > 8 bits."
@@ -863,7 +893,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
priv = g->priv;
buffer = g->p.ptr;
buffer += g->p.x2*g->p.y1;
-
+
memset(&bmpInfo, 0, sizeof(bmpInfo));
bmpInfo.bV4Size = sizeof(bmpInfo);
bmpInfo.bV4Planes = 1;
@@ -982,7 +1012,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
color = GetPixel(priv->dcBuffer, g->p.x, g->p.y);
#endif
ReleaseMutex(drawMutex);
-
+
return gdispNative2Color(color);
}
#endif
@@ -992,7 +1022,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
winPriv * priv;
RECT rect;
coord_t lines;
-
+
priv = g->priv;
#if GDISP_NEED_CONTROL
@@ -1134,18 +1164,49 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
#if GINPUT_NEED_MOUSE
- void ginput_lld_mouse_init(void) {}
- void ginput_lld_mouse_get_reading(MouseReading *pt) {
+ static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance) {
+ (void) m;
+ (void) driverinstance;
+ return TRUE;
+ }
+ static void Win32MouseRead(GMouse *m, GMouseReading *pt) {
GDisplay * g;
winPriv * priv;
- g = mouseDisplay;
+ g = m->display;
priv = g->priv;
pt->x = priv->mousex;
- pt->y = priv->mousey > g->g.Height ? g->g.Height : priv->mousey;
- pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
+ pt->y = priv->mousey;
+ pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0;
pt->buttons = priv->mousebuttons;
+
+ #if GDISP_NEED_CONTROL
+ // If the self-rotation has been set in the VMT then do that here (TESTING ONLY)
+ if ((gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { // For normal setup this is always False
+ coord_t t;
+
+ switch(gdispGGetOrientation(m->display)) {
+ case GDISP_ROTATE_0:
+ default:
+ break;
+ case GDISP_ROTATE_90:
+ t = pt->x;
+ pt->x = g->g.Width - 1 - pt->y;
+ pt->y = t;
+ break;
+ case GDISP_ROTATE_180:
+ pt->x = g->g.Width - 1 - pt->x;
+ pt->y = g->g.Height - 1 - pt->y;
+ break;
+ case GDISP_ROTATE_270:
+ t = pt->y;
+ pt->y = g->g.Height - 1 - pt->x;
+ pt->x = t;
+ break;
+ }
+ }
+ #endif
}
#endif /* GINPUT_NEED_MOUSE */
diff --git a/drivers/multiple/Win32/ginput_lld_mouse_config.h b/drivers/multiple/Win32/ginput_lld_mouse_config.h
deleted file mode 100644
index 8263ebed..00000000
--- a/drivers/multiple/Win32/ginput_lld_mouse_config.h
+++ /dev/null
@@ -1,38 +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
-
-// This driver supports being both a mouse or a touch device (we don't actually know which it really is)
-// When operating in mouse mode a long left button click does not generate a context click.
-// When operating in touch mode we allow sloppier clicks etc
-#if 1
- #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE
- #define GINPUT_MOUSE_CLICK_TIME TIME_INFINITE // Long click != Context Click
- #define GINPUT_MOUSE_NEED_CALIBRATION FALSE
- #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
- #define GINPUT_MOUSE_READ_CYCLES 1
- #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1
- #define GINPUT_MOUSE_MAX_CLICK_JITTER 0
- #define GINPUT_MOUSE_MAX_MOVE_JITTER 0
-#else
- #define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
- #define GINPUT_MOUSE_CLICK_TIME 700 // Long click = Context Click
- #define GINPUT_MOUSE_NEED_CALIBRATION FALSE // Can be set to TRUE just for testing
- #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
- #define GINPUT_MOUSE_READ_CYCLES 1
- #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 2
- #define GINPUT_MOUSE_MAX_CLICK_JITTER 2
- #define GINPUT_MOUSE_MAX_MOVE_JITTER 2
-#endif
-
-// This driver supports both an "interrupt" mode, and a polled mode
-#define GINPUT_MOUSE_POLL_PERIOD TIME_INFINITE // Interrupt driven by the Window thread
-//#define GINPUT_MOUSE_POLL_PERIOD 25 // Poll driven
-
-#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c
index 35cf250d..6e0233ba 100644
--- a/drivers/multiple/X/gdisp_lld_X.c
+++ b/drivers/multiple/X/gdisp_lld_X.c
@@ -10,7 +10,7 @@
#if GFX_USE_GDISP
#define GDISP_DRIVER_VMT GDISPVMT_X11
-#include "drivers/multiple/X/gdisp_lld_config.h"
+#include "gdisp_lld_config.h"
#include "src/gdisp/driver.h"
#ifndef GDISP_FORCE_24BIT
@@ -27,8 +27,45 @@
#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
#if GINPUT_NEED_MOUSE
- /* Include mouse support code */
+ // Include mouse support code
+ #define GMOUSE_DRIVER_VMT GMOUSEVMT_X11
#include "src/ginput/driver_mouse.h"
+
+ // Forward definitions
+ static bool_t XMouseInit(GMouse *m, unsigned driverinstance);
+ static void XMouseRead(GMouse *m, GMouseReading *prd);
+
+ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
+ {
+ GDRIVER_TYPE_MOUSE,
+ GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY,
+ // Extra flags for testing only
+ //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER
+ //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE
+ //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN
+ sizeof(GMouse),
+ _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
+ },
+ 1, // z_max
+ 0, // z_min
+ 1, // z_touchon
+ 0, // z_touchoff
+ { // pen_jitter
+ 0, // calibrate
+ 0, // click
+ 0 // move
+ },
+ { // finger_jitter
+ 0, // calibrate
+ 2, // click
+ 2 // move
+ },
+ XMouseInit, // init
+ 0, // deinit
+ XMouseRead, // get
+ 0, // calsave
+ 0 // calload
+ }};
#endif
#include <X11/Xlib.h>
@@ -45,15 +82,16 @@ static Colormap cmap;
static XVisualInfo vis;
static XContext cxt;
static Atom wmDelete;
-#if GINPUT_NEED_MOUSE
- static coord_t mousex, mousey;
- static uint16_t mousebuttons;
-#endif
typedef struct xPriv {
Pixmap pix;
GC gc;
Window win;
+ #if GINPUT_NEED_MOUSE
+ coord_t mousex, mousey;
+ uint16_t buttons;
+ GMouse * mouse;
+ #endif
} xPriv;
static void ProcessEvent(GDisplay *g, xPriv *priv) {
@@ -80,37 +118,31 @@ static void ProcessEvent(GDisplay *g, xPriv *priv) {
break;
#if GINPUT_NEED_MOUSE
case ButtonPress:
- mousex = evt.xbutton.x;
- mousey = evt.xbutton.y;
+ priv->mousex = evt.xbutton.x;
+ priv->mousey = evt.xbutton.y;
switch(evt.xbutton.button){
- case 1: mousebuttons |= GINPUT_MOUSE_BTN_LEFT; break;
- case 2: mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
- case 3: mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; break;
- case 4: mousebuttons |= GINPUT_MOUSE_BTN_4; break;
+ case 1: priv->buttons |= GINPUT_MOUSE_BTN_LEFT; break;
+ case 2: priv->buttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
+ case 3: priv->buttons |= GINPUT_MOUSE_BTN_RIGHT; break;
+ case 4: priv->buttons |= GINPUT_MOUSE_BTN_4; break;
}
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
+ _gmouseWakeup(priv->mouse);
break;
case ButtonRelease:
- mousex = evt.xbutton.x;
- mousey = evt.xbutton.y;
+ priv->mousex = evt.xbutton.x;
+ priv->mousey = evt.xbutton.y;
switch(evt.xbutton.button){
- case 1: mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
- case 2: mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
- case 3: mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
- case 4: mousebuttons &= ~GINPUT_MOUSE_BTN_4; break;
+ case 1: priv->buttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
+ case 2: priv->buttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
+ case 3: priv->buttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
+ case 4: priv->buttons &= ~GINPUT_MOUSE_BTN_4; break;
}
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
+ _gmouseWakeup(priv->mouse);
break;
case MotionNotify:
- mousex = evt.xmotion.x;
- mousey = evt.xmotion.y;
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
+ priv->mousex = evt.xmotion.x;
+ priv->mousey = evt.xmotion.y;
+ _gmouseWakeup(priv->mouse);
break;
#endif
}
@@ -231,6 +263,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
XSetBackground(dis, priv->gc, BlackPixel(dis, scr));
XSync(dis, TRUE);
+ // Create the associated mouse before the map
+ #if GINPUT_NEED_MOUSE
+ priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
+ #endif
+
XSelectInput(dis, priv->win, StructureNotifyMask);
XMapWindow(dis, priv->win);
@@ -322,16 +359,20 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g)
#endif
#if GINPUT_NEED_MOUSE
-
- void ginput_lld_mouse_init(void) {}
-
- void ginput_lld_mouse_get_reading(MouseReading *pt) {
- pt->x = mousex;
- pt->y = mousey;
- pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
- pt->buttons = mousebuttons;
+ static bool_t XMouseInit(GMouse *m, unsigned driverinstance) {
+ (void) m;
+ (void) driverinstance;
+ return TRUE;
+ }
+ static void XMouseRead(GMouse *m, GMouseReading *pt) {
+ xPriv * priv;
+
+ priv = m->display->priv;
+ pt->x = priv->mousex;
+ pt->y = priv->mousey;
+ pt->z = (priv->buttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0;
+ pt->buttons = priv->buttons;
}
-
#endif /* GINPUT_NEED_MOUSE */
#endif /* GFX_USE_GDISP */
diff --git a/drivers/multiple/X/ginput_lld_mouse_config.h b/drivers/multiple/X/ginput_lld_mouse_config.h
deleted file mode 100644
index 8263ebed..00000000
--- a/drivers/multiple/X/ginput_lld_mouse_config.h
+++ /dev/null
@@ -1,38 +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
-
-// This driver supports being both a mouse or a touch device (we don't actually know which it really is)
-// When operating in mouse mode a long left button click does not generate a context click.
-// When operating in touch mode we allow sloppier clicks etc
-#if 1
- #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE
- #define GINPUT_MOUSE_CLICK_TIME TIME_INFINITE // Long click != Context Click
- #define GINPUT_MOUSE_NEED_CALIBRATION FALSE
- #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
- #define GINPUT_MOUSE_READ_CYCLES 1
- #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1
- #define GINPUT_MOUSE_MAX_CLICK_JITTER 0
- #define GINPUT_MOUSE_MAX_MOVE_JITTER 0
-#else
- #define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
- #define GINPUT_MOUSE_CLICK_TIME 700 // Long click = Context Click
- #define GINPUT_MOUSE_NEED_CALIBRATION FALSE // Can be set to TRUE just for testing
- #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
- #define GINPUT_MOUSE_READ_CYCLES 1
- #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 2
- #define GINPUT_MOUSE_MAX_CLICK_JITTER 2
- #define GINPUT_MOUSE_MAX_MOVE_JITTER 2
-#endif
-
-// This driver supports both an "interrupt" mode, and a polled mode
-#define GINPUT_MOUSE_POLL_PERIOD TIME_INFINITE // Interrupt driven by the Window thread
-//#define GINPUT_MOUSE_POLL_PERIOD 25 // Poll driven
-
-#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
diff --git a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c
index 82c0e2ff..559b0c69 100644
--- a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c
+++ b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c
@@ -10,7 +10,7 @@
#if GFX_USE_GDISP
#define GDISP_DRIVER_VMT GDISPVMT_uGFXnet
-#include "drivers/multiple/uGFXnet/gdisp_lld_config.h"
+#include "gdisp_lld_config.h"
#include "src/gdisp/driver.h"
#include "uGFXnetProtocol.h"
@@ -33,6 +33,48 @@
#define GDISP_GFXNET_BROKEN_LWIP_ACCEPT FALSE
#endif
+#if GINPUT_NEED_MOUSE
+ // Include mouse support code
+ #define GMOUSE_DRIVER_VMT GMOUSEVMT_uGFXnet
+ #include "src/ginput/driver_mouse.h"
+
+ // Forward definitions
+ static bool_t NMouseInit(GMouse *m, unsigned driverinstance);
+ static void NMouseRead(GMouse *m, GMouseReading *prd);
+
+ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
+ {
+ GDRIVER_TYPE_MOUSE,
+ GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY,
+ // Extra flags for testing only
+ //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER
+ //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE
+ //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN
+ sizeof(GMouse),
+ _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
+ },
+ 1, // z_max
+ 0, // z_min
+ 1, // z_touchon
+ 0, // z_touchoff
+ { // pen_jitter
+ 0, // calibrate
+ 0, // click
+ 0 // move
+ },
+ { // finger_jitter
+ 0, // calibrate
+ 2, // click
+ 2 // move
+ },
+ NMouseInit, // init
+ 0, // deinit
+ NMouseRead, // get
+ 0, // calsave
+ 0 // calload
+ }};
+#endif
+
#if GNETCODE_VERSION != GNETCODE_VERSION_1_0
#error "GDISP: uGFXnet - This driver only support protocol V1.0"
#endif
@@ -98,14 +140,8 @@
#endif
#endif
-#define GDISP_FLG_HASMOUSE (GDISP_FLG_DRIVER<<0)
-#define GDISP_FLG_CONNECTED (GDISP_FLG_DRIVER<<1)
-#define GDISP_FLG_HAVEDATA (GDISP_FLG_DRIVER<<2)
-
-#if GINPUT_NEED_MOUSE
- /* Include mouse support code */
- #include "src/ginput/driver_mouse.h"
-#endif
+#define GDISP_FLG_CONNECTED (GDISP_FLG_DRIVER<<0)
+#define GDISP_FLG_HAVEDATA (GDISP_FLG_DRIVER<<1)
/*===========================================================================*/
/* Driver local routines . */
@@ -118,15 +154,12 @@ typedef struct netPriv {
#if GINPUT_NEED_MOUSE
coord_t mousex, mousey;
uint16_t mousebuttons;
+ GMouse * mouse;
#endif
} netPriv;
static gfxThreadHandle hThread;
-#if GINPUT_NEED_MOUSE
- static GDisplay * mouseDisplay;
-#endif
-
#if GDISP_GFXNET_UNSAFE_SOCKETS
static gfxMutex uGFXnetMutex;
#define MUTEX_INIT gfxMutexInit(&uGFXnetMutex)
@@ -156,15 +189,134 @@ static bool_t sendpkt(SOCKET_TYPE netfd, uint16_t *pkt, int len) {
return send(netfd, (const char *)pkt, len, 0) == len;
}
+static bool_t newconnection(SOCKET_TYPE clientfd) {
+ GDisplay * g;
+ netPriv * priv;
+
+ // Look for a display that isn't connected
+ for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
+ // Ignore displays for other controllers
+ #ifdef GDISP_DRIVER_LIST
+ if (gvmt(g) != &GDISPVMT_uGFXnet)
+ continue;
+ #endif
+ if (!(g->flags & GDISP_FLG_CONNECTED))
+ break;
+ }
+
+ // Was anything found?
+ if (!g)
+ return FALSE;
+
+ // Reset the priv area
+ priv = g->priv;
+ priv->netfd = clientfd;
+ priv->databytes = 0;
+ priv->mousebuttons = 0;
+
+ // Send the initialisation data (2 words at a time)
+ priv->data[0] = GNETCODE_INIT;
+ priv->data[1] = GNETCODE_VERSION;
+ sendpkt(priv->netfd, priv->data, 2);
+ priv->data[0] = GDISP_SCREEN_WIDTH;
+ priv->data[1] = GDISP_SCREEN_HEIGHT;
+ sendpkt(priv->netfd, priv->data, 2);
+ priv->data[0] = GDISP_LLD_PIXELFORMAT;
+ priv->data[1] = 1; // We have a mouse
+ MUTEX_ENTER;
+ sendpkt(priv->netfd, priv->data, 2);
+ MUTEX_EXIT;
+
+ // The display is now working
+ g->flags |= GDISP_FLG_CONNECTED;
+
+ // Send a redraw all
+ #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
+ gdispGClear(g, gwinGetDefaultBgColor());
+ gwinRedrawDisplay(g, FALSE);
+ #endif
+
+ return TRUE;
+}
+
+static bool_t rxdata(SOCKET_TYPE fd) {
+ GDisplay * g;
+ netPriv * priv;
+ int len;
+
+ // Look for a display that is connected and the socket descriptor matches
+ for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
+ // Ignore displays for other controllers
+ #ifdef GDISP_DRIVER_LIST
+ if (gvmt(g) != &GDISPVMT_uGFXnet)
+ continue;
+ #endif
+ priv = g->priv;
+ if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == fd)
+ break;
+ }
+ if (!g)
+ gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection");
+
+ if ((g->flags & GDISP_FLG_HAVEDATA)) {
+ // The higher level is still processing the previous data.
+ // Give it a chance to run by coming back to this data.
+ gfxSleepMilliseconds(1);
+ return TRUE;
+ }
+
+ /* handle data from a client */
+ MUTEX_ENTER;
+ if ((len = recv(fd, ((char *)priv->data)+priv->databytes, sizeof(priv->data)-priv->databytes, 0)) <= 0) {
+ // Socket closed or in error state
+ MUTEX_EXIT;
+ g->flags &= ~GDISP_FLG_CONNECTED;
+ return FALSE;
+ }
+ MUTEX_EXIT;
+
+ // Do we have a full reply yet
+ priv->databytes += len;
+ if (priv->databytes < sizeof(priv->data))
+ return TRUE;
+ priv->databytes = 0;
+
+ // Convert network byte or to host byte order
+ priv->data[0] = ntohs(priv->data[0]);
+ priv->data[1] = ntohs(priv->data[1]);
+
+ // Process the data received
+ switch(priv->data[0]) {
+ #if GINPUT_NEED_MOUSE
+ case GNETCODE_MOUSE_X: priv->mousex = priv->data[1]; break;
+ case GNETCODE_MOUSE_Y: priv->mousey = priv->data[1]; break;
+ case GNETCODE_MOUSE_B:
+ priv->mousebuttons = priv->data[1];
+ // Treat the button event as the sync signal
+ _gmouseWakeup(priv->mouse);
+ break;
+ #endif
+ case GNETCODE_CONTROL:
+ case GNETCODE_READ:
+ g->flags |= GDISP_FLG_HAVEDATA;
+ break;
+ case GNETCODE_KILL:
+ gfxHalt("GDISP: uGFXnet - Display sent KILL command");
+ break;
+
+ default:
+ // Just ignore unrecognised data
+ break;
+ }
+ return TRUE;
+}
+
static DECLARE_THREAD_STACK(waNetThread, 512);
static DECLARE_THREAD_FUNCTION(NetThread, param) {
SOCKET_TYPE listenfd, fdmax, i, clientfd;
socklen_t len;
- int leni;
fd_set master, read_fds;
struct sockaddr_in addr;
- GDisplay * g;
- netPriv * priv;
(void)param;
// Start the sockets layer
@@ -197,25 +349,13 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) {
fdmax = listenfd; /* so far, it's this one*/
#if GDISP_GFXNET_BROKEN_LWIP_ACCEPT
- {
#warning "Using GDISP_GFXNET_BROKEN_LWIP_ACCEPT limits the number of displays and the use of GFXNET. Avoid if possible!"
len = sizeof(addr);
if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1)
gfxHalt("GDISP: uGFXnet - Accept failed");
+ //printf("New connection from %s on socket %d\n", inet_ntoa(addr.sin_addr), clientfd);
- // Look for a display that isn't connected
- for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
- // Ignore displays for other controllers
- #ifdef GDISP_DRIVER_LIST
- if (gvmt(g) != &GDISPVMT_uGFXnet)
- continue;
- #endif
- if (!(g->flags & GDISP_FLG_CONNECTED))
- break;
- }
-
- // Was anything found?
- if (!g) {
+ if (!newconnection(clientfd)) {
// No Just close the connection
closesocket(clientfd);
gfxHalt("GDISP: uGFXnet - Can't find display for connection");
@@ -225,33 +365,6 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) {
// Save the descriptor
FD_SET(clientfd, &master);
if (clientfd > fdmax) fdmax = clientfd;
- priv = g->priv;
- memset(priv, 0, sizeof(netPriv));
- priv->netfd = clientfd;
- //printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1);
-
- // Send the initialisation data (2 words at a time)
- priv->data[0] = GNETCODE_INIT;
- priv->data[1] = GNETCODE_VERSION;
- sendpkt(priv->netfd, priv->data, 2);
- priv->data[0] = GDISP_SCREEN_WIDTH;
- priv->data[1] = GDISP_SCREEN_HEIGHT;
- sendpkt(priv->netfd, priv->data, 2);
- priv->data[0] = GDISP_LLD_PIXELFORMAT;
- priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0;
- MUTEX_ENTER;
- sendpkt(priv->netfd, priv->data, 2);
- MUTEX_EXIT;
-
- // The display is now working
- g->flags |= GDISP_FLG_CONNECTED;
-
- // Send a redraw all
- #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
- gdispGClear(g, gwinGetDefaultBgColor());
- gwinRedrawDisplay(g, FALSE);
- #endif
- }
#endif
/* loop */
@@ -268,132 +381,33 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) {
// Handle new connections
if(i == listenfd) {
+
+ // Accept the connection
len = sizeof(addr);
if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1)
gfxHalt("GDISP: uGFXnet - Accept failed");
+ //printf("New connection from %s on socket %d\n", inet_ntoa(addr.sin_addr), clientfd);
+
+ // Can we handle it?
+ if (!newconnection(clientfd)) {
- // Look for a display that isn't connected
- for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
- // Ignore displays for other controllers
- #ifdef GDISP_DRIVER_LIST
- if (gvmt(g) != &GDISPVMT_uGFXnet)
- continue;
- #endif
- if (!(g->flags & GDISP_FLG_CONNECTED))
- break;
- }
-
- // Was anything found?
- if (!g) {
- // No Just close the connection
+ // No - Just close the connection
closesocket(clientfd);
- //printf(New connection from %s on socket %d rejected as all displays are already connected\n", inet_ntoa(addr.sin_addr), clientfd);
+
+ //printf("Rejected connection as all displays are already connected\n");
continue;
}
// Save the descriptor
FD_SET(clientfd, &master);
if (clientfd > fdmax) fdmax = clientfd;
- priv = g->priv;
- memset(priv, 0, sizeof(netPriv));
- priv->netfd = clientfd;
- //printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1);
-
- // Send the initialisation data (2 words at a time)
- priv->data[0] = GNETCODE_INIT;
- priv->data[1] = GNETCODE_VERSION;
- sendpkt(priv->netfd, priv->data, 2);
- priv->data[0] = GDISP_SCREEN_WIDTH;
- priv->data[1] = GDISP_SCREEN_HEIGHT;
- sendpkt(priv->netfd, priv->data, 2);
- priv->data[0] = GDISP_LLD_PIXELFORMAT;
- priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0;
- MUTEX_ENTER;
- sendpkt(priv->netfd, priv->data, 2);
- MUTEX_EXIT;
-
- // The display is now working
- g->flags |= GDISP_FLG_CONNECTED;
-
- // Send a redraw all
- #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
- gdispGClear(g, gwinGetDefaultBgColor());
- gwinRedrawDisplay(g, FALSE);
- #endif
-
continue;
}
// Handle data from a client
-
- // Look for a display that is connected and the socket descriptor matches
- for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
- // Ignore displays for other controllers
- #ifdef GDISP_DRIVER_LIST
- if (gvmt(g) != &GDISPVMT_uGFXnet)
- continue;
- #endif
- priv = g->priv;
- if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == i)
- break;
- }
- if (!g)
- gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection");
-
- if ((g->flags & GDISP_FLG_HAVEDATA)) {
- // The higher level is still processing the previous data.
- // Give it a chance to run by coming back to this data.
- gfxSleepMilliseconds(1);
- continue;
- }
-
- /* handle data from a client */
- MUTEX_ENTER;
- if ((leni = recv(i, ((char *)priv->data)+priv->databytes, sizeof(priv->data)-priv->databytes, 0)) <= 0) {
- // Socket closed or in error state
- MUTEX_EXIT;
- g->flags &= ~GDISP_FLG_CONNECTED;
- memset(priv, 0, sizeof(netPriv));
+ if (!rxdata(i)) {
closesocket(i);
- FD_CLR(i, &master);
- continue;
- }
- MUTEX_EXIT;
-
- // Do we have a full reply yet
- priv->databytes += leni;
- if (priv->databytes < sizeof(priv->data))
- continue;
- priv->databytes = 0;
-
- // Convert network byte or to host byte order
- priv->data[0] = ntohs(priv->data[0]);
- priv->data[1] = ntohs(priv->data[1]);
-
- // Process the data received
- switch(priv->data[0]) {
- #if GINPUT_NEED_MOUSE
- case GNETCODE_MOUSE_X: priv->mousex = priv->data[1]; break;
- case GNETCODE_MOUSE_Y: priv->mousey = priv->data[1]; break;
- case GNETCODE_MOUSE_B:
- priv->mousebuttons = priv->data[1];
- // Treat the button event as the sync signal
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
- break;
- #endif
- case GNETCODE_CONTROL:
- case GNETCODE_READ:
- g->flags |= GDISP_FLG_HAVEDATA;
- break;
- case GNETCODE_KILL:
- gfxHalt("GDISP: uGFXnet - Display sent KILL command");
- break;
-
- default:
- // Just ignore unrecognised data
- break;
+ FD_CLR(clientfd, &master);
}
}
}
@@ -414,14 +428,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
gfxThreadClose(hThread);
}
- // Only turn on mouse on the first window for now
- #if GINPUT_NEED_MOUSE
- if (!g->controllerdisplay) {
- mouseDisplay = g;
- g->flags |= GDISP_FLG_HASMOUSE;
- }
- #endif
-
// Create a private area for this window
if (!(priv = gfxAlloc(sizeof(netPriv))))
gfxHalt("GDISP: uGFXnet - Memory allocation failed");
@@ -429,6 +435,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
g->priv = priv;
g->board = 0; // no board interface for this controller
+ // Create the associated mouse
+ #if GINPUT_NEED_MOUSE
+ priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
+ #endif
+
// Initialise the GDISP structure
g->g.Orientation = GDISP_ROTATE_0;
g->g.Powermode = powerOn;
@@ -694,17 +705,21 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
#if GINPUT_NEED_MOUSE
- void ginput_lld_mouse_init(void) {}
- void ginput_lld_mouse_get_reading(MouseReading *pt) {
+ static bool_t NMouseInit(GMouse *m, unsigned driverinstance) {
+ (void) m;
+ (void) driverinstance;
+ return TRUE;
+ }
+ static void NMouseRead(GMouse *m, GMouseReading *pt) {
GDisplay * g;
netPriv * priv;
- g = mouseDisplay;
+ g = m->display;
priv = g->priv;
pt->x = priv->mousex;
pt->y = priv->mousey;
- pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
+ pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0;
pt->buttons = priv->mousebuttons;
}
#endif /* GINPUT_NEED_MOUSE */