esp8266: Support raising KeyboardInterrupt on Ctrl+C.
This commit is contained in:
parent
077448328a
commit
d3a4d39687
|
@ -98,7 +98,11 @@ void mp_hal_delay_ms(uint32_t delay) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_hal_set_interrupt_char(int c) {
|
void mp_hal_set_interrupt_char(int c) {
|
||||||
// TODO
|
if (c != -1) {
|
||||||
|
mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception));
|
||||||
|
}
|
||||||
|
extern int interrupt_char;
|
||||||
|
interrupt_char = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __assert_func(const char *file, int line, const char *func, const char *expr) {
|
void __assert_func(const char *file, int line, const char *func, const char *expr) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ STATIC void mp_reset(void) {
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
mp_obj_list_init(mp_sys_path, 0);
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
mp_obj_list_init(mp_sys_argv, 0);
|
||||||
|
MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
|
||||||
#if MICROPY_MODULE_FROZEN
|
#if MICROPY_MODULE_FROZEN
|
||||||
pyexec_frozen_module("main");
|
pyexec_frozen_module("main");
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,6 +84,10 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||||
|
|
||||||
|
void mp_keyboard_interrupt(void) {
|
||||||
|
MP_STATE_VM(mp_pending_exception) = MP_STATE_PORT(mp_kbd_exception);
|
||||||
|
}
|
||||||
|
|
||||||
void nlr_jump_fail(void *val) {
|
void nlr_jump_fail(void *val) {
|
||||||
printf("NLR jump failed\n");
|
printf("NLR jump failed\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -99,6 +99,7 @@ extern const struct _mp_obj_module_t mp_module_machine;
|
||||||
|
|
||||||
#define MICROPY_PORT_ROOT_POINTERS \
|
#define MICROPY_PORT_ROOT_POINTERS \
|
||||||
const char *readline_hist[8]; \
|
const char *readline_hist[8]; \
|
||||||
|
mp_obj_t mp_kbd_exception; \
|
||||||
\
|
\
|
||||||
/* Singleton instance of scan callback, meaning that there can
|
/* Singleton instance of scan callback, meaning that there can
|
||||||
be only one concurrent AP scan. */ \
|
be only one concurrent AP scan. */ \
|
||||||
|
|
|
@ -210,10 +210,15 @@ void ICACHE_FLASH_ATTR uart_reattach() {
|
||||||
#include "lib/utils/pyexec.h"
|
#include "lib/utils/pyexec.h"
|
||||||
|
|
||||||
void soft_reset(void);
|
void soft_reset(void);
|
||||||
|
void mp_keyboard_interrupt(void);
|
||||||
|
|
||||||
|
int interrupt_char;
|
||||||
void uart_task_handler(os_event_t *evt) {
|
void uart_task_handler(os_event_t *evt) {
|
||||||
int c, ret = 0;
|
int c, ret = 0;
|
||||||
while ((c = uart_rx_one_char(UART_REPL)) >= 0) {
|
while ((c = uart_rx_one_char(UART_REPL)) >= 0) {
|
||||||
|
if (c == interrupt_char) {
|
||||||
|
mp_keyboard_interrupt();
|
||||||
|
}
|
||||||
ret = pyexec_event_repl_process_char(c);
|
ret = pyexec_event_repl_process_char(c);
|
||||||
if (ret & PYEXEC_FORCED_EXIT) {
|
if (ret & PYEXEC_FORCED_EXIT) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue