【IoT美学】拯救小白专题——基于IoT Link Studio的外设移植(火焰传感器)
一、硬件资源
BearPI+KY_026(火焰传感器)+杜邦线*n
二、实战核心代码
下载KY_026驱动代码(此处建议多用百度)
将KY_026驱动代码移植进项目工程
添加文件路径,需修改user_demo.mk
#example for hello_world_demo
ifeq ($(CONFIG_USER_DEMO), "hello_world_demo")
user_demo_src = ${wildcard $(TARGET_DIR)/Demos/hello_world_demo/*.c}
user_demo_inc = -I $(TARGET_DIR)/Demos/hello_world_demo
user_KY_026_src = ${wildcard $(TARGET_DIR)/Hardware/KY_026/*.c}
user_KY_026_inc = -I ${wildcard $(TARGET_DIR)/Hardware/KY_026}
user_demo_defs = -D CONFIG_HELLO_WORLD_ENABLE=1
endif
C_SOURCES += $(user_demo_src)
C_INCLUDES += $(user_demo_inc)
C_SOURCES += $(user_KY_026_src)
C_INCLUDES += $(user_KY_026_inc)
C_DEFS += $(user_demo_defs)
修改hello_world_demo.c
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <osal.h>
#include "ky_026.h"
#include <gpio.h>
#include <stm32l4xx_it.h>
KY026_Data_TypeDef KY026_Data;
static int app_hello_world_entry()
{
while (1)
{
printf("Hello World! This is LiteOS!\r\n");
osal_task_sleep(4*1000);
}
}
static int app_fire_collect_entry()
{
/* ky_026硬件初始化 */
KY026_Init();
while(1)
{
KY026_Read_State();
if(KY026_Read_State() == 1)
{
printf("fire!\r\n");
}
else
{
printf("no,fire!\r\n");
}
osal_task_sleep(2*1000);
}
return 0;
}
int standard_app_demo_main()
{
osal_task_create("helloworld",app_hello_world_entry,NULL,0x400,NULL,2);
osal_task_create("Fire",app_fire_collect_entry,NULL,0x400,NULL,3);
return 0;
}
调测展示
实物图
- 点赞
- 收藏
- 关注作者
评论(0)