Skip to content

Commit 785cf9a

Browse files
committed
esp8266: Support dedicated REPL loop (aka pull-style).
Event-driven loop (push-style) is still supported and default (controlled by MICROPY_REPL_EVENT_DRIVEN setting, as expected). Dedicated loop worked even without adding ets_loop_iter(), though that needs to be revisited later.
1 parent 777232c commit 785cf9a

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

esp8266/esp_mphal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void mp_hal_delay_us(uint32_t us) {
6666

6767
int mp_hal_stdin_rx_chr(void) {
6868
for (;;) {
69-
int c = uart0_rx();
69+
int c = ringbuf_get(&input_buf);
7070
if (c != -1) {
7171
return c;
7272
}
@@ -156,7 +156,9 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
156156
}
157157

158158
void mp_hal_signal_input(void) {
159+
#if MICROPY_REPL_EVENT_DRIVEN
159160
system_os_post(UART_TASK_ID, 0, 0);
161+
#endif
160162
}
161163

162164
static int call_dupterm_read(void) {

esp8266/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,38 @@ void soft_reset(void) {
6262
mp_hal_stdout_tx_str("PYB: soft reboot\r\n");
6363
mp_hal_delay_us(10000); // allow UART to flush output
6464
mp_reset();
65+
#if MICROPY_REPL_EVENT_DRIVEN
6566
pyexec_event_repl_init();
67+
#endif
6668
}
6769

6870
void init_done(void) {
71+
#if MICROPY_REPL_EVENT_DRIVEN
6972
uart_task_init();
73+
#endif
7074
mp_reset();
7175
mp_hal_stdout_tx_str("\r\n");
76+
#if MICROPY_REPL_EVENT_DRIVEN
7277
pyexec_event_repl_init();
78+
#endif
7379
dupterm_task_init();
80+
81+
#if !MICROPY_REPL_EVENT_DRIVEN
82+
soft_reset:
83+
for (;;) {
84+
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
85+
if (pyexec_raw_repl() != 0) {
86+
break;
87+
}
88+
} else {
89+
if (pyexec_friendly_repl() != 0) {
90+
break;
91+
}
92+
}
93+
}
94+
soft_reset();
95+
goto soft_reset;
96+
#endif
7497
}
7598

7699
void user_init(void) {

esp8266/uart.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ void soft_reset(void);
233233
void mp_keyboard_interrupt(void);
234234

235235
int interrupt_char;
236+
#if MICROPY_REPL_EVENT_DRIVEN
236237
void uart_task_handler(os_event_t *evt) {
237238
if (pyexec_repl_active) {
238239
// TODO: Just returning here isn't exactly right.
@@ -264,3 +265,4 @@ void uart_task_handler(os_event_t *evt) {
264265
void uart_task_init() {
265266
system_os_task(uart_task_handler, UART_TASK_ID, uart_evt_queue, sizeof(uart_evt_queue) / sizeof(*uart_evt_queue));
266267
}
268+
#endif

0 commit comments

Comments
 (0)