Skip to content

Commit 0993ade

Browse files
committed
Bugfixes in the initialization of BT for the new NimBLE controller
1 parent ae3aba8 commit 0993ade

2 files changed

Lines changed: 197 additions & 2 deletions

File tree

src/bt.rs

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,10 @@ where
714714
coex_phy_coded_tx_rx_time_limit: crate::sys::DEFAULT_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF
715715
as _,
716716
dis_scan_backoff: crate::sys::NIMBLE_DISABLE_SCAN_BACKOFF as _,
717+
// `esp32c2` defaults this to 0; every other chip in this block defaults to 1
718+
#[cfg(esp32c2)]
719+
ble_scan_classify_filter_enable: 0,
720+
#[cfg(not(esp32c2))]
717721
ble_scan_classify_filter_enable: 1,
718722
main_xtal_freq: crate::sys::CONFIG_XTAL_FREQ as _,
719723
#[cfg(esp32c2)]
@@ -732,6 +736,198 @@ where
732736
not(esp_idf_version = "5.1")
733737
))]
734738
csa2_select: crate::sys::DEFAULT_BT_LE_50_FEATURE_SUPPORT as _,
739+
// The fields below were added to the modern NimBLE controller config (shared by
740+
// c2/c5/c6/h2) across IDF 5.3.4 / 5.4.2 / 5.5.0. They are absent from `Default`
741+
// (which zeroes them), and several have non-zero upstream defaults - notably
742+
// `vhci_enabled`, without which Bluedroid's HCI host layer fails to start. Field
743+
// availability differs per chip/version, hence the gating below:
744+
// - c6/h2 got Group A/B at 5.3.4; c5 got them one minor later, at 5.4.2.
745+
// - c2 (minimal controller) has Group A but none of the Group B fields.
746+
//
747+
// Group A - c2, c6, h2 (>= 5.3.4) and c5 (>= 5.4.2)
748+
#[cfg(all(
749+
any(
750+
esp_idf_version_patch_at_least_5_3_4,
751+
esp_idf_version_patch_at_least_5_4_2,
752+
esp_idf_version_at_least_5_5_0,
753+
),
754+
any(
755+
not(esp32c5),
756+
esp_idf_version_patch_at_least_5_4_2,
757+
esp_idf_version_at_least_5_5_0,
758+
),
759+
))]
760+
vhci_enabled: crate::sys::DEFAULT_BT_LE_VHCI_ENABLED as _,
761+
#[cfg(all(
762+
any(
763+
esp_idf_version_patch_at_least_5_3_4,
764+
esp_idf_version_patch_at_least_5_4_2,
765+
esp_idf_version_at_least_5_5_0,
766+
),
767+
any(
768+
not(esp32c5),
769+
esp_idf_version_patch_at_least_5_4_2,
770+
esp_idf_version_at_least_5_5_0,
771+
),
772+
))]
773+
ble_aa_check: crate::sys::DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS as _,
774+
#[cfg(all(
775+
any(
776+
esp_idf_version_patch_at_least_5_3_4,
777+
esp_idf_version_patch_at_least_5_4_2,
778+
esp_idf_version_at_least_5_5_0,
779+
),
780+
any(
781+
not(esp32c5),
782+
esp_idf_version_patch_at_least_5_4_2,
783+
esp_idf_version_at_least_5_5_0,
784+
),
785+
))]
786+
ble_llcp_disc_flag: crate::sys::BT_LE_CTRL_LLCP_DISC_FLAG as _,
787+
#[cfg(all(
788+
any(
789+
esp_idf_version_patch_at_least_5_3_4,
790+
esp_idf_version_patch_at_least_5_4_2,
791+
esp_idf_version_at_least_5_5_0,
792+
),
793+
any(
794+
not(esp32c5),
795+
esp_idf_version_patch_at_least_5_4_2,
796+
esp_idf_version_at_least_5_5_0,
797+
),
798+
))]
799+
scan_backoff_upperlimitmax: crate::sys::BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX as _,
800+
// Group B - as Group A, but not present on esp32c2
801+
#[cfg(all(
802+
not(esp32c2),
803+
any(
804+
esp_idf_version_patch_at_least_5_3_4,
805+
esp_idf_version_patch_at_least_5_4_2,
806+
esp_idf_version_at_least_5_5_0,
807+
),
808+
any(
809+
not(esp32c5),
810+
esp_idf_version_patch_at_least_5_4_2,
811+
esp_idf_version_at_least_5_5_0,
812+
),
813+
))]
814+
ble_chan_ass_en: crate::sys::DEFAULT_BT_LE_CTRL_CHAN_ASS_EN as _,
815+
#[cfg(all(
816+
not(esp32c2),
817+
any(
818+
esp_idf_version_patch_at_least_5_3_4,
819+
esp_idf_version_patch_at_least_5_4_2,
820+
esp_idf_version_at_least_5_5_0,
821+
),
822+
any(
823+
not(esp32c5),
824+
esp_idf_version_patch_at_least_5_4_2,
825+
esp_idf_version_at_least_5_5_0,
826+
),
827+
))]
828+
ble_data_lenth_zero_aux: crate::sys::DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX as _,
829+
#[cfg(all(
830+
not(esp32c2),
831+
any(
832+
esp_idf_version_patch_at_least_5_3_4,
833+
esp_idf_version_patch_at_least_5_4_2,
834+
esp_idf_version_at_least_5_5_0,
835+
),
836+
any(
837+
not(esp32c5),
838+
esp_idf_version_patch_at_least_5_4_2,
839+
esp_idf_version_at_least_5_5_0,
840+
),
841+
))]
842+
ptr_check_enabled: crate::sys::DEFAULT_BT_LE_PTR_CHECK_ENABLED as _,
843+
#[cfg(all(
844+
not(esp32c2),
845+
any(
846+
esp_idf_version_patch_at_least_5_3_4,
847+
esp_idf_version_patch_at_least_5_4_2,
848+
esp_idf_version_at_least_5_5_0,
849+
),
850+
any(
851+
not(esp32c5),
852+
esp_idf_version_patch_at_least_5_4_2,
853+
esp_idf_version_at_least_5_5_0,
854+
),
855+
))]
856+
fast_conn_data_tx_en: crate::sys::DEFAULT_BT_LE_CTRL_FAST_CONN_DATA_TX_EN as _,
857+
#[cfg(all(
858+
not(esp32c2),
859+
any(
860+
esp_idf_version_patch_at_least_5_3_4,
861+
esp_idf_version_patch_at_least_5_4_2,
862+
esp_idf_version_at_least_5_5_0,
863+
),
864+
any(
865+
not(esp32c5),
866+
esp_idf_version_patch_at_least_5_4_2,
867+
esp_idf_version_at_least_5_5_0,
868+
),
869+
))]
870+
ch39_txpwr: crate::sys::BLE_LL_TX_PWR_DBM_N as _,
871+
// `adv_rsv_cnt` / `conn_rsv_cnt` mirror the controller's `MIN(...)` macros, which
872+
// bindgen cannot capture as constants, so they are reproduced from their operands.
873+
#[cfg(all(
874+
not(esp32c2),
875+
any(
876+
esp_idf_version_patch_at_least_5_3_4,
877+
esp_idf_version_patch_at_least_5_4_2,
878+
esp_idf_version_at_least_5_5_0,
879+
),
880+
any(
881+
not(esp32c5),
882+
esp_idf_version_patch_at_least_5_4_2,
883+
esp_idf_version_at_least_5_5_0,
884+
),
885+
))]
886+
#[allow(clippy::unnecessary_cast)]
887+
adv_rsv_cnt: core::cmp::min(
888+
crate::sys::DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES as u32,
889+
crate::sys::CONFIG_BT_LE_EXT_ADV_RESERVED_MEMORY_COUNT as u32,
890+
) as _,
891+
#[cfg(all(
892+
not(esp32c2),
893+
any(
894+
esp_idf_version_patch_at_least_5_3_4,
895+
esp_idf_version_patch_at_least_5_4_2,
896+
esp_idf_version_at_least_5_5_0,
897+
),
898+
any(
899+
not(esp32c5),
900+
esp_idf_version_patch_at_least_5_4_2,
901+
esp_idf_version_at_least_5_5_0,
902+
),
903+
))]
904+
#[allow(clippy::unnecessary_cast)]
905+
conn_rsv_cnt: core::cmp::min(
906+
crate::sys::DEFAULT_BT_LE_MAX_CONNECTIONS as u32,
907+
crate::sys::CONFIG_BT_LE_CONN_RESERVED_MEMORY_COUNT as u32,
908+
) as _,
909+
// Group C - `priority_level_cfg`, added in 5.5.0 (still present on 6.0+), not on c2
910+
#[cfg(all(not(esp32c2), esp_idf_version_at_least_5_5_0))]
911+
priority_level_cfg: crate::sys::BT_LL_CTRL_PRIO_LVL_CFG as _,
912+
// Group D - added in 5.5.0 and removed again in 6.0, not on c2
913+
#[cfg(all(
914+
not(esp32c2),
915+
esp_idf_version_at_least_5_5_0,
916+
not(esp_idf_version_at_least_6_0_0),
917+
))]
918+
slv_fst_rx_lat_en: crate::sys::DEFAULT_BT_LE_CTRL_SLV_FAST_RX_CONN_DATA_EN as _,
919+
#[cfg(all(
920+
not(esp32c2),
921+
esp_idf_version_at_least_5_5_0,
922+
not(esp_idf_version_at_least_6_0_0),
923+
))]
924+
dl_itvl_phy_sync_en: crate::sys::DEFAULT_BT_LE_CTRL_DL_ITVL_PHY_SYNC_EN as _,
925+
#[cfg(all(
926+
not(esp32c2),
927+
esp_idf_version_at_least_5_5_0,
928+
not(esp_idf_version_at_least_6_0_0),
929+
))]
930+
scan_allow_adi_filter: crate::sys::DEFAULT_BT_SCAN_ALLOW_ENH_ADI_FILTER as _,
735931
config_magic: CONFIG_MAGIC as _,
736932
..Default::default()
737933
};

src/mqtt/client.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extern crate alloc;
77
use alloc::boxed::Box;
88
use alloc::sync::Arc;
99

10-
use ::log::error;
1110
use embedded_svc::mqtt::client::{asynch, Client, Connection, Enqueue, ErrorType, Publish};
1211

1312
use crate::private::unblocker::Unblocker;
@@ -551,7 +550,7 @@ impl<'a> EspMqttClient<'a> {
551550
#[cfg(esp_idf_mqtt_protocol_5)]
552551
if let Some(props) = conf.mqtt5_connection_property.as_ref() {
553552
if conf.protocol_version != Some(MqttProtocolVersion::V5) {
554-
error!(
553+
::log::error!(
555554
"mqtt5_connection_property requires protocol_version = Some(MqttProtocolVersion::V5)"
556555
);
557556
return Err(EspError::from_infallible::<ESP_ERR_INVALID_ARG>());

0 commit comments

Comments
 (0)