diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index ed983b7946..b9b7c71248 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -47,6 +47,10 @@ #error l2cap channels require synchronous modbluetooth events #endif +#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING && !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS +#error pairing and bonding require synchronous modbluetooth events +#endif + #define MP_BLUETOOTH_CONNECT_DEFAULT_SCAN_DURATION_MS 2000 #define MICROPY_PY_BLUETOOTH_MAX_EVENT_DATA_TUPLE_LEN 5 diff --git a/extmod/modbluetooth.h b/extmod/modbluetooth.h index 9856d4a689..2cb2c709c5 100644 --- a/extmod/modbluetooth.h +++ b/extmod/modbluetooth.h @@ -54,6 +54,12 @@ #define MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS (0) #endif +// A port can optionally enable support for pairing and bonding. +// Requires MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS. +#ifndef MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING +#define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (0) +#endif + // This is used to protect the ringbuffer. // A port may no-op this if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS is enabled. #ifndef MICROPY_PY_BLUETOOTH_ENTER diff --git a/extmod/nimble/nimble.mk b/extmod/nimble/nimble.mk index 00a244d6ea..ba094f16f8 100644 --- a/extmod/nimble/nimble.mk +++ b/extmod/nimble/nimble.mk @@ -24,6 +24,11 @@ ifeq ($(MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY),0) # UART is also polled by the RX IRQ. CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1 +# Without the ringbuffer, and with the full implementation, we can also +# enable pairing and bonding. This requires both synchronous events and +# some customisation of the key store. +CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1 + NIMBLE_LIB_DIR = lib/mynewt-nimble LIB_SRC_C += $(addprefix $(NIMBLE_LIB_DIR)/, \