Skip to content

Commit 90ac070

Browse files
committed
Espressif: Fix interrupts in UART workflow
1 parent 35b188d commit 90ac070

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

ports/espressif/common-hal/busio/UART.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,39 @@
3030
#include "components/driver/include/driver/uart.h"
3131

3232
#include "mpconfigport.h"
33+
#include "shared/readline/readline.h"
3334
#include "shared/runtime/interrupt_char.h"
3435
#include "py/gc.h"
3536
#include "py/mperrno.h"
3637
#include "py/runtime.h"
3738
#include "py/stream.h"
39+
#include "supervisor/port.h"
3840
#include "supervisor/shared/translate.h"
3941
#include "supervisor/shared/tick.h"
4042

4143
uint8_t never_reset_uart_mask = 0;
4244

45+
#ifdef CIRCUITPY_DEBUG_UART_RX
46+
static QueueHandle_t event_queue;
47+
static void event_task(void *param) {
48+
busio_uart_obj_t *self = param;
49+
uart_event_t event;
50+
while (true) {
51+
if (xQueueReceive(event_queue, &event, portMAX_DELAY)) {
52+
if (event.type == UART_PATTERN_DET) {
53+
port_wake_main_task();
54+
if (mp_interrupt_char == CHAR_CTRL_C) {
55+
uart_flush(self->uart_num);
56+
mp_sched_keyboard_interrupt();
57+
}
58+
} else if (event.type == UART_DATA) {
59+
port_wake_main_task();
60+
}
61+
}
62+
}
63+
}
64+
#endif
65+
4366
void uart_reset(void) {
4467
for (uart_port_t num = 0; num < UART_NUM_MAX; num++) {
4568
// Ignore the UART used by the IDF.
@@ -125,9 +148,28 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
125148

126149
uint8_t rx_threshold = UART_FIFO_LEN - 8;
127150
// Install the driver before we change the settings.
128-
if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 0, NULL, 0) != ESP_OK ||
129-
uart_set_mode(self->uart_num, mode) != ESP_OK) {
130-
mp_raise_ValueError(translate("Could not initialize UART"));
151+
#ifdef CIRCUITPY_DEBUG_UART_RX
152+
if (rx == CIRCUITPY_DEBUG_UART_RX) {
153+
if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 20, &event_queue, 0) != ESP_OK ||
154+
uart_set_mode(self->uart_num, mode) != ESP_OK) {
155+
mp_raise_ValueError(translate("Could not initialize UART"));
156+
}
157+
uart_enable_pattern_det_baud_intr(self->uart_num, CHAR_CTRL_C, 1, 1, 0, 0);
158+
xTaskCreatePinnedToCore(
159+
event_task,
160+
"uart_event_task",
161+
configMINIMAL_STACK_SIZE,
162+
self,
163+
5,
164+
NULL,
165+
xPortGetCoreID());
166+
} else
167+
#endif
168+
{
169+
if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 0, NULL, 0) != ESP_OK ||
170+
uart_set_mode(self->uart_num, mode) != ESP_OK) {
171+
mp_raise_ValueError(translate("Could not initialize UART"));
172+
}
131173
}
132174
uart_set_hw_flow_ctrl(self->uart_num, flow_control, rx_threshold);
133175

supervisor/shared/status_leds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
// To work with a NeoPixel, one must have MICROPY_HW_NEOPIXEL defined and
4545
// neopixel_write implemented.
4646

47-
#define CIRCUITPY_PWM_RGB_LED defined(CIRCUITPY_RGB_STATUS_R) || defined(CIRCUITPY_RGB_STATUS_G) || defined(CIRCUITPY_RGB_STATUS_B)
48-
#define CIRCUITPY_STATUS_LED (CIRCUITPY_DIGITALIO && defined(MICROPY_HW_LED_STATUS)) || defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || CIRCUITPY_PWM_RGB_LED
47+
#define CIRCUITPY_PWM_RGB_LED (defined(CIRCUITPY_RGB_STATUS_R) || defined(CIRCUITPY_RGB_STATUS_G) || defined(CIRCUITPY_RGB_STATUS_B))
48+
#define CIRCUITPY_STATUS_LED ((CIRCUITPY_DIGITALIO && defined(MICROPY_HW_LED_STATUS)) || defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || CIRCUITPY_PWM_RGB_LED)
4949

5050
void status_led_init(void);
5151
void status_led_deinit(void);

0 commit comments

Comments
 (0)