|
30 | 30 | #include "components/driver/include/driver/uart.h"
|
31 | 31 |
|
32 | 32 | #include "mpconfigport.h"
|
| 33 | +#include "shared/readline/readline.h" |
33 | 34 | #include "shared/runtime/interrupt_char.h"
|
34 | 35 | #include "py/gc.h"
|
35 | 36 | #include "py/mperrno.h"
|
36 | 37 | #include "py/runtime.h"
|
37 | 38 | #include "py/stream.h"
|
| 39 | +#include "supervisor/port.h" |
38 | 40 | #include "supervisor/shared/translate.h"
|
39 | 41 | #include "supervisor/shared/tick.h"
|
40 | 42 |
|
41 | 43 | uint8_t never_reset_uart_mask = 0;
|
42 | 44 |
|
| 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 | + |
43 | 66 | void uart_reset(void) {
|
44 | 67 | for (uart_port_t num = 0; num < UART_NUM_MAX; num++) {
|
45 | 68 | // Ignore the UART used by the IDF.
|
@@ -125,9 +148,28 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
125 | 148 |
|
126 | 149 | uint8_t rx_threshold = UART_FIFO_LEN - 8;
|
127 | 150 | // 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 | + } |
131 | 173 | }
|
132 | 174 | uart_set_hw_flow_ctrl(self->uart_num, flow_control, rx_threshold);
|
133 | 175 |
|
|
0 commit comments