feat(usb_device_module): 添加电源管理限制功能
- 引入power_manager_event.h头文件 - 实现update_power_manager_restriction函数来控制电源管理级别 - 在VBUS就绪时设置为ALIVE级别,在VUSB移除时设置为SUSPENDED级别 - 模块初始化时默认设置为SUSPENDED级别
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/usb/usbd.h>
|
||||
|
||||
#include <caf/events/power_manager_event.h>
|
||||
|
||||
#include "usb_device_module.h"
|
||||
#include "usb_device_state_event.h"
|
||||
#include "usb_function_ready_event.h"
|
||||
@@ -71,6 +73,13 @@ static void update_usb_device_state(enum usb_device_state state)
|
||||
submit_usb_device_state_event(state);
|
||||
}
|
||||
|
||||
static void update_power_manager_restriction(bool vbus_present)
|
||||
{
|
||||
power_manager_restrict(MODULE_IDX(MODULE),
|
||||
vbus_present ? POWER_MANAGER_LEVEL_ALIVE :
|
||||
POWER_MANAGER_LEVEL_SUSPENDED);
|
||||
}
|
||||
|
||||
static int usb_descriptors_init(void)
|
||||
{
|
||||
int err;
|
||||
@@ -112,6 +121,7 @@ static void usbd_msg_cb(struct usbd_context *const usbd_ctx,
|
||||
|
||||
switch (msg->type) {
|
||||
case USBD_MSG_VBUS_READY:
|
||||
update_power_manager_restriction(true);
|
||||
if (!usb_enabled) {
|
||||
int err = usbd_enable(&blinky_usbd);
|
||||
|
||||
@@ -125,6 +135,7 @@ static void usbd_msg_cb(struct usbd_context *const usbd_ctx,
|
||||
break;
|
||||
|
||||
case USBD_MSG_VBUS_REMOVED:
|
||||
update_power_manager_restriction(false);
|
||||
if (usb_enabled) {
|
||||
int err = usbd_disable(&blinky_usbd);
|
||||
|
||||
@@ -207,6 +218,7 @@ static int module_init(void)
|
||||
ready_function_mask = 0U;
|
||||
prepare_broadcasted = false;
|
||||
usbd_initialized = false;
|
||||
update_power_manager_restriction(false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user