simplify makefile

master
Stefan Dorn 2016-06-12 01:55:08 +01:00
parent 070b4b2caa
commit 1b7a4b23fd
4 changed files with 31 additions and 117 deletions

View File

@ -23,10 +23,9 @@
#pragma once
// --------------------------------------------------------------------
#define KB_ROWS 6 // must match real life
#define KB_COLUMNS 14 // must match real life
#define KB_LAYERS 10
#define KB_ROWS 6 // must match real life
#define KB_COLUMNS 14 // must match real life
#define KB_LAYERS 10
// Name ID // PC Mac Unix Boot Keyboard Req.
// --------------------------- ---- -- --- ---- ---------------------

View File

@ -591,6 +591,8 @@ void main_key_loop() {
// send the USB report (even if nothing's changed)
usb_keyboard_send();
usb_extra_consumer_send();
_delay_ms(MAKEFILE_DEBOUNCE_TIME);
// debounce in ms; see keyswitch spec for necessary value
_delay_ms(5);
}
}

View File

@ -1,71 +1,21 @@
# -----------------------------------------------------------------------------
# makefile for the ergoDOX firmware
#
# - .h file dependencies are automatically generated
#
# - This makefile was originally (extensively) modified from the WinAVR
# makefile template, mostly by removing stuff. The copy I used was from
# [pjrc : usb_keyboard] (http://pjrc.com/teensy/usb_keyboard.zip).
# -----------------------------------------------------------------------------
# Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (MIT) (see "license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
CFLAGS := -mmcu=atmega32u4 # processor type (teensy 2.0); must match real life
CFLAGS += -DF_CPU=16000000 # processor frequency; must match initialization in source
CFLAGS += -std=gnu99 # use C99 plus GCC extensions
CFLAGS += -Os # optimize for size
CFLAGS += -Wall # enable lots of common warnings
CFLAGS += -fpack-struct # pack all structure members together without holes
CFLAGS += -fshort-enums # allocate compact enums
CFLAGS += -ffunction-sections # \ place each function or data into its own
CFLAGS += -fdata-sections # / section in the output file
CFLAGS += -pipe # faster build
LDFLAGS += -Wl,--relax # for some linker optimizations
LDFLAGS += -Wl,--gc-sections # discard unused functions and data
include makefile-options
FORMAT := ihex # the program binary's format
MCU := atmega32u4 # processor type (for teensy 2.0); must match real life
BOARD := teensy-2-0 # see the libraries you're using for what's available
F_CPU := 16000000 # processor speed, in Hz
# firmware stuff
SRC := main.c
OBJ := $(SRC:%.c=%.o)
# keyboard and layout stuff
KEYBOARD := $(strip $(KEYBOARD))
LAYOUT := $(strip $(LAYOUT))
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS := -mmcu=$(MCU) # processor type (teensy 2.0); must match real
# life
CFLAGS += -DF_CPU=$(F_CPU) # processor frequency; must match initialization
# in source
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -DMAKEFILE_BOARD='$(strip $(BOARD))'
CFLAGS += -DMAKEFILE_KEYBOARD='$(strip $(KEYBOARD))'
CFLAGS += -DMAKEFILE_KEYBOARD_LAYOUT='$(strip $(LAYOUT))'
CFLAGS += -DMAKEFILE_DEBOUNCE_TIME='$(strip $(DEBOUNCE_TIME))'
CFLAGS += -DMAKEFILE_LED_BRIGHTNESS='$(strip $(LED_BRIGHTNESS))'
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -std=gnu99 # use C99 plus GCC extensions
CFLAGS += -Os # optimize for size
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -Wall # enable lots of common warnings
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -fpack-struct # "pack all structure members together without holes"
CFLAGS += -fshort-enums # "allocate to an 'enum' type only as many bytes as it
# needs for the declared range of possible values"
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -ffunction-sections # \ "place each function or data into its own
CFLAGS += -fdata-sections # / section in the output file if the
# target supports arbitrary sections." for
# linker optimizations, and discarding
# unused code.
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LDFLAGS := -Wl,-Map=$(strip $(TARGET)).map,--cref # generate a link map, with
# a cross reference table
LDFLAGS += -Wl,--relax # for some linker optimizations
LDFLAGS += -Wl,--gc-sections # discard unused functions and data
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
GENDEPFLAGS += -MMD -MP -MF $@.dep # generate dependency files
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SRC := main.c
CC := avr-gcc
OBJCOPY := avr-objcopy
@ -73,27 +23,23 @@ SIZE := avr-size
CHKSUM := md5sum
MAKEHEADERS := makeheaders
# remove whitespace from some of the options
FORMAT := $(strip $(FORMAT))
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
.PHONY: all clean
all: $(TARGET).hex $(TARGET).eep
all: firmware.hex firmware.eep
@echo
@echo '---------------------------------------------------------------'
@echo '------- done --------------------------------------------------'
@echo
$(SIZE) --target=$(FORMAT) $(TARGET).hex
$(SIZE) --target=ihex firmware.hex
@echo
$(SIZE) --target=$(FORMAT) $(TARGET).eep
$(SIZE) --target=ihex firmware.eep
@echo
$(CHKSUM) $(TARGET).hex $(TARGET).eep
$(CHKSUM) firmware.hex firmware.eep
@echo
@echo 'you can load "$(TARGET).hex" and "$(TARGET).eep" onto the'
@echo 'you can load "firmware.hex" and "firmware.eep" onto the'
@echo 'Teensy using the Teensy loader'
@echo
@echo '---------------------------------------------------------------'
@ -108,36 +54,27 @@ clean:
.SECONDARY:
%.hex: %.elf
firmware.hex: firmware.elf
@echo
@echo --- making $@ ---
# from the WinAVR makefile template (modified)
$(OBJCOPY) -O $(FORMAT) \
$(OBJCOPY) -O ihex \
-R .eeprom -R .fuse -R .lock -R .signature \
$< $@
%.eep: %.elf
firmware.eep: firmware.elf
@echo
@echo --- making $@ ---
# from the WinAVR makefile template (modified)
-$(OBJCOPY) -O $(FORMAT) \
-$(OBJCOPY) -O ihex \
-j .eeprom \
--set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 \
--no-change-warnings \
$< $@ || exit 0
%.elf: $(OBJ)
firmware.elf:
@echo
@echo --- making $@ ---
$(CC) $(strip $(CFLAGS)) $(strip $(LDFLAGS)) $^ --output $@
%.o: %.c
@echo
@echo --- making $@ ---
$(MAKEHEADERS) $<
$(CC) -c $(strip $(CFLAGS)) $(strip $(GENDEPFLAGS)) $< -o $@
# -----------------------------------------------------------------------------
-include $(OBJ:%=%.dep)
$(MAKEHEADERS) $(SRC)
$(CC) $(strip $(CFLAGS)) $(strip $(LDFLAGS)) $(SRC) --output $@

View File

@ -1,24 +0,0 @@
# -----------------------------------------------------------------------------
# certain compilations options
# -----------------------------------------------------------------------------
# Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (MIT) (see "license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
TARGET := firmware # the name we want for our program binary
KEYBOARD := ergodox # keyboard model; see "src/keyboard" for what's available
LAYOUT := saneo-mod # keyboard layout
# see "src/keyboard/*/layout" for what's
# available
DEBOUNCE_TIME := 5 # in ms; see keyswitch spec for necessary value; 5ms should
# be good for cherry mx switches
# remove whitespace
TARGET := $(strip $(TARGET))
KEYBOARD := $(strip $(KEYBOARD))
LAYOUT := $(strip $(LAYOUT))
DEBOUNCE_TIME := $(strip $(DEBOUNCE_TIME))