Skip to content

Commit c239b85

Browse files
committed
ongoing USB development, and some refactoring
1 parent 1eb8cd5 commit c239b85

File tree

10 files changed

+1376
-730
lines changed

10 files changed

+1376
-730
lines changed

cores/xmega/CDC.cpp

Lines changed: 176 additions & 91 deletions
Large diffs are not rendered by default.

cores/xmega/HID.cpp

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
// //
1010
//////////////////////////////////////////////////////////////////////////////
1111

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.
2626
*/
2727

2828
/////////////////////////////////////////////////////////////////////////////////
@@ -46,7 +46,7 @@
4646
#if defined(USBCON)
4747
#ifdef HID_ENABLED
4848

49-
#if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
49+
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
5050
#define PROGMEM_ORIG PROGMEM
5151
#else // PROGMEM workaround
5252

@@ -83,7 +83,7 @@ Keyboard_ Keyboard;
8383

8484
extern const u8 _hidReportDescriptor[] PROGMEM;
8585
const u8 _hidReportDescriptor[] = {
86-
86+
8787
// Mouse
8888
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
8989
0x09, 0x02, // USAGE (Mouse)
@@ -120,25 +120,25 @@ const u8 _hidReportDescriptor[] = {
120120
0xa1, 0x01, // COLLECTION (Application)
121121
0x85, 0x02, // REPORT_ID (2)
122122
0x05, 0x07, // USAGE_PAGE (Keyboard)
123-
123+
124124
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
125125
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
126126
0x15, 0x00, // LOGICAL_MINIMUM (0)
127127
0x25, 0x01, // LOGICAL_MAXIMUM (1)
128128
0x75, 0x01, // REPORT_SIZE (1)
129-
129+
130130
0x95, 0x08, // REPORT_COUNT (8)
131131
0x81, 0x02, // INPUT (Data,Var,Abs)
132132
0x95, 0x01, // REPORT_COUNT (1)
133133
0x75, 0x08, // REPORT_SIZE (8)
134134
0x81, 0x03, // INPUT (Cnst,Var,Abs)
135-
135+
136136
0x95, 0x06, // REPORT_COUNT (6)
137137
0x75, 0x08, // REPORT_SIZE (8)
138138
0x15, 0x00, // LOGICAL_MINIMUM (0)
139139
0x25, 0x65, // LOGICAL_MAXIMUM (101)
140140
0x05, 0x07, // USAGE_PAGE (Keyboard)
141-
141+
142142
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
143143
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
144144
0x81, 0x00, // INPUT (Data,Ary,Abs)
@@ -236,7 +236,7 @@ bool WEAK HID_Setup(Setup& setup)
236236
return true;
237237
}
238238
}
239-
239+
240240
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
241241
{
242242
if (HID_SET_PROTOCOL == r)
@@ -262,11 +262,11 @@ Mouse_::Mouse_(void) : _buttons(0)
262262
{
263263
}
264264

265-
void Mouse_::begin(void)
265+
void Mouse_::begin(void)
266266
{
267267
}
268268

269-
void Mouse_::end(void)
269+
void Mouse_::end(void)
270270
{
271271
}
272272

@@ -297,7 +297,7 @@ void Mouse_::buttons(uint8_t b)
297297
}
298298
}
299299

300-
void Mouse_::press(uint8_t b)
300+
void Mouse_::press(uint8_t b)
301301
{
302302
buttons(_buttons | b);
303303
}
@@ -309,7 +309,7 @@ void Mouse_::release(uint8_t b)
309309

