Skip to content

Commit 8f79094

Browse files
mteidrashna
authored andcommitted
Refactor quantum/split_common/i2c.c, quantum/split_common/serial.c (qmk#4522)
* add temporary compile test shell script * Extended support of SKIP_VERSION to make invariant compile results during testing. * build_keyboard.mk, tmk_core/rules.mk: add LIB_SRC, QUANTUM_LIB_SRC support Support compiled object enclosed in library. e.g. ``` LIB_SRC += xxxx.c xxxx.c --> xxxx.o ---> xxxx.a ``` * remove 'ifdef/ifndef USE_I2C' from quantum/split_common/{i2c|serial}.c * add SKIP_DEBUG_INFO into tmk_core/rules.mk When SKIP_DEBUG_INFO=yes is specified, do not use the -g option at compile time. * tmk_core/rules.mk: Library object need -fno-lto * add SKIP_DEBUG_INFO=yes * remove temporary compile test shell script * add '#define SOFT_SERIAL_PIN D0' to keyboards/lets_split/rev?/config.h * quantum/split_common/serial.c: Changed not to use USE_I2C.
1 parent a49d98e commit 8f79094

File tree

9 files changed

+56
-24
lines changed

9 files changed

+56
-24
lines changed

build_keyboard.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ $(error MASTER does not have a valid value(left/right))
3434
endif
3535
endif
3636

37+
ifdef SKIP_VERSION
38+
OPT_DEFS += -DSKIP_VERSION
39+
endif
40+
3741
# Determine which subfolders exist.
3842
KEYBOARD_FOLDER_PATH_1 := $(KEYBOARD)
3943
KEYBOARD_FOLDER_PATH_2 := $(patsubst %/,%,$(dir $(KEYBOARD_FOLDER_PATH_1)))
@@ -278,6 +282,7 @@ ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
278282
endif
279283

280284
# # project specific files
285+
SRC += $(patsubst %.c,%.clib,$(LIB_SRC))
281286
SRC += $(KEYBOARD_SRC) \
282287
$(KEYMAP_C) \
283288
$(QUANTUM_SRC)
@@ -296,6 +301,7 @@ include $(TMK_PATH)/protocol.mk
296301
include $(TMK_PATH)/common.mk
297302
include bootloader.mk
298303

304+
SRC += $(patsubst %.c,%.clib,$(QUANTUM_LIB_SRC))
299305
SRC += $(TMK_COMMON_SRC)
300306
OPT_DEFS += $(TMK_COMMON_DEFS)
301307
EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)

common_features.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
270270
endif
271271
OPT_DEFS += -DSPLIT_KEYBOARD
272272
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/split_flags.c \
273-
$(QUANTUM_DIR)/split_common/split_util.c \
274-
$(QUANTUM_DIR)/split_common/i2c.c \
275-
$(QUANTUM_DIR)/split_common/serial.c
273+
$(QUANTUM_DIR)/split_common/split_util.c
274+
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/i2c.c
275+
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/serial.c
276276
endif

keyboards/lets_split/rev1/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4545
/* Set 0 if debouncing isn't needed */
4646
#define DEBOUNCING_DELAY 5
4747

48+
/* serial.c configuration for split keyboard */
49+
#define SOFT_SERIAL_PIN D0
50+
4851
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
4952
#define LOCKING_SUPPORT_ENABLE
5053
/* Locking resynchronize hack */

keyboards/lets_split/rev2/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4545
/* Set 0 if debouncing isn't needed */
4646
#define DEBOUNCING_DELAY 5
4747

48+
/* serial.c configuration for split keyboard */
49+
#define SOFT_SERIAL_PIN D0
50+
4851
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
4952
#define LOCKING_SUPPORT_ENABLE
5053
/* Locking resynchronize hack */

keyboards/lets_split/sockets/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4545
/* Set 0 if debouncing isn't needed */
4646
#define DEBOUNCING_DELAY 5
4747

48+
/* serial.c configuration for split keyboard */
49+
#define SOFT_SERIAL_PIN D0
50+
4851
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
4952
#define LOCKING_SUPPORT_ENABLE
5053
/* Locking resynchronize hack */

quantum/split_common/i2c.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "i2c.h"
88
#include "split_flags.h"
99

10-
#if defined(USE_I2C) || defined(EH)
11-
1210
// Limits the amount of we wait for any one i2c transaction.
1311
// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
1412
// 9 bits, a single transaction will take around 90μs to complete.
@@ -184,4 +182,3 @@ ISR(TWI_vect) {
184182
// Reset everything, so we are ready for the next TWI interrupt
185183
TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
186184
}
187-
#endif

quantum/split_common/serial.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
#include <stdbool.h>
1313
#include "serial.h"
1414

15-
#ifndef USE_I2C
16-
17-
#ifndef SOFT_SERIAL_PIN
18-
#error quantum/split_common/serial.c need SOFT_SERIAL_PIN define
19-
#endif
15+
#ifdef SOFT_SERIAL_PIN
2016

