Skip to content

Commit 3c7ca20

Browse files
jimmodpgeorge
authored andcommitted
extmod/modbluetooth: Fix so it builds in peripheral-only mode.
1 parent 43ceada commit 3c7ca20

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

extmod/btstack/modbluetooth_btstack.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ STATIC int btstack_error_to_errno(int err) {
7070
}
7171
}
7272

73+
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
7374
STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(uint16_t uuid16, const uint8_t *uuid128) {
7475
mp_obj_bluetooth_uuid_t result;
7576
if (uuid16 != 0) {
@@ -82,6 +83,7 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(uint16_t uuid16, const uint8_t *uu
8283
}
8384
return result;
8485
}
86+
#endif
8587

8688
// Notes on supporting background ops (e.g. an attempt to gatts_notify while
8789
// an existing notification is in progress):
@@ -286,16 +288,6 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
286288
DEBUG_EVENT_printf(" --> btstack # conns changed\n");
287289
} else if (event_type == HCI_EVENT_VENDOR_SPECIFIC) {
288290
DEBUG_EVENT_printf(" --> hci vendor specific\n");
289-
} else if (event_type == GAP_EVENT_ADVERTISING_REPORT) {
290-
DEBUG_EVENT_printf(" --> gap advertising report\n");
291-
bd_addr_t address;
292-
gap_event_advertising_report_get_address(packet, address);
293-
uint8_t adv_event_type = gap_event_advertising_report_get_advertising_event_type(packet);
294-
uint8_t address_type = gap_event_advertising_report_get_address_type(packet);
295-
int8_t rssi = gap_event_advertising_report_get_rssi(packet);
296-
uint8_t length = gap_event_advertising_report_get_data_length(packet);
297-
const uint8_t *data = gap_event_advertising_report_get_data(packet);
298-
mp_bluetooth_gap_on_scan_result(address_type, address, adv_event_type, rssi, data, length);
299291
} else if (event_type == HCI_EVENT_DISCONNECTION_COMPLETE) {
300292
DEBUG_EVENT_printf(" --> hci disconnect complete\n");
301293
uint16_t conn_handle = hci_event_disconnection_complete_get_connection_handle(packet);
@@ -311,6 +303,16 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
311303
uint8_t addr[6] = {0};
312304
mp_bluetooth_gap_on_connected_disconnected(irq_event, conn_handle, 0xff, addr);
313305
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
306+
} else if (event_type == GAP_EVENT_ADVERTISING_REPORT) {
307+
DEBUG_EVENT_printf(" --> gap advertising report\n");
308+
bd_addr_t address;
309+
gap_event_advertising_report_get_address(packet, address);
310+
uint8_t adv_event_type = gap_event_advertising_report_get_advertising_event_type(packet);
311+
uint8_t address_type = gap_event_advertising_report_get_address_type(packet);
312+
int8_t rssi = gap_event_advertising_report_get_rssi(packet);
313+
uint8_t length = gap_event_advertising_report_get_data_length(packet);
314+
const uint8_t *data = gap_event_advertising_report_get_data(packet);
315+
mp_bluetooth_gap_on_scan_result(address_type, address, adv_event_type, rssi, data, length);
314316
} else if (event_type == GATT_EVENT_QUERY_COMPLETE) {
315317
uint16_t conn_handle = gatt_event_query_complete_get_handle(packet);
316318
uint16_t status = gatt_event_query_complete_get_att_status(packet);

extmod/btstack/modbluetooth_btstack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ typedef struct _mp_bluetooth_btstack_root_pointers_t {
4444
// Characteristic (and descriptor) value storage.
4545
mp_gatts_db_t gatts_db;
4646

47+
btstack_linked_list_t pending_ops;
48+
4749
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
4850
// Registration for notify/indicate events.
4951
gatt_client_notification_t notification;
50-
btstack_linked_list_t pending_ops;
5152
#endif
5253
} mp_bluetooth_btstack_root_pointers_t;
5354

extmod/modbluetooth.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,12 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size
836836
// Note the int8_t got packed into the ringbuf as a uint8_t.
837837
data_tuple->items[j++] = MP_OBJ_NEW_SMALL_INT((int8_t)ringbuf_get(ringbuf));
838838
}
839+
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
839840
if (uuid) {
840841
ringbuf_get_uuid(ringbuf, uuid);
841842
data_tuple->items[j++] = MP_OBJ_FROM_PTR(uuid);
842843
}
844+
#endif
843845
// The code that enqueues into the ringbuf should ensure that it doesn't
844846
// put more than bt->irq_data_data_alloc bytes into the ringbuf, because
845847
// that's what's available here in bt->irq_data_bytes.

extmod/nimble/modbluetooth_nimble.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ STATIC ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_u
9696
}
9797
}
9898

99+
// modbluetooth (and the layers above it) work in BE for addresses, Nimble works in LE.
100+
STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) {
101+
for (int i = 0; i < 6; ++i) {
102+
addr_out[i] = addr_in[5 - i];
103+
}
104+
}
105+
99106
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
100107

101108
STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) {
@@ -123,13 +130,6 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) {
123130
return result;
124131
}
125132

126-
// modbluetooth (and the layers above it) work in BE for addresses, Nimble works in LE.
127-
STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) {
128-
for (int i = 0; i < 6; ++i) {
129-
addr_out[i] = addr_in[5 - i];
130-
}
131-
}
132-
133133
STATIC ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr) {
134134
ble_addr_t addr_nimble;
135135
addr_nimble.type = addr_type;

0 commit comments

Comments
 (0)