summaryrefslogtreecommitdiff
path: root/devices
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-08-30 14:06:48 -0400
committerDan Halbert <halbert@halwitz.org>2020-08-30 14:06:48 -0400
commitb27d51125134b4317b429eb7b015c9f94f22adb0 (patch)
treea7e41afb5f048f98d6dca93e5f70c85216b5e069 /devices
parent770c204d5a283add29e03e421490e1d5b9663f3c (diff)
address review; use constructor for HCI Adapter
Diffstat (limited to 'devices')
-rw-r--r--devices/ble_hci/common-hal/_bleio/Adapter.c3
-rw-r--r--devices/ble_hci/common-hal/_bleio/Adapter.h1
-rw-r--r--devices/ble_hci/common-hal/_bleio/__init__.c10
-rw-r--r--devices/ble_hci/common-hal/_bleio/hci_include/NOTE.txt4
4 files changed, 15 insertions, 3 deletions
diff --git a/devices/ble_hci/common-hal/_bleio/Adapter.c b/devices/ble_hci/common-hal/_bleio/Adapter.c
index 27a251281..559b586de 100644
--- a/devices/ble_hci/common-hal/_bleio/Adapter.c
+++ b/devices/ble_hci/common-hal/_bleio/Adapter.c
@@ -341,7 +341,8 @@ STATIC void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
}
}
-void common_hal_bleio_adapter_hci_uart_init(bleio_adapter_obj_t *self, busio_uart_obj_t *uart, digitalio_digitalinout_obj_t *rts, digitalio_digitalinout_obj_t *cts) {
+void common_hal_bleio_adapter_construct_hci_uart(bleio_adapter_obj_t *self, busio_uart_obj_t *uart, digitalio_digitalinout_obj_t *rts, digitalio_digitalinout_obj_t *cts) {
+ self->allocated = true;
self->hci_uart = uart;
self->rts_digitalinout = rts;
self->cts_digitalinout = cts;
diff --git a/devices/ble_hci/common-hal/_bleio/Adapter.h b/devices/ble_hci/common-hal/_bleio/Adapter.h
index dbccfbfb1..bec1329f2 100644
--- a/devices/ble_hci/common-hal/_bleio/Adapter.h
+++ b/devices/ble_hci/common-hal/_bleio/Adapter.h
@@ -52,6 +52,7 @@ typedef struct _bleio_adapter_obj_t {
busio_uart_obj_t* hci_uart;
digitalio_digitalinout_obj_t *rts_digitalinout;
digitalio_digitalinout_obj_t *cts_digitalinout;
+ bool allocated; // True when in use.
bool now_advertising;
bool extended_advertising;
bool circuitpython_advertising;
diff --git a/devices/ble_hci/common-hal/_bleio/__init__.c b/devices/ble_hci/common-hal/_bleio/__init__.c
index 25aca39b5..9fc4b480d 100644
--- a/devices/ble_hci/common-hal/_bleio/__init__.c
+++ b/devices/ble_hci/common-hal/_bleio/__init__.c
@@ -74,6 +74,9 @@ void bleio_reset() {
return;
}
common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, false);
+ common_hal_bleio_adapter_obj.allocated = false;
+
+ bleio_set_adapter(mp_const_none);
//FIX bonding_reset();
supervisor_start_bluetooth();
@@ -86,6 +89,13 @@ bleio_adapter_obj_t common_hal_bleio_adapter_obj = {
},
};
+bleio_adapter_obj_t *common_hal_bleio_allocate_adapter_or_raise(void) {
+ if (common_hal_bleio_adapter_obj.allocated) {
+ mp_raise_RuntimeError(translate("Too many Adapters"));
+ }
+ return &common_hal_bleio_adapter_obj;
+}
+
void common_hal_bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLE_CONN_HANDLE_INVALID) {
mp_raise_bleio_ConnectionError(translate("Not connected"));
diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/NOTE.txt b/devices/ble_hci/common-hal/_bleio/hci_include/NOTE.txt
index 4d2968c39..ac34c815c 100644
--- a/devices/ble_hci/common-hal/_bleio/hci_include/NOTE.txt
+++ b/devices/ble_hci/common-hal/_bleio/hci_include/NOTE.txt
@@ -1,2 +1,2 @@
-The HCI-related include files here are copied from the Zephyr project:
-https://github.com/zephyrproject-rtos/zephyr/tree/master/include/bluetooth
+The HCI-related include files here were copied from the Zephyr project, from this commit:
+https://github.com/zephyrproject-rtos/zephyr/tree/0a87f9359edf1ec1c169626df3e19c2b4a4e9646/include/bluetooth