Skip to content

Commit

Permalink
update chibios os usb for the otg driver (#8893)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
4 people authored Nov 10, 2020
1 parent 3dcb046 commit 55e2a42
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ static const USBEndpointConfig shared_ep_config = {
};
#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 {
size_t queue_capacity_in;
size_t queue_capacity_out;
Expand All @@ -177,7 +190,54 @@ typedef struct {
const QMKUSBConfig config;
QMKUSBDriver driver;
} 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 */
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
{ \
Expand Down Expand Up @@ -235,6 +295,7 @@ typedef struct {
.ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
} \
}
#endif

typedef struct {
union {
Expand Down Expand Up @@ -327,8 +388,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
#endif
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_out, &drivers.array[i].out_ep_config);
#endif
if (drivers.array[i].config.int_in) {
usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
}
Expand Down Expand Up @@ -553,12 +618,21 @@ static const USBConfig usbcfg = {
*/
void init_usb_driver(USBDriver *usbp) {
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;
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].int_ep_config.in_state = &drivers.array[i].int_ep_state;
qmkusbObjectInit(driver, &drivers.array[i].config);
qmkusbStart(driver, &drivers.array[i].config);
#endif
}

/*
Expand Down
20 changes: 20 additions & 0 deletions tmk_core/protocol/usb_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ enum usb_endpoints {

#ifdef RAW_ENABLE
RAW_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
#define RAW_OUT_EPNUM RAW_IN_EPNUM
#else
RAW_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif

#ifdef SHARED_EP_ENABLE
Expand All @@ -219,25 +223,41 @@ enum usb_endpoints {
// ChibiOS has enough memory and descriptor to actually enable the endpoint
// 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
#if STM32_USB_USE_OTG1
#define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
#else
CONSOLE_OUT_EPNUM = NEXT_EPNUM,
#endif
# else
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# endif
#endif

#ifdef MIDI_ENABLE
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,
#endif
#endif

#ifdef VIRTSER_ENABLE
CDC_NOTIFICATION_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,
#endif
#endif
#ifdef JOYSTICK_ENABLE
JOYSTICK_IN_EPNUM = NEXT_EPNUM,
#if STM32_USB_USE_OTG1
JOYSTICK_OUT_EPNUM = JOYSTICK_IN_EPNUM,
#else
JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
#endif
#endif
};

Expand Down

0 comments on commit 55e2a42

Please sign in to comment.