aboutsummaryrefslogtreecommitdiffstats
path: root/src/ginput
diff options
context:
space:
mode:
Diffstat (limited to 'src/ginput')
-rw-r--r--src/ginput/dial.c2
-rw-r--r--src/ginput/dial.h111
-rw-r--r--src/ginput/driver_dial.h45
-rw-r--r--src/ginput/driver_mouse.h178
-rw-r--r--src/ginput/driver_toggle.h61
-rw-r--r--src/ginput/keyboard.h128
-rw-r--r--src/ginput/mouse.c2
-rw-r--r--src/ginput/mouse.h181
-rw-r--r--src/ginput/sys_defs.h50
-rw-r--r--src/ginput/sys_make.mk (renamed from src/ginput/ginput.mk)10
-rw-r--r--src/ginput/sys_options.h114
-rw-r--r--src/ginput/sys_rules.h37
-rw-r--r--src/ginput/toggle.c2
-rw-r--r--src/ginput/toggle.h100
14 files changed, 1013 insertions, 8 deletions
diff --git a/src/ginput/dial.c b/src/ginput/dial.c
index a9d1858c..410efc1a 100644
--- a/src/ginput/dial.c
+++ b/src/ginput/dial.c
@@ -17,7 +17,7 @@
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL
-#include "ginput/lld/dial.h"
+#include "src/ginput/driver_dial.h"
static GTIMER_DECL(DialTimer);
static struct DialStatus_t {
diff --git a/src/ginput/dial.h b/src/ginput/dial.h
new file mode 100644
index 00000000..a90b5e46
--- /dev/null
+++ b/src/ginput/dial.h
@@ -0,0 +1,111 @@
+/*
+ * 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
+ */
+
+/**
+ * @file include/ginput/dial.h
+ * @brief GINPUT GFX User Input subsystem header file.
+ *
+ * @defgroup Dial Dial
+ * @ingroup GINPUT
+ *
+ * @details A dial provides a powerful way to navigate through menus
+ * on a display.
+ *
+ * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h
+ * @pre GINPUT_NEED_DIAL must be set to TRUE in your gfxconf.h
+ *
+ * @{
+ */
+#ifndef _GINPUT_DIAL_H
+#define _GINPUT_DIAL_H
+
+#if GINPUT_NEED_DIAL || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+// Event types for various ginput sources
+#define GEVENT_DIAL (GEVENT_GINPUT_FIRST+4)
+
+typedef struct GEventDial_t {
+ GEventType type; // The type of this event (GEVENT_DIAL)
+ uint16_t instance; // The dial instance
+ uint16_t value; // The dial value
+ uint16_t maxvalue; // The maximum dial value
+ } GEventDial;
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Create a dial input instance
+ *
+ * @param[in] instance The ID of the dial input instance (from 0 to 9999)
+ *
+ * @return The soure handle of the created dial instance
+ */
+ GSourceHandle ginputGetDial(uint16_t instance);
+
+ /**
+ * @brief Reset the value back to the hardware default
+ *
+ * @param[in] instance The ID of the dial input instance
+ */
+ void ginputResetDialRange(uint16_t instance);
+
+ /**
+ * @brief Get the maximum value
+ * @details The readings are scaled to be 0 ... max.
+ *
+ * @param[in] instance The ID of the dial input instance
+ *
+ * @return The maximum value
+ */
+ uint16_t ginputGetDialRange(uint16_t instance);
+
+ /**
+ * @brief Set the maximum value
+ * @details The readings are scaled to be 0 ... max.
+ *
+ * @param[in] instance The ID of the dial input instance
+ * @param[in] max The maximum value to be set
+ */
+ void ginputSetDialRange(uint16_t instance, uint16_t max);
+
+ /**
+ * @brief Set the level change required before a dial even is generated (threshold)
+ * @note This is done after range scaling
+ *
+ * @param[in] instance The ID of the dial input instance
+ * @param[in] diff The amount of level changes
+ */
+ void ginputSetDialSensitivity(uint16_t instance, uint16_t diff);
+
+ /**
+ * @brief Get the current dial status
+ *
+ * @param[in] instance The ID of the dial input instance
+ * @param[in] pdial The dial event struct
+ *
+ * @return Returns FALSE on an error (eg invalid instance)
+ */
+ bool_t ginputGetDialStatus(uint16_t instance, GEventDial *pdial);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GINPUT_NEED_DIAL */
+
+#endif /* _GINPUT_DIAL_H */
+/** @} */
diff --git a/src/ginput/driver_dial.h b/src/ginput/driver_dial.h
new file mode 100644
index 00000000..bf01da20
--- /dev/null
+++ b/src/ginput/driver_dial.h
@@ -0,0 +1,45 @@
+/*
+ * 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
+ */
+
+/**
+ * @file src/ginput/driver_dial.h
+ * @brief GINPUT header file for dial drivers.
+ *
+ * @defgroup Dial Dial
+ * @ingroup GINPUT
+ * @{
+ */
+
+#ifndef _LLD_GINPUT_DIAL_H
+#define _LLD_GINPUT_DIAL_H
+
+#if GINPUT_NEED_DIAL || defined(__DOXYGEN__)
+
+#include "ginput_lld_dial_config.h"
+
+typedef void (*DialCallbackFn)(uint16_t instance, uint16_t rawvalue);
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void ginput_lld_dial_init(void);
+ void ginput_lld_dial_poll(DialCallbackFn fn);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_TOGGLE */
+
+#endif /* _LLD_GINPUT_TOGGLE_H */
+/** @} */
+
diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h
new file mode 100644
index 00000000..21d87dac
--- /dev/null
+++ b/src/ginput/driver_mouse.h
@@ -0,0 +1,178 @@
+/*
+ * 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
+ */
+
+/**
+ * @file src/ginput/driver_mouse.h
+ * @brief GINPUT LLD header file for mouse/touch drivers.
+ *
+ * @defgroup Mouse Mouse
+ * @ingroup GINPUT
+ * @{
+ */
+
+#ifndef _LLD_GINPUT_MOUSE_H
+#define _LLD_GINPUT_MOUSE_H
+
+#if GINPUT_NEED_MOUSE || defined(__DOXYGEN__)
+
+#include "ginput_lld_mouse_config.h"
+
+// GEVENT_MOUSE or GEVENT_TOUCH - What type of device is this.
+#ifndef GINPUT_MOUSE_EVENT_TYPE
+ #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE
+#endif
+
+// TRUE/FALSE - Does the mouse/touch driver require calibration?
+#ifndef GINPUT_MOUSE_NEED_CALIBRATION
+ #define GINPUT_MOUSE_NEED_CALIBRATION FALSE
+#endif
+
+// TRUE/FALSE - Should the calibration happen at the extremes of the panel?
+#ifndef GINPUT_MOUSE_CALIBRATE_EXTREMES
+ #define GINPUT_MOUSE_CALIBRATE_EXTREMES FALSE
+#endif
+
+// TRUE/FALSE - Can the mouse/touch driver itself save calibration data?
+#ifndef GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE
+ #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
+#endif
+
+// n or -1 - n means to test calibration result (+/- pixels), -1 means not to.
+#ifndef GINPUT_MOUSE_MAX_CALIBRATION_ERROR
+ #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1
+#endif
+
+// n - How many times to read (and average) per poll
+#ifndef GINPUT_MOUSE_READ_CYCLES
+ #define GINPUT_MOUSE_READ_CYCLES 1
+#endif
+
+// n - Millisecs between poll's
+#ifndef GINPUT_MOUSE_POLL_PERIOD
+ #define GINPUT_MOUSE_POLL_PERIOD 25
+#endif
+
+// n - Movement allowed without discarding the CLICK or CLICKCXT event (+/- pixels)
+#ifndef GINPUT_MOUSE_MAX_CLICK_JITTER
+ #define GINPUT_MOUSE_MAX_CLICK_JITTER 1
+#endif
+
+// n - Movement allowed without discarding the MOVE event (+/- pixels)
+#ifndef GINPUT_MOUSE_MAX_MOVE_JITTER
+ #define GINPUT_MOUSE_MAX_MOVE_JITTER 0
+#endif
+
+// ms - Millisecs seperating a CLICK from a CXTCLICK
+#ifndef GINPUT_MOUSE_CLICK_TIME
+ #define GINPUT_MOUSE_CLICK_TIME 700
+#endif
+
+// true/false - Whether the mouse driver internally handles screen rotation
+#ifndef GINPUT_MOUSE_NO_ROTATION
+ #define GINPUT_MOUSE_NO_ROTATION FALSE
+#endif
+
+typedef struct MouseReading_t {
+ coord_t x, y, z;
+ uint16_t buttons;
+ } MouseReading;
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Initialise the mouse/touch.
+ *
+ * @notapi
+ */
+ void ginput_lld_mouse_init(void);
+
+ /**
+ * @brief Read the mouse/touch position.
+ *
+ * @param[in] pt A pointer to the structure to fill
+ *
+ * @note For drivers that don't support returning a position
+ * when the touch is up (most touch devices), it should
+ * return the previous position with the new Z value.
+ * The z value is the pressure for those touch devices
+ * that support it (-100 to 100 where > 0 is touched)
+ * or, 0 or 100 for those drivers that don't.
+ *
+ * @notapi
+ */
+ void ginput_lld_mouse_get_reading(MouseReading *pt);
+
+ #if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE
+ /**
+ * @brief Load calibration data from a storage area on the touch controller.
+ *
+ * @param[in] instance The mouse instance number
+ *
+ * @note The instance parameter is currently always 0 as we only support
+ * one mouse/touch device at a time.
+ * @note This routine should only be provided if the driver has its own
+ * storage area where calibration data can be stored. The drivers
+ * option.h file should define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE = TRUE
+ * if it supports this.
+ *
+ * @notapi
+ */
+ const char *ginput_lld_mouse_calibration_load(uint16_t instance);
+ /**
+ * @brief Save calibration data to a storage area on the touch controller.
+ *
+ * @param[in] instance The mouse instance number
+ * @param[in] calbuf The calibration data to be saved
+ * @param[in] sz The size of the calibration data
+ *
+ * @note The instance parameter is currently always 0 as we only support
+ * one mouse/touch device at a time.
+ * @note This routine should only be provided if the driver has its own
+ * storage area where calibration data can be stored. The drivers
+ * option.h file should define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE = TRUE
+ * if it supports this.
+ *
+ * @notapi
+ */
+ void ginput_lld_mouse_calibration_save(uint16_t instance, const uint8_t *calbuf, size_t sz);
+ #endif
+
+ /**
+ * @brief Wakeup the high level code so that it attempts another read
+ *
+ * @note This routine is provided to low level drivers by the high level code
+ * @note Particularly useful if GINPUT_MOUSE_POLL_PERIOD = TIME_INFINITE
+ *
+ * @notapi
+ */
+ void ginputMouseWakeup(void);
+
+ /**
+ * @brief Wakeup the high level code so that it attempts another read
+ *
+ * @note This routine is provided to low level drivers by the high level code
+ * @note Particularly useful if GINPUT_MOUSE_POLL_PERIOD = TIME_INFINITE
+ *
+ * @iclass
+ * @notapi
+ */
+ void ginputMouseWakeupI(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GINPUT_NEED_MOUSE || GINPUT_NEED_TOUCH */
+
+#endif /* _LLD_GINPUT_MOUSE_H */
+/** @} */
diff --git a/src/ginput/driver_toggle.h b/src/ginput/driver_toggle.h
new file mode 100644
index 00000000..6d672c91
--- /dev/null
+++ b/src/ginput/driver_toggle.h
@@ -0,0 +1,61 @@
+/*
+ * 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
+ */
+
+/**
+ * @file src/ginput/driver_toggle.h
+ * @brief GINPUT header file for toggle drivers.
+ *
+ * @defgroup Toggle Toggle
+ * @ingroup GINPUT
+ * @{
+ */
+
+#ifndef _LLD_GINPUT_TOGGLE_H
+#define _LLD_GINPUT_TOGGLE_H
+
+#if GINPUT_NEED_TOGGLE || defined(__DOXYGEN__)
+
+// Describes how the toggle bits are obtained
+typedef struct GToggleConfig_t {
+ void *id;
+ unsigned mask;
+ unsigned invert;
+ unsigned mode;
+} GToggleConfig;
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ extern const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES];
+
+ void ginput_lld_toggle_init(const GToggleConfig *ptc);
+ unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc);
+
+ /* This routine is provided to low level drivers to wakeup a value read from a thread context.
+ * Particularly useful if GINPUT_TOGGLE_POLL_PERIOD = TIME_INFINITE
+ */
+ void ginputToggleWakeup(void);
+
+ /* This routine is provided to low level drivers to wakeup a value read from an ISR
+ * Particularly useful if GINPUT_TOGGLE_POLL_PERIOD = TIME_INFINITE
+ */
+ void ginputToggleWakeupI(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_TOGGLE */
+
+#endif /* _LLD_GINPUT_TOGGLE_H */
+/** @} */
+
diff --git a/src/ginput/keyboard.h b/src/ginput/keyboard.h
new file mode 100644
index 00000000..d2bebeb8
--- /dev/null
+++ b/src/ginput/keyboard.h
@@ -0,0 +1,128 @@
+/*
+ * 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
+ */
+
+/**
+ * @file include/ginput/keyboard.h
+ * @brief GINPUT GFX User Input subsystem header file.
+ *
+ * @defgroup Keyboard Keyboard
+ * @ingroup GINPUT
+ * @{
+ */
+
+#ifndef _GINPUT_KEYBOARD_H
+#define _GINPUT_KEYBOARD_H
+
+#if GINPUT_NEED_KEYBOARD || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+#define GINPUT_KEYBOARD_NUM_PORTS 1 // The total number of keyboard inputs
+
+// Event types for various ginput sources
+#define GEVENT_KEYBOARD (GEVENT_GINPUT_FIRST+2)
+
+typedef struct GEventKeyboard_t {
+ GEventType type; // The type of this event (GEVENT_KEYBOARD)
+ uint16_t instance; // The keyboard instance
+ char c; // The Ascii code for the current key press.
+ // The only possible values are 0(NUL), 8(BS), 9(TAB), 13(CR), 27(ESC), 32(SPACE) to 126(~), 127(DEL)
+ // 0 indicates an extended only key.
+ uint16_t code; // An extended keyboard code. Codes less than 128 match their ascii equivelent.
+ #define GKEY_NULL 0
+ #define GKEY_BACKSPACE 8
+ #define GKEY_TAB 9
+ #define GKEY_CR 13
+ #define GKEY_ESC 27
+ #define GKEY_SPACE 32
+ #define GKEY_DEL 127
+ #define GKEY_UP 0x0101
+ #define GKEY_DOWN 0x0102
+ #define GKEY_LEFT 0x0103
+ #define GKEY_RIGHT 0x0104
+ #define GKEY_HOME 0x0105
+ #define GKEY_END 0x0106
+ #define GKEY_PAGEUP 0x0107
+ #define GKEY_PAGEDOWN 0x0108
+ #define GKEY_INSERT 0x0109
+ #define GKEY_DELETE 0x010A
+ #define GKEY_SHIFT 0x0201
+ #define GKEY_CNTRL 0x0202
+ #define GKEY_ALT 0x0203
+ #define GKEY_WINKEY 0x0204
+ #define GKEY_RCLKEY 0x0205
+ #define GKEY_FNKEY 0x0206
+ #define GKEY_FN1 0x0301
+ #define GKEY_FN2 0x0302
+ #define GKEY_FN3 0x0303
+ #define GKEY_FN4 0x0304
+ #define GKEY_FN5 0x0305
+ #define GKEY_FN6 0x0306
+ #define GKEY_FN7 0x0307
+ #define GKEY_FN8 0x0308
+ #define GKEY_FN9 0x0309
+ #define GKEY_FN10 0x030A
+ #define GKEY_FN11 0x030B
+ #define GKEY_FN12 0x030C
+ uint16_t current_buttons; // A bit is set to indicate various meta status.
+ #define GMETA_KEY_DOWN 0x0001
+ #define GMETA_KEY_SHIFT 0x0002
+ #define GMETA_KEY_CNTRL 0x0004
+ #define GMETA_KEY_ALT 0x0008
+ #define GMETA_KEY_WINKEY 0x0010
+ #define GMETA_KEY_RCLKKEY 0x0020
+ #define GMETA_KEY_FN 0x0040
+ #define GMETA_KEY_MISSED_EVENT 0x8000
+ uint16_t last_buttons; // The value of current_buttons on the last event
+} GEventKeyboard;
+
+// Keyboard Listen Flags - passed to geventAddSourceToListener()
+#define GLISTEN_KEYREPEATS 0x0001 // Return key repeats (where the key is held down to get a repeat character)
+#define GLISTEN_KEYCODES 0x0002 // Return all key presses including extended code key presses (not just ascii codes)
+#define GLISTEN_KEYALL 0x0004 // Return keyup's, keydown's and everything in between (but not repeats unless GLISTEN_KEYREPEATS is set).
+#define GLISTEN_KEYSINGLE 0x8000 // Return only when one particular extended code key is pressed or released. The particular extended code is OR'd into this value
+ // eg. (GLISTEN_KEYSINGLE | GKEY_CR)
+ // No other flags may be set with this flag.
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Create a keyboard input instance
+ *
+ * @param[in] instance The ID of the keyboard input instance (from 0 to 9999)
+ *
+ * @return The source handle of the created input instance
+ */
+ GSourceHandle ginputGetKeyboard(uint16_t instance);
+
+ /**
+ * @brief Get the current keyboard status
+ *
+ * @param[in] instance The ID of the keyboard input instance
+ * @param[in] pkeyboard The keyboard event struct
+ *
+ * @return Returns FALSE on an error (eg invalid instance)
+ */
+ bool_t ginputGetKeyboardStatus(uint16_t instance, GEventKeyboard *pkeyboard);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GINPUT_NEED_KEYBOARD */
+
+#endif /* _GINPUT_KEYBOARD_H */
+/** @} */
+
diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c
index aad6119a..c7a20ec1 100644
--- a/src/ginput/mouse.c
+++ b/src/ginput/mouse.c
@@ -17,7 +17,7 @@
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__)
-#include "ginput/lld/mouse.h"
+#include "src/ginput/driver_mouse.h"
#if GINPUT_MOUSE_NEED_CALIBRATION
#if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP
diff --git a/src/ginput/mouse.h b/src/ginput/mouse.h
new file mode 100644
index 00000000..669eaec6
--- /dev/null
+++ b/src/ginput/mouse.h
@@ -0,0 +1,181 @@
+/*
+ * 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
+ */
+
+/**
+ * @file include/ginput/mouse.h
+ * @brief GINPUT GFX User Input subsystem header file for mouse and touch.
+ *
+ * @defgroup Mouse Mouse
+ * @ingroup GINPUT
+ *
+ * @details GINPUT allows it to easily interface touchscreens and mices to
+ * your application.
+ *
+ * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h
+ * @pre GINPUT_NEED_MOUSE must be set to TRUE in your gfxconf.h
+ *
+ * @{
+ */
+
+#ifndef _GINPUT_MOUSE_H
+#define _GINPUT_MOUSE_H
+
+#if GINPUT_NEED_MOUSE || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+/* This type definition is also used by touch */
+typedef struct GEventMouse_t {
+ GEventType type; // The type of this event (GEVENT_MOUSE or GEVENT_TOUCH)
+ uint16_t instance; // The mouse/touch instance
+ coord_t x, y, z; // The position of the mouse.
+ // - For touch devices, Z is the current pressure if supported (otherwise 0)
+ // - For mice, Z is the 3rd dimension if supported (otherwise 0)
+ uint16_t current_buttons; // A bit is set if the button is down.
+ // - For touch only bit 0 is relevant
+ // - For mice the order of the buttons is (from 0 to n) left, right, middle, any other buttons
+ // - Bit 15 being set indicates that an important mouse event has been missed.
+ #define GINPUT_MOUSE_BTN_LEFT 0x0001
+ #define GINPUT_MOUSE_BTN_RIGHT 0x0002
+ #define GINPUT_MOUSE_BTN_MIDDLE 0x0004
+ #define GINPUT_MOUSE_BTN_4 0x0008
+ #define GINPUT_MISSED_MOUSE_EVENT 0x8000
+ #define GINPUT_TOUCH_PRESSED GINPUT_MOUSE_BTN_LEFT
+ uint16_t last_buttons; // The value of current_buttons on the last event
+ enum GMouseMeta_e {
+ GMETA_NONE = 0, // There is no meta event currently happening
+ GMETA_MOUSE_DOWN = 1, // Button 0 has just gone down
+ GMETA_MOUSE_UP = 2, // Button 0 has just gone up
+ GMETA_MOUSE_CLICK = 4, // Button 0 has just gone through a short down - up cycle
+ GMETA_MOUSE_CXTCLICK = 8 // For mice - The right button has just been depressed
+ // For touch - a long press has just occurred
+ } meta;
+ GDisplay * display; // The display this mouse is currently associated with.
+ } GEventMouse;
+
+// Mouse/Touch Listen Flags - passed to geventAddSourceToListener()
+#define GLISTEN_MOUSEMETA 0x0001 // Create events for meta events such as CLICK and CXTCLICK
+#define GLISTEN_MOUSEDOWNMOVES 0x0002 // Creates mouse move events when the primary mouse button is down (touch is on the surface)
+#define GLISTEN_MOUSEUPMOVES 0x0004 // Creates mouse move events when the primary mouse button is up (touch is off the surface - if the hardware allows).
+#define GLISTEN_MOUSENOFILTER 0x0008 // Don't filter out mouse moves where the position hasn't changed.
+#define GLISTEN_TOUCHMETA GLISTEN_MOUSEMETA
+#define GLISTEN_TOUCHDOWNMOVES GLISTEN_MOUSEDOWNMOVES
+#define GLISTEN_TOUCHUPMOVES GLISTEN_MOUSEUPMOVES
+#define GLISTEN_TOUCHNOFILTER GLISTEN_MOUSENOFILTER
+
+#define GINPUT_MOUSE_NUM_PORTS 1 // The total number of mouse/touch inputs supported
+
+// Event types for the mouse ginput source
+#define GEVENT_MOUSE (GEVENT_GINPUT_FIRST+0)
+#define GEVENT_TOUCH (GEVENT_GINPUT_FIRST+1)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Creates an instance of a mouse and returns the Source handler
+ * @note HACK: if the instance is 9999, it is treated as instance 0 except
+ * that no calibration will be performed!
+ *
+ * @param[in] instance The ID of the mouse input instance (from 0 to 9999)
+ *
+ * @return The source handle of the created instance
+ */
+ GSourceHandle ginputGetMouse(uint16_t instance);
+
+ /**
+ * @brief Assign the display associated with the mouse
+ * @note This only needs to be called if the mouse is associated with a display
+ * other than the current default display. It must be called before
+ * @p ginputGetMouse() if the new display is to be used during the calibration
+ * process. Other than calibration the display is used for range checking,
+ * and may also be used to display a mouse pointer.
+ *
+ * @param[in] instance The ID of the mouse input instance
+ * @param[in] g The GDisplay to which this mouse belongs
+ */
+ void ginputSetMouseDisplay(uint16_t instance, GDisplay *g);
+
+ /**
+ * @brief Get the display currently associated with the mouse
+ * @return A pointer to the display
+ *
+ * @param[in] instance The ID of the mouse input instance
+ */
+ GDisplay *ginputGetMouseDisplay(uint16_t instance);
+
+ /**
+ * @brief Get the current mouse position and button status
+ * @note Unlinke a listener event, this status cannot record meta events such as
+ * "CLICK".
+ *
+ * @param[in] instance The ID of the mouse input instance
+ * @param[in] pmouse The mouse event
+ *
+ * @return FALSE on an error (eg. invalid instance)
+ */
+ bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pmouse);
+
+ /**
+ * @brief Performs a calibration
+ *
+ * @param[in] instance The ID of the mouse input instance
+ *
+ * @return FALSE if the driver dosen't support a calibration of if the handle is invalid
+ */
+ bool_t ginputCalibrateMouse(uint16_t instance);
+
+ /* Set the routines to save and fetch calibration data.
+ * This function should be called before first calling ginputGetMouse() for a particular instance
+ * as the gdispGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it.
+ * If this is called after gdispGetMouse() has been called and the driver requires calibration storage, it will immediately save the data is has already obtained.
+ * The 'requireFree' parameter indicates if the fetch buffer must be free()'d to deallocate the buffer provided by the Fetch routine.
+ */
+ typedef void (*GMouseCalibrationSaveRoutine)(uint16_t instance, const uint8_t *calbuf, size_t sz); // Save calibration data
+ typedef const char * (*GMouseCalibrationLoadRoutine)(uint16_t instance); // Load calibration data (returns NULL if not data saved)
+
+ /**
+ * @brief Set the routines to store and restore calibration data
+ *
+ * @details This function should be called before first calling ginputGetMouse() for a particular instance
+ * as the gdispGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it.
+ * If this is called after gdispGetMouse() has been called and the driver requires calibration storage, it will immediately save the
+ * data is has already obtained.
+ *
+ * @param[in] instance The ID of the mouse input instance
+ * @param[in] fnsave The routine to save the data
+ * @param[in] fnload The routine to restore the data
+ * @param[in] requireFree TRUE if the buffer returned by the load function must be freed by the mouse code.
+ */
+ void ginputSetMouseCalibrationRoutines(uint16_t instance, GMouseCalibrationSaveRoutine fnsave, GMouseCalibrationLoadRoutine fnload, bool_t requireFree);
+
+ /**
+ * @brief Test if a particular mouse/touch instance requires routines to save it's alibration data
+ * @note Not implemented yet
+ *
+ * @param[in] instance The ID of the mouse input instance
+ *
+ * @return TRUE if needed
+ */
+ bool_t ginputRequireMouseCalibrationStorage(uint16_t instance);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GINPUT_NEED_MOUSE */
+
+#endif /* _GINPUT_MOUSE_H */
+/** @} */
+
diff --git a/src/ginput/sys_defs.h b/src/ginput/sys_defs.h
new file mode 100644
index 00000000..33259da4
--- /dev/null
+++ b/src/ginput/sys_defs.h
@@ -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
+ */
+
+/**
+ * @file src/ginput/sys_defs.h
+ *
+ * @addtogroup GINPUT
+ *
+ * @brief Module to interface different hardware input sources such as touchscreens
+ *
+ * @details GINPUT provides an easy and common interface to use different input devices
+ * such as touchscreens and mices.
+ *
+ * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h
+ *
+ * @{
+ */
+#ifndef _GINPUT_H
+#define _GINPUT_H
+
+#include "gfx.h"
+
+#if GFX_USE_GINPUT || defined(__DOXYGEN__)
+
+/* How to use...
+
+ 1. Get source handles for all the inputs you are interested in.
+ - Attempting to get a handle for one instance of an input more than once will return the same handle
+ 2. Create a listener
+ 3. Assign inputs to your listener.
+ - Inputs can be assigned or released from a listener at any time.
+ - An input can be assigned to more than one listener.
+ 4. Loop on getting listener events
+ 5. When complete destroy the listener
+*/
+
+// Include various ginput types
+#include "src/ginput/mouse.h"
+#include "src/ginput/keyboard.h"
+#include "src/ginput/toggle.h"
+#include "src/ginput/dial.h"
+
+#endif /* GFX_USE_GINPUT */
+
+#endif /* _GINPUT_H */
+/** @} */
diff --git a/src/ginput/ginput.mk b/src/ginput/sys_make.mk
index ed34d46d..34ac4a55 100644
--- a/src/ginput/ginput.mk
+++ b/src/ginput/sys_make.mk
@@ -1,5 +1,5 @@
-GFXSRC += $(GFXLIB)/src/ginput/ginput.c \
- $(GFXLIB)/src/ginput/mouse.c \
- $(GFXLIB)/src/ginput/keyboard.c \
- $(GFXLIB)/src/ginput/toggle.c \
- $(GFXLIB)/src/ginput/dial.c
+GFXSRC += $(GFXLIB)/src/ginput/ginput.c \
+ $(GFXLIB)/src/ginput/mouse.c \
+ $(GFXLIB)/src/ginput/keyboard.c \
+ $(GFXLIB)/src/ginput/toggle.c \
+ $(GFXLIB)/src/ginput/dial.c
diff --git a/src/ginput/sys_options.h b/src/ginput/sys_options.h
new file mode 100644
index 00000000..c606262b
--- /dev/null
+++ b/src/ginput/sys_options.h
@@ -0,0 +1,114 @@
+/*
+ * 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
+ */
+
+/**
+ * @file src/ginput/sys_options.h
+ * @brief GINPUT sub-system options header file.
+ *
+ * @addtogroup GINPUT
+ * @{
+ */
+
+#ifndef _GINPUT_OPTIONS_H
+#define _GINPUT_OPTIONS_H
+
+/**
+ * @name GINPUT Functionality to be included
+ * @{
+ */
+ /**
+ * @brief Should mouse/touch functions be included.
+ * @details Defaults to FALSE
+ * @note Also add the a mouse/touch hardware driver to your makefile.
+ * Eg.
+ * include $(GFXLIB)/drivers/ginput/touch/MCU/ginput_lld.mk
+ */
+ #ifndef GINPUT_NEED_MOUSE
+ #define GINPUT_NEED_MOUSE FALSE
+ #endif
+ /**
+ * @brief Should keyboard functions be included.
+ * @details Defaults to FALSE
+ * @note Also add the a keyboard hardware driver to your makefile.
+ * Eg.
+ * include $(GFXLIB)/drivers/ginput/keyboard/XXXX/ginput_lld.mk
+ */
+ #ifndef GINPUT_NEED_KEYBOARD
+ #define GINPUT_NEED_KEYBOARD FALSE
+ #endif
+ /**
+ * @brief Should hardware toggle/switch/button functions be included.
+ * @details Defaults to FALSE
+ * @note Also add the a toggle hardware driver to your makefile.
+ * Eg.
+ * include $(GFXLIB)/drivers/ginput/toggle/Pal/ginput_lld.mk
+ */
+ #ifndef GINPUT_NEED_TOGGLE
+ #define GINPUT_NEED_TOGGLE FALSE
+ #endif
+ /**
+ * @brief Should analog dial functions be included.
+ * @details Defaults to FALSE
+ * @note Also add the a dial hardware driver to your makefile.
+ * Eg.
+ * include $(GFXLIB)/drivers/ginput/dial/analog/ginput_lld.mk
+ */
+ #ifndef GINPUT_NEED_DIAL
+ #define GINPUT_NEED_DIAL FALSE
+ #endif
+/**
+ * @}
+ *
+ * @name GINPUT Optional Sizing Parameters
+ * @{
+ */
+/**
+ * @}
+ *
+ * @name GINPUT Optional Low Level Driver Defines
+ * @{
+ */
+ /**
+ * @brief Use a custom board definition for the mouse/touch driver even if a board definition exists.
+ * @details Defaults to FALSE
+ * @details If TRUE, add ginput_lld_mouse_board.h to your project directory and customise it.
+ * @note Not all GINPUT mouse/touch low level drivers use board definition files.
+ */
+ #ifndef GINPUT_MOUSE_USE_CUSTOM_BOARD
+ #define GINPUT_MOUSE_USE_CUSTOM_BOARD FALSE
+ #endif
+ /**
+ * @brief Use a custom board definition for the keyboard driver even if a board definition exists.
+ * @details Defaults to FALSE
+ * @details If TRUE, add ginput_lld_keyboard_board.h to your project directory and customise it.
+ * @note Not all GINPUT keyboard low level drivers use board definition files.
+ */
+ #ifndef GINPUT_KEYBOARD_USE_CUSTOM_BOARD
+ #define GINPUT_KEYBOARD_USE_CUSTOM_BOARD FALSE
+ #endif
+ /**
+ * @brief Use a custom board definition for the toggle driver even if a board definition exists.
+ * @details Defaults to FALSE
+ * @details If TRUE, add ginput_lld_toggle_board.h to your project directory and customise it.
+ * @note Not all GINPUT toggle low level drivers use board definition files.
+ */
+ #ifndef GINPUT_TOGGLE_USE_CUSTOM_BOARD
+ #define GINPUT_TOGGLE_USE_CUSTOM_BOARD FALSE
+ #endif
+ /**
+ * @brief Use a custom board definition for the dial driver even if a board definition exists.
+ * @details Defaults to FALSE
+ * @details If TRUE, add ginput_lld_dial_board.h to your project directory and customise it.
+ * @note Not all GINPUT dial low level drivers use board definition files.
+ */
+ #ifndef GINPUT_DIAL_USE_CUSTOM_BOARD
+ #define GINPUT_DIAL_USE_CUSTOM_BOARD FALSE
+ #endif
+/** @} */
+
+#endif /* _GINPUT_OPTIONS_H */
+/** @} */
diff --git a/src/ginput/sys_rules.h b/src/ginput/sys_rules.h
new file mode 100644
index 00000000..f98cc469
--- /dev/null
+++ b/src/ginput/sys_rules.h
@@ -0,0 +1,37 @@
+/*
+ * 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
+ */
+
+/**
+ * @file src/ginput/sys_rules.h
+ * @brief GINPUT safety rules header file.
+ *
+ * @addtogroup GINPUT
+ * @{
+ */
+
+#ifndef _GINPUT_RULES_H
+#define _GINPUT_RULES_H
+
+#if GFX_USE_GINPUT
+ #if !GFX_USE_GEVENT
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #endif
+ #undef GFX_USE_GEVENT
+ #define GFX_USE_GEVENT TRUE
+ #endif
+ #if !GFX_USE_GTIMER
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #endif
+ #undef GFX_USE_GTIMER
+ #define GFX_USE_GTIMER TRUE
+ #endif
+#endif
+
+#endif /* _GINPUT_RULES_H */
+/** @} */
diff --git a/src/ginput/toggle.c b/src/ginput/toggle.c
index ec089ecb..aad9c862 100644
--- a/src/ginput/toggle.c
+++ b/src/ginput/toggle.c
@@ -17,7 +17,7 @@
#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__)
-#include "ginput/lld/toggle.h"
+#include "src/ginput/driver_toggle.h"
#define GINPUT_TOGGLE_ISON 0x01
#define GINPUT_TOGGLE_INVERT 0x02
diff --git a/src/ginput/toggle.h b/src/ginput/toggle.h
new file mode 100644
index 00000000..73cf1e27
--- /dev/null
+++ b/src/ginput/toggle.h
@@ -0,0 +1,100 @@
+/*
+ * 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
+ */
+
+/**
+ * @file include/ginput/toggle.h
+ * @brief GINPUT GFX User Input subsystem header file.
+ *
+ * @defgroup Toggle Toggle
+ * @ingroup GINPUT
+ *
+ * @details GINPUT allows it to interface toggle buttons easily to your
+ * application.
+ *
+ * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h
+ * @pre GINPUT_NEED_TOGGLE must be set to TRUE in your gfxconf.h
+ *
+ * @{
+ */
+
+#ifndef _GINPUT_TOGGLE_H
+#define _GINPUT_TOGGLE_H
+
+#if GINPUT_NEED_TOGGLE || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Low Level Driver details and error checks. */
+/*===========================================================================*/
+
+// Get the hardware definitions - Number of instances etc.
+#include "ginput_lld_toggle_config.h"
+
+#ifndef GINPUT_TOGGLE_POLL_PERIOD
+ #define GINPUT_TOGGLE_POLL_PERIOD 200
+#endif
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+// Event types for various ginput sources
+#define GEVENT_TOGGLE (GEVENT_GINPUT_FIRST+3)
+
+typedef struct GEventToggle_t {
+ GEventType type; // The type of this event (GEVENT_TOGGLE)
+ uint16_t instance; // The toggle instance
+ bool_t on; // True if the toggle/button is on
+ } GEventToggle;
+
+// Toggle Listen Flags - passed to geventAddSourceToListener()
+#define GLISTEN_TOGGLE_ON 0x0001 // Return an event when the toggle turns on
+#define GLISTEN_TOGGLE_OFF 0x0002 // Return an event when the toggle turns off
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief Create a toggle input instance
+ *
+ * @param[in] instance The ID of the toggle input instance (from 0 to 9999)
+ *
+ * @return The source handle of the created instance
+ */
+ GSourceHandle ginputGetToggle(uint16_t instance);
+
+ /**
+ * @brief Can be used to invert the sense of a toggle
+ *
+ * @param[in] instance The ID of the toggle input instance
+ * @param[in] invert If TRUE, will be inverted
+ */
+ void ginputInvertToggle(uint16_t instance, bool_t invert);
+
+ /**
+ * @brief Get the current toggle status
+ *
+ * @param[in] instance The ID of the toggle input instance
+ * @param[in] ptoggle The toggle event struct
+ *
+ * @return Returns FALSE on an error (eg invalid instance)
+ */
+ bool_t ginputGetToggleStatus(uint16_t instance, GEventToggle *ptoggle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GINPUT_NEED_TOGGLE */
+
+#endif /* _GINPUT_TOGGLE_H */
+/** @} */
+