Browse Source

Major Makefile restructuring.
(Note that this happens without changing any binaries!)
Allows options on Make command line "make xx LED=B3"
(see also pin_defs.h)
Divide into "chip" targets and "board" targets.
Most boards are (recursive) board targets with options.
Move isp target to separate makefile (fixes m8 EFUSE)
Some (many) targets will now be rebuilt when not
strictly necessary, so that options will be included.
(any "make" with options will always compile.)
Set many variables with ?= so they can be overridden
Use arduinoISP settings as default for ISP targets
Restructure makeall to build chip targets last, since versions
are built and renamed to make the board targets.
#

westfw 12 years ago
parent
commit
0baaf625bf

+ 345 - 213
optiboot/bootloaders/optiboot/Makefile

@@ -15,7 +15,23 @@
 # make lilypad_isp
 # make ng_isp
 # etc...
+#
+# Edit History
+# 201303xx: WestfW: Major Makefile restructuring.
+#                   Allows options on Make command line "make xx LED=B3"
+#                   (see also pin_defs.h)
+#                   Divide into "chip" targets and "board" targets.
+#                   Most boards are (recursive) board targets with options.
+#                   Move isp target to separate makefile (fixes m8 EFUSE)
+#                   Some (many) targets will now be rebuilt when not
+#                     strictly necessary, so that options will be included.
+#                     (any "make" with options will always compile.)
+#                   Set many variables with ?= so they can be overridden
+#                   Use arduinoISP settings as default for ISP targets
+#
 
+#----------------------------------------------------------------------
+#
 # program name should not be changed...
 PROGRAM    = optiboot
 
@@ -29,22 +45,10 @@ PROGRAM    = optiboot
 # OS ?= macosx
 # OS ?= windows
 
+# export symbols to recursive makes (for ISP)
+export
 
-# enter the parameters for the avrdude isp tool  -b19200
-#
-# These are the parameters for a usb-based STK500v2 programmer.
-# Exact type unknown.  (historical Makefile values.)
-ISPTOOL	   = stk500v2
-ISPPORT	   =  usb
-ISPSPEED   = -b 115200
-#
-#
-# These are parameters for using an Arduino with the ArduinoISP sketch
-#  as the programmer.  On a mac, for a particular Uno as programmer.
-#ISPTOOL	= stk500v1 -C /Applications/arduino/arduino-0022/hardware/tools/avr/etc/avrdude.conf
-#ISPPORT	= /dev/tty.usbmodemfd3141 
-#ISPSPEED	= -b19200
-
+# defaults
 MCU_TARGET = atmega168
 LDSECTIONS  = -Wl,--section-start=.text=0x3e00 -Wl,--section-start=.version=0x3ffe
 
@@ -62,7 +66,6 @@ ifeq ($(ENV), arduino)
 # of avr-tools are "right up there" in standard places.
 TOOLROOT = ../../../tools
 GCCROOT = $(TOOLROOT)/avr/bin/
-AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
 
 ifeq ($(OS), windows)
 # On windows, SOME of the tool paths will need to have backslashes instead
@@ -90,32 +93,14 @@ else
 GCCROOT =
 AVRDUDE_CONF =
 endif
-#
-# End of build environment code.
-
-
-# the efuse should really be 0xf8; since, however, only the lower
-# three bits of that byte are used on the atmega168, avrdude gets
-# confused if you specify 1's for the higher bits, see:
-# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
-#
-# similarly, the lock bits should be 0xff instead of 0x3f (to
-# unlock the bootloader section) and 0xcf instead of 0x2f (to
-# lock it), but since the high two bits of the lock byte are
-# unused, avrdude would get confused.
-
-ISPFUSES    = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
-              -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-              -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \
-              -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
-ISPFLASH    = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
-              -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-              -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x2f:m
 
 STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
 STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
--lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
+           -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
 STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
+#
+# End of build environment code.
+
 
 OBJ        = $(PROGRAM).o
 OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls
@@ -135,59 +120,98 @@ OBJDUMP        = $(call fixpath,$(GCCROOT)avr-objdump)
 
 SIZE           = $(GCCROOT)avr-size
 
-# Test platforms
-# Virtual boot block test
-virboot328: TARGET = atmega328
-virboot328: MCU_TARGET = atmega328p
-virboot328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DVIRTUAL_BOOT'
-virboot328: AVR_FREQ = 16000000L
-virboot328: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
-virboot328: $(PROGRAM)_atmega328.hex
-virboot328: $(PROGRAM)_atmega328.lst
-
-# 20MHz clocked platforms
 #
-# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
+# Make command-line Options.
+# Permit commands like "make atmega328 LED_START_FLASHES=10" to pass the
+# appropriate parameters ("-DLED_START_FLASHES=10") to gcc
 #
 
-pro20: TARGET = pro_20mhz
-pro20: MCU_TARGET = atmega168
-pro20: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-pro20: AVR_FREQ = 20000000L
-pro20: $(PROGRAM)_pro_20mhz.hex
-pro20: $(PROGRAM)_pro_20mhz.lst
+ifdef BAUD_RATE
+BAUD_RATE_CMD = -DBAUD_RATE=$(BAUD_RATE)
+dummy = FORCE
+else
+BAUD_RATE_CMD = -DBAUD_RATE=115200
+endif
 