310310
bool Mouse_::isPressed(uint8_t b)
311311
{
312-
if ((b & _buttons) > 0)
312+
if ((b & _buttons) > 0)
313313
{
314314
return true;
315315
}
@@ -321,15 +321,15 @@ bool Mouse_::isPressed(uint8_t b)
321321
//================================================================================
322322
// Keyboard
323323

324-
Keyboard_::Keyboard_(void)
324+
Keyboard_::Keyboard_(void)
325325
{
326326
}
327327

328-
void Keyboard_::begin(void)
328+
void Keyboard_::begin(void)
329329
{
330330
}
331331

332-
void Keyboard_::end(void)
332+
void Keyboard_::end(void)
333333
{
334334
}
335335

@@ -350,16 +350,16 @@ const uint8_t _asciimap[128] =
350350
0x00, // ETX
351351
0x00, // EOT
352352
0x00, // ENQ
353-
0x00, // ACK
353+
0x00, // ACK
354354
0x00, // BEL
355355
0x2a, // BS Backspace
356356
0x2b, // TAB Tab
357357
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
363363
0x00, // DEL
364364
0x00, // DC1
365365
0x00, // DC2
@@ -369,13 +369,13 @@ const uint8_t _asciimap[128] =
369369
0x00, // SYN
370370
0x00, // ETB
371371
0x00, // CAN
372-
0x00, // EM
372+
0x00, // EM
373373
0x00, // SUB
374374
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
379379

380380
0x2c, // ' '
381381
0x1e|SHIFT, // !
@@ -468,7 +468,7 @@ const uint8_t _asciimap[128] =
468468
0x1b, // x
469469
0x1c, // y
470470
0x1d, // z
471-
0x2f|SHIFT, //
471+
0x2f|SHIFT, //
472472
0x31|SHIFT, // |
473473
0x30|SHIFT, // }
474474
0x35|SHIFT, // ~
@@ -478,10 +478,10 @@ const uint8_t _asciimap[128] =
478478
uint8_t USBPutChar(uint8_t c);
479479

480480
// 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
483483
// 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)
485485
{
486486
uint8_t i;
487487
if (k >= 136) // it's a non-printing key (not a modifier)
@@ -507,10 +507,10 @@ size_t Keyboard_::press(uint8_t k)
507507
k &= 0x7F;
508508
}
509509
}
510-
510+
511511
// Add k to the key report only if it's not already present
512512
// 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 &&
514514
_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
515515
_keyReport.keys[4] != k && _keyReport.keys[5] != k)
516516
{
@@ -526,7 +526,7 @@ size_t Keyboard_::press(uint8_t k)
526526
{
527527
setWriteError();
528528
return 0;
529-
}
529+
}
530530
}
531531

532532
sendReport(&_keyReport);
@@ -536,7 +536,7 @@ size_t Keyboard_::press(uint8_t k)
536536
// release() takes the specified key out of the persistent key report and
537537
// sends the report. This tells the OS the key is no longer pressed and that
538538
// it shouldn't be repeated any more.
539-
size_t Keyboard_::release(uint8_t k)
539+
size_t Keyboard_::release(uint8_t k)
540540
{
541541
uint8_t i;
542542
if (k >= 136)
@@ -561,7 +561,7 @@ size_t Keyboard_::release(uint8_t k)
561561
k &= 0x7F;
562562
}
563563
}
564-
564+
565565
// Test the key report to see if k is present. Clear it if it exists.
566566
// Check all positions in case the key is present more than once (which it shouldn't be)
567567
for (i=0; i<6; i++)
@@ -579,17 +579,17 @@ size_t Keyboard_::release(uint8_t k)
579579
void Keyboard_::releaseAll(void)
580580
{
581581
_keyReport.keys[0] = 0;
582-
_keyReport.keys[1] = 0;
582+
_keyReport.keys[1] = 0;
583583
_keyReport.keys[2] = 0;
584-
_keyReport.keys[3] = 0;
584+
_keyReport.keys[3] = 0;
585585
_keyReport.keys[4] = 0;
586-
_keyReport.keys[5] = 0;
586+
_keyReport.keys[5] = 0;
587587
_keyReport.modifiers = 0;
588588
sendReport(&_keyReport);
589589
}
590590

591591
size_t Keyboard_::write(uint8_t c)
592-
{
592+
{
593593
uint8_t p = press(c); // Keydown
594594
uint8_t r = release(c); // Keyup
595595
return (p); // just return the result of press() since release() almost always returns 1

cores/xmega/HardwareSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "wiring_private.h"
3737
#include "HardwareSerial.h"
3838

39-
#if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
39+
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
4040
#define PROGMEM_ORIG PROGMEM
4141
#else // PROGMEM workaround
4242

@@ -626,7 +626,7 @@ char bCTS = SERIAL_1_CTS_PORT->IN & SERIAL_1_CTS_PIN;
626626
bCTS ||
627627
#endif // SERIAL_1_CTS_ENABLED
628628
tx_buffer2.head == tx_buffer2.tail)
629-
629+
630630
{
631631
#ifdef SERIAL_1_CTS_ENABLED
632632
if(bCTS)
@@ -1398,7 +1398,7 @@ void HardwareSerial::begin(unsigned long baud, byte config)
13981398
_usart->CTRLC = config & ~(_BV(USART_CMODE1_bp)|_BV(USART_CMODE0_bp)); // make sure bits 6 and 7 are cleared
13991399
#ifdef USARTD0_CTRLD
14001400
_usart->CTRLD = 0; // E5 has this register, must assign to zero
1401-
#endif // USARTD0_CTRLD
1401+
#endif // USARTD0_CTRLD
14021402

14031403
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
14041404

0 commit comments

Comments
 (0)