summaryrefslogtreecommitdiff
path: root/extmod/btstack
AgeCommit message (Collapse)Author
2021-06-23extmod/btstack: Check that BLE is active before performing operations.Damien George
Otherwise it can easily lead to a hard crash. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23extmod/btstack: Add missing call to mp_bluetooth_hci_uart_deinit.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32: Provide a custom BTstack runloop that integrates with soft timer.Damien George
It reschedules the BT HCI poll soft timer so that it is called exactly when the next timer expires. Signed-off-by: Damien George <damien@micropython.org>
2021-02-19extmod/modbluetooth: Separate enabling of "client" from "central".Jim Mussared
Previously, the MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE macro controlled enabling both the central mode and the GATT client functionality (because usually the two go together). This commits adds a new MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT macro that separately enables the GATT client functionality. This defaults to MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE. This also fixes a bug in the NimBLE bindings where a notification or indication would not be received by a peripheral (acting as client) as gap_event_cb wasn't handling it. Now both central_gap_event_cb and peripheral_gap_event_cb share the same common handler for these events. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-02-17extmod/btstack: Use MICROPY_HW_BLE_UART_BAUDRATE for first UART init.Damien George
Otherwise the UART may be left in a state at baudrate=0. Signed-off-by: Damien George <damien@micropython.org>
2021-02-17extmod/modbluetooth: Allow NimBLE to use Zephyr static address.Jim Mussared
Zephyr controllers can be queried for a static address (computed from the device ID). BlueKitchen already supports this, but make them both use the same macro to enable the feature.
2021-02-12extmod/btstack: Enable SYNC_EVENTS, PAIRING_BONDING by default.Damien George
Synchronous events work on stm32 and unix ports. Signed-off-by: Damien George <damien@micropython.org>
2021-02-12extmod/btstack: Add stub functions for passkey, l2cap bindings.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-02-12extmod/btstack: Add HCI trace debugging option in btstack_hci_uart.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-12-02extmod/modbluetooth: Add gap_pair(conn_handle) func to intiate pairing.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02extmod/modbluetooth: Allow configuration of pairing/bonding parameters.Jim Mussared
This allows setting the security and MITM-protection requirements. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02extmod/modbluetooth: Add _IRQ_ENCRYPTION_UPDATE event.Andrew Leech
This allows the application to be notified if any of encrypted, authenticated and bonded state change, as well as the encryption key size. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02extmod/modbluetooth: Allow setting char/desc enc/auth options.Andrew Leech
This widens the characteristic/descriptor flags to 16-bit, to allow setting encryption/authentication requirements. Sets the required flags for NimBLE and btstack implementations. The BLE.FLAG_* constants will eventually be deprecated in favour of copy and paste Python constants (like the IRQs). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-12-02extmod/modbluetooth: Add _IRQ_CONNECTION_UPDATE event.Andrew Leech
This allows the application to be notified of changes to the connection interval, connection latency and supervision timeout. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.Jim Mussared
This requires that the event handlers are called from non-interrupt context (i.e. the MicroPython scheduler). This will allow the BLE stack (e.g. NimBLE) to run from the scheduler rather than an IRQ like PENDSV, and therefore be able to invoke Python callbacks directly/synchronously. This allows writing Python BLE handlers for events that require immediate response such as _IRQ_READ_REQUEST (which was previous a hard IRQ) and future events relating to pairing/bonding. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13extmod/modbluetooth: Combine gattc-data-available callbacks into one.Jim Mussared
Instead of having the stack indicate a "start", "data"..., "end", pass through the data in one callback as an array of chunks of data. This is because the upcoming non-ringbuffer modbluetooth implementation cannot buffer the data in the ringbuffer and requires instead a single callback with all the data, to pass to the Python callback. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13extmod/modbluetooth: Make UUID type accessible outside modbluetooth.c.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-05extmod/btstack/btstack.mk: Add -Wimplicit-fallthrough=0.Jim Mussared
This is needed since -Wextra was added to the build in bef412789ea93c521bd9c2dddc22b9b3484da574 Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-09-18extmod/modbluetooth: Implement MTU.Jim Mussared
2020-09-08extmod/btstack: Detect HCI UART init failure.Jim Mussared
2020-09-08extmod/btstack: Add btstack support for _IRQ_GATTS_READ_REQUEST.Andrew Leech
2020-09-08extmod/modbluetooth: Allow using mp_hal_get_mac as a static address.Jim Mussared
Generally a controller should either have its own public address hardcoded, or loaded by the driver (e.g. cywbt43). However, for a controller that has no public address where you still want a long-term stable address, this allows you to use a static address generated by the port. Typically on STM32 this will be an LAA, but a board might override this.
2020-09-08extmod/modbluetooth: Implement configuration of address modes.Jim Mussared
Changes `BLE.config('mac')` to return a tuple (addr_mode, addr). Adds `BLE.config(addr_mode=...)` to set the addressing mode.
2020-09-08unix: Implement BLE H4 HCI UART for btstack/nimble.Jim Mussared
This commit adds support for using Bluetooth on the unix port via a H4 serial interface (distinct from a USB dongle), with both BTstack and NimBLE Bluetooth stacks. Note that MICROPY_PY_BLUETOOTH is now disabled for the coverage variant. Prior to this commit Bluetooth was anyway not being built on Travis because libusb was not detected. But now that bluetooth works in H4 mode it will be built, and will lead to a large decrease in coverage because Bluetooth tests cannot be run on Travis.
2020-09-08extmod/modbluetooth: Refactor stack/hci/driver/port bindings.Jim Mussared
Previously the interaction between the different layers of the Bluetooth stack was different on each port and each stack. This commit defines common interfaces between them and implements them for cyw43, btstack, nimble, stm32, unix.
2020-09-08extmod/modbluetooth: Rename logging macro to be just DEBUG_printf.Jim Mussared
And prefix the debug message with "btstack:" or "nimble:", depending on the context. Also use correct format specifier for %zu.
2020-08-26extmod/bluetooth: Support active scanning in BLE.gap_scan().Andrew Leech
This adds an additional optional parameter to gap_scan() to select active scanning, where scan responses are returned as well as normal scan results. This parameter is False by default which retains the existing behaviour.
2020-08-26extmod/btstack: Implement GAP scan duration_ms parameter.Jim Mussared
This commit makes scanning work when duration_ms is set to zero. Prior to this it would not work with duration_ms set to zero.
2020-07-20extmod/modbluetooth: Add event for "indicate acknowledgement".Jim Mussared
This commit adds the IRQ_GATTS_INDICATE_DONE BLE event which will be raised with the status of gatts_indicate (unlike notify, indications require acknowledgement). An example of its use is added to ble_temperature.py, and to the multitests in ble_characteristic.py. Implemented for btstack and nimble bindings, tested in both directions between unix/btstack and pybd/nimble.
2020-07-20extmod/modbluetooth: Fix so it builds in peripheral-only mode.Jim Mussared
2020-07-18docs/library: Add gatts_indicate() doc to ubluetooth.rst.Jim Mussared
Also clarify behavior of `gatts_notify` and add some TODOs about adding an event for indication acknowledgement.
2020-07-18extmod/btstack: Schedule notify/indicate/write ops for bg completion.Jim Mussared
The goal of this commit is to allow using ble.gatts_notify() at any time, even if the stack is not ready to send the notification right now. It also addresses the same issue for ble.gatts_indicate() and ble.gattc_write() (without response). In addition this commit fixes the case where the buffer passed to write-with-response wasn't copied, meaning it could be modified by the caller, affecting the in-progress write. The changes are: - gatts_notify/indicate will now run in the background if the ACL buffer is currently full, meaning that notify/indicate can be called at any time. - gattc_write(mode=0) (no response) will now allow for one outstanding write. - gattc_write(mode=1) (with response) will now copy the buffer so that it can't be modified by the caller while the write is in progress. All four paths also now track the buffer while the operation is in progress, which prevents the GC free'ing the buffer while it's still needed.
2020-06-18tools/codeformat.py: Include extmod/{btstack,nimble} in code formatting.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-06-05extmod/modbluetooth: Implement read done event.Jim Mussared
On btstack there's no status associated with the read result, it comes through as a separate event. This allows you to detect read failures or timeouts.
2020-06-05extmod/modbluetooth: Allow discovery of svc/char by uuid.Jim Mussared
In most situations this is a more efficient way of going straight to the service and characteristic you need.
2020-06-05extmod/modbluetooth: Add discover complete events for svc/char/desc.Jim Mussared
Without this it's difficult to implement a state machine correctly if the desired services are not found.
2020-05-11extmod/modbluetooth: Add support for changing the GAP device name.Damien George
This commit allows the user to set/get the GAP device name used by service 0x1800, characteristic 0x2a00. The usage is: BLE.config(gap_name="myname") print(BLE.config("gap_name")) As part of this change the compile-time setting MICROPY_PY_BLUETOOTH_DEFAULT_NAME is renamed to MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME to emphasise its link to GAP and this new "gap_name" config value. And the default value of this for the NimBLE bindings is changed from "PYBD" to "MPY NIMBLE" to be more generic.
2020-04-29unix: Add btstack to the unix submodules list.Jim Mussared
But only when bluetooth is enabled, i.e. if building the dev or coverage variants, and we have libusb available. Update travis to match, i.e. specify the variant when doing `make submodules`.
2020-04-29extmod/modbluetooth: Fix sign compare and unused variable warnings.Jim Mussared
2020-04-29unix: Add support for modbluetooth and BLE using btstack.Jim Mussared
This commit adds full support to the unix port for Bluetooth using the common extmod/modbluetooth Python bindings. This uses the libusb HCI transport, which supports many common USB BT adaptors.
2020-04-29extmod/btstack: Implement more robust init/deinit sequencing.Jim Mussared
2020-04-29extmod/modbluetooth: Don't hold atomic section during mp_sched_schedule.Jim Mussared
Because, for example, on unix the atomic section isn't re-entrant, and mp_sched_schedule() will try to re-acquire the atomic section.
2020-04-29stm32/Makefile: Rename SRC_LIB to LIB_SRC_C to match other ports.Jim Mussared
2020-04-07extmod/btstack: Pass through SCAN_RSP events.Damien George
The latest version of BTstack has a bug fixed so that it correctly configures scan parameters if they are set right after activating the stack. This means that BLE.gap_scan() will correctly set the scanning to passive and so SCAN_RSP events are not passed through, so we don't need to explicitly filter them in our bindings.
2020-03-11extmod/modbluetooth: Change scan result's "connectable" to "adv_type".Damien George
This commit changes the BLE _IRQ_SCAN_RESULT data from: addr_type, addr, connectable, rssi, adv_data to: addr_type, addr, adv_type, rssi, adv_data This allows _IRQ_SCAN_RESULT to handle all scan result types (not just connectable and non-connectable passive scans), and to distinguish between them using adv_type which is an integer taking values 0x00-0x04 per the BT specification. This is a breaking change to the API, albeit a very minor one: the existing connectable value was a boolean and True now becomes 0x00, False becomes 0x02. Documentation is updated and a test added. Fixes #5738.
2020-03-11extmod/nimble: Clarify active state and check for active in all methods.Jim Mussared
This commit ensures that the BLE stack is active before allowing operations that may otherwise crash if it's not active. It also clarifies the state better (adding the "stopping" state) and renames mp_bluetooth_is_enabled to the more self-explanatory mp_bluetooth_is_active.
2020-03-10extmod/btstack: Implement notifications/indications for GATT clients.Damien George
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10extmod/btstack: Implement scan and gatt client, connect and disconnect.Damien George
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10extmod/btstack: Implement gatts_db for btstack.Damien George
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10extmod/btstack: Implement service registration.Damien George
Work done in collaboration with Jim Mussared aka @jimmo.