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

@@ -81,30 +81,6 @@ static uint8_t battery_soc_from_mv(int voltage_mv)
return (uint8_t)(bucket * 10);
}
static void submit_bat_state_event(uint8_t soc, bool charging, bool full)
{
struct bat_state_event *event;
if (last_bat_state.valid &&
(last_bat_state.soc == soc) &&
(last_bat_state.charging == charging) &&
(last_bat_state.full == full)) {
return;
}
last_bat_state.valid = true;
last_bat_state.soc = soc;
last_bat_state.charging = charging;
last_bat_state.full = full;
event = new_bat_state_event();
event->soc = soc;
event->charging = charging;
event->full = full;
APP_EVENT_SUBMIT(event);
}
static void battery_sample_fn(struct k_work *work)
{
struct ip5306_status pmic_status;
@@ -137,9 +113,18 @@ static void battery_sample_fn(struct k_work *work)
}
voltage_mv = sensor_value_to_mv(&voltage);
submit_bat_state_event(battery_soc_from_mv(voltage_mv),
pmic_status.charging,
pmic_status.full);
uint8_t soc = battery_soc_from_mv(voltage_mv);
if (!last_bat_state.valid ||
(last_bat_state.soc != soc) ||
(last_bat_state.charging != pmic_status.charging) ||
(last_bat_state.full != pmic_status.full)) {
last_bat_state.valid = true;
last_bat_state.soc = soc;
last_bat_state.charging = pmic_status.charging;
last_bat_state.full = pmic_status.full;
submit_bat_state_event(soc, pmic_status.charging, pmic_status.full);
}
reschedule:
if (running) {