-pro20_isp: pro20
-pro20_isp: TARGET = pro_20mhz
-# 2.7V brownout
-pro20_isp: HFUSE = DD
-# Full swing xtal (20MHz) 258CK/14CK+4.1ms
-pro20_isp: LFUSE = C6
-# 512 byte boot
-pro20_isp: EFUSE = 04
-pro20_isp: isp
+ifdef LED_START_FLASHES
+LED_START_FLASHES_CMD = -DLED_START_FLASHES=$(LED_START_FLASHES)
+dummy = FORCE
+else
+LED_START_FLASHES_CMD = -DLED_START_FLASHES=3
+endif
 
-# 16MHz clocked platforms
-#
-# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
+# BIG_BOOT: Include extra features, up to 1K.
+ifdef BIG_BOOT
+BIG_BOOT_CMD = -DBIG_BOOT
+dummy = FORCE
+endif
+
+ifdef SOFT_UART
+SOFT_UART_CMD = -DSOFT_UART
+dummy = FORCE
+endif
+
+ifdef LED_DATA_FLASH
+LED_DATA_FLASH_CMD = -DLED_DATA_FLASH
+dummy = FORCE
+endif
+
+ifdef LED
+LED_CMD = -DLED=$(LED)
+dummy = FORCE
+endif
+
+COMMON_OPTIONS = $(BAUD_RATE_CMD) $(LED_START_FLASHES_CMD) $(BIG_BOOT_CMD)
+COMMON_OPTIONS += $(SOFT_UART_CMD) $(LED_DATA_FLASH_CMD) $(LED_CMD)
+
+#UART is handled separately and only passed for devices with more than one.
+ifdef UART
+UARTCMD = -DUART=$(UART)
+endif
+
+# Not supported yet
+# ifdef SUPPORT_EEPROM
+# SUPPORT_EEPROM_CMD = -DSUPPORT_EEPROM
+# dummy = FORCE
+# endif
+
+# Not supported yet
+# ifdef TIMEOUT_MS
+# TIMEOUT_MS_CMD = -DTIMEOUT_MS=$(TIMEOUT_MS)
+# dummy = FORCE
+# endif
 #
 
-pro16: TARGET = pro_16MHz
-pro16: MCU_TARGET = atmega168
-pro16: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-pro16: AVR_FREQ = 16000000L
-pro16: $(PROGRAM)_pro_16MHz.hex
-pro16: $(PROGRAM)_pro_16MHz.lst
+#---------------------------------------------------------------------------
+# "Chip-level Platform" targets.
+# A "Chip-level Platform" compiles for a particular chip, but probably does
+# not have "standard" values for things like clock speed, LED pin, etc.
+# Makes for chip-level platforms should usually explicitly define their
+# options like: "make atmega1285 AVR_FREQ=16000000L LED=D0"
+#---------------------------------------------------------------------------
+#
+# Note about fuses:
+# the efuse should really be 0xf8; since, however, only the lower
+# three bits of that byte are used on the atmega168, avrdude gets
+# confused if you specify 1's for the higher bits, see:
+# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
+#
+# similarly, the lock bits should be 0xff instead of 0x3f (to
+# unlock the bootloader section) and 0xcf instead of 0x2f (to
+# lock it), but since the high two bits of the lock byte are
+# unused, avrdude would get confused.
+#---------------------------------------------------------------------------
+#
 
-pro16_isp: pro16
-pro16_isp: TARGET = pro_16MHz
-# 2.7V brownout
-pro16_isp: HFUSE = DD
-# Full swing xtal (20MHz) 258CK/14CK+4.1ms
-pro16_isp: LFUSE = C6
-# 512 byte boot
-pro16_isp: EFUSE = 04
-pro16_isp: isp
+# Test platforms
+# Virtual boot block test
+virboot328: TARGET = atmega328
+virboot328: MCU_TARGET = atmega328p
+virboot328: CFLAGS += $(COMMON_OPTIONS) '-DVIRTUAL_BOOT'
+virboot328: AVR_FREQ ?= 16000000L
+virboot328: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
+virboot328: $(PROGRAM)_atmega328.hex
+virboot328: $(PROGRAM)_atmega328.lst
 
 # Diecimila, Duemilanove with m168, and NG use identical bootloaders
 # Call it "atmega168" for generality and clarity, keep "diecimila" for
@@ -195,41 +219,24 @@ pro16_isp: isp
 #
 atmega168: TARGET = atmega168
 atmega168: MCU_TARGET = atmega168
-atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-atmega168: AVR_FREQ = 16000000L 
+atmega168: CFLAGS += $(COMMON_OPTIONS)
+atmega168: AVR_FREQ ?= 16000000L 
 atmega168: $(PROGRAM)_atmega168.hex
 atmega168: $(PROGRAM)_atmega168.lst
 
 atmega168_isp: atmega168
 atmega168_isp: TARGET = atmega168
 # 2.7V brownout
-atmega168_isp: HFUSE = DD
+atmega168_isp: HFUSE ?= DD
 # Low power xtal (16MHz) 16KCK/14CK+65ms
-atmega168_isp: LFUSE = FF
+atmega168_isp: LFUSE ?= FF
 # 512 byte boot
-atmega168_isp: EFUSE = 04
+atmega168_isp: EFUSE ?= 04
 atmega168_isp: isp
 
-diecimila: TARGET = diecimila
-diecimila: MCU_TARGET = atmega168
-diecimila: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-diecimila: AVR_FREQ = 16000000L 
-diecimila: $(PROGRAM)_diecimila.hex
-diecimila: $(PROGRAM)_diecimila.lst
-
-diecimila_isp: diecimila
-diecimila_isp: TARGET = diecimila
-# 2.7V brownout
-diecimila_isp: HFUSE = DD
-# Low power xtal (16MHz) 16KCK/14CK+65ms
-diecimila_isp: LFUSE = FF
-# 512 byte boot
-diecimila_isp: EFUSE = 04
-diecimila_isp: isp
-
 atmega328: TARGET = atmega328
 atmega328: MCU_TARGET = atmega328p
