aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-06-10 06:30:37 +1000
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commit69e0ad1b2ce43fbf1daa85d22007570430ddf0c7 (patch)
treef317a2b2299ae6cc0c4207b9f89adec2c5b6cd29 /tmk_core
parenta3933bdbe74aa10120da9962b46ee1576450fc07 (diff)
downloadqmk_firmware-69e0ad1b2ce43fbf1daa85d22007570430ddf0c7.tar.gz
qmk_firmware-69e0ad1b2ce43fbf1daa85d22007570430ddf0c7.zip
Additional cleanups for V-USB code (#9310)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common.mk4
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c37
-rw-r--r--tmk_core/protocol/vusb/sendchar_usart.c19
-rw-r--r--tmk_core/protocol/vusb/vusb.c102
5 files changed, 53 insertions, 116 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 63de7c7ed..b7fe45afd 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -113,10 +113,6 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
113 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN 113 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
114endif 114endif
115 115
116ifeq ($(strip $(NO_UART)), yes)
117 TMK_COMMON_DEFS += -DNO_UART
118endif
119
120ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes) 116ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
121 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN 117 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
122endif 118endif
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 5e564f748..1de600308 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -9,13 +9,6 @@ SRC += $(VUSB_DIR)/main.c \
9 $(VUSB_PATH)/usbdrv/usbdrvasm.S \ 9 $(VUSB_PATH)/usbdrv/usbdrvasm.S \
10 $(VUSB_PATH)/usbdrv/oddebug.c 10 $(VUSB_PATH)/usbdrv/oddebug.c
11 11
12ifneq ($(strip $(CONSOLE_ENABLE)), yes)
13ifndef NO_UART
14SRC += $(COMMON_DIR)/sendchar_uart.c \
15 $(COMMON_DIR)/uart.c
16endif
17endif
18
19# Search Path 12# Search Path
20VPATH += $(TMK_PATH)/$(VUSB_DIR) 13VPATH += $(TMK_PATH)/$(VUSB_DIR)
21VPATH += $(VUSB_PATH) 14VPATH += $(VUSB_PATH)
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index b4063273d..a57df5ce0 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -7,19 +7,22 @@
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ 8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
9 */ 9 */
10
10#include <stdint.h> 11#include <stdint.h>
12
11#include <avr/interrupt.h> 13#include <avr/interrupt.h>
14#include <avr/power.h>
12#include <avr/wdt.h> 15#include <avr/wdt.h>
13#include <avr/sleep.h> 16#include <avr/sleep.h>
14#include <util/delay.h> 17
15#include <usbdrv/usbdrv.h> 18#include <usbdrv/usbdrv.h>
16#include <usbdrv/oddebug.h> 19
17#include "vusb.h" 20#include "vusb.h"
21
18#include "keyboard.h" 22#include "keyboard.h"
19#include "host.h" 23#include "host.h"
20#include "timer.h" 24#include "timer.h"
21#include "uart.h" 25#include "print.h"
22#include "debug.h"
23#include "suspend.h" 26#include "suspend.h"
24#include "wait.h" 27#include "wait.h"
25#include "sendchar.h" 28#include "sendchar.h"
@@ -28,8 +31,6 @@
28# include "sleep_led.h" 31# include "sleep_led.h"
29#endif 32#endif
30 33
31#define UART_BAUD_RATE 115200
32
33#ifdef CONSOLE_ENABLE 34#ifdef CONSOLE_ENABLE
34void console_task(void); 35void console_task(void);
35#endif 36#endif
@@ -47,7 +48,7 @@ static void initForUsbConnectivity(void) {
47 usbDeviceDisconnect(); /* do this while interrupts are disabled */ 48 usbDeviceDisconnect(); /* do this while interrupts are disabled */
48 while (--i) { /* fake USB disconnect for > 250 ms */ 49 while (--i) { /* fake USB disconnect for > 250 ms */
49 wdt_reset(); 50 wdt_reset();
50 _delay_ms(1); 51 wait_ms(1);
51 } 52 }
52 usbDeviceConnect(); 53 usbDeviceConnect();
53} 54}
@@ -60,7 +61,7 @@ static void usb_remote_wakeup(void) {
60 USBDDR = ddr_orig | USBMASK; 61 USBDDR = ddr_orig | USBMASK;
61 USBOUT ^= USBMASK; 62 USBOUT ^= USBMASK;
62 63
63 _delay_ms(25); 64 wait_ms(25);
64 65
65 USBOUT ^= USBMASK; 66 USBOUT ^= USBMASK;
66 USBDDR = ddr_orig; 67 USBDDR = ddr_orig;
@@ -74,7 +75,6 @@ static void usb_remote_wakeup(void) {
74 * FIXME: Needs doc 75 * FIXME: Needs doc
75 */ 76 */
76static void setup_usb(void) { 77static void setup_usb(void) {
77 // debug("initForUsbConnectivity()\n");
78 initForUsbConnectivity(); 78 initForUsbConnectivity();
79 79
80 // for Console_Task 80 // for Console_Task
@@ -95,10 +95,7 @@ int main(void) {
95#ifdef CLKPR 95#ifdef CLKPR
96 // avoid unintentional changes of clock frequency in devices that have a 96 // avoid unintentional changes of clock frequency in devices that have a
97 // clock prescaler 97 // clock prescaler
98 CLKPR = 0x80, CLKPR = 0; 98 clock_prescale_set(clock_div_1);
99#endif
100#ifndef NO_UART
101 uart_init(UART_BAUD_RATE);
102#endif 99#endif
103 keyboard_setup(); 100 keyboard_setup();
104 101
@@ -113,7 +110,6 @@ int main(void) {
113 sleep_led_init(); 110 sleep_led_init();
114#endif 111#endif
115 112
116 debug("main loop\n");
117 while (1) { 113 while (1) {
118#if USB_COUNT_SOF 114#if USB_COUNT_SOF
119 if (usbSofCount != 0) { 115 if (usbSofCount != 0) {
@@ -130,19 +126,6 @@ int main(void) {
130# ifdef SLEEP_LED_ENABLE 126# ifdef SLEEP_LED_ENABLE
131 sleep_led_enable(); 127 sleep_led_enable();
132# endif 128# endif
133 /*
134 uart_putchar('S');
135 _delay_ms(1);
136 cli();
137 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
138 sleep_enable();
139 sleep_bod_disable();
140 sei();
141 sleep_cpu();
142 sleep_disable();
143 _delay_ms(10);
144 uart_putchar('W');
145 */
146 } 129 }
147 } 130 }
148#endif 131#endif
diff --git a/tmk_core/protocol/vusb/sendchar_usart.c b/tmk_core/protocol/vusb/sendchar_usart.c
deleted file mode 100644
index a920a9a53..000000000
--- a/tmk_core/protocol/vusb/sendchar_usart.c
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
3 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
4 */
5#include <stdint.h>
6#include <usbdrv/oddebug.h>
7#include "sendchar.h"
8
9#if DEBUG_LEVEL > 0
10/* from oddebug.c */
11int8_t sendchar(uint8_t c) {
12 while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
13 ; /* wait for data register empty */
14 ODDBG_UDR = c;
15 return 1;
16}
17#else
18int8_t sendchar(uint8_t c) { return 1; }
19#endif
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index f4727a0c3..735a1c1d3 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,10 +15,12 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <avr/wdt.h>
19#include <util/delay.h>
20#include <stdint.h> 18#include <stdint.h>
19
20#include <avr/wdt.h>
21
21#include <usbdrv/usbdrv.h> 22#include <usbdrv/usbdrv.h>
23
22#include "usbconfig.h" 24#include "usbconfig.h"
23#include "host.h" 25#include "host.h"
24#include "report.h" 26#include "report.h"
@@ -26,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "vusb.h" 28#include "vusb.h"
27#include "print.h" 29#include "print.h"
28#include "debug.h" 30#include "debug.h"
31#include "wait.h"
29#include "usb_descriptor_common.h" 32#include "usb_descriptor_common.h"
30 33
31#ifdef RAW_ENABLE 34#ifdef RAW_ENABLE
@@ -56,7 +59,7 @@ enum usb_interfaces {
56#ifdef CONSOLE_ENABLE 59#ifdef CONSOLE_ENABLE
57 CONSOLE_INTERFACE = NEXT_INTERFACE, 60 CONSOLE_INTERFACE = NEXT_INTERFACE,
58#endif 61#endif
59 TOTAL_INTERFACES = NEXT_INTERFACE, 62 TOTAL_INTERFACES = NEXT_INTERFACE
60}; 63};
61 64
62#define MAX_INTERFACES 2 65#define MAX_INTERFACES 2
@@ -86,19 +89,13 @@ void vusb_transfer_keyboard(void) {
86 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); 89 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
87 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; 90 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
88 if (debug_keyboard) { 91 if (debug_keyboard) {
89 print("V-USB: kbuf["); 92 dprintf("V-USB: kbuf[%d->%d](%02X)\n", kbuf_tail, kbuf_head, (kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
90 pdec(kbuf_tail);
91 print("->");
92 pdec(kbuf_head);
93 print("](");
94 phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
95 print(")\n");
96 } 93 }
97 } 94 }
98 break; 95 break;
99 } 96 }
100 usbPoll(); 97 usbPoll();
101 _delay_ms(1); 98 wait_ms(1);
102 } 99 }
103} 100}
104 101
@@ -220,7 +217,7 @@ static void send_keyboard(report_keyboard_t *report) {
220 kbuf[kbuf_head] = *report; 217 kbuf[kbuf_head] = *report;
221 kbuf_head = next; 218 kbuf_head = next;
222 } else { 219 } else {
223 debug("kbuf: full\n"); 220 dprint("kbuf: full\n");
224 } 221 }
225 222
226 // NOTE: send key strokes of Macro 223 // NOTE: send key strokes of Macro
@@ -283,37 +280,35 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
283 280
284 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ 281 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
285 if (rq->bRequest == USBRQ_HID_GET_REPORT) { 282 if (rq->bRequest == USBRQ_HID_GET_REPORT) {
286 debug("GET_REPORT:"); 283 dprint("GET_REPORT:");
287 if (rq->wIndex.word == KEYBOARD_INTERFACE) { 284 if (rq->wIndex.word == KEYBOARD_INTERFACE) {
288 usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; 285 usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
289 return sizeof(keyboard_report_sent); 286 return sizeof(keyboard_report_sent);
290 } 287 }
291 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { 288 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
292 debug("GET_IDLE: "); 289 dprint("GET_IDLE:");
293 // debug_hex(vusb_idle_rate);
294 usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; 290 usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
295 return 1; 291 return 1;
296 } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { 292 } else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
297 vusb_idle_rate = rq->wValue.bytes[1]; 293 vusb_idle_rate = rq->wValue.bytes[1];
298 debug("SET_IDLE: "); 294 dprintf("SET_IDLE: %02X", vusb_idle_rate);
299 debug_hex(vusb_idle_rate);
300 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { 295 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
301 debug("SET_REPORT: "); 296 dprint("SET_REPORT:");
302 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) 297 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
303 if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { 298 if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
304 debug("SET_LED: "); 299 dprint("SET_LED:");
305 last_req.kind = SET_LED; 300 last_req.kind = SET_LED;
306 last_req.len = rq->wLength.word; 301 last_req.len = rq->wLength.word;
307 } 302 }
308 return USB_NO_MSG; // to get data in usbFunctionWrite 303 return USB_NO_MSG; // to get data in usbFunctionWrite
309 } else { 304 } else {
310 debug("UNKNOWN:"); 305 dprint("UNKNOWN:");
311 } 306 }
312 } else { 307 } else {
313 debug("VENDOR:"); 308 dprint("VENDOR:");
314 /* no vendor specific requests implemented */ 309 /* no vendor specific requests implemented */
315 } 310 }
316 debug("\n"); 311 dprint("\n");
317 return 0; /* default for not implemented requests: return no data back to host */ 312 return 0; /* default for not implemented requests: return no data back to host */
318} 313}
319 314
@@ -323,9 +318,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
323 } 318 }
324 switch (last_req.kind) { 319 switch (last_req.kind) {
325 case SET_LED: 320 case SET_LED:
326 debug("SET_LED: "); 321 dprintf("SET_LED: %02X\n", data[0]);
327 debug_hex(data[0]);
328 debug("\n");
329 keyboard_led_state = data[0]; 322 keyboard_led_state = data[0];
330 last_req.len = 0; 323 last_req.len = 0;
331 return 1; 324 return 1;
@@ -342,13 +335,13 @@ void usbFunctionWriteOut(uchar *data, uchar len) {
342#ifdef RAW_ENABLE 335#ifdef RAW_ENABLE
343 // Data from host must be divided every 8bytes 336 // Data from host must be divided every 8bytes
344 if (len != 8) { 337 if (len != 8) {
345 debug("RAW: invalid length"); 338 dprint("RAW: invalid length\n");
346 raw_output_received_bytes = 0; 339 raw_output_received_bytes = 0;
347 return; 340 return;
348 } 341 }
349 342
350 if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) { 343 if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
351 debug("RAW: buffer full"); 344 dprint("RAW: buffer full\n");
352 raw_output_received_bytes = 0; 345 raw_output_received_bytes = 0;
353 } else { 346 } else {
354 for (uint8_t i = 0; i < 8; i++) { 347 for (uint8_t i = 0; i < 8; i++) {
@@ -404,29 +397,6 @@ const PROGMEM uchar keyboard_hid_report[] = {
404 0xC0 // End Collection 397 0xC0 // End Collection
405}; 398};
406 399
407#ifdef RAW_ENABLE
408const PROGMEM uchar raw_hid_report[] = {
409 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
410 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
411 0xA1, 0x01, // Collection (Application)
412 // Data to host
413 0x09, 0x62, // Usage (Vendor Defined)
414 0x15, 0x00, // Logical Minimum (0)
415 0x26, 0xFF, 0x00, // Logical Maximum (255)
416 0x95, RAW_BUFFER_SIZE, // Report Count
417 0x75, 0x08, // Report Size (8)
418 0x81, 0x02, // Input (Data, Variable, Absolute)
419 // Data from host
420 0x09, 0x63, // Usage (Vendor Defined)
421 0x15, 0x00, // Logical Minimum (0)
422 0x26, 0xFF, 0x00, // Logical Maximum (255)
423 0x95, RAW_BUFFER_SIZE, // Report Count
424 0x75, 0x08, // Report Size (8)
425 0x91, 0x02, // Output (Data, Variable, Absolute)
426 0xC0 // End Collection
427};
428#endif
429
430#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) 400#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
431const PROGMEM uchar mouse_extra_hid_report[] = { 401const PROGMEM uchar mouse_extra_hid_report[] = {
432# ifdef MOUSE_ENABLE 402# ifdef MOUSE_ENABLE
@@ -511,6 +481,29 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
511}; 481};
512#endif 482#endif
513 483
484#ifdef RAW_ENABLE
485const PROGMEM uchar raw_hid_report[] = {
486 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
487 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
488 0xA1, 0x01, // Collection (Application)
489 // Data to host
490 0x09, 0x62, // Usage (Vendor Defined)
491 0x15, 0x00, // Logical Minimum (0)
492 0x26, 0xFF, 0x00, // Logical Maximum (255)
493 0x95, RAW_BUFFER_SIZE, // Report Count
494 0x75, 0x08, // Report Size (8)
495 0x81, 0x02, // Input (Data, Variable, Absolute)
496 // Data from host
497 0x09, 0x63, // Usage (Vendor Defined)
498 0x15, 0x00, // Logical Minimum (0)
499 0x26, 0xFF, 0x00, // Logical Maximum (255)
500 0x95, RAW_BUFFER_SIZE, // Report Count
501 0x75, 0x08, // Report Size (8)
502 0x91, 0x02, // Output (Data, Variable, Absolute)
503 0xC0 // End Collection
504};
505#endif
506
514#if defined(CONSOLE_ENABLE) 507#if defined(CONSOLE_ENABLE)
515const PROGMEM uchar console_hid_report[] = { 508const PROGMEM uchar console_hid_report[] = {
516 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible) 509 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
@@ -801,14 +794,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
801USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) { 794USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
802 usbMsgLen_t len = 0; 795 usbMsgLen_t len = 0;
803 796
804 /*
805 debug("usbFunctionDescriptor: ");
806 debug_hex(rq->bmRequestType); debug(" ");
807 debug_hex(rq->bRequest); debug(" ");
808 debug_hex16(rq->wValue.word); debug(" ");
809 debug_hex16(rq->wIndex.word); debug(" ");
810 debug_hex16(rq->wLength.word); debug("\n");
811 */
812 switch (rq->wValue.bytes[1]) { 797 switch (rq->wValue.bytes[1]) {
813 case USBDESCR_DEVICE: 798 case USBDESCR_DEVICE:
814 usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor; 799 usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
@@ -892,6 +877,5 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
892 } 877 }
893 break; 878 break;
894 } 879 }
895 // debug("desc len: "); debug_hex(len); debug("\n");
896 return len; 880 return len;
897} 881}