aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyke van Laethem2017-11-26 21:58:25 +0100
committerDamien George2018-07-18 17:12:25 +1000
commita248db6916dd534f82b6faad7d6aa430ad0d5056 (patch)
tree617bf1ed26a69fe0d7291f8790adbbde119cb883
parent03b8429c0cf182f89fea8883cfc005dbb041ba2f (diff)
nrf: Option to enable Ctrl-C in NUS console.
Costs 136 bytes on a nRF51822.
-rw-r--r--ports/nrf/Makefile1
-rw-r--r--ports/nrf/drivers/bluetooth/ble_uart.c10
-rw-r--r--ports/nrf/main.c14
-rw-r--r--ports/nrf/mpconfigport.h1
-rw-r--r--ports/nrf/mphalport.c4
5 files changed, 22 insertions, 8 deletions
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index eb3e78786..69a8d1e91 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 4646d4987..081dfe87c 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 d3c72ede8..1090d8fb5 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 de9ac036b..85991d0eb 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 1abd4b186..d8c3a9d2a 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))) {