mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
feat(ble): optimize reconfig hci uart pin code
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -37,7 +37,6 @@ typedef struct {
|
||||
static hci_driver_uart_env_t s_hci_driver_uart_env;
|
||||
static struct hci_h4_sm s_hci_driver_uart_h4_sm;
|
||||
static uint8_t s_hci_driver_uart_rx_data[CONFIG_BT_LE_HCI_RX_PROC_DATA_LEN];
|
||||
static hci_driver_uart_params_config_t hci_driver_uart_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
static int
|
||||
hci_driver_uart_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_t length,
|
||||
@ -190,8 +189,8 @@ hci_driver_uart_init(hci_driver_forward_fn *cb)
|
||||
|
||||
s_hci_driver_uart_env.rx_data = s_hci_driver_uart_rx_data;
|
||||
s_hci_driver_uart_env.forward_cb = cb;
|
||||
s_hci_driver_uart_env.hci_uart_params = &hci_driver_uart_params;
|
||||
hci_driver_uart_config(&hci_driver_uart_params);
|
||||
s_hci_driver_uart_env.hci_uart_params = hci_driver_uart_config_param_get();
|
||||
hci_driver_uart_config(s_hci_driver_uart_env.hci_uart_params);
|
||||
/* Currently, the queue size is set to 1. It will be considered as semaphore. */
|
||||
ESP_ERROR_CHECK(uart_driver_install(s_hci_driver_uart_env.hci_uart_params->hci_uart_port,
|
||||
CONFIG_BT_LE_HCI_UART_RX_BUFFER_SIZE,
|
||||
@ -215,14 +214,9 @@ int
|
||||
hci_driver_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
int rc;
|
||||
hci_driver_uart_params_config_t *uart_param = s_hci_driver_uart_env.hci_uart_params;
|
||||
|
||||
hci_driver_uart_task_delete();
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
hci_driver_uart_config(uart_param);
|
||||
hci_driver_uart_pin_update(tx_pin, rx_pin, cts_pin, rts_pin);
|
||||
/* Currently, the queue size is set to 1. It will be considered as semaphore. */
|
||||
ESP_ERROR_CHECK(uart_driver_install(s_hci_driver_uart_env.hci_uart_params->hci_uart_port,
|
||||
CONFIG_BT_LE_HCI_UART_RX_BUFFER_SIZE,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -60,6 +60,28 @@ typedef struct hci_driver_uart_params_config
|
||||
*/
|
||||
int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config);
|
||||
|
||||
/**
|
||||
* @brief Update the UART pin configuration for the HCI driver.
|
||||
*
|
||||
* This function updates the TX, RX, CTS, and RTS pin assignments for the HCI driver operating over UART.
|
||||
* It allows dynamic reconfiguration of UART pins as needed.
|
||||
*
|
||||
* @param tx_pin The GPIO number assigned to the UART TX pin.
|
||||
* @param rx_pin The GPIO number assigned to the UART RX pin.
|
||||
* @param cts_pin The GPIO number assigned to the UART CTS pin.
|
||||
* @param rts_pin The GPIO number assigned to the UART RTS pin.
|
||||
*
|
||||
* @return 0 on success, or a negative error code on failure.
|
||||
*/
|
||||
int hci_driver_uart_pin_update(int tx_pin, int rx_pin, int cts_pin, int rts_pin);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current UART configuration parameters for the HCI driver.
|
||||
*
|
||||
* @return hci_driver_uart_params_config_t* Pointer to the structure with UART configuration parameters.
|
||||
*/
|
||||
hci_driver_uart_params_config_t * hci_driver_uart_config_param_get(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -10,9 +10,9 @@
|
||||
#include "driver/uart.h"
|
||||
#include "hci_driver_uart.h"
|
||||
|
||||
|
||||
static const char *TAG = "hci_uart_config";
|
||||
static uart_config_t s_uart_cfg;
|
||||
static hci_driver_uart_params_config_t s_hci_driver_uart_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
{
|
||||
@ -26,7 +26,6 @@ int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
uart_cfg->source_clk= UART_SCLK_DEFAULT;
|
||||
uart_cfg->rx_flow_ctrl_thresh = UART_HW_FIFO_LEN(uart_config->hci_uart_port) - 1;
|
||||
|
||||
|
||||
ESP_LOGI(TAG,"set uart pin tx:%d, rx:%d.\n", uart_config->hci_uart_tx_pin, uart_config->hci_uart_rx_pin);
|
||||
ESP_LOGI(TAG,"set rts:%d, cts:%d.\n", uart_config->hci_uart_rts_pin, uart_config->hci_uart_cts_pin);
|
||||
ESP_LOGI(TAG,"set baud_rate:%d.\n", uart_config->hci_uart_baud);
|
||||
@ -38,3 +37,20 @@ int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
uart_config->hci_uart_rts_pin, uart_config->hci_uart_cts_pin));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
hci_driver_uart_pin_update(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
hci_driver_uart_params_config_t *uart_param = &s_hci_driver_uart_params;
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
return hci_driver_uart_config(uart_param);
|
||||
}
|
||||
|
||||
hci_driver_uart_params_config_t *
|
||||
hci_driver_uart_config_param_get(void)
|
||||
{
|
||||
return &s_hci_driver_uart_params;
|
||||
}
|
||||
|
@ -113,7 +113,6 @@ int hci_driver_uart_dma_tx_start(esp_bt_hci_tl_callback_t callback, void *arg);
|
||||
static const char *TAG = "uart_dma";
|
||||
static hci_driver_uart_dma_env_t s_hci_driver_uart_dma_env;
|
||||
static struct hci_h4_sm s_hci_driver_uart_h4_sm;
|
||||
static hci_driver_uart_params_config_t hci_driver_uart_dma_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
/* The list for hci_rx_data */
|
||||
STAILQ_HEAD(g_hci_rxinfo_list, hci_message);
|
||||
@ -626,8 +625,8 @@ hci_driver_uart_dma_init(hci_driver_forward_fn *cb)
|
||||
}
|
||||
|
||||
s_hci_driver_uart_dma_env.forward_cb = cb;
|
||||
s_hci_driver_uart_dma_env.hci_uart_params = &hci_driver_uart_dma_params;
|
||||
hci_driver_uart_config(&hci_driver_uart_dma_params);
|
||||
s_hci_driver_uart_dma_env.hci_uart_params = hci_driver_uart_config_param_get();
|
||||
hci_driver_uart_config(s_hci_driver_uart_dma_env.hci_uart_params);
|
||||
|
||||
ESP_LOGI(TAG, "uart attach uhci!");
|
||||
hci_driver_uart_dma_install();
|
||||
@ -654,12 +653,7 @@ error:
|
||||
int
|
||||
hci_driver_uart_dma_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
hci_driver_uart_params_config_t *uart_param = s_hci_driver_uart_dma_env.hci_uart_params;
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
return hci_driver_uart_config(uart_param);
|
||||
return hci_driver_uart_pin_update(tx_pin, rx_pin, cts_pin, rts_pin);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user