Skip to content

Commit 7f79a0e

Browse files
committed
added Ctrl+C interrupt
1 parent a021a9e commit 7f79a0e

File tree

3 files changed

+122
-110
lines changed

3 files changed

+122
-110
lines changed

ports/nrf/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ SRC_C += \
151151
lib/timeutils/timeutils.c \
152152
lib/utils/buffer_helper.c \
153153
lib/utils/context_manager_helpers.c \
154+
lib/utils/interrupt_char.c \
154155
lib/utils/pyexec.c \
155156
lib/libc/string0.c \
156157
lib/mp-readline/readline.c \

ports/nrf/hal/hal_uart.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "hal_uart.h"
3333
#include "fifo.h"
3434

35+
#include "lib/utils/interrupt_char.h"
36+
3537
#ifdef HAL_UART_MODULE_ENABLED
3638

3739
FIFO_DEF(_ff_uart, 128, uint8_t, true, UARTE0_UART0_IRQn);
@@ -162,7 +164,15 @@ void UARTE0_UART0_IRQHandler(void)
162164
if (p_instance->EVENTS_RXDRDY)
163165
{
164166
uint8_t ch = (uint8_t) p_instance->RXD;
165-
fifo_write(_ff_uart, &ch);
167+
168+
// Keyboard interrupt
169+
if (mp_interrupt_char != -1 && ch == mp_interrupt_char)
170+
{
171+
mp_keyboard_interrupt();
172+
}else
173+
{
174+
fifo_write(_ff_uart, &ch);
175+
}
166176

167177
p_instance->EVENTS_RXDRDY = 0x0UL;
168178
}

ports/nrf/mpconfigport.h

+110-109
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,45 @@
3030
#include <mpconfigboard.h>
3131

3232
// options to control how MicroPython is built
33-
#define MICROPY_ALLOC_PATH_MAX (512)
34-
#define MICROPY_PERSISTENT_CODE_LOAD (1)
35-
#define MICROPY_EMIT_THUMB (0)
36-
#define MICROPY_EMIT_INLINE_THUMB (0)
37-
#define MICROPY_COMP_MODULE_CONST (0)
38-
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
39-
#define MICROPY_READER_VFS (MICROPY_VFS)
40-
#define MICROPY_ENABLE_GC (1)
41-
#define MICROPY_ENABLE_FINALISER (1)
42-
#define MICROPY_STACK_CHECK (0)
43-
#define MICROPY_HELPER_REPL (1)
44-
#define MICROPY_REPL_EMACS_KEYS (0)
45-
#define MICROPY_REPL_AUTO_INDENT (1)
46-
#define MICROPY_ENABLE_SOURCE_LINE (0)
33+
#define MICROPY_ALLOC_PATH_MAX (512)
34+
#define MICROPY_PERSISTENT_CODE_LOAD (1)
35+
#define MICROPY_EMIT_THUMB (0)
36+
#define MICROPY_EMIT_INLINE_THUMB (0)
37+
#define MICROPY_COMP_MODULE_CONST (0)
38+
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
39+
#define MICROPY_READER_VFS (MICROPY_VFS)
40+
#define MICROPY_ENABLE_GC (1)
41+
#define MICROPY_ENABLE_FINALISER (1)
42+
#define MICROPY_STACK_CHECK (0)
43+
#define MICROPY_HELPER_REPL (1)
44+
#define MICROPY_REPL_EMACS_KEYS (0)
45+
#define MICROPY_REPL_AUTO_INDENT (1)
46+
#define MICROPY_ENABLE_SOURCE_LINE (0)
4747
//CP UPDATE: See mpconfigport.h for LONGINT implementation
48-
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
48+
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
4949
#if NRF51
50-
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
50+
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
5151
#else
52-
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
52+
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
5353
#endif
5454

55-
#define MICROPY_OPT_COMPUTED_GOTO (0)
55+
#define MICROPY_OPT_COMPUTED_GOTO (0)
5656
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
57-
#define MICROPY_OPT_MPZ_BITWISE (0)
57+
#define MICROPY_OPT_MPZ_BITWISE (0)
5858

5959
// fatfs configuration used in ffconf.h
60-
#define MICROPY_FATFS_ENABLE_LFN (1)
61-
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
62-
#define MICROPY_FATFS_USE_LABEL (1)
63-
#define MICROPY_FATFS_RPATH (2)
64-
#define MICROPY_FATFS_MULTI_PARTITION (0)
65-
#define MICROPY_FATFS_NUM_PERSISTENT (1)
60+
#define MICROPY_FATFS_ENABLE_LFN (1)
61+
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
62+
#define MICROPY_FATFS_USE_LABEL (1)
63+
#define MICROPY_FATFS_RPATH (2)
64+
#define MICROPY_FATFS_MULTI_PARTITION (0)
65+
#define MICROPY_FATFS_NUM_PERSISTENT (1)
6666

67-
//#define MICROPY_FATFS_MAX_SS (4096)
67+
//#define MICROPY_FATFS_MAX_SS (4096)
68+
#define FILESYSTEM_BLOCK_SIZE (512)
6869

69-
#define FILESYSTEM_BLOCK_SIZE 512
70-
71-
#define MICROPY_VFS (1)
72-
#define MICROPY_VFS_FAT (MICROPY_VFS)
70+
#define MICROPY_VFS (1)
71+
#define MICROPY_VFS_FAT (MICROPY_VFS)
7372

7473
// TODO these should be generic, not bound to fatfs
7574
#define mp_type_fileio fatfs_type_fileio
@@ -82,101 +81,104 @@
8281
#define mp_builtin_open_obj mp_vfs_open_obj
8382
#endif
8483

85-
#define MICROPY_STREAMS_NON_BLOCK (1)
86-
#define MICROPY_MODULE_WEAK_LINKS (1)
87-
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
88-
#define MICROPY_USE_INTERNAL_ERRNO (1)
89-
#define MICROPY_PY_FUNCTION_ATTRS (1)
90-
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
91-
#define MICROPY_PY_BUILTINS_STR_CENTER (0)
92-
#define MICROPY_PY_BUILTINS_STR_PARTITION (0)
93-
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
94-
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
95-
#define MICROPY_PY_BUILTINS_FROZENSET (1)
96-
#define MICROPY_PY_BUILTINS_EXECFILE (0)
97-
#define MICROPY_PY_BUILTINS_COMPILE (1)
98-
#define MICROPY_PY_BUILTINS_HELP (1)
99-
#define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text
100-
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
101-
#define MICROPY_MODULE_BUILTIN_INIT (1)
102-
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
103-
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
104-
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
105-
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
106-
#define MICROPY_PY_SYS_EXIT (1)
107-
#define MICROPY_PY_SYS_MAXSIZE (1)
108-
#define MICROPY_PY_SYS_STDFILES (0)
109-
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
110-
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
111-
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
112-
#define MICROPY_PY_CMATH (0)
113-
#define MICROPY_PY_IO (0)
114-
#define MICROPY_PY_IO_FILEIO (0)
115-
#define MICROPY_PY_UERRNO (0)
116-
#define MICROPY_PY_UBINASCII (0)
117-
#define MICROPY_PY_URANDOM (0)
118-
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
119-
#define MICROPY_PY_UCTYPES (0)
120-
#define MICROPY_PY_UZLIB (0)
121-
#define MICROPY_PY_UJSON (0)
122-
#define MICROPY_PY_URE (0)
123-
#define MICROPY_PY_UHEAPQ (0)
124-
#define MICROPY_PY_UHASHLIB (0)
125-
#define MICROPY_PY_UTIME_MP_HAL (1)
126-
#define MICROPY_PY_MACHINE (1)
127-
#define MICROPY_PY_MACHINE_PULSE (0)
128-
#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
129-
#define MICROPY_PY_MACHINE_SPI (0)
130-
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
131-
#define MICROPY_PY_FRAMEBUF (0)
84+
#define MICROPY_STREAMS_NON_BLOCK (1)
85+
#define MICROPY_MODULE_WEAK_LINKS (1)
86+
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
87+
#define MICROPY_USE_INTERNAL_ERRNO (1)
88+
#define MICROPY_PY_FUNCTION_ATTRS (1)
89+
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
90+
#define MICROPY_PY_BUILTINS_STR_CENTER (0)
91+
#define MICROPY_PY_BUILTINS_STR_PARTITION (0)
92+
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
93+
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
94+
#define MICROPY_PY_BUILTINS_FROZENSET (1)
95+
#define MICROPY_PY_BUILTINS_EXECFILE (0)
96+
#define MICROPY_PY_BUILTINS_COMPILE (1)
97+
#define MICROPY_PY_BUILTINS_HELP (1)
98+
#define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text
99+
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
100+
#define MICROPY_PY_BUILTINS_INPUT (1)
101+
#define MICROPY_MODULE_BUILTIN_INIT (1)
102+
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
103+
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
104+
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
105+
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
106+
#define MICROPY_PY_SYS_EXIT (1)
107+
#define MICROPY_PY_SYS_MAXSIZE (1)
108+
#define MICROPY_PY_SYS_STDFILES (0)
109+
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
110+
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
111+
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
112+
#define MICROPY_PY_CMATH (0)
113+
#define MICROPY_PY_IO (0)
114+
#define MICROPY_PY_IO_FILEIO (0)
115+
#define MICROPY_PY_UERRNO (0)
116+
#define MICROPY_PY_UBINASCII (0)
117+
#define MICROPY_PY_URANDOM (0)
118+
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
119+
#define MICROPY_PY_UCTYPES (0)
120+
#define MICROPY_PY_UZLIB (0)
121+
#define MICROPY_PY_UJSON (0)
122+
#define MICROPY_PY_URE (0)
123+
#define MICROPY_PY_UHEAPQ (0)
124+
#define MICROPY_PY_UHASHLIB (0)
125+
#define MICROPY_PY_UTIME_MP_HAL (1)
126+
#define MICROPY_PY_MACHINE (1)
127+
#define MICROPY_PY_MACHINE_PULSE (0)
128+
#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
129+
#define MICROPY_PY_MACHINE_SPI (0)
130+
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
131+
#define MICROPY_PY_FRAMEBUF (0)
132+
133+
#define MICROPY_KBD_EXCEPTION (1)
132134

