Skip to content

Commit 5521b6a

Browse files
committed
extmod/modbluetooth: Remove non-sync event support.
This was the original implementation before we had a way to support running events synchronously from the BLE stack. ESP32 was the last remaining port using this, and now that it's been updated (in 5dbb822 & e05d0a6) we can remove this. Removes the MICROPY_PY_BLUETOOTH_ENTER. This was previously a no-op on ports (e.g. stm32) using sync events anyway. Replaced with MICROPY_BEGIN_ATOMIC_SECTION where necessary (e.g. unix mpbthciport.c). Also makes pairing&bonding enabled by default (this was effectively the current behavior as it was enabled when sync events were enabled). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 5dbb822 commit 5521b6a

File tree

16 files changed

+17
-596
lines changed

16 files changed

+17
-596
lines changed

docs/library/bluetooth.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ Configuration
7070
characteristic 0x2a00. This can be set at any time and changed multiple
7171
times.
7272

73-
- ``'rxbuf'``: Get/set the size in bytes of the internal buffer used to store
74-
incoming events. This buffer is global to the entire BLE driver and so
75-
handles incoming data for all events, including all characteristics.
76-
Increasing this allows better handling of bursty incoming data (for
77-
example scan results) and the ability to receive larger characteristic values.
78-
7973
- ``'mtu'``: Get/set the MTU that will be used during a ATT MTU exchange. The
8074
resulting MTU will be the minimum of this and the remote device's MTU.
8175
ATT MTU exchange will not happen automatically (unless the remote device initiates
@@ -114,7 +108,7 @@ Event Handling
114108
**Note:** As an optimisation to prevent unnecessary allocations, the ``addr``,
115109
``adv_data``, ``char_data``, ``notify_data``, and ``uuid`` entries in the
116110
tuples are read-only memoryview instances pointing to :mod:`bluetooth`'s internal
117-
ringbuffer, and are only valid during the invocation of the IRQ handler
111+
memory, and are only valid during the invocation of the IRQ handler
118112
function. If your program needs to save one of these values to access after
119113
the IRQ handler has returned (e.g. by saving it in a class instance or global
120114
variable), then it needs to take a copy of the data, either by using ``bytes()``
@@ -128,6 +122,8 @@ Event Handling
128122
used elsewhere in the program. And to print data from within the IRQ handler,
129123
``print(bytes(addr))`` will be needed.
130124

125+
This is also true of the ``data`` tuple itself, do not store a reference to it.
126+
131127
An event handler showing all possible events::
132128

133129
def bt_irq(event, data):

extmod/btstack/btstack.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ EXTMOD_SRC_C += extmod/btstack/modbluetooth_btstack.c
1111
INC += -I$(TOP)/$(BTSTACK_EXTMOD_DIR)
1212

1313
CFLAGS_MOD += -DMICROPY_BLUETOOTH_BTSTACK=1
14-
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1
15-
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1
1614

1715
BTSTACK_DIR = $(TOP)/lib/btstack
1816

extmod/btstack/modbluetooth_btstack.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ struct _mp_btstack_pending_op_t {
160160
uint8_t buf[];
161161
};
162162

163-
// Must hold MICROPY_PY_BLUETOOTH_ENTER.
164163
STATIC void btstack_remove_pending_operation(mp_btstack_pending_op_t *pending_op, bool del) {
165164
bool removed = btstack_linked_list_remove(&MP_STATE_PORT(bluetooth_btstack_root_pointers)->pending_ops, (btstack_linked_item_t *)pending_op);
166165
assert(removed);
@@ -174,7 +173,6 @@ STATIC void btstack_remove_pending_operation(mp_btstack_pending_op_t *pending_op
174173
// att_server_request_to_send_notification.
175174
// We now have an opportunity to re-try the operation with an empty ACL buffer.
176175
STATIC void btstack_notify_indicate_ready_handler(void *context) {
177-
MICROPY_PY_BLUETOOTH_ENTER
178176
mp_btstack_pending_op_t *pending_op = (mp_btstack_pending_op_t *)context;
179177
DEBUG_printf("btstack_notify_indicate_ready_handler op_type=%d conn_handle=%d value_handle=%d len=%zu\n", pending_op->op_type, pending_op->conn_handle, pending_op->value_handle, pending_op->len);
180178
if (pending_op->op_type == MP_BLUETOOTH_BTSTACK_PENDING_NOTIFY) {
@@ -191,7 +189,6 @@ STATIC void btstack_notify_indicate_ready_handler(void *context) {
191189
}
192190
// Can't free the pending op as we're in IRQ context. Leave it for the GC.
193191
btstack_remove_pending_operation(pending_op, false /* del */);
194-
MICROPY_PY_BLUETOOTH_EXIT
195192
}
196193

197194
// Register a pending background operation -- copies the buffer, and makes it known to the GC.
@@ -209,11 +206,9 @@ STATIC mp_btstack_pending_op_t *btstack_enqueue_pending_operation(uint16_t op_ty
209206
pending_op->context_registration.context = pending_op;
210207
}
211208

212-
MICROPY_PY_BLUETOOTH_ENTER
213209
bool added = btstack_linked_list_add(&MP_STATE_PORT(bluetooth_btstack_root_pointers)->pending_ops, (btstack_linked_item_t *)pending_op);
214210
assert(added);
215211
(void)added;
216-
MICROPY_PY_BLUETOOTH_EXIT
217212

218213
return pending_op;
219214
}
@@ -226,7 +221,6 @@ STATIC mp_btstack_pending_op_t *btstack_enqueue_pending_operation(uint16_t op_ty
226221
// TODO: Can we make btstack give us the value_handle for regular write (with response) so that we
227222
// know for sure that we're using the correct entry.
228223
STATIC mp_btstack_pending_op_t *btstack_finish_pending_operation(uint16_t op_type, uint16_t conn_handle, uint16_t value_handle, bool del) {
229-
MICROPY_PY_BLUETOOTH_ENTER
230224
DEBUG_printf("btstack_finish_pending_operation op_type=%d conn_handle=%d value_handle=%d\n", op_type, conn_handle, value_handle);
231225
btstack_linked_list_iterator_t it;
232226
btstack_linked_list_iterator_init(&it, &MP_STATE_PORT(bluetooth_btstack_root_pointers)->pending_ops);
@@ -236,12 +230,10 @@ STATIC mp_btstack_pending_op_t *btstack_finish_pending_operation(uint16_t op_typ
236230
if (pending_op->op_type == op_type && pending_op->conn_handle == conn_handle && (value_handle == 0xffff || pending_op->value_handle == value_handle)) {
237231
DEBUG_printf("btstack_finish_pending_operation: found value_handle=%d len=%zu\n", pending_op->value_handle, pending_op->len);
238232
btstack_remove_pending_operation(pending_op, del);
239-
MICROPY_PY_BLUETOOTH_EXIT
240233
return del ? NULL : pending_op;
241234
}
242235
}
243236
DEBUG_printf("btstack_finish_pending_operation: not found\n");
244-
MICROPY_PY_BLUETOOTH_EXIT
245237
return NULL;
246238
}
247239
#endif
@@ -1118,9 +1110,7 @@ int mp_bluetooth_gatts_notify_send(uint16_t conn_handle, uint16_t value_handle,
11181110
}
11191111

11201112
// Attempt to send immediately. If it succeeds, btstack will copy the buffer.
1121-
MICROPY_PY_BLUETOOTH_ENTER
11221113
int err = att_server_notify(conn_handle, value_handle, value, value_len);
1123-
MICROPY_PY_BLUETOOTH_EXIT
11241114

11251115
if (err == BTSTACK_ACL_BUFFERS_FULL) {
11261116
DEBUG_printf("mp_bluetooth_gatts_notify_send: ACL buffer full, scheduling callback\n");
@@ -1155,9 +1145,7 @@ int mp_bluetooth_gatts_indicate(uint16_t conn_handle, uint16_t value_handle) {
11551145
// acknowledged (or timeout/error).
11561146

11571147
// Attempt to send immediately, will copy buffer.
1158-
MICROPY_PY_BLUETOOTH_ENTER
11591148
int err = att_server_indicate(conn_handle, value_handle, data, len);
1160-
MICROPY_PY_BLUETOOTH_EXIT
11611149

11621150
if (err == BTSTACK_ACL_BUFFERS_FULL) {
11631151
DEBUG_printf("mp_bluetooth_gatts_indicate: ACL buffer full, scheduling callback\n");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy