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:
@@ -20,6 +20,16 @@ struct bat_state_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(bat_state_event);
|
||||
|
||||
static inline void submit_bat_state_event(uint8_t soc, bool charging, bool full)
|
||||
{
|
||||
struct bat_state_event *event = new_bat_state_event();
|
||||
|
||||
event->soc = soc;
|
||||
event->charging = charging;
|
||||
event->full = full;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_BLE_SERIAL_RX_EVENT_H_
|
||||
#define BLINKY_BLE_SERIAL_RX_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -15,6 +19,23 @@ struct ble_serial_rx_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(ble_serial_rx_event);
|
||||
|
||||
static inline int submit_ble_serial_rx_event(const uint8_t *data, size_t len)
|
||||
{
|
||||
struct ble_serial_rx_event *event;
|
||||
|
||||
if ((data == NULL) && (len > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_ble_serial_rx_event(len);
|
||||
if (len > 0U) {
|
||||
memcpy(event->dyndata.data, data, len);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_BLE_SERIAL_TX_EVENT_H_
|
||||
#define BLINKY_BLE_SERIAL_TX_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -15,6 +19,23 @@ struct ble_serial_tx_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(ble_serial_tx_event);
|
||||
|
||||
static inline int submit_ble_serial_tx_event(const uint8_t *data, size_t len)
|
||||
{
|
||||
struct ble_serial_tx_event *event;
|
||||
|
||||
if ((data == NULL) && (len > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_ble_serial_tx_event(len);
|
||||
if (len > 0U) {
|
||||
memcpy(event->dyndata.data, data, len);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_CDC_PROTO_TX_EVENT_H_
|
||||
#define BLINKY_CDC_PROTO_TX_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -16,6 +20,25 @@ struct cdc_proto_tx_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(cdc_proto_tx_event);
|
||||
|
||||
static inline 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;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef BLINKY_DATETIME_EVENT_H_
|
||||
#define BLINKY_DATETIME_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -19,6 +22,22 @@ struct datetime_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(datetime_event);
|
||||
|
||||
static inline int submit_datetime_event(const char *date_text, const char *time_text)
|
||||
{
|
||||
struct datetime_event *event = new_datetime_event();
|
||||
|
||||
if ((date_text == NULL) || (time_text == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
strncpy(event->date_text, date_text, sizeof(event->date_text));
|
||||
event->date_text[sizeof(event->date_text) - 1] = '\0';
|
||||
strncpy(event->time_text, time_text, sizeof(event->time_text));
|
||||
event->time_text[sizeof(event->time_text) - 1] = '\0';
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,14 @@ struct encoder_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(encoder_event);
|
||||
|
||||
static inline void submit_encoder_event(int8_t detents)
|
||||
{
|
||||
struct encoder_event *event = new_encoder_event();
|
||||
|
||||
event->detents = detents;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef BLINKY_FUNCTION_BITMAP_UPDATE_EVENT_H_
|
||||
#define BLINKY_FUNCTION_BITMAP_UPDATE_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -17,6 +20,20 @@ struct function_bitmap_update_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(function_bitmap_update_event);
|
||||
|
||||
static inline int submit_function_bitmap_update_event(const uint8_t *bitmap)
|
||||
{
|
||||
struct function_bitmap_update_event *event;
|
||||
|
||||
if (bitmap == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_function_bitmap_update_event();
|
||||
memcpy(event->bitmap, bitmap, sizeof(event->bitmap));
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,15 @@ struct hid_led_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(hid_led_event);
|
||||
|
||||
static inline void submit_hid_led_event(enum hid_transport transport, uint8_t led_bm)
|
||||
{
|
||||
struct hid_led_event *event = new_hid_led_event();
|
||||
|
||||
event->transport = transport;
|
||||
event->led_bm = led_bm;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,19 @@ struct hid_report_sent_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(hid_report_sent_event);
|
||||
|
||||
static inline void submit_hid_report_sent_event(enum hid_transport transport,
|
||||
enum keyboard_report_type report_type,
|
||||
uint16_t sequence, bool error)
|
||||
{
|
||||
struct hid_report_sent_event *event = new_hid_report_sent_event();
|
||||
|
||||
event->transport = transport;
|
||||
event->report_type = report_type;
|
||||
event->sequence = sequence;
|
||||
event->error = error;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,20 @@ struct hid_transport_state_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(hid_transport_state_event);
|
||||
|
||||
static inline void submit_hid_transport_state_event(
|
||||
enum hid_transport transport, bool ready, bool keys_ready,
|
||||
bool consumer_ready, enum keyboard_protocol_mode protocol_mode)
|
||||
{
|
||||
struct hid_transport_state_event *event = new_hid_transport_state_event();
|
||||
|
||||
event->transport = transport;
|
||||
event->ready = ready;
|
||||
event->keys_ready = keys_ready;
|
||||
event->consumer_ready = consumer_ready;
|
||||
event->protocol_mode = protocol_mode;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_HID_TX_REPORT_EVENT_H_
|
||||
#define BLINKY_HID_TX_REPORT_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -21,6 +25,31 @@ struct hid_tx_report_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(hid_tx_report_event);
|
||||
|
||||
static inline int submit_hid_tx_report_event(enum hid_transport transport,
|
||||
enum keyboard_report_type report_type,
|
||||
enum keyboard_protocol_mode protocol_mode,
|
||||
uint16_t sequence,
|
||||
const uint8_t *data, size_t size)
|
||||
{
|
||||
struct hid_tx_report_event *event;
|
||||
|
||||
if ((data == NULL) && (size > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_hid_tx_report_event(size);
|
||||
event->transport = transport;
|
||||
event->report_type = report_type;
|
||||
event->protocol_mode = protocol_mode;
|
||||
event->sequence = sequence;
|
||||
if (size > 0U) {
|
||||
memcpy(event->dyndata.data, data, size);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,15 @@ struct key_function_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(key_function_event);
|
||||
|
||||
static inline void submit_key_function_event(uint16_t usage, uint8_t action)
|
||||
{
|
||||
struct key_function_event *event = new_key_function_event();
|
||||
|
||||
event->usage = usage;
|
||||
event->action = action;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_KEYBOARD_HID_REPORT_EVENT_H_
|
||||
#define BLINKY_KEYBOARD_HID_REPORT_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -22,6 +26,30 @@ struct keyboard_hid_report_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(keyboard_hid_report_event);
|
||||
|
||||
static inline int submit_keyboard_hid_report_event(
|
||||
enum mode_switch_mode mode, enum keyboard_report_type report_type,
|
||||
enum keyboard_protocol_mode protocol_mode,
|
||||
enum hid_queue_policy queue_policy, const uint8_t *data, size_t size)
|
||||
{
|
||||
struct keyboard_hid_report_event *event;
|
||||
|
||||
if ((data == NULL) && (size > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_keyboard_hid_report_event(size);
|
||||
event->mode = mode;
|
||||
event->report_type = report_type;
|
||||
event->protocol_mode = protocol_mode;
|
||||
event->queue_policy = queue_policy;
|
||||
if (size > 0U) {
|
||||
memcpy(event->dyndata.data, data, size);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,14 @@ struct led_strip_en_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(led_strip_en_event);
|
||||
|
||||
static inline void submit_led_strip_en_event(bool enabled)
|
||||
{
|
||||
struct led_strip_en_event *event = new_led_strip_en_event();
|
||||
|
||||
event->enabled = enabled;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,16 @@ struct mode_switch_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(mode_switch_event);
|
||||
|
||||
static inline void submit_mode_switch_event(enum mode_switch_mode mode,
|
||||
uint16_t voltage_mv)
|
||||
{
|
||||
struct mode_switch_event *event = new_mode_switch_event();
|
||||
|
||||
event->mode = mode;
|
||||
event->voltage_mv = voltage_mv;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,16 @@ struct set_protocol_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(set_protocol_event);
|
||||
|
||||
static inline void submit_set_protocol_event(enum hid_transport transport,
|
||||
enum keyboard_protocol_mode protocol_mode)
|
||||
{
|
||||
struct set_protocol_event *event = new_set_protocol_event();
|
||||
|
||||
event->transport = transport;
|
||||
event->protocol_mode = protocol_mode;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,14 @@ struct theme_rgb_update_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(theme_rgb_update_event);
|
||||
|
||||
static inline void submit_theme_rgb_update_event(struct theme_rgb theme)
|
||||
{
|
||||
struct theme_rgb_update_event *event = new_theme_rgb_update_event();
|
||||
|
||||
event->theme = theme;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,20 @@ struct time_sync_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(time_sync_event);
|
||||
|
||||
static inline void submit_time_sync_event(uint32_t version, uint32_t flags,
|
||||
int32_t timezone_min, uint64_t utc_ms,
|
||||
uint32_t accuracy_ms)
|
||||
{
|
||||
struct time_sync_event *event = new_time_sync_event();
|
||||
|
||||
event->version = version;
|
||||
event->flags = flags;
|
||||
event->timezone_min = timezone_min;
|
||||
event->utc_ms = utc_ms;
|
||||
event->accuracy_ms = accuracy_ms;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_USB_CDC_RX_EVENT_H_
|
||||
#define BLINKY_USB_CDC_RX_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -15,6 +19,23 @@ struct usb_cdc_rx_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(usb_cdc_rx_event);
|
||||
|
||||
static inline int submit_usb_cdc_rx_event(const uint8_t *data, size_t len)
|
||||
{
|
||||
struct usb_cdc_rx_event *event;
|
||||
|
||||
if ((data == NULL) && (len > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_usb_cdc_rx_event(len);
|
||||
if (len > 0U) {
|
||||
memcpy(event->dyndata.data, data, len);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BLINKY_USB_CDC_TX_EVENT_H_
|
||||
#define BLINKY_USB_CDC_TX_EVENT_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
@@ -15,6 +19,23 @@ struct usb_cdc_tx_event {
|
||||
|
||||
APP_EVENT_TYPE_DYNDATA_DECLARE(usb_cdc_tx_event);
|
||||
|
||||
static inline int submit_usb_cdc_tx_event(const uint8_t *data, size_t len)
|
||||
{
|
||||
struct usb_cdc_tx_event *event;
|
||||
|
||||
if ((data == NULL) && (len > 0U)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
event = new_usb_cdc_tx_event(len);
|
||||
if (len > 0U) {
|
||||
memcpy(event->dyndata.data, data, len);
|
||||
}
|
||||
|
||||
APP_EVENT_SUBMIT(event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,14 @@ struct usb_device_state_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(usb_device_state_event);
|
||||
|
||||
static inline void submit_usb_device_state_event(enum usb_device_state state)
|
||||
{
|
||||
struct usb_device_state_event *event = new_usb_device_state_event();
|
||||
|
||||
event->state = state;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,14 @@ struct usb_function_ready_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(usb_function_ready_event);
|
||||
|
||||
static inline void submit_usb_function_ready_event(uint8_t function_mask)
|
||||
{
|
||||
struct usb_function_ready_event *event = new_usb_function_ready_event();
|
||||
|
||||
event->function_mask = function_mask;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,11 @@ struct usb_prepare_event {
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(usb_prepare_event);
|
||||
|
||||
static inline void submit_usb_prepare_event(void)
|
||||
{
|
||||
APP_EVENT_SUBMIT(new_usb_prepare_event());
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user