update chibios os usb for the otg driver (#8893)

* add support for otg

* update endpoint numbering for stm32f4

* removed testing file

* add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#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` (#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 <david@kosorin.net>

Co-authored-by: David Kosorin <david@kosorin.net>

* add support for otg

* update endpoint numbering for stm32f4

* removed testing file

* added missing #endif

Co-authored-by: Takeshi ISHII <2170248+mtei@users.noreply.github.com>
Co-authored-by: precondition <57645186+precondition@users.noreply.github.com>
Co-authored-by: David Kosorin <david@kosorin.net>
This commit is contained in:
yulei 2020-11-11 00:17:42 +08:00 committed by GitHub
parent 3dcb0463ad
commit 55e2a42047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 0 deletions

View file

@ -165,6 +165,19 @@ static const USBEndpointConfig shared_ep_config = {
}; };
#endif #endif
#if STM32_USB_USE_OTG1
typedef struct {
size_t queue_capacity_in;
size_t queue_capacity_out;
USBInEndpointState in_ep_state;
USBOutEndpointState out_ep_state;
USBInEndpointState int_ep_state;
USBEndpointConfig inout_ep_config;
USBEndpointConfig int_ep_config;
const QMKUSBConfig config;
QMKUSBDriver driver;
} usb_driver_config_t;
#else
typedef struct { typedef struct {
size_t queue_capacity_in; size_t queue_capacity_in;
size_t queue_capacity_out; size_t queue_capacity_out;
@ -177,7 +190,54 @@ typedef struct {
const QMKUSBConfig config; const QMKUSBConfig config;
QMKUSBDriver driver; QMKUSBDriver driver;
} usb_driver_config_t; } usb_driver_config_t;
#endif
#if STM32_USB_USE_OTG1
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
{ \
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
.inout_ep_config = \
{ \
stream##_IN_MODE, /* Interrupt EP */ \
NULL, /* SETUP packet notification callback */ \
qmkusbDataTransmitted, /* IN notification callback */ \
qmkusbDataReceived, /* OUT notification callback */ \
stream##_EPSIZE, /* IN maximum packet size */ \
stream##_EPSIZE, /* OUT maximum packet size */ \
NULL, /* IN Endpoint state */ \
NULL, /* OUT endpoint state */ \
2, /* IN multiplier */ \
NULL /* SETUP buffer (not a SETUP endpoint) */ \
}, \
.int_ep_config = \
{ \
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
NULL, /* SETUP packet notification callback */ \
qmkusbInterruptTransmitted, /* IN notification callback */ \
NULL, /* OUT notification callback */ \
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
0, /* OUT maximum packet size */ \
NULL, /* IN Endpoint state */ \
NULL, /* OUT endpoint state */ \
2, /* IN multiplier */ \
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
}, \
.config = { \
.usbp = &USB_DRIVER, \
.bulk_in = stream##_IN_EPNUM, \
.bulk_out = stream##_OUT_EPNUM, \
.int_in = notification, \
.in_buffers = stream##_IN_CAPACITY, \
.out_buffers = stream##_OUT_CAPACITY, \
.in_size = stream##_EPSIZE, \
.out_size = stream##_EPSIZE, \
.fixed_size = fixedsize, \
.ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
} \
}
#else
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */ /* Reusable initialization structure - see USBEndpointConfig comment at top of file */
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \ #define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
{ \ { \
@ -235,6 +295,7 @@ typedef struct {
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \ .ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
} \ } \
} }
#endif
typedef struct { typedef struct {
union { union {
@ -327,8 +388,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config); usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
#endif #endif
for (int i = 0; i < NUM_USB_DRIVERS; i++) { for (int i = 0; i < NUM_USB_DRIVERS; i++) {
#if STM32_USB_USE_OTG1
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
#else
usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config); usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config); usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
#endif
if (drivers.array[i].config.int_in) { if (drivers.array[i].config.int_in) {
usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config); usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
} }
@ -553,12 +618,21 @@ static const USBConfig usbcfg = {
*/ */
void init_usb_driver(USBDriver *usbp) { void init_usb_driver(USBDriver *usbp) {
for (int i = 0; i < NUM_USB_DRIVERS; i++) { for (int i = 0; i < NUM_USB_DRIVERS; i++) {
#if STM32_USB_USE_OTG1
QMKUSBDriver *driver = &drivers.array[i].driver;
drivers.array[i].inout_ep_config.in_state = &drivers.array[i].in_ep_state;
drivers.array[i].inout_ep_config.out_state = &drivers.array[i].out_ep_state;
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
qmkusbObjectInit(driver, &drivers.array[i].config);
qmkusbStart(driver, &drivers.array[i].config);
#else
QMKUSBDriver *driver = &drivers.array[i].driver; QMKUSBDriver *driver = &drivers.array[i].driver;
drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state; drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state; drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state; drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
qmkusbObjectInit(driver, &drivers.array[i].config); qmkusbObjectInit(driver, &drivers.array[i].config);
qmkusbStart(driver, &drivers.array[i].config); qmkusbStart(driver, &drivers.array[i].config);
#endif
} }
/* /*

View file

@ -205,7 +205,11 @@ enum usb_endpoints {
#ifdef RAW_ENABLE #ifdef RAW_ENABLE
RAW_IN_EPNUM = NEXT_EPNUM, RAW_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
#define RAW_OUT_EPNUM RAW_IN_EPNUM
#else
RAW_OUT_EPNUM = NEXT_EPNUM, RAW_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif #endif
#ifdef SHARED_EP_ENABLE #ifdef SHARED_EP_ENABLE
@ -219,7 +223,11 @@ enum usb_endpoints {
// ChibiOS has enough memory and descriptor to actually enable the endpoint // ChibiOS has enough memory and descriptor to actually enable the endpoint
// It could use the same endpoint numbers, as that's supported by ChibiOS // It could use the same endpoint numbers, as that's supported by ChibiOS
// But the QMK code currently assumes that the endpoint numbers are different // But the QMK code currently assumes that the endpoint numbers are different
#if STM32_USB_USE_OTG1
#define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
#else
CONSOLE_OUT_EPNUM = NEXT_EPNUM, CONSOLE_OUT_EPNUM = NEXT_EPNUM,
#endif
# else # else
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM # define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# endif # endif
@ -227,17 +235,29 @@ enum usb_endpoints {
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM, MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
#define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
#else
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM, MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif #endif
#ifdef VIRTSER_ENABLE #ifdef VIRTSER_ENABLE
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM, CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
CDC_IN_EPNUM = NEXT_EPNUM, CDC_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
#define CDC_OUT_EPNUM CDC_IN_EPNUM
#else
CDC_OUT_EPNUM = NEXT_EPNUM, CDC_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif #endif
#ifdef JOYSTICK_ENABLE #ifdef JOYSTICK_ENABLE
JOYSTICK_IN_EPNUM = NEXT_EPNUM, JOYSTICK_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
JOYSTICK_OUT_EPNUM = JOYSTICK_IN_EPNUM,
#else
JOYSTICK_OUT_EPNUM = NEXT_EPNUM, JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif #endif
}; };