diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2020-08-14 15:47:21 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-09-08 12:53:24 +1000 |
commit | c4af714d58213bb23b81f3736f785d897e60ac77 (patch) | |
tree | 62fae24743bf5e80dac4d81bb256b6399bc44cac /extmod/modbluetooth.c | |
parent | 1b1b22905e1aa7676c51078f75b1bd73d8383a4a (diff) |
extmod/modbluetooth: Implement configuration of address modes.
Changes `BLE.config('mac')` to return a tuple (addr_mode, addr).
Adds `BLE.config(addr_mode=...)` to set the addressing mode.
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r-- | extmod/modbluetooth.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 82efe4938..a8a762ce3 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -308,9 +308,11 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map return mp_obj_new_bytes(buf, len); } case MP_QSTR_mac: { + uint8_t addr_type; uint8_t addr[6]; - mp_bluetooth_get_device_addr(addr); - return mp_obj_new_bytes(addr, MP_ARRAY_SIZE(addr)); + mp_bluetooth_get_current_address(&addr_type, addr); + mp_obj_t items[] = { MP_OBJ_NEW_SMALL_INT(addr_type), mp_obj_new_bytes(addr, MP_ARRAY_SIZE(addr)) }; + return mp_obj_new_tuple(2, items); } case MP_QSTR_rxbuf: return mp_obj_new_int(self->ringbuf.size); @@ -366,6 +368,11 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map m_del(uint8_t, old_irq_data_buf, old_irq_data_alloc); break; } + case MP_QSTR_addr_mode: { + mp_int_t addr_mode = mp_obj_get_int(e->value); + mp_bluetooth_set_address_mode(addr_mode); + break; + } default: mp_raise_ValueError(MP_ERROR_TEXT("unknown config param")); } |