nrf: Option to enable Ctrl-C in NUS console.

Costs 136 bytes on a nRF51822.
This commit is contained in:
Ayke van Laethem 2017-11-26 21:58:25 +01:00 committed by Damien George
parent 03b8429c0c
commit a248db6916
5 changed files with 22 additions and 8 deletions

View File

@ -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 \

View File

@ -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]);
}
}
}
}

View File

@ -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;
}

View File

@ -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

View File

@ -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))) {