version 2.8
ginput_driver_mouse.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /**
9  * @file src/ginput/ginput_driver_mouse.h
10  * @brief GINPUT LLD header file for mouse/touch drivers.
11  *
12  * @defgroup Mouse Mouse
13  * @ingroup GINPUT
14  * @{
15  */
16 
17 #ifndef _LLD_GINPUT_MOUSE_H
18 #define _LLD_GINPUT_MOUSE_H
19 
20 #if GINPUT_NEED_MOUSE //|| defined(__DOXYGEN__)
21 
22 // Include the GDRIVER infrastructure
23 #include "../gdriver/gdriver.h"
24 
25 typedef struct GMouseReading {
26  coord_t x, y, z;
27  uint16_t buttons;
28  } GMouseReading;
29 
30 #if !GINPUT_TOUCH_NOCALIBRATE
31  typedef struct GMouseCalibration {
32  float ax;
33  float bx;
34  float cx;
35  float ay;
36  float by;
37  float cy;
38  } GMouseCalibration;
39 #endif
40 
41 typedef struct GMouse {
42  GDriver d; // The driver overheads and vmt
43  GMouseReading r; // The current position and state
44  uint16_t flags; // Flags
45  #define GMOUSE_FLG_CLICK_TIMER 0x0001 // Currently timing a click
46  #define GMOUSE_FLG_INDELTA 0x0002 // Currently in a up/down transition test
47  #define GMOUSE_FLG_CLIP 0x0004 // Clip reading to the display
48  #define GMOUSE_FLG_CALIBRATE 0x0008 // Calibrate readings
49  #define GMOUSE_FLG_IN_CAL 0x0010 // Currently in calibration routine
50  #define GMOUSE_FLG_FINGERMODE 0x0020 // Mouse is currently in finger mode
51  #define GMOUSE_FLG_NEEDREAD 0x0040 // The mouse needs reading
52  #define GMOUSE_FLG_DRIVER_FIRST 0x0100 // The first flag available for the driver
53  point clickpos; // The position of the last click event
54  systemticks_t clicktime; // The time of the last click event
55  GDisplay * display; // The display the mouse is associated with
56  #if !GINPUT_TOUCH_NOCALIBRATE
57  GMouseCalibration caldata; // The calibration data
58  #endif
59  // Other driver specific fields may follow.
60 } GMouse;
61 
62 typedef struct GMouseJitter {
63  coord_t calibrate; // Maximum error for a calibration to succeed
64  coord_t click; // Movement allowed without discarding the CLICK or CLICKCXT event
65  coord_t move; // Movement allowed without discarding the MOVE event
66 } GMouseJitter;
67 
68 typedef struct GMouseVMT {
69  GDriverVMT d; // Device flags are part of the general vmt
70  #define GMOUSE_VFLG_TOUCH 0x0001 // This is a touch device (rather than a mouse). Button 1 is calculated from z value.
71  #define GMOUSE_VFLG_NOPOLL 0x0002 // Do not poll this device - it is purely interrupt driven
72  #define GMOUSE_VFLG_SELFROTATION 0x0004 // This device returns readings that are aligned with the display orientation
73  #define GMOUSE_VFLG_DEFAULTFINGER 0x0008 // Default to finger mode
74  #define GMOUSE_VFLG_CALIBRATE 0x0010 // This device requires calibration
75  #define GMOUSE_VFLG_CAL_EXTREMES 0x0020 // Use edge to edge calibration
76  #define GMOUSE_VFLG_CAL_TEST 0x0040 // Test the results of the calibration
77  #define GMOUSE_VFLG_ONLY_DOWN 0x0100 // This device returns a valid position only when the mouse is down
78  #define GMOUSE_VFLG_POORUPDOWN 0x0200 // Position readings during up/down are unreliable
79  #define GMOUSE_VFLG_DYNAMICONLY 0x8000 // This mouse driver should not be statically initialized eg Win32
80  coord_t z_max; // TOUCH: Maximum possible z value (fully touched)
81  coord_t z_min; // TOUCH: Minimum possible z value (touch off screen). Note may also be > z_max
82  coord_t z_touchon; // TOUCH: z values between z_max and this are a solid touch on
83  coord_t z_touchoff; // TOUCH: z values between z_min and this are a solid touch off
84 
85  GMouseJitter pen_jitter; // PEN MODE: Jitter settings
86  GMouseJitter finger_jitter; // FINGER MODE: Jitter settings
87 
88  bool_t (*init)(GMouse *m, unsigned driverinstance); // Required
89  void (*deinit)(GMouse *m); // Optional
90  bool_t (*get)(GMouse *m, GMouseReading *prd); // Required
91  void (*calsave)(GMouse *m, const void *buf, size_t sz); // Optional
92  bool_t (*calload)(GMouse *m, void *buf, size_t sz); // Optional
93 } GMouseVMT;
94 
95 #define gmvmt(m) ((const GMouseVMT const *)((m)->d.vmt))
96 
97 /*===========================================================================*/
98 /* External declarations. */
99 /*===========================================================================*/
100 
101 // If we are not using multiple mice then hard-code the VMT name
102 #if !defined(GINPUT_MOUSE_DRIVER_LIST)
103  #undef GMOUSE_DRIVER_VMT
104  #define GMOUSE_DRIVER_VMT GMOUSEVMT_OnlyOne
105 #endif
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110  /**
111  * @brief Initialize a mouse driver
112  *
113  * @param[in] g The mouse driver
114  * @param[in] display The display to which the mouse shall be assigned
115  * @param[in] driverinstance The driver instance ToDo: Add some more details
116  * @param[in] systeminstance The mouse instance ToDo: Add some more details
117  *
118  * @return TRUE on success, FALSE otherwise
119  * @note This routine is provided by the high level code for
120  * use in the driver VMT's GMouseVMT.d structure.
121  *
122  * @notapi
123  */
124  bool_t _gmouseInitDriver(GDriver *g, void *display, unsigned driverinstance, unsigned systeminstance);
125 
126  /**
127  * @brief Routine that is called after initialization
128  *
129  * @param[in] g The mouse driver
130  * @note This routine is provided by the high level code for
131  * use in the driver VMT's GMouseVMT.d structure.
132  *
133  * @notapi
134  */
135  void _gmousePostInitDriver(GDriver *g);
136 
137  /**
138  * @brief Deinitialize a mouse driver
139  *
140  * @param[in] g The mouse driver
141  * @note This routine is provided by the high level code for
142  * use in the driver VMT's GMouseVMT.d structure.
143  *
144  * @notapi
145  */
146  void _gmouseDeInitDriver(GDriver *g);
147 
148  /**
149  * @brief Wakeup the high level code so that it attempts another read
150  *
151  * @note This routine is provided to low level drivers by the high level code
152  *
153  * @notapi
154  */
155  void _gmouseWakeup(GMouse *m);
156 
157  /**
158  * @brief Wakeup the high level code so that it attempts another read
159  *
160  * @note This routine is provided to low level drivers by the high level code
161  *
162  * @iclass
163  * @notapi
164  */
165  void _gmouseWakeupI(GMouse *m);
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif /* GINPUT_NEED_MOUSE */
172 
173 #endif /* _LLD_GINPUT_MOUSE_H */
174 /** @} */
int16_t coord_t
The type for a coordinate or length on the screen.
Definition: gdisp.h:39
All runtime driver structures start with this structure.
Definition: gdriver.h:58
Type for a 2D point on the screen.
Definition: gdisp.h:51
All driver VMT's start with this structure.
Definition: gdriver.h:66