# Paramètres de compilation
CC = avr-gcc
MCU = atmega32u4
F_CPU = 16000000UL

# Options du compilateur
CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Os

# Fichiers source
SRC = main.c HD44780.c

# Nom de l'exécutable
TARGET = lcd

all: $(TARGET).hex

$(TARGET).hex: $(TARGET).elf
	avr-objcopy -O ihex -R .eeprom $< $@

$(TARGET).elf: $(SRC)
	$(CC) $(CFLAGS) -o $@ $^

dfu: $(TARGET).hex
	dfu-programmer $(MCU) erase
	dfu-programmer $(MCU) flash $(TARGET).hex
	dfu-programmer $(MCU) reset

clean:
	rm -f $(TARGET).elf $(TARGET).hex

.PHONY: all upload clean

