diff options
| author | arturo182 <arturo182@tlen.pl> | 2018-07-08 21:13:05 +0200 |
|---|---|---|
| committer | arturo182 <arturo182@tlen.pl> | 2018-07-13 16:01:15 +0200 |
| commit | 05c1384b677c64ea39d25b4bcd5dc5e38a4b134d (patch) | |
| tree | a3ba8560a608494a0f073dabfcf3bb5a1dbd5313 /ports/nrf/modules | |
| parent | 2f877bd8510c5650b5517e5f1920fb2a155132d3 (diff) | |
nrf: Split the ble module into a shared part and the port implementation
This allows other ports to implement these shared bindings.
Diffstat (limited to 'ports/nrf/modules')
| -rw-r--r-- | ports/nrf/modules/ble/help_sd.h | 47 | ||||
| -rw-r--r-- | ports/nrf/modules/ble/modble.c | 104 |
2 files changed, 0 insertions, 151 deletions
diff --git a/ports/nrf/modules/ble/help_sd.h b/ports/nrf/modules/ble/help_sd.h deleted file mode 100644 index 027bbdd51..000000000 --- a/ports/nrf/modules/ble/help_sd.h +++ /dev/null @@ -1,47 +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. - */ - -#ifndef HELP_SD_H__ -#define HELP_SD_H__ - -#include "bluetooth_conf.h" - -#if MICROPY_PY_BLE - -#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 diff --git a/ports/nrf/modules/ble/modble.c b/ports/nrf/modules/ble/modble.c deleted file mode 100644 index 5b75025d1..000000000 --- a/ports/nrf/modules/ble/modble.c +++ /dev/null @@ -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 |
