diff options
Diffstat (limited to 'ports/zephyr/src')
-rw-r--r-- | ports/zephyr/src/usbd.c | 14 | ||||
-rw-r--r-- | ports/zephyr/src/zephyr_getchar.c | 17 | ||||
-rw-r--r-- | ports/zephyr/src/zephyr_getchar.h | 1 |
3 files changed, 21 insertions, 11 deletions
diff --git a/ports/zephyr/src/usbd.c b/ports/zephyr/src/usbd.c index 2444706cbe..36b07a8638 100644 --- a/ports/zephyr/src/usbd.c +++ b/ports/zephyr/src/usbd.c @@ -34,12 +34,22 @@ #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(mp_usbd); +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(4, 1, 0) + +#define BLOCKLIST , blocklist + /* By default, do not register the USB DFU class DFU mode instance. */ static const char *const blocklist[] = { "dfu_dfu", NULL, }; +#else + +#define BLOCKLIST + +#endif + USBD_DEVICE_DEFINE(mp_usbd, DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), CONFIG_MICROPY_USB_DEVICE_VID, CONFIG_MICROPY_USB_DEVICE_PID); @@ -121,7 +131,7 @@ struct usbd_context *mp_usbd_init_device(usbd_msg_cb_t msg_cb) { return NULL; } - err = usbd_register_all_classes(&mp_usbd, USBD_SPEED_HS, 1, blocklist); + err = usbd_register_all_classes(&mp_usbd, USBD_SPEED_HS, 1 BLOCKLIST); if (err) { LOG_ERR("Failed to add register classes"); return NULL; @@ -137,7 +147,7 @@ struct usbd_context *mp_usbd_init_device(usbd_msg_cb_t msg_cb) { return NULL; } - err = usbd_register_all_classes(&mp_usbd, USBD_SPEED_FS, 1, blocklist); + err = usbd_register_all_classes(&mp_usbd, USBD_SPEED_FS, 1 BLOCKLIST); if (err) { LOG_ERR("Failed to add register classes"); return NULL; diff --git a/ports/zephyr/src/zephyr_getchar.c b/ports/zephyr/src/zephyr_getchar.c index 94e35e2e84..bf504a97c9 100644 --- a/ports/zephyr/src/zephyr_getchar.c +++ b/ports/zephyr/src/zephyr_getchar.c @@ -23,12 +23,10 @@ extern int mp_interrupt_char; void mp_sched_keyboard_interrupt(void); void mp_hal_signal_event(void); -void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms); -static struct k_sem uart_sem; -#define UART_BUFSIZE 256 +#define UART_BUFSIZE (512) static uint8_t uart_ringbuf[UART_BUFSIZE]; -static uint8_t i_get, i_put; +static uint16_t i_get, i_put; static int console_irq_input_hook(uint8_t ch) { int i_next = (i_put + 1) & (UART_BUFSIZE - 1); @@ -44,14 +42,16 @@ static int console_irq_input_hook(uint8_t ch) { uart_ringbuf[i_put] = ch; i_put = i_next; } - // printk("%x\n", ch); - k_sem_give(&uart_sem); return 1; } +// Returns true if a char is available for reading. +int zephyr_getchar_check(void) { + return i_get != i_put; +} + int zephyr_getchar(void) { - mp_hal_wait_sem(&uart_sem, 0); - if (k_sem_take(&uart_sem, K_MSEC(0)) == 0) { + if (i_get != i_put) { unsigned int key = irq_lock(); int c = (int)uart_ringbuf[i_get++]; i_get &= UART_BUFSIZE - 1; @@ -62,7 +62,6 @@ int zephyr_getchar(void) { } void zephyr_getchar_init(void) { - k_sem_init(&uart_sem, 0, UINT_MAX); uart_console_in_debug_hook_install(console_irq_input_hook); // All NULLs because we're interested only in the callback above uart_register_input(NULL, NULL, NULL); diff --git a/ports/zephyr/src/zephyr_getchar.h b/ports/zephyr/src/zephyr_getchar.h index fee899e1b4..3f31c4317f 100644 --- a/ports/zephyr/src/zephyr_getchar.h +++ b/ports/zephyr/src/zephyr_getchar.h @@ -17,4 +17,5 @@ #include <stdint.h> void zephyr_getchar_init(void); +int zephyr_getchar_check(void); int zephyr_getchar(void); |