sanguino/cores/arduino/HID.cpp

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
permissions
-rw-r--r--

added missing sanguino files

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 /* Copyright (c) 2011, Peter Barrett
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4 **
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 ** Permission to use, copy, modify, and/or distribute this software for
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 ** any purpose with or without fee is hereby granted, provided that the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 ** above copyright notice and this permission notice appear in all copies.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 **
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11 ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 ** SOFTWARE.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 #include "Platform.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 #include "USBAPI.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 #include "USBDesc.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 #if defined(USBCON)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24 #ifdef HID_ENABLED
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 //#define RAWHID_ENABLED
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 // Singletons for mouse and keyboard
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30 Mouse_ Mouse;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 Keyboard_ Keyboard;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 // HID report descriptor
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 #define LSB(_x) ((_x) & 0xFF)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39 #define MSB(_x) ((_x) >> 8)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 #define RAWHID_USAGE_PAGE 0xFFC0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 #define RAWHID_USAGE 0x0C00
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 #define RAWHID_TX_SIZE 64
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 #define RAWHID_RX_SIZE 64
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 extern const u8 _hidReportDescriptor[] PROGMEM;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 const u8 _hidReportDescriptor[] = {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 // Mouse
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 0x09, 0x02, // USAGE (Mouse)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 0xa1, 0x01, // COLLECTION (Application)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 0x09, 0x01, // USAGE (Pointer)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 0xa1, 0x00, // COLLECTION (Physical)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 0x85, 0x01, // REPORT_ID (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 0x05, 0x09, // USAGE_PAGE (Button)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 0x19, 0x01, // USAGE_MINIMUM (Button 1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59 0x15, 0x00, // LOGICAL_MINIMUM (0)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 0x25, 0x01, // LOGICAL_MAXIMUM (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 0x95, 0x03, // REPORT_COUNT (3)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62 0x75, 0x01, // REPORT_SIZE (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63 0x81, 0x02, // INPUT (Data,Var,Abs)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64 0x95, 0x01, // REPORT_COUNT (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 0x75, 0x05, // REPORT_SIZE (5)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66 0x81, 0x03, // INPUT (Cnst,Var,Abs)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 0x09, 0x30, // USAGE (X)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 0x09, 0x31, // USAGE (Y)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 0x09, 0x38, // USAGE (Wheel)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71 0x15, 0x81, // LOGICAL_MINIMUM (-127)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73 0x75, 0x08, // REPORT_SIZE (8)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74 0x95, 0x03, // REPORT_COUNT (3)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75 0x81, 0x06, // INPUT (Data,Var,Rel)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 0xc0, // END_COLLECTION
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
77 0xc0, // END_COLLECTION
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
78
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
79 // Keyboard
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
80 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
81 0x09, 0x06, // USAGE (Keyboard)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
82 0xa1, 0x01, // COLLECTION (Application)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
83 0x85, 0x02, // REPORT_ID (2)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
84 0x05, 0x07, // USAGE_PAGE (Keyboard)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
85
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
86 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
87 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
88 0x15, 0x00, // LOGICAL_MINIMUM (0)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
89 0x25, 0x01, // LOGICAL_MAXIMUM (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
90 0x75, 0x01, // REPORT_SIZE (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
91
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
92 0x95, 0x08, // REPORT_COUNT (8)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
93 0x81, 0x02, // INPUT (Data,Var,Abs)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
94 0x95, 0x01, // REPORT_COUNT (1)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
95 0x75, 0x08, // REPORT_SIZE (8)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
96 0x81, 0x03, // INPUT (Cnst,Var,Abs)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
97
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
98 0x95, 0x06, // REPORT_COUNT (6)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
99 0x75, 0x08, // REPORT_SIZE (8)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
100 0x15, 0x00, // LOGICAL_MINIMUM (0)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
101 0x25, 0x65, // LOGICAL_MAXIMUM (101)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
102 0x05, 0x07, // USAGE_PAGE (Keyboard)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
103
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
104 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
105 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
106 0x81, 0x00, // INPUT (Data,Ary,Abs)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
107 0xc0, // END_COLLECTION
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
108
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
109 #if RAWHID_ENABLED
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
110 // RAW HID
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
111 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
112 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
113
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
114 0xA1, 0x01, // Collection 0x01
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
115 0x85, 0x03, // REPORT_ID (3)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
116 0x75, 0x08, // report size = 8 bits
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
117 0x15, 0x00, // logical minimum = 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
118 0x26, 0xFF, 0x00, // logical maximum = 255
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
119
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
120 0x95, 64, // report count TX
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
121 0x09, 0x01, // usage
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
122 0x81, 0x02, // Input (array)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
123
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
124 0x95, 64, // report count RX
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
125 0x09, 0x02, // usage
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
126 0x91, 0x02, // Output (array)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
127 0xC0 // end collection
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
128 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
129 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
130
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
131 extern const HIDDescriptor _hidInterface PROGMEM;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
132 const HIDDescriptor _hidInterface =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
133 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
134 D_INTERFACE(HID_INTERFACE,1,3,0,0),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
135 D_HIDREPORT(sizeof(_hidReportDescriptor)),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
136 D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
137 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
138
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
139 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
140 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
141 // Driver
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
142
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
143 u8 _hid_protocol = 1;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
144 u8 _hid_idle = 1;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
145
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
146 #define WEAK __attribute__ ((weak))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
147
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
148 int WEAK HID_GetInterface(u8* interfaceNum)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
149 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
150 interfaceNum[0] += 1; // uses 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
151 return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
152 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
153
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
154 int WEAK HID_GetDescriptor(int i)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
155 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
156 return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
157 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
158
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
159 void WEAK HID_SendReport(u8 id, const void* data, int len)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
160 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
161 USB_Send(HID_TX, &id, 1);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
162 USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
163 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
164
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
165 bool WEAK HID_Setup(Setup& setup)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
166 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
167 u8 r = setup.bRequest;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
168 u8 requestType = setup.bmRequestType;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
169 if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
170 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
171 if (HID_GET_REPORT == r)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
172 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
173 //HID_GetReport();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
174 return true;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
175 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
176 if (HID_GET_PROTOCOL == r)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
177 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
178 //Send8(_hid_protocol); // TODO
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
179 return true;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
180 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
181 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
182
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
183 if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
184 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
185 if (HID_SET_PROTOCOL == r)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
186 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
187 _hid_protocol = setup.wValueL;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
188 return true;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
189 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
190
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
191 if (HID_SET_IDLE == r)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
192 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
193 _hid_idle = setup.wValueL;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
194 return true;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
195 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
196 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
197 return false;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
198 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
199
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
200 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
201 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
202 // Mouse
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
203
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
204 Mouse_::Mouse_(void) : _buttons(0)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
205 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
206 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
207
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
208 void Mouse_::begin(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
209 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
210 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
211
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
212 void Mouse_::end(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
213 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
214 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
215
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
216 void Mouse_::click(uint8_t b)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
217 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
218 _buttons = b;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
219 move(0,0,0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
220 _buttons = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
221 move(0,0,0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
222 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
223
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
224 void Mouse_::move(signed char x, signed char y, signed char wheel)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
225 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
226 u8 m[4];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
227 m[0] = _buttons;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
228 m[1] = x;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
229 m[2] = y;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
230 m[3] = wheel;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
231 HID_SendReport(1,m,4);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
232 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
233
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
234 void Mouse_::buttons(uint8_t b)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
235 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
236 if (b != _buttons)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
237 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
238 _buttons = b;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
239 move(0,0,0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
240 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
241 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
242
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
243 void Mouse_::press(uint8_t b)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
244 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
245 buttons(_buttons | b);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
246 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
247
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
248 void Mouse_::release(uint8_t b)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
249 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
250 buttons(_buttons & ~b);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
251 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
252
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
253 bool Mouse_::isPressed(uint8_t b)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
254 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
255 if ((b & _buttons) > 0)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
256 return true;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
257 return false;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
258 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
259
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
260 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
261 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
262 // Keyboard
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
263
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
264 Keyboard_::Keyboard_(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
265 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
266 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
267
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
268 void Keyboard_::begin(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
269 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
270 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
271
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
272 void Keyboard_::end(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
273 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
274 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
275
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
276 void Keyboard_::sendReport(KeyReport* keys)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
277 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
278 HID_SendReport(2,keys,sizeof(KeyReport));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
279 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
280
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
281 extern
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
282 const uint8_t _asciimap[128] PROGMEM;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
283
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
284 #define SHIFT 0x80
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
285 const uint8_t _asciimap[128] =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
286 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
287 0x00, // NUL
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
288 0x00, // SOH
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
289 0x00, // STX
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
290 0x00, // ETX
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
291 0x00, // EOT
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
292 0x00, // ENQ
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
293 0x00, // ACK
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
294 0x00, // BEL
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
295 0x2a, // BS Backspace
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
296 0x2b, // TAB Tab
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
297 0x28, // LF Enter
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
298 0x00, // VT
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
299 0x00, // FF
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
300 0x00, // CR
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
301 0x00, // SO
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
302 0x00, // SI
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
303 0x00, // DEL
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
304 0x00, // DC1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
305 0x00, // DC2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
306 0x00, // DC3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
307 0x00, // DC4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
308 0x00, // NAK
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
309 0x00, // SYN
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
310 0x00, // ETB
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
311 0x00, // CAN
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
312 0x00, // EM
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
313 0x00, // SUB
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
314 0x00, // ESC
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
315 0x00, // FS
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
316 0x00, // GS
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
317 0x00, // RS
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
318 0x00, // US
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
319
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
320 0x2c, // ' '
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
321 0x1e|SHIFT, // !
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
322 0x34|SHIFT, // "
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
323 0x20|SHIFT, // #
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
324 0x21|SHIFT, // $
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
325 0x22|SHIFT, // %
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
326 0x24|SHIFT, // &
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
327 0x34, // '
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
328 0x26|SHIFT, // (
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
329 0x27|SHIFT, // )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
330 0x25|SHIFT, // *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
331 0x2e|SHIFT, // +
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
332 0x36, // ,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
333 0x2d, // -
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
334 0x37, // .
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
335 0x38, // /
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
336 0x27, // 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
337 0x1e, // 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
338 0x1f, // 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
339 0x20, // 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
340 0x21, // 4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
341 0x22, // 5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
342 0x23, // 6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
343 0x24, // 7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
344 0x25, // 8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
345 0x26, // 9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
346 0x33|SHIFT, // :
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
347 0x33, // ;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
348 0x36|SHIFT, // <
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
349 0x2e, // =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
350 0x37|SHIFT, // >
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
351 0x38|SHIFT, // ?
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
352 0x1f|SHIFT, // @
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
353 0x04|SHIFT, // A
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
354 0x05|SHIFT, // B
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
355 0x06|SHIFT, // C
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
356 0x07|SHIFT, // D
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
357 0x08|SHIFT, // E
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
358 0x09|SHIFT, // F
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
359 0x0a|SHIFT, // G
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
360 0x0b|SHIFT, // H
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
361 0x0c|SHIFT, // I
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
362 0x0d|SHIFT, // J
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
363 0x0e|SHIFT, // K
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
364 0x0f|SHIFT, // L
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
365 0x10|SHIFT, // M
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
366 0x11|SHIFT, // N
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
367 0x12|SHIFT, // O
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
368 0x13|SHIFT, // P
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
369 0x14|SHIFT, // Q
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
370 0x15|SHIFT, // R
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
371 0x16|SHIFT, // S
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
372 0x17|SHIFT, // T
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
373 0x18|SHIFT, // U
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
374 0x19|SHIFT, // V
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
375 0x1a|SHIFT, // W
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
376 0x1b|SHIFT, // X
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
377 0x1c|SHIFT, // Y
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
378 0x1d|SHIFT, // Z
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
379 0x2f, // [
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
380 0x31, // bslash
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
381 0x30, // ]
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
382 0x23|SHIFT, // ^
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
383 0x2d|SHIFT, // _
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
384 0x35, // `
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
385 0x04, // a
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
386 0x05, // b
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
387 0x06, // c
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
388 0x07, // d
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
389 0x08, // e
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
390 0x09, // f
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
391 0x0a, // g
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
392 0x0b, // h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
393 0x0c, // i
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
394 0x0d, // j
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
395 0x0e, // k
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
396 0x0f, // l
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
397 0x10, // m
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
398 0x11, // n
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
399 0x12, // o
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
400 0x13, // p
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
401 0x14, // q
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
402 0x15, // r
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
403 0x16, // s
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
404 0x17, // t
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
405 0x18, // u
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
406 0x19, // v
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
407 0x1a, // w
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
408 0x1b, // x
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
409 0x1c, // y
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
410 0x1d, // z
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
411 0x2f|SHIFT, //
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
412 0x31|SHIFT, // |
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
413 0x30|SHIFT, // }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
414 0x35|SHIFT, // ~
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
415 0 // DEL
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
416 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
417
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
418 uint8_t USBPutChar(uint8_t c);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
419
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
420 // press() adds the specified key (printing, non-printing, or modifier)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
421 // to the persistent key report and sends the report. Because of the way
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
422 // USB HID works, the host acts like the key remains pressed until we
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
423 // call release(), releaseAll(), or otherwise clear the report and resend.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
424 size_t Keyboard_::press(uint8_t k)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
425 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
426 uint8_t i;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
427 if (k >= 136) { // it's a non-printing key (not a modifier)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
428 k = k - 136;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
429 } else if (k >= 128) { // it's a modifier key
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
430 _keyReport.modifiers |= (1<<(k-128));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
431 k = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
432 } else { // it's a printing key
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
433 k = pgm_read_byte(_asciimap + k);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
434 if (!k) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
435 setWriteError();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
436 return 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
437 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
438 if (k & 0x80) { // it's a capital letter or other character reached with shift
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
439 _keyReport.modifiers |= 0x02; // the left shift modifier
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
440 k &= 0x7F;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
441 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
442 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
443
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
444 // Add k to the key report only if it's not already present
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
445 // and if there is an empty slot.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
446 if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
447 _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
448 _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
449
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
450 for (i=0; i<6; i++) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
451 if (_keyReport.keys[i] == 0x00) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
452 _keyReport.keys[i] = k;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
453 break;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
454 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
455 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
456 if (i == 6) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
457 setWriteError();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
458 return 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
459 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
460 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
461 sendReport(&_keyReport);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
462 return 1;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
463 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
464
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
465 // release() takes the specified key out of the persistent key report and
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
466 // sends the report. This tells the OS the key is no longer pressed and that
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
467 // it shouldn't be repeated any more.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
468 size_t Keyboard_::release(uint8_t k)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
469 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
470 uint8_t i;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
471 if (k >= 136) { // it's a non-printing key (not a modifier)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
472 k = k - 136;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
473 } else if (k >= 128) { // it's a modifier key
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
474 _keyReport.modifiers &= ~(1<<(k-128));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
475 k = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
476 } else { // it's a printing key
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
477 k = pgm_read_byte(_asciimap + k);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
478 if (!k) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
479 return 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
480 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
481 if (k & 0x80) { // it's a capital letter or other character reached with shift
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
482 _keyReport.modifiers &= ~(0x02); // the left shift modifier
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
483 k &= 0x7F;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
484 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
485 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
486
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
487 // Test the key report to see if k is present. Clear it if it exists.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
488 // Check all positions in case the key is present more than once (which it shouldn't be)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
489 for (i=0; i<6; i++) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
490 if (0 != k && _keyReport.keys[i] == k) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
491 _keyReport.keys[i] = 0x00;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
492 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
493 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
494
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
495 sendReport(&_keyReport);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
496 return 1;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
497 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
498
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
499 void Keyboard_::releaseAll(void)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
500 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
501 _keyReport.keys[0] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
502 _keyReport.keys[1] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
503 _keyReport.keys[2] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
504 _keyReport.keys[3] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
505 _keyReport.keys[4] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
506 _keyReport.keys[5] = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
507 _keyReport.modifiers = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
508 sendReport(&_keyReport);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
509 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
510
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
511 size_t Keyboard_::write(uint8_t c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
512 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
513 uint8_t p = press(c); // Keydown
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
514 uint8_t r = release(c); // Keyup
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
515 return (p); // just return the result of press() since release() almost always returns 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
516 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
517
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
518 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
519
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
520 #endif /* if defined(USBCON) */

mercurial