diff options
| -rw-r--r-- | .github/workflows/compile.yml | 4 | ||||
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | bin/build-all.sh | 35 | ||||
| -rwxr-xr-x | bin/build.sh | 41 | ||||
| -rwxr-xr-x | bin/detect-mcu.sh | 6 | ||||
| -rwxr-xr-x | bin/dfp-install.sh | 2 | ||||
| -rwxr-xr-x | bin/flash-tiny13-fuses.bat | 1 | ||||
| -rwxr-xr-x | bin/flash-tiny13-fuses.sh | 8 | ||||
| -rwxr-xr-x | bin/flash-tiny13.bat | 1 | ||||
| -rwxr-xr-x | bin/flash-tiny13.sh | 3 | ||||
| -rwxr-xr-x | bin/flash-tiny1616.sh | 10 | ||||
| -rwxr-xr-x | bin/flash-tiny1634-fuses.sh | 2 | ||||
| -rwxr-xr-x | bin/flash-tiny1634.sh | 6 | ||||
| -rwxr-xr-x | bin/flash-tiny25-fuses.sh | 8 | ||||
| -rwxr-xr-x | bin/flash-tiny25.sh | 3 | ||||
| -rwxr-xr-x | bin/flash-tiny85-fuses.sh | 2 | ||||
| -rwxr-xr-x | bin/flash-tiny85.sh | 6 | ||||
| -rwxr-xr-x | bin/flash.sh | 12 | ||||
| -rwxr-xr-x | make | 18 | ||||
| -rwxr-xr-x | ui/fireflies-ui/build-all.sh | 2 | ||||
| -rwxr-xr-x | ui/rampingios/build-all.sh | 2 | ||||
| -rwxr-xr-x | ui/werner/build-all.sh | 2 |
23 files changed, 83 insertions, 102 deletions
diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 57d049c..893eb41 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -15,6 +15,10 @@ jobs: - name: Checkout uses: actions/checkout@master + - name: Stop committing version.h + # reject commit if version.h was changed + run: grep 1969-07-20 ui/anduril/version.h + - name: Requirements run: | sudo apt-get -qqy update @@ -1,8 +1,13 @@ +.env/ +.venv/ +.*.swo +.*.swp arch/dfp/ env/ hex/ ignore/ old/ +venv/ *~ *.cpp *.elf @@ -11,5 +16,3 @@ old/ *.o *.old *.otl -.*.swo -.*.swp @@ -117,8 +117,8 @@ If you use `pymcuprog` to flash firmware, a few extras are needed: ```sh sudo apt install python3 python3-pip python3-venv -python3 -m venv env -source env/bin/activate +python3 -m venv .venv +source .venv/bin/activate pip install pymcuprog ``` diff --git a/bin/build-all.sh b/bin/build-all.sh index 0372ad7..130923f 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # Anduril / FSM build wrapper script # Copyright (C) 2017-2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later @@ -6,9 +6,12 @@ # Usage: build-all.sh [pattern] # If pattern given, only build targets which match. -if [ ! -z "$1" ]; then +# enable "**" for recursive glob (requires bash) +shopt -s globstar + +if [ "$#" -gt 0 ]; then # multiple search terms with "AND" - SEARCH=$@ + SEARCH=( "$@" ) # memes [ "$1" = "me" ] && shift && shift && echo "Make your own $*." && exit 1 fi @@ -27,18 +30,19 @@ FAIL=0 PASSED='' FAILED='' -# build targets are hw/*/**/$UI.h -for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do +# build targets are hw/$vendor/$model/**/$ui.h +for TARGET in hw/*/*/**/"$UI".h ; do # friendly name for this build NAME=$(echo "$TARGET" | perl -ne 's|/|-|g; /hw-(.*)-'"$UI"'.h/ && print "$1\n";') # limit builds to searched patterns, if given SKIP=0 - if [ ! -z "$SEARCH" ]; then - for text in $SEARCH ; do - echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null - if [ 0 != $? ]; then SKIP=1 ; fi + if [ ${#SEARCH[@]} -gt 0 ]; then + for text in "${SEARCH[@]}" ; do + if ! echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null ; then + SKIP=1 + fi done fi if [ 1 = $SKIP ]; then continue ; fi @@ -46,18 +50,15 @@ for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do # announce what we're going to build echo "===== $UI : $NAME =====" - # try to compile - bin/build.sh "$TARGET" - - # track result, and rename compiled files - if [ 0 = $? ] ; then - mv -f "ui/$UI/$UI".hex hex/"$UI".$NAME.hex + # try to compile, track result, and rename compiled files + if bin/build.sh "$TARGET" ; then + mv -f "ui/$UI/$UI".hex "hex/$UI.$NAME.hex" echo " > hex/$UI.$NAME.hex" - PASS=$(($PASS + 1)) + PASS=$((PASS + 1)) PASSED="$PASSED $NAME" else echo "ERROR: build failed" - FAIL=$(($FAIL + 1)) + FAIL=$((FAIL + 1)) FAILED="$FAILED $NAME" fi diff --git a/bin/build.sh b/bin/build.sh index 50f93b7..9b4b0b3 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Anduril / FSM build script # Copyright (C) 2014-2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later @@ -6,7 +6,7 @@ # Instead of using a Makefile, since most of the firmwares here build in the # same exact way, here's a script to do the same thing -if [ -z "$1" ]; then +if [ 0 = "$#" ]; then echo "Usage: build.sh TARGET USER" echo "Example: build.sh hw/hank/emisar-d4/anduril.h users/myuser" echo "(but USER isn't implemented yet)" @@ -14,18 +14,19 @@ if [ -z "$1" ]; then fi # repo root dir -BASEDIR=$(dirname $(dirname "$0")) +BASEDIR=$(dirname "$(dirname "$0")") -TARGET=$1 ; shift -UI=$(basename $TARGET .h) -MODEL=$(dirname $TARGET) +TARGET="$1" ; shift +ARGS="$*" +UI=$(basename "$TARGET" .h) +MODEL=$(dirname "$TARGET") PROGRAM="ui/$UI/$UI" # figure out the model number -MODEL_NUMBER=$(head -1 $MODEL/model) +MODEL_NUMBER=$(head -1 "$MODEL/model") # figure out the MCU type and set some vars -eval $( bin/detect-mcu.sh "$TARGET" ) +eval "$( bin/detect-mcu.sh "$TARGET" )" # detect and enable a relevant Atmel DFP if [[ $MCUNAME =~ "attiny" ]]; then @@ -56,23 +57,19 @@ export LDFLAGS="-fgnu89-inline" export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex --remove-section .fuse' export OBJS=$PROGRAM.o -OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\"" -for arg in "$*" ; do - OTHERFLAGS="$OTHERFLAGS $arg" -done +OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\" $ARGS" function run () { - #echo $1 ; shift - #echo $* - $* - if [ x"$?" != x0 ]; then exit 1 ; fi + #echo "$1" ; shift + #echo "$*" + $* || exit 1 } -run $CPP $OTHERFLAGS $CPPFLAGS -o foo.cpp $PROGRAM.c -grep -a -E -v '^#|^$' foo.cpp > $PROGRAM.cpp ; rm foo.cpp -run $CC $OTHERFLAGS $CFLAGS -o $PROGRAM.o -c $PROGRAM.c -run $CC $OFLAGS $LDFLAGS -o $PROGRAM.elf $PROGRAM.o -run $OBJCOPY $OBJCOPYFLAGS $PROGRAM.elf $PROGRAM.hex +run "$CPP" "$OTHERFLAGS" "$CPPFLAGS" -o foo.cpp "$PROGRAM.c" +grep -a -E -v '^#|^$' foo.cpp > "$PROGRAM.cpp" ; rm foo.cpp +run "$CC" "$OTHERFLAGS" "$CFLAGS" -o "$PROGRAM.o" -c "$PROGRAM.c" +run "$CC" "$OFLAGS" "$LDFLAGS" -o "$PROGRAM.elf" "$PROGRAM.o" +run "$OBJCOPY" "$OBJCOPYFLAGS" "$PROGRAM.elf" "$PROGRAM.hex" # deprecated #run avr-size -C --mcu=$MCUNAME $PROGRAM.elf | grep Full -run avr-objdump -Pmem-usage $PROGRAM.elf | grep -E 'Full|Device' | sed 's/^/ /;' +run avr-objdump -Pmem-usage "$PROGRAM".elf | grep -E 'Full|Device' | sed 's/^/ /;' diff --git a/bin/detect-mcu.sh b/bin/detect-mcu.sh index 761eac1..57670e2 100755 --- a/bin/detect-mcu.sh +++ b/bin/detect-mcu.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # Anduril / FSM MCU type detection script # Copyright (C) 2014-2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later @@ -15,7 +15,7 @@ TARGET=$1 while [ -n "$TARGET" ]; do #echo "... $TARGET" if [ -f "$TARGET" ]; then # use the dir/$UI.h file - ATTINY=$(grep 'ATTINY:' $TARGET | awk '{ print $3 }') + ATTINY=$(grep 'ATTINY:' "$TARGET" | awk '{ print $3 }') if [ -n "$ATTINY" ]; then echo "export MCUNAME=attiny${ATTINY}" echo "export MCU=0x${ATTINY}" @@ -39,7 +39,7 @@ while [ -n "$TARGET" ]; do # move up one dir # if target doesn't change here, exit to avoid infinite loop FOO="$TARGET" - TARGET=$(dirname $TARGET) + TARGET=$(dirname "$TARGET") [ "$FOO" = "$TARGET" ] && exit 1 done diff --git a/bin/dfp-install.sh b/bin/dfp-install.sh index a73c4d5..24b4908 100755 --- a/bin/dfp-install.sh +++ b/bin/dfp-install.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # Atmel DFP download/install/setup script # Copyright (C) 2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later diff --git a/bin/flash-tiny13-fuses.bat b/bin/flash-tiny13-fuses.bat deleted file mode 100755 index cec982e..0000000 --- a/bin/flash-tiny13-fuses.bat +++ /dev/null @@ -1 +0,0 @@ -avrdude -c usbasp -p t13 -u -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m diff --git a/bin/flash-tiny13-fuses.sh b/bin/flash-tiny13-fuses.sh deleted file mode 100755 index fe479a8..0000000 --- a/bin/flash-tiny13-fuses.sh +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/sh -# 4.8 MHz (~4.0 MHz actual), 4ms boot delay, enable flashing -# (everything else disabled) -# Use low fuse 0x75 for 4ms startup delay, -# or 0x79 for 64ms (useful on a twisty light) -avrdude -c usbasp -p t13 -u -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m - -# http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATtiny13A&P=ATtiny13A&M_LOW_0x0F=0x05&M_LOW_0x80=0x00&M_HIGH_0x06=0x06&B_SPIEN=P&B_SUT1=P&B_CKSEL1=P&V_LOW=75&V_HIGH=FF&O_HEX=Apply+values diff --git a/bin/flash-tiny13.bat b/bin/flash-tiny13.bat deleted file mode 100755 index db75fd8..0000000 --- a/bin/flash-tiny13.bat +++ /dev/null @@ -1 +0,0 @@ -avrdude -p t13 -c usbasp -u -Uflash:w:%1:a diff --git a/bin/flash-tiny13.sh b/bin/flash-tiny13.sh deleted file mode 100755 index 47b2bfe..0000000 --- a/bin/flash-tiny13.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/sh -FIRMWARE=$1 -avrdude -c usbasp -p t13 -u -Uflash:w:$FIRMWARE diff --git a/bin/flash-tiny1616.sh b/bin/flash-tiny1616.sh index 44d716c..3ad37b9 100755 --- a/bin/flash-tiny1616.sh +++ b/bin/flash-tiny1616.sh @@ -1,5 +1,5 @@ -#/bin/sh -FIRMWARE=$1 +#!/usr/bin/env sh +FIRMWARE="$1" if [ -z "$AVRDUDE_TTYUSB" ]; then AVRDUDE_TTYUSB=/dev/ttyUSB0 ; fi # In your shell config: @@ -7,8 +7,8 @@ if [ -z "$AVRDUDE_TTYUSB" ]; then AVRDUDE_TTYUSB=/dev/ttyUSB0 ; fi # export AVRDUDE_CONF="-C$HOME/path/to/jtag2updi/avrdude.conf" # export AVRDUDE_TTYUSB="/dev/ttyUSB2" -avrdude $AVRDUDE_CONF \ +avrdude "$AVRDUDE_CONF" \ -c jtag2updi \ - -P $AVRDUDE_TTYUSB \ + -P "$AVRDUDE_TTYUSB" \ -p t1616 \ - -u -Uflash:w:$FIRMWARE + -u -Uflash:w:"$FIRMWARE" diff --git a/bin/flash-tiny1634-fuses.sh b/bin/flash-tiny1634-fuses.sh index 1bc73e1..5b95411 100755 --- a/bin/flash-tiny1634-fuses.sh +++ b/bin/flash-tiny1634-fuses.sh @@ -1,4 +1,4 @@ -#/bin/sh +#!/usr/bin/env sh # 8 MHz, 64ms boot delay, enable flashing # (everything else disabled) # Use low fuse 0xD2 for 4ms startup delay, diff --git a/bin/flash-tiny1634.sh b/bin/flash-tiny1634.sh index 2eb9b77..5516d08 100755 --- a/bin/flash-tiny1634.sh +++ b/bin/flash-tiny1634.sh @@ -1,3 +1,3 @@ -#/bin/sh -FIRMWARE=$1 -avrdude -c usbasp -p t1634 -u -Uflash:w:$FIRMWARE +#!/usr/bin/env sh +FIRMWARE="$1" +avrdude -c usbasp -p t1634 -u -Uflash:w:"$FIRMWARE" diff --git a/bin/flash-tiny25-fuses.sh b/bin/flash-tiny25-fuses.sh deleted file mode 100755 index 65d5b1d..0000000 --- a/bin/flash-tiny25-fuses.sh +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/sh -# 8 MHz, 4ms boot delay, enable flashing -# (everything else disabled) -# Use low fuse 0xD2 for 4ms startup delay, -# or 0xE2 for 64ms (useful on a twisty light) -avrdude -c usbasp -p t25 -u -U lfuse:w:0xd2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m - -# http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATtiny25&P=ATtiny25&M_LOW_0x3F=0x22&M_HIGH_0x07=0x07&M_HIGH_0x20=0x00&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_CKSEL0=P&V_LOW=E2&V_HIGH=DF&V_EXTENDED=FF&O_HEX=Apply+values diff --git a/bin/flash-tiny25.sh b/bin/flash-tiny25.sh deleted file mode 100755 index 9975671..0000000 --- a/bin/flash-tiny25.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/sh -FIRMWARE=$1 -avrdude -c usbasp -p t25 -u -Uflash:w:$FIRMWARE diff --git a/bin/flash-tiny85-fuses.sh b/bin/flash-tiny85-fuses.sh index f49049a..d73eae0 100755 --- a/bin/flash-tiny85-fuses.sh +++ b/bin/flash-tiny85-fuses.sh @@ -1,4 +1,4 @@ -#/bin/sh +#!/usr/bin/env sh # 8 MHz, 64ms boot delay, enable flashing # (everything else disabled) # Use low fuse 0xD2 for 4ms startup delay, diff --git a/bin/flash-tiny85.sh b/bin/flash-tiny85.sh index 0f5a292..a0dfae9 100755 --- a/bin/flash-tiny85.sh +++ b/bin/flash-tiny85.sh @@ -1,3 +1,3 @@ -#/bin/sh -FIRMWARE=$1 -avrdude -c usbasp -p t85 -u -Uflash:w:$FIRMWARE +#!/usr/bin/env sh +FIRMWARE="$1" +avrdude -c usbasp -p t85 -u -Uflash:w:"$FIRMWARE" diff --git a/bin/flash.sh b/bin/flash.sh index 0423c90..a0eafc5 100755 --- a/bin/flash.sh +++ b/bin/flash.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Flashes both fuses and firmware. @@ -11,9 +11,9 @@ fi set -e -BASEDIR=$(dirname "$0") -export ATTINY=$1 ; shift -export PROGRAM=$1 ; shift +BASEDIR="$(dirname "$0")" +export ATTINY="$1" ; shift +export PROGRAM="$1" ; shift if [ ! -f "$PROGRAM" ]; then PROGRAM="$PROGRAM".hex ; fi -$BASEDIR/flash-tiny"$ATTINY"-fuses.sh -$BASEDIR/flash-tiny"$ATTINY".sh "$PROGRAM" +"$BASEDIR"/flash-tiny"$ATTINY"-fuses.sh +"$BASEDIR"/flash-tiny"$ATTINY".sh "$PROGRAM" @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Anduril / FSM "make" script # Copyright (C) 2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later @@ -50,12 +50,12 @@ ENDOFHELP # sub-command parser / dispatcher function main() { case "$MODE" in - -h|--help|help|/?|/h|/help) + -h|--help|help|/\?|/h|/help) help ;; clean) - echo 'rm -vf **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp' - rm -vf **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp + echo 'rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp' + rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp ;; dfp) shift @@ -76,7 +76,7 @@ function main() { echo "Not implemented yet." ;; todo) - grep -E 'TODO:|FIXME:' **/*.[ch] + grep -E 'TODO:|FIXME:' -- **/*.[ch] **/*.md ;; *) exec ./bin/build-all.sh "$@" @@ -86,15 +86,15 @@ function main() { function make-docs () { for md in **/*.md ; do - echo "$md" - html=$(echo "$md" | sed 's/.md$/.html/') + html=${md//.md/.html} + echo "$md --> $html" cmark-gfm "$md" > "$html" done } # go to the repo root -BASEDIR=$(dirname $0) -cd "$BASEDIR" +BASEDIR=$(dirname "$0") +cd "$BASEDIR" || (echo "Error: Can't cd to basedir." && exit 1) # do whatever the user requested main "$@" diff --git a/ui/fireflies-ui/build-all.sh b/ui/fireflies-ui/build-all.sh index 81ebd97..83c6964 100755 --- a/ui/fireflies-ui/build-all.sh +++ b/ui/fireflies-ui/build-all.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh cp -av --no-clobber ../anduril/cfg-ff*.h . diff --git a/ui/rampingios/build-all.sh b/ui/rampingios/build-all.sh index 106dc15..c788b1f 100755 --- a/ui/rampingios/build-all.sh +++ b/ui/rampingios/build-all.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh cp -av ../anduril/cfg-emisar*.h . diff --git a/ui/werner/build-all.sh b/ui/werner/build-all.sh index b114101..4c88369 100755 --- a/ui/werner/build-all.sh +++ b/ui/werner/build-all.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh cp -av ../anduril/cfg*.h . |
