From ac35a6e8f23f9cfe7452ae78e5c9ebebbdf331e0 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Thu, 22 May 2025 16:54:20 +0800 Subject: [PATCH] feat(ble): provided dynamic spi enable/disable api (cherry picked from commit 3568f19fef2c205556eb95c3e2ba116368f4be97) Co-authored-by: Zhou Xiao --- .../bt/common/ble_log/ble_log_spi_out.c | 21 +++++++++++++++++++ .../ble_log/include/ble_log/ble_log_spi_out.h | 1 + 2 files changed, 22 insertions(+) diff --git a/components/bt/common/ble_log/ble_log_spi_out.c b/components/bt/common/ble_log/ble_log_spi_out.c index 0c7105a2d7..0366e555a1 100644 --- a/components/bt/common/ble_log/ble_log_spi_out.c +++ b/components/bt/common/ble_log/ble_log_spi_out.c @@ -91,6 +91,7 @@ enum { // Private variables static bool spi_out_inited = false; +static bool spi_out_enabled = false; static spi_device_handle_t spi_handle = NULL; static uint32_t last_tx_done_ts = 0; @@ -239,6 +240,13 @@ IRAM_ATTR static inline int spi_out_append_trans(spi_out_trans_cb_t *trans_cb) return -1; } + // Note: To support dump log when disabled + if (!spi_out_enabled) { + trans_cb->length = 0; + trans_cb->flag = TRANS_CB_FLAG_AVAILABLE; + return 0; + } + // CRITICAL: Length unit conversion from bytes to bits trans_cb->trans.length = trans_cb->length * 8; trans_cb->trans.rxlength = 0; @@ -740,6 +748,7 @@ int ble_log_spi_out_init(void) // Initialization done ESP_LOGI(BLE_LOG_TAG, "Succeeded to initialize BLE log SPI output interface!"); spi_out_inited = true; + spi_out_enabled = true; #if SPI_OUT_FLUSH_TIMER_ENABLED // Start flushout timer @@ -796,6 +805,7 @@ void ble_log_spi_out_deinit(void) // Reset init flag spi_out_inited = false; + spi_out_enabled = false; } #if SPI_OUT_TS_SYNC_ENABLED @@ -1050,4 +1060,15 @@ void ble_log_spi_out_dump_all(void) portEXIT_CRITICAL_SAFE(&spinlock); } +void ble_log_spi_out_enable(bool enable) +{ + spi_out_enabled = enable; + + if (!enable) { +#if CONFIG_BT_BLE_LOG_SPI_OUT_TS_SYNC_ENABLED + ble_log_spi_out_ts_sync_stop(); +#endif // CONFIG_BT_BLE_LOG_SPI_OUT_TS_SYNC_ENABLED + } +} + #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED diff --git a/components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h b/components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h index 60c4aad1b1..4272d6ff0b 100644 --- a/components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h +++ b/components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h @@ -55,5 +55,6 @@ int ble_log_spi_out_printf(uint8_t source, const char *format, ...); int ble_log_spi_out_printf_enh(uint8_t source, uint8_t level, const char *tag, const char *format, ...); int ble_log_spi_out_write_with_ts(uint8_t source, const uint8_t *addr, uint16_t len); void ble_log_spi_out_dump_all(void); +void ble_log_spi_out_enable(bool enable); #endif // __BT_SPI_OUT_H__