-
Notifications
You must be signed in to change notification settings - Fork 4
/
micropython.patch
152 lines (139 loc) · 4.74 KB
/
micropython.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index f5e284f..331040e 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -38,6 +38,10 @@
STATIC byte input_buf_array[256];
ringbuf_t input_buf = {input_buf_array, sizeof(input_buf_array)};
+// Separate buffer for duplicate terminal (WebREPL) so that UART can be detached from REPL
+STATIC byte dupterm_buf_array[256];
+ringbuf_t dupterm_buf = {dupterm_buf_array, sizeof(dupterm_buf_array)};
+
void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len);
const mp_print_t mp_debug_print = {NULL, mp_hal_debug_tx_strn_cooked};
@@ -56,10 +60,17 @@ void mp_hal_delay_us(uint32_t us) {
int mp_hal_stdin_rx_chr(void) {
for (;;) {
- int c = ringbuf_get(&input_buf);
+ //int c = ringbuf_get(&input_buf);
+ int c = uart_std_getc();
+ if (c != -1) {
+ return c;
+ }
+ // Read next char from duplicate terminal (WebREPL) - note that UART has priority when enabled
+ c = ringbuf_get(&dupterm_buf);
if (c != -1) {
return c;
}
+
#if 0
// Idles CPU but need more testing before enabling
if (!ets_loop_iter()) {
@@ -72,7 +83,8 @@ int mp_hal_stdin_rx_chr(void) {
}
void mp_hal_stdout_tx_char(char c) {
- uart_tx_one_char(UART0, c);
+ //uart_tx_one_char(UART0, c);
+ uart_std_putc(c);
mp_uos_dupterm_tx_strn(&c, 1);
}
@@ -195,7 +207,7 @@ STATIC void dupterm_task_handler(os_event_t *evt) {
if (c < 0) {
break;
}
- ringbuf_put(&input_buf, c);
+ ringbuf_put(&dupterm_buf, c);
}
mp_hal_signal_input();
lock = 0;
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index b7ce122..695c737 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -519,6 +519,15 @@ void error_check(bool status, const char *msg) {
}
}
+
+
+STATIC mp_obj_t esp_uart_nostdio(mp_obj_t val) {
+ extern void uart_os_nostdio(int);
+ uart_os_nostdio(mp_obj_get_int(val));
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_uart_nostdio_obj, esp_uart_nostdio);
+
STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
if (val == mp_const_none) {
uart_os_config(-1);
@@ -826,6 +835,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_uart_nostdio), (mp_obj_t)&esp_uart_nostdio_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },
diff --git a/esp8266/uart.c b/esp8266/uart.c
index 001a9c6..916671e 100644
--- a/esp8266/uart.c
+++ b/esp8266/uart.c
@@ -29,6 +29,7 @@ extern UartDevice UartDev;
// the uart to which OS messages go; -1 to disable
static int uart_os = UART_OS;
+static int uart_stdio_disable = 0;
#if MICROPY_REPL_EVENT_DRIVEN
static os_event_t uart_evt_queue[16];
@@ -141,6 +142,11 @@ uart_os_config(int uart) {
uart_os = uart;
}
+void
+uart_os_nostdio(int dis) {
+ uart_stdio_disable = dis;
+}
+
/******************************************************************************
* FunctionName : uart0_rx_intr_handler
* Description : Internal used function
@@ -170,7 +176,7 @@ static void uart0_rx_intr_handler(void *para) {
while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff;
- if (RcvChar == mp_interrupt_char) {
+ if (RcvChar == mp_interrupt_char && !uart_stdio_disable) {
mp_keyboard_interrupt();
} else {
ringbuf_put(&input_buf, RcvChar);
@@ -200,6 +206,24 @@ bool uart_rx_wait(uint32_t timeout_us) {
}
}
+void uart_std_putc(uint8 c)
+{
+ if (uart_stdio_disable) {
+ return;
+ }
+ uart_tx_one_char(UART0, c);
+}
+
+// Returns char from the input buffer, else -1 if buffer is empty.
+int uart_std_getc(void) {
+ // DBE - Disconnect REPL
+ if (uart_stdio_disable) {
+ return -1;
+ }
+ return ringbuf_get(&input_buf);
+}
+
+
// Returns char from the input buffer, else -1 if buffer is empty.
int uart_rx_char(void) {
return ringbuf_get(&input_buf);
diff --git a/esp8266/uart.h b/esp8266/uart.h
index 2b97683..9fd00cb 100644
--- a/esp8266/uart.h
+++ b/esp8266/uart.h
@@ -99,5 +99,8 @@ void uart_tx_one_char(uint8 uart, uint8 TxChar);
void uart_flush(uint8 uart);
void uart_os_config(int uart);
void uart_setup(uint8 uart);
+// UART functions used by STDIO (REPL)
+int uart_std_getc(void);
+void uart_std_putc(uint8 c);
#endif // _INCLUDED_UART_H_