8000 shared/tinyusb: Allow ports to use 1200bps-touch without other CDC code. · micropython/micropython@84a8f7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 84a8f7e

Browse files
committed
shared/tinyusb: Allow ports to use 1200bps-touch without other CDC code.
This fixes the build for some esp32 and nrf boards (for example `ARDUINO_NANO_33_BLE_SENSE` and `ARDUINO_NANO_ESP32`) due to commit c98789a. Changes are: - Allow the CDC TX/RX functions in `mp_usbd_cdc.c` to be enabled separately to those needed for `MICROPY_HW_USB_CDC_1200BPS_TOUCH`. - Add `MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC` option as a temporary workaround for the nrf port to use. - Declare `mp_usbd_line_state_cb()` in a header as a public function. - Fix warning with type cast of `.callback_line_state_changed`. Signed-off-by: Damien George <damien@micropython.org>
1 parent c1a6b95 commit 84a8f7e

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

ports/esp32/boards/ARDUINO_NANO_ESP32/board_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <string.h>
2828
#include "py/mphal.h"
29+
#include "shared/tinyusb/mp_usbd_cdc.h"
2930

3031
#include <esp_system.h>
3132
#include <esp_ota_ops.h>
@@ -87,7 +88,6 @@ void NANO_ESP32_enter_bootloader(void) {
8788
}
8889

8990
void NANO_ESP32_usb_callback_line_state_changed(int itf, void *event_in) {
90-
extern void mp_usbd_line_state_cb(uint8_t itf, bool dtr, bool rts);
9191
cdcacm_event_t *event = event_in;
9292
mp_usbd_line_state_cb(itf, event->line_state_changed_data.dtr, event->line_state_changed_data.rts);
9393
}

ports/esp32/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void usb_init(void) {
7979
.callback_rx_wanted_char = &MICROPY_HW_USB_CUSTOM_RX_WANTED_CHAR_CB,
8080
#endif
8181
#ifdef MICROPY_HW_USB_CUSTOM_LINE_STATE_CB
82-
.callback_line_state_changed = &MICROPY_HW_USB_CUSTOM_LINE_STATE_CB,
82+
.callback_line_state_changed = (tusb_cdcacm_callback_t)&MICROPY_HW_USB_CUSTOM_LINE_STATE_CB,
8383
#endif
8484
#ifdef MICROPY_HW_USB_CUSTOM_LINE_CODING_CB
8585
.callback_line_coding_changed = &MICROPY_HW_USB_CUSTOM_LINE_CODING_CB,

ports/nrf/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ long unsigned int rng_generate_random_word(void);
335335
#if MICROPY_HW_USB_CDC
336336
#include "device/usbd.h"
337337
#define MICROPY_HW_USBDEV_TASK_HOOK extern void tud_task(void); tud_task();
338+
#define MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC (1)
338339
#else
339340
#define MICROPY_HW_USBDEV_TASK_HOOK ;
340341
#endif

shared/tinyusb/mp_usbd_cdc.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626

2727
#include "py/runtime.h"
2828
#include "py/mphal.h"
29-
#include "py/mpconfig.h"
3029
#include "py/stream.h"
3130
#include "extmod/modmachine.h"
3231

33-
#if MICROPY_HW_USB_CDC && MICROPY_HW_ENABLE_USBDEV
34-
#include "tusb.h"
35-
#include "device/usbd.h"
36-
37-
#include "mp_usbd_cdc.h"
3832
#include "mp_usbd.h"
33+
#include "mp_usbd_cdc.h"
34+
35+
#if MICROPY_HW_USB_CDC && MICROPY_HW_ENABLE_USBDEV && !MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC
3936

4037
static uint8_t cdc_itf_pending; // keep track of cdc interfaces which need attention to poll
4138

@@ -122,6 +119,8 @@ mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) {
122119
return i;
123120
}
124121

122+
#endif
123+
125124
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH && MICROPY_HW_ENABLE_USBDEV
126125

127126
static mp_sched_node_t mp_bootloader_sched_node;
@@ -150,4 +149,3 @@ tud_cdc_line_state_cb
150149
}
151150

152151
#endif
153-
#endif

shared/tinyusb/mp_usbd_cdc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ uintptr_t mp_usbd_cdc_poll_interfaces(uintptr_t poll_flags);
3535
void tud_cdc_rx_cb(uint8_t itf);
3636
mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len);
3737

38+
#if MICROPY_HW_USB_EXTERNAL_TINYUSB
39+
void mp_usbd_line_state_cb(uint8_t itf, bool dtr, bool rts);
40+
#endif
3841

3942
#endif // MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_CDC_H

0 commit comments

Comments
 (0)
0