-atmega328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
+atmega328: CFLAGS += $(COMMON_OPTIONS)
 atmega328: AVR_FREQ ?= 16000000L
 atmega328: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
 atmega328: $(PROGRAM)_atmega328.hex
@@ -239,79 +246,59 @@ atmega328_isp: atmega328
 atmega328_isp: TARGET = atmega328
 atmega328_isp: MCU_TARGET = atmega328p
 # 512 byte boot, SPIEN
-atmega328_isp: HFUSE = DE
+atmega328_isp: HFUSE ?= DE
 # Low power xtal (16MHz) 16KCK/14CK+65ms
-atmega328_isp: LFUSE = FF
+atmega328_isp: LFUSE ?= FF
 # 2.7V brownout
-atmega328_isp: EFUSE = FD
+atmega328_isp: EFUSE ?= FD
 atmega328_isp: isp
 
+atmega644p: TARGET = atmega644p
+atmega644p: MCU_TARGET = atmega644p
+atmega644p: CFLAGS += $(COMMON_OPTIONS) -DBIGBOOT $(LED_CMD)
+atmega644p: AVR_FREQ ?= 16000000L
+atmega644p: LDSECTIONS  = -Wl,--section-start=.text=0xfc00 -Wl,--section-start=.version=0xfffe
+atmega644p: CFLAGS += $(UARTCMD)
+atmega644p: $(PROGRAM)_atmega644p.hex
+atmega644p: $(PROGRAM)_atmega644p.lst
+
 atmega1284: TARGET = atmega1284p
 atmega1284: MCU_TARGET = atmega1284p
-atmega1284: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
-atmega1284: AVR_FREQ = 16000000L
+atmega1284: CFLAGS += $(COMMON_OPTIONS) -DBIGBOOT $(LED_CMD)
+atmega1284: AVR_FREQ ?= 16000000L
 atmega1284: LDSECTIONS  = -Wl,--section-start=.text=0x1fc00 -Wl,--section-start=.version=0x1fffe
+atmega1284: CFLAGS += $(UARTCMD)
 atmega1284: $(PROGRAM)_atmega1284p.hex
 atmega1284: $(PROGRAM)_atmega1284p.lst
 
+atmega1284p: atmega1284
+
 atmega1284_isp: atmega1284
 atmega1284_isp: TARGET = atmega1284p
 atmega1284_isp: MCU_TARGET = atmega1284p
 # 1024 byte boot
-atmega1284_isp: HFUSE = DE
+atmega1284_isp: HFUSE ?= DE
 # Full Swing xtal (16MHz) 16KCK/14CK+65ms
-atmega1284_isp: LFUSE = F7
+atmega1284_isp: LFUSE ?= F7
 # 2.7V brownout
-atmega1284_isp: EFUSE = FD
+atmega1284_isp: EFUSE ?= FD
 atmega1284_isp: isp
 
-# Sanguino has a minimum boot size of 1024 bytes, so enable extra functions
-#
-sanguino: TARGET = atmega644p
-sanguino: MCU_TARGET = atmega644p
-sanguino: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
-sanguino: AVR_FREQ = 16000000L
-sanguino: LDSECTIONS  = -Wl,--section-start=.text=0xfc00 -Wl,--section-start=.version=0xfffe
-sanguino: $(PROGRAM)_atmega644p.hex
-sanguino: $(PROGRAM)_atmega644p.lst
-
-sanguino_isp: sanguino
-sanguino_isp: TARGET = atmega644p
-sanguino_isp: MCU_TARGET = atmega644p
-# 1024 byte boot
-sanguino_isp: HFUSE = DE
-# Full swing xtal (16MHz) 16KCK/14CK+65ms
-sanguino_isp: LFUSE = F7
-# 2.7V brownout
-sanguino_isp: EFUSE = FD
-sanguino_isp: isp
-
-# Mega has a minimum boot size of 1024 bytes, so enable extra functions
-#mega: TARGET = atmega1280
-mega1280: MCU_TARGET = atmega1280
-mega1280: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
-mega1280: AVR_FREQ = 16000000L
-mega1280: LDSECTIONS  = -Wl,--section-start=.text=0x1fc00  -Wl,--section-start=.version=0x1fffe
-mega1280: $(PROGRAM)_atmega1280.hex
-mega1280: $(PROGRAM)_atmega1280.lst
+#Atmega1280
+atmega1280: MCU_TARGET = atmega1280
+atmega1280: CFLAGS += $(COMMON_OPTIONS) -DBIGBOOT $(UART_CMD)
+atmega1280: AVR_FREQ ?= 16000000L
+atmega1280: LDSECTIONS  = -Wl,--section-start=.text=0x1fc00  -Wl,--section-start=.version=0x1fffe
+atmega1280: $(PROGRAM)_atmega1280.hex
+atmega1280: $(PROGRAM)_atmega1280.lst
 
-mega1280_isp: mega1280
-mega1280_isp: TARGET = atmega1280
-mega1280_isp: MCU_TARGET = atmega1280
-# 1024 byte boot
-mega1280_isp: HFUSE = DE
-# Low power xtal (16MHz) 16KCK/14CK+65ms
-mega1280_isp: LFUSE = FF
-# 2.7V brownout
-mega1280_isp: EFUSE = FD
-mega1280_isp: isp
 
 # ATmega8
 #
 atmega8: TARGET = atmega8
 atmega8: MCU_TARGET = atmega8
-atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-atmega8: AVR_FREQ = 16000000L 
+atmega8: CFLAGS += $(COMMON_OPTIONS)
+atmega8: AVR_FREQ ?= 16000000L 
 atmega8: LDSECTIONS  = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
 atmega8: $(PROGRAM)_atmega8.hex
 atmega8: $(PROGRAM)_atmega8.lst
@@ -320,17 +307,17 @@ atmega8_isp: atmega8
 atmega8_isp: TARGET = atmega8
 atmega8_isp: MCU_TARGET = atmega8
 # SPIEN, CKOPT (for full swing xtal), Bootsize=512B
-atmega8_isp: HFUSE = CC
+atmega8_isp: HFUSE ?= CC
 # 2.7V brownout, 16MHz Xtal, 16KCK/14CK+65ms
-atmega8_isp: LFUSE = BF
+atmega8_isp: LFUSE ?= BF
 atmega8_isp: isp
 
 # ATmega88
 #
 atmega88: TARGET = atmega88
 atmega88: MCU_TARGET = atmega88
-atmega88: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-atmega88: AVR_FREQ = 16000000L 
+atmega88: CFLAGS += $(COMMON_OPTIONS)
+atmega88: AVR_FREQ ?= 16000000L 
 atmega88: LDSECTIONS  = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
 atmega88: $(PROGRAM)_atmega88.hex
 atmega88: $(PROGRAM)_atmega88.lst
@@ -339,17 +326,17 @@ atmega88_isp: atmega88
 atmega88_isp: TARGET = atmega88
 atmega88_isp: MCU_TARGET = atmega88
 # 2.7V brownout
-atmega88_isp: HFUSE = DD
+atmega88_isp: HFUSE ?= DD
 # Low power xtal (16MHz) 16KCK/14CK+65ms
-atemga88_isp: LFUSE = FF
+atemga88_isp: LFUSE ?= FF
 # 512 byte boot
-atmega88_isp: EFUSE = 04
+atmega88_isp: EFUSE ?= 04
 atmega88_isp: isp
 
 atmega32: TARGET = atmega32
 atmega32: MCU_TARGET = atmega32
-atmega32: CFLAGS += '-DLED_START_FLASHES=2' '-DBAUD_RATE=115200' '-DLED_DATA_FLASH'
-atmega32: AVR_FREQ = 11059200L
+atmega32: CFLAGS += $(COMMON_OPTIONS)
+atmega32: AVR_FREQ ?= 11059200L
 atmega32: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
 atmega32: $(PROGRAM)_atmega32.hex
 atmega32: $(PROGRAM)_atmega32.lst
@@ -358,84 +345,227 @@ atmega32_isp: atmega32
 atmega32_isp: TARGET = atmega32
 atmega32_isp: MCU_TARGET = atmega32
 # No OCD or JTAG, SPIEN, CKOPT (for full swing xtal), Bootsize=512B
-atmega32_isp: HFUSE = CE
+atmega32_isp: HFUSE ?= CE
 # 2.7V brownout, 16MHz Xtal, 16KCK/14CK+65ms
-atemga32_isp: LFUSE = BF
+atemga32_isp: LFUSE ?= BF
 atmega32_isp: isp
 
