summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-02-20 21:55:04 -0500
committerDan Halbert <halbert@halwitz.org>2020-02-20 21:55:04 -0500
commite31ac710be0e1983ec791dc4db169505afdd8d63 (patch)
treee14b70fa0d5ee349ad62729c85bf0163d27d4c57 /shared-bindings
parent675930083de102ab73af6f6a586614793e467f5f (diff)
Enable _bleio adapter when _bleio is imported
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_bleio/Adapter.c2
-rw-r--r--shared-bindings/_bleio/__init__.c12
2 files changed, 13 insertions, 1 deletions
diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c
index 500055cf3..921667f0f 100644
--- a/shared-bindings/_bleio/Adapter.c
+++ b/shared-bindings/_bleio/Adapter.c
@@ -117,7 +117,7 @@ const mp_obj_property_t bleio_adapter_address_obj = {
//| .. attribute:: name
//|
-//| name of the BLE adapter used once connected. Not used in advertisements.
+//| name of the BLE adapter used once connected.
//| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
//| to make it easy to distinguish multiple CircuitPython boards.
//|
diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c
index 5d26862a6..dd401398c 100644
--- a/shared-bindings/_bleio/__init__.c
+++ b/shared-bindings/_bleio/__init__.c
@@ -132,6 +132,14 @@ NORETURN void mp_raise_bleio_SecurityError(const compressed_string_t* fmt, ...)
nlr_raise(exception);
}
+// Called when _bleio is imported.
+STATIC mp_obj_t bleio___init__(void) {
+ common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, true);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(bleio___init___obj, bleio___init__);
+
+
STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
// Name must be the first entry so that the exception printing below is correct.
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__bleio) },
@@ -156,6 +164,10 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ConnectionError), MP_ROM_PTR(&mp_type_bleio_ConnectionError) },
{ MP_ROM_QSTR(MP_QSTR_RoleError), MP_ROM_PTR(&mp_type_bleio_RoleError) },
{ MP_ROM_QSTR(MP_QSTR_SecurityError), MP_ROM_PTR(&mp_type_bleio_SecurityError) },
+
+ // Initialization
+ { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&bleio___init___obj) },
+
};
STATIC MP_DEFINE_CONST_DICT(bleio_module_globals, bleio_module_globals_table);