zephyr-configurator/script.sh

313 lines
6.9 KiB
Bash
Raw Normal View History

2023-07-31 08:47:57 +00:00
#!/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
}
2023-08-03 06:20:34 +00:00
display_code() {
string="----- Imports -----
${2}
----- Code -----
${3}"
dialog --title "$1" \
--backtitle "Configure Zephyr RTOS" \
--no-collapse \
--msgbox "$string" -1 -1
}
2023-07-31 08:47:57 +00:00
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() {
2023-08-03 06:20:34 +00:00
# TODO
2023-07-31 08:47:57 +00:00
connectivity=$( dialog --stdout \
--backtitle "Connectivity" \
2023-08-03 06:20:34 +00:00
--menu "Please select:" $HEIGHT $WIDTH 4 \
1 "WiFi" \
2 "Bluetooth" \
3 "LoRaWAN" \
4 "NB-IoT")
2023-07-31 08:47:57 +00:00
2023-08-03 06:20:34 +00:00
case $connectivity in
1 ) # WiFi
# TODO
;;
2 ) # Bluetooth
# TODO
;;
3 ) # LoRaWAN
# TODO
;;
4 ) # NB-IoT
# TODO
;;
esac
2023-07-31 08:47:57 +00:00
}
protocols_dialog() {
2023-08-03 06:20:34 +00:00
# TODO
2023-07-31 08:47:57 +00:00
protocols=$( dialog --stdout \
--backtitle "Protocols" \
2023-08-03 06:20:34 +00:00
--menu "Please select:" $HEIGHT $WIDTH 4 \
1 "MQTT" \
2 "REST" \
3 "CoAP")
2023-07-31 08:47:57 +00:00
2023-08-03 06:20:34 +00:00
case $protocols in
1 ) # MQTT
# TODO
;;
2 ) # REST
# TODO
;;
3 ) # CoAP
# TODO
;;
esac
2023-07-31 08:47:57 +00:00
}
interfaces_dialog() {
2023-08-03 06:20:34 +00:00
# TODO
2023-07-31 08:47:57 +00:00
interfaces=$( dialog --stdout \
--backtitle "Interfaces" \
2023-08-03 06:20:34 +00:00
--menu "Please select:" $HEIGHT $WIDTH 4 \
1 "I2C" \
2 "SPI" \
3 "UART")
2023-07-31 08:47:57 +00:00
2023-08-03 06:20:34 +00:00
case $interfaces in
1 ) # I2C
# TODO
;;
2 ) # SPI
# TODO
;;
esac
2023-07-31 08:47:57 +00:00
}
sensors_dialog() {
2023-08-03 06:20:34 +00:00
# TODO
2023-07-31 08:47:57 +00:00
sensors=$( dialog --stdout \
--backtitle "Sensors" \
2023-08-03 06:20:34 +00:00
--menu "Please select:" $HEIGHT $WIDTH 4 \
1 "Button" \
2 "Sensor 2" \
3 "Sensor 3" \
4 "Sensor 4" )
2023-07-31 08:47:57 +00:00
2023-08-03 06:20:34 +00:00
case $sensors in
1 ) # Button
imports=$(cat snippets/button/imports.txt)
code=$(cat snippets/led/code.txt)
display_code "Use this code snippet" "$imports" "$code"
;;
2 )
# TODO
;;
3 )
# TODO
;;
esac
2023-07-31 08:47:57 +00:00
}
actuators_dialog() {
2023-08-03 06:20:34 +00:00
# TODO
2023-07-31 08:47:57 +00:00
actuators=$( dialog --stdout \
--backtitle "Actuators" \
2023-08-03 06:20:34 +00:00
--menu "Please select:" $HEIGHT $WIDTH 4 \
1 "LED" \
2 "Actuators 2" \
3 "Actuators 3" \
4 "Actuators 4" )
2023-07-31 08:47:57 +00:00
2023-08-03 06:20:34 +00:00
case $actuators in
1 ) # LED
imports=$(cat snippets/led/imports.txt)
code=$(cat snippets/led/code.txt)
display_code "Use this code snippet" "$imports" "$code"
;;
2 )
# TODO
;;
3 )
# TODO
;;
4 )
# TODO
;;
esac
2023-07-31 08:47:57 +00:00
}
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
2023-08-03 06:20:34 +00:00
2023-07-31 08:47:57 +00:00
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/*
2023-08-03 06:20:34 +00:00
2023-07-31 08:47:57 +00:00
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