+
+
+#---------------------------------------------------------------------------
+# "Board-level Platform" targets.
+# A "Board-level Platform" implies a manufactured platform with a particular
+# AVR_FREQ, LED, and so on.  Parameters are not particularly changable from
+# the "make" command line.
+# Most of the board-level platform builds should envoke make recursively
+#  appropriate specific options
+#---------------------------------------------------------------------------
+# 20MHz clocked platforms
+#
+# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
+#
+
+pro20: TARGET = pro_20mhz
+pro20: CHIP = atmega168
+pro20:
+	$(MAKE) atmega168 AVR_FREQ=20000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+pro20_isp: pro20
+pro20_isp: TARGET = pro_20mhz
+# 2.7V brownout
+pro20_isp: HFUSE ?= DD
+# Full swing xtal (20MHz) 258CK/14CK+4.1ms
+pro20_isp: LFUSE ?= C6
+# 512 byte boot
+pro20_isp: EFUSE ?= 04
+pro20_isp: isp
+
+# 16MHz clocked platforms
+#
+# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
+#
+
+pro16: TARGET = pro_16MHz
+pro16: CHIP = atmega168
+pro16:
+	$(MAKE) $(CHIP) AVR_FREQ=16000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+pro16_isp: pro16
+pro16_isp: TARGET = pro_16MHz
+# 2.7V brownout
+pro16_isp: HFUSE ?= DD
+# Full swing xtal (20MHz) 258CK/14CK+4.1ms
+pro16_isp: LFUSE ?= C6
+# 512 byte boot
+pro16_isp: EFUSE ?= 04
+pro16_isp: isp
+
+diecimila: TARGET = diecimila
+diecimila: CHIP = atmega168
+diecimila:
+	$(MAKE) $(CHIP) AVR_FREQ=16000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+diecimila_isp: diecimila
+diecimila_isp: TARGET = diecimila
+# 2.7V brownout
+diecimila_isp: HFUSE ?= DD
+# Low power xtal (16MHz) 16KCK/14CK+65ms
+diecimila_isp: LFUSE ?= FF
+# 512 byte boot
+diecimila_isp: EFUSE ?= 04
+diecimila_isp: isp
+
+# Sanguino has a minimum boot size of 1024 bytes, so enable extra functions
+#
+sanguino: TARGET = $@
+sanguino: CHIP = atmega644p
+sanguino:
+	$(MAKE) $(CHIP) AVR_FREQ=16000000L LED=B0
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+sanguino_isp: sanguino
+sanguino_isp: TARGET = sanguino
+sanguino_isp: MCU_TARGET = atmega644p
+# 1024 byte boot
+sanguino_isp: HFUSE ?= DE
+# Full swing xtal (16MHz) 16KCK/14CK+65ms
+sanguino_isp: LFUSE ?= F7
+# 2.7V brownout
+sanguino_isp: EFUSE ?= FD
+sanguino_isp: isp
+
+mighty1284: TARGET = $@
+mighty1284: CHIP = atmega1284p
+mighty1284:
+	$(MAKE) $(CHIP) AVR_FREQ=16000000L LED=B7
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+mighty1284_isp: mighty1284
+mighty1284_isp: TARGET = mighty1284
+mighty1284_isp: MCU_TARGET = atmega1284p
+# 1024 byte boot
+mighty1284_isp: HFUSE ?= DE
+# Full swing xtal (16MHz) 16KCK/14CK+65ms
+mighty1284_isp: LFUSE ?= F7
+# 2.7V brownout
+mighty1284_isp: EFUSE ?= FD
+mighty1284_isp: isp
+
+bobuino: TARGET = $@
+bobuino: CHIP = atmega1284p
+bobuino:
+	$(MAKE) $(CHIP) AVR_FREQ=16000000L LED=B5
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
+
+bobuino_isp: bobuino
+bobuino_isp: TARGET = bobuino
+bobuino_isp: MCU_TARGET = atmega1284p
+# 1024 byte boot
+bobuino_isp: HFUSE ?= DE
+# Full swing xtal (16MHz) 16KCK/14CK+65ms
+bobuino_isp: LFUSE ?= F7
+# 2.7V brownout
+bobuino_isp: EFUSE ?= FD
+bobuino_isp: isp
+
+# MEGA1280 Board (this is different from the atmega1280 chip platform)
+# Mega has a minimum boot size of 1024 bytes, so enable extra functions
+# Note that optiboot does not (can not) work on the MEGA2560
+#mega: TARGET = atmega1280
+mega1280: atmega1280
+
+
+mega1280_isp: mega1280
+mega1280_isp: TARGET = atmega1280
+mega1280_isp: MCU_TARGET = atmega1280
+# 1024 byte boot
+mega1280_isp: HFUSE ?= DE
+# Low power xtal (16MHz) 16KCK/14CK+65ms
+mega1280_isp: LFUSE ?= FF
+# 2.7V brownout; wants F5 for some reason...
+mega1280_isp: EFUSE ?= F5
+mega1280_isp: isp
+
 # 8MHz clocked platforms
 #
 # These are capable of 115200 baud
+# Note that "new" Arduinos with an AVR as USB/Serial converter will NOT work
+# with an 8MHz target Arduino.  The bitrate errors are in opposite directions,
+# and total too large a number.
 #
 
-lilypad: TARGET = lilypad
-lilypad: MCU_TARGET = atmega168
-lilypad: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-lilypad: AVR_FREQ = 8000000L
-lilypad: $(PROGRAM)_lilypad.hex
-lilypad: $(PROGRAM)_lilypad.lst
+lilypad: TARGET = $@
+lilypad: CHIP = atmega168
+lilypad:
+	$(MAKE) $(CHIP) AVR_FREQ=8000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
 
 lilypad_isp: lilypad
 lilypad_isp: TARGET = lilypad
 # 2.7V brownout
-lilypad_isp: HFUSE = DD
+lilypad_isp: HFUSE ?= DD
 # Internal 8MHz osc (8MHz) Slow rising power
-lilypad_isp: LFUSE = E2
+lilypad_isp: LFUSE ?= E2
 # 512 byte boot
-lilypad_isp: EFUSE = 04
+lilypad_isp: EFUSE ?= 04
 lilypad_isp: isp
 
-lilypad_resonator: TARGET = lilypad_resonator
-lilypad_resonator: MCU_TARGET = atmega168
-lilypad_resonator: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-lilypad_resonator: AVR_FREQ = 8000000L
-lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
-lilypad_resonator: $(PROGRAM)_lilypad_resonator.lst
+# lilypad_resonator is the same as a 8MHz lilypad, except for fuses.
+lilypad_resonator: lilypad
 
-lilypad_resonator_isp: lilypad_resonator
-lilypad_resonator_isp: TARGET = lilypad_resonator
+lilypad_resonator_isp: lilypad
+lilypad_resonator_isp: TARGET = lilypad
 # 2.7V brownout
-lilypad_resonator_isp: HFUSE = DD
+lilypad_resonator_isp: HFUSE ?= DD
 # Full swing xtal (20MHz) 258CK/14CK+4.1ms
-lilypad_resonator_isp: LFUSE = C6
+lilypad_resonator_isp: LFUSE ?= C6
 # 512 byte boot
-lilypad_resonator_isp: EFUSE = 04
+lilypad_resonator_isp: EFUSE ?= 04
 lilypad_resonator_isp: isp
 
 pro8: TARGET = pro_8MHz
-pro8: MCU_TARGET = atmega168
-pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-pro8: AVR_FREQ = 8000000L
-pro8: $(PROGRAM)_pro_8MHz.hex
-pro8: $(PROGRAM)_pro_8MHz.lst
+pro8: CHIP = atmega168
+pro8:
+	$(MAKE) $(CHIP) AVR_FREQ=8000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
 
 pro8_isp: pro8
 pro8_isp: TARGET = pro_8MHz
 # 2.7V brownout
