Initial commit

This commit is contained in:
Florian Kaiser 2023-07-31 10:47:57 +02:00
commit 8f9cff0934
Signed by: H4CK3R-01
SSH Key Fingerprint: SHA256:Zh0ZE/S6X5mfivz9uLnbQizfkJfEQTjL8FlWbPqhqk0
8 changed files with 305 additions and 0 deletions

10
Dockerfile Normal file
View File

@ -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

15
README.md Normal file
View File

@ -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.

12
data/CMakeLists.txt Normal file
View File

@ -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)

5
data/VERSION Normal file
View File

@ -0,0 +1,5 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =

0
data/app.overlay Normal file
View File

17
data/main.c Normal file
View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <app_version.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
int main(void)
{
printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
return 0;
}

0
data/prj.conf Normal file
View File

246
script.sh Executable file
View File

@ -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