simple button-only gamepad project where a Pro Mini is built into the gamepad case and sends keys over UART

Makefile 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #############################################
  2. # CPU type
  3. MCU = atmega328p
  4. # CPU frequency [Hz]
  5. F_CPU = 16000000
  6. # Fuses (refer to datasheet)
  7. LFUSE = 0xFF
  8. HFUSE = 0xDE
  9. EFUSE = 0x05
  10. # AVRDUDE settings
  11. PROG_BAUD = 57600
  12. PROG_DEV = /dev/ttyUSB0
  13. PROG_TYPE = arduino
  14. # Build the final AVRDUDE arguments
  15. PROG_ARGS = -c $(PROG_TYPE) -p $(MCU) -b $(PROG_BAUD) -P $(PROG_DEV)
  16. #############################################
  17. # Main file
  18. BINARY = main
  19. # Obj files to be built <- add .o for any .c files you add!
  20. OBJS = $(BINARY).o
  21. OBJS += lib/usart.o
  22. OBJS += lib/iopins.o
  23. OBJS += lib/spi.o
  24. OBJS += lib/debounce.o
  25. # Dirs with header files
  26. INCL_DIRS = . lib/
  27. # Pre-defined macros
  28. DEFS = -DF_CPU=$(F_CPU)UL
  29. #############################################
  30. # C flags
  31. CFLAGS = -std=gnu99 -mmcu=$(MCU) $(DEFS) $(INCL_DIRS:%=-I%)
  32. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding
  33. CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment
  34. CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
  35. CFLAGS += -ffunction-sections -fdata-sections -Os
  36. LDFLAGS = -Wl,--gc-sections -Wl,--relax -lm
  37. #LD_FLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
  38. #LD_FLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
  39. #############################################
  40. ## Defined programs / locations
  41. CC = avr-gcc
  42. OBJCOPY = avr-objcopy
  43. OBJDUMP = avr-objdump
  44. AVRSIZE = avr-size
  45. AVRDUDE = avrdude
  46. JUNK = *.o *.d *.elf *.bin *.hex *.srec *.list *.lst *.map *.dis *.disasm *.eep *.eeprom *.lss
  47. .SUFFIXES: .elf .bin .hex .lst .map .eeprom .pre
  48. .SECONDEXPANSION:
  49. .SECONDARY:
  50. .PHONY: all elf bin hex lst pre ee eeprom dis size clean flash flashe shell fuses show_fuses set_default_fuses
  51. all: hex size
  52. elf: $(BINARY).elf
  53. bin: $(BINARY).bin
  54. hex: $(BINARY).hex
  55. lst: $(BINARY).lst
  56. pre: $(BINARY).pre
  57. ee: $(BINARY).eeprom
  58. eeprom: $(BINARY).eeprom
  59. dis: lst
  60. # Show how big the resulting program is
  61. size: elf
  62. $(AVRSIZE) -C --mcu=$(MCU) $(BINARY).elf
  63. # --- Magic build targets ----------------
  64. %.hex: %.elf
  65. $(OBJCOPY) -R .eeprom -O ihex $< $@
  66. %.elf %.map: $(OBJS)
  67. $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(*).elf
  68. %.pre: %.c
  69. $(CC) $(CFLAGS) -E $(*).c --output $@
  70. %.eeprom: %.elf
  71. $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
  72. %.lst: %.elf
  73. $(Q)$(OBJDUMP) -S $(*).elf > $(*).lst
  74. %.o: %.c
  75. $(CC) $(CFLAGS) -o $(*).o -c $(*).c
  76. %.o: %.s
  77. $(CC) $(CFLAGS) -o $(*).o -c $(*).s
  78. # Clean all produced trash
  79. clean:
  80. rm -f $(JUNK)
  81. cd lib && rm -f $(JUNK)
  82. ## === avrdude ===
  83. flash: $(BINARY).hex
  84. $(AVRDUDE) $(PROG_ARGS) -U flash:w:$<
  85. flashe: $(BINARY).eeprom
  86. $(AVRDUDE) $(PROG_ARGS) -U eeprom:w:$<
  87. shell:
  88. $(AVRDUDE) $(PROG_ARGS) -nt
  89. # === fuses ===
  90. # this may not work with the arduino programmer, I haven't tried.
  91. FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  92. fuses:
  93. $(AVRDUDE) $(PROG_ARGS) $(FUSE_STRING)
  94. show_fuses:
  95. $(AVRDUDE) $(PROG_ARGS) -nv