feat(events): 添加事件提交函数到各个头文件中

为多个事件头文件添加了静态内联提交函数,包括:
- bat_state_event: 添加submit_bat_state_event函数
- ble_serial_rx_event: 添加submit_ble_serial_rx_event函数
- ble_serial_tx_event: 添加submit_ble_serial_tx_event函数
- cdc_proto_tx_event: 添加submit_cdc_proto_tx_event函数
- datetime_event: 添加submit_datetime_event函数
- encoder_event: 添加submit_encoder_event函数
- function_bitmap_update_event: 添加submit_function_bitmap_update_event函数
- hid_led_event: 添加submit_hid_led_event函数
- hid_report_sent_event: 添加submit_hid_report_sent_event函数
- hid_transport_state_event: 添加submit_hid_transport_state_event函数
- hid_tx_report_event: 添加submit_hid_tx_report_event函数
- key_function_event: 添加submit_key_function_event函数
- keyboard_hid_report_event: 添加submit_keyboard_hid_report_event函数
- led_strip_en_event: 添加submit_led_strip_en_event函数
- mode_switch_event: 添加submit_mode_switch_event函数
- set_protocol_event: 添加submit_set_protocol_event函数
- theme_rgb_update_event: 添加submit_theme_rgb_update_event函数
- time_sync_event: 添加submit_time_sync_event函数
- usb_cdc_rx_event: 添加submit_usb_cdc_rx_event函数
- usb_cdc_tx_event: 添加submit_usb_cdc_tx_event函数
- usb_device_state_event: 添加submit_usb_device_state_event函数
- usb_function_ready_event: 添加submit_usb_function_ready_event函数
- usb_prepare_event: 添加submit_usb_prepare_event函数

这些函数提供了一致的事件提交接口,简化了事件创建和提交过程。
This commit is contained in:
2026-04-14 16:42:04 +08:00
parent c342a8d3f0
commit 78a6dc212d
37 changed files with 485 additions and 624 deletions

View File