-pro8_isp: HFUSE = DD
+pro8_isp: HFUSE ?= DD
 # Full swing xtal (20MHz) 258CK/14CK+4.1ms
-pro8_isp: LFUSE = C6
+pro8_isp: LFUSE ?= C6
 # 512 byte boot
-pro8_isp: EFUSE = 04
+pro8_isp: EFUSE ?= 04
 pro8_isp: isp
 
 atmega328_pro8: TARGET = atmega328_pro_8MHz
-atmega328_pro8: MCU_TARGET = atmega328p
-atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
-atmega328_pro8: AVR_FREQ = 8000000L
-atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
-atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
-atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.lst
+atmega328_pro8: CHIP = atmega328
+atmega328_pro8:
+	$(MAKE) $(CHIP) AVR_FREQ=8000000L LED_START_FLASHES=3
+	mv $(PROGRAM)_$(CHIP).hex $(PROGRAM)_$(TARGET).hex
+	mv $(PROGRAM)_$(CHIP).lst $(PROGRAM)_$(TARGET).lst
 
 atmega328_pro8_isp: atmega328_pro8
 atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
 atmega328_pro8_isp: MCU_TARGET = atmega328p
 # 512 byte boot, SPIEN
-atmega328_pro8_isp: HFUSE = DE
+atmega328_pro8_isp: HFUSE ?= DE
 # Low power xtal (16MHz) 16KCK/14CK+65ms
-atmega328_pro8_isp: LFUSE = FF
+atmega328_pro8_isp: LFUSE ?= FF
 # 2.7V brownout
-atmega328_pro8_isp: EFUSE = DE
+atmega328_pro8_isp: EFUSE ?= DE
 atmega328_pro8_isp: isp
 
 # 1MHz clocked platforms
@@ -445,9 +575,9 @@ atmega328_pro8_isp: isp
 
 luminet: TARGET = luminet
 luminet: MCU_TARGET = attiny84
-luminet: CFLAGS += '-DLED_START_FLASHES=3' '-DSOFT_UART' '-DBAUD_RATE=9600'
+luminet: CFLAGS += $(COMMON_OPTIONS) '-DSOFT_UART' '-DBAUD_RATE=9600'
 luminet: CFLAGS += '-DVIRTUAL_BOOT_PARTITION'
-luminet: AVR_FREQ = 1000000L
+luminet: AVR_FREQ ?= 1000000L
 luminet: LDSECTIONS = -Wl,--section-start=.text=0x1d00 -Wl,--section-start=.version=0x1efe
 luminet: $(PROGRAM)_luminet.hex
 luminet: $(PROGRAM)_luminet.lst
@@ -456,28 +586,30 @@ luminet_isp: luminet
 luminet_isp: TARGET = luminet
 luminet_isp: MCU_TARGET = attiny84
 # Brownout disabled
-luminet_isp: HFUSE = DF
+luminet_isp: HFUSE ?= DF
 # 1MHz internal oscillator, slowly rising power
-luminet_isp: LFUSE = 62
+luminet_isp: LFUSE ?= 62
 # Self-programming enable
-luminet_isp: EFUSE = FE
+luminet_isp: EFUSE ?= FE
 luminet_isp: isp
 
+
+#---------------------------------------------------------------------------
 #
 # Generic build instructions
 #
-#
+
+FORCE:
 
 isp: $(TARGET)
-	$(ISPFUSES)
-	$(ISPFLASH)
+	$(MAKE) -f Makefile.isp isp TARGET=$(TARGET)
 
 isp-stk500: $(PROGRAM)_$(TARGET).hex
 	$(STK500-1)
 	$(STK500-2)
 
