+uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
+
+DEVICE=attiny85
+F_CPU=1000000
+#F_CPU=128000
+ifeq ($(uname_S),Linux)
+#SERIAL:=/dev/ttyACM0
+#AVRDUDE = avrdude -c usbasp -p $(DEVICE) -b 19200
+AVRDUDE = avrdude -c atmelice_isp -p $(DEVICE)
+else
+SERIAL=COM5
+AVRDUDE = avrdude -c avrisp -p $(DEVICE) -P $(SERIAL) -b 19200 \
+ -C/opt/arduino-1.0.3/hardware/tools/avr/etc/avrdude.conf
+endif
+
+INC = -I.
+COMPILE = avr-gcc -Wall -Os $(INC) -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
+
+OBJECTS = main.o
+
+# symbolic targets:
+all: main.hex
+
+.c.o:
+ $(COMPILE) -c $< -o $@
+
+.S.o:
+ @$(COMPILE) -x assembler-with-cpp -c $< -o $@
+# "-x assembler-with-cpp" should not be necessary since this is the default
+# file type for the .S (with capital S) extension. However, upper case
+# characters are not always preserved on Windows. To ensure WinAVR
+# compatibility define the file type manually.
+
+.c.s:
+ @$(COMPILE) -S $< -o $@
+
+flash: all
+ $(AVRDUDE) -U flash:w:main.hex:i
+
+# Fuse high byte:
+# 0xdd = 1 1 0 1 1 1 0 1
+# ^ ^ ^ ^ ^ \-+-/
+# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
+# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
+# | | | +-------------- WDTON (watchdog timer always on -> disable)
+# | | +---------------- SPIEN (enable serial programming -> enabled)
+# | +------------------ DWEN (debug wire enable)
+# +-------------------- RSTDISBL (disable external reset -> enabled)
+#
+# Fuse low byte:
+# 0xe1 = 1 1 1 0 0 0 0 1
+# ^ ^ \+/ \--+--/
+# | | | +------- CKSEL 3..0 (clock selection -> HF PLL)
+# | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
+# | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
+# +-------------------- CKDIV8 (divide clock by 8, 1 means divided)
+# For 16.5MHz internal: -U hfuse:w:0xd5:m -U lfuse:w:0xe1:m
+# For 12MHz crystal: -U hfuse:w:0xdd:m -U lfuse:w:0b11111111:m
+# For 8MHz internal: -U hfuse:w:0xd5:m -U lfuse:w:0xe2:m
+# For 1MHz internal: -U hfuse:w:0xd5:m -U lfuse:w:0x62:m
+# For 128kHz clock : -U hfuse:w:0xdf:m -U lfuse:w:0xe4:m
+# Note: 0xd5 is as per 0xdd but with EESAVE enabled.
+
+fuse:
+ @echo "Programming fuses for 1MHz internal oscillator (BOD disabled)"
+ $(AVRDUDE) -U hfuse:w:0xdf:m -U lfuse:w:0x62:m
+
+readcal:
+ $(AVRDUDE) -U calibration:r:/dev/stdout:i | head -1
+
+eeread:
+ $(AVRDUDE) -U eeprom:r:eeprom:i
+
+eewrite:
+ $(AVRDUDE) -U eeprom:w:eeprom:i
+
+clean:
+ @rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o
+
+# file targets:
+main.bin: $(OBJECTS)
+ $(COMPILE) -o main.bin $(OBJECTS)
+
+main.hex: main.bin
+ @rm -f main.hex
+ @avr-objcopy -j .text -j .data -O ihex main.bin main.hex
+ @$(SHELL) checksize main.bin 8192 256
+# do the checksize script as our last action to allow successful compilation
+# on Windows with WinAVR where the Unix commands will fail.
+
+eeprom: main.eep.hex
+main.eep.hex: main.bin
+ @avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
+ --change-section-lma .eeprom=0 -O ihex main.bin main.eep.hex
+ @echo call configure_eeprom.py to set eeprom values
+
+flash_eeprom:
+ $(AVRDUDE) -U eeprom:w:main.eep.hex:i
+
+disasm: main.bin
+ avr-objdump -d main.bin
+
+cpp:
+ $(COMPILE) -E main.c