133135
#ifndef MICROPY_HW_LED_COUNT
134-
#define MICROPY_HW_LED_COUNT (0)
136+
#define MICROPY_HW_LED_COUNT (0)
135137
#endif
136138

137139
#ifndef MICROPY_HW_LED_PULLUP
138-
#define MICROPY_HW_LED_PULLUP (0)
140+
#define MICROPY_HW_LED_PULLUP (0)
139141
#endif
140142

141143
#ifndef MICROPY_PY_MUSIC
142-
#define MICROPY_PY_MUSIC (0)
144+
#define MICROPY_PY_MUSIC (0)
143145
#endif
144146

145147
#ifndef MICROPY_PY_MACHINE_ADC
146-
#define MICROPY_PY_MACHINE_ADC (0)
148+
#define MICROPY_PY_MACHINE_ADC (0)
147149
#endif
148150

149151
#ifndef MICROPY_PY_MACHINE_I2C
150-
#define MICROPY_PY_MACHINE_I2C (0)
152+
#define MICROPY_PY_MACHINE_I2C (0)
151153
#endif
152154

153155
#ifndef MICROPY_PY_MACHINE_HW_SPI
154-
#define MICROPY_PY_MACHINE_HW_SPI (1)
156+
#define MICROPY_PY_MACHINE_HW_SPI (1)
155157
#endif
156158

157159
#ifndef MICROPY_PY_MACHINE_HW_PWM
158-
#define MICROPY_PY_MACHINE_HW_PWM (0)
160+
#define MICROPY_PY_MACHINE_HW_PWM (0)
159161
#endif
160162

161163
#ifndef MICROPY_PY_MACHINE_SOFT_PWM
162-
#define MICROPY_PY_MACHINE_SOFT_PWM (0)
164+
#define MICROPY_PY_MACHINE_SOFT_PWM (0)
163165
#endif
164166

165167
#ifndef MICROPY_PY_MACHINE_TIMER
166-
#define MICROPY_PY_MACHINE_TIMER (0)
168+
#define MICROPY_PY_MACHINE_TIMER (0)
167169
#endif
168170

