本文基于Bearpi-HM-Micro开发版进行开发,本系列主要讲NativeAPP开发(C++)基本开发概念和基础API。
参考地址:https://gitee.com/bearpi
下载bearpi-hm_micro_small后目录结构如下
主要目录介绍:
application: 应用文件夹,app包括hap应用;命令行应用;hdf应用;
build:项目编译目录,生成app,driver,rootfs,toolchain等基本镜像;
device:硬件驱动,默认的有gpio,i2c,uart,wlan等;
foundation:基础组件接口;
out:生成文件位置
第一个应用HelloWorld:
运行结果开发最简单的helloworld应用开发步骤:
1)在applications\BearPi\BearPi-HM_Micro\samples里建立my_first_app目录,建立BUILD.gn,hello_world.c两个文件
BUILD.gn:
import("//build/lite/config/component/lite_component.gni")
executable("hello_world_lib") {
output_name = "hello_world"
sources = [ "hello_world.c" ]
include_dirs = []
defines = []
cflags_c = []
ldflags = []
}
lite_component("my_app") {
features = [ ":hello_world_lib", ]
}hello_world.c:
#include <stdio.h>
int main(int argc, char **argv){
printf("\n************************************************\n");
printf("\n\t\tHello BearPi!\n");
printf("\n************************************************\n\n");
return 0;
}2)添加新组件
在build\lite\components\applications.json增加
{
"component": "my_sample",
"description": "my samples",
"optional": "true",
"dirs": [
"applications/BearPi/BearPi-HM_Micro/samples/my_first_app"
],
"targets": [
"//applications/BearPi/BearPi-HM_Micro/samples/my_first_app:my_app"
],
"rom": "",
"ram": "",
"output": [],
"adapted_kernel": [ "liteos_a" ],
"features": [],
"deps": {
"components": [],
"third_party": [ ]
}
}3)编译运行
网友评论