]> git.donarmstrong.com Git - kiibohd-controller.git/blob - LoadFile/winload.teensy
1d86daf17a0a914a11afb945830080089a74e124
[kiibohd-controller.git] / LoadFile / winload.teensy
1 #!/bin/bash
2 # Convenience script for loading firmware onto a teensy type device
3 # By default, initiates teensy-load-cli
4
5 SERIAL_PORT=""
6 AUTO_SCREEN_SESSION=""
7 PROG_NAME=$(basename $0)
8
9 # Parse all the command line arguments
10 while (( "$#" >= "1" )); do
11         # Scan each argument
12         key="$1"
13         case $key in
14         -a|--autoscreen)
15                 AUTO_SCREEN_SESSION="$2"
16                 shift
17                 ;;
18         -f|--fastload)
19                 SERIAL_PORT="$2"
20                 shift
21                 ;;
22         -h|--help)
23                 echo "Usage: $PROG_NAME [options...]"
24                 echo ""
25                 echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
26                 echo "Requires Cygwin."
27                 echo "  (winload.teensy)"
28                 echo ""
29                 echo "Arguments:"
30                 echo " -f, --fastload SERIAL_PORT    Send the reload command to the debug terminal."
31                 echo "                               e.g. /dev/ttyACM0"
32                 echo "                               NOTE: May not work due to non-functional terminal, or disable remote flashing"
33                 echo " -h, --help                    This message."
34                 exit 1
35                 ;;
36         *)
37                 echo "INVALID ARG: '$1'"
38                 exit 2
39                 ;;
40         esac
41
42         # Shift to the next argument
43         shift
44 done
45
46 # First check to see teensy-loader-cli has been compiled
47 if [ ! -e teensy-loader-cli/teensy-loader-cli ]; then
48         # Compile teensy-loader-cli
49         mkdir -p teensy-loader-cli
50         cd teensy-loader-cli
51         cmake -G "Unix Makefiles" $(cygpath -u @CMAKE_SOURCE_DIR@/LoadFile)
52         make || exit 3
53         cd -
54 fi
55
56 # If a SERIAL_PORT was specified set the uC into reflash mode
57 # XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
58 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
59         echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
60         printf "reload\r" > $SERIAL_PORT
61         sleep 1
62 fi
63
64 # Loads the hex file onto the teensy
65 teensy-loader-cli/teensy-loader-cli -mmcu=@MCU@ -w @TARGET_HEX@
66 EXIT_STATUS=$?
67
68 exit $EXIT_STATUS
69