feat(led): 使用CAF LEDs模块替代自定义LED驱动
- 移除src/modules/led_module.c中的自定义GPIO LED实现 - 在CMakeLists.txt中移除对led_module.c的引用 - 更新prj.conf配置,启用CAF LEDs相关功能 - 添加CONFIG_CAF_POWER_MANAGER配置项以支持电源管理 - 在main.c中集成LED事件,在系统就绪时触发启动LED效果 - 实现白色常亮LED效果作为系统启动指示
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
#include <app_event_manager.h>
|
||||
#define MODULE led
|
||||
#include <caf/events/module_state_event.h>
|
||||
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(MODULE);
|
||||
|
||||
static const struct gpio_dt_spec status_led = GPIO_DT_SPEC_GET(DT_PATH(led_0, chan0), gpios);
|
||||
|
||||
static void led_module_start(void)
|
||||
{
|
||||
if (!gpio_is_ready_dt(&status_led)) {
|
||||
LOG_ERR("LED GPIO controller is not ready");
|
||||
return;
|
||||
}
|
||||
|
||||
int err = gpio_pin_configure_dt(&status_led, GPIO_OUTPUT_ACTIVE);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to turn on LED (err: %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INF("LED is on");
|
||||
}
|
||||
|
||||
static bool app_event_handler(const struct app_event_header *aeh)
|
||||
{
|
||||
/* 仅处理 module_state_event,其他事件交给系统继续分发。 */
|
||||
if (is_module_state_event(aeh)) {
|
||||
const struct module_state_event *event = cast_module_state_event(aeh);
|
||||
|
||||
if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
|
||||
led_module_start();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
APP_EVENT_LISTENER(led_module, app_event_handler);
|
||||
APP_EVENT_SUBSCRIBE(led_module, module_state_event);
|
||||
|
||||
Reference in New Issue
Block a user