Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ports/zephyr-cp/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void serial_cb(const struct device *dev, void *user_data) {
if (uart_fifo_read(dev, &c, 1) != 1) {
break;
}
if (mp_interrupt_char == c) {
if (self->sigint_enabled && mp_interrupt_char == c) {
common_hal_busio_uart_clear_rx_buffer(self);
mp_sched_keyboard_interrupt();
port_wake_main_task_from_isr();
Expand All @@ -83,7 +83,7 @@ static void serial_cb(const struct device *dev, void *user_data) {
}

// Helper function for Zephyr-specific initialization from device tree
mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer) {
mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled) {
self->base.type = &busio_uart_type;
self->uart_device = uart_device;
self->dynamic = false;
Expand All @@ -104,6 +104,7 @@ mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, con
self->write_timeout = K_FOREVER;
self->rx_paused = false;
self->flow_control = false;
self->sigint_enabled = sigint_enabled;
uart_irq_rx_enable(uart_device);

return MP_OBJ_FROM_PTR(self);
Expand Down Expand Up @@ -148,7 +149,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
allocated_buffer = true;
}

common_hal_busio_uart_construct_from_device(self, dev, receiver_buffer_size, receiver_buffer);
common_hal_busio_uart_construct_from_device(self, dev, receiver_buffer_size, receiver_buffer, sigint_enabled);
self->dynamic = true;
self->receiver_buffer = allocated_buffer ? receiver_buffer : NULL;
self->tx = tx;
Expand Down
4 changes: 3 additions & 1 deletion ports/zephyr-cp/common-hal/busio/UART.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ typedef struct {
// Set when the sender waits for unread data (USB CDC), so RX can
// pause on a full msgq instead of dropping bytes.
bool flow_control;
// Raise KeyboardInterrupt on mp_interrupt_char.
bool sigint_enabled;

// True when the underlying Zephyr device was dynamically routed to the
// pins above at construction time. Such objects own their receiver
Expand All @@ -38,7 +40,7 @@ typedef struct {
} busio_uart_obj_t;

// Helper function for Zephyr-specific initialization from device tree
mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer);
mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled);

// Internal helper for clearing buffer
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self);
Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr-cp/common-hal/usb_cdc/Serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "common-hal/busio/UART.h"
#include "supervisor/shared/tick.h"

mp_obj_t common_hal_usb_cdc_serial_construct_from_device(usb_cdc_serial_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer) {
common_hal_busio_uart_construct_from_device(self, uart_device, receiver_buffer_size, receiver_buffer);
mp_obj_t common_hal_usb_cdc_serial_construct_from_device(usb_cdc_serial_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled) {
common_hal_busio_uart_construct_from_device(self, uart_device, receiver_buffer_size, receiver_buffer, sigint_enabled);
self->flow_control = true;
self->base.type = &usb_cdc_serial_type;
return MP_OBJ_FROM_PTR(self);
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr-cp/common-hal/usb_cdc/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
typedef busio_uart_obj_t usb_cdc_serial_obj_t;

// Helper function for Zephyr-specific initialization from device tree
mp_obj_t common_hal_usb_cdc_serial_construct_from_device(usb_cdc_serial_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer);
mp_obj_t common_hal_usb_cdc_serial_construct_from_device(usb_cdc_serial_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled);
2 changes: 1 addition & 1 deletion ports/zephyr-cp/cptools/zephyr2cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ def zephyr_dts_to_cp_board(board_id, portdir, builddir, zephyrbuilddir, mpconfig
if driver == "serial":
# UART needs a receiver buffer
buffer_decl = f"static byte {instance_name}_buffer[128];"
construct_call = f"common_hal_busio_uart_construct_from_device(&{instance_name}_obj, DEVICE_DT_GET(DT_NODELABEL({labels[0]})), 128, {instance_name}_buffer)"
construct_call = f"common_hal_busio_uart_construct_from_device(&{instance_name}_obj, DEVICE_DT_GET(DT_NODELABEL({labels[0]})), 128, {instance_name}_buffer, false)"
else:
# Default case (I2C, SPI, I2S)
buffer_decl = ""
Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr-cp/supervisor/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ usb_cdc_serial_obj_t *usb_console;
#else
#include "shared-bindings/busio/UART.h"
static busio_uart_obj_t uart_console;
static uint8_t buffer[64];
static uint8_t buffer[1024];
#endif

void port_serial_early_init(void) {
#if CIRCUITPY_USB_DEVICE == 0
uart_console.base.type = &busio_uart_type;
common_hal_busio_uart_construct_from_device(&uart_console, DEVICE_DT_GET(DT_CHOSEN(zephyr_console)), sizeof(buffer), buffer);
common_hal_busio_uart_construct_from_device(&uart_console, DEVICE_DT_GET(DT_CHOSEN(zephyr_console)), sizeof(buffer), buffer, true);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr-cp/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void usb_init(void) {
if (console) {
uint8_t *receiver_buffer = port_malloc(1024, true);
if (receiver_buffer != NULL) {
common_hal_usb_cdc_serial_construct_from_device(&usb_cdc_console_obj, DEVICE_DT_GET(DT_NODELABEL(cdc_acm_console)), 1024, receiver_buffer);
common_hal_usb_cdc_serial_construct_from_device(&usb_cdc_console_obj, DEVICE_DT_GET(DT_NODELABEL(cdc_acm_console)), 1024, receiver_buffer, true);
} else {
console = false;
}
Expand All @@ -283,7 +283,7 @@ void usb_init(void) {
if (data) {
uint8_t *receiver_buffer = port_malloc(1024, true);
if (receiver_buffer != NULL) {
common_hal_usb_cdc_serial_construct_from_device(&usb_cdc_data_obj, DEVICE_DT_GET(DT_NODELABEL(cdc_acm_data)), 1024, receiver_buffer);
common_hal_usb_cdc_serial_construct_from_device(&usb_cdc_data_obj, DEVICE_DT_GET(DT_NODELABEL(cdc_acm_data)), 1024, receiver_buffer, false);
} else {
data = false;
}
Expand Down
Loading