aboutsummaryrefslogtreecommitdiff
path: root/extmod/modbluetooth.c
AgeCommit message (Collapse)Author
2019-12-02extmod/modbluetooth: Simplify how BLE IRQ callback is scheduled.Damien George
Instead of enqueue_irq() inspecting the ringbuf to decide whether to schedule the IRQ callback (if ringbuf is empty), maintain a flag that knows if the callback is on the schedule queue or not. This saves about 150 bytes of code (for stm32 builds), and simplifies all uses of enqueue_irq() and schedule_ringbuf().
2019-11-25extmod/modbluetooth: Simplify management of pre-allocated event data.Jim Mussared
The address, adv payload and uuid fields of the event are pre-allocated by modbluetooth, and reused in the IRQ handler. Simplify this and move all storage into the `mp_obj_bluetooth_ble_t` instance. This now allows users to hold on to a reference to these instances without crashes, although they may be overwritten by future events. If they want to hold onto the values longer term they need to copy them.
2019-11-25extmod/modbluetooth: Create UUID from bytes and allow comparison ops.Jim Mussared
This allows construction of UUID objects from advertising data payloads and matching against known UUIDs.
2019-11-21extmod/modbluetooth: Prioritise non-scan-result events.Jim Mussared
Remove existing scan result events from the ringbuf if the ringbuf is full and we're trying to enqueue any other event. This is needed so that events such as SCAN_COMPLETE are always put on the ringbuf.
2019-10-29extmod/modbluetooth: Add gatts_set_buffer.Jim Mussared
- Adds an explicit way to set the size of a value's internal buffer, replacing `ble.gatts_write(handle, bytes(size))` (although that still works). - Add an "append" mode for values, which means that remote writes will append to the buffer.
2019-10-22extmod/modbluetooth: Rename module to "ubluetooth".Jim Mussared
For consistency with "umachine". Now that weak links are enabled by default for built-in modules, this should be a no-op, but allows extension of the bluetooth module by user code. Also move registration of ubluetooth to objmodule rather than port-specific.
2019-10-22extmod/modbluetooth: Persist reference to NimBLE service instances.Jim Mussared
NimBLE doesn't actually copy this data, it requires it to stay live. Only dereference when we register a new set of services. Fixes #5226 This will allow incrementally adding services in the future, so rename `reset` to `append` to make it clearer.
2019-10-22extmod/modbluetooth: Make UUID support the buffer protocol.Jim Mussared
Internally change the representation of UUIDs to LE uint8* to simplify this. This allows UUIDs to be easily used in BLE payloads (such as advertising). Ref: #5186
2019-10-15extmod/modbluetooth: In gap_advertise only accept None to stop adv.Damien George
To match the docs, and interval=0 may be used in the future to indicate something else.
2019-10-15extmod/modbluetooth: Make gap_disconnect not raise when disconnected.Jim Mussared
Previously it raised OSError(MP_ENOTCONN) if the conn_handle was already disconnected. Now it returns True/False.
2019-10-15extmod/modbluetooth: Improve ringbuf handling.Jim Mussared
No need to share the irq_data buffer with addresses. Split them into two separate buffers and manage their max length independently.
2019-10-15extmod/modbluetooth: Fix order of params to IRQ_GATTS_WRITE event.Jim Mussared
2019-10-15extmod/modbluetooth: Clear gap_advertise payload when data is empty.Jim Mussared
Also fix default adv interval to 500ms.
2019-10-11extmod/modbluetooth: Use us instead of ms for advertising interval.Jim Mussared
This is to more accurately match the BLE spec, where intervals are configured in units of channel hop time (625us). When it was specified in ms, not all "valid" intervals were able to be specified. Now that we're also allowing configuration of scan interval, this commit updates advertising to match.
2019-10-11extmod/modbluetooth: Allow config of scan interval/window.Jim Mussared
This adds two additional optional kwargs to `gap_scan()`: - `interval_us`: How long between scans. - `window_us`: How long to scan for during a scan. The default with NimBLE is a 11.25ms window with a 1.28s interval. Changing these parameters is important for detecting low-frequency advertisements (e.g. beacons). Note: these params are in microseconds, not milliseconds in order to allow the 625us granularity offered by the spec.
2019-10-01extmod/modbluetooth: Add low-level Python BLE API.Jim Mussared