diff options
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/protocol.mk | 5 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/arm_atsam_protocol.h | 1 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/md_bootloader.h | 24 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/startup.c | 6 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udc.c | 5 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/chibios.c | 3 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 31 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 103 | ||||
-rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 2 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 1 | ||||
-rw-r--r-- | tmk_core/rules.mk | 524 |
11 files changed, 67 insertions, 638 deletions
diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index 31a6de76f1..19fd7d2425 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -28,6 +28,11 @@ ifeq ($(strip $(EXTRAKEY_ENABLE)), yes) SHARED_EP_ENABLE = yes endif +ifeq ($(strip $(PROGRAMMABLE_BUTTON_ENABLE)), yes) + TMK_COMMON_DEFS += -DPROGRAMMABLE_BUTTON_ENABLE + SHARED_EP_ENABLE = yes +endif + ifeq ($(strip $(RAW_ENABLE)), yes) TMK_COMMON_DEFS += -DRAW_ENABLE endif diff --git a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h index e1749f872d..319ff8487d 100644 --- a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h +++ b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h @@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define _ARM_ATSAM_PROTOCOL_H_ #include "samd51j18a.h" -#include "md_bootloader.h" #include "timer.h" #include "d51_util.h" diff --git a/tmk_core/protocol/arm_atsam/md_bootloader.h b/tmk_core/protocol/arm_atsam/md_bootloader.h deleted file mode 100644 index 362b9bd52a..0000000000 --- a/tmk_core/protocol/arm_atsam/md_bootloader.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _MD_BOOTLOADER_H_ -#define _MD_BOOTLOADER_H_ - -extern uint32_t _srom; -extern uint32_t _lrom; -extern uint32_t _erom; - -#define BOOTLOADER_SERIAL_MAX_SIZE 20 // DO NOT MODIFY! - -#ifdef KEYBOARD_massdrop_ctrl -// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support -extern uint32_t _eram; -# define BOOTLOADER_MAGIC 0x3B9ACA00 -# define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4) -#endif - -#ifdef MD_BOOTLOADER - -# define MCU_HZ 48000000 -# define I2C_HZ 0 // Not used - -#endif // MD_BOOTLOADER - -#endif //_MD_BOOTLOADER_H_ diff --git a/tmk_core/protocol/arm_atsam/startup.c b/tmk_core/protocol/arm_atsam/startup.c index 7a5791ab55..ce043bad51 100644 --- a/tmk_core/protocol/arm_atsam/startup.c +++ b/tmk_core/protocol/arm_atsam/startup.c @@ -28,7 +28,6 @@ */ #include "samd51.h" -#include "md_bootloader.h" /* Initialize segments */ extern uint32_t _sfixed; @@ -496,6 +495,11 @@ __attribute__((section(".vectors"))) const DeviceVectors exception_table = { #endif }; +// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support +extern uint32_t _eram; +#define BOOTLOADER_MAGIC 0x3B9ACA00 +#define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4) + /** * \brief This is the code that gets called on processor reset. * To initialize the device, and call the main() routine. diff --git a/tmk_core/protocol/arm_atsam/usb/udc.c b/tmk_core/protocol/arm_atsam/usb/udc.c index d04e9b7b28..1f0c0d95d6 100644 --- a/tmk_core/protocol/arm_atsam/usb/udc.c +++ b/tmk_core/protocol/arm_atsam/usb/udc.c @@ -51,7 +51,8 @@ #include "udi_device_conf.h" #include "udi.h" #include "udc.h" -#include "md_bootloader.h" + +#define BOOTLOADER_SERIAL_MAX_SIZE 20 // DO NOT MODIFY! /** * \ingroup udc_group @@ -122,6 +123,8 @@ static uint8_t udc_string_product_name[] = USB_DEVICE_PRODUCT_NAME; # define USB_DEVICE_SERIAL_NAME_SIZE 0 #endif +extern uint32_t _srom; + uint8_t usb_device_serial_name_size = 0; #if defined USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL uint8_t bootloader_serial_number[BOOTLOADER_SERIAL_MAX_SIZE + 1] = ""; diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index 41752b2130..b6cff05e9f 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c @@ -60,10 +60,11 @@ void send_keyboard(report_keyboard_t *report); void send_mouse(report_mouse_t *report); void send_system(uint16_t data); void send_consumer(uint16_t data); +void send_programmable_button(uint32_t data); void send_digitizer(report_digitizer_t *report); /* host struct */ -host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; +host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; #ifdef VIRTSER_ENABLE void virtser_task(void); diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index ac46a9312b..30bfac9f3e 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -734,7 +734,7 @@ void init_usb_driver(USBDriver *usbp) { * after a reset. */ usbDisconnectBus(usbp); - wait_ms(1500); + wait_ms(50); usbStart(usbp, &usbcfg); usbConnectBus(usbp); @@ -975,6 +975,35 @@ void send_consumer(uint16_t data) { #endif } +void send_programmable_button(uint32_t data) { +#ifdef PROGRAMMABLE_BUTTON_ENABLE + osalSysLock(); + if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) { + osalSysUnlock(); + return; + } + + if (usbGetTransmitStatusI(&USB_DRIVER, SHARED_IN_EPNUM)) { + /* Need to either suspend, or loop and call unlock/lock during + * every iteration - otherwise the system will remain locked, + * no interrupts served, so USB not going through as well. + * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */ + if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[SHARED_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) { + osalSysUnlock(); + return; + } + } + static report_programmable_button_t report = { + .report_id = REPORT_ID_PROGRAMMABLE_BUTTON, + }; + + report.usage = data; + + usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report)); + osalSysUnlock(); +#endif +} + void send_digitizer(report_digitizer_t *report) { #ifdef DIGITIZER_ENABLE # ifdef DIGITIZER_SHARED_EP diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index e3be96d93d..3943f8c92b 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -67,10 +67,10 @@ extern keymap_config_t keymap_config; #ifdef BLUETOOTH_ENABLE # include "outputselect.h" -# ifdef MODULE_ADAFRUIT_BLE -# include "adafruit_ble.h" -# else -# include "../serial.h" +# ifdef BLUETOOTH_BLUEFRUIT_LE +# include "bluefruit_le.h" +# elif BLUETOOTH_RN42 +# include "rn42.h" # endif #endif @@ -90,46 +90,6 @@ extern keymap_config_t keymap_config; # include "joystick.h" #endif -// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734 -static inline uint16_t CONSUMER2RN42(uint16_t usage) { - switch (usage) { - case AC_HOME: - return 0x0001; - case AL_EMAIL: - return 0x0002; - case AC_SEARCH: - return 0x0004; - case AL_KEYBOARD_LAYOUT: - return 0x0008; - case AUDIO_VOL_UP: - return 0x0010; - case AUDIO_VOL_DOWN: - return 0x0020; - case AUDIO_MUTE: - return 0x0040; - case TRANSPORT_PLAY_PAUSE: - return 0x0080; - case TRANSPORT_NEXT_TRACK: - return 0x0100; - case TRANSPORT_PREV_TRACK: - return 0x0200; - case TRANSPORT_STOP: - return 0x0400; - case TRANSPORT_EJECT: - return 0x0800; - case TRANSPORT_FAST_FORWARD: - return 0x1000; - case TRANSPORT_REWIND: - return 0x2000; - case TRANSPORT_STOP_EJECT: - return 0x4000; - case AL_LOCAL_BROWSER: - return 0x8000; - default: - return 0; - } -} - uint8_t keyboard_idle = 0; /* 0: Boot Protocol, 1: Report Protocol(default) */ uint8_t keyboard_protocol = 1; @@ -685,17 +645,10 @@ static void send_keyboard(report_keyboard_t *report) { #ifdef BLUETOOTH_ENABLE if (where_to_send() == OUTPUT_BLUETOOTH) { -# ifdef MODULE_ADAFRUIT_BLE - adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); -# elif MODULE_RN42 - serial_send(0xFD); - serial_send(0x09); - serial_send(0x01); - serial_send(report->mods); - serial_send(report->reserved); - for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { - serial_send(report->keys[i]); - } +# ifdef BLUETOOTH_BLUEFRUIT_LE + bluefruit_le_send_keys(report->mods, report->keys, sizeof(report->keys)); +# elif BLUETOOTH_RN42 + rn42_send_keyboard(report); # endif return; } @@ -738,19 +691,11 @@ static void send_mouse(report_mouse_t *report) { # ifdef BLUETOOTH_ENABLE if (where_to_send() == OUTPUT_BLUETOOTH) { -# ifdef MODULE_ADAFRUIT_BLE +# ifdef BLUETOOTH_BLUEFRUIT_LE // FIXME: mouse buttons - adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); -# else - serial_send(0xFD); - serial_send(0x00); - serial_send(0x03); - serial_send(report->buttons); - serial_send(report->x); - serial_send(report->y); - serial_send(report->v); // should try sending the wheel v here - serial_send(report->h); // should try sending the wheel h here - serial_send(0x00); + bluefruit_le_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); +# elif BLUETOOTH_RN42 + rn42_send_mouse(report); # endif return; } @@ -818,18 +763,10 @@ static void send_consumer(uint16_t data) { #ifdef EXTRAKEY_ENABLE # ifdef BLUETOOTH_ENABLE if (where_to_send() == OUTPUT_BLUETOOTH) { -# ifdef MODULE_ADAFRUIT_BLE - adafruit_ble_send_consumer_key(data); -# elif MODULE_RN42 - static uint16_t last_data = 0; - if (data == last_data) return; - last_data = data; - uint16_t bitmap = CONSUMER2RN42(data); - serial_send(0xFD); - serial_send(0x03); - serial_send(0x03); - serial_send(bitmap & 0xFF); - serial_send((bitmap >> 8) & 0xFF); +# ifdef BLUETOOTH_BLUEFRUIT_LE + bluefruit_le_send_consumer_key(data); +# elif BLUETOOTH_RN42 + rn42_send_consumer(data); # endif return; } @@ -1076,8 +1013,8 @@ void protocol_pre_init(void) { setup_usb(); sei(); -#if defined(MODULE_RN42) - serial_init(); +#if defined(BLUETOOTH_RN42) + rn42_init(); #endif /* wait for USB startup & debug output */ @@ -1129,8 +1066,8 @@ void protocol_post_task(void) { MIDI_Device_USBTask(&USB_MIDI_Interface); #endif -#ifdef MODULE_ADAFRUIT_BLE - adafruit_ble_task(); +#ifdef BLUETOOTH_BLUEFRUIT_LE + bluefruit_le_task(); #endif #ifdef VIRTSER_ENABLE diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index a43755f899..0b992ba6c5 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -450,7 +450,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { #endif #ifndef USB_POLLING_INTERVAL_MS -# define USB_POLLING_INTERVAL_MS 10 +# define USB_POLLING_INTERVAL_MS 1 #endif /* diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index bd0f1c21aa..8bdcccc9c9 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -647,7 +647,6 @@ const PROGMEM uchar console_hid_report[] = { # define USB_MAX_POWER_CONSUMPTION 500 #endif -// TODO: change this to 10ms to match LUFA #ifndef USB_POLLING_INTERVAL_MS # define USB_POLLING_INTERVAL_MS 1 #endif diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk deleted file mode 100644 index 6767a8e4af..0000000000 --- a/tmk_core/rules.mk +++ /dev/null @@ -1,524 +0,0 @@ -# Hey Emacs, this is a -*- makefile -*- -#---------------------------------------------------------------------------- -# WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al. -# -# Released to the Public Domain -# -# Additional material for this makefile was written by: -# Peter Fleury -# Tim Henigan -# Colin O'Flynn -# Reiner Patommel -# Markus Pfaff -# Sander Pool -# Frederik Rouleau -# Carlos Lamas -# - -# Enable vpath seraching for source files only -# Without this, output files, could be read from the wrong .build directories -VPATH_SRC := $(VPATH) -vpath %.c $(VPATH_SRC) -vpath %.h $(VPATH_SRC) -vpath %.cpp $(VPATH_SRC) -vpath %.cc $(VPATH_SRC) -vpath %.hpp $(VPATH_SRC) -vpath %.S $(VPATH_SRC) -VPATH := - -# Convert all SRC to OBJ -define OBJ_FROM_SRC -$(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$(patsubst %.clib,$1/%.a,$($1_SRC)))))) -endef -$(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT)))) - -# Define a list of all objects -OBJ := $(foreach OUTPUT,$(OUTPUTS),$($(OUTPUT)_OBJ)) -NO_LTO_OBJ := $(filter %.a,$(OBJ)) - -MASTER_OUTPUT := $(firstword $(OUTPUTS)) - - - -# Output format. (can be srec, ihex, binary) -FORMAT = ihex - -# Optimization level, can be [0, 1, 2, 3, s]. -# 0 = turn off optimization. s = optimize for size. -# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) -OPT ?= s - -# Compiler flag to set the C Standard level. -# c89 = "ANSI" C -# gnu89 = c89 plus GCC extensions -# c99 = ISO C99 standard (not yet fully implemented) -# gnu99 = c99 plus GCC extensions -CSTANDARD = -std=gnu99 - - -# Place -D or -U options here for C sources -#CDEFS += - - -# Place -D or -U options here for ASM sources -#ADEFS += - - -# Place -D or -U options here for C++ sources -#CXXDEFS += -D__STDC_LIMIT_MACROS -#CXXDEFS += -D__STDC_CONSTANT_MACROS -#CXXDEFS += - -# Speed up recompilations by opt-in usage of ccache -USE_CCACHE ?= no -ifneq ($(USE_CCACHE),no) - CC_PREFIX ?= ccache -endif - -#---------------- Compiler Options C ---------------- -# -g*: generate debugging information -# -O*: optimization level -# -f...: tuning, see GCC manual and avr-libc documentation -# -Wall...: warning level -# -Wa,...: tell GCC to pass this to the assembler. -ifeq ($(strip $(LTO_ENABLE)), yes) - ifeq ($(PLATFORM),CHIBIOS) - $(info Enabling LTO on ChibiOS-targeting boards is known to have a high likelihood of failure.) - $(info If unsure, set LTO_ENABLE = no.) - endif - CDEFS += -flto - CDEFS += -DLTO_ENABLE -endif - -DEBUG_ENABLE ?= yes -ifeq ($(strip $(SKIP_DEBUG_INFO)),yes) - DEBUG_ENABLE=no -endif - -ifeq ($(strip $(DEBUG_ENABLE)),yes) - CFLAGS += -g$(DEBUG) -endif -CFLAGS += $(CDEFS) -CFLAGS += -O$(OPT) -# add color -ifeq ($(COLOR),true) -ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "") - CFLAGS+= -fdiagnostics-color -endif -endif -CFLAGS += -Wall -CFLAGS += -Wstrict-prototypes -ifneq ($(strip $(ALLOW_WARNINGS)), yes) - CFLAGS += -Werror -endif -#CFLAGS += -mshort-calls -#CFLAGS += -fno-unit-at-a-time -#CFLAGS += -Wundef -#CFLAGS += -Wunreachable-code -#CFLAGS += -Wsign-compare -CFLAGS += $(CSTANDARD) - -# This fixes lots of keyboards linking errors but SHOULDN'T BE A FINAL SOLUTION -# Fixing of multiple variable definitions must be made. -CFLAGS += -fcommon - -#---------------- Compiler Options C++ ---------------- -# -g*: generate debugging information -# -O*: optimization level -# -f...: tuning, see GCC manual and avr-libc documentation -# -Wall...: warning level -# -Wa,...: tell GCC to pass this to the assembler. -ifeq ($(strip $(DEBUG_ENABLE)),yes) - CXXFLAGS += -g$(DEBUG) -endif -CXXFLAGS += $(CXXDEFS) -CXXFLAGS += -O$(OPT) -# to supress "warning: only initialized variables can be placed into program memory area" -CXXFLAGS += -w -CXXFLAGS += -Wall -CXXFLAGS += -Wundef - -ifneq ($(strip $(ALLOW_WARNINGS)), yes) - CXXFLAGS += -Werror -endif -#CXXFLAGS += -mshort-calls -#CXXFLAGS += -fno-unit-at-a-time -#CXXFLAGS += -Wstrict-prototypes -#CXXFLAGS += -Wunreachable-code -#CXXFLAGS += -Wsign-compare -#CXXFLAGS += $(CSTANDARD) - -#---------------- Assembler Options ---------------- -ASFLAGS += $(ADEFS) -ifeq ($(VERBOSE_AS_CMD),yes) - ASFLAGS += -v -endif - -#---------------- Library Options ---------------- -# Minimalistic printf version -PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min - -# Floating point printf version (requires MATH_LIB = -lm below) -PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt - -# If this is left blank, then it will use the Standard printf version. -PRINTF_LIB = -#PRINTF_LIB = $(PRINTF_LIB_MIN) -#PRINTF_LIB = $(PRINTF_LIB_FLOAT) - - -# Minimalistic scanf version -SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min - -# Floating point + %[ scanf version (requires MATH_LIB = -lm below) -SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt - -# If this is left blank, then it will use the Standard scanf version. -SCANF_LIB = -#SCANF_LIB = $(SCANF_LIB_MIN) -#SCANF_LIB = $(SCANF_LIB_FLOAT) - - -MATH_LIB = -lm -CREATE_MAP ?= yes - - -#---------------- Linker Options ---------------- -# -Wl,...: tell GCC to pass this to linker. -# -Map: create map file -# --cref: add cross reference to map file -# -# Comennt out "--relax" option to avoid a error such: -# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' -# - -ifeq ($(CREATE_MAP),yes) - LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -endif -ifeq ($(VERBOSE_LD_CMD),yes) - LDFLAGS += -v -endif -#LDFLAGS += -Wl,--relax -LDFLAGS += $(EXTMEMOPTS) -LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) -LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) -#LDFLAGS += -T linker_script.x -# You can give EXTRALDFLAGS at 'make' command line. -LDFLAGS += $(EXTRALDFLAGS) - -#---------------- Assembler Listings ---------------- -# -Wa,...: tell GCC to pass this to the assembler. -# -adhlns: create listing -# -gstabs: have the assembler create line number information; note that -# for use in COFF files, additional information about filenames -# and function names needs to be present in the assembler source -# files -- see avr-libc docs [FIXME: not yet described there] -# -listing-cont-lines: Sets the maximum number of continuation lines of hex -# dump that will be displayed for a given single line of source input. - -ADHLNS_ENABLE ?= no -ifeq ($(ADHLNS_ENABLE),yes) - # Avoid "Options to '-Xassembler' do not match" - only specify assembler options at LTO link time - ifeq ($(strip $(LTO_ENABLE)), yes) - LDFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(TARGET).lst - else - CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) - CXXFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) - ifeq ($(strip $(DEBUG_ENABLE)),yes) - ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 - else - ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),--listing-cont-lines=100 - endif - endif -endif - -# Define programs and commands. -SHELL = sh -REMOVE = rm -f -REMOVEDIR = rmdir -COPY = cp -WINSHELL = cmd -SECHO = $(SILENT) || echo -MD5SUM ?= md5sum -ifneq ($(filter Darwin FreeBSD,$(shell uname -s)),) - MD5SUM = md5 -endif - -# UF2 format settings -# To produce a UF2 file in your build, add to your keyboard's rules.mk: -# FIRMWARE_FORMAT = uf2 -UF2CONV = $(TOP_DIR)/util/uf2conv.py -UF2_FAMILY ?= 0x0 - -# Compiler flags to generate dependency files. -#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d -GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@) - - -# Combine all necessary flags and optional flags. -# Add target processor to flags. -# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar -ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS) -ALL_CXXFLAGS = $(MCUFLAGS) -x c++ $(CXXFLAGS) $(EXTRAFLAGS) -ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) - -define NO_LTO -$(patsubst %.a,%.o,$1): NOLTO_CFLAGS += -fno-lto -endef -$(foreach LOBJ, $(NO_LTO_OBJ), $(eval $(call NO_LTO,$(LOBJ)))) - -MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) - -# For a ChibiOS build, ensure that the board files have the hook overrides injected -define BOARDSRC_INJECT_HOOKS -$(KEYBOARD_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): INIT_HOOK_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h -endef -$(foreach LOBJ, $(BOARDSRC), $(eval $(call BOARDSRC_INJECT_HOOKS,$(LOBJ)))) - -# Add QMK specific flags -DFU_SUFFIX ?= dfu-suffix -DFU_SUFFIX_ARGS ?= - - -elf: $(BUILD_DIR)/$(TARGET).elf -hex: $(BUILD_DIR)/$(TARGET).hex -uf2: $(BUILD_DIR)/$(TARGET).uf2 -cpfirmware: $(FIRMWARE_FORMAT) - $(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to qmk_firmware folder" | $(AWK_CMD) - $(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK) -eep: $(BUILD_DIR)/$(TARGET).eep -lss: $(BUILD_DIR)/$(TARGET).lss -sym: $(BUILD_DIR)/$(TARGET).sym -LIBNAME=lib$(TARGET).a -lib: $(LIBNAME) - -# Display size of file. -HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex -#ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf -ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf - -sizebefore: - @if test -f $(BUILD_DIR)/$(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \ - 2>/dev/null; $(SECHO); fi - -sizeafter: $(BUILD_DIR)/$(TARGET).hex - @if test -f $(BUILD_DIR)/$(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \ - 2>/dev/null; $(SECHO); fi - -# Display compiler version information. -gccversion : - @$(SILENT) || $(CC) --version - -# Create final output files (.hex, .eep) from ELF output file. -%.hex: %.elf - $(eval CMD=$(HEX) $< $@) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD) - @$(BUILD_CMD) - -%.uf2: %.hex - $(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex -o $(BUILD_DIR)/$(TARGET).uf2 -c -f $(UF2_FAMILY) >/dev/null 2>&1) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD) - @$(BUILD_CMD) - -%.eep: %.elf - $(eval CMD=$(EEP) $< $@ || exit 0) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD) - @$(BUILD_CMD) - -# Create extended listing file from ELF output file. -%.lss: %.elf - $(eval CMD=$(OBJDUMP) -h -S -z $< > $@) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD) - @$(BUILD_CMD) - -# Create a symbol table from ELF output file. -%.sym: %.elf - $(eval CMD=$(NM) -n $< > $@ ) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD) - @$(BUILD_CMD) - -%.bin: %.elf - $(eval CMD=$(BIN) $< $@ || exit 0) - #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" - @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD) - @$(BUILD_CMD) - if [ ! -z "$(DFU_SUFFIX_ARGS)" ]; then \ - $(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null ;\ - fi - #$(SILENT) || printf "$(MSG_EXECUTING) '$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null':\n" ;\ - $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin; - -BEGIN = gccversion sizebefore - -# Link: create ELF output file from object files. -.SECONDARY : $(BUILD_DIR)/$(TARGET).elf -.PRECIOUS : $(OBJ) -# Note the obj.txt depeendency is there to force linking if a source file is deleted -%.elf: $(OBJ) $(MASTER_OUTPUT)/cflags.txt $(MASTER_OUTPUT)/ldflags.txt $(MASTER_OUTPUT)/obj.txt | $(BEGIN) - @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=MAKE=$(MAKE) $(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) - @$(BUILD_CMD) - - -define GEN_OBJRULE -$1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC)) -ifdef $1_CONFIG -$1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) -endif -$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) -$1_CXXFLAGS = $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) -$1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) - -# Compile: create object files from C source files. -$1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) - @mkdir -p $$(@D) - @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) - $$(eval CC_EXEC := $$(CC)) - ifneq ($$(VERBOSE_C_CMD),) - $$(if $$(filter $$(notdir $$(VERBOSE_C_CMD)),$$(notdir $$<)),$$(eval CC_EXEC += -v)) - endif - ifneq ($$(VERBOSE_C_INCLUDE),) - $$(if $$(filter $$(notdir $$(VERBOSE_C_INCLUDE)),$$(notdir $$<)),$$(eval CC_EXEC += -H)) - endif - $$(eval CMD := $$(CC_EXEC) -c $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) - @$$(BUILD_CMD) - ifneq ($$(DUMP_C_MACROS),) - $$(eval CMD := $$(CC) -E -dM $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$<) - @$$(if $$(filter $$(notdir $$(DUMP_C_MACROS)),$$(notdir $$<)),$$(BUILD_CMD)) - endif - -# Compile: create object files from C++ source files. -$1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) - @mkdir -p $$(@D) - @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) - $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) - @$$(BUILD_CMD) - -$1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) - @mkdir -p $$(@D) - @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) - $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) - @$$(BUILD_CMD) - -# Assemble: create object files from assembler source files. -$1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN) - @mkdir -p $$(@D) - @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD) - $$(eval CMD=$$(CC) -c $$($1_ASFLAGS) $$< -o $$@) - @$$(BUILD_CMD) - -$1/%.a : $1/%.o - @mkdir -p $$(@D) - @$(SILENT) || printf "Archiving: $$<" | $$(AWK_CMD) - $$(eval CMD=$$(AR) rcs $$@ $$<) - @$$(BUILD_CMD) - -$1/force: - -$1/cflags.txt: $1/force - echo '$$($1_CFLAGS)' | cmp -s - $$@ || echo '$$($1_CFLAGS)' > $$@ - -$1/cxxflags.txt: $1/force - echo '$$($1_CXXFLAGS)' | cmp -s - $$@ || echo '$$($1_CXXFLAGS)' > $$@ - -$1/asflags.txt: $1/force - echo '$$($1_ASFLAGS)' | cmp -s - $$@ || echo '$$($1_ASFLAGS)' > $$@ - -$1/compiler.txt: $1/force - $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@ -endef - -.PRECIOUS: $(MASTER_OUTPUT)/obj.txt -$(MASTER_OUTPUT)/obj.txt: $(MASTER_OUTPUT)/force - echo '$(OBJ)' | cmp -s - $@ || echo '$(OBJ)' > $@ - -.PRECIOUS: $(MASTER_OUTPUT)/ldflags.txt -$(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force - echo '$(LDFLAGS)' | cmp -s - $@ || echo '$(LDFLAGS)' > $@ - - -# We have to use static rules for the .d files for some reason -DEPS = $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ))) -# Keep the .d files -.PRECIOUS: $(DEPS) -# Empty rule to force recompilation if the .d file is missing -$(DEPS): - - -$(foreach OUTPUT,$(OUTPUTS),$(eval $(call GEN_OBJRULE,$(OUTPUT)))) - -# Create preprocessed source for use in sending a bug report. -%.i : %.c | $(BEGIN) - $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ - -# Target: clean project. -clean: - $(foreach OUTPUT,$(OUTPUTS), $(REMOVE) -r $(OUTPUT) 2>/dev/null) - $(REMOVE) $(BUILD_DIR)/$(TARGET).* - -show_path: - @echo VPATH=$(VPATH) - @echo SRC=$(SRC) - @echo OBJ=$(OBJ) - -dump_vars: ERROR_IF_EMPTY="" -dump_vars: ERROR_IF_NONBOOL="" -dump_vars: ERROR_IF_UNSET="" -dump_vars: - @$(foreach V,$(sort $(.VARIABLES)),$(if $(filter-out environment% default automatic,$(origin $V)),$(info $V=$($V)))) - -objs-size: - for i in $(OBJ); do echo $$i; done | sort | xargs $(SIZE) - -ifeq ($(findstring avr-gcc,$(CC)),avr-gcc) -SIZE_MARGIN = 1024 - -check-size: - $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) - $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi)) - $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE))) - $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE))) - $(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE))) - if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \ - $(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \ - if [ $(CURRENT_SIZE) -gt $(MAX_SIZE) ]; then \ - printf "\n * $(MSG_FILE_TOO_BIG)"; $(PRINT_ERROR_PLAIN); \ - else \ - if [ $(FREE_SIZE) -lt $(SIZE_MARGIN) ]; then \ - $(PRINT_WARNING_PLAIN); printf " * $(MSG_FILE_NEAR_LIMIT)"; \ - else \ - $(PRINT_OK); $(SILENT) || printf " * $(MSG_FILE_JUST_RIGHT)"; \ - fi ; \ - fi ; \ - fi -else -check-size: - $(SILENT) || echo "$(MSG_CHECK_FILESIZE_SKIPPED)" -endif - -check-md5: - $(MD5SUM) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) - -# Create build directory -$(shell mkdir -p $(BUILD_DIR) 2>/dev/null) - -# Create object files directory -$(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null))) - -# Include the dependency files. --include $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ))) - - -# Listing of phony targets. -.PHONY : all dump_vars finish sizebefore sizeafter qmkversion \ -gccversion build elf hex uf2 eep lss sym coff extcoff \ -clean clean_list debug gdb-config show_path \ -program teensy dfu dfu-ee dfu-start \ -flash dfu-split-left dfu-split-right \ -avrdude-split-left avrdude-split-right \ -avrdude-loop usbasp |