83 lines
1.9 KiB
C
83 lines
1.9 KiB
C
|
|
#ifndef BLINKY_USB_STATE_EVENT_H_
|
||
|
|
#define BLINKY_USB_STATE_EVENT_H_
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#include <app_event_manager.h>
|
||
|
|
#include <app_event_manager_profiler_tracer.h>
|
||
|
|
#include <zephyr/sys/util.h>
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
enum usb_state_event_op {
|
||
|
|
USB_STATE_EVENT_OP_SET_BITS,
|
||
|
|
USB_STATE_EVENT_OP_CLEAR_BITS,
|
||
|
|
USB_STATE_EVENT_OP_SNAPSHOT,
|
||
|
|
};
|
||
|
|
|
||
|
|
enum usb_state_flag {
|
||
|
|
USB_STATEF_PREPARE = BIT(0),
|
||
|
|
USB_STATEF_HID_READY = BIT(1),
|
||
|
|
USB_STATEF_CDC_READY = BIT(2),
|
||
|
|
USB_STATEF_STACK_READY = BIT(3),
|
||
|
|
USB_STATEF_POWERED = BIT(4),
|
||
|
|
USB_STATEF_ACTIVE = BIT(5),
|
||
|
|
USB_STATEF_SUSPENDED = BIT(6),
|
||
|
|
USB_STATEF_STACK_RUNNING = BIT(31),
|
||
|
|
};
|
||
|
|
|
||
|
|
struct usb_state_event {
|
||
|
|
struct app_event_header header;
|
||
|
|
const void *src_module_id;
|
||
|
|
const void *sink_module_id;
|
||
|
|
uint8_t op;
|
||
|
|
uint32_t flags;
|
||
|
|
};
|
||
|
|
|
||
|
|
APP_EVENT_TYPE_DECLARE(usb_state_event);
|
||
|
|
|
||
|
|
static inline void submit_usb_state_event(const void *src_module_id,
|
||
|
|
const void *sink_module_id,
|
||
|
|
uint8_t op,
|
||
|
|
uint32_t flags)
|
||
|
|
{
|
||
|
|
struct usb_state_event *event = new_usb_state_event();
|
||
|
|
|
||
|
|
event->src_module_id = src_module_id;
|
||
|
|
event->sink_module_id = sink_module_id;
|
||
|
|
event->op = op;
|
||
|
|
event->flags = flags;
|
||
|
|
APP_EVENT_SUBMIT(event);
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void submit_usb_state_set(const void *src_module_id,
|
||
|
|
const void *sink_module_id,
|
||
|
|
uint32_t flags)
|
||
|
|
{
|
||
|
|
submit_usb_state_event(src_module_id, sink_module_id,
|
||
|
|
USB_STATE_EVENT_OP_SET_BITS, flags);
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void submit_usb_state_clear(const void *src_module_id,
|
||
|
|
const void *sink_module_id,
|
||
|
|
uint32_t flags)
|
||
|
|
{
|
||
|
|
submit_usb_state_event(src_module_id, sink_module_id,
|
||
|
|
USB_STATE_EVENT_OP_CLEAR_BITS, flags);
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void submit_usb_state_snapshot(const void *src_module_id,
|
||
|
|
uint32_t flags)
|
||
|
|
{
|
||
|
|
submit_usb_state_event(src_module_id, NULL,
|
||
|
|
USB_STATE_EVENT_OP_SNAPSHOT, flags);
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif /* BLINKY_USB_STATE_EVENT_H_ */
|