Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

load 2.1KB

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