星期四, 27. 九月 2018 12:00 上午 - BEAUTIFULZZZZ
一, 前言
前几天给大家介绍了如何手动搭建安卓 App 命令行开发环境和 nRF51822 命令行开发环境, 中秋这几天我把上面篇文章的操作流程全部做成了 shell 脚本, 使得可以让其他人简单运行下脚本, 就能够直接建立绿色开发环境, 岂不美哉?
《[编译] 5, 在 Linux 下搭建安卓 App 的开发烧写环境 (makefile 版)-- 在 Linux 上用命令行 + VIM 开发安卓 App》
《[编译] 4, 在 Linux 下搭建 nRF51822 的开发烧写环境 (makefile 版)》
二, nrf_linux_tool 开源项目介绍
2.1) 项目简介
- The project provides a nRF51 App command-line development environment based on Linux system.
- You can directly write,build,install App(HEX/BIN) without using IDE.
- Git clone Git@GitHub.com:nbtool/nrf_linux_tool.Git
2.2) 如何使用
- If it is the first time to compile, It is recommended to run goto tool directly, and then run the './run.sh tool' to download gcc,SDK,build-tools etc.
- cd ./tool
- ./run.sh tool
- Build the project(for example:app_nrf51_hids_keyboard):
- cd ./App/app_nrf51_hids_keyboard/build
- make clean
- make all
- Install the App:
- make erase
- make flash_flash_softdevice
- make flash
2.3)DEMO 介绍
app_nrf51_peri_blinky> 简单工程, 主要用 nRF51 的 GPIO 外设控制一个 LED 闪烁;
app_nrf51_ble_hrs> BLE 工程, 心律计, BLE DEMO 级工程, 展示心律, 电池电量等特征;
app_nrf51_hids_mouse> BLE 工程, 蓝牙鼠标 DEMO 级工程, 了解 HID;
app_nrf51_hids_keyboard> BLE 工程, 蓝牙键盘 DEMO 级工程, 按动按键给上位机发送 hello;
2.4) 工程结构介绍
未运行 run.sh 构建环境前的目录结构:(可见, 当前 App 层只有 4 个简单的 DEMO,tool 里面只有一个 run.sh 脚本)
- nrf_linux_tool Git:(master) tree -L 2
- .
├── App
│ ├── app_nrf51_ble_hrs
│ ├── app_nrf51_hids_keyboard
│ ├── app_nrf51_hids_mouse
│ └── app_nrf51_peri_blinky
├── README.md
└── tool
└── run.sh
构建之后的目录结构:(比未构建多了一个 sdk/nRF5_SDK_12.3.0_d7731ad,gcc-ARM 编译器, 和 nRF5x 命令行工具)
- nrf_linux_tool Git:(master) tree -L 2
- .
├── App
│ ├── app_nrf51_ble_hrs
│ ├── app_nrf51_hids_keyboard
│ ├── app_nrf51_hids_mouse
│ └── app_nrf51_peri_blinky
├── README.md
├── sdk
│ └── nRF5_SDK_12.3.0_d7731ad
└── tool
├── gcc-ARM-none-eabi-5_4-2016q3
├── nRF5x-Command-Line-Tools_9_7_3
└── run.sh
注: 之所以将 SDK 和 GCC 等工具通过构建产生, 是为了减少 Git 仓库的大小!
2.5)run.sh 构建脚本介绍
run.sh 脚本比较长, 其最核心的在于 tool 函数, 在该函数内是分别判断 GCC,nRF5_Command_Lind,nRF5_SDK 是否存在, 如果不存在则下载:(以下载安装 nRF5x command line tool 为例)
- echo "> install nRF5x command line tool ..."
- if [ ! -d $NRF5X_COMMAND_LINE_PATH ]; then
- pack=nRF5x-Command-Line-Tools_9_7_3_Linux-x86_64.tar
- wget -O $pack $NRF5X_COMMAND_LINE_LINK
- mkdir $NRF5X_COMMAND_LINE_PATH
- tar -xvf $pack -C $NRF5X_COMMAND_LINE_PATH
- rm -rf $pack
- fi
特殊的, 在博客《编译 4》中介绍: SDK 安装好之后需要更新 / components/toolchain/gcc/Makefile.posix, 这里我们也用脚本实现:
- echo "> update the *.posix file, when the project root is changed ..."
- t_arm_gcc_path=`pwd`/gcc-ARM-none-eabi-5_4-2016q3
- posix_file=$NRF5_SDK_12_3_0_PATH"/components/toolchain/gcc/Makefile.posix"
- echo "GNU_INSTALL_ROOT := $t_arm_gcc_path"> $posix_file
- echo "GNU_VERSION := 5.4.1">> $posix_file
- echo "GNU_PREFIX := ARM-none-eabi">> $posix_file
由于这里 GNU_INSTALL_ROOT 采用的是绝对路径, 因此一旦整个工程的根目录发生变化, 需要运行./run.sh tool 更新 posix 文件.
2.6) 典例 DEMO 介绍
BLE 工程太过复杂, 我们还是看看闪灯工程吧:
- app_nrf51_peri_blinky Git:(master) tree
- .
├── build
│ ├── blinky_gcc_nrf51.ld
│ ├── Makefile
│ ├── objects.mk
│ ├── sdk_config.h
│ └── sources.mk
└── main.c
其中 main.c 是唯一一个 App 层代码文件, build 目录下是一个简单的 makefile 框架, 用来编译, 烧写, 擦除程序:
- #include <stdbool.h>
- #include <stdint.h>
- #include "nrf_delay.h"
- #include "boards.h"
- /**
- * @brief Function for application main entry.
- */
- int main(void)
- {
- /* Configure board. */
- bsp_board_leds_init();
- /* Toggle LEDs. */
- while (true)
- {
- for (int i = 0; i < LEDS_NUMBER; i++)
- {
- bsp_board_led_invert(i);
- nrf_delay_ms(500);
- }
- }
- }
注: App 中的 4 个 DEMO 是从 SDK 的 example 中移植上来的, 改动比较小, 后续会把更多 DEMO 移到 App 里, 并写博客介绍~
三, android_app_linux_tool 开源项目介绍
3.1) 项目简介
The project provides a Android App command-line development environment based on Linux system.
You can directly write,build,install Android App without using IDE.
Git clone Git@GitHub.com:nbtool/android_app_linux_tool.Git
3.2) 如何使用
- Enter the root directory of an example (for example: HelloAndroid).
- If it is the first time to compile, It is recommended to run make tool to download platform,SDK,build-tools etc.
- cd ./example/HelloAndroid
- make tool
- Build the project:
- make build
- Install the App:
- make program
3.3)DEMO 介绍
- HelloAndroid: hello world demo
- BluetoorhScan: bluetooth scan + surface(canvas) + handler + bundle
- FlyGame: surface(canvas) + fly game demo
第一个是 hello world; 第二个是蓝牙 scan 周边设备的信号强度; 第三个是几年前做的一款小游戏:
3.4) 工程结构介绍
类似上一个开源项目, 未构建前只有 DEMO:
- android_app_linux_tool Git:(master) tree -L 3
- .
├── example
│ ├── BluetoothScan
│ │ ├── run.sh
│ │ └── ...
│ ├── FlyGame ...
│ └── HelloAndroid ...
└── readme.md
构建之后多了安卓 SDK:
- android_app_linux_tool Git:(master) tree -L 3
- .
├── example
│ ├── BluetoothScan
│ │ ├── run.sh
│ │ └── ...
│ ├── FlyGame ...
│ └── HelloAndroid ...
├── readme.md
└── tool
└── Android-sdk
├── build-tools
├── licenses
├── platforms
├── platform-tools
└── tools
注: 安卓工程里的 run.sh 不是放在 tool 中, 而是放在每个 DEMO 里面, 因为每个 DEMO 所依赖的 SDK 和 build 工具的版本可能不一样!
3.5)run.sh 构建脚本介绍
和上一个类似, tool 函数用来下载相关 SDK, 编译工具, plantform-tool 等, 同时这里也把编译 build, 烧写 program, 和清除 clean 也集成进 run.sh 中了. 真正用的时候是通过 makefile 调用 run.sh 实现:
- HelloAndroid Git:(master) cat makefile
- tool:
- ./run.sh tool
- clean:
- ./run.sh clean
- build:
- ./run.sh build
- program:
- ./run.sh program
- all:
- ./run.sh all
3.6) 典例 DEMO 介绍
以 Hello World 为例:
- HelloAndroid Git:(master) tree
- .
├── AndroidManifest.xml
├── bin
├── libs
├── makefile
├── mykey.keystore
├── obj
├── res
│ ├── layout
│ │ └── activity_main.xml
│ └── values
│ └── strings.xml
├── run.sh
└── src
└── com
└── example
└── helloandroid
└── MainActivity.java
麻雀虽小, 五脏俱全, 该工程包含一个 MainActivity.java 文件, 两个资源文件, 一个 Manifest.xml 文件, 最终生成的 apk 会存放到 bin 文件中.
同样的, 今后我还会在 Example 中增加更多 DEMO, 并在博客中进行介绍. 同时, 也欢迎其他人来贡献 DEMO ~
LINKS
[1].nrf_linux_tool 项目 GitHub 地址 https://GitHub.com/nbtool/nrf_linux_tool
[2].android_app_linux_tool 项目 GitHub 地址 https://GitHub.com/nbtool/android_app_linux_tool
[3]. 在 Linux 下搭建 nRF51822 的开发烧写环境
[4]. 在 Linux 下搭建安卓 App 的开发烧写环境
来源: https://www.cnblogs.com/zjutlitao/p/9710859.html