From 30f22d450da19c65584e6deb8515a1fa5b074e07 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 20:21:28 +0300 Subject: [PATCH 01/26] Add basic infrastrucure for building full tests --- Makefile | 2 +- build_full_test.mk | 14 ++++++++++++++ build_test.mk | 3 +++ testlist.mk | 4 ++++ tests/basic/config.h | 22 ++++++++++++++++++++++ tests/basic/rules.mk | 14 ++++++++++++++ tests/basic/test.c | 17 +++++++++++++++++ 7 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 build_full_test.mk create mode 100644 tests/basic/config.h create mode 100644 tests/basic/rules.mk create mode 100644 tests/basic/test.c diff --git a/Makefile b/Makefile index 6a93692bf..f789409b7 100644 --- a/Makefile +++ b/Makefile @@ -419,7 +419,7 @@ define BUILD_TEST MAKE_TARGET := $2 COMMAND := $1 MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET) - MAKE_VARS := TEST=$$(TEST_NAME) + MAKE_VARS := TEST=$$(TEST_NAME) FULL_TESTS=$$(FULL_TESTS) MAKE_MSG := $$(MSG_MAKE_TEST) $$(eval $$(call BUILD)) ifneq ($$(MAKE_TARGET),clean) diff --git a/build_full_test.mk b/build_full_test.mk new file mode 100644 index 000000000..0405b9d0f --- /dev/null +++ b/build_full_test.mk @@ -0,0 +1,14 @@ +# Copyright 2017 Fred Sundvik +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . \ No newline at end of file diff --git a/build_test.mk b/build_test.mk index ee15a4572..32bb4d807 100644 --- a/build_test.mk +++ b/build_test.mk @@ -43,6 +43,9 @@ VPATH += $(COMMON_VPATH) include $(TMK_PATH)/common.mk include $(QUANTUM_PATH)/serial_link/tests/rules.mk +ifneq ($(filter $(FULL_TESTS),$(TEST)),) +include build_full_test.mk +endif $(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) $(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) diff --git a/testlist.mk b/testlist.mk index 1884d6d3f..d949fb3ea 100644 --- a/testlist.mk +++ b/testlist.mk @@ -1,3 +1,6 @@ +TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk))) +FULL_TESTS := $(TEST_LIST) + include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk define VALIDATE_TEST_LIST @@ -10,4 +13,5 @@ define VALIDATE_TEST_LIST endif endef + $(eval $(call VALIDATE_TEST_LIST,$(firstword $(TEST_LIST)),$(wordlist 2,9999,$(TEST_LIST)))) \ No newline at end of file diff --git a/tests/basic/config.h b/tests/basic/config.h new file mode 100644 index 000000000..c24fdcf3f --- /dev/null +++ b/tests/basic/config.h @@ -0,0 +1,22 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TESTS_BASIC_CONFIG_H_ +#define TESTS_BASIC_CONFIG_H_ + + + +#endif /* TESTS_BASIC_CONFIG_H_ */ diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk new file mode 100644 index 000000000..0405b9d0f --- /dev/null +++ b/tests/basic/rules.mk @@ -0,0 +1,14 @@ +# Copyright 2017 Fred Sundvik +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . \ No newline at end of file diff --git a/tests/basic/test.c b/tests/basic/test.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tests/basic/test.c @@ -0,0 +1,17 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + From 7424261dae180d1cc0e4e46b4ee2d51ef5524e0a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:34:01 +0300 Subject: [PATCH 02/26] Try to build tmk_common --- build_full_test.mk | 10 +++- build_keyboard.mk | 122 -------------------------------------------- common.mk | 124 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 124 deletions(-) diff --git a/build_full_test.mk b/build_full_test.mk index 0405b9d0f..5b4685a91 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -11,4 +11,12 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . \ No newline at end of file +# along with this program. If not, see . + +include tests/$(TEST)/rules.mk +#include $(TMK_PATH)/protocol.mk + +TEST_PATH=tests/$(TEST) + +$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) +$(TEST)_DEFS=$(TMK_COMMON_DEFS) diff --git a/build_keyboard.mk b/build_keyboard.mk index 36eab3a9e..f13d5b6d6 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -131,128 +131,6 @@ ifndef CUSTOM_MATRIX SRC += $(QUANTUM_DIR)/matrix.c endif -ifeq ($(strip $(API_SYSEX_ENABLE)), yes) - OPT_DEFS += -DAPI_SYSEX_ENABLE - SRC += $(QUANTUM_DIR)/api/api_sysex.c - OPT_DEFS += -DAPI_ENABLE - SRC += $(QUANTUM_DIR)/api.c - MIDI_ENABLE=yes -endif - -MUSIC_ENABLE := 0 - -ifeq ($(strip $(AUDIO_ENABLE)), yes) - OPT_DEFS += -DAUDIO_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c - SRC += $(QUANTUM_DIR)/audio/audio.c - SRC += $(QUANTUM_DIR)/audio/voices.c - SRC += $(QUANTUM_DIR)/audio/luts.c -endif - -ifeq ($(strip $(MIDI_ENABLE)), yes) - OPT_DEFS += -DMIDI_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c -endif - -ifeq ($(MUSIC_ENABLE), 1) - SRC += $(QUANTUM_DIR)/process_keycode/process_music.c -endif - -ifeq ($(strip $(COMBO_ENABLE)), yes) - OPT_DEFS += -DCOMBO_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c -endif - -ifeq ($(strip $(VIRTSER_ENABLE)), yes) - OPT_DEFS += -DVIRTSER_ENABLE -endif - -ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) - OPT_DEFS += -DFAUXCLICKY_ENABLE - SRC += $(QUANTUM_DIR)/fauxclicky.c -endif - -ifeq ($(strip $(UCIS_ENABLE)), yes) - OPT_DEFS += -DUCIS_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c -endif - -ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) - OPT_DEFS += -DUNICODEMAP_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c -endif - -ifeq ($(strip $(UNICODE_ENABLE)), yes) - OPT_DEFS += -DUNICODE_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c -endif - -ifeq ($(strip $(UNICODE_COMMON)), yes) - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c -endif - -ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) - OPT_DEFS += -DRGBLIGHT_ENABLE - SRC += $(QUANTUM_DIR)/light_ws2812.c - SRC += $(QUANTUM_DIR)/rgblight.c - CIE1931_CURVE = yes - LED_BREATHING_TABLE = yes -endif - -ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) - OPT_DEFS += -DTAP_DANCE_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c -endif - -ifeq ($(strip $(PRINTING_ENABLE)), yes) - OPT_DEFS += -DPRINTING_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c - SRC += $(TMK_DIR)/protocol/serial_uart.c -endif - -ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) - SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) - OPT_DEFS += $(SERIAL_DEFS) - VAPTH += $(SERIAL_PATH) -endif - -ifneq ($(strip $(VARIABLE_TRACE)),) - SRC += $(QUANTUM_DIR)/variable_trace.c - OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) -ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) - OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) -endif -endif - -ifeq ($(strip $(LCD_ENABLE)), yes) - CIE1931_CURVE = yes -endif - -ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) - ifeq ($(strip $(VISUALIZER_ENABLE)), yes) - CIE1931_CURVE = yes - endif -endif - -ifeq ($(strip $(CIE1931_CURVE)), yes) - OPT_DEFS += -DUSE_CIE1931_CURVE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_BREATHING_TABLE)), yes) - OPT_DEFS += -DUSE_LED_BREATHING_TABLE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_TABLES)), yes) - SRC += $(QUANTUM_DIR)/led_tables.c -endif - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/common.mk b/common.mk index c4b9394a2..51e4283ba 100644 --- a/common.mk +++ b/common.mk @@ -24,4 +24,126 @@ COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras COMMON_VPATH += $(QUANTUM_PATH)/audio COMMON_VPATH += $(QUANTUM_PATH)/process_keycode COMMON_VPATH += $(QUANTUM_PATH)/api -COMMON_VPATH += $(SERIAL_PATH) \ No newline at end of file +COMMON_VPATH += $(SERIAL_PATH) + +ifeq ($(strip $(API_SYSEX_ENABLE)), yes) + OPT_DEFS += -DAPI_SYSEX_ENABLE + SRC += $(QUANTUM_DIR)/api/api_sysex.c + OPT_DEFS += -DAPI_ENABLE + SRC += $(QUANTUM_DIR)/api.c + MIDI_ENABLE=yes +endif + +MUSIC_ENABLE := 0 + +ifeq ($(strip $(AUDIO_ENABLE)), yes) + OPT_DEFS += -DAUDIO_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c + SRC += $(QUANTUM_DIR)/audio/audio.c + SRC += $(QUANTUM_DIR)/audio/voices.c + SRC += $(QUANTUM_DIR)/audio/luts.c +endif + +ifeq ($(strip $(MIDI_ENABLE)), yes) + OPT_DEFS += -DMIDI_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c +endif + +ifeq ($(MUSIC_ENABLE), 1) + SRC += $(QUANTUM_DIR)/process_keycode/process_music.c +endif + +ifeq ($(strip $(COMBO_ENABLE)), yes) + OPT_DEFS += -DCOMBO_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c +endif + +ifeq ($(strip $(VIRTSER_ENABLE)), yes) + OPT_DEFS += -DVIRTSER_ENABLE +endif + +ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) + OPT_DEFS += -DFAUXCLICKY_ENABLE + SRC += $(QUANTUM_DIR)/fauxclicky.c +endif + +ifeq ($(strip $(UCIS_ENABLE)), yes) + OPT_DEFS += -DUCIS_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c +endif + +ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) + OPT_DEFS += -DUNICODEMAP_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c +endif + +ifeq ($(strip $(UNICODE_ENABLE)), yes) + OPT_DEFS += -DUNICODE_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c +endif + +ifeq ($(strip $(UNICODE_COMMON)), yes) + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c +endif + +ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) + OPT_DEFS += -DRGBLIGHT_ENABLE + SRC += $(QUANTUM_DIR)/light_ws2812.c + SRC += $(QUANTUM_DIR)/rgblight.c + CIE1931_CURVE = yes + LED_BREATHING_TABLE = yes +endif + +ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) + OPT_DEFS += -DTAP_DANCE_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c +endif + +ifeq ($(strip $(PRINTING_ENABLE)), yes) + OPT_DEFS += -DPRINTING_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c + SRC += $(TMK_DIR)/protocol/serial_uart.c +endif + +ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) + SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) + OPT_DEFS += $(SERIAL_DEFS) + VAPTH += $(SERIAL_PATH) +endif + +ifneq ($(strip $(VARIABLE_TRACE)),) + SRC += $(QUANTUM_DIR)/variable_trace.c + OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) +ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) + OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) +endif +endif + +ifeq ($(strip $(LCD_ENABLE)), yes) + CIE1931_CURVE = yes +endif + +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + ifeq ($(strip $(VISUALIZER_ENABLE)), yes) + CIE1931_CURVE = yes + endif +endif + +ifeq ($(strip $(CIE1931_CURVE)), yes) + OPT_DEFS += -DUSE_CIE1931_CURVE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_BREATHING_TABLE)), yes) + OPT_DEFS += -DUSE_LED_BREATHING_TABLE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_TABLES)), yes) + SRC += $(QUANTUM_DIR)/led_tables.c +endif From 8674f9c466906c18349490f954c84e501fe3ccb6 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:38:34 +0300 Subject: [PATCH 03/26] Make sure config.h is included --- build_full_test.mk | 1 + build_test.mk | 1 + 2 files changed, 2 insertions(+) diff --git a/build_full_test.mk b/build_full_test.mk index 5b4685a91..8b04cc3a4 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -20,3 +20,4 @@ TEST_PATH=tests/$(TEST) $(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(TEST)_DEFS=$(TMK_COMMON_DEFS) +$(TEST)_CONFIG=$(TEST_PATH)/config.h diff --git a/build_test.mk b/build_test.mk index 32bb4d807..4d532e5bd 100644 --- a/build_test.mk +++ b/build_test.mk @@ -50,6 +50,7 @@ endif $(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) $(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) $(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS) +$(TEST_OBJ)/$(TEST)_CONFIG := $($(TEST)_CONFIG) include $(TMK_PATH)/native.mk include $(TMK_PATH)/rules.mk From 585d64612811a61f8476380dac77199c04246085 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:39:00 +0300 Subject: [PATCH 04/26] Define MATRIX_COLS and MATRIX_ROWS --- tests/basic/config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/basic/config.h b/tests/basic/config.h index c24fdcf3f..c5578b83f 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -17,6 +17,8 @@ #ifndef TESTS_BASIC_CONFIG_H_ #define TESTS_BASIC_CONFIG_H_ +#define MATRIX_ROWS 1 +#define MATRIX_COLS 2 #endif /* TESTS_BASIC_CONFIG_H_ */ From efaf0e830b48bd5a8a62c4963e67fda3582e747c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:41:34 +0300 Subject: [PATCH 05/26] Empty implementation of wait --- tmk_core/common/wait.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 82727be01..911c9ddb5 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -9,13 +9,16 @@ extern "C" { # include # define wait_ms(ms) _delay_ms(ms) # define wait_us(us) _delay_us(us) -#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ +#elif defined(PROTOCOL_CHIBIOS) # include "ch.h" # define wait_ms(ms) chThdSleepMilliseconds(ms) # define wait_us(us) chThdSleepMicroseconds(us) -#elif defined(__arm__) /* __AVR__ */ +#elif defined(__arm__) # include "wait_api.h" -#endif /* __AVR__ */ +#else // Unit tests +#define wait_ms(ms) +#define wait_us(us) +#endif #ifdef __cplusplus } From fdfd48e8c8a4c713be0d2d978bbe40c5f083abc5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:43:36 +0300 Subject: [PATCH 06/26] Fix program mem functionality --- tmk_core/common/progmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index 5b2765625..a09f91be8 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h @@ -3,7 +3,7 @@ #if defined(__AVR__) # include -#elif defined(__arm__) +#else # define PROGMEM # define pgm_read_byte(p) *((unsigned char*)p) # define pgm_read_word(p) *((uint16_t*)p) From 26eb97a4a8c260a9b5613d425bcdd175a4c67761 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:47:59 +0300 Subject: [PATCH 07/26] Empty implementation of bootloader, suspend and timer --- tmk_core/common.mk | 2 ++ tmk_core/common/native/bootloader.c | 17 +++++++++++++++++ tmk_core/common/native/suspend.c | 17 +++++++++++++++++ tmk_core/common/native/timer.c | 17 +++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 tmk_core/common/native/bootloader.c create mode 100644 tmk_core/common/native/suspend.c create mode 100644 tmk_core/common/native/timer.c diff --git a/tmk_core/common.mk b/tmk_core/common.mk index edec2acb4..c69e7e2d5 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -3,6 +3,8 @@ ifeq ($(PLATFORM),AVR) PLATFORM_COMMON_DIR = $(COMMON_DIR)/avr else ifeq ($(PLATFORM),CHIBIOS) PLATFORM_COMMON_DIR = $(COMMON_DIR)/chibios +else + PLATFORM_COMMON_DIR = $(COMMON_DIR)/native endif TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ diff --git a/tmk_core/common/native/bootloader.c b/tmk_core/common/native/bootloader.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tmk_core/common/native/bootloader.c @@ -0,0 +1,17 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + diff --git a/tmk_core/common/native/suspend.c b/tmk_core/common/native/suspend.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tmk_core/common/native/suspend.c @@ -0,0 +1,17 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + diff --git a/tmk_core/common/native/timer.c b/tmk_core/common/native/timer.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tmk_core/common/native/timer.c @@ -0,0 +1,17 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + From 83509adc3a6ac71db7c7be32026a351fe08dc13a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:51:40 +0300 Subject: [PATCH 08/26] Add empty timer functions --- tmk_core/common/native/timer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tmk_core/common/native/timer.c b/tmk_core/common/native/timer.c index 01d1930ea..e21cd7d55 100644 --- a/tmk_core/common/native/timer.c +++ b/tmk_core/common/native/timer.c @@ -14,4 +14,14 @@ * along with this program. If not, see . */ +#include "timer.h" + +void timer_init(void) {} + +void timer_clear(void) {} + +uint16_t timer_read(void) { return 0; } +uint32_t timer_read32(void) { return 0; } +uint16_t timer_elapsed(uint16_t last) { return 0; } +uint32_t timer_elapsed32(uint32_t last) { return 0; } From f646f00b93b0caeb045d4aabd3b3b985f0f06402 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:53:21 +0300 Subject: [PATCH 09/26] Rename native to test --- tmk_core/common.mk | 2 +- tmk_core/common/{native => test}/bootloader.c | 0 tmk_core/common/{native => test}/suspend.c | 0 tmk_core/common/{native => test}/timer.c | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename tmk_core/common/{native => test}/bootloader.c (100%) rename tmk_core/common/{native => test}/suspend.c (100%) rename tmk_core/common/{native => test}/timer.c (100%) diff --git a/tmk_core/common.mk b/tmk_core/common.mk index c69e7e2d5..9b3002cc9 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -4,7 +4,7 @@ ifeq ($(PLATFORM),AVR) else ifeq ($(PLATFORM),CHIBIOS) PLATFORM_COMMON_DIR = $(COMMON_DIR)/chibios else - PLATFORM_COMMON_DIR = $(COMMON_DIR)/native + PLATFORM_COMMON_DIR = $(COMMON_DIR)/test endif TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ diff --git a/tmk_core/common/native/bootloader.c b/tmk_core/common/test/bootloader.c similarity index 100% rename from tmk_core/common/native/bootloader.c rename to tmk_core/common/test/bootloader.c diff --git a/tmk_core/common/native/suspend.c b/tmk_core/common/test/suspend.c similarity index 100% rename from tmk_core/common/native/suspend.c rename to tmk_core/common/test/suspend.c diff --git a/tmk_core/common/native/timer.c b/tmk_core/common/test/timer.c similarity index 100% rename from tmk_core/common/native/timer.c rename to tmk_core/common/test/timer.c From d29906cb64f3c49da43c209ce341e577278e5fad Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:01:21 +0300 Subject: [PATCH 10/26] Emulate eeprom --- build_test.mk | 1 + tmk_core/common.mk | 4 ++ tmk_core/common/eeprom.h | 2 + tmk_core/common/test/eeprom.c | 98 +++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 tmk_core/common/test/eeprom.c diff --git a/build_test.mk b/build_test.mk index 4d532e5bd..609b094af 100644 --- a/build_test.mk +++ b/build_test.mk @@ -40,6 +40,7 @@ VPATH +=\ all: elf VPATH += $(COMMON_VPATH) +PLATFORM:=TEST include $(TMK_PATH)/common.mk include $(QUANTUM_PATH)/serial_link/tests/rules.mk diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 9b3002cc9..4f80e0fa9 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -31,6 +31,10 @@ ifeq ($(PLATFORM),CHIBIOS) TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c endif +ifeq ($(PLATFORM),TEST) + TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c +endif + # Option modules diff --git a/tmk_core/common/eeprom.h b/tmk_core/common/eeprom.h index 2cc2ccee3..3696d0df3 100644 --- a/tmk_core/common/eeprom.h +++ b/tmk_core/common/eeprom.h @@ -4,6 +4,8 @@ #if defined(__AVR__) #include #else +#include + uint8_t eeprom_read_byte (const uint8_t *__p); uint16_t eeprom_read_word (const uint16_t *__p); uint32_t eeprom_read_dword (const uint32_t *__p); diff --git a/tmk_core/common/test/eeprom.c b/tmk_core/common/test/eeprom.c new file mode 100644 index 000000000..61cc039ef --- /dev/null +++ b/tmk_core/common/test/eeprom.c @@ -0,0 +1,98 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "eeprom.h" + +#define EEPROM_SIZE 32 + +static uint8_t buffer[EEPROM_SIZE]; + +uint8_t eeprom_read_byte(const uint8_t *addr) { + uintptr_t offset = (uintptr_t)addr; + return buffer[offset]; +} + +void eeprom_write_byte(uint8_t *addr, uint8_t value) { + uintptr_t offset = (uintptr_t)addr; + buffer[offset] = value; +} + +uint16_t eeprom_read_word(const uint16_t *addr) { + const uint8_t *p = (const uint8_t *)addr; + return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); +} + +uint32_t eeprom_read_dword(const uint32_t *addr) { + const uint8_t *p = (const uint8_t *)addr; + return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) + | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); +} + +void eeprom_read_block(void *buf, const void *addr, uint32_t len) { + const uint8_t *p = (const uint8_t *)addr; + uint8_t *dest = (uint8_t *)buf; + while (len--) { + *dest++ = eeprom_read_byte(p++); + } +} + +void eeprom_write_word(uint16_t *addr, uint16_t value) { + uint8_t *p = (uint8_t *)addr; + eeprom_write_byte(p++, value); + eeprom_write_byte(p, value >> 8); +} + +void eeprom_write_dword(uint32_t *addr, uint32_t value) { + uint8_t *p = (uint8_t *)addr; + eeprom_write_byte(p++, value); + eeprom_write_byte(p++, value >> 8); + eeprom_write_byte(p++, value >> 16); + eeprom_write_byte(p, value >> 24); +} + +void eeprom_write_block(const void *buf, void *addr, uint32_t len) { + uint8_t *p = (uint8_t *)addr; + const uint8_t *src = (const uint8_t *)buf; + while (len--) { + eeprom_write_byte(p++, *src++); + } +} + +void eeprom_update_byte(uint8_t *addr, uint8_t value) { + eeprom_write_byte(addr, value); +} + +void eeprom_update_word(uint16_t *addr, uint16_t value) { + uint8_t *p = (uint8_t *)addr; + eeprom_write_byte(p++, value); + eeprom_write_byte(p, value >> 8); +} + +void eeprom_update_dword(uint32_t *addr, uint32_t value) { + uint8_t *p = (uint8_t *)addr; + eeprom_write_byte(p++, value); + eeprom_write_byte(p++, value >> 8); + eeprom_write_byte(p++, value >> 16); + eeprom_write_byte(p, value >> 24); +} + +void eeprom_update_block(const void *buf, void *addr, uint32_t len) { + uint8_t *p = (uint8_t *)addr; + const uint8_t *src = (const uint8_t *)buf; + while (len--) { + eeprom_write_byte(p++, *src++); + } +} From 1c0fe956ac242b1c85a9b024b9b3966020b862ed Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:14:47 +0300 Subject: [PATCH 11/26] Split common.mk into common.mk and common_features.mk To support including keyboard/keymap specific rules before it --- build_full_test.mk | 2 +- build_keyboard.mk | 15 +---- build_test.mk | 5 ++ common.mk | 128 ------------------------------------ common_features.mk | 152 +++++++++++++++++++++++++++++++++++++++++++ tests/basic/rules.mk | 4 +- 6 files changed, 164 insertions(+), 142 deletions(-) create mode 100644 common_features.mk diff --git a/build_full_test.mk b/build_full_test.mk index 8b04cc3a4..a4fc8d820 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -18,6 +18,6 @@ include tests/$(TEST)/rules.mk TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) +$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h diff --git a/build_keyboard.mk b/build_keyboard.mk index f13d5b6d6..3ec389ac9 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -31,8 +31,6 @@ $(error MASTER does not have a valid value(left/right)) endif endif - - KEYBOARD_PATH := keyboards/$(KEYBOARD) KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c @@ -42,7 +40,6 @@ else $(error "$(KEYBOARD_C)" does not exist) endif - ifneq ($(SUBPROJECT),) SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT) SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c @@ -118,19 +115,12 @@ endif # # project specific files SRC += $(KEYBOARD_C) \ $(KEYMAP_C) \ - $(QUANTUM_DIR)/quantum.c \ - $(QUANTUM_DIR)/keymap_common.c \ - $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c + $(QUANTUM_SRC) ifneq ($(SUBPROJECT),) SRC += $(SUBPROJECT_C) endif -ifndef CUSTOM_MATRIX - SRC += $(QUANTUM_DIR)/matrix.c -endif - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax @@ -142,9 +132,10 @@ endif VPATH += $(KEYBOARD_PATH) VPATH += $(COMMON_VPATH) +include common_features.mk include $(TMK_PATH)/protocol.mk - include $(TMK_PATH)/common.mk + SRC += $(TMK_COMMON_SRC) OPT_DEFS += $(TMK_COMMON_DEFS) EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS) diff --git a/build_test.mk b/build_test.mk index 609b094af..cac2cba50 100644 --- a/build_test.mk +++ b/build_test.mk @@ -42,6 +42,11 @@ all: elf VPATH += $(COMMON_VPATH) PLATFORM:=TEST +ifneq ($(filter $(FULL_TESTS),$(TEST)),) +include tests/$(TEST)/rules.mk +endif + +include common_features.mk include $(TMK_PATH)/common.mk include $(QUANTUM_PATH)/serial_link/tests/rules.mk ifneq ($(filter $(FULL_TESTS),$(TEST)),) diff --git a/common.mk b/common.mk index 51e4283ba..70f7ae099 100644 --- a/common.mk +++ b/common.mk @@ -11,12 +11,6 @@ QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) BUILD_DIR := $(TOP_DIR)/.build -SERIAL_DIR := $(QUANTUM_DIR)/serial_link -SERIAL_PATH := $(QUANTUM_PATH)/serial_link -SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) -SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) -SERIAL_DEFS += -DSERIAL_LINK_ENABLE - COMMON_VPATH := $(TOP_DIR) COMMON_VPATH += $(TMK_PATH) COMMON_VPATH += $(QUANTUM_PATH) @@ -25,125 +19,3 @@ COMMON_VPATH += $(QUANTUM_PATH)/audio COMMON_VPATH += $(QUANTUM_PATH)/process_keycode COMMON_VPATH += $(QUANTUM_PATH)/api COMMON_VPATH += $(SERIAL_PATH) - -ifeq ($(strip $(API_SYSEX_ENABLE)), yes) - OPT_DEFS += -DAPI_SYSEX_ENABLE - SRC += $(QUANTUM_DIR)/api/api_sysex.c - OPT_DEFS += -DAPI_ENABLE - SRC += $(QUANTUM_DIR)/api.c - MIDI_ENABLE=yes -endif - -MUSIC_ENABLE := 0 - -ifeq ($(strip $(AUDIO_ENABLE)), yes) - OPT_DEFS += -DAUDIO_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c - SRC += $(QUANTUM_DIR)/audio/audio.c - SRC += $(QUANTUM_DIR)/audio/voices.c - SRC += $(QUANTUM_DIR)/audio/luts.c -endif - -ifeq ($(strip $(MIDI_ENABLE)), yes) - OPT_DEFS += -DMIDI_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c -endif - -ifeq ($(MUSIC_ENABLE), 1) - SRC += $(QUANTUM_DIR)/process_keycode/process_music.c -endif - -ifeq ($(strip $(COMBO_ENABLE)), yes) - OPT_DEFS += -DCOMBO_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c -endif - -ifeq ($(strip $(VIRTSER_ENABLE)), yes) - OPT_DEFS += -DVIRTSER_ENABLE -endif - -ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) - OPT_DEFS += -DFAUXCLICKY_ENABLE - SRC += $(QUANTUM_DIR)/fauxclicky.c -endif - -ifeq ($(strip $(UCIS_ENABLE)), yes) - OPT_DEFS += -DUCIS_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c -endif - -ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) - OPT_DEFS += -DUNICODEMAP_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c -endif - -ifeq ($(strip $(UNICODE_ENABLE)), yes) - OPT_DEFS += -DUNICODE_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c -endif - -ifeq ($(strip $(UNICODE_COMMON)), yes) - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c -endif - -ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) - OPT_DEFS += -DRGBLIGHT_ENABLE - SRC += $(QUANTUM_DIR)/light_ws2812.c - SRC += $(QUANTUM_DIR)/rgblight.c - CIE1931_CURVE = yes - LED_BREATHING_TABLE = yes -endif - -ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) - OPT_DEFS += -DTAP_DANCE_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c -endif - -ifeq ($(strip $(PRINTING_ENABLE)), yes) - OPT_DEFS += -DPRINTING_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c - SRC += $(TMK_DIR)/protocol/serial_uart.c -endif - -ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) - SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) - OPT_DEFS += $(SERIAL_DEFS) - VAPTH += $(SERIAL_PATH) -endif - -ifneq ($(strip $(VARIABLE_TRACE)),) - SRC += $(QUANTUM_DIR)/variable_trace.c - OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) -ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) - OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) -endif -endif - -ifeq ($(strip $(LCD_ENABLE)), yes) - CIE1931_CURVE = yes -endif - -ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) - ifeq ($(strip $(VISUALIZER_ENABLE)), yes) - CIE1931_CURVE = yes - endif -endif - -ifeq ($(strip $(CIE1931_CURVE)), yes) - OPT_DEFS += -DUSE_CIE1931_CURVE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_BREATHING_TABLE)), yes) - OPT_DEFS += -DUSE_LED_BREATHING_TABLE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_TABLES)), yes) - SRC += $(QUANTUM_DIR)/led_tables.c -endif diff --git a/common_features.mk b/common_features.mk new file mode 100644 index 000000000..a8a52afb9 --- /dev/null +++ b/common_features.mk @@ -0,0 +1,152 @@ +# Copyright 2017 Fred Sundvik +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +SERIAL_DIR := $(QUANTUM_DIR)/serial_link +SERIAL_PATH := $(QUANTUM_PATH)/serial_link +SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) +SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) +SERIAL_DEFS += -DSERIAL_LINK_ENABLE + +ifeq ($(strip $(API_SYSEX_ENABLE)), yes) + OPT_DEFS += -DAPI_SYSEX_ENABLE + SRC += $(QUANTUM_DIR)/api/api_sysex.c + OPT_DEFS += -DAPI_ENABLE + SRC += $(QUANTUM_DIR)/api.c + MIDI_ENABLE=yes +endif + +MUSIC_ENABLE := 0 + +ifeq ($(strip $(AUDIO_ENABLE)), yes) + OPT_DEFS += -DAUDIO_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c + SRC += $(QUANTUM_DIR)/audio/audio.c + SRC += $(QUANTUM_DIR)/audio/voices.c + SRC += $(QUANTUM_DIR)/audio/luts.c +endif + +ifeq ($(strip $(MIDI_ENABLE)), yes) + OPT_DEFS += -DMIDI_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c +endif + +ifeq ($(MUSIC_ENABLE), 1) + SRC += $(QUANTUM_DIR)/process_keycode/process_music.c +endif + +ifeq ($(strip $(COMBO_ENABLE)), yes) + OPT_DEFS += -DCOMBO_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c +endif + +ifeq ($(strip $(VIRTSER_ENABLE)), yes) + OPT_DEFS += -DVIRTSER_ENABLE +endif + +ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) + OPT_DEFS += -DFAUXCLICKY_ENABLE + SRC += $(QUANTUM_DIR)/fauxclicky.c +endif + +ifeq ($(strip $(UCIS_ENABLE)), yes) + OPT_DEFS += -DUCIS_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c +endif + +ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) + OPT_DEFS += -DUNICODEMAP_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c +endif + +ifeq ($(strip $(UNICODE_ENABLE)), yes) + OPT_DEFS += -DUNICODE_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c +endif + +ifeq ($(strip $(UNICODE_COMMON)), yes) + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c +endif + +ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) + OPT_DEFS += -DRGBLIGHT_ENABLE + SRC += $(QUANTUM_DIR)/light_ws2812.c + SRC += $(QUANTUM_DIR)/rgblight.c + CIE1931_CURVE = yes + LED_BREATHING_TABLE = yes +endif + +ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) + OPT_DEFS += -DTAP_DANCE_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c +endif + +ifeq ($(strip $(PRINTING_ENABLE)), yes) + OPT_DEFS += -DPRINTING_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c + SRC += $(TMK_DIR)/protocol/serial_uart.c +endif + +ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) + SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) + OPT_DEFS += $(SERIAL_DEFS) + VAPTH += $(SERIAL_PATH) +endif + +ifneq ($(strip $(VARIABLE_TRACE)),) + SRC += $(QUANTUM_DIR)/variable_trace.c + OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) +ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) + OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) +endif +endif + +ifeq ($(strip $(LCD_ENABLE)), yes) + CIE1931_CURVE = yes +endif + +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + ifeq ($(strip $(VISUALIZER_ENABLE)), yes) + CIE1931_CURVE = yes + endif +endif + +ifeq ($(strip $(CIE1931_CURVE)), yes) + OPT_DEFS += -DUSE_CIE1931_CURVE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_BREATHING_TABLE)), yes) + OPT_DEFS += -DUSE_LED_BREATHING_TABLE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_TABLES)), yes) + SRC += $(QUANTUM_DIR)/led_tables.c +endif + +QUANTUM_SRC:= \ + $(QUANTUM_DIR)/quantum.c \ + $(QUANTUM_DIR)/keymap_common.c \ + $(QUANTUM_DIR)/keycode_config.c \ + $(QUANTUM_DIR)/process_keycode/process_leader.c + +ifndef CUSTOM_MATRIX + QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c +endif \ No newline at end of file diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk index 0405b9d0f..8a906807c 100644 --- a/tests/basic/rules.mk +++ b/tests/basic/rules.mk @@ -11,4 +11,6 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . \ No newline at end of file +# along with this program. If not, see . + +CUSTOM_MATRIX=yes \ No newline at end of file From a72e8f0865e54777a152652c5d46280ceb58efbc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:30:07 +0300 Subject: [PATCH 12/26] Dummy test matrix implementation --- build_full_test.mk | 4 ++-- tests/test_common/matrix.c | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/test_common/matrix.c diff --git a/build_full_test.mk b/build_full_test.mk index a4fc8d820..43e2a20a7 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -13,11 +13,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -include tests/$(TEST)/rules.mk #include $(TMK_PATH)/protocol.mk TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) +$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) tests/test_common/matrix.c $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h +VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c new file mode 100644 index 000000000..940f28f35 --- /dev/null +++ b/tests/test_common/matrix.c @@ -0,0 +1,43 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "matrix.h" + +void matrix_init(void) { + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + matrix_scan_quantum(); + return 1; +} + +matrix_row_t matrix_get_row(uint8_t row) { + return 0; +} + +void matrix_print(void) { + +} + +void matrix_init_kb(void) { + +} + +void matrix_scan_kb(void) { + +} From c588fca06cd63c440678d04806042b52ff8a5610 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:32:04 +0300 Subject: [PATCH 13/26] Empty bootloader_jump --- tmk_core/common/test/bootloader.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tmk_core/common/test/bootloader.c b/tmk_core/common/test/bootloader.c index 01d1930ea..5155d9ff0 100644 --- a/tmk_core/common/test/bootloader.c +++ b/tmk_core/common/test/bootloader.c @@ -14,4 +14,6 @@ * along with this program. If not, see . */ +#include "bootloader.h" +void bootloader_jump(void) {} From 617578399cf1a0fff70ceeb21d63a06524c801a3 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:39:56 +0300 Subject: [PATCH 14/26] Add keymap --- tests/basic/config.h | 2 +- tests/basic/test.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/basic/config.h b/tests/basic/config.h index c5578b83f..4da8d0425 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -17,7 +17,7 @@ #ifndef TESTS_BASIC_CONFIG_H_ #define TESTS_BASIC_CONFIG_H_ -#define MATRIX_ROWS 1 +#define MATRIX_ROWS 2 #define MATRIX_COLS 2 diff --git a/tests/basic/test.c b/tests/basic/test.c index 01d1930ea..2afb4d6a9 100644 --- a/tests/basic/test.c +++ b/tests/basic/test.c @@ -14,4 +14,11 @@ * along with this program. If not, see . */ +#include "quantum.h" +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = { + {KC_A, KC_B}, + {KC_C, KC_D} + }, +}; From 3bb0586acc6472380365d78ee81a332aca468239 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 23:50:44 +0300 Subject: [PATCH 15/26] Add a couple of basic tests and implement driver mock --- build_full_test.mk | 7 ++- tests/basic/test.cpp | 50 ++++++++++++++++ tests/test_common/matrix.c | 13 ++++- tests/test_common/test_driver.cpp | 58 +++++++++++++++++++ tests/test_common/test_driver.h | 45 ++++++++++++++ .../test.c => test_common/test_matrix.h} | 21 ++++--- 6 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 tests/basic/test.cpp create mode 100644 tests/test_common/test_driver.cpp create mode 100644 tests/test_common/test_driver.h rename tests/{basic/test.c => test_common/test_matrix.h} (70%) diff --git a/build_full_test.mk b/build_full_test.mk index 43e2a20a7..5f9bbe5e6 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -17,7 +17,12 @@ TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) tests/test_common/matrix.c +$(TEST)_SRC= \ + $(TEST_PATH)/test.cpp \ + $(TMK_COMMON_SRC) \ + $(QUANTUM_SRC) \ + tests/test_common/matrix.c \ + tests/test_common/test_driver.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp new file mode 100644 index 000000000..ce9a0cd72 --- /dev/null +++ b/tests/basic/test.cpp @@ -0,0 +1,50 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "quantum.h" +#include "keyboard.h" +#include "test_driver.h" +#include "test_matrix.h" + +using testing::_; +using testing::Return; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = { + {KC_A, KC_B}, + {KC_C, KC_D} + }, +}; + +TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { + keyboard_init(); + TestDriver driver; + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); +} + +TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { + keyboard_init(); + TestDriver driver; + press_key(0, 0); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_task(); +} diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 940f28f35..85556e2c4 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -16,6 +16,9 @@ #include "matrix.h" +#include "test_matrix.h" + +static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { matrix_init_quantum(); @@ -27,7 +30,7 @@ uint8_t matrix_scan(void) { } matrix_row_t matrix_get_row(uint8_t row) { - return 0; + return matrix[row]; } void matrix_print(void) { @@ -41,3 +44,11 @@ void matrix_init_kb(void) { void matrix_scan_kb(void) { } + +void press_key(uint8_t col, uint8_t row) { + matrix[row] |= 1 << col; +} + +void release_key(uint8_t col, uint8_t row) { + matrix[row] &= ~(1 << col); +} diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp new file mode 100644 index 000000000..7c67f5776 --- /dev/null +++ b/tests/test_common/test_driver.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test_driver.h" + +TestDriver* TestDriver::m_this = nullptr; + +TestDriver::TestDriver() + : m_driver{ + &TestDriver::keyboard_leds, + &TestDriver::send_keyboard, + &TestDriver::send_mouse, + &TestDriver::send_system, + &TestDriver::send_consumer + } +{ + + host_set_driver(&m_driver); + m_this = this; +} + +TestDriver::~TestDriver() { + m_this = nullptr; +} + +uint8_t TestDriver::keyboard_leds(void) { + return m_this->keyboard_leds_mock(); +} + +void TestDriver::send_keyboard(report_keyboard_t* report) { + m_this->send_keyboard_mock(report); + +} + +void TestDriver::send_mouse(report_mouse_t* report) { + m_this->send_mouse_mock(report); +} + +void TestDriver::send_system(uint16_t data) { + m_this->send_system_mock(data); +} + +void TestDriver::send_consumer(uint16_t data) { + m_this->send_consumer_mock(data); +} diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h new file mode 100644 index 000000000..d5b831884 --- /dev/null +++ b/tests/test_common/test_driver.h @@ -0,0 +1,45 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_ +#define TESTS_TEST_COMMON_TEST_DRIVER_H_ + +#include "gmock/gmock.h" +#include +#include "host.h" + + +class TestDriver { +public: + TestDriver(); + ~TestDriver(); + MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t*)); + MOCK_METHOD1(send_mouse_mock, void (report_mouse_t*)); + MOCK_METHOD1(send_system_mock, void (uint16_t)); + MOCK_METHOD1(send_consumer_mock, void (uint16_t)); +private: + static uint8_t keyboard_leds(void); + static void send_keyboard(report_keyboard_t *report); + static void send_mouse(report_mouse_t* report); + static void send_system(uint16_t data); + static void send_consumer(uint16_t data); + host_driver_t m_driver; + static TestDriver* m_this; +}; + + +#endif /* TESTS_TEST_COMMON_TEST_DRIVER_H_ */ diff --git a/tests/basic/test.c b/tests/test_common/test_matrix.h similarity index 70% rename from tests/basic/test.c rename to tests/test_common/test_matrix.h index 2afb4d6a9..afc65c556 100644 --- a/tests/basic/test.c +++ b/tests/test_common/test_matrix.h @@ -14,11 +14,18 @@ * along with this program. If not, see . */ -#include "quantum.h" +#ifndef TESTS_TEST_COMMON_TEST_MATRIX_H_ +#define TESTS_TEST_COMMON_TEST_MATRIX_H_ -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = { - {KC_A, KC_B}, - {KC_C, KC_D} - }, -}; +#ifdef __cplusplus +extern "C" { +#endif + +void press_key(uint8_t col, uint8_t row); +void release_key(uint8_t col, uint8_t row); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_TEST_COMMON_TEST_MATRIX_H_ */ From c38589d8615ba3ff93736cb02d12b3c8ceb68094 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 15:18:30 +0300 Subject: [PATCH 16/26] Fix the order of init and driver creation --- tests/basic/test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index ce9a0cd72..e3190085d 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -33,16 +33,18 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { - keyboard_init(); TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { - keyboard_init(); TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)); From 017458a07bda3f4b2604d079ec65ef607a1a1e57 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 15:19:15 +0300 Subject: [PATCH 17/26] Move functionality from action_util to report The functions also takes report_kebyoard_t parameters, so that they can be used elsewhere. --- tmk_core/common.mk | 1 + tmk_core/common/action_util.c | 176 +-------------------------------- tmk_core/common/action_util.h | 2 - tmk_core/common/report.c | 177 ++++++++++++++++++++++++++++++++++ tmk_core/common/report.h | 10 ++ 5 files changed, 193 insertions(+), 173 deletions(-) create mode 100644 tmk_core/common/report.c diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 4f80e0fa9..75b810d98 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -18,6 +18,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/debug.c \ $(COMMON_DIR)/util.c \ $(COMMON_DIR)/eeconfig.c \ + $(COMMON_DIR)/report.c \ $(PLATFORM_COMMON_DIR)/suspend.c \ $(PLATFORM_COMMON_DIR)/timer.c \ $(PLATFORM_COMMON_DIR)/bootloader.c \ diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 77848c092..511649676 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -25,13 +25,6 @@ along with this program. If not, see . extern keymap_config_t keymap_config; -static inline void add_key_byte(uint8_t code); -static inline void del_key_byte(uint8_t code); -#ifdef NKRO_ENABLE -static inline void add_key_bit(uint8_t code); -static inline void del_key_bit(uint8_t code); -#endif - static uint8_t real_mods = 0; static uint8_t weak_mods = 0; static uint8_t macro_mods = 0; @@ -134,7 +127,7 @@ void send_keyboard_report(void) { } #endif keyboard_report->mods |= oneshot_mods; - if (has_anykey()) { + if (has_anykey(keyboard_report)) { clear_oneshot_mods(); } } @@ -148,22 +141,22 @@ void add_key(uint8_t key) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { - add_key_bit(key); + add_key_bit(keyboard_report, key); return; } #endif - add_key_byte(key); + add_key_byte(keyboard_report, key); } void del_key(uint8_t key) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { - del_key_bit(key); + del_key_bit(keyboard_report, key); return; } #endif - del_key_byte(key); + del_key_byte(keyboard_report, key); } void clear_keys(void) @@ -221,166 +214,7 @@ uint8_t get_oneshot_mods(void) /* * inspect keyboard state */ -uint8_t has_anykey(void) -{ - uint8_t cnt = 0; - for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { - if (keyboard_report->raw[i]) - cnt++; - } - return cnt; -} - uint8_t has_anymod(void) { return bitpop(real_mods); } - -uint8_t get_first_key(void) -{ -#ifdef NKRO_ENABLE - if (keyboard_protocol && keymap_config.nkro) { - uint8_t i = 0; - for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) - ; - return i<<3 | biton(keyboard_report->nkro.bits[i]); - } -#endif -#ifdef USB_6KRO_ENABLE - uint8_t i = cb_head; - do { - if (keyboard_report->keys[i] != 0) { - break; - } - i = RO_INC(i); - } while (i != cb_tail); - return keyboard_report->keys[i]; -#else - return keyboard_report->keys[0]; -#endif -} - - - -/* local functions */ -static inline void add_key_byte(uint8_t code) -{ -#ifdef USB_6KRO_ENABLE - int8_t i = cb_head; - int8_t empty = -1; - if (cb_count) { - do { - if (keyboard_report->keys[i] == code) { - return; - } - if (empty == -1 && keyboard_report->keys[i] == 0) { - empty = i; - } - i = RO_INC(i); - } while (i != cb_tail); - if (i == cb_tail) { - if (cb_tail == cb_head) { - // buffer is full - if (empty == -1) { - // pop head when has no empty space - cb_head = RO_INC(cb_head); - cb_count--; - } - else { - // left shift when has empty space - uint8_t offset = 1; - i = RO_INC(empty); - do { - if (keyboard_report->keys[i] != 0) { - keyboard_report->keys[empty] = keyboard_report->keys[i]; - keyboard_report->keys[i] = 0; - empty = RO_INC(empty); - } - else { - offset++; - } - i = RO_INC(i); - } while (i != cb_tail); - cb_tail = RO_SUB(cb_tail, offset); - } - } - } - } - // add to tail - keyboard_report->keys[cb_tail] = code; - cb_tail = RO_INC(cb_tail); - cb_count++; -#else - int8_t i = 0; - int8_t empty = -1; - for (; i < KEYBOARD_REPORT_KEYS; i++) { - if (keyboard_report->keys[i] == code) { - break; - } - if (empty == -1 && keyboard_report->keys[i] == 0) { - empty = i; - } - } - if (i == KEYBOARD_REPORT_KEYS) { - if (empty != -1) { - keyboard_report->keys[empty] = code; - } - } -#endif -} - -static inline void del_key_byte(uint8_t code) -{ -#ifdef USB_6KRO_ENABLE - uint8_t i = cb_head; - if (cb_count) { - do { - if (keyboard_report->keys[i] == code) { - keyboard_report->keys[i] = 0; - cb_count--; - if (cb_count == 0) { - // reset head and tail - cb_tail = cb_head = 0; - } - if (i == RO_DEC(cb_tail)) { - // left shift when next to tail - do { - cb_tail = RO_DEC(cb_tail); - if (keyboard_report->keys[RO_DEC(cb_tail)] != 0) { - break; - } - } while (cb_tail != cb_head); - } - break; - } - i = RO_INC(i); - } while (i != cb_tail); - } -#else - for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { - if (keyboard_report->keys[i] == code) { - keyboard_report->keys[i] = 0; - } - } -#endif -} - -#ifdef NKRO_ENABLE -static inline void add_key_bit(uint8_t code) -{ - if ((code>>3) < KEYBOARD_REPORT_BITS) { - keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); - } else { - dprintf("add_key_bit: can't add: %02X\n", code); - } -} - -static inline void del_key_bit(uint8_t code) -{ - if ((code>>3) < KEYBOARD_REPORT_BITS) { - keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); - } else { - dprintf("del_key_bit: can't del: %02X\n", code); - } -} -#endif diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index dd0c4c2bf..8fb88c0f6 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h @@ -82,9 +82,7 @@ uint8_t get_oneshot_layer_state(void); bool has_oneshot_layer_timed_out(void); /* inspect */ -uint8_t has_anykey(void); uint8_t has_anymod(void); -uint8_t get_first_key(void); #ifdef __cplusplus } diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c new file mode 100644 index 000000000..0a67b2534 --- /dev/null +++ b/tmk_core/common/report.c @@ -0,0 +1,177 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "report.h" +#include "host.h" +#include "keycode_config.h" +#include "debug.h" +#include "util.h" + +uint8_t has_anykey(report_keyboard_t* keyboard_report) +{ + uint8_t cnt = 0; + for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { + if (keyboard_report->raw[i]) + cnt++; + } + return cnt; +} + +uint8_t get_first_key(report_keyboard_t* keyboard_report) +{ +#ifdef NKRO_ENABLE + if (keyboard_protocol && keymap_config.nkro) { + uint8_t i = 0; + for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) + ; + return i<<3 | biton(keyboard_report->nkro.bits[i]); + } +#endif +#ifdef USB_6KRO_ENABLE + uint8_t i = cb_head; + do { + if (keyboard_report->keys[i] != 0) { + break; + } + i = RO_INC(i); + } while (i != cb_tail); + return keyboard_report->keys[i]; +#else + return keyboard_report->keys[0]; +#endif +} + +void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) +{ +#ifdef USB_6KRO_ENABLE + int8_t i = cb_head; + int8_t empty = -1; + if (cb_count) { + do { + if (keyboard_report->keys[i] == code) { + return; + } + if (empty == -1 && keyboard_report->keys[i] == 0) { + empty = i; + } + i = RO_INC(i); + } while (i != cb_tail); + if (i == cb_tail) { + if (cb_tail == cb_head) { + // buffer is full + if (empty == -1) { + // pop head when has no empty space + cb_head = RO_INC(cb_head); + cb_count--; + } + else { + // left shift when has empty space + uint8_t offset = 1; + i = RO_INC(empty); + do { + if (keyboard_report->keys[i] != 0) { + keyboard_report->keys[empty] = keyboard_report->keys[i]; + keyboard_report->keys[i] = 0; + empty = RO_INC(empty); + } + else { + offset++; + } + i = RO_INC(i); + } while (i != cb_tail); + cb_tail = RO_SUB(cb_tail, offset); + } + } + } + } + // add to tail + keyboard_report->keys[cb_tail] = code; + cb_tail = RO_INC(cb_tail); + cb_count++; +#else + int8_t i = 0; + int8_t empty = -1; + for (; i < KEYBOARD_REPORT_KEYS; i++) { + if (keyboard_report->keys[i] == code) { + break; + } + if (empty == -1 && keyboard_report->keys[i] == 0) { + empty = i; + } + } + if (i == KEYBOARD_REPORT_KEYS) { + if (empty != -1) { + keyboard_report->keys[empty] = code; + } + } +#endif +} + +void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) +{ +#ifdef USB_6KRO_ENABLE + uint8_t i = cb_head; + if (cb_count) { + do { + if (keyboard_report->keys[i] == code) { + keyboard_report->keys[i] = 0; + cb_count--; + if (cb_count == 0) { + // reset head and tail + cb_tail = cb_head = 0; + } + if (i == RO_DEC(cb_tail)) { + // left shift when next to tail + do { + cb_tail = RO_DEC(cb_tail); + if (keyboard_report->keys[RO_DEC(cb_tail)] != 0) { + break; + } + } while (cb_tail != cb_head); + } + break; + } + i = RO_INC(i); + } while (i != cb_tail); + } +#else + for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { + if (keyboard_report->keys[i] == code) { + keyboard_report->keys[i] = 0; + } + } +#endif +} + +#ifdef NKRO_ENABLE +void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) +{ + if ((code>>3) < KEYBOARD_REPORT_BITS) { + keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); + } else { + dprintf("add_key_bit: can't add: %02X\n", code); + } +} + +void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) +{ + if ((code>>3) < KEYBOARD_REPORT_BITS) { + keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); + } else { + dprintf("del_key_bit: can't del: %02X\n", code); + } +} +#endif diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 8fb28b6ce..30ce80542 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -174,6 +174,16 @@ typedef struct { (key == KC_WWW_REFRESH ? AC_REFRESH : \ (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))) +uint8_t has_anykey(report_keyboard_t* keyboard_report); +uint8_t get_first_key(report_keyboard_t* keyboard_report); + +void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code); +void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code); +#ifdef NKRO_ENABLE +void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code); +void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code); +#endif + #ifdef __cplusplus } #endif From fb95d86b39074b581455fb35a17477cce79a3738 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 17:55:44 +0300 Subject: [PATCH 18/26] Move functions for adding keys from to reports to report.h --- tmk_core/common/action_util.c | 32 -------------------------------- tmk_core/common/action_util.h | 14 +++++++++++--- tmk_core/common/report.c | 30 ++++++++++++++++++++++++++++++ tmk_core/common/report.h | 4 ++++ 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 511649676..f76398fb9 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -136,38 +136,6 @@ void send_keyboard_report(void) { host_keyboard_send(keyboard_report); } -/* key */ -void add_key(uint8_t key) -{ -#ifdef NKRO_ENABLE - if (keyboard_protocol && keymap_config.nkro) { - add_key_bit(keyboard_report, key); - return; - } -#endif - add_key_byte(keyboard_report, key); -} - -void del_key(uint8_t key) -{ -#ifdef NKRO_ENABLE - if (keyboard_protocol && keymap_config.nkro) { - del_key_bit(keyboard_report, key); - return; - } -#endif - del_key_byte(keyboard_report, key); -} - -void clear_keys(void) -{ - // not clear mods - for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { - keyboard_report->raw[i] = 0; - } -} - - /* modifier */ uint8_t get_mods(void) { return real_mods; } void add_mods(uint8_t mods) { real_mods |= mods; } diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index 8fb88c0f6..345893151 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h @@ -29,9 +29,17 @@ extern report_keyboard_t *keyboard_report; void send_keyboard_report(void); /* key */ -void add_key(uint8_t key); -void del_key(uint8_t key); -void clear_keys(void); +inline void add_key(uint8_t key) { + add_key_to_report(keyboard_report, key); +} + +inline void del_key(uint8_t key) { + del_key_from_report(keyboard_report, key); +} + +inline void clear_keys(void) { + clear_keys_from_report(keyboard_report); +} /* modifier */ uint8_t get_mods(void); diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c index 0a67b2534..74c6d3fdd 100644 --- a/tmk_core/common/report.c +++ b/tmk_core/common/report.c @@ -175,3 +175,33 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) } } #endif + +void add_key_to_report(report_keyboard_t* keyboard_report, int8_t key) +{ +#ifdef NKRO_ENABLE + if (keyboard_protocol && keymap_config.nkro) { + add_key_bit(keyboard_report, key); + return; + } +#endif + add_key_byte(keyboard_report, key); +} + +void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) +{ +#ifdef NKRO_ENABLE + if (keyboard_protocol && keymap_config.nkro) { + del_key_bit(keyboard_report, key); + return; + } +#endif + del_key_byte(keyboard_report, key); +} + +void clear_keys_from_report(report_keyboard_t* keyboard_report) +{ + // not clear mods + for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { + keyboard_report->raw[i] = 0; + } +} \ No newline at end of file diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 30ce80542..899fc524c 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -184,6 +184,10 @@ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code); void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code); #endif +void add_key_to_report(report_keyboard_t* keyboard_report, int8_t key); +void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key); +void clear_keys_from_report(report_keyboard_t* keyboard_report); + #ifdef __cplusplus } #endif From bd1729d5be376fecae67ab5ddc92eab82416a5c1 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 18:18:15 +0300 Subject: [PATCH 19/26] Actually test for correct key presses --- build_full_test.mk | 3 +- tests/basic/test.cpp | 8 +++- tests/test_common/keyboard_report_util.cpp | 47 ++++++++++++++++++++++ tests/test_common/keyboard_report_util.h | 39 ++++++++++++++++++ tests/test_common/test_driver.cpp | 6 +-- tests/test_common/test_driver.h | 5 ++- 6 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 tests/test_common/keyboard_report_util.cpp create mode 100644 tests/test_common/keyboard_report_util.h diff --git a/build_full_test.mk b/build_full_test.mk index 5f9bbe5e6..67c1ca5e5 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -22,7 +22,8 @@ $(TEST)_SRC= \ $(TMK_COMMON_SRC) \ $(QUANTUM_SRC) \ tests/test_common/matrix.c \ - tests/test_common/test_driver.cpp + tests/test_common/test_driver.cpp \ + tests/test_common/keyboard_report_util.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index e3190085d..804642eae 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -21,6 +21,7 @@ #include "keyboard.h" #include "test_driver.h" #include "test_matrix.h" +#include "keyboard_report_util.h" using testing::_; using testing::Return; @@ -32,7 +33,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, }; -TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { +TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); @@ -41,12 +42,15 @@ TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { keyboard_task(); } -TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { +TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); +} EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_task(); } diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp new file mode 100644 index 000000000..70fc1c048 --- /dev/null +++ b/tests/test_common/keyboard_report_util.cpp @@ -0,0 +1,47 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + #include "keyboard_report_util.h" + using namespace testing; + +bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { + return memcmp(lhs.raw, rhs.raw, sizeof(lhs.raw))==0; +} + +std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { + stream << "Keyboard report:" << std::endl; + stream << (uint32_t)value.keys[0] << std::endl; + return stream; +} + +KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { + memset(m_report.raw, 0, sizeof(m_report.raw)); + for (auto k: keys) { + add_key_to_report(&m_report, k); + } +} + +bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { + return m_report == report; +} + +void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { + *os << "is equal to " << m_report; +} + +void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << "is not equal to " << m_report; +} \ No newline at end of file diff --git a/tests/test_common/keyboard_report_util.h b/tests/test_common/keyboard_report_util.h new file mode 100644 index 000000000..48543c205 --- /dev/null +++ b/tests/test_common/keyboard_report_util.h @@ -0,0 +1,39 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include "report.h" +#include +#include "gmock/gmock.h" + +bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs); +std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value); + +class KeyboardReportMatcher : public testing::MatcherInterface { + public: + KeyboardReportMatcher(const std::vector& keys); + virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override; + virtual void DescribeTo(::std::ostream* os) const override; + virtual void DescribeNegationTo(::std::ostream* os) const override; +private: + report_keyboard_t m_report; +}; + + +template +inline testing::Matcher KeyboardReport(Ts... keys) { + return testing::MakeMatcher(new KeyboardReportMatcher(std::vector({keys...}))); +} \ No newline at end of file diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 7c67f5776..9e618aa97 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -41,12 +41,12 @@ uint8_t TestDriver::keyboard_leds(void) { } void TestDriver::send_keyboard(report_keyboard_t* report) { - m_this->send_keyboard_mock(report); + m_this->send_keyboard_mock(*report); } void TestDriver::send_mouse(report_mouse_t* report) { - m_this->send_mouse_mock(report); + m_this->send_mouse_mock(*report); } void TestDriver::send_system(uint16_t data) { @@ -54,5 +54,5 @@ void TestDriver::send_system(uint16_t data) { } void TestDriver::send_consumer(uint16_t data) { - m_this->send_consumer_mock(data); + m_this->send_consumer(data); } diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h index d5b831884..b1b95fbcc 100644 --- a/tests/test_common/test_driver.h +++ b/tests/test_common/test_driver.h @@ -20,6 +20,7 @@ #include "gmock/gmock.h" #include #include "host.h" +#include "keyboard_report_util.h" class TestDriver { @@ -27,8 +28,8 @@ public: TestDriver(); ~TestDriver(); MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); - MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t*)); - MOCK_METHOD1(send_mouse_mock, void (report_mouse_t*)); + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); + MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); MOCK_METHOD1(send_system_mock, void (uint16_t)); MOCK_METHOD1(send_consumer_mock, void (uint16_t)); private: From 6a76192fa4bb8c5757c32cf3c65c4e7e7f6c7c3e Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 14:39:58 +0300 Subject: [PATCH 20/26] Fix problems with undefined inlines in debug mode --- tmk_core/common/action_util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index f76398fb9..148162a51 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -43,6 +43,10 @@ static int8_t cb_count = 0; //report_keyboard_t keyboard_report = {}; report_keyboard_t *keyboard_report = &(report_keyboard_t){}; +extern inline void add_key(uint8_t key); +extern inline void del_key(uint8_t key); +extern inline void clear_keys(void); + #ifndef NO_ACTION_ONESHOT static int8_t oneshot_mods = 0; static int8_t oneshot_locked_mods = 0; From e85b1857968d4c0378b9778650c30b9d2bca3ea9 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 14:40:22 +0300 Subject: [PATCH 21/26] Test two keys pressed at once --- tests/basic/test.cpp | 16 +++++++++++- tests/test_common/keyboard_report_util.cpp | 30 ++++++++++++++++++++-- tests/test_common/matrix.c | 2 ++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 804642eae..398063fca 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -51,6 +51,20 @@ TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } - EXPECT_CALL(driver, send_keyboard_mock(_)); + +TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_init(); + press_key(1, 0); + press_key(0, 1); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + //TODO: This is a left-over from the previous test and need to be fixed + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); + //Note that QMK only processes one key at a time + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); keyboard_task(); } diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index 70fc1c048..34e53cd4c 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -15,15 +15,41 @@ */ #include "keyboard_report_util.h" + #include + #include using namespace testing; + namespace + { + std::vector get_keys(const report_keyboard_t& report) { + std::vector result; + #if defined(NKRO_ENABLE) + #error NKRO support not implemented yet + #elif defined(USB_6KRO_ENABLE) + #error 6KRO support not implemented yet + #else + for(size_t i=0; i static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { + memset(matrix, 0, sizeof(matrix)); matrix_init_quantum(); } From 36f820be7e80bc8f1f5489373708356cf142c269 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 23:49:38 +0300 Subject: [PATCH 22/26] Add a test fixture It only initializes QMK once, and clears the matrix after each test. --- build_full_test.mk | 3 ++- tests/basic/test.cpp | 19 +++++---------- tests/test_common/matrix.c | 6 ++++- tests/test_common/test_fixture.cpp | 38 ++++++++++++++++++++++++++++++ tests/test_common/test_fixture.h | 28 ++++++++++++++++++++++ tests/test_common/test_matrix.h | 1 + 6 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 tests/test_common/test_fixture.cpp create mode 100644 tests/test_common/test_fixture.h diff --git a/build_full_test.mk b/build_full_test.mk index 67c1ca5e5..bfd89174d 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -23,7 +23,8 @@ $(TEST)_SRC= \ $(QUANTUM_SRC) \ tests/test_common/matrix.c \ tests/test_common/test_driver.cpp \ - tests/test_common/keyboard_report_util.cpp + tests/test_common/keyboard_report_util.cpp \ + tests/test_common/test_fixture.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 398063fca..26a09585c 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -18,10 +18,10 @@ #include "gmock/gmock.h" #include "quantum.h" -#include "keyboard.h" #include "test_driver.h" #include "test_matrix.h" #include "keyboard_report_util.h" +#include "test_fixture.h" using testing::_; using testing::Return; @@ -33,35 +33,28 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, }; -TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { +class KeyPress : public TestFixture {}; + +TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } -TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { +TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } -TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { +TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_init(); press_key(1, 0); press_key(0, 1); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); - //TODO: This is a left-over from the previous test and need to be fixed - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 5ab5bac6c..0d9fa68b0 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -22,7 +22,7 @@ static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { - memset(matrix, 0, sizeof(matrix)); + clear_all_keys(); matrix_init_quantum(); } @@ -54,3 +54,7 @@ void press_key(uint8_t col, uint8_t row) { void release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); } + +void clear_all_keys(void) { + memset(matrix, 0, sizeof(matrix)); +} diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp new file mode 100644 index 000000000..aff518d21 --- /dev/null +++ b/tests/test_common/test_fixture.cpp @@ -0,0 +1,38 @@ +#include "test_fixture.h" +#include "gmock/gmock.h" +#include "test_driver.h" +#include "test_matrix.h" +#include "keyboard.h" + +using testing::_; +using testing::AnyNumber; +using testing::Return; +using testing::Between; + +void TestFixture::SetUpTestCase() { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); +} + +void TestFixture::TearDownTestCase() { +} + +TestFixture::TestFixture() { +} + +TestFixture::~TestFixture() { + TestDriver driver; + clear_all_keys(); + // Run for a while to make sure all keys are completely released + // Should probably wait until tapping term etc, has timed out + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + for (int i=0; i<100; i++) { + keyboard_task(); + } + testing::Mock::VerifyAndClearExpectations(&driver); + // Verify that the matrix really is cleared + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); +} \ No newline at end of file diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.h new file mode 100644 index 000000000..a775a425a --- /dev/null +++ b/tests/test_common/test_fixture.h @@ -0,0 +1,28 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + #pragma once + +#include "gtest/gtest.h" + +class TestFixture : public testing::Test { +public: + TestFixture(); + ~TestFixture(); + static void SetUpTestCase(); + static void TearDownTestCase(); + +}; \ No newline at end of file diff --git a/tests/test_common/test_matrix.h b/tests/test_common/test_matrix.h index afc65c556..174fc4f22 100644 --- a/tests/test_common/test_matrix.h +++ b/tests/test_common/test_matrix.h @@ -23,6 +23,7 @@ extern "C" { void press_key(uint8_t col, uint8_t row); void release_key(uint8_t col, uint8_t row); +void clear_all_keys(void); #ifdef __cplusplus } From 43d8fa5bf1248ce5c1ce5f9cb0d238d794b4475d Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:19:09 +0300 Subject: [PATCH 23/26] More natural interface for setting keyboard leds --- tests/basic/test.cpp | 3 --- tests/test_common/test_driver.cpp | 3 +-- tests/test_common/test_driver.h | 4 +++- tests/test_common/test_fixture.cpp | 2 -- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 26a09585c..1bd5c2762 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -37,7 +37,6 @@ class KeyPress : public TestFixture {}; TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } @@ -45,7 +44,6 @@ TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; press_key(0, 0); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } @@ -54,7 +52,6 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; press_key(1, 0); press_key(0, 1); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 9e618aa97..feb80563a 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -27,7 +27,6 @@ TestDriver::TestDriver() &TestDriver::send_consumer } { - host_set_driver(&m_driver); m_this = this; } @@ -37,7 +36,7 @@ TestDriver::~TestDriver() { } uint8_t TestDriver::keyboard_leds(void) { - return m_this->keyboard_leds_mock(); + return m_this->m_leds; } void TestDriver::send_keyboard(report_keyboard_t* report) { diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h index b1b95fbcc..0123fd539 100644 --- a/tests/test_common/test_driver.h +++ b/tests/test_common/test_driver.h @@ -27,7 +27,8 @@ class TestDriver { public: TestDriver(); ~TestDriver(); - MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); + void set_leds(uint8_t leds) { m_leds = leds; } + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); MOCK_METHOD1(send_system_mock, void (uint16_t)); @@ -39,6 +40,7 @@ private: static void send_system(uint16_t data); static void send_consumer(uint16_t data); host_driver_t m_driver; + uint8_t m_leds = 0; static TestDriver* m_this; }; diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index aff518d21..eef9b854b 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -27,12 +27,10 @@ TestFixture::~TestFixture() { // Run for a while to make sure all keys are completely released // Should probably wait until tapping term etc, has timed out EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); for (int i=0; i<100; i++) { keyboard_task(); } testing::Mock::VerifyAndClearExpectations(&driver); // Verify that the matrix really is cleared EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); } \ No newline at end of file From fb9b8dadb97e69f2c206a96e879a9350b535fe98 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:22:12 +0300 Subject: [PATCH 24/26] Add a couple of todos to keyboard_report_util.cpp Also print the modifier state --- tests/test_common/keyboard_report_util.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index 34e53cd4c..aca4433dd 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -47,6 +47,8 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { stream << "Keyboard report:" << std::endl; + stream << "Mods: " << value.mods << std::endl; + // TODO: This should probably print friendly names for the keys for (uint32_t k: get_keys(value)) { stream << k << std::endl; } @@ -54,6 +56,7 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { } KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { + // TODO: Support modifiers memset(m_report.raw, 0, sizeof(m_report.raw)); for (auto k: keys) { add_key_to_report(&m_report, k); From 0f163c00287070e0314a984f2b58da4a58621058 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:24:32 +0300 Subject: [PATCH 25/26] Add todo to timer.c --- tmk_core/common/test/timer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tmk_core/common/test/timer.c b/tmk_core/common/test/timer.c index e21cd7d55..09ea91a89 100644 --- a/tmk_core/common/test/timer.c +++ b/tmk_core/common/test/timer.c @@ -16,6 +16,9 @@ #include "timer.h" +// TODO: the timer should work, but at a much faster rate than realtime +// It should also have some kind of integration with the testing system + void timer_init(void) {} void timer_clear(void) {} From 1aa0be4cf1d00f852150e2b2ed5e4c151aeeef3a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:46:53 +0300 Subject: [PATCH 26/26] Fix serial_link vpath problem --- common.mk | 3 +-- common_features.mk | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common.mk b/common.mk index 70f7ae099..f87c20934 100644 --- a/common.mk +++ b/common.mk @@ -17,5 +17,4 @@ COMMON_VPATH += $(QUANTUM_PATH) COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras COMMON_VPATH += $(QUANTUM_PATH)/audio COMMON_VPATH += $(QUANTUM_PATH)/process_keycode -COMMON_VPATH += $(QUANTUM_PATH)/api -COMMON_VPATH += $(SERIAL_PATH) +COMMON_VPATH += $(QUANTUM_PATH)/api \ No newline at end of file diff --git a/common_features.mk b/common_features.mk index a8a52afb9..f5e7af01f 100644 --- a/common_features.mk +++ b/common_features.mk @@ -18,6 +18,7 @@ SERIAL_PATH := $(QUANTUM_PATH)/serial_link SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) SERIAL_DEFS += -DSERIAL_LINK_ENABLE +COMMON_VPATH += $(SERIAL_PATH) ifeq ($(strip $(API_SYSEX_ENABLE)), yes) OPT_DEFS += -DAPI_SYSEX_ENABLE