From 8f9cff093480312e72f492b1ea0cda210d203d29 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Mon, 31 Jul 2023 10:47:57 +0200 Subject: [PATCH] Initial commit --- Dockerfile | 10 ++ README.md | 15 +++ data/CMakeLists.txt | 12 +++ data/VERSION | 5 + data/app.overlay | 0 data/main.c | 17 +++ data/prj.conf | 0 script.sh | 246 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 305 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 data/CMakeLists.txt create mode 100644 data/VERSION create mode 100644 data/app.overlay create mode 100644 data/main.c create mode 100644 data/prj.conf create mode 100755 script.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e4ec61d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM ghcr.io/zephyrproject-rtos/zephyr-build:latest + +RUN sudo apt update && sudo apt install dialog -y + +COPY script.sh /opt +COPY data /opt/data + +RUN sudo chmod +x /opt/script.sh + +ENTRYPOINT /opt/script.sh \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..79b3254 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Zephyr configurator + +## Run +``` +docker build . -t zephyr-config + +docker volume create --driver local --name zephyr --opt type=none --opt device=$HOME/zephyrproject --opt o=uid=root,gid=root --opt o=bind +docker run -it -v zephyr:/workdir --rm zephyr-config +``` + +## Developing +1. Create the zephyr workspace if you are running the container for the first time by using the first option in the menu +2. Create a new project by selecting the second option +3. Open the `$HOME/zephyrproject/app` directory in your IDE. The source code is located in the `src` subdirectory. +4. Build and flash the project using the options 4 and 5. diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt new file mode 100644 index 0000000..eff0ff6 --- /dev/null +++ b/data/CMakeLists.txt @@ -0,0 +1,12 @@ +#------------------------------------------------------------------------------- +# Zephyr Example Application +# +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(app LANGUAGES C) + +target_sources(app PRIVATE src/main.c) \ No newline at end of file diff --git a/data/VERSION b/data/VERSION new file mode 100644 index 0000000..79053a5 --- /dev/null +++ b/data/VERSION @@ -0,0 +1,5 @@ +VERSION_MAJOR = 1 +VERSION_MINOR = 0 +PATCHLEVEL = 0 +VERSION_TWEAK = 0 +EXTRAVERSION = \ No newline at end of file diff --git a/data/app.overlay b/data/app.overlay new file mode 100644 index 0000000..e69de29 diff --git a/data/main.c b/data/main.c new file mode 100644 index 0000000..aff2071 --- /dev/null +++ b/data/main.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); + +int main(void) +{ + printk("Zephyr Example Application %s\n", APP_VERSION_STRING); + + return 0; +} \ No newline at end of file diff --git a/data/prj.conf b/data/prj.conf new file mode 100644 index 0000000..e69de29 diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..04e797b --- /dev/null +++ b/script.sh @@ -0,0 +1,246 @@ +#!/bin/bash + +DIALOG_CANCEL=1 +DIALOG_ESC=255 +HEIGHT=-1 +WIDTH=-1 + +# Choices +PLATTFORM=nrf52840dongle_nrf52840 +CONNECTIVITY= +INTERFACES= +PROTOCOLS= +SENSORS= +ACTUATORS= + +display_result() { + dialog --title "$1" \ + --backtitle "Configure Zephyr RTOS" \ + --no-collapse \ + --msgbox "$2" -1 -1 +} + +main_dialog() { + selection=$(dialog --stdout \ + --backtitle "Configure Zephyr RTOS" \ + --title "Menu" \ + --no-cancel \ + --menu "Please select:" $HEIGHT $WIDTH 4 \ + "1" "Init Zephyr workspace" \ + "2" "Create empty project" \ + "3" "Add additional functionalities" \ + "4" "Build project" \ + "5" "Flash project" \ + "6" "Clean build directory" \ + "7" "Exit") + + case $selection in + 1 ) + init_workspace + ;; + 2 ) + init_project + ;; + 3 ) + settings_dialog + ;; + 4 ) + build_project + ;; + 5 ) + flash_project + ;; + 6 ) + clean_build_dir + ;; + 7 ) + clear + exit + ;; + esac +} + +settings_dialog() { + selection=$(dialog --stdout \ + --backtitle "Configure Zephyr RTOS" \ + --title "Menu" \ + --cancel-label "Exit" \ + --menu "Please select:" $HEIGHT $WIDTH 4 \ + "1" "Connectivity" \ + "2" "Protocols" \ + "3" "Interfaces" \ + "4" "Sensors" \ + "5" "Actuators" ) + + case $selection in + 1 ) + connectivity_dialog + ;; + 2 ) + protocols_dialog + ;; + 3 ) + interfaces_dialog + ;; + 4 ) + sensors_dialog + ;; + 5 ) + actuators_dialog + ;; + esac +} + +plattform_dialog() { + plattform=$( dialog --stdout \ + --backtitle "Plattform" \ + --default-item "$PLATTFORM" \ + --no-tags \ + --no-cancel \ + --radiolist "Select plattform:" $HEIGHT $WIDTH 4 \ + esp32c3_devkitm "ESP32-C3" $(equals "$PLATTFORM" "esp32c3_devkitm") \ + nrf5340dk_nrf5340_cpuapp "nRF5340 DK" $(equals "$PLATTFORM" "nrf5340dk_nrf5340_cpuapp") \ + nrf52840dongle_nrf52840 "nRF52840 Dongle" $(equals "$PLATTFORM" "nrf52840dongle_nrf52840") \ + thingy91_nrf9160_ns "Thingy:91 (nRF9160)" $(equals "$PLATTFORM" "thingy91_nrf9160_ns") \ + thingy91_nrf52840 "Thingy:91 (nRF52840)" $(equals "$PLATTFORM" "thingy91_nrf52840") ) + + if [ ! -z "$plattform" ]; then + PLATTFORM=$plattform + fi +} + +connectivity_dialog() { + connectivity=$( dialog --stdout \ + --backtitle "Connectivity" \ + --checklist "Select connectivity:" $HEIGHT $WIDTH 4 \ + 1 "WiFi" $(in_array "$CONNECTIVITY" 1) \ + 2 "Bluetooth" $(in_array "$CONNECTIVITY" 2) \ + 3 "LoRaWAN" $(in_array "$CONNECTIVITY" 3) \ + 4 "NB-IoT" $(in_array "$CONNECTIVITY" 4) ) + + if [ ! -z "$connectivity" ]; then + CONNECTIVITY=$connectivity + fi +} + +protocols_dialog() { + protocols=$( dialog --stdout \ + --backtitle "Protocols" \ + --checklist "Select protocols:" $HEIGHT $WIDTH 4 \ + 1 "MQTT" $(in_array "$PROTOCOLS" 1) \ + 2 "REST" $(in_array "$PROTOCOLS" 2) \ + 3 "CoAP" $(in_array "$PROTOCOLS" 3) ) + + if [ ! -z "$protocols" ]; then + PROTOCOLS=$protocols + fi +} + +interfaces_dialog() { + interfaces=$( dialog --stdout \ + --backtitle "Interfaces" \ + --checklist "Select interfaces:" $HEIGHT $WIDTH 4 \ + 1 "I2C" $(in_array "$INTERFACES" 1) \ + 2 "SPI" $(in_array "$INTERFACES" 2) \ + 3 "UART" $(in_array "$INTERFACES" 3) ) + + if [ ! -z "$interfaces" ]; then + INTERFACES=$interfaces + fi +} + +sensors_dialog() { + sensors=$( dialog --stdout \ + --backtitle "Sensors" \ + --checklist "Select sensors:" $HEIGHT $WIDTH 4 \ + 1 "Sensor 1" $(in_array "$SENSORS" 1) \ + 2 "Sensor 2" $(in_array "$SENSORS" 2) \ + 3 "Sensor 3" $(in_array "$SENSORS" 3) \ + 4 "Sensor 4" $(in_array "$SENSORS" 4) ) + + if [ ! -z "$sensors" ]; then + SENSORS=$sensors + fi +} + +actuators_dialog() { + actuators=$( dialog --stdout \ + --backtitle "Actuators" \ + --checklist "Select actuators:" $HEIGHT $WIDTH 4 \ + 1 "Actuators 1" $(in_array "$ACTUATORS" 1) \ + 2 "Actuators 2" $(in_array "$ACTUATORS" 2) \ + 3 "Actuators 3" $(in_array "$ACTUATORS" 3) \ + 4 "Actuators 4" $(in_array "$ACTUATORS" 4) ) + + if [ ! -z "$actuators" ]; then + ACTUATORS=$actuators + fi +} + +init_workspace() { + cd /workdir + { west init; west update; west zephyr-export; echo "Created workspace successfully"; } 2>&1 | dialog --programbox -1 -1 +} + +init_project() { + mkdir /workdir/app + mkdir /workdir/app/src + + cp /opt/data/main.c /workdir/app/src/main.c + cp /opt/data/app.overlay /workdir/app/app.overlay + cp /opt/data/CMakeLists.txt /workdir/app/CMakeLists.txt + cp /opt/data/prj.conf /workdir/app/prj.conf + cp /opt/data/VERSION /workdir/app/VERSION + + display_result 'Created project' "Project created successfully.\nThe project is located in /workdir.\nYou can edit it by using your favorite IDE." +} + +build_project() { + plattform_dialog + + { cd /workdir/app/; west build -b $PLATTFORM; } 2>&1 | dialog --programbox -1 -1 +} + +flash_project() { + plattform_dialog + + case "$PLATTFORM" in + "nrf52840dongle_nrf52840") + display_result 'Flash project' "Please run those commands in an environment where nrfutil and the compiled hex files are available:\\n\\n\\nnrfutil pkg generate --hw-version 52 --sd-req=0x00 --application build/zephyr/zephyr.hex --application-version 1 mcuboot.zip\\n\\nnrfutil dfu usb-serial -pkg mcuboot.zip -p /dev/ttyACM0" + ;; + *) + display_result "Error" "Board not configured in this tool yet\nSee https://docs.zephyrproject.org/latest/boards/index.html#boards" + ;; + esac +} + +clean_build_dir() { + rm -rf /workdir/app/build/* + + display_result "Cleaned build" "Cleaned build directory successfully" +} + +in_array() { + if [[ $1 =~ (^|[[:space:]])"$2"($|[[:space:]]) ]] ; then + echo on; + else + echo off; + fi +} + +equals() { + if [[ $1 == "$2" ]] ; then + echo on; + else + echo off; + fi +} + +if ! command -v dialog &> /dev/null +then + sudo apt update && sudo apt install dialog +fi + +while true; do + main_dialog +done \ No newline at end of file