From d56989d2198403988836e16bca3e3dcddfe74364 Mon Sep 17 00:00:00 2001 From: skiinder Date: Tue, 7 Apr 2026 10:26:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=81=E7=A7=BB=E4=B8=BB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=A8=8B=E5=BA=8F=E4=BB=A5=E4=BD=BF=E7=94=A8CAF?= =?UTF-8?q?=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在prj.conf中启用CAF、堆内存池、日志和断言配置 - 将main.c重构为使用应用事件管理器和模块状态事件 - 移除GPIO LED闪烁功能,改为初始化事件管理系统 - 添加日志模块注册和错误处理 --- prj.conf | 5 ++++- src/main.c | 52 +++++++++++----------------------------------------- 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/prj.conf b/prj.conf index 91c3c15..e7af48a 100644 --- a/prj.conf +++ b/prj.conf @@ -1 +1,4 @@ -CONFIG_GPIO=y +CONFIG_CAF=y +CONFIG_HEAP_MEM_POOL_SIZE=2048 +CONFIG_LOG=y +CONFIG_ASSERT=y diff --git a/src/main.c b/src/main.c index 4cab496..7d5c6bb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,48 +1,18 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ +#include -#include -#include -#include +#define MODULE main +#include -/* 1000 msec = 1 sec */ -#define SLEEP_TIME_MS 1000 - -/* The devicetree node identifier for the "led0" alias. */ -#define LED0_NODE DT_ALIAS(led0) - -/* - * A build error on this line means your board is unsupported. - * See the sample documentation for information on how to fix this. - */ -static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); +#include +LOG_MODULE_REGISTER(MODULE); int main(void) { - int ret; - bool led_state = true; + if (app_event_manager_init()) { + LOG_ERR("Application Event Manager not initialized"); + } else { + module_set_state(MODULE_STATE_READY); + } - if (!gpio_is_ready_dt(&led)) { - return 0; - } - - ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); - if (ret < 0) { - return 0; - } - - while (1) { - ret = gpio_pin_toggle_dt(&led); - if (ret < 0) { - return 0; - } - - led_state = !led_state; - printf("LED state: %s\n", led_state ? "ON" : "OFF"); - k_msleep(SLEEP_TIME_MS); - } - return 0; + return 0; }