169171
#ifndef MICROPY_PY_MACHINE_RTC
170-
#define MICROPY_PY_MACHINE_RTC (0)
172+
#define MICROPY_PY_MACHINE_RTC (0)
171173
#endif
172174

173175
#ifndef MICROPY_PY_HW_RNG
174-
#define MICROPY_PY_HW_RNG (1)
176+
#define MICROPY_PY_HW_RNG (1)
175177
#endif
176178

177179

178180
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
179-
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
181+
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
180182

181183
// if sdk is in use, import configuration
182184
#if BLUETOOTH_SD
@@ -256,39 +258,38 @@ extern const struct _mp_obj_module_t ble_module;
256258
#endif
257259

258260
#define MICROPY_PORT_BUILTIN_MODULES \
259-
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
260-
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
261-
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \
262-
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
263-
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \
264-
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
265-
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \
266-
{ MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \
267-
/*{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module },*/\
268-
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
269-
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
270-
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
271-
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \
272-
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
261+
{ MP_OBJ_NEW_QSTR (MP_QSTR_board ), (mp_obj_t)&board_module }, \
262+
{ MP_OBJ_NEW_QSTR (MP_QSTR_busio ), (mp_obj_t)&busio_module }, \
263+
{ MP_OBJ_NEW_QSTR (MP_QSTR_analogio ), (mp_obj_t)&analogio_module }, \
264+
{ MP_OBJ_NEW_QSTR (MP_QSTR_digitalio ), (mp_obj_t)&digitalio_module }, \
265+
{ MP_OBJ_NEW_QSTR (MP_QSTR_pulseio ), (mp_obj_t)&pulseio_module }, \
266+
{ MP_OBJ_NEW_QSTR (MP_QSTR_microcontroller ), (mp_obj_t)&microcontroller_module }, \
267+
{ MP_OBJ_NEW_QSTR (MP_QSTR_os ), (mp_obj_t)&os_module }, \
268+
{ MP_OBJ_NEW_QSTR (MP_QSTR_random ), (mp_obj_t)&random_module }, \
269+
{ MP_OBJ_NEW_QSTR (MP_QSTR_storage ), (mp_obj_t)&storage_module },\
270+
{ MP_OBJ_NEW_QSTR (MP_QSTR_supervisor ), (mp_obj_t)&supervisor_module }, \
271+
{ MP_OBJ_NEW_QSTR (MP_QSTR_time ), (mp_obj_t)&time_module }, \
272+
{ MP_ROM_QSTR (MP_QSTR_pyb ), MP_ROM_PTR(&pyb_module) }, \
273+
{ MP_ROM_QSTR (MP_QSTR_utime ), MP_ROM_PTR(&mp_module_utime) }, \
273274
MUSIC_MODULE \
274275
RANDOM_MODULE \
275276
/*BLE_MODULE \
276277
UBLUEPY_MODULE \*/
277278

278279

279-
280280
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
281-
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
281+
{ MP_ROM_QSTR (MP_QSTR_time ), MP_ROM_PTR(&mp_module_utime) }, \
282282

283283
// extra built in names to add to the global namespace
284284
#define MICROPY_PORT_BUILTINS \
285-
{ MP_ROM_QSTR(MP_QSTR_help), MP_ROM_PTR(&mp_builtin_help_obj) }, \
286-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
285+
{ MP_ROM_QSTR (MP_QSTR_help), MP_ROM_PTR(&mp_builtin_help_obj) }, \
286+
{ MP_OBJ_NEW_QSTR (MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
287+
{ MP_ROM_QSTR (MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
287288

288289
// extra constants
289290
#define MICROPY_PORT_CONSTANTS \
290-
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
291-
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
291+
{ MP_ROM_QSTR (MP_QSTR_pyb ), MP_ROM_PTR(&pyb_module) }, \
292+
{ MP_ROM_QSTR (MP_QSTR_machine ), MP_ROM_PTR(&machine_module) }, \
292293
BLE_MODULE \
293294

294295
#define MP_STATE_PORT MP_STATE_VM

0 commit comments

Comments
 (0)