-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMakefile.vusb
128 lines (101 loc) · 3.66 KB
/
Makefile.vusb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Name: Makefile.vusb
# Project: Kinesis Ergonomic Keyboard Firmware Replacement (v-usb)
# Author: Christian Starkjohann, Chris Andreae
# Creation Date: 2012-08-12
# Tabsize: 4
# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH, 2012 by Chris Andreae
# License: GNU GPL v2 (see GPL2.txt)
# Select hardware variant
HARDWARE_VARIANT ?= KINESIS
HAS_EXTERNAL_STORAGE ?= 1
DEVICE = atmega32
AVRDUDE_DEVICE = atmega32
FUSE_L = 0xFF
FUSE_H = 0xC1
F_CPU = 16000000 # in Hz
AVRDUDE = avrdude -c usbasp -p $(AVRDUDE_DEVICE) # edit this line for your programmer
CFLAGS = -I. -Ivusb -Ivusb/usbdrv -DDEBUG_LEVEL=0 -DHARDWARE_VARIANT=$(HARDWARE_VARIANT) -DBUILD_FOR_VUSB -std=gnu99 -ffunction-sections
CFLAGS += -fshort-enums -fno-strict-aliasing -fpack-struct -funsigned-bitfields -fshort-wchar -fwrapv
ifneq ($(HAS_EXTERNAL_STORAGE),1)
CFLAGS += -DNO_EXTERNAL_STORAGE
endif
OBJDIR = obj
SRCS = vusb/usbdrv/usbdrv.o \
vusb/usbdrv/usbdrvasm.o \
vusb/usbdrv/oddebug.o \
vusb/vusb_main.o \
Keyboard.o \
Descriptors.o \
twi.o \
printing.o \
keystate.o \
config.o \
storage.o \
storage/i2c_eeprom.o \
storage/avr_eeprom.o \
storage/avr_pgm.o \
buzzer.o \
leds.o \
hardware.o \
interpreter.o \
macro_index.o \
macro.o \
extrareport.o \
sort.o
OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SRCS))))
COMPILE = avr-gcc -Wall -Werror=implicit-function-declaration -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
# symbolic targets:
.PHONY: hex help program flash fuse clean
hex: vusb_main.hex
help:
@echo "This Makefile has no default rule. Use one of the following:"
@echo "make hex ....... to build main.hex"
@echo "make program ... to flash fuses and firmware"
@echo "make fuse ...... to flash the fuses"
@echo "make flash ..... to flash the firmware (use this on metaboard)"
@echo "make clean ..... to delete objects and hex file"
program: flash fuse
# rule for programming fuse bits:
fuse:
@[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
{ echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
$(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
# rule for uploading firmware:
flash: vusb_main.hex
$(AVRDUDE) -U flash:w:vusb_main.hex:i
# rule for deleting dependent files (those which can be built by Make):
clean:
rm -rf vusb_main.hex vusb_main.lst vusb_main.obj vusb_main.cof \
vusb_main.list vusb_main.map vusb_main.eep.hex vusb_main.elf \
obj/*
# Ensure output directories exist:
%/.made:
mkdir -p $(dir $@)
touch $@
# Dependencies
DEPS=$(addsuffix .d,$(basename $(OBJECTS)))
-include $(DEPS)
$(OBJECTS): | $(addsuffix .made,$(sort $(dir $(OBJECTS))))
# Generic rule for compiling C files:
$(OBJDIR)/%.o: %.c
$(COMPILE) -c -MMD -MF ${@:.o=.d} -MT $@ -o $@ $<
# Generic rule for assembling Assembler source files:
$(OBJDIR)/%.o: %.S
$(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.
LDFLAGS=-Wl,-Map=$(OBJDIR)/vusb_main.map \
-Wl,--cref \
-Wl,--gc-sections \
-Wl,--section-start=.eeexternal=00850000
vusb_main.elf: $(OBJECTS)
$(COMPILE) -o vusb_main.elf $(LDFLAGS) $(OBJECTS)
vusb_main.hex: vusb_main.elf
rm -f vusb_main.hex vusb_main.eep.hex
avr-objcopy -j .text -j .data -O ihex vusb_main.elf vusb_main.hex
avr-size vusb_main.hex
# debugging targets:
disasm: vusb_main.elf
avr-objdump -d vusb_main.elf