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:
@@ -172,81 +172,6 @@ static int encode_led_state(uint32_t led_mask, uint8_t *payload,
|
||||
return encode_body(&body, payload, payload_buf_size, payload_len);
|
||||
}
|
||||
|
||||
static int submit_cdc_proto_tx_event(uint8_t type, const uint8_t *payload,
|
||||
size_t payload_len)
|
||||
{
|
||||
struct cdc_proto_tx_event *event;
|
||||
|
||||
if ((payload == NULL) && (payload_len > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_cdc_proto_tx_event(payload_len);
|
||||
event->type = type;
|
||||
if (payload_len > 0U) {
|
||||
memcpy(event->dyndata.data, payload, payload_len);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int submit_function_bitmap_update_event(const Bitmap *bitmap)
|
||||
{
|
||||
struct function_bitmap_update_event *event;
|
||||
|
||||
if ((bitmap == NULL) ||
|
||||
(bitmap->usage_bitmap.size != KEYBOARD_PROTOCOL_BITMAP_BYTES)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_function_bitmap_update_event();
|
||||
memcpy(event->bitmap, bitmap->usage_bitmap.bytes,
|
||||
KEYBOARD_PROTOCOL_BITMAP_BYTES);
|
||||
APP_EVENT_SUBMIT(event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int submit_theme_rgb_update_event(const ThemeRgb *theme_rgb)
|
||||
{
|
||||
struct theme_rgb_update_event *event;
|
||||
|
||||
if ((theme_rgb == NULL) ||
|
||||
(theme_rgb->red > 255U) ||
|
||||
(theme_rgb->green > 255U) ||
|
||||
(theme_rgb->blue > 255U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_theme_rgb_update_event();
|
||||
event->theme.r = (uint8_t)theme_rgb->red;
|
||||
event->theme.g = (uint8_t)theme_rgb->green;
|
||||
event->theme.b = (uint8_t)theme_rgb->blue;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int submit_time_sync_event(const TimeSync *time_sync)
|
||||
{
|
||||
struct time_sync_event *event;
|
||||
|
||||
if (time_sync == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_time_sync_event();
|
||||
event->version = time_sync->version;
|
||||
event->flags = time_sync->flags;
|
||||
event->timezone_min = time_sync->timezone_min;
|
||||
event->utc_ms = time_sync->utc_ms;
|
||||
event->accuracy_ms = time_sync->accuracy_ms;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int encode_error_response(uint8_t req_type, ErrorCode error_code,
|
||||
uint8_t *rsp_type, uint8_t *rsp_payload,
|
||||
size_t rsp_payload_buf_size,
|
||||
@@ -387,7 +312,8 @@ int protocol_module_process_cdc_packet(uint8_t req_type,
|
||||
rsp_payload_len);
|
||||
}
|
||||
|
||||
err = submit_function_bitmap_update_event(&body.body.bitmap);
|
||||
err = submit_function_bitmap_update_event(
|
||||
body.body.bitmap.usage_bitmap.bytes);
|
||||
if (err) {
|
||||
return encode_error_response(req_type, ErrorCode_ERROR_CODE_INVALID_PARAM,
|
||||
rsp_type, rsp_payload,
|
||||
@@ -413,14 +339,11 @@ int protocol_module_process_cdc_packet(uint8_t req_type,
|
||||
rsp_payload_len);
|
||||
}
|
||||
|
||||
err = submit_time_sync_event(&body.body.time_sync);
|
||||
if (err) {
|
||||
return encode_error_response(req_type, ErrorCode_ERROR_CODE_INVALID_PARAM,
|
||||
rsp_type, rsp_payload,
|
||||
rsp_payload_buf_size,
|
||||
rsp_payload_len);
|
||||
}
|
||||
|
||||
submit_time_sync_event(body.body.time_sync.version,
|
||||
body.body.time_sync.flags,
|
||||
body.body.time_sync.timezone_min,
|
||||
body.body.time_sync.utc_ms,
|
||||
body.body.time_sync.accuracy_ms);
|
||||
return encode_ack_response(req_type, rsp_type, rsp_payload,
|
||||
rsp_payload_buf_size, rsp_payload_len);
|
||||
|
||||
@@ -432,14 +355,20 @@ int protocol_module_process_cdc_packet(uint8_t req_type,
|
||||
rsp_payload_len);
|
||||
}
|
||||
|
||||
err = submit_theme_rgb_update_event(&body.body.theme_rgb);
|
||||
if (err) {
|
||||
if ((body.body.theme_rgb.red > 255U) ||
|
||||
(body.body.theme_rgb.green > 255U) ||
|
||||
(body.body.theme_rgb.blue > 255U)) {
|
||||
return encode_error_response(req_type, ErrorCode_ERROR_CODE_INVALID_PARAM,
|
||||
rsp_type, rsp_payload,
|
||||
rsp_payload_buf_size,
|
||||
rsp_payload_len);
|
||||
}
|
||||
|
||||
submit_theme_rgb_update_event((struct theme_rgb) {
|
||||
.r = (uint8_t)body.body.theme_rgb.red,
|
||||
.g = (uint8_t)body.body.theme_rgb.green,
|
||||
.b = (uint8_t)body.body.theme_rgb.blue,
|
||||
});
|
||||
return encode_ack_response(req_type, rsp_type, rsp_payload,
|
||||
rsp_payload_buf_size, rsp_payload_len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user