@@ -98,54 +98,19 @@ static const uint8_t hid_report_desc[] = {
0xC0 /* End Collection */
};
static void submit_set_protocol_event(void)
static void submit_ble_transport_state_event(void)
{
struct set_protocol_event *event = new_set_protocol_event();
event->transport = HID_TRANSPORT_BLE;
event->protocol_mode = protocol_mode;
APP_EVENT_SUBMIT(event);
}
static void submit_hid_led_event(uint8_t led_bm)
{
struct hid_led_event *event = new_hid_led_event();
event->transport = HID_TRANSPORT_BLE;
event->led_bm = led_bm;
APP_EVENT_SUBMIT(event);
}
static void submit_transport_state_event(void)
{
struct hid_transport_state_event *event = new_hid_transport_state_event();
bool ready = running && secured && (active_conn != NULL);
event->transport = HID_TRANSPORT_BLE;
event->ready = ready;
event->protocol_mode = protocol_mode;
event->keys_ready = ready &&
((protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT) ?
boot_keyboard_notify_enabled :
keyboard_report_notify_enabled);
event->consumer_ready = ready &&
(protocol_mode == KEYBOARD_PROTOCOL_MODE_REPORT) &&
consumer_report_notify_enabled;
APP_EVENT_SUBMIT(event);
}
static void submit_hid_report_sent_event(enum keyboard_report_type report_type,
uint16_t sequence, bool error)
{
struct hid_report_sent_event *event = new_hid_report_sent_event();
event->transport = HID_TRANSPORT_BLE;
event->report_type = report_type;
event->sequence = sequence;
event->error = error;
APP_EVENT_SUBMIT(event);
submit_hid_transport_state_event(
HID_TRANSPORT_BLE,
ready,
ready && ((protocol_mode == KEYBOARD_PROTOCOL_MODE_BOOT) ?
boot_keyboard_notify_enabled :
keyboard_report_notify_enabled),
ready && (protocol_mode == KEYBOARD_PROTOCOL_MODE_REPORT) &&
consumer_report_notify_enabled,
protocol_mode);
}
static void input_report_notify_handler(uint8_t report_id, enum bt_hids_notify_evt evt)
@@ -158,13 +123,13 @@ static void input_report_notify_handler(uint8_t report_id, enum bt_hids_notify_e
consumer_report_notify_enabled = enabled;
}
submit_transport_state_event();
submit_ble_transport_state_event();
}
static void boot_keyboard_notify_handler(enum bt_hids_notify_evt evt)
{
boot_keyboard_notify_enabled = (evt == BT_HIDS_CCCD_EVT_NOTIFY_ENABLED);
submit_transport_state_event();
submit_ble_transport_state_event();
}
static void hid_report_complete_cb(struct bt_conn *conn, void *user_data)
@@ -176,7 +141,8 @@ static void hid_report_complete_cb(struct bt_conn *conn, void *user_data)
return;
}
submit_hid_report_sent_event(in_flight.report_type, in_flight.sequence, false);
submit_hid_report_sent_event(HID_TRANSPORT_BLE, in_flight.report_type,
in_flight.sequence, false);
in_flight.active = false;
}
@@ -186,7 +152,7 @@ static void keyboard_led_report_common(struct bt_hids_rep *rep, bool write)
return;
}
submit_hid_led_event(rep->data[0]);
submit_hid_led_event(HID_TRANSPORT_BLE, rep->data[0]);
}
static void keyboard_led_report_handler(struct bt_hids_rep *rep,
@@ -224,8 +190,8 @@ static void pm_evt_handler(enum bt_hids_pm_evt evt, struct bt_conn *conn)
return;
}
submit_set_protocol_event();
submit_transport_state_event();
submit_set_protocol_event(HID_TRANSPORT_BLE, protocol_mode);
submit_ble_transport_state_event();
}
static int module_init(void)
@@ -272,7 +238,7 @@ static int module_start(void)
}
running = true;
submit_transport_state_event();
submit_ble_transport_state_event();
return 0;
}
@@ -285,7 +251,7 @@ static void module_pause(void)
in_flight.active = false;
running = false;
submit_transport_state_event();
submit_ble_transport_state_event();
}
static void reset_connection_state(void)
@@ -311,12 +277,12 @@ static bool handle_ble_peer_event(const struct ble_peer_event *event)
active_conn = event->id;
protocol_mode = KEYBOARD_PROTOCOL_MODE_REPORT;
submit_set_protocol_event();
submit_set_protocol_event(HID_TRANSPORT_BLE, protocol_mode);
err = bt_hids_connected(&hids_obj, event->id);
if (err) {
LOG_ERR("bt_hids_connected failed (%d)", err);
}
submit_transport_state_event();
submit_ble_transport_state_event();
return false;
case PEER_STATE_SECURED:
@@ -325,7 +291,7 @@ static bool handle_ble_peer_event(const struct ble_peer_event *event)
}
secured = true;
submit_transport_state_event();
submit_ble_transport_state_event();
return false;
case PEER_STATE_DISCONNECTED:
@@ -339,7 +305,7 @@ static bool handle_ble_peer_event(const struct ble_peer_event *event)
}
reset_connection_state();
submit_transport_state_event();
submit_ble_transport_state_event();
return false;
default:
@@ -387,7 +353,8 @@ static bool handle_hid_tx_report_event(const struct hid_tx_report_event *event)
if (err) {
in_flight.active = false;
LOG_WRN("BLE keyboard report submit failed (%d)", err);
submit_hid_report_sent_event(KEYBOARD_REPORT_TYPE_KEYS,
submit_hid_report_sent_event(HID_TRANSPORT_BLE,
KEYBOARD_REPORT_TYPE_KEYS,
event->sequence, true);
}
@@ -413,7 +380,8 @@ static bool handle_hid_tx_report_event(const struct hid_tx_report_event *event)
if (err) {
in_flight.active = false;
LOG_WRN("BLE consumer report submit failed (%d)", err);
submit_hid_report_sent_event(KEYBOARD_REPORT_TYPE_CONSUMER,
submit_hid_report_sent_event(HID_TRANSPORT_BLE,
KEYBOARD_REPORT_TYPE_CONSUMER,
event->sequence, true);
}
}