-%.elf: $(OBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+%.elf: $(OBJ) $(dummy)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
 	$(SIZE) $@
 
 clean:

+ 7 - 7
optiboot/bootloaders/optiboot/makeall

@@ -1,13 +1,7 @@
 #!/bin/bash
 make clean
 #
-# The "big three" standard bootloaders.
-make atmega8
-make atmega168
-make atmega328
-#
-# additional buildable platforms of
-#  somewhat questionable support level
+#  buildable platforms of somewhat questionable support level
 make lilypad
 make lilypad_resonator
 make pro8
@@ -18,3 +12,9 @@ make sanguino
 make mega
 make atmega88
 make luminet
+#
+# The "big three" standard bootloaders.
+# These need to be built AFTER the platforms, or they'll get removed
+make atmega8
+make atmega168
+make atmega328

+ 20 - 1
optiboot/bootloaders/optiboot/optiboot.c

@@ -138,7 +138,9 @@
 /*  repository and was distributed with Arduino 0022.     */
 /* Version 4 starts with the arduino repository commit    */
 /*  that brought the arduino repository up-to-date with   */
-/* the optiboot source tree changes since v3.             */
+/*  the optiboot source tree changes since v3.            */
+/* Version 5 was created at the time of the new Makefile  */
+/*  structure (Mar, 2013), even though no binaries changed*/
 /* It would be good if versions implemented outside the   */
 /*  official repository used an out-of-seqeunce version   */
 /*  number (like 104.6 if based on based on 4.5) to       */
@@ -149,6 +151,14 @@
 /**********************************************************/
 /* Edit History:					  */
 /*							  */
+/* Mar 2013                                               */
+/* 4.6 WestfW: Major Makefile restructuring.              */
+/*             See Makefile and pin_defs.h                */
+/*             (no binary changes)                        */
+/*                                                        */
+/* 4.6 WestfW/Pito: Add ATmega32 support                  */
+/* 4.6 WestfW/radoni: Don't set LED_PIN as an output if   */
+/*                    not used. (LED_START_FLASHES = 0)   */
 /* Jan 2013						  */
 /* 4.6 WestfW/dkinzer: use autoincrement lpm for read     */
 /* 4.6 WestfW/dkinzer: pass reset cause to app in R2      */
@@ -349,18 +359,27 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
 # define UART_SRL UBRR0L
 # define UART_UDR UDR0
 #elif UART == 1
+#if !defined(UDR1)
+#error UART == 1, but no UART1 on device
+#endif
 # define UART_SRA UCSR1A
 # define UART_SRB UCSR1B
 # define UART_SRC UCSR1C
 # define UART_SRL UBRR1L
 # define UART_UDR UDR1
 #elif UART == 2
+#if !defined(UDR2)
+#error UART == 2, but no UART2 on device
+#endif
 # define UART_SRA UCSR2A
 # define UART_SRB UCSR2B
 # define UART_SRC UCSR2C
 # define UART_SRL UBRR2L
 # define UART_UDR UDR2
 #elif UART == 3
+#if !defined(UDR1)
+#error UART == 3, but no UART3 on device
+#endif
 # define UART_SRA UCSR3A
 # define UART_SRB UCSR3B
 # define UART_SRC UCSR3C

+ 676 - 17
optiboot/bootloaders/optiboot/pin_defs.h

@@ -1,9 +1,12 @@
+/*------------------------------------------------------------------------ */
 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
-/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */ 
-#define LED_DDR     DDRB
-#define LED_PORT    PORTB
-#define LED_PIN     PINB
-#define LED         PINB5
+/*------------------------------------------------------------------------ */
+
+/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove
+ */ 
+#if !defined(LED)
+#define LED B5
+#endif
 
 /* Ports for soft UART */
 #ifdef SOFT_UART
@@ -30,12 +33,14 @@
 #endif
 
 /* Luminet support */
+/*------------------------------------------------------------------------ */
 #if defined(__AVR_ATtiny84__)
+/*------------------------------------------------------------------------ */
 /* Red LED is connected to pin PA4 */ 
-#define LED_DDR     DDRA
-#define LED_PORT    PORTA
-#define LED_PIN     PINA
-#define LED         PINA4
+#if !defined(LED)
+#define LED         A4
+#endif
+
 /* Ports for soft UART - left port only for now. TX/RX on PA2/PA3 */
 #ifdef SOFT_UART
 #define UART_PORT   PORTA
@@ -46,13 +51,14 @@
 #endif
 #endif
 
+/*------------------------------------------------------------------------ */
 /* Sanguino support (and other 40pin DIP cpus) */
 #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega32__)
+/*------------------------------------------------------------------------ */
 /* Onboard LED is connected to pin PB0 on Sanguino */ 
-#define LED_DDR     DDRB
-#define LED_PORT    PORTB
-#define LED_PIN     PINB
-#define LED         PINB0
+#if !defined(LED)
+#define LED         B0
+#endif
 
 /* Ports for soft UART */
 #ifdef SOFT_UART
@@ -64,13 +70,14 @@
 #endif
 #endif
 
+/*------------------------------------------------------------------------ */
 /* Mega support */
 #if defined(__AVR_ATmega1280__)
+/*------------------------------------------------------------------------ */
 /* Onboard LED is connected to pin PB7 on Arduino Mega */ 
-#define LED_DDR     DDRB
-#define LED_PORT    PORTB
-#define LED_PIN     PINB
-#define LED         PINB7
+#if !defined(LED)
+#define LED         B7
+#endif
 
 /* Ports for soft UART */
 #ifdef SOFT_UART
@@ -81,3 +88,655 @@
 #define UART_RX_BIT 0
 #endif
 #endif
+
+/*
+ * ------------------------------------------------------------------------
+ * A bunch of macros to enable the LED to be specifed as "B5" for bit 5 
+ * of port B, and similar.
+ */
+
+#define A0 0x100
+#define A1 0x101
+#define A2 0x102
+#define A3 0x103
+#define A4 0x104
+#define A5 0x105
+#define A6 0x106
+#define A7 0x107
+
+#define B0 0x200
+#define B1 0x201
+#define B2 0x202
+#define B3 0x203
+#define B4 0x204
+#define B5 0x205
+#define B6 0x206
+#define B7 0x207
+
+#define C0 0x300
+#define C1 0x301
+#define C2 0x302
+#define C3 0x303
+#define C4 0x304
+#define C5 0x305
+#define C6 0x306
+#define C7 0x307
+
+#define D0 0x400
+#define D1 0x401
+#define D2 0x402
+#define D3 0x403
+#define D4 0x404
+#define D5 0x405
+#define D6 0x406
+#define D7 0x407
+
+#define E0 0x500
+#define E1 0x501
+#define E2 0x502
+#define E3 0x503
+#define E4 0x504
+#define E5 0x505
+#define E6 0x506
+#define E7 0x507
+
+#define F0 0x600
+#define F1 0x601
+#define F2 0x602
+#define F3 0x603
+#define F4 0x604
+#define F5 0x605
+#define F6 0x606
+#define F7 0x607
+
+#define G0 0x700
+#define G1 0x701
+#define G2 0x702
+#define G3 0x703
+#define G4 0x704
+#define G5 0x705
+#define G6 0x706
+#define G7 0x707
+
+#define H0 0x800
+#define H1 0x801
+#define H2 0x802
+#define H3 0x803
+#define H4 0x804
+#define H5 0x805
+#define H6 0x806
+#define H7 0x807
+
+#define J0 0xA00
+#define J1 0xA01
+#define J2 0xA02
+#define J3 0xA03
+#define J4 0xA04
+#define J5 0xA05
+#define J6 0xA06
+#define J7 0xA07
+
+#define K0 0xB00
+#define K1 0xB01
+#define K2 0xB02
+#define K3 0xB03
+#define K4 0xB04
+#define K5 0xB05
+#define K6 0xB06
+#define K7 0xB07
+
+#define L0 0xC00
+#define L1 0xC01
+#define L2 0xC02
+#define L3 0xC03
+#define L4 0xC04
+#define L5 0xC05
+#define L6 0xC06
+#define L7 0xC07
+
+
+
+#if LED == B0
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB0
+#elif LED == B1
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB1
+#elif LED == B2
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB2
+#elif LED == B3
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB3
+#elif LED == B4
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB4
+#elif LED == B5
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB5
+#elif LED == B6
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB6
+#elif LED == B7
+#undef LED
+#define LED_DDR     DDRB
+#define LED_PORT    PORTB
+#define LED_PIN     PINB
+#define LED	    PINB7
+
+#elif LED == C0
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC0
+#elif LED == C1
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC1
+#elif LED == C2
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC2
+#elif LED == C3
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC3
+#elif LED == C4
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC4
+#elif LED == C5
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC5
+#elif LED == C6
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC6
+#elif LED == C7
+#undef LED
+#define LED_DDR     DDRC
+#define LED_PORT    PORTC
+#define LED_PIN     PINC
+#define LED	    PINC7
+
+#elif LED == D0
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND0
+#elif LED == D1
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND1
+#elif LED == D2
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND2
+#elif LED == D3
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND3
+#elif LED == D4
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND4
+#elif LED == D5
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND5
+#elif LED == D6
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND6
+#elif LED == D7
+#undef LED
+#define LED_DDR     DDRD
+#define LED_PORT    PORTD
+#define LED_PIN     PIND
+#define LED	    PIND7
+
+#elif LED == E0
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE0
+#elif LED == E1
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE1
+#elif LED == E2
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE2
+#elif LED == E3
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE3
+#elif LED == E4
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE4
+#elif LED == E5
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE5
+#elif LED == E6
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE6
+#elif LED == E7
+#undef LED
+#define LED_DDR     DDRE
+#define LED_PORT    PORTE
+#define LED_PIN     PINE
+#define LED	    PINE7
+
+#elif LED == F0
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF0
+#elif LED == F1
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF1
+#elif LED == F2
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF2
+#elif LED == F3
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF3
+#elif LED == F4
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF4
+#elif LED == F5
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF5
+#elif LED == F6
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF6
+#elif LED == F7
+#undef LED
+#define LED_DDR     DDRF
+#define LED_PORT    PORTF
+#define LED_PIN     PINF
+#define LED	    PINF7
+
+#elif LED == G0
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING0
+#elif LED == G1
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING1
+#elif LED == G2
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING2
+#elif LED == G3
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING3
+#elif LED == G4
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING4
+#elif LED == G5
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING5
+#elif LED == G6
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING6
+#elif LED == G7
+#undef LED
+#define LED_DDR     DDRG
+#define LED_PORT    PORTG
+#define LED_PIN     PING
+#define LED	    PING7
+
+#elif LED == H0
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH0
+#elif LED == H1
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH1
+#elif LED == H2
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH2
+#elif LED == H3
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH3
+#elif LED == H4
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH4
+#elif LED == H5
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH5
+#elif LED == H6
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH6
+#elif LED == H7
+#undef LED
+#define LED_DDR     DDRH
+#define LED_PORT    PORTH
+#define LED_PIN     PINH
+#define LED	    PINH7
+
+#elif LED == J0
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ0
+#elif LED == J1
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ1
+#elif LED == J2
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ2
+#elif LED == J3
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ3
+#elif LED == J4
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ4
+#elif LED == J5
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ5
+#elif LED == J6
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ6
+#elif LED == J7
+#undef LED
+#define LED_DDR     DDRJ
+#define LED_PORT    PORTJ
+#define LED_PIN     PINJ
+#define LED	    PINJ7
+
+#elif LED == K0
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK0
+#elif LED == K1
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK1
+#elif LED == K2
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK2
+#elif LED == K3
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK3
+#elif LED == K4
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK4
+#elif LED == K5
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK5
+#elif LED == K6
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK6
+#elif LED == K7
+#undef LED
+#define LED_DDR     DDRK
+#define LED_PORT    PORTK
+#define LED_PIN     PINK
+#define LED	    PINK7
+
+#elif LED == L0
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL0
+#elif LED == L1
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL1
+#elif LED == L2
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL2
+#elif LED == L3
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL3
+#elif LED == L4
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL4
+#elif LED == L5
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL5
+#elif LED == L6
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL6
+#elif LED == L7
+#undef LED
+#define LED_DDR     DDRL
+#define LED_PORT    PORTL
+#define LED_PIN     PINL
+#define LED	    PINL7
+
+#elif LED == A0
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA0
+#elif LED == A1
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA1
+#elif LED == A2
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA2
+#elif LED == A3
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA3
+#elif LED == A4
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA4
+#elif LED == A5
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA5
+#elif LED == A6
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA6
+#elif LED == A7
+#undef LED
+#define LED_DDR     DDRA
+#define LED_PORT    PORTA
+#define LED_PIN     PINA
+#define LED	    PINA7
+
+#else
+#error -------------------------------------------
+#error Unrecognized LED name.  Should be like "B5"
+#error -------------------------------------------
+#endif