Skip to content

Commit 089ab15

Browse files
yuleimteipreconditionkosorin
authored
update chibios os usb for the otg driver (qmk#8893)
* add support for otg * update endpoint numbering for stm32f4 * removed testing file * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (qmk#10824) Add a Make variable to easily enable DEBUG_MATRIX_SCAN_RATE on the command line. eg. ``` make DEBUG_MATRIX_SCAN_RATE_ENABLE=yes KEYBOARD:KEYMAP ``` * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (qmk#10549) * Added `add_oneshot_mods` & `del_oneshot_mods` Deleted undefined and unused prototypes: - void oneshot_enable(void) - void oneshot_disable(void) - void oneshot_toggle(void) Reordered the oneshot functions to follow the same order as other mod functions, that is to say : get, add, del, set, clear * Stricter conditions on add_oneshot_mods & del_oneshot_mods Prevent extending the one shot timer if the called add_oneshot_mods or del_oneshot_mods do not change anything to the current one shot mod state. Co-authored-by: David Kosorin <[email protected]> Co-authored-by: David Kosorin <[email protected]> * add support for otg * update endpoint numbering for stm32f4 * removed testing file * added missing #endif Co-authored-by: Takeshi ISHII <[email protected]> Co-authored-by: precondition <[email protected]> Co-authored-by: David Kosorin <[email protected]>
1 parent 86e03ae commit 089ab15

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

tmk_core/protocol/chibios/usb_main.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ static const USBEndpointConfig shared_ep_config = {
165165
};
166166
#endif
167167

168+
#if STM32_USB_USE_OTG1
169+
typedef struct {
170+
size_t queue_capacity_in;
171+
size_t queue_capacity_out;
172+
USBInEndpointState in_ep_state;
173+
USBOutEndpointState out_ep_state;
174+
USBInEndpointState int_ep_state;
175+
USBEndpointConfig inout_ep_config;
176+
USBEndpointConfig int_ep_config;
177+
const QMKUSBConfig config;
178+
QMKUSBDriver driver;
179+
} usb_driver_config_t;
180+
#else
168181
typedef struct {
169182
size_t queue_capacity_in;
170183
size_t queue_capacity_out;
@@ -177,7 +190,54 @@ typedef struct {
177190
const QMKUSBConfig config;
178191
QMKUSBDriver driver;
179192
} usb_driver_config_t;
193+
#endif
180194

195+
#if STM32_USB_USE_OTG1
196+
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
197+
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
198+
{ \
199+
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
200+
.inout_ep_config = \
201+
{ \
202+
stream##_IN_MODE, /* Interrupt EP */ \
203+
NULL, /* SETUP packet notification callback */ \
204+
qmkusbDataTransmitted, /* IN notification callback */ \
205+
qmkusbDataReceived, /* OUT notification callback */ \
206+
stream##_EPSIZE, /* IN maximum packet size */ \
207+
stream##_EPSIZE, /* OUT maximum packet size */ \
208+
NULL, /* IN Endpoint state */ \
209+
NULL, /* OUT endpoint state */ \
210+
2, /* IN multiplier */ \
211+
NULL /* SETUP buffer (not a SETUP endpoint) */ \
212+
}, \
213+
.int_ep_config = \
214+
{ \
215+
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
216+
NULL, /* SETUP packet notification callback */ \
217+
qmkusbInterruptTransmitted, /* IN notification callback */ \
218+
NULL, /* OUT notification callback */ \
219+
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
220+
0, /* OUT maximum packet size */ \
221+
NULL, /* IN Endpoint state */ \
222+
NULL, /* OUT endpoint state */ \
223+
2, /* IN multiplier */ \
224+
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
225+
}, \
226+
.config = { \
227+
.usbp = &USB_DRIVER, \
228+
.bulk_in = stream##_IN_EPNUM, \
229+
.bulk_out = stream##_OUT_EPNUM, \
230+
.int_in = notification, \
231+
.in_buffers = stream##_IN_CAPACITY, \
232+
.out_buffers = stream##_OUT_CAPACITY, \
233+
.in_size = stream##_EPSIZE, \
234+
.out_size = stream##_EPSIZE, \
235+
.fixed_size = fixedsize, \
236+
.ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
237+
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
238+
} \
239+
}
240+
#else
181241
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
182242
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
183243
{ \
@@ -235,6 +295,7 @@ typedef struct {
235295
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
236296
} \
237297
}
298+
#endif
238299

239300
typedef struct {
240301
union {
@@ -327,8 +388,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
327388
usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
328389
#endif
329390
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
391+
#if STM32_USB_USE_OTG1
392+
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
393+
#else
330394
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
331395
usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
396+
#endif
332397
if (drivers.array[i].config.int_in) {
333398
usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
334399
}
@@ -553,12 +618,21 @@ static const USBConfig usbcfg = {
553618
*/
554619
void init_usb_driver(USBDriver *usbp) {
555620
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
621+
#if STM32_USB_USE_OTG1
622+
QMKUSBDriver *driver = &drivers.array[i].driver;
623+
drivers.array[i].inout_ep_config.in_state = &drivers.array[i].in_ep_state;
624+
drivers.array[i].inout_ep_config.out_state = &drivers.array[i].out_ep_state;
625+
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
626+
qmkusbObjectInit(driver, &drivers.array[i].config);
627+
qmkusbStart(driver, &drivers.array[i].config);
628+
#else
556629
QMKUSBDriver *driver = &drivers.array[i].driver;
557630
drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
558631
drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
559632
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
560633
qmkusbObjectInit(driver, &drivers.array[i].config);
561634
qmkusbStart(driver, &drivers.array[i].config);
635+
#endif
562636
}
563637

564638
/*

tmk_core/protocol/usb_descriptor.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ enum usb_endpoints {
205205

206206
#ifdef RAW_ENABLE
207207
RAW_IN_EPNUM = NEXT_EPNUM,
208+
#if STM32_USB_USE_OTG1
209+
#define RAW_OUT_EPNUM RAW_IN_EPNUM
210+
#else
208211
RAW_OUT_EPNUM = NEXT_EPNUM,
212+
#endif
209213
#endif
210214

211215
#ifdef SHARED_EP_ENABLE
@@ -219,25 +223,41 @@ enum usb_endpoints {
219223
// ChibiOS has enough memory and descriptor to actually enable the endpoint
220224
// It could use the same endpoint numbers, as that's supported by ChibiOS
221225
// But the QMK code currently assumes that the endpoint numbers are different
226+
#if STM32_USB_USE_OTG1
227+
#define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
228+
#else
222229
CONSOLE_OUT_EPNUM = NEXT_EPNUM,
230+
#endif
223231
# else
224232
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
225233
# endif
226234
#endif
227235

228236
#ifdef MIDI_ENABLE
229237
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
238+
#if STM32_USB_USE_OTG1
239+
#define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
240+
#else
230241
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
242+
#endif
231243
#endif
232244

233245
#ifdef VIRTSER_ENABLE
234246
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
235247
CDC_IN_EPNUM = NEXT_EPNUM,
248+
#if STM32_USB_USE_OTG1
249+
#define CDC_OUT_EPNUM CDC_IN_EPNUM
250+
#else
236251
CDC_OUT_EPNUM = NEXT_EPNUM,
252+
#endif
237253
#endif
238254
#ifdef JOYSTICK_ENABLE
239255
JOYSTICK_IN_EPNUM = NEXT_EPNUM,
256+
#if STM32_USB_USE_OTG1
257+
JOYSTICK_OUT_EPNUM = JOYSTICK_IN_EPNUM,
258+
#else
240259
JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
260+
#endif
241261
#endif
242262
};
243263

0 commit comments

Comments
 (0)