Skip to content

Commit 2722f6b

Browse files
committed
Espressif BLE fixes: advertising duration, _bleio.adapter.connected
1. The advertising duration value for "forever" is different for `ble_gap_adv_start()` and `ble_gap_ext_adv_start()`. It is `BLE_HS_FOREVER` and `0`, respectively. 2. Code was added in adafruit#9289 that required that the MTU value was non-zero when returning true for `_bleio.adapter.connected`. This caused a brief interval, while a central was connecting, for a peripheral with both `ble.connected()` and `ble.advertising()` being `False`. The transition between the two states did not appear atomic. This compares with `nordic` where it was.
1 parent 6b4970b commit 2722f6b

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎ports/espressif/common-hal/_bleio/Adapter.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,6 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
561561
bool high_duty_directed = directed_to != NULL && interval <= 3.5 && timeout <= 1; // Really 1.3, but it's an int
562562

563563
uint32_t timeout_ms = timeout * 1000;
564-
if (timeout_ms == 0) {
565-
timeout_ms = BLE_HS_FOREVER;
566-
}
567-
568564

569565
#if MYNEWT_VAL(BLE_EXT_ADV)
570566
bool extended = advertising_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN ||
@@ -626,8 +622,12 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
626622
}
627623
}
628624

625+
// If timeout_ms is zero, it means advertise forever. This is different than ble_gap_adv_start().
629626
rc = ble_gap_ext_adv_start(0, timeout_ms, 0);
627+
630628
#else
629+
// Extended advertising not enabled.
630+
631631
uint8_t conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON;
632632
if (directed_to != NULL) {
633633
conn_mode = BLE_GAP_CONN_MODE_DIR;
@@ -654,8 +654,10 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
654654
return rc;
655655
}
656656
}
657-
rc = ble_gap_adv_start(own_addr_type, directed_to != NULL ? &peer: NULL,
658-
timeout_ms,
657+
// If timeout_ms is BLE_HS_FOREVER, it means advertise forever. This is different than ble_gap_ext_adv_start().
658+
rc = ble_gap_adv_start(own_addr_type,
659+
directed_to != NULL ? &peer: NULL,
660+
timeout_ms == 0 ? BLE_HS_FOREVER : timeout_ms,
659661
&adv_params,
660662
_advertising_event, self);
661663
#endif
@@ -739,7 +741,7 @@ bool common_hal_bleio_adapter_get_advertising(bleio_adapter_obj_t *self) {
739741
bool common_hal_bleio_adapter_get_connected(bleio_adapter_obj_t *self) {
740742
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
741743
bleio_connection_internal_t *connection = &bleio_connections[i];
742-
if (connection->conn_handle != BLEIO_HANDLE_INVALID && connection->mtu != 0) {
744+
if (connection->conn_handle != BLEIO_HANDLE_INVALID) {
743745
return true;
744746
}
745747
}
@@ -754,7 +756,7 @@ mp_obj_t common_hal_bleio_adapter_get_connections(bleio_adapter_obj_t *self) {
754756
mp_obj_t items[BLEIO_TOTAL_CONNECTION_COUNT];
755757
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
756758
bleio_connection_internal_t *connection = &bleio_connections[i];
757-
if (connection->conn_handle != BLEIO_HANDLE_INVALID && connection->mtu != 0) {
759+
if (connection->conn_handle != BLEIO_HANDLE_INVALID) {
758760
if (connection->connection_obj == mp_const_none) {
759761
connection->connection_obj = bleio_connection_new_from_internal(connection);
760762
}

0 commit comments

Comments
 (0)