Skip to content

Commit

Permalink
shared/tinyusb: Add USBD_CDC class to access usb serial port.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Oct 27, 2024
1 parent a231a63 commit ab8bfd4
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 14 deletions.
7 changes: 7 additions & 0 deletions extmod/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "extmod/modmachine.h"
#include "shared/runtime/pyexec.h"

#if MICROPY_HW_USB_CDC
#include "shared/tinyusb/mp_usbd_cdc.h"
#endif

#if MICROPY_PY_MACHINE_DHT_READINTO
#include "drivers/dht/dht.h"
#endif
Expand Down Expand Up @@ -234,6 +238,9 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = {
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
{ MP_ROM_QSTR(MP_QSTR_USBDevice), MP_ROM_PTR(&machine_usb_device_type) },
#endif
#if MICROPY_HW_USB_CDC
{ MP_ROM_QSTR(MP_QSTR_USBD_CDC), MP_ROM_PTR(&machine_usbd_cdc_type) },
#endif
#if MICROPY_PY_MACHINE_WDT
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) },
#endif
Expand Down
5 changes: 5 additions & 0 deletions shared/tinyusb/mp_usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "py/obj.h"
#include "py/objarray.h"
#include "py/runtime.h"
#include "mp_usbd_cdc.h"

#ifndef NO_QSTR
#include "tusb.h"
Expand All @@ -45,6 +46,10 @@ static inline void mp_usbd_init_tud(void) {
tusb_init();
tud_cdc_configure_fifo_t cfg = { .rx_persistent = 0, .tx_persistent = 1 };
tud_cdc_configure_fifo(&cfg);

#if MICROPY_HW_USB_CDC
machine_usbd_cdc_init0();
#endif
}

// Run the TinyUSB device task
Expand Down
Loading

0 comments on commit ab8bfd4

Please sign in to comment.