Merge pull request #1014 from arturo182/nrf_shared_ble
nrf: Split the ble module into a shared part and the port implementation
This commit is contained in:
commit
bfe14ff824
|
@ -146,7 +146,6 @@ DRIVERS_SRC_C += $(addprefix modules/,\
|
|||
ubluepy/ubluepy_descriptor.c \
|
||||
ubluepy/ubluepy_scanner.c \
|
||||
ubluepy/ubluepy_scan_entry.c \
|
||||
ble/modble.c \
|
||||
)
|
||||
|
||||
SRC_COMMON_HAL += \
|
||||
|
@ -173,6 +172,12 @@ SRC_COMMON_HAL += \
|
|||
supervisor/__init__.c \
|
||||
supervisor/Runtime.c \
|
||||
|
||||
ifneq ($(SD), )
|
||||
SRC_COMMON_HAL += \
|
||||
bleio/__init__.c \
|
||||
bleio/Adapter.c
|
||||
endif
|
||||
|
||||
# These don't have corresponding files in each port but are still located in
|
||||
# shared-bindings to make it clear what the contents of the modules are.
|
||||
SRC_BINDINGS_ENUMS = \
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef BLUETOOTH_CONF_H__
|
||||
#define BLUETOOTH_CONF_H__
|
||||
|
||||
#define MICROPY_PY_BLE (1)
|
||||
#define MICROPY_PY_BLE_NUS (0)
|
||||
#define BLUETOOTH_WEBBLUETOOTH_REPL (0)
|
||||
#define MICROPY_PY_UBLUEPY (1)
|
||||
#define MICROPY_PY_UBLUEPY_PERIPHERAL (1)
|
||||
#define MICROPY_PY_UBLUEPY_CENTRAL (1)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ble_drv.h"
|
||||
#include "nrfx.h"
|
||||
#include "nrf_error.h"
|
||||
#include "py/misc.h"
|
||||
|
||||
void common_hal_bleio_adapter_set_enabled(bool enabled) {
|
||||
if (enabled) {
|
||||
const uint32_t err = ble_drv_stack_enable();
|
||||
if (err != NRF_SUCCESS) {
|
||||
NRFX_ASSERT(err);
|
||||
}
|
||||
|
||||
printf("SoftDevice enabled\n");
|
||||
} else {
|
||||
ble_drv_stack_disable();
|
||||
}
|
||||
}
|
||||
|
||||
bool common_hal_bleio_adapter_get_enabled(void) {
|
||||
return ble_drv_stack_enabled();
|
||||
}
|
||||
|
||||
void common_hal_bleio_adapter_get_address(vstr_t *vstr) {
|
||||
ble_drv_addr_t address;
|
||||
ble_drv_address_get(&address);
|
||||
|
||||
vstr_printf(vstr, ""HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
|
||||
HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
|
||||
address.addr[5], address.addr[4], address.addr[3],
|
||||
address.addr[2], address.addr[1], address.addr[0]);
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -24,24 +25,13 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef HELP_SD_H__
|
||||
#define HELP_SD_H__
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_ADAPTER_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_ADAPTER_H
|
||||
|
||||
#include "bluetooth_conf.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
#if MICROPY_PY_BLE
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
} super_adapter_obj_t;
|
||||
|
||||
#define HELP_TEXT_SD \
|
||||
"If compiled with SD=<softdevice> the additional commands are\n" \
|
||||
"available:\n" \
|
||||
" ble.enable() -- enable bluetooth stack\n" \
|
||||
" ble.disable() -- disable bluetooth stack\n" \
|
||||
" ble.enabled() -- check whether bluetooth stack is enabled\n" \
|
||||
" ble.address() -- return device address as text string\n" \
|
||||
"\n"
|
||||
|
||||
#else
|
||||
#define HELP_TEXT_SD
|
||||
#endif // MICROPY_PY_BLE
|
||||
|
||||
#endif
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_ADAPTER_H
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/bleio/__init__.h"
|
||||
#include "shared-bindings/bleio/Adapter.h"
|
||||
|
||||
// The singleton bleio.Adapter object, bound to bleio.adapter
|
||||
// It currently only has properties and no state
|
||||
const super_adapter_obj_t common_hal_bleio_adapter_obj = {
|
||||
.base = {
|
||||
.type = &bleio_adapter_type,
|
||||
},
|
||||
};
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_PY_BLE
|
||||
|
||||
#include "mpconfigboard.h"
|
||||
#include "ble_drv.h"
|
||||
|
||||
/// \method enable()
|
||||
/// Enable BLE softdevice.
|
||||
mp_obj_t ble_obj_enable(void) {
|
||||
printf("SoftDevice enabled\n");
|
||||
uint32_t err_code = ble_drv_stack_enable();
|
||||
if (err_code < 0) {
|
||||
// TODO: raise exception.
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
/// \method disable()
|
||||
/// Disable BLE softdevice.
|
||||
mp_obj_t ble_obj_disable(void) {
|
||||
ble_drv_stack_disable();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
/// \method enabled()
|
||||
/// Get state of whether the softdevice is enabled or not.
|
||||
mp_obj_t ble_obj_enabled(void) {
|
||||
uint8_t is_enabled = ble_drv_stack_enabled();
|
||||
mp_int_t enabled = is_enabled;
|
||||
return MP_OBJ_NEW_SMALL_INT(enabled);
|
||||
}
|
||||
|
||||
/// \method address()
|
||||
/// Return device address as text string.
|
||||
mp_obj_t ble_obj_address(void) {
|
||||
ble_drv_addr_t local_addr;
|
||||
ble_drv_address_get(&local_addr);
|
||||
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, 17);
|
||||
|
||||
vstr_printf(&vstr, ""HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
|
||||
HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
|
||||
local_addr.addr[5], local_addr.addr[4], local_addr.addr[3],
|
||||
local_addr.addr[2], local_addr.addr[1], local_addr.addr[0]);
|
||||
|
||||
mp_obj_t mac_str = mp_obj_new_str(vstr.buf, vstr.len, false);
|
||||
|
||||
vstr_clear(&vstr);
|
||||
|
||||
return mac_str;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enable_obj, ble_obj_enable);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_disable_obj, ble_obj_disable);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enabled_obj, ble_obj_enabled);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_address_obj, ble_obj_address);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ble_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ble) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&ble_obj_enable_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&ble_obj_disable_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enabled), MP_ROM_PTR(&ble_obj_enabled_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&ble_obj_address_obj) },
|
||||
};
|
||||
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table);
|
||||
|
||||
const mp_obj_module_t ble_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&ble_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_BLE
|
|
@ -126,27 +126,27 @@
|
|||
|
||||
#define MICROPY_KBD_EXCEPTION (1)
|
||||
|
||||
#ifndef MICROPY_PY_HW_RNG
|
||||
#define MICROPY_PY_HW_RNG (1)
|
||||
#endif
|
||||
|
||||
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
|
||||
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
|
||||
|
||||
// Scan gamepad every 32ms
|
||||
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
|
||||
|
||||
// if sdk is in use, import configuration
|
||||
#if BLUETOOTH_SD
|
||||
#include "bluetooth_conf.h"
|
||||
#define MICROPY_PY_BLEIO (1)
|
||||
#define MICROPY_PY_BLE_NUS (0)
|
||||
#define MICROPY_PY_UBLUEPY (1)
|
||||
#define MICROPY_PY_UBLUEPY_PERIPHERAL (1)
|
||||
#define MICROPY_PY_UBLUEPY_CENTRAL (1)
|
||||
#define BLUETOOTH_WEBBLUETOOTH_REPL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_BLEIO
|
||||
#define MICROPY_PY_BLEIO (0)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_UBLUEPY
|
||||
#define MICROPY_PY_UBLUEPY (0)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_BLE_NUS
|
||||
#define MICROPY_PY_BLE_NUS (0)
|
||||
#define MICROPY_PY_UBLUEPY (0)
|
||||
#endif
|
||||
|
||||
// type definitions for the specific machine
|
||||
|
@ -181,22 +181,20 @@ extern const struct _mp_obj_module_t struct_module;
|
|||
extern const struct _mp_obj_module_t time_module;
|
||||
extern const struct _mp_obj_module_t supervisor_module;
|
||||
extern const struct _mp_obj_module_t gamepad_module;
|
||||
extern const struct _mp_obj_module_t bleio_module;
|
||||
|
||||
extern const struct _mp_obj_module_t mp_module_ubluepy;
|
||||
|
||||
extern const struct _mp_obj_module_t ble_module;
|
||||
|
||||
#if MICROPY_PY_UBLUEPY
|
||||
#define UBLUEPY_MODULE { MP_ROM_QSTR(MP_QSTR_ubluepy), MP_ROM_PTR(&mp_module_ubluepy) },
|
||||
#else
|
||||
#define UBLUEPY_MODULE
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_BLE
|
||||
extern const struct _mp_obj_module_t ble_module;
|
||||
#define BLE_MODULE { MP_ROM_QSTR(MP_QSTR_ble), MP_ROM_PTR(&ble_module) },
|
||||
#if MICROPY_PY_BLEIO
|
||||
#define BLEIO_MODULE { MP_ROM_QSTR(MP_QSTR_bleio), MP_ROM_PTR(&bleio_module) },
|
||||
#else
|
||||
#define BLE_MODULE
|
||||
#define BLEIO_MODULE
|
||||
#endif
|
||||
|
||||
#define MICROPY_PORT_BUILTIN_MODULES \
|
||||
|
@ -214,7 +212,7 @@ extern const struct _mp_obj_module_t ble_module;
|
|||
{ MP_OBJ_NEW_QSTR (MP_QSTR_supervisor ), (mp_obj_t)&supervisor_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_gamepad ), (mp_obj_t)&gamepad_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_time ), (mp_obj_t)&time_module }, \
|
||||
BLE_MODULE \
|
||||
BLEIO_MODULE \
|
||||
UBLUEPY_MODULE \
|
||||
|
||||
// extra built in names to add to the global namespace
|
||||
|
@ -223,10 +221,6 @@ extern const struct _mp_obj_module_t ble_module;
|
|||
{ MP_OBJ_NEW_QSTR (MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
|
||||
{ MP_ROM_QSTR (MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
|
||||
|
||||
// extra constants
|
||||
#define MICROPY_PORT_CONSTANTS \
|
||||
BLE_MODULE \
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/objproperty.h"
|
||||
#include "shared-bindings/bleio/Adapter.h"
|
||||
|
||||
//| .. currentmodule:: bleio
|
||||
//|
|
||||
//| :class:`Adapter` --- BLE adapter information
|
||||
//| ----------------------------------------------------
|
||||
//|
|
||||
//| Get current status of the BLE adapter
|
||||
//|
|
||||
//| Usage::
|
||||
//|
|
||||
//| import bleio
|
||||
//| bleio.adapter.enabled = True
|
||||
//| print(bleio.adapter.address)
|
||||
//|
|
||||
|
||||
//| .. class:: Adapter()
|
||||
//|
|
||||
//| You cannot create an instance of `bleio.Adapter`.
|
||||
//| Use `bleio.adapter` to access the sole instance available.
|
||||
//|
|
||||
|
||||
//| .. attribute:: adapter.enabled
|
||||
//|
|
||||
//| State of the BLE adapter.
|
||||
//|
|
||||
|
||||
//| .. attribute:: adapter.address
|
||||
//|
|
||||
//| MAC address of the BLE adapter. (read-only)
|
||||
//|
|
||||
|
||||
#define BLE_ADDRESS_LEN 17
|
||||
|
||||
STATIC mp_obj_t bleio_adapter_get_enabled(mp_obj_t self) {
|
||||
return mp_obj_new_bool(common_hal_bleio_adapter_get_enabled());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_get_enabled_obj, bleio_adapter_get_enabled);
|
||||
|
||||
static mp_obj_t bleio_adapter_set_enabled(mp_obj_t self, mp_obj_t value) {
|
||||
const bool enabled = mp_obj_is_true(value);
|
||||
|
||||
common_hal_bleio_adapter_set_enabled(enabled);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_adapter_set_enabled_obj, bleio_adapter_set_enabled);
|
||||
|
||||
const mp_obj_property_t bleio_adapter_enabled_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = { (mp_obj_t)&bleio_adapter_get_enabled_obj,
|
||||
(mp_obj_t)&bleio_adapter_set_enabled_obj,
|
||||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) {
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, BLE_ADDRESS_LEN);
|
||||
|
||||
common_hal_bleio_adapter_get_address(&vstr);
|
||||
|
||||
const mp_obj_t mac_str = mp_obj_new_str(vstr.buf, vstr.len, false);
|
||||
|
||||
vstr_clear(&vstr);
|
||||
|
||||
return mac_str;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_get_address_obj, bleio_adapter_get_address);
|
||||
|
||||
const mp_obj_property_t bleio_adapter_address_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = { (mp_obj_t)&bleio_adapter_get_address_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t bleio_adapter_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_enabled), MP_ROM_PTR(&bleio_adapter_enabled_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_adapter_address_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(bleio_adapter_locals_dict, bleio_adapter_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t bleio_adapter_type = {
|
||||
.base = { &mp_type_type },
|
||||
.name = MP_QSTR_Adapter,
|
||||
.locals_dict = (mp_obj_t)&bleio_adapter_locals_dict,
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADAPTER_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADAPTER_H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
const mp_obj_type_t bleio_adapter_type;
|
||||
|
||||
extern bool common_hal_bleio_adapter_get_enabled(void);
|
||||
extern void common_hal_bleio_adapter_set_enabled(bool enabled);
|
||||
extern void common_hal_bleio_adapter_get_address(vstr_t *address);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADAPTER_H
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "shared-bindings/bleio/__init__.h"
|
||||
|
||||
//| :mod:`bleio` --- Bluetooth Low Energy functionality
|
||||
//| ================================================================
|
||||
//|
|
||||
//| .. module:: bleio
|
||||
//| :synopsis: Bluetooth Low Energy functionality
|
||||
//| :platform: nRF
|
||||
//|
|
||||
//| The `bleio` module contains methods for managing the BLE adapter.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Adapter
|
||||
//|
|
||||
//| .. attribute:: adapter
|
||||
//|
|
||||
//| BLE Adapter information, such as enabled state as well as MAC
|
||||
//| address.
|
||||
//| This object is the sole instance of `bleio.Adapter`.
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_adapter), MP_ROM_PTR(&common_hal_bleio_adapter_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(bleio_module_globals, bleio_module_globals_table);
|
||||
|
||||
const mp_obj_module_t bleio_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&bleio_module_globals,
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* Copyright (c) 2018 Artur Pacholec
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO___INIT___H
|
||||
|
||||
#include "common-hal/bleio/Adapter.h"
|
||||
|
||||
extern const super_adapter_obj_t common_hal_bleio_adapter_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO___INIT___H
|
|
@ -29,6 +29,7 @@ Module Supported Ports
|
|||
`binascii` **ESP8266**
|
||||
`bitbangio` **SAMD Express, ESP8266**
|
||||
`board` **All Supported**
|
||||
`bleio` **nRF**
|
||||
`busio` **All Supported**
|
||||
`digitalio` **All Supported**
|
||||
`gamepad` **SAMD Express, nRF**
|
||||
|
|
Loading…
Reference in New Issue