diff --git a/prj.conf b/prj.conf index 54cd056..f0ce0ec 100644 --- a/prj.conf +++ b/prj.conf @@ -34,6 +34,10 @@ CONFIG_BT_SETTINGS=y CONFIG_CAF_BLE_STATE=y CONFIG_CAF_BLE_ADV=y +CONFIG_CAF_BLE_ADV_FAST_ADV=y +CONFIG_CAF_BLE_ADV_FAST_INT_MIN=0x0030 +CONFIG_CAF_BLE_ADV_FAST_INT_MAX=0x0060 +CONFIG_CAF_BLE_ADV_FAST_ADV_TIMEOUT=180 CONFIG_CAF_MODULE_SUSPEND_EVENTS=y CONFIG_CAF_SETTINGS_LOADER=y CONFIG_BT_ADV_PROV_FLAGS=y diff --git a/src/modules/ble_bond_module.c b/src/modules/ble_bond_module.c index 9ccf683..6b54959 100644 --- a/src/modules/ble_bond_module.c +++ b/src/modules/ble_bond_module.c @@ -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; } diff --git a/src/modules/ble_hid_module.c b/src/modules/ble_hid_module.c index 2deb6ec..ac6b284 100644 --- a/src/modules/ble_hid_module.c +++ b/src/modules/ble_hid_module.c @@ -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; } diff --git a/src/modules/usb_hid_module.c b/src/modules/usb_hid_module.c index e3c79a8..d5386d3 100644 --- a/src/modules/usb_hid_module.c +++ b/src/modules/usb_hid_module.c @@ -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; }