feat(ble): 添加快速广告配置并优化连接状态检查
添加了BLE快速广告相关的配置选项到prj.conf中,包括快速广告间隔、超时等参数。 同时修复了ble_bond_module中的连接状态检查逻辑,避免在挂起后保留LE连接时进行不必要的 断开操作。 在ble_hid_module和usb_hid_module中改进了HID传输事件处理逻辑,确保在相应模式未激活 或连接未建立时正确提交传输完成事件,提高了设备响应的准确性。 BREAKING CHANGE: 广告行为在连接保持情况下有所改变,可能影响配对流程。
This commit is contained in:
@@ -215,6 +215,23 @@ static void disconnect_le_conn_cb(struct bt_conn *conn, void *user_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void mark_le_conn_found_cb(struct bt_conn *conn, void *user_data)
|
||||
{
|
||||
bool *found = user_data;
|
||||
|
||||
ARG_UNUSED(conn);
|
||||
*found = true;
|
||||
}
|
||||
|
||||
static bool has_any_le_conn(void)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
bt_conn_foreach(BT_CONN_TYPE_LE, mark_le_conn_found_cb, &found);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
struct peer_bond_lookup {
|
||||
const bt_addr_le_t *peer_addr;
|
||||
bool found;
|
||||
@@ -532,7 +549,16 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
if (bond.state == BLE_BOND_STATE_STANDBY) {
|
||||
bond.state = BLE_BOND_STATE_IDLE;
|
||||
module_set_state(MODULE_STATE_READY);
|
||||
submit_peer_op_event(PEER_OPERATION_SELECTED, bond.storage.cur_peer_id);
|
||||
/*
|
||||
* If a LE link survived suspend, keep it untouched. CAF ble_adv
|
||||
* treats PEER_OPERATION_SELECTED as a real identity switch and
|
||||
* will disconnect the current peer. If no link exists, re-emit
|
||||
* the selection so advertising resumes on the selected slot.
|
||||
*/
|
||||
if (!has_any_le_conn()) {
|
||||
submit_peer_op_event(PEER_OPERATION_SELECTED,
|
||||
bond.storage.cur_peer_id);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,11 +52,6 @@ static bool ble_hid_is_connected(void)
|
||||
return ble_hid.link.conn != NULL;
|
||||
}
|
||||
|
||||
static bool ble_hid_is_active(void)
|
||||
{
|
||||
return ble_hid.policy.ble_mode_selected && ble_hid_is_connected();
|
||||
}
|
||||
|
||||
static bool ble_hid_is_boot_mode(void)
|
||||
{
|
||||
return ble_hid.link.protocol_mode == BT_HIDS_PM_BOOT;
|
||||
@@ -232,7 +227,12 @@ static void handle_ble_peer_event(const struct ble_peer_event *event)
|
||||
|
||||
static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
{
|
||||
if (!ble_hid_is_active()) {
|
||||
if (!ble_hid.policy.ble_mode_selected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ble_hid_is_connected()) {
|
||||
hid_tx_done_event_submit(event->kind, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
int err;
|
||||
|
||||
if (!ble_hid_is_boot_mode()) {
|
||||
hid_tx_done_event_submit(HID_TX_KIND_BOOT, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -263,6 +264,7 @@ static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
}
|
||||
|
||||
if (!ble_hid_is_report_mode()) {
|
||||
hid_tx_done_event_submit(HID_TX_KIND_REPORT, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -711,11 +711,17 @@ static bool handle_wake_up_event(void)
|
||||
|
||||
static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
{
|
||||
if (!g_usb_hid.policy.usb_mode_selected || !usb_hid_stack_is_active())
|
||||
if (!g_usb_hid.policy.usb_mode_selected)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!usb_hid_stack_is_active())
|
||||
{
|
||||
submit_usb_tx_done(event->kind, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event->kind == HID_TX_KIND_BOOT)
|
||||
{
|
||||
const uint8_t *payload = hid_tx_event_get_data(event);
|
||||
@@ -724,6 +730,7 @@ static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
|
||||
if (g_usb_hid.current_protocol != HID_PROTO_BOOT)
|
||||
{
|
||||
submit_usb_tx_done(HID_TX_KIND_BOOT, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -762,6 +769,7 @@ static bool handle_hid_tx_event(const struct hid_tx_event *event)
|
||||
*/
|
||||
if (g_usb_hid.current_protocol != HID_PROTO_REPORT)
|
||||
{
|
||||
submit_usb_tx_done(HID_TX_KIND_REPORT, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user