]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/Makefile
Datasheet for lxhl-bd01 high-power red LED
[bike-lights.git] / firmware / Makefile
1
2 PROGRAM=lights
3 SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c ambient.c pattern.c \
4         buttons.c battery.c control.c
5 OBJ=$(SRC:.c=.o)
6
7
8 MCU=attiny861a
9 # AVRDUDE_MCU=$(MCU)
10 AVRDUDE_MCU=attiny861
11 AVRDUDE_PROGRAMMER=usbasp
12
13 CFLAGS=-Wall -Os -mmcu=$(MCU) -DUSE_LOGGING=1 -DF_CPU=1000000UL -std=gnu99
14 LDFLAGS=
15 AVRDUDE_FLAGS= -p$(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
16
17 FORMAT=ihex
18
19 CC=avr-gcc
20 OBJCOPY=avr-objcopy
21 OBJDUMP=avr-objdump
22 AVRDUDE=avrdude
23
24 all: $(PROGRAM).hex $(PROGRAM).eep
25
26 program: $(PROGRAM).hex $(PROGRAM).eep
27         $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i -U eeprom:w:$(PROGRAM).eep:i
28
29 program_flash: $(PROGRAM).hex
30         $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i
31
32 program_eeprom: $(PROGRAM).eep
33         $(AVRDUDE) $(AVRDUDE_FLAGS) eeprom:w:$(PROGRAM).eep:i
34
35 dump_eeprom:
36         $(AVRDUDE) $(AVRDUDE_FLAGS) -U eeprom:r:eeprom.raw:r
37         od -tx1 eeprom.raw
38
39 objdump: $(PROGRAM).elf
40         $(OBJDUMP) --disassemble $<
41
42 .PRECIOUS : $(OBJ) $(PROGRAM).elf
43
44 %.hex: %.elf
45         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
46
47 %.eep: %.elf
48         $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
49                 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
50
51 %.elf: $(OBJ)
52         $(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
53
54 %.o: %.c lights.h Makefile
55         $(CC) -c $(CFLAGS) $< -o $@
56
57 %.s: %.c lights.h Makefile
58         $(CC) -S -c $(CFLAGS) $< -o $@
59
60 %.o: %.S
61         $(CC) -c $(CFLAGS) $< -o $@
62
63 clean:
64         rm -f $(PROGRAM).hex $(PROGRAM).eep $(PROGRAM).elf *.o *.s eeprom.raw
65
66 .PHONY: all clean dump_eeprom program program_flash program_eeprom objdump
67