@@ -528,7 +528,6 @@ static int _advertising_event(struct ble_gap_event *event, void *self_in) {
528
528
#endif
529
529
break ;
530
530
}
531
- background_callback_add_core (& bleio_background_callback );
532
531
return 0 ;
533
532
}
534
533
@@ -559,7 +558,13 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
559
558
return rc ;
560
559
}
561
560
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
+
563
568
564
569
#if MYNEWT_VAL (BLE_EXT_ADV )
565
570
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,
621
626
}
622
627
}
623
628
624
- rc = ble_gap_ext_adv_start (0 , timeout / 10 , 0 );
629
+ rc = ble_gap_ext_adv_start (0 , timeout_ms , 0 );
625
630
#else
626
631
uint8_t conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON ;
627
632
if (directed_to != NULL ) {
@@ -650,7 +655,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
650
655
}
651
656
}
652
657
rc = ble_gap_adv_start (own_addr_type , directed_to != NULL ? & peer : NULL ,
653
- timeout / 10 ,
658
+ timeout_ms ,
654
659
& adv_params ,
655
660
_advertising_event , self );
656
661
#endif
@@ -694,11 +699,9 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
694
699
mp_raise_NotImplementedError (NULL );
695
700
}
696
701
697
- if (!timeout ) {
698
- timeout = BLE_HS_FOREVER ;
699
- } else if (timeout > INT32_MAX ) {
702
+ if ((uint64_t )timeout * 1000ll >= BLE_HS_FOREVER ) {
700
703
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 );
702
705
}
703
706
704
707
CHECK_NIMBLE_ERROR (_common_hal_bleio_adapter_start_advertising (self , connectable , anonymous , timeout , interval ,
0 commit comments