Skip to content

Commit

Permalink
shared/tinyusb: Use TinyUSB wanted_char for interrupt char handling.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <andrew@alelec.net>
  • Loading branch information
pi-anl committed Oct 27, 2024
1 parent f535f30 commit 1bc3485
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions shared/runtime/interrupt_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@
#include "py/obj.h"
#include "py/mpstate.h"

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

#if MICROPY_KBD_EXCEPTION

int mp_interrupt_char = -1;

void mp_hal_set_interrupt_char(int c) {
mp_interrupt_char = c;

#if MICROPY_HW_USB_CDC && MICROPY_HW_ENABLE_USBDEV
machine_usbd_cdc_set_interrupt_char(c);
#endif
}

#endif
9 changes: 7 additions & 2 deletions shared/tinyusb/mp_usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,24 @@ static void machine_usbd_cdc_print(const mp_print_t *print, mp_obj_t self_in, mp
mp_printf(print, "USBD_CDC()");
}

void machine_usbd_cdc_set_interrupt_char(int c) {
tud_cdc_set_wanted_char(c);
}


static void machine_usbd_cdc_attach_to_repl(const machine_usbd_cdc_obj_t *self, bool attached) {
UNUSED(self);
// self->attached_to_repl = attached;
if (attached) {
// Default behavior is non-blocking when attached to repl
// self->flow &= ~USBD_CDC_FLOWCONTROL_CTS;
#if MICROPY_KBD_EXCEPTION
tud_cdc_set_wanted_char(mp_interrupt_char);
machine_usbd_cdc_set_interrupt_char(mp_interrupt_char);
#endif
} else {
// self->flow |= USBD_CDC_FLOWCONTROL_CTS;
#if MICROPY_KBD_EXCEPTION
tud_cdc_set_wanted_char(-1);
machine_usbd_cdc_set_interrupt_char(-1);
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared/tinyusb/mp_usbd_cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
void machine_usbd_cdc_init0(void);
// extern const mp_obj_type_t pyb_usb_vcp_type;
extern const mp_obj_type_t machine_usbd_cdc_type;
// extern void machine_usbd_cdc_attach_to_repl(const machine_usbd_cdc_obj_t *self, bool attached);
void machine_usbd_cdc_set_interrupt_char(int c);


uintptr_t mp_usbd_cdc_poll_interfaces(uintptr_t poll_flags);
Expand Down

0 comments on commit 1bc3485

Please sign in to comment.