aboutsummaryrefslogtreecommitdiff
path: root/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'protocol')
-rw-r--r--protocol/pjrc/usb_keyboard.c2
-rw-r--r--protocol/serial_mouse.h33
-rw-r--r--protocol/serial_mouse_microsoft.c124
-rw-r--r--protocol/serial_mouse_mousesystems.c131
-rw-r--r--protocol/serial_soft.c20
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h2
-rw-r--r--protocol/usb_hid/override_wiring.c1
-rw-r--r--protocol/usb_hid/parser.cpp2
-rw-r--r--protocol/vusb/usbdrv/usbdrv.c8
-rw-r--r--protocol/vusb/usbdrv/usbdrv.h14
-rw-r--r--protocol/vusb/vusb.c17
11 files changed, 332 insertions, 22 deletions
diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c
index d16833187..758a4edc6 100644
--- a/protocol/pjrc/usb_keyboard.c
+++ b/protocol/pjrc/usb_keyboard.c
@@ -39,7 +39,7 @@ uint8_t keyboard_protocol=1;
39// the idle configuration, how often we send the report to the 39// the idle configuration, how often we send the report to the
40// host (ms * 4) even when it hasn't changed 40// host (ms * 4) even when it hasn't changed
41// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request. 41// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request.
42uint8_t keyobard_idle=125; 42uint8_t keyboard_idle=125;
43 43
44// count until idle timeout 44// count until idle timeout
45uint8_t usb_keyboard_idle_count=0; 45uint8_t usb_keyboard_idle_count=0;
diff --git a/protocol/serial_mouse.h b/protocol/serial_mouse.h
new file mode 100644
index 000000000..226314fc0
--- /dev/null
+++ b/protocol/serial_mouse.h
@@ -0,0 +1,33 @@
1/*
2Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef SERIAL_MOUSE_H
19#define SERIAL_MOUSE_H
20
21#include <stdint.h>
22
23#include "serial.h"
24
25static inline uint8_t serial_mouse_init(void)
26{
27 serial_init();
28 return 0;
29}
30
31void serial_mouse_task(void);
32
33#endif
diff --git a/protocol/serial_mouse_microsoft.c b/protocol/serial_mouse_microsoft.c
new file mode 100644
index 000000000..ab74b7cdd
--- /dev/null
+++ b/protocol/serial_mouse_microsoft.c
@@ -0,0 +1,124 @@
1/*
2Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <avr/io.h>
20#include <util/delay.h>
21
22#include "serial.h"
23#include "serial_mouse.h"
24#include "report.h"
25#include "host.h"
26#include "timer.h"
27#include "print.h"
28#include "debug.h"
29
30#ifdef MAX
31#undef MAX
32#endif
33#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
34
35static void print_usb_data(const report_mouse_t *report);
36
37void serial_mouse_task(void)
38{
39 /* 3 byte ring buffer */
40 static uint8_t buffer[3];
41 static int buffer_cur = 0;
42
43 static report_mouse_t report = {};
44
45 int16_t rcv;
46
47 rcv = serial_recv2();
48 if (rcv < 0)
49 /* no new data */
50 return;
51
52 if (debug_mouse)
53 xprintf("serial_mouse: byte: %04X\n", rcv);
54
55 /*
56 * If bit 6 is one, this signals the beginning
57 * of a 3 byte sequence/packet.
58 */
59 if (rcv & (1 << 6))
60 buffer_cur = 0;
61
62 buffer[buffer_cur] = (uint8_t)rcv;
63
64 if (buffer_cur == 0 && buffer[buffer_cur] == 0x20) {
65 /*
66 * Logitech extension: This must be a follow-up on
67 * the last 3-byte packet signaling a middle button click
68 */
69 report.buttons |= MOUSE_BTN3;
70 report.x = report.y = 0;
71
72 print_usb_data(&report);
73 host_mouse_send(&report);
74 return;
75 }
76
77 buffer_cur++;
78
79 if (buffer_cur < 3)
80 return;
81 buffer_cur = 0;
82
83 /*
84 * parse 3 byte packet.
85 * NOTE: We only get a complete packet
86 * if the mouse moved or the button states
87 * change.
88 */
89 report.buttons = 0;
90 if (buffer[0] & (1 << 5))
91 report.buttons |= MOUSE_BTN1;
92 if (buffer[0] & (1 << 4))
93 report.buttons |= MOUSE_BTN2;
94
95 report.x = (buffer[0] << 6) | buffer[1];
96 report.y = ((buffer[0] << 4) & 0xC0) | buffer[2];
97
98 /* USB HID uses values from -127 to 127 only */
99 report.x = MAX(report.x, -127);
100 report.y = MAX(report.y, -127);
101
102#if 0
103 if (!report.buttons && !report.x && !report.y) {
104 /*
105 * Microsoft extension: Middle mouse button pressed
106 * FIXME: I don't know how exactly this extension works.
107 */
108 report.buttons |= MOUSE_BTN3;
109 }
110#endif
111
112 print_usb_data(&report);
113 host_mouse_send(&report);
114}
115
116static void print_usb_data(const report_mouse_t *report)
117{
118 if (!debug_mouse)
119 return;
120
121 xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
122 report->buttons, report->x, report->y,
123 report->v, report->h);
124}
diff --git a/protocol/serial_mouse_mousesystems.c b/protocol/serial_mouse_mousesystems.c
new file mode 100644
index 000000000..cfe899621
--- /dev/null
+++ b/protocol/serial_mouse_mousesystems.c
@@ -0,0 +1,131 @@
1/*
2Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <avr/io.h>
20#include <util/delay.h>
21
22#include "serial.h"
23#include "serial_mouse.h"
24#include "report.h"
25#include "host.h"
26#include "timer.h"
27#include "print.h"
28#include "debug.h"
29
30#ifdef MAX
31#undef MAX
32#endif
33#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
34
35//#define SERIAL_MOUSE_CENTER_SCROLL
36
37static void print_usb_data(const report_mouse_t *report);
38
39void serial_mouse_task(void)
40{
41 /* 5 byte ring buffer */
42 static uint8_t buffer[5];
43 static int buffer_cur = 0;
44
45 int16_t rcv;
46
47 report_mouse_t report = {0, 0, 0, 0, 0};
48
49 rcv = serial_recv2();
50 if (rcv < 0)
51 /* no new data */
52 return;
53
54 if (debug_mouse)
55 xprintf("serial_mouse: byte: %04X\n", rcv);
56
57 /*
58 * Synchronization: mouse(4) says that all
59 * bytes but the first one in the packet have
60 * bit 7 == 0, but this is untrue.
61 * Therefore we discard all bytes up to the
62 * first one with the characteristic bit pattern.
63 */
64 if (buffer_cur == 0 && (rcv >> 3) != 0x10)
65 return;
66
67 buffer[buffer_cur++] = (uint8_t)rcv;
68
69 if (buffer_cur < 5)
70 return;
71 buffer_cur = 0;
72
73#ifdef SERIAL_MOUSE_CENTER_SCROLL
74 if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) {
75 /* USB HID uses only values from -127 to 127 */
76 report.h = MAX((int8_t)buffer[1], -127);
77 report.v = MAX((int8_t)buffer[2], -127);
78
79 print_usb_data(&report);
80 host_mouse_send(&report);
81
82 if (buffer[3] || buffer[4]) {
83 report.h = MAX((int8_t)buffer[3], -127);
84 report.v = MAX((int8_t)buffer[4], -127);
85
86 print_usb_data(&report);
87 host_mouse_send(&report);
88 }
89
90 return;
91 }
92#endif
93
94 /*
95 * parse 5 byte packet.
96 * NOTE: We only get a complete packet
97 * if the mouse moved or the button states
98 * change.
99 */
100 if (!(buffer[0] & (1 << 2)))
101 report.buttons |= MOUSE_BTN1;
102 if (!(buffer[0] & (1 << 1)))
103 report.buttons |= MOUSE_BTN3;
104 if (!(buffer[0] & (1 << 0)))
105 report.buttons |= MOUSE_BTN2;
106
107 /* USB HID uses only values from -127 to 127 */
108 report.x = MAX((int8_t)buffer[1], -127);
109 report.y = MAX(-(int8_t)buffer[2], -127);
110
111 print_usb_data(&report);
112 host_mouse_send(&report);
113
114 if (buffer[3] || buffer[4]) {
115 report.x = MAX((int8_t)buffer[3], -127);
116 report.y = MAX(-(int8_t)buffer[4], -127);
117
118 print_usb_data(&report);
119 host_mouse_send(&report);
120 }
121}
122
123static void print_usb_data(const report_mouse_t *report)
124{
125 if (!debug_mouse)
126 return;
127
128 xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
129 report->buttons, report->x, report->y,
130 report->v, report->h);
131}
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
index e8870bcd7..44822b7e4 100644
--- a/protocol/serial_soft.c
+++ b/protocol/serial_soft.c
@@ -122,7 +122,11 @@ void serial_send(uint8_t data)
122 /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */ 122 /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
123 123
124#ifdef SERIAL_SOFT_BIT_ORDER_MSB 124#ifdef SERIAL_SOFT_BIT_ORDER_MSB
125 #ifdef SERIAL_SOFT_DATA_7BIT
126 uint8_t mask = 0x40;
127 #else
125 uint8_t mask = 0x80; 128 uint8_t mask = 0x80;
129 #endif
126#else 130#else
127 uint8_t mask = 0x01; 131 uint8_t mask = 0x01;
128#endif 132#endif
@@ -133,7 +137,11 @@ void serial_send(uint8_t data)
133 SERIAL_SOFT_TXD_OFF(); 137 SERIAL_SOFT_TXD_OFF();
134 _delay_us(WAIT_US); 138 _delay_us(WAIT_US);
135 139
136 while (mask) { 140#ifdef SERIAL_SOFT_DATA_7BIT
141 while (mask&0x7F) {
142#else
143 while (mask&0xFF) {
144#endif
137 if (data&mask) { 145 if (data&mask) {
138 SERIAL_SOFT_TXD_ON(); 146 SERIAL_SOFT_TXD_ON();
139 parity ^= 1; 147 parity ^= 1;
@@ -173,7 +181,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
173 uint8_t data = 0; 181 uint8_t data = 0;
174 182
175#ifdef SERIAL_SOFT_BIT_ORDER_MSB 183#ifdef SERIAL_SOFT_BIT_ORDER_MSB
184 #ifdef SERIAL_SOFT_DATA_7BIT
185 uint8_t mask = 0x40;
186 #else
176 uint8_t mask = 0x80; 187 uint8_t mask = 0x80;
188 #endif
177#else 189#else
178 uint8_t mask = 0x01; 190 uint8_t mask = 0x01;
179#endif 191#endif
@@ -197,7 +209,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
197#else 209#else
198 mask <<= 1; 210 mask <<= 1;
199#endif 211#endif
200 } while (mask); 212#ifdef SERIAL_SOFT_DATA_7BIT
213 } while (mask&0x7F);
214#else
215 } while (mask&0xFF);
216#endif
201 217
202#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD) 218#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
203 /* to center of parity bit */ 219 /* to center of parity bit */
diff --git a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
index d76d2a33d..947325e5f 100644
--- a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
+++ b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
@@ -35,7 +35,7 @@
35// -std=c++0x 35// -std=c++0x
36 36
37class __FlashStringHelper; 37class __FlashStringHelper;
38#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) 38#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
39 39
40// An inherited class for holding the result of a concatenation. These 40// An inherited class for holding the result of a concatenation. These
41// result objects are assumed to be writable by subsequent concatenations. 41// result objects are assumed to be writable by subsequent concatenations.
diff --git a/protocol/usb_hid/override_wiring.c b/protocol/usb_hid/override_wiring.c
index 3b3f5e302..1e9a94ce2 100644
--- a/protocol/usb_hid/override_wiring.c
+++ b/protocol/usb_hid/override_wiring.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * To keep Timer0 for common/timer.c override arduino/wiring.c. 2 * To keep Timer0 for common/timer.c override arduino/wiring.c.
3 */ 3 */
4#define __DELAY_BACKWARD_COMPATIBLE__
4#include <util/delay.h> 5#include <util/delay.h>
5#include "common/timer.h" 6#include "common/timer.h"
6#include "Arduino.h" 7#include "Arduino.h"
diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp
index 66e949518..28151f9d5 100644
--- a/protocol/usb_hid/parser.cpp
+++ b/protocol/usb_hid/parser.cpp
@@ -1,5 +1,3 @@
1#include <cstring.h>
2
3#include "parser.h" 1#include "parser.h"
4#include "usb_hid.h" 2#include "usb_hid.h"
5 3
diff --git a/protocol/vusb/usbdrv/usbdrv.c b/protocol/vusb/usbdrv/usbdrv.c
index 21ed554f8..2e8dd8756 100644
--- a/protocol/vusb/usbdrv/usbdrv.c
+++ b/protocol/vusb/usbdrv/usbdrv.c
@@ -67,7 +67,7 @@ optimizing hints:
67#if USB_CFG_DESCR_PROPS_STRING_0 == 0 67#if USB_CFG_DESCR_PROPS_STRING_0 == 0
68#undef USB_CFG_DESCR_PROPS_STRING_0 68#undef USB_CFG_DESCR_PROPS_STRING_0
69#define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) 69#define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0)
70PROGMEM char usbDescriptorString0[] = { /* language descriptor */ 70const PROGMEM char usbDescriptorString0[] = { /* language descriptor */
71 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ 71 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */
72 3, /* descriptor type */ 72 3, /* descriptor type */
73 0x09, 0x04, /* language index (0x0409 = US-English) */ 73 0x09, 0x04, /* language index (0x0409 = US-English) */
@@ -77,7 +77,7 @@ PROGMEM char usbDescriptorString0[] = { /* language descriptor */
77#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN 77#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
78#undef USB_CFG_DESCR_PROPS_STRING_VENDOR 78#undef USB_CFG_DESCR_PROPS_STRING_VENDOR
79#define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) 79#define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor)
80PROGMEM int usbDescriptorStringVendor[] = { 80const PROGMEM int usbDescriptorStringVendor[] = {
81 USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), 81 USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN),
82 USB_CFG_VENDOR_NAME 82 USB_CFG_VENDOR_NAME
83}; 83};
@@ -86,7 +86,7 @@ PROGMEM int usbDescriptorStringVendor[] = {
86#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN 86#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
87#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT 87#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
88#define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) 88#define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice)
89PROGMEM int usbDescriptorStringDevice[] = { 89const PROGMEM int usbDescriptorStringDevice[] = {
90 USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), 90 USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
91 USB_CFG_DEVICE_NAME 91 USB_CFG_DEVICE_NAME
92}; 92};
@@ -108,7 +108,7 @@ PROGMEM int usbDescriptorStringSerialNumber[] = {
108#if USB_CFG_DESCR_PROPS_DEVICE == 0 108#if USB_CFG_DESCR_PROPS_DEVICE == 0
109#undef USB_CFG_DESCR_PROPS_DEVICE 109#undef USB_CFG_DESCR_PROPS_DEVICE
110#define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) 110#define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice)
111PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ 111const PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */
112 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ 112 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
113 USBDESCR_DEVICE, /* descriptor type */ 113 USBDESCR_DEVICE, /* descriptor type */
114 0x10, 0x01, /* USB version supported */ 114 0x10, 0x01, /* USB version supported */
diff --git a/protocol/vusb/usbdrv/usbdrv.h b/protocol/vusb/usbdrv/usbdrv.h
index 3a78f307b..42fe16372 100644
--- a/protocol/vusb/usbdrv/usbdrv.h
+++ b/protocol/vusb/usbdrv/usbdrv.h
@@ -452,43 +452,43 @@ extern
452#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) 452#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
453PROGMEM 453PROGMEM
454#endif 454#endif
455char usbDescriptorDevice[]; 455const char usbDescriptorDevice[];
456 456
457extern 457extern
458#if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) 458#if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM)
459PROGMEM 459PROGMEM
460#endif 460#endif
461char usbDescriptorConfiguration[]; 461const char usbDescriptorConfiguration[];
462 462
463extern 463extern
464#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) 464#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
465PROGMEM 465PROGMEM
466#endif 466#endif
467char usbDescriptorHidReport[]; 467const char usbDescriptorHidReport[];
468 468
469extern 469extern
470#if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) 470#if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM)
471PROGMEM 471PROGMEM
472#endif 472#endif
473char usbDescriptorString0[]; 473const char usbDescriptorString0[];
474 474
475extern 475extern
476#if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) 476#if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM)
477PROGMEM 477PROGMEM
478#endif 478#endif
479int usbDescriptorStringVendor[]; 479const int usbDescriptorStringVendor[];
480 480
481extern 481extern
482#if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) 482#if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM)
483PROGMEM 483PROGMEM
484#endif 484#endif
485int usbDescriptorStringDevice[]; 485const int usbDescriptorStringDevice[];
486 486
487extern 487extern
488#if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) 488#if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM)
489PROGMEM 489PROGMEM
490#endif 490#endif
491int usbDescriptorStringSerialNumber[]; 491const int usbDescriptorStringSerialNumber[];
492 492
493#endif /* __ASSEMBLER__ */ 493#endif /* __ASSEMBLER__ */
494 494
diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c
index 328885a9b..7d0292ed1 100644
--- a/protocol/vusb/vusb.c
+++ b/protocol/vusb/vusb.c
@@ -35,6 +35,13 @@ static report_keyboard_t kbuf[KBUF_SIZE];
35static uint8_t kbuf_head = 0; 35static uint8_t kbuf_head = 0;
36static uint8_t kbuf_tail = 0; 36static uint8_t kbuf_tail = 0;
37 37
38typedef struct {
39 uint8_t modifier;
40 uint8_t reserved;
41 uint8_t keycode[6];
42} keyboard_report_t;
43
44static keyboard_report_t keyboard_report; // sent to PC
38 45
39/* transfer keyboard report from buffer */ 46/* transfer keyboard report from buffer */
40void vusb_transfer_keyboard(void) 47void vusb_transfer_keyboard(void)
@@ -168,8 +175,8 @@ usbRequest_t *rq = (void *)data;
168 if(rq->bRequest == USBRQ_HID_GET_REPORT){ 175 if(rq->bRequest == USBRQ_HID_GET_REPORT){
169 debug("GET_REPORT:"); 176 debug("GET_REPORT:");
170 /* we only have one report type, so don't look at wValue */ 177 /* we only have one report type, so don't look at wValue */
171 usbMsgPtr = (void *)keyboard_report; 178 usbMsgPtr = (void *)&keyboard_report;
172 return sizeof(*keyboard_report); 179 return sizeof(keyboard_report);
173 }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ 180 }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
174 debug("GET_IDLE: "); 181 debug("GET_IDLE: ");
175 //debug_hex(vusb_idle_rate); 182 //debug_hex(vusb_idle_rate);
@@ -232,7 +239,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
232 * 239 *
233 * from an example in HID spec appendix 240 * from an example in HID spec appendix
234 */ 241 */
235PROGMEM uchar keyboard_hid_report[] = { 242const PROGMEM uchar keyboard_hid_report[] = {
236 0x05, 0x01, // Usage Page (Generic Desktop), 243 0x05, 0x01, // Usage Page (Generic Desktop),
237 0x09, 0x06, // Usage (Keyboard), 244 0x09, 0x06, // Usage (Keyboard),
238 0xA1, 0x01, // Collection (Application), 245 0xA1, 0x01, // Collection (Application),
@@ -275,7 +282,7 @@ PROGMEM uchar keyboard_hid_report[] = {
275 * http://www.keil.com/forum/15671/ 282 * http://www.keil.com/forum/15671/
276 * http://www.microsoft.com/whdc/device/input/wheel.mspx 283 * http://www.microsoft.com/whdc/device/input/wheel.mspx
277 */ 284 */
278PROGMEM uchar mouse_hid_report[] = { 285const PROGMEM uchar mouse_hid_report[] = {
279 /* mouse */ 286 /* mouse */
280 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 287 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
281 0x09, 0x02, // USAGE (Mouse) 288 0x09, 0x02, // USAGE (Mouse)
@@ -358,7 +365,7 @@ PROGMEM uchar mouse_hid_report[] = {
358 * contains: device, interface, HID and endpoint descriptors 365 * contains: device, interface, HID and endpoint descriptors
359 */ 366 */
360#if USB_CFG_DESCR_PROPS_CONFIGURATION 367#if USB_CFG_DESCR_PROPS_CONFIGURATION
361PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 368const PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */
362 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ 369 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
363 USBDESCR_CONFIG, /* descriptor type */ 370 USBDESCR_CONFIG, /* descriptor type */
364 9 + (9 + 9 + 7) + (9 + 9 + 7), 0, 371 9 + (9 + 9 + 7) + (9 + 9 + 7), 0,