From b1f8debeeb84badfc5c8809b4961ad312d188cc1 Mon Sep 17 00:00:00 2001
From: Scott Bronson <brons_git@rinspin.com>
Date: Wed, 25 Jan 2012 21:02:59 -0800
Subject: [PATCH] add ability to program teensy

---
 Makefile |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 1f8e4b2..cd559ca 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,9 @@ F_CPU = 16000000
 # Output format. (can be srec, ihex, binary)
 FORMAT = ihex
 
+# The programmer to use for 'make program'
+PROGRAMMER = teensy
+
 
 # Object files directory
 #     To put object files in current directory, use a dot (.), do NOT make
@@ -245,7 +248,6 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
 #LDFLAGS += -T linker_script.x
 
 
-
 #---------------- Programming Options (avrdude) ----------------
 
 # Programming hardware
@@ -282,6 +284,18 @@ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
 
 
 
+#---------------- Programming Options (teensy_loader) ----------------
+
+TEENSY_VERBOSE = -v
+# If WAIT_FOR_DEVICE is set, programmer blocks until device is programmable
+# (push button).  If not, and no device found, it exits with error.
+TEENSY_WAIT_FOR_DEVICE = -w
+
+TEENSY_FLAGS += -mmcu=$(MCU)
+TEENSY_FLAGS += $(TEENSY_VERBOSE)
+TEENSY_FLAGS += $(TEENSY_WAIT_FOR_DEVICE)
+
+
 #---------------- Debugging Options ----------------
 
 # For simulavr only - target MCU frequency.
@@ -323,6 +337,7 @@ SIZE = avr-size
 AR = avr-ar rcs
 NM = avr-nm
 AVRDUDE = avrdude
+TEENSY = teensy_loader_cli
 REMOVE = rm -f
 REMOVEDIR = rm -rf
 COPY = cp
@@ -425,8 +440,13 @@ gccversion :
 
 
 # Program the device.  
+ifeq ($(PROGRAMMER),avrdude)
 program: $(TARGET).hex $(TARGET).eep
 	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
+else
+program: $(TARGET).hex
+	$(TEENSY) $(TEENSY_FLAGS) $<
+endif
 
 
 # Generate avr-gdb config/init file which does the following:
-- 
1.7.5.4