2117
#ifdef __AVR_ATmega32U4__
2218
// if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial.
23-
#ifdef USE_I2C
24-
#if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
25-
#error Using ATmega32U4 I2C, so can not use PD0, PD1
26-
#endif
19+
#ifdef USE_AVR_I2C
20+
#if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
21+
#error Using ATmega32U4 I2C, so can not use PD0, PD1
22+
#endif
2723
#endif
2824

2925
#if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3
@@ -278,4 +274,4 @@ int serial_update_buffers(void) {
278274
return 0;
279275
}
280276

281-
#endif
277+
#endif /* SOFT_SERIAL_PIN */

tmk_core/common/command.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ static void print_version(void)
181181
print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
182182
"PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
183183
"VER: " STR(DEVICE_VER) "\n");
184+
#ifdef SKIP_VERSION
185+
print("BUILD: (" __DATE__ ")\n");
186+
#else
184187
print("BUILD: " STR(QMK_VERSION) " (" __TIME__ " " __DATE__ ")\n");
188+
#endif
185189

186190
/* build options */
187191
print("OPTIONS:"

tmk_core/rules.mk

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ VPATH :=
2828

2929
# Convert all SRC to OBJ
3030
define OBJ_FROM_SRC
31-
$(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$($1_SRC)))))
31+
$(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$(patsubst %.clib,$1/%.a,$($1_SRC))))))
3232
endef
3333
$(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT))))
3434

3535
# Define a list of all objects
3636
OBJ := $(foreach OUTPUT,$(OUTPUTS),$($(OUTPUT)_OBJ))
37+
NO_LTO_OBJ := $(filter %.a,$(OBJ))
3738

3839
MASTER_OUTPUT := $(firstword $(OUTPUTS))
3940

@@ -81,7 +82,9 @@ CSTANDARD = -std=gnu99
8182
# -Wall...: warning level
8283
# -Wa,...: tell GCC to pass this to the assembler.
8384
# -adhlns...: create assembler listing
84-
CFLAGS += -g$(DEBUG)
85+
ifndef SKIP_DEBUG_INFO
86+
CFLAGS += -g$(DEBUG)
87+
endif
8588
CFLAGS += $(CDEFS)
8689
CFLAGS += -O$(OPT)
8790
# add color
@@ -110,7 +113,9 @@ CFLAGS += $(CSTANDARD)
110113
# -Wall...: warning level
111114
# -Wa,...: tell GCC to pass this to the assembler.
112115
# -adhlns...: create assembler listing
113-
CPPFLAGS += -g$(DEBUG)
116+
ifndef SKIP_DEBUG_INFO
117+
CPPFLAGS += -g$(DEBUG)
118+
endif
114119
CPPFLAGS += $(CPPDEFS)
115120
CPPFLAGS += -O$(OPT)
116121
# to supress "warning: only initialized variables can be placed into program memory area"
@@ -138,7 +143,11 @@ CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
138143
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
139144
# dump that will be displayed for a given single line of source input.
140145
ASFLAGS += $(ADEFS)
141-
ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
146+
ifndef SKIP_DEBUG_INFO
147+
ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
148+
else
149+
ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),--listing-cont-lines=100
150+
endif
142151

143152
#---------------- Library Options ----------------
144153
# Minimalistic printf version
@@ -210,6 +219,11 @@ ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS)
210219
ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(EXTRAFLAGS)
211220
ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
212221

222+
define NO_LTO
223+
$(patsubst %.a,%.o,$1): NOLTO_CFLAGS += -fno-lto
224+
endef
225+
$(foreach LOBJ, $(NO_LTO_OBJ), $(eval $(call NO_LTO,$(LOBJ))))
226+
213227
MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
214228

215229

@@ -290,8 +304,8 @@ $1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC))
290304
ifdef $1_CONFIG
291305
$1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG))
292306
endif
293-
$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS)
294-
$1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS)
307+
$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS)
308+
$1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS)
295309
$1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS)
296310

297311
# Compile: create object files from C source files.
@@ -321,6 +335,12 @@ $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
321335
$$(eval CMD=$$(CC) -c $$($1_ASFLAGS) $$< -o $$@)
322336
@$$(BUILD_CMD)
323337

338+
$1/%.a : $1/%.o
339+
@mkdir -p $$(@D)
340+
@$(SILENT) || printf "Archiving: $$<" | $$(AWK_CMD)
341+
$$(eval CMD=$$(AR) $$@ $$<)
342+
@$$(BUILD_CMD)
343+
324344
$1/force:
325345

326346
$1/cflags.txt: $1/force
@@ -346,7 +366,7 @@ $(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force
346366

347367

348368
# We have to use static rules for the .d files for some reason
349-
DEPS = $(patsubst %.o,%.d,$(OBJ))
369+
DEPS = $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ)))
350370
# Keep the .d files
351371
.PRECIOUS: $(DEPS)
352372
# Empty rule to force recompilation if the .d file is missing
@@ -391,7 +411,7 @@ $(shell mkdir -p $(BUILD_DIR) 2>/dev/null)
391411
$(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))
392412

393413
# Include the dependency files.
394-
-include $(patsubst %.o,%.d,$(OBJ))
414+
-include $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ)))
395415

396416

397417
# Listing of phony targets.

0 commit comments

Comments
 (0)