aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-06-19 14:04:19 -0400
committerGitHub <noreply@github.com>2017-06-19 14:04:19 -0400
commite951317acbad8ef67a9da13b657e13e6c1d27e1d (patch)
treea9c616a4a7d91eaf38bef570c9487493ca2b2c2e
parent621ae42a6cb9f96b8c02a0094b36daf125c4e6ca (diff)
parent1aa0be4cf1d00f852150e2b2ed5e4c151aeeef3a (diff)
downloadqmk_firmware-e951317acbad8ef67a9da13b657e13e6c1d27e1d.tar.gz
qmk_firmware-e951317acbad8ef67a9da13b657e13e6c1d27e1d.zip
Merge pull request #1409 from fredizzimo/full_unit_test
Take first baby steps towards testing the whole QMK
-rw-r--r--Makefile2
-rw-r--r--build_full_test.mk30
-rw-r--r--build_keyboard.mk137
-rw-r--r--build_test.mk10
-rw-r--r--common.mk9
-rw-r--r--common_features.mk153
-rw-r--r--testlist.mk4
-rw-r--r--tests/basic/config.h24
-rw-r--r--tests/basic/rules.mk16
-rw-r--r--tests/basic/test.cpp60
-rw-r--r--tests/test_common/keyboard_report_util.cpp76
-rw-r--r--tests/test_common/keyboard_report_util.h39
-rw-r--r--tests/test_common/matrix.c60
-rw-r--r--tests/test_common/test_driver.cpp57
-rw-r--r--tests/test_common/test_driver.h48
-rw-r--r--tests/test_common/test_fixture.cpp36
-rw-r--r--tests/test_common/test_fixture.h28
-rw-r--r--tests/test_common/test_matrix.h32
-rw-r--r--tmk_core/common.mk7
-rw-r--r--tmk_core/common/action_util.c204
-rw-r--r--tmk_core/common/action_util.h16
-rw-r--r--tmk_core/common/eeprom.h2
-rw-r--r--tmk_core/common/progmem.h2
-rw-r--r--tmk_core/common/report.c207
-rw-r--r--tmk_core/common/report.h14
-rw-r--r--tmk_core/common/test/bootloader.c19
-rw-r--r--tmk_core/common/test/eeprom.c98
-rw-r--r--tmk_core/common/test/suspend.c17
-rw-r--r--tmk_core/common/test/timer.c30
-rw-r--r--tmk_core/common/wait.h9
30 files changed, 1095 insertions, 351 deletions
diff --git a/Makefile b/Makefile
index 6a93692bf..f789409b7 100644
--- a/Makefile
+++ b/Makefile
@@ -419,7 +419,7 @@ define BUILD_TEST
419 MAKE_TARGET := $2 419 MAKE_TARGET := $2
420 COMMAND := $1 420 COMMAND := $1
421 MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET) 421 MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET)
422 MAKE_VARS := TEST=$$(TEST_NAME) 422 MAKE_VARS := TEST=$$(TEST_NAME) FULL_TESTS=$$(FULL_TESTS)
423 MAKE_MSG := $$(MSG_MAKE_TEST) 423 MAKE_MSG := $$(MSG_MAKE_TEST)
424 $$(eval $$(call BUILD)) 424 $$(eval $$(call BUILD))
425 ifneq ($$(MAKE_TARGET),clean) 425 ifneq ($$(MAKE_TARGET),clean)
diff --git a/build_full_test.mk b/build_full_test.mk
new file mode 100644
index 000000000..bfd89174d
--- /dev/null
+++ b/build_full_test.mk
@@ -0,0 +1,30 @@
1# Copyright 2017 Fred Sundvik
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16#include $(TMK_PATH)/protocol.mk
17
18TEST_PATH=tests/$(TEST)
19
20$(TEST)_SRC= \
21 $(TEST_PATH)/test.cpp \
22 $(TMK_COMMON_SRC) \
23 $(QUANTUM_SRC) \
24 tests/test_common/matrix.c \
25 tests/test_common/test_driver.cpp \
26 tests/test_common/keyboard_report_util.cpp \
27 tests/test_common/test_fixture.cpp
28$(TEST)_DEFS=$(TMK_COMMON_DEFS)
29$(TEST)_CONFIG=$(TEST_PATH)/config.h
30VPATH+=$(TOP_DIR)/tests/test_common
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 36eab3a9e..3ec389ac9 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -31,8 +31,6 @@ $(error MASTER does not have a valid value(left/right))
31 endif 31 endif
32endif 32endif
33 33
34
35
36KEYBOARD_PATH := keyboards/$(KEYBOARD) 34KEYBOARD_PATH := keyboards/$(KEYBOARD)
37KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c 35KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c
38 36
@@ -42,7 +40,6 @@ else
42 $(error "$(KEYBOARD_C)" does not exist) 40 $(error "$(KEYBOARD_C)" does not exist)
43endif 41endif
44 42
45
46ifneq ($(SUBPROJECT),) 43ifneq ($(SUBPROJECT),)
47 SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT) 44 SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT)
48 SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c 45 SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c
@@ -118,141 +115,12 @@ endif
118# # project specific files 115# # project specific files
119SRC += $(KEYBOARD_C) \ 116SRC += $(KEYBOARD_C) \
120 $(KEYMAP_C) \ 117 $(KEYMAP_C) \
121 $(QUANTUM_DIR)/quantum.c \ 118 $(QUANTUM_SRC)
122 $(QUANTUM_DIR)/keymap_common.c \
123 $(QUANTUM_DIR)/keycode_config.c \
124 $(QUANTUM_DIR)/process_keycode/process_leader.c
125 119
126ifneq ($(SUBPROJECT),) 120ifneq ($(SUBPROJECT),)
127 SRC += $(SUBPROJECT_C) 121 SRC += $(SUBPROJECT_C)
128endif 122endif
129 123
130ifndef CUSTOM_MATRIX
131 SRC += $(QUANTUM_DIR)/matrix.c
132endif
133
134ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
135 OPT_DEFS += -DAPI_SYSEX_ENABLE
136 SRC += $(QUANTUM_DIR)/api/api_sysex.c
137 OPT_DEFS += -DAPI_ENABLE
138 SRC += $(QUANTUM_DIR)/api.c
139 MIDI_ENABLE=yes
140endif
141
142MUSIC_ENABLE := 0
143
144ifeq ($(strip $(AUDIO_ENABLE)), yes)
145 OPT_DEFS += -DAUDIO_ENABLE
146 MUSIC_ENABLE := 1
147 SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c
148 SRC += $(QUANTUM_DIR)/audio/audio.c
149 SRC += $(QUANTUM_DIR)/audio/voices.c
150 SRC += $(QUANTUM_DIR)/audio/luts.c
151endif
152
153ifeq ($(strip $(MIDI_ENABLE)), yes)
154 OPT_DEFS += -DMIDI_ENABLE
155 MUSIC_ENABLE := 1
156 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
157endif
158
159ifeq ($(MUSIC_ENABLE), 1)
160 SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
161endif
162
163ifeq ($(strip $(COMBO_ENABLE)), yes)
164 OPT_DEFS += -DCOMBO_ENABLE
165 SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c
166endif
167
168ifeq ($(strip $(VIRTSER_ENABLE)), yes)
169 OPT_DEFS += -DVIRTSER_ENABLE
170endif
171
172ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
173 OPT_DEFS += -DFAUXCLICKY_ENABLE
174 SRC += $(QUANTUM_DIR)/fauxclicky.c
175endif
176
177ifeq ($(strip $(UCIS_ENABLE)), yes)
178 OPT_DEFS += -DUCIS_ENABLE
179 UNICODE_COMMON = yes
180 SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
181endif
182
183ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
184 OPT_DEFS += -DUNICODEMAP_ENABLE
185 UNICODE_COMMON = yes
186 SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
187endif
188
189ifeq ($(strip $(UNICODE_ENABLE)), yes)
190 OPT_DEFS += -DUNICODE_ENABLE
191 UNICODE_COMMON = yes
192 SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
193endif
194
195ifeq ($(strip $(UNICODE_COMMON)), yes)
196 SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c
197endif
198
199ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
200 OPT_DEFS += -DRGBLIGHT_ENABLE
201 SRC += $(QUANTUM_DIR)/light_ws2812.c
202 SRC += $(QUANTUM_DIR)/rgblight.c
203 CIE1931_CURVE = yes
204 LED_BREATHING_TABLE = yes
205endif
206
207ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
208 OPT_DEFS += -DTAP_DANCE_ENABLE
209 SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
210endif
211
212ifeq ($(strip $(PRINTING_ENABLE)), yes)
213 OPT_DEFS += -DPRINTING_ENABLE
214 SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c
215 SRC += $(TMK_DIR)/protocol/serial_uart.c
216endif
217
218ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
219 SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
220 OPT_DEFS += $(SERIAL_DEFS)
221 VAPTH += $(SERIAL_PATH)
222endif
223
224ifneq ($(strip $(VARIABLE_TRACE)),)
225 SRC += $(QUANTUM_DIR)/variable_trace.c
226 OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
227ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
228 OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
229endif
230endif
231
232ifeq ($(strip $(LCD_ENABLE)), yes)
233 CIE1931_CURVE = yes
234endif
235
236ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
237 ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
238 CIE1931_CURVE = yes
239 endif
240endif
241
242ifeq ($(strip $(CIE1931_CURVE)), yes)
243 OPT_DEFS += -DUSE_CIE1931_CURVE
244 LED_TABLES = yes
245endif
246
247ifeq ($(strip $(LED_BREATHING_TABLE)), yes)
248 OPT_DEFS += -DUSE_LED_BREATHING_TABLE
249 LED_TABLES = yes
250endif
251
252ifeq ($(strip $(LED_TABLES)), yes)
253 SRC += $(QUANTUM_DIR)/led_tables.c
254endif
255
256# Optimize size but this may cause error "relocation truncated to fit" 124# Optimize size but this may cause error "relocation truncated to fit"
257#EXTRALDFLAGS = -Wl,--relax 125#EXTRALDFLAGS = -Wl,--relax
258 126
@@ -264,9 +132,10 @@ endif
264VPATH += $(KEYBOARD_PATH) 132VPATH += $(KEYBOARD_PATH)
265VPATH += $(COMMON_VPATH) 133VPATH += $(COMMON_VPATH)
266 134
135include common_features.mk
267include $(TMK_PATH)/protocol.mk 136include $(TMK_PATH)/protocol.mk
268
269include $(TMK_PATH)/common.mk 137include $(TMK_PATH)/common.mk
138
270SRC += $(TMK_COMMON_SRC) 139SRC += $(TMK_COMMON_SRC)
271OPT_DEFS += $(TMK_COMMON_DEFS) 140OPT_DEFS += $(TMK_COMMON_DEFS)
272EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS) 141EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)
diff --git a/build_test.mk b/build_test.mk
index ee15a4572..cac2cba50 100644
--- a/build_test.mk
+++ b/build_test.mk
@@ -40,13 +40,23 @@ VPATH +=\
40all: elf 40all: elf
41 41
42VPATH += $(COMMON_VPATH) 42VPATH += $(COMMON_VPATH)
43PLATFORM:=TEST
43 44
45ifneq ($(filter $(FULL_TESTS),$(TEST)),)
46include tests/$(TEST)/rules.mk
47endif
48
49include common_features.mk
44include $(TMK_PATH)/common.mk 50include $(TMK_PATH)/common.mk
45include $(QUANTUM_PATH)/serial_link/tests/rules.mk 51include $(QUANTUM_PATH)/serial_link/tests/rules.mk
52ifneq ($(filter $(FULL_TESTS),$(TEST)),)
53include build_full_test.mk
54endif
46 55
47$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) 56$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC)
48$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) 57$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC)
49$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS) 58$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS)
59$(TEST_OBJ)/$(TEST)_CONFIG := $($(TEST)_CONFIG)
50 60
51include $(TMK_PATH)/native.mk 61include $(TMK_PATH)/native.mk
52include $(TMK_PATH)/rules.mk 62include $(TMK_PATH)/rules.mk
diff --git a/common.mk b/common.mk
index c4b9394a2..f87c20934 100644
--- a/common.mk
+++ b/common.mk
@@ -11,17 +11,10 @@ QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)
11 11
12BUILD_DIR := $(TOP_DIR)/.build 12BUILD_DIR := $(TOP_DIR)/.build
13 13
14SERIAL_DIR := $(QUANTUM_DIR)/serial_link
15SERIAL_PATH := $(QUANTUM_PATH)/serial_link
16SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c)
17SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
18SERIAL_DEFS += -DSERIAL_LINK_ENABLE
19
20COMMON_VPATH := $(TOP_DIR) 14COMMON_VPATH := $(TOP_DIR)
21COMMON_VPATH += $(TMK_PATH) 15COMMON_VPATH += $(TMK_PATH)
22COMMON_VPATH += $(QUANTUM_PATH) 16COMMON_VPATH += $(QUANTUM_PATH)
23COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras 17COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras
24COMMON_VPATH += $(QUANTUM_PATH)/audio 18COMMON_VPATH += $(QUANTUM_PATH)/audio
25COMMON_VPATH += $(QUANTUM_PATH)/process_keycode 19COMMON_VPATH += $(QUANTUM_PATH)/process_keycode
26COMMON_VPATH += $(QUANTUM_PATH)/api 20COMMON_VPATH += $(QUANTUM_PATH)/api \ No newline at end of file
27COMMON_VPATH += $(SERIAL_PATH) \ No newline at end of file
diff --git a/common_features.mk b/common_features.mk
new file mode 100644
index 000000000..f5e7af01f
--- /dev/null
+++ b/common_features.mk
@@ -0,0 +1,153 @@
1# Copyright 2017 Fred Sundvik
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16SERIAL_DIR := $(QUANTUM_DIR)/serial_link
17SERIAL_PATH := $(QUANTUM_PATH)/serial_link
18SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c)
19SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
20SERIAL_DEFS += -DSERIAL_LINK_ENABLE
21COMMON_VPATH += $(SERIAL_PATH)
22
23ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
24 OPT_DEFS += -DAPI_SYSEX_ENABLE
25 SRC += $(QUANTUM_DIR)/api/api_sysex.c
26 OPT_DEFS += -DAPI_ENABLE
27 SRC += $(QUANTUM_DIR)/api.c
28 MIDI_ENABLE=yes
29endif
30
31MUSIC_ENABLE := 0
32
33ifeq ($(strip $(AUDIO_ENABLE)), yes)
34 OPT_DEFS += -DAUDIO_ENABLE
35 MUSIC_ENABLE := 1
36 SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c
37 SRC += $(QUANTUM_DIR)/audio/audio.c
38 SRC += $(QUANTUM_DIR)/audio/voices.c
39 SRC += $(QUANTUM_DIR)/audio/luts.c
40endif
41
42ifeq ($(strip $(MIDI_ENABLE)), yes)
43 OPT_DEFS += -DMIDI_ENABLE
44 MUSIC_ENABLE := 1
45 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
46endif
47
48ifeq ($(MUSIC_ENABLE), 1)
49 SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
50endif
51
52ifeq ($(strip $(COMBO_ENABLE)), yes)
53 OPT_DEFS += -DCOMBO_ENABLE
54 SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c
55endif
56
57ifeq ($(strip $(VIRTSER_ENABLE)), yes)
58 OPT_DEFS += -DVIRTSER_ENABLE
59endif
60
61ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
62 OPT_DEFS += -DFAUXCLICKY_ENABLE
63 SRC += $(QUANTUM_DIR)/fauxclicky.c
64endif
65
66ifeq ($(strip $(UCIS_ENABLE)), yes)
67 OPT_DEFS += -DUCIS_ENABLE
68 UNICODE_COMMON = yes
69 SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
70endif
71
72ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
73 OPT_DEFS += -DUNICODEMAP_ENABLE
74 UNICODE_COMMON = yes
75 SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
76endif
77
78ifeq ($(strip $(UNICODE_ENABLE)), yes)
79 OPT_DEFS += -DUNICODE_ENABLE
80 UNICODE_COMMON = yes
81 SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
82endif
83
84ifeq ($(strip $(UNICODE_COMMON)), yes)
85 SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c
86endif
87
88ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
89 OPT_DEFS += -DRGBLIGHT_ENABLE
90 SRC += $(QUANTUM_DIR)/light_ws2812.c
91 SRC += $(QUANTUM_DIR)/rgblight.c
92 CIE1931_CURVE = yes
93 LED_BREATHING_TABLE = yes
94endif
95
96ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
97 OPT_DEFS += -DTAP_DANCE_ENABLE
98 SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
99endif
100
101ifeq ($(strip $(PRINTING_ENABLE)), yes)
102 OPT_DEFS += -DPRINTING_ENABLE
103 SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c
104 SRC += $(TMK_DIR)/protocol/serial_uart.c
105endif
106
107ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
108 SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
109 OPT_DEFS += $(SERIAL_DEFS)
110 VAPTH += $(SERIAL_PATH)
111endif
112
113ifneq ($(strip $(VARIABLE_TRACE)),)
114 SRC += $(QUANTUM_DIR)/variable_trace.c
115 OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
116ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
117 OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
118endif
119endif
120
121ifeq ($(strip $(LCD_ENABLE)), yes)
122 CIE1931_CURVE = yes
123endif
124
125ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
126 ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
127 CIE1931_CURVE = yes
128 endif
129endif
130
131ifeq ($(strip $(CIE1931_CURVE)), yes)
132 OPT_DEFS += -DUSE_CIE1931_CURVE
133 LED_TABLES = yes
134endif
135
136ifeq ($(strip $(LED_BREATHING_TABLE)), yes)
137 OPT_DEFS += -DUSE_LED_BREATHING_TABLE
138 LED_TABLES = yes
139endif
140
141ifeq ($(strip $(LED_TABLES)), yes)
142 SRC += $(QUANTUM_DIR)/led_tables.c
143endif
144
145QUANTUM_SRC:= \
146 $(QUANTUM_DIR)/quantum.c \
147 $(QUANTUM_DIR)/keymap_common.c \
148 $(QUANTUM_DIR)/keycode_config.c \
149 $(QUANTUM_DIR)/process_keycode/process_leader.c
150
151ifndef CUSTOM_MATRIX
152 QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
153endif \ No newline at end of file
diff --git a/testlist.mk b/testlist.mk
index 1884d6d3f..d949fb3ea 100644
--- a/testlist.mk
+++ b/testlist.mk
@@ -1,3 +1,6 @@
1TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk)))
2FULL_TESTS := $(TEST_LIST)
3
1include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk 4include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk
2 5
3define VALIDATE_TEST_LIST 6define VALIDATE_TEST_LIST
@@ -10,4 +13,5 @@ define VALIDATE_TEST_LIST
10 endif 13 endif
11endef 14endef
12 15
16
13$(eval $(call VALIDATE_TEST_LIST,$(firstword $(TEST_LIST)),$(wordlist 2,9999,$(TEST_LIST)))) \ No newline at end of file 17$(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..4da8d0425
--- /dev/null
+++ b/tests/basic/config.h
@@ -0,0 +1,24 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef TESTS_BASIC_CONFIG_H_
18#define TESTS_BASIC_CONFIG_H_
19
20#define MATRIX_ROWS 2
21#define MATRIX_COLS 2
22
23
24#endif /* TESTS_BASIC_CONFIG_H_ */
diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk
new file mode 100644
index 000000000..8a906807c
--- /dev/null
+++ b/tests/basic/rules.mk
@@ -0,0 +1,16 @@
1# Copyright 2017 Fred Sundvik
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16CUSTOM_MATRIX=yes \ No newline at end of file
diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp
new file mode 100644
index 000000000..1bd5c2762
--- /dev/null
+++ b/tests/basic/test.cpp
@@ -0,0 +1,60 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "gtest/gtest.h"
18#include "gmock/gmock.h"
19
20#include "quantum.h"
21#include "test_driver.h"
22#include "test_matrix.h"
23#include "keyboard_report_util.h"
24#include "test_fixture.h"
25
26using testing::_;
27using testing::Return;
28
29const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
30 [0] = {
31 {KC_A, KC_B},
32 {KC_C, KC_D}
33 },
34};
35
36class KeyPress : public TestFixture {};
37
38TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
39 TestDriver driver;
40 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
41 keyboard_task();
42}
43
44TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
45 TestDriver driver;
46 press_key(0, 0);
47 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
48 keyboard_task();
49}
50
51TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
52 TestDriver driver;
53 press_key(1, 0);
54 press_key(0, 1);
55 //Note that QMK only processes one key at a time
56 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
57 keyboard_task();
58 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
59 keyboard_task();
60}
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
new file mode 100644
index 000000000..aca4433dd
--- /dev/null
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -0,0 +1,76 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include "keyboard_report_util.h"
18 #include <vector>
19 #include <algorithm>
20 using namespace testing;
21
22 namespace
23 {
24 std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
25 std::vector<uint8_t> result;
26 #if defined(NKRO_ENABLE)
27 #error NKRO support not implemented yet
28 #elif defined(USB_6KRO_ENABLE)
29 #error 6KRO support not implemented yet
30 #else
31 for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) {
32 if (report.keys[i]) {
33 result.emplace_back(report.keys[i]);
34 }
35 }
36 #endif
37 std::sort(result.begin(), result.end());
38 return result;
39 }
40 }
41
42bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
43 auto lhskeys = get_keys(lhs);
44 auto rhskeys = get_keys(rhs);
45 return lhs.mods == rhs.mods && lhskeys == rhskeys;
46}
47
48std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
49 stream << "Keyboard report:" << std::endl;
50 stream << "Mods: " << value.mods << std::endl;
51 // TODO: This should probably print friendly names for the keys
52 for (uint32_t k: get_keys(value)) {
53 stream << k << std::endl;
54 }
55 return stream;
56}
57
58KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
59 // TODO: Support modifiers
60 memset(m_report.raw, 0, sizeof(m_report.raw));
61 for (auto k: keys) {
62 add_key_to_report(&m_report, k);
63 }
64}
65
66bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
67 return m_report == report;
68}
69
70void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const {
71 *os << "is equal to " << m_report;
72}
73
74void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const {
75 *os << "is not equal to " << m_report;
76} \ 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 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18#include "report.h"
19#include <ostream>
20#include "gmock/gmock.h"
21
22bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs);
23std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value);
24
25class KeyboardReportMatcher : public testing::MatcherInterface<report_keyboard_t&> {
26 public:
27 KeyboardReportMatcher(const std::vector<uint8_t>& keys);
28 virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override;
29 virtual void DescribeTo(::std::ostream* os) const override;
30 virtual void DescribeNegationTo(::std::ostream* os) const override;
31private:
32 report_keyboard_t m_report;
33};
34
35
36template<typename... Ts>
37inline testing::Matcher<report_keyboard_t&> KeyboardReport(Ts... keys) {
38 return testing::MakeMatcher(new KeyboardReportMatcher(std::vector<uint8_t>({keys...})));
39} \ No newline at end of file
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c
new file mode 100644
index 000000000..0d9fa68b0
--- /dev/null
+++ b/tests/test_common/matrix.c
@@ -0,0 +1,60 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17
18#include "matrix.h"
19#include "test_matrix.h"
20#include <string.h>
21
22static matrix_row_t matrix[MATRIX_ROWS] = {};
23
24void matrix_init(void) {
25 clear_all_keys();
26 matrix_init_quantum();
27}
28
29uint8_t matrix_scan(void) {
30 matrix_scan_quantum();
31 return 1;
32}
33
34matrix_row_t matrix_get_row(uint8_t row) {
35 return matrix[row];
36}
37
38void matrix_print(void) {
39
40}
41
42void matrix_init_kb(void) {
43
44}
45
46void matrix_scan_kb(void) {
47
48}
49
50void press_key(uint8_t col, uint8_t row) {
51 matrix[row] |= 1 << col;
52}
53
54void release_key(uint8_t col, uint8_t row) {
55 matrix[row] &= ~(1 << col);
56}
57
58void clear_all_keys(void) {
59 memset(matrix, 0, sizeof(matrix));
60}
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
new file mode 100644
index 000000000..feb80563a
--- /dev/null
+++ b/tests/test_common/test_driver.cpp
@@ -0,0 +1,57 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "test_driver.h"
18
19TestDriver* TestDriver::m_this = nullptr;
20
21TestDriver::TestDriver()
22 : m_driver{
23 &TestDriver::keyboard_leds,
24 &TestDriver::send_keyboard,
25 &TestDriver::send_mouse,
26 &TestDriver::send_system,
27 &TestDriver::send_consumer
28 }
29{
30 host_set_driver(&m_driver);
31 m_this = this;
32}
33
34TestDriver::~TestDriver() {
35 m_this = nullptr;
36}
37
38uint8_t TestDriver::keyboard_leds(void) {
39 return m_this->m_leds;
40}
41
42void TestDriver::send_keyboard(report_keyboard_t* report) {
43 m_this->send_keyboard_mock(*report);
44
45}
46
47void TestDriver::send_mouse(report_mouse_t* report) {
48 m_this->send_mouse_mock(*report);
49}
50
51void TestDriver::send_system(uint16_t data) {
52 m_this->send_system_mock(data);
53}
54
55void TestDriver::send_consumer(uint16_t data) {
56 m_this->send_consumer(data);
57}
diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h
new file mode 100644
index 000000000..0123fd539
--- /dev/null
+++ b/tests/test_common/test_driver.h
@@ -0,0 +1,48 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_
18#define TESTS_TEST_COMMON_TEST_DRIVER_H_
19
20#include "gmock/gmock.h"
21#include <stdint.h>
22#include "host.h"
23#include "keyboard_report_util.h"
24
25
26class TestDriver {
27public:
28 TestDriver();
29 ~TestDriver();
30 void set_leds(uint8_t leds) { m_leds = leds; }
31
32 MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&));
33 MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&));
34 MOCK_METHOD1(send_system_mock, void (uint16_t));
35 MOCK_METHOD1(send_consumer_mock, void (uint16_t));
36private:
37 static uint8_t keyboard_leds(void);
38 static void send_keyboard(report_keyboard_t *report);
39 static void send_mouse(report_mouse_t* report);
40 static void send_system(uint16_t data);
41 static void send_consumer(uint16_t data);
42 host_driver_t m_driver;
43 uint8_t m_leds = 0;
44 static TestDriver* m_this;
45};
46
47
48#endif /* TESTS_TEST_COMMON_TEST_DRIVER_H_ */
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
new file mode 100644
index 000000000..eef9b854b
--- /dev/null
+++ b/tests/test_common/test_fixture.cpp
@@ -0,0 +1,36 @@
1#include "test_fixture.h"
2#include "gmock/gmock.h"
3#include "test_driver.h"
4#include "test_matrix.h"
5#include "keyboard.h"
6
7using testing::_;
8using testing::AnyNumber;
9using testing::Return;
10using testing::Between;
11
12void TestFixture::SetUpTestCase() {
13 TestDriver driver;
14 EXPECT_CALL(driver, send_keyboard_mock(_));
15 keyboard_init();
16}
17
18void TestFixture::TearDownTestCase() {
19}
20
21TestFixture::TestFixture() {
22}
23
24TestFixture::~TestFixture() {
25 TestDriver driver;
26 clear_all_keys();
27 // Run for a while to make sure all keys are completely released
28 // Should probably wait until tapping term etc, has timed out
29 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
30 for (int i=0; i<100; i++) {
31 keyboard_task();
32 }
33 testing::Mock::VerifyAndClearExpectations(&driver);
34 // Verify that the matrix really is cleared
35 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1));
36} \ 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 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #pragma once
18
19#include "gtest/gtest.h"
20
21class TestFixture : public testing::Test {
22public:
23 TestFixture();
24 ~TestFixture();
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27
28}; \ No newline at end of file
diff --git a/tests/test_common/test_matrix.h b/tests/test_common/test_matrix.h
new file mode 100644
index 000000000..174fc4f22
--- /dev/null
+++ b/tests/test_common/test_matrix.h
@@ -0,0 +1,32 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef TESTS_TEST_COMMON_TEST_MATRIX_H_
18#define TESTS_TEST_COMMON_TEST_MATRIX_H_
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24void press_key(uint8_t col, uint8_t row);
25void release_key(uint8_t col, uint8_t row);
26void clear_all_keys(void);
27
28#ifdef __cplusplus
29}
30#endif
31
32#endif /* TESTS_TEST_COMMON_TEST_MATRIX_H_ */
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index edec2acb4..75b810d98 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -3,6 +3,8 @@ ifeq ($(PLATFORM),AVR)
3 PLATFORM_COMMON_DIR = $(COMMON_DIR)/avr 3 PLATFORM_COMMON_DIR = $(COMMON_DIR)/avr
4else ifeq ($(PLATFORM),CHIBIOS) 4else ifeq ($(PLATFORM),CHIBIOS)
5 PLATFORM_COMMON_DIR = $(COMMON_DIR)/chibios 5 PLATFORM_COMMON_DIR = $(COMMON_DIR)/chibios
6else
7 PLATFORM_COMMON_DIR = $(COMMON_DIR)/test
6endif 8endif
7 9
8TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ 10TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
@@ -16,6 +18,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
16 $(COMMON_DIR)/debug.c \ 18 $(COMMON_DIR)/debug.c \
17 $(COMMON_DIR)/util.c \ 19 $(COMMON_DIR)/util.c \
18 $(COMMON_DIR)/eeconfig.c \ 20 $(COMMON_DIR)/eeconfig.c \
21 $(COMMON_DIR)/report.c \
19 $(PLATFORM_COMMON_DIR)/suspend.c \ 22 $(PLATFORM_COMMON_DIR)/suspend.c \
20 $(PLATFORM_COMMON_DIR)/timer.c \ 23 $(PLATFORM_COMMON_DIR)/timer.c \
21 $(PLATFORM_COMMON_DIR)/bootloader.c \ 24 $(PLATFORM_COMMON_DIR)/bootloader.c \
@@ -29,6 +32,10 @@ ifeq ($(PLATFORM),CHIBIOS)
29 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c 32 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
30endif 33endif
31 34
35ifeq ($(PLATFORM),TEST)
36 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
37endif
38
32 39
33 40
34# Option modules 41# Option modules
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 77848c092..148162a51 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 <http://www.gnu.org/licenses/>.
25extern keymap_config_t keymap_config; 25extern keymap_config_t keymap_config;
26 26
27 27
28static inline void add_key_byte(uint8_t code);
29static inline void del_key_byte(uint8_t code);
30#ifdef NKRO_ENABLE
31static inline void add_key_bit(uint8_t code);
32static inline void del_key_bit(uint8_t code);
33#endif
34
35static uint8_t real_mods = 0; 28static uint8_t real_mods = 0;
36static uint8_t weak_mods = 0; 29static uint8_t weak_mods = 0;
37static uint8_t macro_mods = 0; 30static uint8_t macro_mods = 0;
@@ -50,6 +43,10 @@ static int8_t cb_count = 0;
50//report_keyboard_t keyboard_report = {}; 43//report_keyboard_t keyboard_report = {};
51report_keyboard_t *keyboard_report = &(report_keyboard_t){}; 44report_keyboard_t *keyboard_report = &(report_keyboard_t){};
52 45
46extern inline void add_key(uint8_t key);
47extern inline void del_key(uint8_t key);
48extern inline void clear_keys(void);
49
53#ifndef NO_ACTION_ONESHOT 50#ifndef NO_ACTION_ONESHOT
54static int8_t oneshot_mods = 0; 51static int8_t oneshot_mods = 0;
55static int8_t oneshot_locked_mods = 0; 52static int8_t oneshot_locked_mods = 0;
@@ -134,7 +131,7 @@ void send_keyboard_report(void) {
134 } 131 }
135#endif 132#endif
136 keyboard_report->mods |= oneshot_mods; 133 keyboard_report->mods |= oneshot_mods;
137 if (has_anykey()) { 134 if (has_anykey(keyboard_report)) {
138 clear_oneshot_mods(); 135 clear_oneshot_mods();
139 } 136 }
140 } 137 }
@@ -143,38 +140,6 @@ void send_keyboard_report(void) {
143 host_keyboard_send(keyboard_report); 140 host_keyboard_send(keyboard_report);
144} 141}
145 142
146/* key */
147void add_key(uint8_t key)
148{
149#ifdef NKRO_ENABLE
150 if (keyboard_protocol && keymap_config.nkro) {
151 add_key_bit(key);
152 return;
153 }
154#endif
155 add_key_byte(key);
156}
157
158void del_key(uint8_t key)
159{
160#ifdef NKRO_ENABLE
161 if (keyboard_protocol && keymap_config.nkro) {
162 del_key_bit(key);
163 return;
164 }
165#endif
166 del_key_byte(key);
167}
168
169void clear_keys(void)
170{
171 // not clear mods
172 for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
173 keyboard_report->raw[i] = 0;
174 }
175}
176
177
178/* modifier */ 143/* modifier */
179uint8_t get_mods(void) { return real_mods; } 144uint8_t get_mods(void) { return real_mods; }
180void add_mods(uint8_t mods) { real_mods |= mods; } 145void add_mods(uint8_t mods) { real_mods |= mods; }
@@ -221,166 +186,7 @@ uint8_t get_oneshot_mods(void)
221/* 186/*
222 * inspect keyboard state 187 * inspect keyboard state
223 */ 188 */
224uint8_t has_anykey(void)
225{
226 uint8_t cnt = 0;
227 for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
228 if (keyboard_report->raw[i])
229 cnt++;
230 }
231 return cnt;
232}
233
234uint8_t has_anymod(void) 189uint8_t has_anymod(void)
235{ 190{
236 return bitpop(real_mods); 191 return bitpop(real_mods);
237} 192}
238
239uint8_t get_first_key(void)
240{
241#ifdef NKRO_ENABLE
242 if (keyboard_protocol && keymap_config.nkro) {
243 uint8_t i = 0;
244 for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
245 ;
246 return i<<3 | biton(keyboard_report->nkro.bits[i]);
247 }
248#endif
249#ifdef USB_6KRO_ENABLE
250 uint8_t i = cb_head;
251 do {
252 if (keyboard_report->keys[i] != 0) {
253 break;
254 }
255 i = RO_INC(i);
256 } while (i != cb_tail);
257 return keyboard_report->keys[i];
258#else
259 return keyboard_report->keys[0];
260#endif
261}
262
263
264
265/* local functions */
266static inline void add_key_byte(uint8_t code)
267{
268#ifdef USB_6KRO_ENABLE
269 int8_t i = cb_head;
270 int8_t empty = -1;
271 if (cb_count) {
272 do {
273 if (keyboard_report->keys[i] == code) {
274 return;
275 }
276 if (empty == -1 && keyboard_report->keys[i] == 0) {
277 empty = i;
278 }
279 i = RO_INC(i);
280 } while (i != cb_tail);
281 if (i == cb_tail) {
282 if (cb_tail == cb_head) {
283 // buffer is full
284 if (empty == -1) {
285 // pop head when has no empty space
286 cb_head = RO_INC(cb_head);
287 cb_count--;
288 }
289 else {
290 // left shift when has empty space
291 uint8_t offset = 1;
292 i = RO_INC(empty);
293 do {
294 if (keyboard_report->keys[i] != 0) {
295 keyboard_report->keys[empty] = keyboard_report->keys[i];
296 keyboard_report->keys[i] = 0;
297 empty = RO_INC(empty);
298 }
299 else {
300 offset++;
301 }
302 i = RO_INC(i);
303 } while (i != cb_tail);
304 cb_tail = RO_SUB(cb_tail, offset);
305 }
306 }
307 }
308 }
309 // add to tail
310 keyboard_report->keys[cb_tail] = code;
311 cb_tail = RO_INC(cb_tail);
312 cb_count++;
313#else
314 int8_t i = 0;
315 int8_t empty = -1;
316 for (; i < KEYBOARD_REPORT_KEYS; i++) {
317 if (keyboard_report->keys[i] == code) {
318 break;
319 }
320 if (empty == -1 && keyboard_report->keys[i] == 0) {
321 empty = i;
322 }
323 }
324 if (i == KEYBOARD_REPORT_KEYS) {
325 if (empty != -1) {
326 keyboard_report->keys[empty] = code;
327 }
328 }
329#endif
330}
331
332static inline void del_key_byte(uint8_t code)
333{
334#ifdef USB_6KRO_ENABLE
335 uint8_t i = cb_head;
336 if (cb_count) {
337 do {
338 if (keyboard_report->keys[i] == code) {
339 keyboard_report->keys[i] = 0;
340 cb_count--;
341 if (cb_count == 0) {
342 // reset head and tail
343 cb_tail = cb_head = 0;
344 }
345 if (i == RO_DEC(cb_tail)) {
346 // left shift when next to tail
347 do {
348 cb_tail = RO_DEC(cb_tail);
349 if (keyboard_report->keys[RO_DEC(cb_tail)] != 0) {
350 break;
351 }
352 } while (cb_tail != cb_head);
353 }
354 break;
355 }
356 i = RO_INC(i);
357 } while (i != cb_tail);
358 }
359#else
360 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
361 if (keyboard_report->keys[i] == code) {
362 keyboard_report->keys[i] = 0;
363 }
364 }
365#endif
366}
367
368#ifdef NKRO_ENABLE
369static inline void add_key_bit(uint8_t code)
370{
371 if ((code>>3) < KEYBOARD_REPORT_BITS) {
372 keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
373 } else {
374 dprintf("add_key_bit: can't add: %02X\n", code);
375 }
376}
377
378static inline void del_key_bit(uint8_t code)
379{
380 if ((code>>3) < KEYBOARD_REPORT_BITS) {
381 keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
382 } else {
383 dprintf("del_key_bit: can't del: %02X\n", code);
384 }
385}
386#endif
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h
index dd0c4c2bf..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;
29void send_keyboard_report(void); 29void send_keyboard_report(void);
30 30
31/* key */ 31/* key */
32void add_key(uint8_t key); 32inline void add_key(uint8_t key) {
33void del_key(uint8_t key); 33 add_key_to_report(keyboard_report, key);
34void clear_keys(void); 34}
35
36inline void del_key(uint8_t key) {
37 del_key_from_report(keyboard_report, key);
38}
39
40inline void clear_keys(void) {
41 clear_keys_from_report(keyboard_report);
42}
35 43
36/* modifier */ 44/* modifier */
37uint8_t get_mods(void); 45uint8_t get_mods(void);
@@ -82,9 +90,7 @@ uint8_t get_oneshot_layer_state(void);
82bool has_oneshot_layer_timed_out(void); 90bool has_oneshot_layer_timed_out(void);
83 91
84/* inspect */ 92/* inspect */
85uint8_t has_anykey(void);
86uint8_t has_anymod(void); 93uint8_t has_anymod(void);
87uint8_t get_first_key(void);
88 94
89#ifdef __cplusplus 95#ifdef __cplusplus
90} 96}
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 @@
4#if defined(__AVR__) 4#if defined(__AVR__)
5#include <avr/eeprom.h> 5#include <avr/eeprom.h>
6#else 6#else
7#include <stdint.h>
8
7uint8_t eeprom_read_byte (const uint8_t *__p); 9uint8_t eeprom_read_byte (const uint8_t *__p);
8uint16_t eeprom_read_word (const uint16_t *__p); 10uint16_t eeprom_read_word (const uint16_t *__p);
9uint32_t eeprom_read_dword (const uint32_t *__p); 11uint32_t eeprom_read_dword (const uint32_t *__p);
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 @@
3 3
4#if defined(__AVR__) 4#if defined(__AVR__)
5# include <avr/pgmspace.h> 5# include <avr/pgmspace.h>
6#elif defined(__arm__) 6#else
7# define PROGMEM 7# define PROGMEM
8# define pgm_read_byte(p) *((unsigned char*)p) 8# define pgm_read_byte(p) *((unsigned char*)p)
9# define pgm_read_word(p) *((uint16_t*)p) 9# define pgm_read_word(p) *((uint16_t*)p)
diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c
new file mode 100644
index 000000000..74c6d3fdd
--- /dev/null
+++ b/tmk_core/common/report.c
@@ -0,0 +1,207 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "report.h"
18#include "host.h"
19#include "keycode_config.h"
20#include "debug.h"
21#include "util.h"
22
23uint8_t has_anykey(report_keyboard_t* keyboard_report)
24{
25 uint8_t cnt = 0;
26 for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
27 if (keyboard_report->raw[i])
28 cnt++;
29 }
30 return cnt;
31}
32
33uint8_t get_first_key(report_keyboard_t* keyboard_report)
34{
35#ifdef NKRO_ENABLE
36 if (keyboard_protocol && keymap_config.nkro) {
37 uint8_t i = 0;
38 for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
39 ;
40 return i<<3 | biton(keyboard_report->nkro.bits[i]);
41 }
42#endif
43#ifdef USB_6KRO_ENABLE
44 uint8_t i = cb_head;
45 do {
46 if (keyboard_report->keys[i] != 0) {
47 break;
48 }
49 i = RO_INC(i);
50 } while (i != cb_tail);
51 return keyboard_report->keys[i];
52#else
53 return keyboard_report->keys[0];
54#endif
55}
56
57void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
58{
59#ifdef USB_6KRO_ENABLE
60 int8_t i = cb_head;
61 int8_t empty = -1;
62 if (cb_count) {
63 do {
64 if (keyboard_report->keys[i] == code) {
65 return;
66 }
67 if (empty == -1 && keyboard_report->keys[i] == 0) {
68 empty = i;
69 }
70 i = RO_INC(i);
71 } while (i != cb_tail);
72 if (i == cb_tail) {
73 if (cb_tail == cb_head) {
74 // buffer is full
75 if (empty == -1) {
76 // pop head when has no empty space
77 cb_head = RO_INC(cb_head);
78 cb_count--;
79 }
80 else {
81 // left shift when has empty space
82 uint8_t offset = 1;
83 i = RO_INC(empty);
84 do {
85 if (keyboard_report->keys[i] != 0) {
86 keyboard_report->keys[empty] = keyboard_report->keys[i];
87 keyboard_report->keys[i] = 0;
88 empty = RO_INC(empty);
89 }
90 else {
91 offset++;
92 }
93 i = RO_INC(i);
94 } while (i != cb_tail);
95 cb_tail = RO_SUB(cb_tail, offset);
96 }
97 }
98 }
99 }
100 // add to tail
101 keyboard_report->keys[cb_tail] = code;
102 cb_tail = RO_INC(cb_tail);
103 cb_count++;
104#else
105 int8_t i = 0;
106 int8_t empty = -1;
107 for (; i < KEYBOARD_REPORT_KEYS; i++) {
108 if (keyboard_report->keys[i] == code) {
109 break;
110 }
111 if (empty == -1 && keyboard_report->keys[i] == 0) {
112 empty = i;
113 }
114 }
115 if (i == KEYBOARD_REPORT_KEYS) {
116 if (empty != -1) {
117 keyboard_report->keys[empty] = code;
118 }
119 }
120#endif
121}
122
123void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code)
124{
125#ifdef USB_6KRO_ENABLE
126 uint8_t i = cb_head;
127 if (cb_count) {
128 do {
129 if (keyboard_report->keys[i] == code) {
130 keyboard_report->keys[i] = 0;
131 cb_count--;
132 if (cb_count == 0) {
133 // reset head and tail
134 cb_tail = cb_head = 0;
135 }
136 if (i == RO_DEC(cb_tail)) {
137 // left shift when next to tail
138 do {
139 cb_tail = RO_DEC(cb_tail);
140 if (keyboard_report->keys[RO_DEC(cb_tail)] != 0) {
141 break;
142 }
143 } while (cb_tail != cb_head);
144 }
145 break;
146 }
147 i = RO_INC(i);
148 } while (i != cb_tail);
149 }
150#else
151 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
152 if (keyboard_report->keys[i] == code) {
153 keyboard_report->keys[i] = 0;
154 }
155 }
156#endif
157}
158
159#ifdef NKRO_ENABLE
160void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
161{
162 if ((code>>3) < KEYBOARD_REPORT_BITS) {
163 keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
164 } else {
165 dprintf("add_key_bit: can't add: %02X\n", code);
166 }
167}
168
169void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code)
170{
171 if ((code>>3) < KEYBOARD_REPORT_BITS) {
172 keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
173 } else {
174 dprintf("del_key_bit: can't del: %02X\n", code);
175 }
176}
177#endif
178
179void add_key_to_report(report_keyboard_t* keyboard_report, int8_t key)
180{
181#ifdef NKRO_ENABLE
182 if (keyboard_protocol && keymap_config.nkro) {
183 add_key_bit(keyboard_report, key);
184 return;
185 }
186#endif
187 add_key_byte(keyboard_report, key);
188}
189
190void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key)
191{
192#ifdef NKRO_ENABLE
193 if (keyboard_protocol && keymap_config.nkro) {
194 del_key_bit(keyboard_report, key);
195 return;
196 }
197#endif
198 del_key_byte(keyboard_report, key);
199}
200
201void clear_keys_from_report(report_keyboard_t* keyboard_report)
202{
203 // not clear mods
204 for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
205 keyboard_report->raw[i] = 0;
206 }
207} \ No newline at end of file
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 8fb28b6ce..899fc524c 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -174,6 +174,20 @@ typedef struct {
174 (key == KC_WWW_REFRESH ? AC_REFRESH : \ 174 (key == KC_WWW_REFRESH ? AC_REFRESH : \
175 (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))) 175 (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0)))))))))))))))))))))
176 176
177uint8_t has_anykey(report_keyboard_t* keyboard_report);
178uint8_t get_first_key(report_keyboard_t* keyboard_report);
179
180void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
181void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
182#ifdef NKRO_ENABLE
183void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
184void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
185#endif
186
187void add_key_to_report(report_keyboard_t* keyboard_report, int8_t key);
188void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key);
189void clear_keys_from_report(report_keyboard_t* keyboard_report);
190
177#ifdef __cplusplus 191#ifdef __cplusplus
178} 192}
179#endif 193#endif
diff --git a/tmk_core/common/test/bootloader.c b/tmk_core/common/test/bootloader.c
new file mode 100644
index 000000000..5155d9ff0
--- /dev/null
+++ b/tmk_core/common/test/bootloader.c
@@ -0,0 +1,19 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "bootloader.h"
18
19void bootloader_jump(void) {}
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 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "eeprom.h"
18
19#define EEPROM_SIZE 32
20
21static uint8_t buffer[EEPROM_SIZE];
22
23uint8_t eeprom_read_byte(const uint8_t *addr) {
24 uintptr_t offset = (uintptr_t)addr;
25 return buffer[offset];
26}
27
28void eeprom_write_byte(uint8_t *addr, uint8_t value) {
29 uintptr_t offset = (uintptr_t)addr;
30 buffer[offset] = value;
31}
32
33uint16_t eeprom_read_word(const uint16_t *addr) {
34 const uint8_t *p = (const uint8_t *)addr;
35 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
36}
37
38uint32_t eeprom_read_dword(const uint32_t *addr) {
39 const uint8_t *p = (const uint8_t *)addr;
40 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
41 | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
42}
43
44void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
45 const uint8_t *p = (const uint8_t *)addr;
46 uint8_t *dest = (uint8_t *)buf;
47 while (len--) {
48 *dest++ = eeprom_read_byte(p++);
49 }
50}
51
52void eeprom_write_word(uint16_t *addr, uint16_t value) {
53 uint8_t *p = (uint8_t *)addr;
54 eeprom_write_byte(p++, value);
55 eeprom_write_byte(p, value >> 8);
56}
57
58void eeprom_write_dword(uint32_t *addr, uint32_t value) {
59 uint8_t *p = (uint8_t *)addr;
60 eeprom_write_byte(p++, value);
61 eeprom_write_byte(p++, value >> 8);
62 eeprom_write_byte(p++, value >> 16);
63 eeprom_write_byte(p, value >> 24);
64}
65
66void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
67 uint8_t *p = (uint8_t *)addr;
68 const uint8_t *src = (const uint8_t *)buf;
69 while (len--) {
70 eeprom_write_byte(p++, *src++);
71 }
72}
73
74void eeprom_update_byte(uint8_t *addr, uint8_t value) {
75 eeprom_write_byte(addr, value);
76}
77
78void eeprom_update_word(uint16_t *addr, uint16_t value) {
79 uint8_t *p = (uint8_t *)addr;
80 eeprom_write_byte(p++, value);
81 eeprom_write_byte(p, value >> 8);
82}
83
84void eeprom_update_dword(uint32_t *addr, uint32_t value) {
85 uint8_t *p = (uint8_t *)addr;
86 eeprom_write_byte(p++, value);
87 eeprom_write_byte(p++, value >> 8);
88 eeprom_write_byte(p++, value >> 16);
89 eeprom_write_byte(p, value >> 24);
90}
91
92void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
93 uint8_t *p = (uint8_t *)addr;
94 const uint8_t *src = (const uint8_t *)buf;
95 while (len--) {
96 eeprom_write_byte(p++, *src++);
97 }
98}
diff --git a/tmk_core/common/test/suspend.c b/tmk_core/common/test/suspend.c
new file mode 100644
index 000000000..01d1930ea
--- /dev/null
+++ b/tmk_core/common/test/suspend.c
@@ -0,0 +1,17 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17
diff --git a/tmk_core/common/test/timer.c b/tmk_core/common/test/timer.c
new file mode 100644
index 000000000..09ea91a89
--- /dev/null
+++ b/tmk_core/common/test/timer.c
@@ -0,0 +1,30 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "timer.h"
18
19// TODO: the timer should work, but at a much faster rate than realtime
20// It should also have some kind of integration with the testing system
21
22void timer_init(void) {}
23
24void timer_clear(void) {}
25
26uint16_t timer_read(void) { return 0; }
27uint32_t timer_read32(void) { return 0; }
28uint16_t timer_elapsed(uint16_t last) { return 0; }
29uint32_t timer_elapsed32(uint32_t last) { return 0; }
30
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" {
9# include <util/delay.h> 9# include <util/delay.h>
10# define wait_ms(ms) _delay_ms(ms) 10# define wait_ms(ms) _delay_ms(ms)
11# define wait_us(us) _delay_us(us) 11# define wait_us(us) _delay_us(us)
12#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ 12#elif defined(PROTOCOL_CHIBIOS)
13# include "ch.h" 13# include "ch.h"
14# define wait_ms(ms) chThdSleepMilliseconds(ms) 14# define wait_ms(ms) chThdSleepMilliseconds(ms)
15# define wait_us(us) chThdSleepMicroseconds(us) 15# define wait_us(us) chThdSleepMicroseconds(us)
16#elif defined(__arm__) /* __AVR__ */ 16#elif defined(__arm__)
17# include "wait_api.h" 17# include "wait_api.h"
18#endif /* __AVR__ */ 18#else // Unit tests
19#define wait_ms(ms)
20#define wait_us(us)
21#endif
19 22
20#ifdef __cplusplus 23#ifdef __cplusplus
21} 24}