@@ -280,7 +280,7 @@ STATIC void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
280280 const size_t len = sizeof (default_ble_name );
281281
282282 bt_addr_t addr ;
283- check_hci_error (hci_read_bd_addr (& addr ));
283+ hci_check_error (hci_read_bd_addr (& addr ));
284284
285285 default_ble_name [len - 4 ] = nibble_to_hex_lower [addr .val [1 ] >> 4 & 0xf ];
286286 default_ble_name [len - 3 ] = nibble_to_hex_lower [addr .val [1 ] & 0xf ];
@@ -373,7 +373,7 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
373373 }
374374
375375 // Enabling or disabling: stop any current activity; reset to known state.
376- check_hci_error ( hci_reset () );
376+ hci_reset ();
377377 self -> now_advertising = false;
378378 self -> extended_advertising = false;
379379 self -> circuitpython_advertising = false;
@@ -397,7 +397,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
397397 check_enabled (self );
398398
399399 bt_addr_t addr ;
400- check_hci_error (hci_read_bd_addr (& addr ));
400+ hci_check_error (hci_read_bd_addr (& addr ));
401401
402402 bleio_address_obj_t * address = m_new_obj (bleio_address_obj_t );
403403 address -> base .type = & bleio_address_type ;
@@ -406,6 +406,14 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
406406 return address ;
407407}
408408
409+ bool common_hal_bleio_adapter_set_address (bleio_adapter_obj_t * self , bleio_address_obj_t * address ) {
410+ mp_buffer_info_t bufinfo ;
411+ if (!mp_get_buffer (address -> bytes , & bufinfo , MP_BUFFER_READ )) {
412+ return false;
413+ }
414+ return hci_le_set_random_address (bufinfo .buf ) == HCI_OK ;
415+ }
416+
409417mp_obj_str_t * common_hal_bleio_adapter_get_name (bleio_adapter_obj_t * self ) {
410418 return self -> name ;
411419}
@@ -673,7 +681,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
673681 // Advertising interval.
674682 uint32_t interval_units = SEC_TO_UNITS (interval , UNIT_0_625_MS );
675683
676- check_hci_error (
684+ hci_check_error (
677685 hci_le_set_extended_advertising_parameters (
678686 0 , // handle
679687 props , // adv properties
@@ -697,7 +705,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
697705 uint8_t handle [1 ] = { 0 };
698706 uint16_t duration_10msec [1 ] = { timeout * 100 };
699707 uint8_t max_ext_adv_evts [1 ] = { 0 };
700- check_hci_error (
708+ hci_check_error (
701709 hci_le_set_extended_advertising_enable (
702710 BT_HCI_LE_ADV_ENABLE ,
703711 1 , // one advertising set.
@@ -725,7 +733,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
725733 // Advertising interval.
726734 uint16_t interval_units = SEC_TO_UNITS (interval , UNIT_0_625_MS );
727735
728- check_hci_error (
736+ hci_check_error (
729737 hci_le_set_advertising_parameters (
730738 interval_units , // min interval
731739 interval_units , // max interval
@@ -740,19 +748,19 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
740748 // even though the actual data length may be shorter.
741749 uint8_t full_data [MAX_ADVERTISEMENT_SIZE ] = { 0 };
742750 memcpy (full_data , advertising_data , MIN (sizeof (full_data ), advertising_data_len ));
743- check_hci_error (hci_le_set_advertising_data (advertising_data_len , full_data ));
751+ hci_check_error (hci_le_set_advertising_data (advertising_data_len , full_data ));
744752 memset (full_data , 0 , sizeof (full_data ));
745753 if (scan_response_data_len > 0 ) {
746754 memcpy (full_data , scan_response_data , MIN (sizeof (full_data ), scan_response_data_len ));
747- check_hci_error (hci_le_set_scan_response_data (scan_response_data_len , full_data ));
755+ hci_check_error (hci_le_set_scan_response_data (scan_response_data_len , full_data ));
748756 }
749757
750758 // No duration mechanism is provided for legacy advertising, so we need to do our own.
751759 self -> advertising_timeout_msecs = timeout * 1000 ;
752760 self -> advertising_start_ticks = supervisor_ticks_ms64 ();
753761
754762 // Start advertising.
755- check_hci_error (hci_le_set_advertising_enable (BT_HCI_LE_ADV_ENABLE ));
763+ hci_check_error (hci_le_set_advertising_enable (BT_HCI_LE_ADV_ENABLE ));
756764 self -> extended_advertising = false;
757765 } // end legacy advertising setup
758766
@@ -809,7 +817,7 @@ void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
809817 // OK if we're already stopped. There seems to be an ESP32 HCI bug:
810818 // If advertising is already off, then LE_SET_ADV_ENABLE does not return a response.
811819 if (result != HCI_RESPONSE_TIMEOUT ) {
812- check_hci_error (result );
820+ hci_check_error (result );
813821 }
814822
815823 //TODO startup CircuitPython advertising again.
@@ -942,5 +950,8 @@ void bleio_adapter_background(bleio_adapter_obj_t* adapter) {
942950 common_hal_bleio_adapter_stop_advertising (adapter );
943951 }
944952
945- hci_poll_for_incoming_pkt ();
953+ hci_result_t result = hci_poll_for_incoming_pkt ();
954+ if (result != HCI_OK ) {
955+ mp_printf (& mp_plat_print , "bad hci_poll_for_incoming_pkt() result in background: %d\n" , result );
956+ }
946957}
0 commit comments