extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.
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>
This commit is contained in:
committed by
Damien George
parent
6d9fdff8d0
commit
81e92d3d6e
@@ -838,15 +838,15 @@ STATIC uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_GATTS_ON_READ_CALLBACK
|
||||
// Allow Python code to override value (by using gatts_write), or deny (by returning false) the read.
|
||||
// Note this will be a no-op if the ringbuffer implementation is being used, as the Python callback cannot
|
||||
// be executed synchronously. This is currently always the case for btstack.
|
||||
if ((buffer == NULL) && (buffer_size == 0)) {
|
||||
if (!mp_bluetooth_gatts_on_read_request(connection_handle, att_handle)) {
|
||||
DEBUG_printf("att_read_callback: read request denied\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t ret = att_read_callback_handle_blob(entry->data, entry->data_len, offset, buffer, buffer_size);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user