Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 0372114

Browse files
author
iwahdan88
committed
esp32/micropython: correction to keyboard interrupts exposure
1 parent bc4d7d0 commit 0372114

File tree

5 files changed

+6
-48
lines changed

5 files changed

+6
-48
lines changed

esp32/hal/esp32_mphal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,5 @@ void mp_hal_delay_ms(uint32_t delay);
2929
void mp_hal_set_interrupt_char(int c);
3030
void mp_hal_set_reset_char(int c);
3131
void mp_hal_reset_safe_and_boot(bool reset);
32-
void mp_hal_set_persistent_interrupt_char(int c);
33-
int mp_hal_get_persistent_interrupt_char(void);
34-
void mp_hal_set_persistent_reset_char(int c);
35-
int mp_hal_get_persistent_reset_char(void) ;
3632

3733
#endif // _INCLUDED_MPHAL_H_

lib/utils/interrupt_char.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@
2626

2727
#include "py/obj.h"
2828
#include "py/mpstate.h"
29-
#include "readline.h"
3029

3130
#if MICROPY_KBD_EXCEPTION
3231

3332
int mp_interrupt_char;
3433
int mp_reset_char;
35-
int mp_persistent_interrupt_char = CHAR_CTRL_C;
36-
int mp_persistent_reset_char = CHAR_CTRL_F;
3734

3835
void mp_hal_set_interrupt_char(int c) {
3936
if (c != -1) {
@@ -42,27 +39,10 @@ void mp_hal_set_interrupt_char(int c) {
4239
mp_interrupt_char = c;
4340
}
4441

45-
void mp_hal_set_persistent_interrupt_char(int c) {
46-
47-
mp_persistent_interrupt_char = c;
48-
}
49-
50-
int mp_hal_get_persistent_interrupt_char(void) {
51-
return mp_persistent_interrupt_char;
52-
}
53-
5442
void mp_hal_set_reset_char(int c) {
5543
mp_reset_char = c;
5644
}
5745

58-
void mp_hal_set_persistent_reset_char(int c) {
59-
mp_persistent_reset_char = c;
60-
}
61-
62-
int mp_hal_get_persistent_reset_char(void) {
63-
return mp_persistent_reset_char;
64-
}
65-
6646
void mp_keyboard_interrupt(void) {
6747
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
6848
#if MICROPY_ENABLE_SCHEDULER

lib/utils/interrupt_char.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
extern int mp_interrupt_char;
3030
extern int mp_reset_char;
3131
void mp_hal_set_interrupt_char(int c);
32-
void mp_hal_set_persistent_interrupt_char(int c);
33-
int mp_hal_get_persistent_interrupt_char(void);
3432
void mp_hal_set_reset_char(int c);
35-
void mp_hal_set_persistent_reset_char(int c);
36-
int mp_hal_get_persistent_reset_char(void) ;
3733
void mp_keyboard_interrupt(void);
3834

3935
#endif // MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H

lib/utils/pyexec.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
9797
}
9898

9999
// execute code
100-
mp_hal_set_interrupt_char(mp_hal_get_persistent_interrupt_char()); // allow char interrupt
100+
mp_hal_set_interrupt_char(CHAR_CTRL_C); // allow ctrl-C to interrupt us
101101
start = mp_hal_ticks_ms();
102102
mp_call_function_0(module_fun);
103103
mp_hal_set_interrupt_char(-1); // disable interrupt
104-
mp_hal_set_reset_char(mp_hal_get_persistent_reset_char()); // enable reset char
104+
mp_hal_set_reset_char(CHAR_CTRL_F); // enable reset char
105105
nlr_pop();
106106
ret = 1;
107107
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
@@ -111,6 +111,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
111111
// uncaught exception
112112
// FIXME it could be that an interrupt happens just before we disable it here
113113
mp_hal_set_interrupt_char(-1); // disable interrupt
114+
mp_hal_set_reset_char(CHAR_CTRL_F); // enable reset char, might be wrong here
114115
// print EOF after normal output
115116
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
116117
mp_hal_stdout_tx_strn("\x04", 1);

py/modmicropython.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_
142142
#if MICROPY_KBD_EXCEPTION
143143
STATIC mp_obj_t mp_micropython_kbd_intr(size_t n_args, const mp_obj_t *args) {
144144
int c = mp_obj_get_int(args[0]);
145-
mp_hal_set_persistent_interrupt_char(c);
145+
mp_hal_set_interrupt_char(c);
146146
if (n_args == 1) {
147147
if (c == -1) {
148-
mp_hal_set_persistent_reset_char(-1);
148+
mp_hal_set_reset_char(-1);
149149
}
150150
} else {
151-
mp_hal_set_persistent_reset_char(mp_obj_get_int(args[1]));
151+
mp_hal_set_reset_char(mp_obj_get_int(args[1]));
152152
}
153153
return mp_const_none;
154154
}
155155
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_kbd_intr_obj, 1, 2, mp_micropython_kbd_intr);
156-
157-
STATIC mp_obj_t mp_micropython_get_kbd_intr(void) {
158-
159-
STATIC const qstr kbd_intr_fields[] = {
160-
MP_QSTR_interrupt, MP_QSTR_reset
161-
};
162-
163-
mp_obj_t tuple[2];
164-
tuple[0] = mp_obj_new_int(mp_hal_get_persistent_interrupt_char());
165-
tuple[1] = mp_obj_new_int(mp_hal_get_persistent_reset_char());
166-
167-
return mp_obj_new_attrtuple(kbd_intr_fields, 2, tuple);
168-
}
169-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_get_kbd_intr_obj, mp_micropython_get_kbd_intr);
170156
#endif
171157

172158
#if MICROPY_ENABLE_SCHEDULER
@@ -209,7 +195,6 @@ STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = {
209195
#endif
210196
#if MICROPY_KBD_EXCEPTION
211197
{ MP_ROM_QSTR(MP_QSTR_kbd_intr), MP_ROM_PTR(&mp_micropython_kbd_intr_obj) },
212-
{ MP_ROM_QSTR(MP_QSTR_get_kbd_intr), MP_ROM_PTR(&mp_micropython_get_kbd_intr_obj) },
213198
#endif
214199
#if MICROPY_ENABLE_SCHEDULER
215200
{ MP_ROM_QSTR(MP_QSTR_schedule), MP_ROM_PTR(&mp_micropython_schedule_obj) },

0 commit comments

Comments
 (0)