Skip to content

Commit 41c2578

Browse files
author
Erik Tylek Kettenburg
committed
Merge pull request #30 from vlee489/master
Updates DigiKeyboard.h to add arrows keys.
2 parents 280b22b + 2b684b9 commit 41c2578

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h

+40-38
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,39 @@
2323
typedef uint8_t byte;
2424

2525

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
2727

2828

29-
static uchar idleRate; // in 4 ms units
29+
static uchar idleRate; // in 4 ms units
3030

3131

3232
/* We use a simplifed keyboard report descriptor which does not support the
3333
* boot protocol. We don't allow setting status LEDs and but we do allow
34-
* simultaneous key presses.
34+
* simultaneous key presses.
3535
* The report descriptor has been created with usb.org's "HID Descriptor Tool"
3636
* which can be downloaded from http://www.usb.org/developers/hidpage/.
3737
* Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
3838
* for the second INPUT item.
3939
*/
4040
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
5959
};
6060

6161

@@ -126,8 +126,10 @@ const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH]
126126
#define KEY_F11 68
127127
#define KEY_F12 69
128128

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
131133

132134
class DigiKeyboardDevice : public Print {
133135
public:
@@ -139,19 +141,19 @@ class DigiKeyboardDevice : public Print {
139141

140142

141143
usbInit();
142-
144+
143145
sei();
144146

145147
// TODO: Remove the next two lines once we fix
146148
// missing first keystroke bug properly.
147-
memset(reportBuffer, 0, sizeof(reportBuffer));
149+
memset(reportBuffer, 0, sizeof(reportBuffer));
148150
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
149151
}
150-
152+
151153
void update() {
152154
usbPoll();
153155
}
154-
156+
155157
// delay while updating until we are finished delaying
156158
void delay(long milli) {
157159
unsigned long last = millis();
@@ -162,7 +164,7 @@ class DigiKeyboardDevice : public Print {
162164
update();
163165
}
164166
}
165-
167+
166168
//sendKeyStroke: sends a key press AND release
167169
void sendKeyStroke(byte keyStroke) {
168170
sendKeyStroke(keyStroke, 0);
@@ -191,21 +193,21 @@ class DigiKeyboardDevice : public Print {
191193
usbPoll();
192194
_delay_ms(5);
193195
}
194-
196+
195197
memset(reportBuffer, 0, sizeof(reportBuffer));
196-
198+
197199
reportBuffer[0] = modifiers;
198200
reportBuffer[1] = keyPress;
199-
201+
200202
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
201203
}
202-
204+
203205
size_t write(uint8_t chr) {
204206
uint8_t data = pgm_read_byte_near(ascii_to_scan_code_table + (chr - 8));
205207
sendKeyStroke(data & 0b01111111, data >> 7 ? MOD_SHIFT_RIGHT : 0);
206208
return 1;
207209
}
208-
210+
209211
//private: TODO: Make friend?
210212
uchar reportBuffer[2]; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
211213
using Print::write;
@@ -215,7 +217,7 @@ DigiKeyboardDevice DigiKeyboard = DigiKeyboardDevice();
215217

216218
#ifdef __cplusplus
217219
extern "C"{
218-
#endif
220+
#endif
219221
// USB_PUBLIC uchar usbFunctionSetup
220222
uchar usbFunctionSetup(uchar data[8]) {
221223
usbRequest_t *rq = (usbRequest_t *)((void *)data);
@@ -228,22 +230,22 @@ extern "C"{
228230
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
229231

230232
/* 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?
232234
return 0;
233235

234236
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
235237
//usbMsgPtr = &idleRate;
236238
//return 1;
237239
return 0;
238-
240+
239241
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
240242
idleRate = rq->wValue.bytes[1];
241-
243+
242244
}
243245
} else {
244246
/* no vendor specific requests implemented */
245247
}
246-
248+
247249
return 0;
248250
}
249251
#ifdef __cplusplus

0 commit comments

Comments
 (0)