Skip to content

Commit c1bcc25

Browse files
committed
nrf: _bleio: clean up timeout calculation
The timeout value is calculated by the common-hal layer now, so we don't need to be quite so clever about calculating it here. Signed-off-by: Sean Cross <[email protected]>
1 parent f56188c commit c1bcc25

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ports/nrf/bluetooth/ble_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
4343
#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION))
44+
#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME) * (RESOLUTION)) / 1000000)
4445
// 0.625 msecs (625 usecs)
4546
#define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625)
4647
// Microseconds is the base unit. The macros above know that.

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,13 @@ STATIC bool advertising_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
600600

601601
switch (ble_evt->header.evt_id) {
602602
case BLE_GAP_EVT_ADV_SET_TERMINATED:
603-
mp_printf(&mp_plat_print, "Advertising set terminated - %d advertising events were completed - reason: %d\n", ble_evt->evt.gap_evt.params.adv_set_terminated.num_completed_adv_events, ble_evt->evt.gap_evt.params.adv_set_terminated.reason);
604603
common_hal_bleio_adapter_stop_advertising(self);
605604
ble_drv_remove_event_handler(advertising_on_ble_evt, self_in);
606605
break;
607606

608607
default:
609608
// For debugging.
610-
mp_printf(&mp_plat_print, "Unhandled Advertising etvent: 0x%04x\n", ble_evt->header.evt_id);
609+
// mp_printf(&mp_plat_print, "Unhandled advertising event: 0x%04x\n", ble_evt->header.evt_id);
611610
return false;
612611
break;
613612
}
@@ -722,7 +721,7 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
722721
if (!timeout) {
723722
if (anonymous) {
724723
// The Nordic macro is in units of 10ms. Convert to seconds.
725-
uint32_t adv_timeout_max_secs = BLE_GAP_ADV_TIMEOUT_LIMITED_MAX / 100;
724+
uint32_t adv_timeout_max_secs = UNITS_TO_SEC(BLE_GAP_ADV_TIMEOUT_LIMITED_MAX, UNIT_10_MS);
726725
uint32_t rotate_timeout_max_secs = BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S;
727726
timeout = MIN(adv_timeout_max_secs, rotate_timeout_max_secs);
728727
}
@@ -732,7 +731,7 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
732731
} else {
733732
if (SEC_TO_UNITS(timeout, UNIT_10_MS) > BLE_GAP_ADV_TIMEOUT_LIMITED_MAX) {
734733
mp_raise_bleio_BluetoothError(translate("Timeout is too long: Maximum timeout length is %d seconds"),
735-
BLE_GAP_ADV_TIMEOUT_LIMITED_MAX / 100);
734+
UNITS_TO_SEC(BLE_GAP_ADV_TIMEOUT_LIMITED_MAX, UNIT_10_MS));
736735
}
737736
}
738737

0 commit comments

Comments
 (0)