Skip to content

Commit 1bc3485

Browse files
committed
shared/tinyusb: Use TinyUSB wanted_char for interrupt char handling.
Signed-off-by: Andrew Leech <[email protected]>
1 parent f535f30 commit 1bc3485

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

shared/runtime/interrupt_char.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@
2727
#include "py/obj.h"
2828
#include "py/mpstate.h"
2929

30+
#if MICROPY_HW_USB_CDC && MICROPY_HW_ENABLE_USBDEV
31+
#include "shared/tinyusb/mp_usbd_cdc.h"
32+
#endif
33+
3034
#if MICROPY_KBD_EXCEPTION
3135

3236
int mp_interrupt_char = -1;
3337

3438
void mp_hal_set_interrupt_char(int c) {
3539
mp_interrupt_char = c;
40+
41+
#if MICROPY_HW_USB_CDC && MICROPY_HW_ENABLE_USBDEV
42+
machine_usbd_cdc_set_interrupt_char(c);
43+
#endif
3644
}
3745

3846
#endif

shared/tinyusb/mp_usbd_cdc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,24 @@ static void machine_usbd_cdc_print(const mp_print_t *print, mp_obj_t self_in, mp
281281
mp_printf(print, "USBD_CDC()");
282282
}
283283

284+
void machine_usbd_cdc_set_interrupt_char(int c) {
285+
tud_cdc_set_wanted_char(c);
286+
}
287+
288+
284289
static void machine_usbd_cdc_attach_to_repl(const machine_usbd_cdc_obj_t *self, bool attached) {
285290
UNUSED(self);
286291
// self->attached_to_repl = attached;
287292
if (attached) {
288293
// Default behavior is non-blocking when attached to repl
289294
// self->flow &= ~USBD_CDC_FLOWCONTROL_CTS;
290295
#if MICROPY_KBD_EXCEPTION
291-
tud_cdc_set_wanted_char(mp_interrupt_char);
296+
machine_usbd_cdc_set_interrupt_char(mp_interrupt_char);
292297
#endif
293298
} else {
294299
// self->flow |= USBD_CDC_FLOWCONTROL_CTS;
295300
#if MICROPY_KBD_EXCEPTION
296-
tud_cdc_set_wanted_char(-1);
301+
machine_usbd_cdc_set_interrupt_char(-1);
297302
#endif
298303
}
299304
}

shared/tinyusb/mp_usbd_cdc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
void machine_usbd_cdc_init0(void);
4141
// extern const mp_obj_type_t pyb_usb_vcp_type;
4242
extern const mp_obj_type_t machine_usbd_cdc_type;
43-
// extern void machine_usbd_cdc_attach_to_repl(const machine_usbd_cdc_obj_t *self, bool attached);
43+
void machine_usbd_cdc_set_interrupt_char(int c);
4444

4545

4646
uintptr_t mp_usbd_cdc_poll_interfaces(uintptr_t poll_flags);

0 commit comments

Comments
 (0)