From 3d98f6b80a6d74ce31e33588f430a5ec17099620 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Tue, 4 Jul 2023 12:24:35 +0200 Subject: [PATCH] esp32/usb: Add custom TinyUSB callback support. Allow boards to define their own additional USB callbacks. Signed-off-by: Luca Burelli --- ports/esp32/usb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 83ba9533d3..b9d99676d3 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -67,16 +67,22 @@ void usb_init(void) { ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg)); // Initialise the USB serial interface. - tinyusb_config_cdcacm_t amc_cfg = { + tinyusb_config_cdcacm_t acm_cfg = { .usb_dev = TINYUSB_USBDEV_0, .cdc_port = CDC_ITF, .rx_unread_buf_sz = 256, .callback_rx = &usb_callback_rx, - .callback_rx_wanted_char = NULL, - .callback_line_state_changed = NULL, - .callback_line_coding_changed = NULL + #ifdef MICROPY_HW_USB_CUSTOM_RX_WANTED_CHAR_CB + .callback_rx_wanted_char = &MICROPY_HW_USB_CUSTOM_RX_WANTED_CHAR_CB, + #endif + #ifdef MICROPY_HW_USB_CUSTOM_LINE_STATE_CB + .callback_line_state_changed = &MICROPY_HW_USB_CUSTOM_LINE_STATE_CB, + #endif + #ifdef MICROPY_HW_USB_CUSTOM_LINE_CODING_CB + .callback_line_coding_changed = &MICROPY_HW_USB_CUSTOM_LINE_CODING_CB, + #endif }; - ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg)); + ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg)); }