星期四, 27. 九月 2018 12:00上午 - BEAUTIFULZZZZhtml
前幾天給你們介紹瞭如何手動搭建安卓APP命令行開發環境和nRF51822命令行開發環境,中秋這幾天我把上面篇文章的操做流程所有作成了shell腳本,使得可讓其餘人簡單運行下腳本、就可以直接創建綠色開發環境,豈不美哉?java
2.1)項目簡介linux
The project provides a nRF51 APP command-line development environment based on Linux system.android
You can directly write、build、install APP(HEX/BIN) without using IDE.git
git clone git@github.com:nbtool/nrf_linux_tool.git
2.2)如何使用github
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.shell
cd ./tool ./run.sh tool
Build the project(for example:app_nrf51_hids_keyboard):canvas
cd ./app/app_nrf51_hids_keyboard/build make clean make all
Install the APP:app
make erase make flash_flash_softdevice make flash
2.3)DEMO介紹框架
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裏,並寫博客介紹~
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介紹
第一個是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 ~
[1].nrf_linux_tool項目GITHUB地址
[2].android_app_linux_tool項目GITHUB地址
[3].在Linux下搭建nRF51822的開發燒寫環境
[4].在Linux下搭建安卓APP的開發燒寫環境
@beautifulzzzz 智能硬件、物聯網,熱愛技術,關注產品 博客:http://blog.beautifulzzzz.com 園友交流羣:414948975