From a0e03fa82c999744b8b2d449784f1e14bf8dc21f Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 19 Feb 2017 17:04:09 -0800 Subject: snapshot sketch and infrastructure from the Kaleidoscope example --- .gitignore | 3 + .kaleidoscope-builder.conf | 3 + .travis.yml | 31 +++++ Makefile | 10 ++ Model01-Firmware.ino | 148 +++++++++++++++++++++ tools/kaleidoscope-builder | 312 +++++++++++++++++++++++++++++++++++++++++++++ tools/settings.sh | 85 ++++++++++++ 7 files changed, 592 insertions(+) create mode 100644 .gitignore create mode 100644 .kaleidoscope-builder.conf create mode 100644 .travis.yml create mode 100644 Makefile create mode 100644 Model01-Firmware.ino create mode 100755 tools/kaleidoscope-builder create mode 100644 tools/settings.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09b121a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +.#* +/output/ diff --git a/.kaleidoscope-builder.conf b/.kaleidoscope-builder.conf new file mode 100644 index 0000000..e4a5db4 --- /dev/null +++ b/.kaleidoscope-builder.conf @@ -0,0 +1,3 @@ +# -*- mode: sh -*- + +DEFAULT_SKETCH=Model01-Firmware diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b61d8af --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: c +before_install: +- pushd .. +- wget http://downloads.arduino.cc/arduino-1.6.11-linux64.tar.xz +- tar xf arduino-1.6.11-linux64.tar.xz +- popd +install: +- pushd .. +- mkdir -p arduino-local/hardware/keyboardio +- git clone https://github.com/keyboardio/Arduino-Boards arduino-local/hardware/keyboardio/avr +- cd arduino-local/hardware/keyboardio/avr +- git submodule sync --recursive +- git submodule update --init --recursive +- popd +script: +- make ARDUINO_PATH=../arduino-1.6.11 ARDUINO_LOCAL_LIB_PATH=../arduino-local build-all +notifications: + irc: + channels: + - "chat.freenode.net#keyboardio" + use_notice: true + skip_join: true + template: + - "%{repository_name}/%{branch} %{commit} by %{author}: %{commit_subject} %{build_url} %{message}" + email: + on_success: change + on_failure: change + slack: + secure: geVAHVhYQ5bY7ja5vx1Tgxc5y64WLuXVEWKmw4LqiThFYCjtpdWkHGiZJfhUwkVI11u5w8w1FUmrB7ZP4EUGoXhCK/z1mvVMVJ9+fS+WoaqcTHFJi0hGbvXaFPD7QA+ef7TLrFcU643kf6KHN/P+dVVndLyhctXZqOZHHwXmKZNMt8qM5Gh5h41HOi0YjT9yFafSU0qf5jphF5qvjlxKsVJF+WxtMSU4xMYxzq7rf80bPi2pu4ijgqR5+Haaa71DJ1V2TA4wZ+BFTBo2YUJIGZ8qDlqmb7RdF/u72G/8HbT/Hzj55blrpBXU/BPkokGOPJlIGHPV76ESpJI0ZUILRifmkZY6ylMjl/hutDYPNjhMq8Z/UKSLN6pJQAq0PjqAoHCtPsXTbRMT0lhVt2itkCPwAXVgszTrE6INsNylY/soaDu66Sjmz2zQH8sC6hbL8SrZ0xGs1Q+e3q5WMETPIAS9f4n2YCxkIz4ORoL9IrOXUcebVNriiWKzOBt6bleWPJlGc6yVYkkUhvURH+jEp6v2Y5SqsaJVTD3I5Gq/H/0PJBtPdzu470yQ3/FD4g6M0AmWx8DCuvl1O295QOZbUtujpIowTm7PynFrAgW3ptSidjzWjzZaHc0iQJBiNi86dg3GomoEEOPzx8hnX7fhFgsR+Ixqfzx0srrQYqleQGY= +cache: + ccache: true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e73d34f --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +# default action for `make` is `build` +build: + +astyle: + find . -type f -name \*.cpp |xargs -n 1 astyle --style=google + find . -type f -name \*.ino |xargs -n 1 astyle --style=google + find . -type f -name \*.h |xargs -n 1 astyle --style=google + +%: + @tools/kaleidoscope-builder $@ diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino new file mode 100644 index 0000000..2db600e --- /dev/null +++ b/Model01-Firmware.ino @@ -0,0 +1,148 @@ +// -*- mode: c++ -*- +// Copyright 2016 Keyboardio, inc. +// See "LICENSE" for license details + +#define DEBUG_SERIAL false + +#include "Kaleidoscope-MouseKeys.h" +#include "Kaleidoscope-Macros.h" +#include "Kaleidoscope-LEDControl.h" +#include "Kaleidoscope-Numlock.h" +#include "Kaleidoscope.h" + +#include "LED-Off.h" +#include "Kaleidoscope-LEDEffect-SolidColor.h" +#include "Kaleidoscope-LEDEffect-Breathe.h" +#include "Kaleidoscope-LEDEffect-Chase.h" +#include "Kaleidoscope-LEDEffect-Rainbow.h" +#include "Kaleidoscope-Model01-TestMode.h" + +uint8_t primary_keymap = 0; +uint8_t temporary_keymap = 0; + +#define NUMPAD_KEYMAP 2 + +#define COLEMAK KEYMAP ( \ + ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ + Key_Backtick, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_Tab, Key_Enter, Key_J, Key_L, Key_U, Key_Y, Key_Semicolon, Key_Equals, \ + Key_PageUp, Key_A, Key_R, Key_S, Key_T, Key_D, Key_H, Key_N, Key_E, Key_I, Key_O, Key_Quote, \ + Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, ___, Key_K, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,\ + Key_LCtrl, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl,\ + Key_Keymap1_Momentary, Key_Keymap1_Momentary,\ +) + +#define DVORAK KEYMAP ( \ + ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ + Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_Tab, Key_Enter, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Slash, \ + Key_PageUp, Key_A, Key_O, Key_E, Key_U, Key_I, Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus, \ + Key_PageDn, Key_Semicolon, Key_Q, Key_J, Key_K, Key_X, Key_Esc, ___, Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals, \ + Key_LCtrl, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl, \ + Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ +) + +#define GENERIC_FN2 KEYMAP_STACKED ( \ + ___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, XXX, \ + Key_Tab, Key_mouseBtnM, Key_mouseUp, ___, Key_mouseWarpNW, Key_mouseWarpNE, Key_nextTrack, \ + Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseWarpSW, Key_mouseWarpSE, \ + Key_End, Key_Z, Key_X, Key_C, Key_V, Key_mouseWarpEnd, ___, \ + Key_LCtrl, Key_mouseBtnL, Key_LGUI, Key_LShift, \ + ___,\ +\ + XXX, Key_F6, Key_F7, Key_F8, Key_F9, ___, ___,\ + Key_Delete, Key_playPause, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_sleep,\ + Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_F11, Key_F12,\ + ___, Key_volumeDown, Key_volumeUp, Key_BacklightDn, Key_BacklightUp, Key_Backslash, Key_Pipe,\ + Key_RShift, Key_RAlt, Key_mouseBtnR, Key_RCtrl,\ + ___\ +) + + + +#define MALTRON KEYMAP ( \ + ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ + Key_Backtick, Key_Q, Key_P, Key_Y, Key_C, Key_B, Key_Tab, Key_Enter, Key_V, Key_M, Key_U, Key_Z, Key_L, Key_Equals, \ + Key_PageUp, Key_A, Key_N, Key_I, Key_S, Key_F, Key_D, Key_T, Key_H, Key_O, Key_R, Key_Quote, \ + Key_PageDn, Key_Comma, Key_Period, Key_J, Key_G, Key_Slash, Key_Esc, ___, Key_Semicolon, Key_W, Key_K, Key_Minus, Key_X, Key_LSquareBracket, \ + Key_E, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl, \ + Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ +) + +#define NUMPAD KEYMAP (\ + ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadMinus, ___, \ + ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadPlus, ___, \ + ___, ___, ___, ___, ___, ___, ___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, Key_Quote, \ + ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadSlash, Key_Enter, \ + Key_LCtrl, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl, \ + Key_Keymap1_Momentary, Key_Keymap1_Momentary \ +) + +#define QWERTY KEYMAP ( \ + ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ + Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, \ + Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, \ + Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, ___, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, \ + Key_LCtrl, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl, \ + Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ +) + +#define WORKMAN KEYMAP ( \ + ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ + Key_Backtick, Key_Q, Key_D, Key_R, Key_W, Key_B, Key_Tab, Key_Enter, Key_J, Key_F, Key_U, Key_P, Key_Semicolon, Key_Equals, \ + Key_PageUp, Key_A, Key_S, Key_H, Key_T, Key_G, Key_Y, Key_N, Key_E, Key_O, Key_I, Key_Quote, \ + Key_PageDn, Key_Z, Key_X, Key_M, Key_C, Key_V, Key_Esc, ___, Key_K, Key_L, Key_Comma, Key_Period, Key_Slash, Key_Minus, \ + Key_LCtrl, Key_Backspace, Key_LGUI, Key_LShift, Key_RShift, Key_RAlt, Key_Space, Key_RCtrl, \ + Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ +) + +const Key keymaps[][ROWS][COLS] PROGMEM = { + QWERTY, + GENERIC_FN2, + NUMPAD + + + }; + +static LEDSolidColor solidRed (60, 0, 0); +static LEDSolidColor solidOrange (60, 20, 0); +static LEDSolidColor solidYellow (40, 35, 0); +static LEDSolidColor solidGreen (0, 100, 0); +static LEDSolidColor solidBlue (0, 15, 100); +static LEDSolidColor solidIndigo (0, 0, 100); +static LEDSolidColor solidViolet (70, 0, 60); + +const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { + if (macroIndex == TOGGLENUMLOCK && key_toggled_on(keyState)) { + return NumLock.toggle (Macros.row, Macros.col, NUMPAD_KEYMAP); + } + + if (macroIndex == 1 && key_toggled_on(keyState)) { + Serial.print("Keyboard.IO keyboard driver v0.00"); + return MACRO(I(25), + D(LShift), T(M), U(LShift), T(O), T(D), T(E), T(L), + T(Space), + W(100), + T(0), T(1), + END); + } + return MACRO_NONE; +} + +void setup() { + Kaleidoscope.setup(KEYMAP_SIZE); + + Kaleidoscope.use(&TestMode, + &LEDControl, &LEDOff, + &solidRed, &solidOrange, &solidYellow, &solidGreen, &solidBlue, &solidIndigo, &solidViolet, + &LEDBreatheEffect, &LEDRainbowEffect, &LEDChaseEffect, &NumLock, + + &Macros, + &MouseKeys, + NULL); + + LEDOff.activate(); +} + + +void loop() { + Kaleidoscope.loop(); +} diff --git a/tools/kaleidoscope-builder b/tools/kaleidoscope-builder new file mode 100755 index 0000000..97d1188 --- /dev/null +++ b/tools/kaleidoscope-builder @@ -0,0 +1,312 @@ +#! /bin/sh + +set -e + +firmware_size () { + ## This is a terrible hack, please don't hurt me. - algernon + + MAX_PROG_SIZE=28672 + + output="$($@ | grep "\\(Program\\|Data\\):" | sed -e 's,^, - ,' && echo)" + + PROGSIZE="$(echo "${output}" | grep Program: | cut -d: -f2 | awk '{print $1}')" + + PERCENT="$(echo ${PROGSIZE} ${MAX_PROG_SIZE} | awk "{ printf \"%02.01f\", \$1 / \$2 * 100 }")" + + echo "${output}" | sed -e "s,\(Program:.*\)(\([0-9\.]*%\) Full),\1(${PERCENT}% Full)," +} + +find_sketch () { + if [ -e "${SOURCEDIR}/.kaleidoscope-builder.conf" ]; then + . "${SOURCEDIR}/.kaleidoscope-builder.conf" + fi + + SKETCH="${SKETCH:-${DEFAULT_SKETCH}}" + LIBRARY="${LIBRARY:-${SKETCH}}" + + for path in "hardware/keyboardio/avr/libraries/Kaleidoscope-${LIBRARY}/examples/${SKETCH}" \ + "examples/${LIBRARY}" \ + "src"; do + if [ -f "${path}/${SKETCH}.ino" ]; then + echo "${path}" + return + fi + done + exit 1 +} + +prepare_to_flash () { + if [ ! -e "${HEX_FILE_PATH}" ]; then + compile + fi + + echo "Press ENTER when ready..." + read a +} + +flash () { + prepare_to_flash + reset_device + sleep 3s + flash_over_usb + +} + +flash_over_usb () { + avrdude -q -q -p${MCU} -cavr109 -D -P ${DEVICE_PORT_BOOTLOADER} -b57600 "-Uflash:w:${HEX_FILE_PATH}:i" + +} + +program() { + prepare_to_flash + flash_with_programmer +} + +flash_with_programmer() { + + avrdude -v \ + -p${MCU} \ + -cusbtiny \ + -D \ + -B 1 \ + "-Uflash:w:${HEX_FILE_PATH}:i" +} + +hex_with_bootloader () { + if [ ! -e "${HEX_FILE_PATH}" ]; then + compile + fi + + cat ${HEX_FILE_PATH} | awk '/^:00000001FF/ == 0' > ${HEX_FILE_WITH_BOOTLOADER_PATH} + echo "Using ${BOOTLOADER_PATH}" + ${MD5} ${BOOTLOADER_PATH} + cat ${BOOTLOADER_PATH} >> ${HEX_FILE_WITH_BOOTLOADER_PATH} + cat <&2 + exit 1 + ;; +esac + +SKETCH="${SKETCH:-${DEFAULT_SKETCH}}" +LIBRARY="${LIBRARY:-${SKETCH}}" + +if [ -z "${SKETCH}" ] || [ -z "${LIBRARY}" ] || [ -z "${ROOT}" ] || [ -z "${SOURCEDIR}" ]; then + echo "SKETCH, LIBRARY, SOURCEDIR, and ROOT need to be set before including this file!" >&2 + exit 1 +fi + +BOARD="${BOARD:-model01}" +MCU="${MCU:-atmega32u4}" +FQBN="${FQBN:-keyboardio:avr:${BOARD}}" + +DEVICE_PORT="$(ls /dev/ttyACM* 2>/dev/null || echo '')" +DEVICE_PORT_BOOTLOADER="$(ls /dev/ttyACM* 2>/dev/null || echo '')" + +RESET_DEVICE="stty -F ${DEVICE_PORT} 1200 hupcl" + +ARDUINO_PATH="${ARDUINO_PATH:-/usr/local/arduino}" +ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-${HOME}/Arduino}" +ARDUINO_TOOLS_PATH="${ARDUINO_TOOLS_PATH:-${ARDUINO_PATH}/hardware/tools}" +ARDUINO_BUILDER="${ARDUINO_BUILDER:-${ARDUINO_PATH}/arduino-builder}" +ARDUINO_IDE_VERSION="100607" + +BOARD_HARDWARE_PATH="${BOARD_HARDWARE_PATH:-${ARDUINO_LOCAL_LIB_PATH}/hardware}" +BOOTLOADER_PATH="${BOARD_HARDWARE_PATH}/keyboardio/avr/bootloaders/caterina/Caterina.hex" + +AVR_SIZE="${AVR_SIZE:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-size}" +AVR_NM="${AVR_NM:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-nm}" +AVR_OBJDUMP="${AVR_OBJDUMP:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-objdump}" + +MD5="md5sum" + +BUILD_PATH="${BUILD_PATH:-$(mktemp -d 2>/dev/null || mktemp -d -t 'build')}" +OUTPUT_DIR="${OUTPUT_DIR:-output/${LIBRARY}}" +OUTPUT_PATH="${OUTPUT_PATH:-${SOURCEDIR}/${OUTPUT_DIR}}" + +GIT_VERSION="$(cd $(find_sketch); git describe --abbrev=4 --dirty --always)" +LIB_VERSION="$(cd $(find_sketch); (grep version= ../../library.properties 2>/dev/null || echo version=0.0.0) | cut -d= -f2)-g${GIT_VERSION}" + +OUTPUT_FILE_PREFIX="${SKETCH}-${LIB_VERSION}" + +HEX_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex" +HEX_FILE_WITH_BOOTLOADER_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex" +ELF_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf" + +ARDUINO_TOOLS_PARAM="-tools ${ARDUINO_TOOLS_PATH}" +if [ -z "${ARDUINO_TOOLS_PATH}" ]; then + ARDUINO_TOOLS_PARAM="" +fi + +if [ ! -z "${AVR_GCC_PREFIX}" ]; then + ARDUINO_AVR_GCC_PREFIX_PARAM="-prefs \"runtime.tools.avr-gcc.path=${AVR_GCC_PREFIX}\"" +fi + +if [ ! -z "${VERBOSE}" ] && [ "${VERBOSE}" -gt 0 ]; then + ARDUINO_VERBOSE="-verbose" +else + ARDUINO_VERBOSE="-quiet" +fi + +## Platform-specific overrides +# Shamelessly stolen from git's Makefile +uname_S=$(uname -s 2>/dev/null || echo not) + +if [ "${uname_S}" = "Darwin" ]; then + DEVICE_PORT="$(ls /dev/cu.usbmodemHID?? /dev/cu.usbmodem14*)" + DEVICE_PORT_BOOTLOADER="$(ls /dev/cu.usbmodem14*)" + + ARDUINO_PATH="/Applications/Arduino.app/Contents/Java/" + ARDUINO_LOCAL_LIB_PATH="${HOME}/Documents/Arduino" + + MD5="md5" + + RESET_DEVICE="stty -f ${DEVICE_PORT} 1200" +fi -- cgit v1.2.3