@@ -528,7 +528,6 @@ static int _advertising_event(struct ble_gap_event *event, void *self_in) {
528528 #endif
529529 break ;
530530 }
531- background_callback_add_core (& bleio_background_callback );
532531 return 0 ;
533532}
534533
@@ -559,7 +558,13 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
559558 return rc ;
560559 }
561560
562- bool high_duty_directed = directed_to != NULL && interval <= 3.5 && timeout <= 1.3 ;
561+ bool high_duty_directed = directed_to != NULL && interval <= 3.5 && timeout <= 1 ; // Really 1.3, but it's an int
562+
563+ uint32_t timeout_ms = timeout * 1000 ;
564+ if (timeout_ms == 0 ) {
565+ timeout_ms = BLE_HS_FOREVER ;
566+ }
567+
563568
564569 #if MYNEWT_VAL (BLE_EXT_ADV )
565570 bool extended = advertising_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN ||
@@ -621,7 +626,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
621626 }
622627 }
623628
624- rc = ble_gap_ext_adv_start (0 , timeout / 10 , 0 );
629+ rc = ble_gap_ext_adv_start (0 , timeout_ms , 0 );
625630 #else
626631 uint8_t conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON ;
627632 if (directed_to != NULL ) {
@@ -650,7 +655,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
650655 }
651656 }
652657 rc = ble_gap_adv_start (own_addr_type , directed_to != NULL ? & peer : NULL ,
653- timeout / 10 ,
658+ timeout_ms ,
654659 & adv_params ,
655660 _advertising_event , self );
656661 #endif
@@ -694,11 +699,9 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
694699 mp_raise_NotImplementedError (NULL );
695700 }
696701
697- if (!timeout ) {
698- timeout = BLE_HS_FOREVER ;
699- } else if (timeout > INT32_MAX ) {
702+ if ((uint64_t )timeout * 1000ll >= BLE_HS_FOREVER ) {
700703 mp_raise_bleio_BluetoothError (MP_ERROR_TEXT ("Timeout is too long: Maximum timeout length is %d seconds" ),
701- INT32_MAX / 1000 );
704+ BLE_HS_FOREVER / 1000 - 1 );
702705 }
703706
704707 CHECK_NIMBLE_ERROR (_common_hal_bleio_adapter_start_advertising (self , connectable , anonymous , timeout , interval ,
0 commit comments