前言
之前在nuttx下编写应用的时候,陷入了之前写单片机代码的误区,没有很好的讲逻辑层和驱动层的代码分割开来,
导致写出来的程序,可读性和可移植性太差,这次参考ardupilot的思路重新整理下实现的过程;
目标
实现一个电机接口库,具体目标如下:
1.这个库应该是建立在nuttx上;
2.利用os原有的PWM驱动以及IO驱动实现电机的控制接口;
3.抽象出电机模型(例如差速模型、姿态模型、自行车模型、单电机模型...);
4.文件目录层级:
|—../app/libraries
|—motor
|—差速模型(*.c、.h、.....)
|—自行车模型(*.c、.h、.....)
|—.......
|—单电机模型(*.c、.h、.....)
|—InertialSensor
....
|—编译文件(makefile、Kconfig、make.dep、make.defs)
文件的大概目录就是这样,下面结合实际的例子来详细说明。
libraries
libraries这个文件夹是新建的,就从这里开始吧~
然后编译器在编译的时候才找得到新建的源文件,从而编译;
首先在app下面按照上面的文件目录层级建立好所需要的源文件,接下怎么呢?
刚开始我蒙圈了,经验告诉我去看看readme,里面有如下描述:(我就只挑重点的来了)
Building NuttX with Board-Specific Pieces Outside the Source Tree
-----------------------------------------------------------------
3) If you like the random collection of stuff in the apps/ directory
but just want to expand the existing components with your own,
external sub-directory then there is an easy way to that too:
You just create a sympolic link in the apps/ directory that
redirects to your application sub-directory.
In order to be incorporated into the build, the directory that
you link under the apps/ directory should contain (1) a Makefile
that supports the clean and distclean targets (see other Makefiles
for examples), and (2) a tiny Make.defs file that simply adds the
custon build directories to the variable CONFIGURED_APPS like:
CONFIGURED_APPS += my_directory1 my_directory2
The apps/Makefile will always automatically check for the
existence of subdirectories containing a Makefile and a Make.defs
file. The Makefile will be used only to support cleaning ope