|
|
|
|
|
|
|
# Shamelessly stolen from git's Makefile
|
|
|
|
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
|
|
|
|
|
|
|
|
|
|
|
DEVICE_PORT := `ls /dev/ttyACM*`
|
|
|
|
DEVICE_PORT_BOOTLOADER := `ls /dev/ttyACM*`
|
|
|
|
ARDUINO_PATH?=/usr/local/arduino
|
|
|
|
ARDUINO_LOCAL_LIB_PATH?=$(HOME)/Arduino
|
|
|
|
|
|
|
|
MD5 = md5sum
|
|
|
|
|
|
|
|
RESET_BOARD=stty -F $(DEVICE_PORT) 1200 hupcl
|
|
|
|
|
|
|
|
ifeq ($(uname_S),Darwin)
|
|
|
|
|
|
|
|
# Port locations
|
|
|
|
|
|
|
|
DEVICE_PORT := `ls /dev/cu.usbmodemHID?? /dev/cu.usbmodem14*`
|
|
|
|
DEVICE_PORT_BOOTLOADER := `ls /dev/cu.usbmodem14*`
|
|
|
|
|
|
|
|
# Tools
|
|
|
|
|
|
|
|
ARDUINO_PATH=/Applications/Arduino.app/Contents/Java/
|
|
|
|
ARDUINO_LOCAL_LIB_PATH=$(HOME)/Documents/Arduino
|
|
|
|
|
|
|
|
MD5 = md5
|
|
|
|
|
|
|
|
RESET_BOARD=stty -f $(DEVICE_PORT) 1200
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ARDUINO_TOOLS_PATH=$(ARDUINO_PATH)/hardware/tools
|
|
|
|
ARDUINO_BUILDER_PATH=$(ARDUINO_PATH)/arduino-builder
|
|
|
|
AVRDUDE_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avrdude
|
|
|
|
AVRDUDE_CONF_PATH=$(ARDUINO_TOOLS_PATH)/avr/etc/avrdude.conf
|
|
|
|
AVR_SIZE_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-size
|
|
|
|
AVR_NM_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-nm
|
|
|
|
AVR_OBJDUMP_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-objdump
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Device and sketch info
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
BOARD = model01
|
|
|
|
MCU = atmega32u4
|
|
|
|
FQBN=keyboardio:avr:model01
|
|
|
|
SKETCH=KeyboardioFirmware.ino
|
|
|
|
BOOTLOADER_PATH = $(ARDUINO_LOCAL_LIB_PATH)/hardware/keyboardio/avr/bootloaders/caterina/Caterina.hex
|
|
|
|
VERBOSE= #-verbose
|
|
|
|
|
Support an Arch-style Arduino installation
Arch puts the Arduino tools into /usr/bin, hardware bits under
/usr/share/arduino, and so on. To make ends meet, and support both the
traditional install, and Arch, introduce a bit of magic:
- If `ARDUINO_TOOLS_PATH` is empty, then we should not add the `-tools`
param that refers to it. On arch, this is not needed, and there is no
reasonable alternative, that would also make sense. So in this case,
it should not be added at all. Setting the variable to an empty string
accomplishes that goal nicely.
- If an `AVR_GCC_PREFIX` variable is set, use that as the value for
`runtime.tools.avr-gcc.path`, otherwise `arduino-builder` will try to
find the avr-* tools somewhere under the Arduino prefix, which on
Arch, is not the case.
With this change, along with keyboardio/KeyboardioHID#3, and adding an
`archlinux-arduino`=>`arduino` symlink somewhere, it becomes possible to
complie KeyboardioFirmware on Arch, using the packaged Arduino, with the
following commandline:
> make ARDUINO_BUILDER_PATH=/usr/bin/arduino-builder \
> ARDUINO_PATH=/usr/share/arduino \
> ARDUINO_LOCAL_LIB_PATH=../arduino-local \
> AVR_GCC_PREFIX=/usr \
> ARDUINO_TOOLS_PATH= \
> AVR_SIZE_PATH=avr-size
Not the nicest, by far, but possible.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
8 years ago
|
|
|
ARDUINO_TOOLS_PARAM = -tools $(ARDUINO_TOOLS_PATH)
|
|
|
|
ifeq ($(ARDUINO_TOOLS_PATH),)
|
|
|
|
ARDUINO_TOOLS_PARAM =
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef AVR_GCC_PREFIX
|
|
|
|
ARDUINO_AVR_GCC_PREFIX_PREF = -prefs "runtime.tools.avr-gcc.path=$(AVR_GCC_PREFIX)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Build
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
BUILD_PATH := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'build')
|
|
|
|
OUTPUT_PATH=./output
|
|
|
|
ARDUINO_IDE_VERSION=100607
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Output
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always)
|
|
|
|
OUTPUT_FILE_PREFIX=$(SKETCH)-$(GIT_VERSION)
|
|
|
|
HEX_FILE_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).hex
|
|
|
|
ELF_FILE_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).elf
|
|
|
|
HEX_FILE_WITH_BOOTLOADER_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX)-with-bootloader.hex
|
|
|
|
|
|
|
|
# default action for `make` is `build`
|
|
|
|
build: compile size
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
generate-keymaps:
|
|
|
|
-rm examples/KeyboardioFirmware/generated/keymaps.h
|
|
|
|
cd examples/KeyboardioFirmware/layouts && ( find . -type f | sort | xargs -n 1 -I % sh -c 'perl ../../../tools/generate_keymaps.pl < % >> ../generated/keymaps.h' )
|
|
|
|
|
|
|
|
dirs:
|
|
|
|
mkdir -p $(OUTPUT_PATH)
|
|
|
|
|
|
|
|
compile: dirs
|
|
|
|
$(ARDUINO_BUILDER_PATH) \
|
|
|
|
-hardware $(ARDUINO_PATH)/hardware \
|
|
|
|
-hardware $(ARDUINO_LOCAL_LIB_PATH)/hardware \
|
Support an Arch-style Arduino installation
Arch puts the Arduino tools into /usr/bin, hardware bits under
/usr/share/arduino, and so on. To make ends meet, and support both the
traditional install, and Arch, introduce a bit of magic:
- If `ARDUINO_TOOLS_PATH` is empty, then we should not add the `-tools`
param that refers to it. On arch, this is not needed, and there is no
reasonable alternative, that would also make sense. So in this case,
it should not be added at all. Setting the variable to an empty string
accomplishes that goal nicely.
- If an `AVR_GCC_PREFIX` variable is set, use that as the value for
`runtime.tools.avr-gcc.path`, otherwise `arduino-builder` will try to
find the avr-* tools somewhere under the Arduino prefix, which on
Arch, is not the case.
With this change, along with keyboardio/KeyboardioHID#3, and adding an
`archlinux-arduino`=>`arduino` symlink somewhere, it becomes possible to
complie KeyboardioFirmware on Arch, using the packaged Arduino, with the
following commandline:
> make ARDUINO_BUILDER_PATH=/usr/bin/arduino-builder \
> ARDUINO_PATH=/usr/share/arduino \
> ARDUINO_LOCAL_LIB_PATH=../arduino-local \
> AVR_GCC_PREFIX=/usr \
> ARDUINO_TOOLS_PATH= \
> AVR_SIZE_PATH=avr-size
Not the nicest, by far, but possible.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
8 years ago
|
|
|
$(ARDUINO_TOOLS_PARAM) \
|
|
|
|
-tools $(ARDUINO_PATH)/tools-builder \
|
|
|
|
-fqbn $(FQBN) \
|
|
|
|
-libraries $(ARDUINO_LOCAL_LIB_PATH) \
|
|
|
|
-libraries . \
|
|
|
|
$(VERBOSE) \
|
|
|
|
-build-path $(BUILD_PATH) \
|
|
|
|
-ide-version $(ARDUINO_IDE_VERSION) \
|
Support an Arch-style Arduino installation
Arch puts the Arduino tools into /usr/bin, hardware bits under
/usr/share/arduino, and so on. To make ends meet, and support both the
traditional install, and Arch, introduce a bit of magic:
- If `ARDUINO_TOOLS_PATH` is empty, then we should not add the `-tools`
param that refers to it. On arch, this is not needed, and there is no
reasonable alternative, that would also make sense. So in this case,
it should not be added at all. Setting the variable to an empty string
accomplishes that goal nicely.
- If an `AVR_GCC_PREFIX` variable is set, use that as the value for
`runtime.tools.avr-gcc.path`, otherwise `arduino-builder` will try to
find the avr-* tools somewhere under the Arduino prefix, which on
Arch, is not the case.
With this change, along with keyboardio/KeyboardioHID#3, and adding an
`archlinux-arduino`=>`arduino` symlink somewhere, it becomes possible to
complie KeyboardioFirmware on Arch, using the packaged Arduino, with the
following commandline:
> make ARDUINO_BUILDER_PATH=/usr/bin/arduino-builder \
> ARDUINO_PATH=/usr/share/arduino \
> ARDUINO_LOCAL_LIB_PATH=../arduino-local \
> AVR_GCC_PREFIX=/usr \
> ARDUINO_TOOLS_PATH= \
> AVR_SIZE_PATH=avr-size
Not the nicest, by far, but possible.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
8 years ago
|
|
|
$(ARDUINO_AVR_GCC_PREFIX_PREF) \
|
|
|
|
examples/KeyboardioFirmware/$(SKETCH)
|
|
|
|
@cp $(BUILD_PATH)/$(SKETCH).hex $(HEX_FILE_PATH)
|
|
|
|
@cp $(BUILD_PATH)/$(SKETCH).elf $(ELF_FILE_PATH)
|
|
|
|
@echo "Firmware is available at $(HEX_FILE_PATH)"
|
|
|
|
@echo "Have fun!\n"
|
|
|
|
|
|
|
|
size: compile
|
|
|
|
$(AVR_SIZE_PATH) -C --mcu=$(MCU) $(ELF_FILE_PATH)
|
|
|
|
|
|
|
|
size-map: compile
|
|
|
|
$(AVR_NM_PATH) --size-sort -C -r $(ELF_FILE_PATH)
|
|
|
|
|
|
|
|
decompile: compile
|
|
|
|
$(AVR_OBJDUMP_PATH) -d $(ELF_FILE_PATH)
|
|
|
|
|
|
|
|
hex-with-bootloader: compile
|
|
|
|
@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)
|
|
|
|
@echo "Combined firmware and bootloader are now at $(HEX_FILE_WITH_BOOTLOADER_PATH)"
|
|
|
|
@echo "Make sure you have the bootloader version you expect."
|
|
|
|
@echo "\n\nAnd TEST THIS ON REAL HARDWARE BEFORE YOU GIVE IT TO ANYONE\n\n"
|
|
|
|
|
|
|
|
reset-device:
|
|
|
|
$(RESET_BOARD)
|
|
|
|
|
|
|
|
flash: compile reset-device
|
|
|
|
sleep 3
|
|
|
|
$(AVRDUDE_PATH) \
|
|
|
|
-C$(AVRDUDE_CONF_PATH) \
|
|
|
|
-v \
|
|
|
|
-p$(MCU) \
|
|
|
|
-cavr109 \
|
|
|
|
-P$(DEVICE_PORT_BOOTLOADER) \
|
|
|
|
-b57600 \
|
|
|
|
-D \
|
|
|
|
-Uflash:w:$(HEX_FILE_PATH):i
|
|
|
|
|
|
|
|
program:
|
|
|
|
$(AVRDUDE_PATH) \
|
|
|
|
-C$(AVRDUDE_CONF_PATH) \
|
|
|
|
-v \
|
|
|
|
-p$(MCU) \
|
|
|
|
-cusbtiny \
|
|
|
|
-D \
|
|
|
|
-B 1 \
|
|
|
|
-Uflash:w:$(HEX_FILE_PATH):i
|
|
|
|
|