static_library("led") {
sources = [ "led.c" ]
include_dirs = [
"//utils/native/lite/include",
"//kernel/liteos_m/kal",
"//base/iot_hardware/inteRFaces/kits/wifiiot_lite",
}
#include
#include
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
// LED灯任务处理,在此函数内循环点亮和熄灭LED灯
static void *LedTask(const char *arg)
{
(void)arg;
while (1) {
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0); // LED_ON
usleep(300*1000);
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1); // LED_OFF
usleep(300*1000);
}
return NULL;
}
static void Demo_Led(void)
{
osThreadAttr_t attr;
// 初始化LED,连接的是GPIO9
GpioInit();
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_GPIO);
GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_DIR_OUT);
attr.name = "LedTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 512U;
attr.priority = osPriorityNormal; // 任务优先级为常规级别
// 新建LED任务
if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
printf("[Demo Led] create LedTask Failed!rn");
}
}
SYS_RUN(Demo_Led);`
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [
"led:led",
}
全部0条评论
快来发表一下你的评论吧 !