summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2024-01-09 14:01:34 +0000
committerGitHub <noreply@github.com>2024-01-09 14:01:34 +0000
commitb6b3efc14b21117d13ae33a2eda96c5647817d5b (patch)
treea9c686de2276c3980dec5d8afc499a4ea515da95 /tmk_core
parentccec4867c80d25548871e2534d2ca6205891824a (diff)
Remove console out endpoint (#22304)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c103
-rw-r--r--tmk_core/protocol/chibios/usb_main.h3
-rw-r--r--tmk_core/protocol/lufa/lufa.c46
-rw-r--r--tmk_core/protocol/usb_descriptor.c20
-rw-r--r--tmk_core/protocol/usb_descriptor.h14
-rw-r--r--tmk_core/protocol/vusb/vusb.c17
-rw-r--r--tmk_core/protocol/vusb/vusb.h1
7 files changed, 66 insertions, 138 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 66f9ad0318..7b1e641213 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -51,6 +51,11 @@
51extern keymap_config_t keymap_config; 51extern keymap_config_t keymap_config;
52#endif 52#endif
53 53
54#if defined(CONSOLE_ENABLE)
55# define RBUF_SIZE 256
56# include "ring_buffer.h"
57#endif
58
54/* --------------------------------------------------------- 59/* ---------------------------------------------------------
55 * Global interface variables and declarations 60 * Global interface variables and declarations
56 * --------------------------------------------------------- 61 * ---------------------------------------------------------
@@ -217,6 +222,24 @@ static const USBEndpointConfig digitizer_ep_config = {
217}; 222};
218#endif 223#endif
219 224
225#ifdef CONSOLE_ENABLE
226/* Console endpoint state structure */
227static USBInEndpointState console_ep_state;
228
229/* Console endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
230static const USBEndpointConfig console_ep_config = {
231 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
232 NULL, /* SETUP packet notification callback */
233 dummy_usb_cb, /* IN notification callback */
234 NULL, /* OUT notification callback */
235 CONSOLE_EPSIZE, /* IN maximum packet size */
236 0, /* OUT maximum packet size */
237 &console_ep_state, /* IN Endpoint state */
238 NULL, /* OUT endpoint state */
239 usb_lld_endpoint_fields /* USB driver specific endpoint fields */
240};
241#endif
242
220#ifdef USB_ENDPOINTS_ARE_REORDERABLE 243#ifdef USB_ENDPOINTS_ARE_REORDERABLE
221typedef struct { 244typedef struct {
222 size_t queue_capacity_in; 245 size_t queue_capacity_in;
@@ -347,9 +370,6 @@ typedef struct {
347typedef struct { 370typedef struct {
348 union { 371 union {
349 struct { 372 struct {
350#ifdef CONSOLE_ENABLE
351 usb_driver_config_t console_driver;
352#endif
353#ifdef RAW_ENABLE 373#ifdef RAW_ENABLE
354 usb_driver_config_t raw_driver; 374 usb_driver_config_t raw_driver;
355#endif 375#endif
@@ -365,13 +385,6 @@ typedef struct {
365} usb_driver_configs_t; 385} usb_driver_configs_t;
366 386
367static usb_driver_configs_t drivers = { 387static usb_driver_configs_t drivers = {
368#ifdef CONSOLE_ENABLE
369# define CONSOLE_IN_CAPACITY 4
370# define CONSOLE_OUT_CAPACITY 4
371# define CONSOLE_IN_MODE USB_EP_MODE_TYPE_INTR
372# define CONSOLE_OUT_MODE USB_EP_MODE_TYPE_INTR
373 .console_driver = QMK_USB_DRIVER_CONFIG(CONSOLE, 0, true),
374#endif
375#ifdef RAW_ENABLE 388#ifdef RAW_ENABLE
376# ifndef RAW_IN_CAPACITY 389# ifndef RAW_IN_CAPACITY
377# define RAW_IN_CAPACITY 4 390# define RAW_IN_CAPACITY 4
@@ -510,6 +523,9 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
510#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP) 523#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
511 usbInitEndpointI(usbp, DIGITIZER_IN_EPNUM, &digitizer_ep_config); 524 usbInitEndpointI(usbp, DIGITIZER_IN_EPNUM, &digitizer_ep_config);
512#endif 525#endif
526#ifdef CONSOLE_ENABLE
527 usbInitEndpointI(usbp, CONSOLE_IN_EPNUM, &console_ep_config);
528#endif
513 for (int i = 0; i < NUM_USB_DRIVERS; i++) { 529 for (int i = 0; i < NUM_USB_DRIVERS; i++) {
514#ifdef USB_ENDPOINTS_ARE_REORDERABLE 530#ifdef USB_ENDPOINTS_ARE_REORDERABLE
515 usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config); 531 usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
@@ -915,50 +931,35 @@ void send_digitizer(report_digitizer_t *report) {
915#ifdef CONSOLE_ENABLE 931#ifdef CONSOLE_ENABLE
916 932
917int8_t sendchar(uint8_t c) { 933int8_t sendchar(uint8_t c) {
918 static bool timed_out = false; 934 rbuf_enqueue(c);
919 /* The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state. 935 return 0;
920 *
921 * When a 5ms timeout write has timed out, hid_listen is most likely not running, or not
922 * listening to this keyboard, so we go into the timed_out state. In this state we assume
923 * that hid_listen is most likely not gonna be connected to us any time soon, so it would
924 * be wasteful to write follow-up characters with a 5ms timeout, it would all add up and
925 * unncecessarily slow down the firmware. However instead of just dropping the characters,
926 * we write them with a TIME_IMMEDIATE timeout, which is a zero timeout,
927 * and this will succeed only if hid_listen gets connected again. When a write with
928 * TIME_IMMEDIATE timeout succeeds, we know that hid_listen is listening to us again, and
929 * we can go back to the timed_out = false state, and following writes will be executed
930 * with a 5ms timeout. The reason we don't just send all characters with the TIME_IMMEDIATE
931 * timeout is that this could cause bytes to be lost even if hid_listen is running, if there
932 * is a lot of data being sent over the console.
933 *
934 * This logic will work correctly as long as hid_listen is able to receive at least 200
935 * bytes per second. On a heavily overloaded machine that's so overloaded that it's
936 * unusable, and constantly swapping, hid_listen might have trouble receiving 200 bytes per
937 * second, so some bytes might be lost on the console.
938 */
939
940 const sysinterval_t timeout = timed_out ? TIME_IMMEDIATE : TIME_MS2I(5);
941 const size_t result = chnWriteTimeout(&drivers.console_driver.driver, &c, 1, timeout);
942 timed_out = (result == 0);
943 return result;
944}
945
946// Just a dummy function for now, this could be exposed as a weak function
947// Or connected to the actual QMK console
948static void console_receive(uint8_t *data, uint8_t length) {
949 (void)data;
950 (void)length;
951} 936}
952 937
953void console_task(void) { 938void console_task(void) {
954 uint8_t buffer[CONSOLE_EPSIZE]; 939 if (!rbuf_has_data()) {
955 size_t size = 0; 940 return;
956 do { 941 }
957 size = chnReadTimeout(&drivers.console_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE); 942
958 if (size > 0) { 943 osalSysLock();
959 console_receive(buffer, size); 944 if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
960 } 945 osalSysUnlock();
961 } while (size > 0); 946 return;
947 }
948
949 if (usbGetTransmitStatusI(&USB_DRIVER, CONSOLE_IN_EPNUM)) {
950 osalSysUnlock();
951 return;
952 }
953
954 // Send in chunks - padded with zeros to 32
955 char send_buf[CONSOLE_EPSIZE] = {0};
956 uint8_t send_buf_count = 0;
957 while (rbuf_has_data() && send_buf_count < CONSOLE_EPSIZE) {
958 send_buf[send_buf_count++] = rbuf_dequeue();
959 }
960
961 usbStartTransmitI(&USB_DRIVER, CONSOLE_IN_EPNUM, (const uint8_t *)send_buf, CONSOLE_EPSIZE);
962 osalSysUnlock();
962} 963}
963 964
964#endif /* CONSOLE_ENABLE */ 965#endif /* CONSOLE_ENABLE */
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
index 07186f76b8..3fd1e84fe8 100644
--- a/tmk_core/protocol/chibios/usb_main.h
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -57,7 +57,4 @@ void usb_event_queue_task(void);
57/* Putchar over the USB console */ 57/* Putchar over the USB console */
58int8_t sendchar(uint8_t c); 58int8_t sendchar(uint8_t c);
59 59
60/* Flush output (send everything immediately) */
61void console_flush_output(void);
62
63#endif /* CONSOLE_ENABLE */ 60#endif /* CONSOLE_ENABLE */
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 553f69b1e4..22cc0db8ce 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -184,41 +184,16 @@ static void raw_hid_task(void) {
184 * Console 184 * Console
185 ******************************************************************************/ 185 ******************************************************************************/
186#ifdef CONSOLE_ENABLE 186#ifdef CONSOLE_ENABLE
187/** \brief Console Task 187/** \brief Console Tasks
188 * 188 *
189 * FIXME: Needs doc 189 * FIXME: Needs doc
190 */ 190 */
191static void Console_Task(void) { 191static void console_flush_task(void) {
192 /* Device must be connected and configured for the task to run */ 192 /* Device must be connected and configured for the task to run */
193 if (USB_DeviceState != DEVICE_STATE_Configured) return; 193 if (USB_DeviceState != DEVICE_STATE_Configured) return;
194 194
195 uint8_t ep = Endpoint_GetCurrentEndpoint(); 195 uint8_t ep = Endpoint_GetCurrentEndpoint();
196 196
197# if 0
198 // TODO: impl receivechar()/recvchar()
199 Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM);
200
201 /* Check to see if a packet has been sent from the host */
202 if (Endpoint_IsOUTReceived())
203 {
204 /* Check to see if the packet contains data */
205 if (Endpoint_IsReadWriteAllowed())
206 {
207 /* Create a temporary buffer to hold the read in report from the host */
208 uint8_t ConsoleData[CONSOLE_EPSIZE];
209
210 /* Read Console Report Data */
211 Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL);
212
213 /* Process Console Report Data */
214 //ProcessConsoleHIDReport(ConsoleData);
215 }
216
217 /* Finalize the stream transfer to send the last packet */
218 Endpoint_ClearOUT();
219 }
220# endif
221
222 /* IN packet */ 197 /* IN packet */
223 Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); 198 Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
224 if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) { 199 if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
@@ -237,6 +212,10 @@ static void Console_Task(void) {
237 212
238 Endpoint_SelectEndpoint(ep); 213 Endpoint_SelectEndpoint(ep);
239} 214}
215
216void console_task(void) {
217 // do nothing
218}
240#endif 219#endif
241 220
242/******************************************************************************* 221/*******************************************************************************
@@ -341,7 +320,7 @@ void EVENT_USB_Device_StartOfFrame(void) {
341 count = 0; 320 count = 0;
342 321
343 if (!console_flush) return; 322 if (!console_flush) return;
344 Console_Task(); 323 console_flush_task();
345 console_flush = false; 324 console_flush = false;
346} 325}
347 326
@@ -381,9 +360,6 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
381#ifdef CONSOLE_ENABLE 360#ifdef CONSOLE_ENABLE
382 /* Setup console endpoint */ 361 /* Setup console endpoint */
383 ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1); 362 ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
384# if 0
385 ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
386# endif
387#endif 363#endif
388 364
389#ifdef MIDI_ENABLE 365#ifdef MIDI_ENABLE
@@ -627,7 +603,7 @@ int8_t sendchar(uint8_t c) {
627 // The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state. 603 // The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
628 static bool timed_out = false; 604 static bool timed_out = false;
629 605
630 // prevents Console_Task() from running during sendchar() runs. 606 // prevents console_flush_task() from running during sendchar() runs.
631 // or char will be lost. These two function is mutually exclusive. 607 // or char will be lost. These two function is mutually exclusive.
632 CONSOLE_FLUSH_SET(false); 608 CONSOLE_FLUSH_SET(false);
633 609
@@ -812,7 +788,7 @@ static void setup_usb(void) {
812 788
813 USB_Init(); 789 USB_Init();
814 790
815 // for Console_Task 791 // for console_flush_task
816 USB_Device_EnableSOFEvents(); 792 USB_Device_EnableSOFEvents();
817} 793}
818 794
@@ -876,6 +852,10 @@ void protocol_pre_task(void) {
876} 852}
877 853
878void protocol_post_task(void) { 854void protocol_post_task(void) {
855#ifdef CONSOLE_ENABLE
856 console_task();
857#endif
858
879#ifdef MIDI_ENABLE 859#ifdef MIDI_ENABLE
880 MIDI_Device_USBTask(&USB_MIDI_Interface); 860 MIDI_Device_USBTask(&USB_MIDI_Interface);
881#endif 861#endif
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index eb214c0492..0e2e63ad8e 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -420,14 +420,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
420 HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE), 420 HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
421 HID_RI_REPORT_SIZE(8, 0x08), 421 HID_RI_REPORT_SIZE(8, 0x08),
422 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), 422 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
423
424 // Data from host
425 HID_RI_USAGE(8, 0x76), // Vendor Defined
426 HID_RI_LOGICAL_MINIMUM(8, 0x00),
427 HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
428 HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
429 HID_RI_REPORT_SIZE(8, 0x08),
430 HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
431 HID_RI_END_COLLECTION(0), 423 HID_RI_END_COLLECTION(0),
432}; 424};
433#endif 425#endif
@@ -677,7 +669,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
677 }, 669 },
678 .InterfaceNumber = CONSOLE_INTERFACE, 670 .InterfaceNumber = CONSOLE_INTERFACE,
679 .AlternateSetting = 0x00, 671 .AlternateSetting = 0x00,
680 .TotalEndpoints = 2, 672 .TotalEndpoints = 1,
681 .Class = HID_CSCP_HIDClass, 673 .Class = HID_CSCP_HIDClass,
682 .SubClass = HID_CSCP_NonBootSubclass, 674 .SubClass = HID_CSCP_NonBootSubclass,
683 .Protocol = HID_CSCP_NonBootProtocol, 675 .Protocol = HID_CSCP_NonBootProtocol,
@@ -704,16 +696,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
704 .EndpointSize = CONSOLE_EPSIZE, 696 .EndpointSize = CONSOLE_EPSIZE,
705 .PollingIntervalMS = 0x01 697 .PollingIntervalMS = 0x01
706 }, 698 },
707 .Console_OUTEndpoint = {
708 .Header = {
709 .Size = sizeof(USB_Descriptor_Endpoint_t),
710 .Type = DTYPE_Endpoint
711 },
712 .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM),
713 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
714 .EndpointSize = CONSOLE_EPSIZE,
715 .PollingIntervalMS = 0x01
716 },
717#endif 699#endif
718 700
719#ifdef MIDI_ENABLE 701#ifdef MIDI_ENABLE
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index 1268bdae73..2469990f4d 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -97,7 +97,6 @@ typedef struct {
97 USB_Descriptor_Interface_t Console_Interface; 97 USB_Descriptor_Interface_t Console_Interface;
98 USB_HID_Descriptor_HID_t Console_HID; 98 USB_HID_Descriptor_HID_t Console_HID;
99 USB_Descriptor_Endpoint_t Console_INEndpoint; 99 USB_Descriptor_Endpoint_t Console_INEndpoint;
100 USB_Descriptor_Endpoint_t Console_OUTEndpoint;
101#endif 100#endif
102 101
103#ifdef MIDI_ENABLE 102#ifdef MIDI_ENABLE
@@ -232,19 +231,6 @@ enum usb_endpoints {
232 231
233#ifdef CONSOLE_ENABLE 232#ifdef CONSOLE_ENABLE
234 CONSOLE_IN_EPNUM = NEXT_EPNUM, 233 CONSOLE_IN_EPNUM = NEXT_EPNUM,
235
236# ifdef PROTOCOL_CHIBIOS
237// ChibiOS has enough memory and descriptor to actually enable the endpoint
238// It could use the same endpoint numbers, as that's supported by ChibiOS
239// But the QMK code currently assumes that the endpoint numbers are different
240# ifdef USB_ENDPOINTS_ARE_REORDERABLE
241# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
242# else
243 CONSOLE_OUT_EPNUM = NEXT_EPNUM,
244# endif
245# else
246# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
247# endif
248#endif 234#endif
249 235
250#ifdef MIDI_ENABLE 236#ifdef MIDI_ENABLE
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index d09b2f19b7..cfeeed3712 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -717,13 +717,6 @@ const PROGMEM uchar console_hid_report[] = {
717 0x95, CONSOLE_BUFFER_SIZE, // Report Count 717 0x95, CONSOLE_BUFFER_SIZE, // Report Count
718 0x75, 0x08, // Report Size (8) 718 0x75, 0x08, // Report Size (8)
719 0x81, 0x02, // Input (Data, Variable, Absolute) 719 0x81, 0x02, // Input (Data, Variable, Absolute)
720 // Data from host
721 0x09, 0x76, // Usage (Vendor Defined)
722 0x15, 0x00, // Logical Minimum (0x00)
723 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
724 0x95, CONSOLE_BUFFER_SIZE, // Report Count
725 0x75, 0x08, // Report Size (8)
726 0x91, 0x02, // Output (Data)
727 0xC0 // End Collection 720 0xC0 // End Collection
728}; 721};
729#endif 722#endif
@@ -991,16 +984,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
991 .wMaxPacketSize = CONSOLE_EPSIZE, 984 .wMaxPacketSize = CONSOLE_EPSIZE,
992 .bInterval = 0x01 985 .bInterval = 0x01
993 }, 986 },
994 .consoleOUTEndpoint = {
995 .header = {
996 .bLength = sizeof(usbEndpointDescriptor_t),
997 .bDescriptorType = USBDESCR_ENDPOINT
998 },
999 .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER),
1000 .bmAttributes = 0x03,
1001 .wMaxPacketSize = CONSOLE_EPSIZE,
1002 .bInterval = 0x01
1003 }
1004# endif 987# endif
1005}; 988};
1006 989
diff --git a/tmk_core/protocol/vusb/vusb.h b/tmk_core/protocol/vusb/vusb.h
index ae17e5e014..4750e95bf2 100644
--- a/tmk_core/protocol/vusb/vusb.h
+++ b/tmk_core/protocol/vusb/vusb.h
@@ -114,7 +114,6 @@ typedef struct usbConfigurationDescriptor {
114 usbInterfaceDescriptor_t consoleInterface; 114 usbInterfaceDescriptor_t consoleInterface;
115 usbHIDDescriptor_t consoleHID; 115 usbHIDDescriptor_t consoleHID;
116 usbEndpointDescriptor_t consoleINEndpoint; 116 usbEndpointDescriptor_t consoleINEndpoint;
117 usbEndpointDescriptor_t consoleOUTEndpoint;
118#endif 117#endif
119} __attribute__((packed)) usbConfigurationDescriptor_t; 118} __attribute__((packed)) usbConfigurationDescriptor_t;
120 119