23
23
typedef uint8_t byte;
24
24
25
25
26
- #define BUFFER_SIZE 2 // Minimum of 2: 1 for modifiers + 1 for keystroke
26
+ #define BUFFER_SIZE 2 // Minimum of 2: 1 for modifiers + 1 for keystroke
27
27
28
28
29
- static uchar idleRate; // in 4 ms units
29
+ static uchar idleRate; // in 4 ms units
30
30
31
31
32
32
/* We use a simplifed keyboard report descriptor which does not support the
33
33
* boot protocol. We don't allow setting status LEDs and but we do allow
34
- * simultaneous key presses.
34
+ * simultaneous key presses.
35
35
* The report descriptor has been created with usb.org's "HID Descriptor Tool"
36
36
* which can be downloaded from http://www.usb.org/developers/hidpage/.
37
37
* Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
38
38
* for the second INPUT item.
39
39
*/
40
40
const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
41
- 0x05 , 0x01 , // USAGE_PAGE (Generic Desktop)
42
- 0x09 , 0x06 , // USAGE (Keyboard)
43
- 0xa1 , 0x01 , // COLLECTION (Application)
44
- 0x05 , 0x07 , // USAGE_PAGE (Keyboard)
45
- 0x19 , 0xe0 , // USAGE_MINIMUM (Keyboard LeftControl)
46
- 0x29 , 0xe7 , // USAGE_MAXIMUM (Keyboard Right GUI)
47
- 0x15 , 0x00 , // LOGICAL_MINIMUM (0)
48
- 0x25 , 0x01 , // LOGICAL_MAXIMUM (1)
49
- 0x75 , 0x01 , // REPORT_SIZE (1)
50
- 0x95 , 0x08 , // REPORT_COUNT (8)
51
- 0x81 , 0x02 , // INPUT (Data,Var,Abs)
52
- 0x95 , 0x01 , // REPORT_COUNT (simultaneous keystrokes)
53
- 0x75 , 0x08 , // REPORT_SIZE (8)
54
- 0x25 , 0x65 , // LOGICAL_MAXIMUM (101)
55
- 0x19 , 0x00 , // USAGE_MINIMUM (Reserved (no event indicated))
56
- 0x29 , 0x65 , // USAGE_MAXIMUM (Keyboard Application)
57
- 0x81 , 0x00 , // INPUT (Data,Ary,Abs)
58
- 0xc0 // END_COLLECTION
41
+ 0x05 , 0x01 , // USAGE_PAGE (Generic Desktop)
42
+ 0x09 , 0x06 , // USAGE (Keyboard)
43
+ 0xa1 , 0x01 , // COLLECTION (Application)
44
+ 0x05 , 0x07 , // USAGE_PAGE (Keyboard)
45
+ 0x19 , 0xe0 , // USAGE_MINIMUM (Keyboard LeftControl)
46
+ 0x29 , 0xe7 , // USAGE_MAXIMUM (Keyboard Right GUI)
47
+ 0x15 , 0x00 , // LOGICAL_MINIMUM (0)
48
+ 0x25 , 0x01 , // LOGICAL_MAXIMUM (1)
49
+ 0x75 , 0x01 , // REPORT_SIZE (1)
50
+ 0x95 , 0x08 , // REPORT_COUNT (8)
51
+ 0x81 , 0x02 , // INPUT (Data,Var,Abs)
52
+ 0x95 , 0x01 , // REPORT_COUNT (simultaneous keystrokes)
53
+ 0x75 , 0x08 , // REPORT_SIZE (8)
54
+ 0x25 , 0x65 , // LOGICAL_MAXIMUM (101)
55
+ 0x19 , 0x00 , // USAGE_MINIMUM (Reserved (no event indicated))
56
+ 0x29 , 0x65 , // USAGE_MAXIMUM (Keyboard Application)
57
+ 0x81 , 0x00 , // INPUT (Data,Ary,Abs)
58
+ 0xc0 // END_COLLECTION
59
59
};
60
60
61
61
@@ -126,8 +126,10 @@ const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH]
126
126
#define KEY_F11 68
127
127
#define KEY_F12 69
128
128
129
- #define KEY_ARROW_LEFT 0x50
130
-
129
+ #define KEY_ARROW_UP 82
130
+ #define KEY_ARROW_DOWN 81
131
+ #define KEY_ARROW_LEFT 80
132
+ #define KEY_ARROW_RIGHT 79
131
133
132
134
class DigiKeyboardDevice : public Print {
133
135
public:
@@ -139,19 +141,19 @@ class DigiKeyboardDevice : public Print {
139
141
140
142
141
143
usbInit ();
142
-
144
+
143
145
sei ();
144
146
145
147
// TODO: Remove the next two lines once we fix
146
148
// missing first keystroke bug properly.
147
- memset (reportBuffer, 0 , sizeof (reportBuffer));
149
+ memset (reportBuffer, 0 , sizeof (reportBuffer));
148
150
usbSetInterrupt (reportBuffer, sizeof (reportBuffer));
149
151
}
150
-
152
+
151
153
void update () {
152
154
usbPoll ();
153
155
}
154
-
156
+
155
157
// delay while updating until we are finished delaying
156
158
void delay (long milli) {
157
159
unsigned long last = millis ();
@@ -162,7 +164,7 @@ class DigiKeyboardDevice : public Print {
162
164
update ();
163
165
}
164
166
}
165
-
167
+
166
168
// sendKeyStroke: sends a key press AND release
167
169
void sendKeyStroke (byte keyStroke) {
168
170
sendKeyStroke (keyStroke, 0 );
@@ -191,21 +193,21 @@ class DigiKeyboardDevice : public Print {
191
193
usbPoll ();
192
194
_delay_ms (5 );
193
195
}
194
-
196
+
195
197
memset (reportBuffer, 0 , sizeof (reportBuffer));
196
-
198
+
197
199
reportBuffer[0 ] = modifiers;
198
200
reportBuffer[1 ] = keyPress;
199
-
201
+
200
202
usbSetInterrupt (reportBuffer, sizeof (reportBuffer));
201
203
}
202
-
204
+
203
205
size_t write (uint8_t chr) {
204
206
uint8_t data = pgm_read_byte_near (ascii_to_scan_code_table + (chr - 8 ));
205
207
sendKeyStroke (data & 0b01111111 , data >> 7 ? MOD_SHIFT_RIGHT : 0 );
206
208
return 1 ;
207
209
}
208
-
210
+
209
211
// private: TODO: Make friend?
210
212
uchar reportBuffer[2 ]; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
211
213
using Print::write;
@@ -215,7 +217,7 @@ DigiKeyboardDevice DigiKeyboard = DigiKeyboardDevice();
215
217
216
218
#ifdef __cplusplus
217
219
extern " C" {
218
- #endif
220
+ #endif
219
221
// USB_PUBLIC uchar usbFunctionSetup
220
222
uchar usbFunctionSetup (uchar data[8 ]) {
221
223
usbRequest_t *rq = (usbRequest_t *)((void *)data);
@@ -228,22 +230,22 @@ extern "C"{
228
230
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
229
231
230
232
/* we only have one report type, so don't look at wValue */
231
- // TODO: Ensure it's okay not to return anything here?
233
+ // TODO: Ensure it's okay not to return anything here?
232
234
return 0 ;
233
235
234
236
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
235
237
// usbMsgPtr = &idleRate;
236
238
// return 1;
237
239
return 0 ;
238
-
240
+
239
241
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
240
242
idleRate = rq->wValue .bytes [1 ];
241
-
243
+
242
244
}
243
245
} else {
244
246
/* no vendor specific requests implemented */
245
247
}
246
-
248
+
247
249
return 0 ;
248
250
}
249
251
#ifdef __cplusplus
0 commit comments