#2020征文-开发板#HiSpark智能AI开发板连载-终于把灯点亮了
手欠在搭环境的时候烧录了一次官方3516的uboot,本来挺好看的灯一下子全都不亮了,AI Camera 开发板资料中又没有提供对应的uboot,只好黑灯瞎火的折腾。幸好网络灯还能亮,至少能提示有电没电。不过这些灯早晚要点亮的,既然没提供那就自己弄。
我知道和Linux一样,应用层的程序是不能直接操作硬件的,需要通过驱动层来中转一下。但是鸿蒙目前没有insmod功能,而且2.0的代码有bug,不能在系统中通过网络把程序传过来,只能编写好代码重新编译再烧写进去的方式运行(应用程序可以通过TF卡拷贝,驱动程序就别想了)。整个过程太痛苦,所以写代码的时候尽量减少出错的可能,把所有问题想全面了再去编译和烧写。
这篇帖子虽然标题是点灯,但是实际上点灯的代码反而是最简单的,大部分的工作量都是在配置各种编译的文件上。基于此本文不给出具体的代码,只总结操作过程,把这些折腾明白了代码根本不算个事。
点灯的过程分为两部分,驱动程序和应用程序。为了能够清晰描述操作,每个部分都分为创建新文件和修改现有文件增加内容,简称“新建”和“修改”;路径中不存在的目录说明是要手动建立的,不再重复说明。
一、驱动程序(必须在vendor目录下):
新建:
1. ”/vendor/huawei/hdf/LED/LED.c “,驱动程序代码文件;
2. ”/vendor/huawei/hdf/LED/Kconfig“,内核配置文件;
3. ”/vendor/huawei/hdf/LED/Makefile“,编译配置文件;
4. ”/vendor/hisi/hi35xx/hi3516dv300/config/LED/LED_config.hcs“,HDF的配置文件;
Kconfig文件内容:
config LOSCFG_DRIVERS_HDF_PLATFORM_LED
bool "Enable HDF LED driver"
default n
depends on LOSCFG_DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF LED platform driver.
Makefile文件内容:
include $(LITEOSTOPDIR)/config.mk
include $(LITEOSTOPDIR)/../../drivers/hdf/lite/lite.mk
MODULE_NAME := LED
LOCAL_CFLAGS += $(HDF_INCLUDE)
LOCAL_SRCS += LED.c
LOCAL_INCLUDE := ./
LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror
include $(HDF_DRIVER)
LED_config.hcs文件内容:
root {
module = "LED";
author = "tjCFeng";
serviceName = "ServiceLED";
}
修改:
1. ”/vendor/huawei/hdf/Kconfig“
source "../../vendor/huawei/hdf/LED/Kconfig"
2.”/vendor/huawei/hdf/hdf_vendor.mk“
LITEOS_BASELIB += -lLED
LIB_SUBDIRS += $(VENDOR_HDF_DRIVERS_ROOT)/LED
3.”/vendor/hisi/hi35xx/hi3516dv300/config/hdf.hcs“
#include "LED/LED_config.hcs"
4.”/vendor/hisi/hi35xx/hi3516dv300/config/device_info/device_info.hcs“
DriverHDF :: device {
device0 :: deviceNode {
policy = 2;
preload = 0;
permission = 0644;
moduleName = "LED";
deviceMatchAttr = "LED";
serviceName = "ServiceLED";
}
}
二、应用程序(可以在任何目录下):
新建:
1.”/applications/CallLED/CallLED.c“,应用程序代码文件;
修改:
1.”/drivers/hdf/lite/manager/BUILD.gn“
executable("CallLED") {
sources = [
"//applications/CallLED/CallLED.c"
]
include_dirs = [
"../adapter/syscall/include",
"../adapter/vnode/include","$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//third_party/bounds_checking_function/include",
]
deps = [
"//drivers/hdf/lite/manager:hdf_core",
"//drivers/hdf/lite/adapter/osal/posix:hdf_posix_osal",
]
public_deps = [
"//third_party/bounds_checking_function:libsec_shared",
]
defines = [
"__USER__",
]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
]
}
lite_component("hdf_manager") {
features = [
":hdf_core",
":CallLED",
]
}
配置工作就是这些,可能在Windows下的DevEco工具会自动完成,我没有用过不了解,因为我全部的操作都是在Linux下手动完成。至于灯的控制,AI Camera开发板的两个灯分别是GPIO2_3和GPIO3_4,高电平亮低电平灭。参考上一篇帖子https://bbs.elecfans.com/jishu_1996035_1_1.html,重新编译、烧写,进入系统后运行
./bin/CallLED
灯亮了!!!