9
9
// //
10
10
// ////////////////////////////////////////////////////////////////////////////
11
11
12
- /* Copyright (c) 2011, Peter Barrett
13
- **
14
- ** Permission to use, copy, modify, and/or distribute this software for
15
- ** any purpose with or without fee is hereby granted, provided that the
16
- ** above copyright notice and this permission notice appear in all copies.
17
- **
18
- ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
19
- ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
20
- ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
21
- ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
22
- ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23
- ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24
- ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
25
- ** SOFTWARE.
12
+ /* Copyright (c) 2011, Peter Barrett
13
+ **
14
+ ** Permission to use, copy, modify, and/or distribute this software for
15
+ ** any purpose with or without fee is hereby granted, provided that the
16
+ ** above copyright notice and this permission notice appear in all copies.
17
+ **
18
+ ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
19
+ ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
20
+ ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
21
+ ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
22
+ ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23
+ ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24
+ ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
25
+ ** SOFTWARE.
26
26
*/
27
27
28
28
// ///////////////////////////////////////////////////////////////////////////////
46
46
#if defined(USBCON)
47
47
#ifdef HID_ENABLED
48
48
49
- #if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
49
+ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
50
50
#define PROGMEM_ORIG PROGMEM
51
51
#else // PROGMEM workaround
52
52
@@ -83,7 +83,7 @@ Keyboard_ Keyboard;
83
83
84
84
extern const u8 _hidReportDescriptor[] PROGMEM;
85
85
const u8 _hidReportDescriptor[] = {
86
-
86
+
87
87
// Mouse
88
88
0x05 , 0x01 , // USAGE_PAGE (Generic Desktop) // 54
89
89
0x09 , 0x02 , // USAGE (Mouse)
@@ -120,25 +120,25 @@ const u8 _hidReportDescriptor[] = {
120
120
0xa1 , 0x01 , // COLLECTION (Application)
121
121
0x85 , 0x02 , // REPORT_ID (2)
122
122
0x05 , 0x07 , // USAGE_PAGE (Keyboard)
123
-
123
+
124
124
0x19 , 0xe0 , // USAGE_MINIMUM (Keyboard LeftControl)
125
125
0x29 , 0xe7 , // USAGE_MAXIMUM (Keyboard Right GUI)
126
126
0x15 , 0x00 , // LOGICAL_MINIMUM (0)
127
127
0x25 , 0x01 , // LOGICAL_MAXIMUM (1)
128
128
0x75 , 0x01 , // REPORT_SIZE (1)
129
-
129
+
130
130
0x95 , 0x08 , // REPORT_COUNT (8)
131
131
0x81 , 0x02 , // INPUT (Data,Var,Abs)
132
132
0x95 , 0x01 , // REPORT_COUNT (1)
133
133
0x75 , 0x08 , // REPORT_SIZE (8)
134
134
0x81 , 0x03 , // INPUT (Cnst,Var,Abs)
135
-
135
+
136
136
0x95 , 0x06 , // REPORT_COUNT (6)
137
137
0x75 , 0x08 , // REPORT_SIZE (8)
138
138
0x15 , 0x00 , // LOGICAL_MINIMUM (0)
139
139
0x25 , 0x65 , // LOGICAL_MAXIMUM (101)
140
140
0x05 , 0x07 , // USAGE_PAGE (Keyboard)
141
-
141
+
142
142
0x19 , 0x00 , // USAGE_MINIMUM (Reserved (no event indicated))
143
143
0x29 , 0x65 , // USAGE_MAXIMUM (Keyboard Application)
144
144
0x81 , 0x00 , // INPUT (Data,Ary,Abs)
@@ -236,7 +236,7 @@ bool WEAK HID_Setup(Setup& setup)
236
236
return true ;
237
237
}
238
238
}
239
-
239
+
240
240
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
241
241
{
242
242
if (HID_SET_PROTOCOL == r)
@@ -262,11 +262,11 @@ Mouse_::Mouse_(void) : _buttons(0)
262
262
{
263
263
}
264
264
265
- void Mouse_::begin (void )
265
+ void Mouse_::begin (void )
266
266
{
267
267
}
268
268
269
- void Mouse_::end (void )
269
+ void Mouse_::end (void )
270
270
{
271
271
}
272
272
@@ -297,7 +297,7 @@ void Mouse_::buttons(uint8_t b)
297
297
}
298
298
}
299
299
300
- void Mouse_::press (uint8_t b)
300
+ void Mouse_::press (uint8_t b)
301
301
{
302
302
buttons (_buttons | b);
303
303
}
@@ -309,7 +309,7 @@ void Mouse_::release(uint8_t b)
309
309
310
310
bool Mouse_::isPressed (uint8_t b)
311
311
{
312
- if ((b & _buttons) > 0 )
312
+ if ((b & _buttons) > 0 )
313
313
{
314
314
return true ;
315
315
}
@@ -321,15 +321,15 @@ bool Mouse_::isPressed(uint8_t b)
321
321
// ================================================================================
322
322
// Keyboard
323
323
324
- Keyboard_::Keyboard_ (void )
324
+ Keyboard_::Keyboard_ (void )
325
325
{
326
326
}
327
327
328
- void Keyboard_::begin (void )
328
+ void Keyboard_::begin (void )
329
329
{
330
330
}
331
331
332
- void Keyboard_::end (void )
332
+ void Keyboard_::end (void )
333
333
{
334
334
}
335
335
@@ -350,16 +350,16 @@ const uint8_t _asciimap[128] =
350
350
0x00 , // ETX
351
351
0x00 , // EOT
352
352
0x00 , // ENQ
353
- 0x00 , // ACK
353
+ 0x00 , // ACK
354
354
0x00 , // BEL
355
355
0x2a , // BS Backspace
356
356
0x2b , // TAB Tab
357
357
0x28 , // LF Enter
358
- 0x00 , // VT
359
- 0x00 , // FF
360
- 0x00 , // CR
361
- 0x00 , // SO
362
- 0x00 , // SI
358
+ 0x00 , // VT
359
+ 0x00 , // FF
360
+ 0x00 , // CR
361
+ 0x00 , // SO
362
+ 0x00 , // SI
363
363
0x00 , // DEL
364
364
0x00 , // DC1
365
365
0x00 , // DC2
@@ -369,13 +369,13 @@ const uint8_t _asciimap[128] =
369
369
0x00 , // SYN
370
370
0x00 , // ETB
371
371
0x00 , // CAN
372
- 0x00 , // EM
372
+ 0x00 , // EM
373
373
0x00 , // SUB
374
374
0x00 , // ESC
375
- 0x00 , // FS
376
- 0x00 , // GS
377
- 0x00 , // RS
378
- 0x00 , // US
375
+ 0x00 , // FS
376
+ 0x00 , // GS
377
+ 0x00 , // RS
378
+ 0x00 , // US
379
379
380
380
0x2c , // ' '
381
381
0x1e |SHIFT, // !
@@ -468,7 +468,7 @@ const uint8_t _asciimap[128] =
468
468
0x1b , // x
469
469
0x1c , // y
470
470
0x1d , // z
471
- 0x2f |SHIFT, //
471
+ 0x2f |SHIFT, //
472
472
0x31 |SHIFT, // |
473
473
0x30 |SHIFT, // }
474
474
0x35 |SHIFT, // ~
@@ -478,10 +478,10 @@ const uint8_t _asciimap[128] =
478
478
uint8_t USBPutChar (uint8_t c);
479
479
480
480
// press() adds the specified key (printing, non-printing, or modifier)
481
- // to the persistent key report and sends the report. Because of the way
482
- // USB HID works, the host acts like the key remains pressed until we
481
+ // to the persistent key report and sends the report. Because of the way
482
+ // USB HID works, the host acts like the key remains pressed until we
483
483
// call release(), releaseAll(), or otherwise clear the report and resend.
484
- size_t Keyboard_::press (uint8_t k)
484
+ size_t Keyboard_::press (uint8_t k)
485
485
{
486
486
uint8_t i;
487
487
if (k >= 136 ) // it's a non-printing key (not a modifier)
@@ -507,10 +507,10 @@ size_t Keyboard_::press(uint8_t k)
507
507
k &= 0x7F ;
508
508
}
509
509
}
510
-
510
+
511
511
// Add k to the key report only if it's not already present
512
512
// and if there is an empty slot.
513
- if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
513
+ if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
514
514
_keyReport.keys [2 ] != k && _keyReport.keys [3 ] != k &&
515
515
_keyReport.keys [4 ] != k && _keyReport.keys [5 ] != k)
516
516
{
@@ -526,7 +526,7 @@ size_t Keyboard_::press(uint8_t k)
526
526
{
527
527
setWriteError ();
528
528
return 0 ;
529
- }
529
+ }
530
530
}
531
531
532
532
sendReport (&_keyReport);
@@ -536,7 +536,7 @@ size_t Keyboard_::press(uint8_t k)
536
536
// release() takes the specified key out of the persistent key report and
537
537
// sends the report. This tells the OS the key is no longer pressed and that
538
538
// it shouldn't be repeated any more.
539
- size_t Keyboard_::release (uint8_t k)
539
+ size_t Keyboard_::release (uint8_t k)
540
540
{
541
541
uint8_t i;
542
542
if (k >= 136 )
@@ -561,7 +561,7 @@ size_t Keyboard_::release(uint8_t k)
561
561
k &= 0x7F ;
562
562
}
563
563
}
564
-
564
+
565
565
// Test the key report to see if k is present. Clear it if it exists.
566
566
// Check all positions in case the key is present more than once (which it shouldn't be)
567
567
for (i=0 ; i<6 ; i++)
@@ -579,17 +579,17 @@ size_t Keyboard_::release(uint8_t k)
579
579
void Keyboard_::releaseAll (void )
580
580
{
581
581
_keyReport.keys [0 ] = 0 ;
582
- _keyReport.keys [1 ] = 0 ;
582
+ _keyReport.keys [1 ] = 0 ;
583
583
_keyReport.keys [2 ] = 0 ;
584
- _keyReport.keys [3 ] = 0 ;
584
+ _keyReport.keys [3 ] = 0 ;
585
585
_keyReport.keys [4 ] = 0 ;
586
- _keyReport.keys [5 ] = 0 ;
586
+ _keyReport.keys [5 ] = 0 ;
587
587
_keyReport.modifiers = 0 ;
588
588
sendReport (&_keyReport);
589
589
}
590
590
591
591
size_t Keyboard_::write (uint8_t c)
592
- {
592
+ {
593
593
uint8_t p = press (c); // Keydown
594
594
uint8_t r = release (c); // Keyup
595
595
return (p); // just return the result of press() since release() almost always returns 1
0 commit comments