diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index eb3e78786a..69a8d1e91c 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -125,6 +125,7 @@ SRC_LIB += $(addprefix lib/,\ libc/string0.c \ mp-readline/readline.c \ utils/pyexec.c \ + utils/interrupt_char.c \ timeutils/timeutils.c \ oofatfs/ff.c \ oofatfs/option/unicode.c \ diff --git a/ports/nrf/drivers/bluetooth/ble_uart.c b/ports/nrf/drivers/bluetooth/ble_uart.c index 4646d49876..081dfe87cf 100644 --- a/ports/nrf/drivers/bluetooth/ble_uart.c +++ b/ports/nrf/drivers/bluetooth/ble_uart.c @@ -30,6 +30,7 @@ #include "ble_uart.h" #include "ringbuffer.h" #include "hal/hal_time.h" +#include "lib/utils/interrupt_char.h" #if MICROPY_PY_BLE_NUS @@ -154,7 +155,14 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at m_cccd_enabled = true; } else if (ble_uart_char_rx.handle == attr_handle) { for (uint16_t i = 0; i < length; i++) { - bufferWrite(mp_rx_ring_buffer, data[i]); + #if MICROPY_KBD_EXCEPTION + if (data[i] == mp_interrupt_char) { + mp_keyboard_interrupt(); + } else + #endif + { + bufferWrite(mp_rx_ring_buffer, data[i]); + } } } } diff --git a/ports/nrf/main.c b/ports/nrf/main.c index d3c72ede8f..1090d8fb57 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -47,6 +47,7 @@ #include "led.h" #include "uart.h" #include "nrf.h" +#include "nrf_sdm.h" #include "pin.h" #include "spi.h" #include "i2c.h" @@ -220,12 +221,13 @@ pin_init0(); mp_deinit(); - if (ret_code == PYEXEC_FORCED_EXIT) { - NVIC_SystemReset(); - } else { - printf("MPY: soft reboot\n"); - goto soft_reset; - } + printf("MPY: soft reboot\n"); + +#if BLUETOOTH_SD + sd_softdevice_disable(); +#endif + + goto soft_reset; return 0; } diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index de9ac036bd..85991d0eb4 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -47,6 +47,7 @@ #define MICROPY_HELPER_REPL (1) #define MICROPY_REPL_EMACS_KEYS (0) #define MICROPY_REPL_AUTO_INDENT (1) +#define MICROPY_KBD_EXCEPTION (0) #define MICROPY_ENABLE_SOURCE_LINE (0) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #if NRF51 diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index 1abd4b186a..d8c3a9d2a8 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -44,11 +44,13 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(mp_hal_status_to_errno_table[status]))); } +#if !MICROPY_KBD_EXCEPTION void mp_hal_set_interrupt_char(int c) { } +#endif -#if (MICROPY_PY_BLE_NUS == 0) +#if !MICROPY_PY_BLE_NUS int mp_hal_stdin_rx_chr(void) { for (;;) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {