diff options
48 files changed, 2537 insertions, 227 deletions
diff --git a/build_test.mk b/build_test.mk index 77c4265f9..5171c58c3 100644 --- a/build_test.mk +++ b/build_test.mk | |||
@@ -49,6 +49,7 @@ endif | |||
49 | 49 | ||
50 | include common_features.mk | 50 | include common_features.mk |
51 | include $(TMK_PATH)/common.mk | 51 | include $(TMK_PATH)/common.mk |
52 | include $(QUANTUM_PATH)/debounce/tests/rules.mk | ||
52 | include $(QUANTUM_PATH)/sequencer/tests/rules.mk | 53 | include $(QUANTUM_PATH)/sequencer/tests/rules.mk |
53 | include $(QUANTUM_PATH)/serial_link/tests/rules.mk | 54 | include $(QUANTUM_PATH)/serial_link/tests/rules.mk |
54 | ifneq ($(filter $(FULL_TESTS),$(TEST)),) | 55 | ifneq ($(filter $(FULL_TESTS),$(TEST)),) |
diff --git a/docs/breaking_changes.md b/docs/breaking_changes.md index 3e85a7076..2ad8b5a14 100644 --- a/docs/breaking_changes.md +++ b/docs/breaking_changes.md | |||
@@ -96,3 +96,7 @@ This happens immediately after the previous `develop` branch is merged. | |||
96 | * [ ] Create a PR for `develop` | 96 | * [ ] Create a PR for `develop` |
97 | * [ ] Make sure travis comes back clean | 97 | * [ ] Make sure travis comes back clean |
98 | * [ ] Merge `develop` PR | 98 | * [ ] Merge `develop` PR |
99 | |||
100 | ## Post-merge operations | ||
101 | |||
102 | * (Optional) [update ChibiOS + ChibiOS-Contrib on `develop`](chibios_upgrade_instructions.md) \ No newline at end of file | ||
diff --git a/docs/chibios_upgrade_instructions.md b/docs/chibios_upgrade_instructions.md new file mode 100644 index 000000000..40c2faafc --- /dev/null +++ b/docs/chibios_upgrade_instructions.md | |||
@@ -0,0 +1,56 @@ | |||
1 | # ChibiOS Upgrade Procedure | ||
2 | |||
3 | ChibiOS and ChibiOS-Contrib need to be updated in tandem -- the latter has a branch tied to the ChibiOS version in use and should not be mixed with different versions. | ||
4 | |||
5 | ## Getting ChibiOS | ||
6 | |||
7 | * `svn` Initialisation: | ||
8 | * Only needed to be done once | ||
9 | * You might need to separately install `git-svn` package in your OS's package manager | ||
10 | * `git svn init --stdlayout --prefix='svn/' http://svn.osdn.net/svnroot/chibios/` | ||
11 | * `git remote add qmk git@github.com:qmk/ChibiOS.git` | ||
12 | * Updating: | ||
13 | * `git svn fetch` | ||
14 | * First time around this will take several hours | ||
15 | * Subsequent updates will be incremental only | ||
16 | * Tagging example (work out which version first!): | ||
17 | * `git tag -a ver20.3.3 -m ver20.3.3 svn/tags/ver20.3.3` | ||
18 | * `git push qmk ver20.3.3` | ||
19 | * `git tag -a breaking_YYYY_qN -m breaking_YYYY_qN svn/tags/ver20.3.3` | ||
20 | * `git push qmk breaking_YYYY_qN` | ||
21 | |||
22 | ## Getting ChibiOS-Contrib | ||
23 | |||
24 | * `git` Initialisation: | ||
25 | * `git clone git@github.com:qmk/ChibiOS-Contrib` | ||
26 | * `git remote add upstream https://github.com/ChibiOS/ChibiOS-Contrib` | ||
27 | * `git checkout -b chibios-20.3.x upstream/chibios-20.3.x` | ||
28 | * Updating: | ||
29 | * `git fetch --all --tags --prune` | ||
30 | * `git checkout chibios-20.3.x` | ||
31 | * `git pull --ff-only` | ||
32 | * `git push origin chibios-20.3.x` | ||
33 | * `git tag -a breaking_YYYY_qN -m breaking_YYYY_qN chibios-20.3.x` | ||
34 | * `git push origin breaking_YYYY_qN` | ||
35 | |||
36 | ## Updating submodules | ||
37 | |||
38 | * Update the submodules | ||
39 | * `cd $QMK_FIRMWARE` | ||
40 | * `git checkout develop` | ||
41 | * `git pull --ff-only` | ||
42 | * `git checkout -b chibios-version-bump` | ||
43 | * `cd lib/chibios` | ||
44 | * `git fetch --all --tags --prune` | ||
45 | * `git checkout breaking_YYYY_qN` | ||
46 | * `cd ../chibios-contrib` | ||
47 | * `git fetch --all --tags --prune` | ||
48 | * `git checkout breaking_YYYY_qN` | ||
49 | * Build everything | ||
50 | * `cd $QMK_FIRMWARE` | ||
51 | * `qmk multibuild -j4` | ||
52 | * Make sure there are no errors | ||
53 | * Push to the repo | ||
54 | * `git commit -am 'Update ChibiOS to XXXXXXXXX'` | ||
55 | * `git push --set-upstream origin chibios-version-bump` | ||
56 | * Make a PR to qmk_firmware with the new branch \ No newline at end of file | ||
diff --git a/docs/config_options.md b/docs/config_options.md index d0f0b316e..26fe8cea5 100644 --- a/docs/config_options.md +++ b/docs/config_options.md | |||
@@ -51,8 +51,10 @@ This is a C header file that is one of the first things included, and will persi | |||
51 | * the number of columns in your keyboard's matrix | 51 | * the number of columns in your keyboard's matrix |
52 | * `#define MATRIX_ROW_PINS { D0, D5, B5, B6 }` | 52 | * `#define MATRIX_ROW_PINS { D0, D5, B5, B6 }` |
53 | * pins of the rows, from top to bottom | 53 | * pins of the rows, from top to bottom |
54 | * may be omitted by the keyboard designer if matrix reads are handled in an alternate manner. See [low-level matrix overrides](custom_quantum_functions.md?id=low-level-matrix-overrides) for more information. | ||
54 | * `#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }` | 55 | * `#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }` |
55 | * pins of the columns, from left to right | 56 | * pins of the columns, from left to right |
57 | * may be omitted by the keyboard designer if matrix reads are handled in an alternate manner. See [low-level matrix overrides](custom_quantum_functions.md?id=low-level-matrix-overrides) for more information. | ||
56 | * `#define MATRIX_IO_DELAY 30` | 58 | * `#define MATRIX_IO_DELAY 30` |
57 | * the delay in microseconds when between changing matrix pin state and reading values | 59 | * the delay in microseconds when between changing matrix pin state and reading values |
58 | * `#define UNUSED_PINS { D1, D2, D3, B1, B2, B3 }` | 60 | * `#define UNUSED_PINS { D1, D2, D3, B1, B2, B3 }` |
@@ -280,6 +282,7 @@ There are a few different ways to set handedness for split keyboards (listed in | |||
280 | * `#define MATRIX_ROW_PINS_RIGHT { <row pins> }` | 282 | * `#define MATRIX_ROW_PINS_RIGHT { <row pins> }` |
281 | * `#define MATRIX_COL_PINS_RIGHT { <col pins> }` | 283 | * `#define MATRIX_COL_PINS_RIGHT { <col pins> }` |
282 | * If you want to specify a different pinout for the right half than the left half, you can define `MATRIX_ROW_PINS_RIGHT`/`MATRIX_COL_PINS_RIGHT`. Currently, the size of `MATRIX_ROW_PINS` must be the same as `MATRIX_ROW_PINS_RIGHT` and likewise for the definition of columns. | 284 | * If you want to specify a different pinout for the right half than the left half, you can define `MATRIX_ROW_PINS_RIGHT`/`MATRIX_COL_PINS_RIGHT`. Currently, the size of `MATRIX_ROW_PINS` must be the same as `MATRIX_ROW_PINS_RIGHT` and likewise for the definition of columns. |
285 | * may be omitted by the keyboard designer if matrix reads are handled in an alternate manner. See [low-level matrix overrides](custom_quantum_functions.md?id=low-level-matrix-overrides) for more information. | ||
283 | 286 | ||
284 | * `#define DIRECT_PINS_RIGHT { { F1, F0, B0, C7 }, { F4, F5, F6, F7 } }` | 287 | * `#define DIRECT_PINS_RIGHT { { F1, F0, B0, C7 }, { F4, F5, F6, F7 } }` |
285 | * If you want to specify a different direct pinout for the right half than the left half, you can define `DIRECT_PINS_RIGHT`. Currently, the size of `DIRECT_PINS` must be the same as `DIRECT_PINS_RIGHT`. | 288 | * If you want to specify a different direct pinout for the right half than the left half, you can define `DIRECT_PINS_RIGHT`. Currently, the size of `DIRECT_PINS` must be the same as `DIRECT_PINS_RIGHT`. |
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md index 694b421e7..30c637bb4 100644 --- a/docs/custom_quantum_functions.md +++ b/docs/custom_quantum_functions.md | |||
@@ -144,6 +144,14 @@ This is useful for setting up stuff that you may need elsewhere, but isn't hardw | |||
144 | * Keyboard/Revision: `void matrix_init_kb(void)` | 144 | * Keyboard/Revision: `void matrix_init_kb(void)` |
145 | * Keymap: `void matrix_init_user(void)` | 145 | * Keymap: `void matrix_init_user(void)` |
146 | 146 | ||
147 | ### Low-level Matrix Overrides Function Documentation :id=low-level-matrix-overrides | ||
148 | |||
149 | * GPIO pin initialisation: `void matrix_init_pins(void)` | ||
150 | * This needs to perform the low-level initialisation of all row and column pins. By default this will initialise the input/output state of each of the GPIO pins listed in `MATRIX_ROW_PINS` and `MATRIX_COL_PINS`, based on whether or not the keyboard is set up for `ROW2COL`, `COL2ROW`, or `DIRECT_PINS`. Should the keyboard designer override this function, no initialisation of pin state will occur within QMK itself, instead deferring to the keyboard's override. | ||
151 | * `COL2ROW`-based row reads: `void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)` | ||
152 | * `ROW2COL`-based column reads: `void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)` | ||
153 | * `DIRECT_PINS`-based reads: `void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)` | ||
154 | * These three functions need to perform the low-level retrieval of matrix state of relevant input pins, based on the matrix type. Only one of the functions should be implemented, if needed. By default this will iterate through `MATRIX_ROW_PINS` and `MATRIX_COL_PINS`, configuring the inputs and outputs based on whether or not the keyboard is set up for `ROW2COL`, `COL2ROW`, or `DIRECT_PINS`. Should the keyboard designer override this function, no manipulation of matrix GPIO pin state will occur within QMK itself, instead deferring to the keyboard's override. | ||
147 | 155 | ||
148 | ## Keyboard Post Initialization code | 156 | ## Keyboard Post Initialization code |
149 | 157 | ||
diff --git a/drivers/chibios/spi_master.c b/drivers/chibios/spi_master.c index 4852a6eba..28ddcbb2b 100644 --- a/drivers/chibios/spi_master.c +++ b/drivers/chibios/spi_master.c | |||
@@ -18,8 +18,13 @@ | |||
18 | 18 | ||
19 | #include "timer.h" | 19 | #include "timer.h" |
20 | 20 | ||
21 | static pin_t currentSlavePin = NO_PIN; | 21 | static pin_t currentSlavePin = NO_PIN; |
22 | static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; | 22 | |
23 | #if defined(K20x) || defined(KL2x) | ||
24 | static SPIConfig spiConfig = {NULL, 0, 0, 0}; | ||
25 | #else | ||
26 | static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; | ||
27 | #endif | ||
23 | 28 | ||
24 | __attribute__((weak)) void spi_init(void) { | 29 | __attribute__((weak)) void spi_init(void) { |
25 | static bool is_initialised = false; | 30 | static bool is_initialised = false; |
@@ -27,15 +32,15 @@ __attribute__((weak)) void spi_init(void) { | |||
27 | is_initialised = true; | 32 | is_initialised = true; |
28 | 33 | ||
29 | // Try releasing special pins for a short time | 34 | // Try releasing special pins for a short time |
30 | palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_INPUT); | 35 | setPinInput(SPI_SCK_PIN); |
31 | palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_INPUT); | 36 | setPinInput(SPI_MOSI_PIN); |
32 | palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_INPUT); | 37 | setPinInput(SPI_MISO_PIN); |
33 | 38 | ||
34 | chThdSleepMilliseconds(10); | 39 | chThdSleepMilliseconds(10); |
35 | #if defined(USE_GPIOV1) | 40 | #if defined(USE_GPIOV1) |
36 | palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); | 41 | palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), SPI_SCK_PAL_MODE); |
37 | palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); | 42 | palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE); |
38 | palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); | 43 | palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE); |
39 | #else | 44 | #else |
40 | palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); | 45 | palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); |
41 | palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); | 46 | palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); |
@@ -58,6 +63,54 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { | |||
58 | return false; | 63 | return false; |
59 | } | 64 | } |
60 | 65 | ||
66 | #if defined(K20x) || defined(KL2x) | ||
67 | spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1); | ||
68 | |||
69 | if (lsbFirst) { | ||
70 | spiConfig.tar0 |= SPIx_CTARn_LSBFE; | ||
71 | } | ||
72 | |||
73 | switch (mode) { | ||
74 | case 0: | ||
75 | break; | ||
76 | case 1: | ||
77 | spiConfig.tar0 |= SPIx_CTARn_CPHA; | ||
78 | break; | ||
79 | case 2: | ||
80 | spiConfig.tar0 |= SPIx_CTARn_CPOL; | ||
81 | break; | ||
82 | case 3: | ||
83 | spiConfig.tar0 |= SPIx_CTARn_CPHA | SPIx_CTARn_CPOL; | ||
84 | break; | ||
85 | } | ||
86 | |||
87 | switch (roundedDivisor) { | ||
88 | case 2: | ||
89 | spiConfig.tar0 |= SPIx_CTARn_BR(0); | ||
90 | break; | ||
91 | case 4: | ||
92 | spiConfig.tar0 |= SPIx_CTARn_BR(1); | ||
93 | break; | ||
94 | case 8: | ||
95 | spiConfig.tar0 |= SPIx_CTARn_BR(3); | ||
96 | break; | ||
97 | case 16: | ||
98 | spiConfig.tar0 |= SPIx_CTARn_BR(4); | ||
99 | break; | ||
100 | case 32: | ||
101 | spiConfig.tar0 |= SPIx_CTARn_BR(5); | ||
102 | break; | ||
103 | case 64: | ||
104 | spiConfig.tar0 |= SPIx_CTARn_BR(6); | ||
105 | break; | ||
106 | case 128: | ||
107 | spiConfig.tar0 |= SPIx_CTARn_BR(7); | ||
108 | break; | ||
109 | case 256: | ||
110 | spiConfig.tar0 |= SPIx_CTARn_BR(8); | ||
111 | break; | ||
112 | } | ||
113 | #else | ||
61 | spiConfig.cr1 = 0; | 114 | spiConfig.cr1 = 0; |
62 | 115 | ||
63 | if (lsbFirst) { | 116 | if (lsbFirst) { |
@@ -103,6 +156,7 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { | |||
103 | spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0; | 156 | spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0; |
104 | break; | 157 | break; |
105 | } | 158 | } |
159 | #endif | ||
106 | 160 | ||
107 | currentSlavePin = slavePin; | 161 | currentSlavePin = slavePin; |
108 | spiConfig.ssport = PAL_PORT(slavePin); | 162 | spiConfig.ssport = PAL_PORT(slavePin); |
diff --git a/drivers/chibios/spi_master.h b/drivers/chibios/spi_master.h index e93580e31..b5a6ef143 100644 --- a/drivers/chibios/spi_master.h +++ b/drivers/chibios/spi_master.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
22 | 22 | ||
23 | #include "gpio.h" | 23 | #include "gpio.h" |
24 | #include "chibios_config.h" | ||
24 | 25 | ||
25 | #ifndef SPI_DRIVER | 26 | #ifndef SPI_DRIVER |
26 | # define SPI_DRIVER SPID2 | 27 | # define SPI_DRIVER SPID2 |
@@ -31,7 +32,11 @@ | |||
31 | #endif | 32 | #endif |
32 | 33 | ||
33 | #ifndef SPI_SCK_PAL_MODE | 34 | #ifndef SPI_SCK_PAL_MODE |
34 | # define SPI_SCK_PAL_MODE 5 | 35 | # if defined(USE_GPIOV1) |
36 | # define SPI_SCK_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL | ||
37 | # else | ||
38 | # define SPI_SCK_PAL_MODE 5 | ||
39 | # endif | ||
35 | #endif | 40 | #endif |
36 | 41 | ||
37 | #ifndef SPI_MOSI_PIN | 42 | #ifndef SPI_MOSI_PIN |
@@ -39,7 +44,11 @@ | |||
39 | #endif | 44 | #endif |
40 | 45 | ||
41 | #ifndef SPI_MOSI_PAL_MODE | 46 | #ifndef SPI_MOSI_PAL_MODE |
42 | # define SPI_MOSI_PAL_MODE 5 | 47 | # if defined(USE_GPIOV1) |
48 | # define SPI_MOSI_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL | ||
49 | # else | ||
50 | # define SPI_MOSI_PAL_MODE 5 | ||
51 | # endif | ||
43 | #endif | 52 | #endif |
44 | 53 | ||
45 | #ifndef SPI_MISO_PIN | 54 | #ifndef SPI_MISO_PIN |
@@ -47,7 +56,11 @@ | |||
47 | #endif | 56 | #endif |
48 | 57 | ||
49 | #ifndef SPI_MISO_PAL_MODE | 58 | #ifndef SPI_MISO_PAL_MODE |
50 | # define SPI_MISO_PAL_MODE 5 | 59 | # if defined(USE_GPIOV1) |
60 | # define SPI_MISO_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL | ||
61 | # else | ||
62 | # define SPI_MISO_PAL_MODE 5 | ||
63 | # endif | ||
51 | #endif | 64 | #endif |
52 | 65 | ||
53 | typedef int16_t spi_status_t; | 66 | typedef int16_t spi_status_t; |
diff --git a/keyboards/anavi/macropad8/keymaps/default/config.h b/keyboards/anavi/macropad8/keymaps/default/config.h new file mode 100644 index 000000000..dd687cad5 --- /dev/null +++ b/keyboards/anavi/macropad8/keymaps/default/config.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 | #define LAYER_STATE_8BIT | ||
diff --git a/keyboards/handwired/frankie_macropad/keymaps/default/config.h b/keyboards/handwired/frankie_macropad/keymaps/default/config.h new file mode 100644 index 000000000..dd687cad5 --- /dev/null +++ b/keyboards/handwired/frankie_macropad/keymaps/default/config.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 | #define LAYER_STATE_8BIT | ||
diff --git a/keyboards/kbdfans/kbd67/rev1/keymaps/default/config.h b/keyboards/kbdfans/kbd67/rev1/keymaps/default/config.h index a3ed4f762..90fb10ebb 100644 --- a/keyboards/kbdfans/kbd67/rev1/keymaps/default/config.h +++ b/keyboards/kbdfans/kbd67/rev1/keymaps/default/config.h | |||
@@ -16,4 +16,4 @@ | |||
16 | 16 | ||
17 | #pragma once | 17 | #pragma once |
18 | 18 | ||
19 | // place overrides here | 19 | #define LAYER_STATE_8BIT |
diff --git a/keyboards/mt84/keymaps/default/config.h b/keyboards/mt84/keymaps/default/config.h new file mode 100644 index 000000000..dd687cad5 --- /dev/null +++ b/keyboards/mt84/keymaps/default/config.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 | #define LAYER_STATE_8BIT | ||
diff --git a/keyboards/sofle/keymaps/killmaster/config.h b/keyboards/sofle/keymaps/killmaster/config.h new file mode 100644 index 000000000..2e6abe84e --- /dev/null +++ b/keyboards/sofle/keymaps/killmaster/config.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* Copyright 2021 Carlos Martins | ||
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 | #pragma once | ||
17 | |||
18 | /* The way how "handedness" is decided (which half is which), | ||
19 | see https://docs.qmk.fm/#/feature_split_keyboard?id=setting-handedness | ||
20 | for more options. | ||
21 | */ | ||
22 | |||
23 | #define RGB_DI_PIN D3 | ||
24 | |||
25 | #ifdef RGB_MATRIX_ENABLE | ||
26 | |||
27 | #define RGBLED_NUM 72 | ||
28 | #define DRIVER_LED_TOTAL RGBLED_NUM | ||
29 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 120 // limits maximum brightness of LEDs to 150 out of 255. Higher may cause the controller to crash. | ||
30 | #define RGB_MATRIX_HUE_STEP 8 | ||
31 | #define RGB_MATRIX_SAT_STEP 8 | ||
32 | #define RGB_MATRIX_VAL_STEP 8 | ||
33 | #define RGB_MATRIX_SPD_STEP 10 | ||
34 | #define RGB_MATRIX_KEYPRESSES | ||
35 | #define RGB_MATRIX_FRAMEBUFFER_EFFECTS | ||
36 | #define RGB_MATRIX_SPLIT {36,36} | ||
37 | #define SPLIT_TRANSPORT_MIRROR | ||
38 | |||
39 | #endif | ||
40 | |||
41 | #ifdef RGBLIGHT_ENABLE | ||
42 | #define RGBLIGHT_SPLIT | ||
43 | #define RGBLED_NUM 70 | ||
44 | #define RGB_SPLIT {36,36} | ||
45 | #define RGBLIGHT_LIMIT_VAL 120 | ||
46 | // #define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */ | ||
47 | // /*== all animations enable ==*/ | ||
48 | // #define RGBLIGHT_ANIMATIONS | ||
49 | // /*== or choose animations ==*/ | ||
50 | // #define RGBLIGHT_EFFECT_BREATHING | ||
51 | //#define RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
52 | //#define RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
53 | // #define RGBLIGHT_EFFECT_SNAKE | ||
54 | // #define RGBLIGHT_EFFECT_KNIGHT | ||
55 | // #define RGBLIGHT_EFFECT_CHRISTMAS | ||
56 | #define RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
57 | #define RGBLIGHT_EFFECT_RGB_TEST | ||
58 | // #define RGBLIGHT_EFFECT_ALTERNATING | ||
59 | #endif | ||
60 | |||
61 | #define MEDIA_KEY_DELAY 2 | ||
62 | |||
63 | #define USB_POLLING_INTERVAL_MS 1 | ||
64 | #define QMK_KEYS_PER_SCAN 12 | ||
diff --git a/keyboards/sofle/keymaps/killmaster/keymap.c b/keyboards/sofle/keymaps/killmaster/keymap.c new file mode 100644 index 000000000..950dee36b --- /dev/null +++ b/keyboards/sofle/keymaps/killmaster/keymap.c | |||
@@ -0,0 +1,403 @@ | |||
1 | /* Copyright 2021 Carlos Martins | ||
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 QMK_KEYBOARD_H | ||
18 | #include <stdio.h> | ||
19 | |||
20 | enum sofle_layers { | ||
21 | /* _M_XYZ = Mac Os, _W_XYZ = Win/Linux */ | ||
22 | _QWERTY, | ||
23 | _LOWER, | ||
24 | _RAISE, | ||
25 | _ADJUST, | ||
26 | }; | ||
27 | |||
28 | enum custom_keycodes { | ||
29 | KC_QWERTY = SAFE_RANGE, | ||
30 | KC_LOWER, | ||
31 | KC_RAISE, | ||
32 | KC_ADJUST, | ||
33 | KC_PRVWD, | ||
34 | KC_NXTWD, | ||
35 | KC_LSTRT, | ||
36 | KC_LEND, | ||
37 | KC_DLINE | ||
38 | }; | ||
39 | |||
40 | |||
41 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
42 | /* | ||
43 | * QWERTY | ||
44 | * ,-----------------------------------------. ,-----------------------------------------. | ||
45 | * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ` | | ||
46 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
47 | * | ESC | Q | W | E | R | T | | Y | U | I | O | P | Bspc | | ||
48 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
49 | * | Tab | A | S | D | F | G |-------. ,-------| H | J | K | L | ; | ' | | ||
50 | * |------+------+------+------+------+------| | | |------+------+------+------+------+------| | ||
51 | * |LShift| Z | X | C | V | B |-------| |-------| N | M | , | . | / |RShift| | ||
52 | * `-----------------------------------------/ / \ \-----------------------------------------' | ||
53 | * | LGUI | LAlt | LCTR |LOWER | /Space / \Enter \ |RAISE | RCTR | RAlt | RGUI | | ||
54 | * | | | | |/ / \ \ | | | | | | ||
55 | * `----------------------------------' '------''---------------------------' | ||
56 | */ | ||
57 | |||
58 | [_QWERTY] = LAYOUT( | ||
59 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, | ||
60 | KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, | ||
61 | KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, | ||
62 | KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_MUTE, KC_MPLY,KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSPC, | ||
63 | KC_LGUI,KC_LALT,KC_LCTRL, KC_LOWER, KC_SPC, KC_ENT, KC_RAISE, KC_RCTRL, KC_RALT, KC_RGUI | ||
64 | ), | ||
65 | /* LOWER | ||
66 | * ,-----------------------------------------. ,-----------------------------------------. | ||
67 | * | | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | F11 | | ||
68 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
69 | * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | F12 | | ||
70 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
71 | * | Tab | ! | @ | # | $ | % |-------. ,-------| ^ | & | * | ( | ) | | | | ||
72 | * |------+------+------+------+------+------| MUTE | | |------+------+------+------+------+------| | ||
73 | * | Shift| = | - | + | { | } |-------| |-------| [ | ] | ; | : | \ | Shift| | ||
74 | * `-----------------------------------------/ / \ \-----------------------------------------' | ||
75 | * | LGUI | LAlt | LCTR |LOWER | /Enter / \Space \ |RAISE | RCTR | RAlt | RGUI | | ||
76 | * | | | | |/ / \ \ | | | | | | ||
77 | * `----------------------------------' '------''---------------------------' | ||
78 | */ | ||
79 | [_LOWER] = LAYOUT( | ||
80 | _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, | ||
81 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_F12, | ||
82 | _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PIPE, | ||
83 | _______, KC_EQL, KC_MINS, KC_PLUS, KC_LCBR, KC_RCBR, _______, _______, KC_LBRC, KC_RBRC, KC_SCLN, KC_COLN, KC_BSLS, _______, | ||
84 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ | ||
85 | ), | ||
86 | /* RAISE | ||
87 | * ,----------------------------------------. ,-----------------------------------------. | ||
88 | * | | | | | | | | | | | | | | | ||
89 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
90 | * | Esc | Ins | Pscr | Menu | |RGBTog| | | PWrd | Up | NWrd | DLine| Bspc | | ||
91 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
92 | * | Tab | LAt | LCtl |LShift| | Caps |-------. ,-------| | Left | Down | Rigth| Del | Bspc | | ||
93 | * |------+------+------+------+------+------| MUTE | | |------+------+------+------+------+------| | ||
94 | * |Shift | Undo | Cut | Copy | Paste| |-------| |-------| | LStr | | LEnd | | Shift| | ||
95 | * `-----------------------------------------/ / \ \-----------------------------------------' | ||
96 | * | LGUI | LAlt | LCTR |LOWER | /Enter / \Space \ |RAISE | RCTR | RAlt | RGUI | | ||
97 | * | | | | |/ / \ \ | | | | | | ||
98 | * `----------------------------------' '------''---------------------------' | ||
99 | */ | ||
100 | [_RAISE] = LAYOUT( | ||
101 | _______, _______ , _______ , _______ , RGB_RMOD , RGB_MOD, _______, _______ , _______, _______ , _______ ,_______, | ||
102 | _______, KC_INS, KC_PSCR, KC_APP, XXXXXXX, RGB_TOG, KC_PGUP, KC_PRVWD, KC_UP, KC_NXTWD,KC_DLINE, KC_BSPC, | ||
103 | _______, KC_LALT, KC_LCTL, KC_LSFT, XXXXXXX, KC_CAPS, KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT, KC_DEL, KC_BSPC, | ||
104 | _______,XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, _______, XXXXXXX, KC_LSTRT, XXXXXXX, KC_LEND, XXXXXXX, _______, | ||
105 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ | ||
106 | ), | ||
107 | /* ADJUST | ||
108 | * ,-----------------------------------------. ,-----------------------------------------. | ||
109 | * | | | | | | | | | | | | | | | ||
110 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
111 | * | RESET| |QWERTY|COLEMAK| | | | | | | | | | | ||
112 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
113 | * | | |MACWIN| | | |-------. ,-------| | VOLDO| MUTE | VOLUP| | | | ||
114 | * |------+------+------+------+------+------| MUTE | | |------+------+------+------+------+------| | ||
115 | * | | | | | | |-------| |-------| | PREV | PLAY | NEXT | | | | ||
116 | * `-----------------------------------------/ / \ \-----------------------------------------' | ||
117 | * | LGUI | LAlt | LCTR |LOWER | /Enter / \Space \ |RAISE | RCTR | RAlt | RGUI | | ||
118 | * | | | | |/ / \ \ | | | | | | ||
119 | * `----------------------------------' '------''---------------------------' | ||
120 | */ | ||
121 | [_ADJUST] = LAYOUT( | ||
122 | XXXXXXX , XXXXXXX, XXXXXXX , XXXXXXX , XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
123 | RESET , XXXXXXX, KC_QWERTY, XXXXXXX , CG_TOGG,XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
124 | XXXXXXX , XXXXXXX,CG_TOGG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_VOLD, KC_MUTE, KC_VOLU, XXXXXXX, XXXXXXX, | ||
125 | XXXXXXX , XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MPRV, KC_MPLY, KC_MNXT, XXXXXXX, XXXXXXX, | ||
126 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ | ||
127 | ) | ||
128 | }; | ||
129 | |||
130 | #ifdef OLED_DRIVER_ENABLE | ||
131 | |||
132 | static void render_logo(void) { | ||
133 | static const char PROGMEM bananas_logo[] = { | ||
134 | // 'killmaster_bananas', 128x32px | ||
135 | 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xc0, 0xe0, 0x02, 0x0e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
137 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
139 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
143 | 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
144 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, | ||
145 | 0x00, 0x00, 0x80, 0xc0, 0x40, 0x00, 0x00, 0x00, 0x40, 0x40, 0xd8, 0xc8, 0x00, 0x00, 0x00, 0x00, | ||
146 | 0x08, 0x08, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0xf8, 0x00, 0x00, 0x00, | ||
147 | 0x00, 0x00, 0xc0, 0x40, 0x40, 0xc0, 0x80, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, | ||
148 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0xc0, 0x40, 0x00, 0x00, 0x40, 0x40, 0xf0, | ||
149 | 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0xc0, 0x80, 0x00, 0x00, 0x00, | ||
150 | 0x40, 0xc0, 0x80, 0x40, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
151 | 0x00, 0x01, 0x0f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xf0, | ||
152 | 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, | ||
153 | 0x02, 0x07, 0x0d, 0x10, 0x20, 0x20, 0x00, 0x00, 0x20, 0x20, 0x3f, 0x3f, 0x20, 0x20, 0x00, 0x00, | ||
154 | 0x00, 0x00, 0x1f, 0x3f, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x20, 0x20, 0x20, | ||
155 | 0x00, 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x1c, 0x36, 0x22, 0x22, 0x22, | ||
156 | 0x1f, 0x20, 0x00, 0x00, 0x10, 0x23, 0x22, 0x22, 0x26, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1f, | ||
157 | 0x30, 0x20, 0x20, 0x20, 0x00, 0x00, 0x0f, 0x1f, 0x32, 0x22, 0x22, 0x32, 0x23, 0x00, 0x00, 0x00, | ||
158 | 0x20, 0x3f, 0x21, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
159 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x1f, 0x1f, | ||
160 | 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3e, 0x3e, 0x1c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
161 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
162 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
163 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
164 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
166 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
167 | }; | ||
168 | oled_write_raw_P(bananas_logo, sizeof(bananas_logo)); | ||
169 | } | ||
170 | |||
171 | static void print_status_narrow(void) { | ||
172 | // Print current mode | ||
173 | oled_write_P(PSTR("Sofle"), false); | ||
174 | oled_write_P(PSTR("\n\n\n"), false); | ||
175 | switch (get_highest_layer(default_layer_state)) { | ||
176 | case _QWERTY: | ||
177 | oled_write_ln_P(PSTR("QWERT"), false); | ||
178 | break; | ||
179 | default: | ||
180 | oled_write_P(PSTR("Undef"), false); | ||
181 | } | ||
182 | oled_write_P(PSTR("\n\n"), false); | ||
183 | // Print current layer | ||
184 | oled_write_ln_P(PSTR("Layer"), false); | ||
185 | switch (get_highest_layer(layer_state)) { | ||
186 | case _QWERTY: | ||
187 | oled_write_P(PSTR("Base\n"), false); | ||
188 | break; | ||
189 | case _RAISE: | ||
190 | oled_write_P(PSTR("Raise"), false); | ||
191 | break; | ||
192 | case _LOWER: | ||
193 | oled_write_P(PSTR("Lower"), false); | ||
194 | break; | ||
195 | case _ADJUST: | ||
196 | oled_write_P(PSTR("Adj\n"), false); | ||
197 | break; | ||
198 | default: | ||
199 | oled_write_ln_P(PSTR("Undef"), false); | ||
200 | } | ||
201 | oled_write_P(PSTR("\n\n"), false); | ||
202 | } | ||
203 | |||
204 | oled_rotation_t oled_init_user(oled_rotation_t rotation) { | ||
205 | if (is_keyboard_master()) { | ||
206 | return OLED_ROTATION_270; | ||
207 | } | ||
208 | else { | ||
209 | return OLED_ROTATION_180; | ||
210 | } | ||
211 | return rotation; | ||
212 | } | ||
213 | |||
214 | void oled_task_user(void) { | ||
215 | if (is_keyboard_master()) { | ||
216 | print_status_narrow(); | ||
217 | } else { | ||
218 | render_logo(); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | |||
223 | |||
224 | #endif // OLED_DRIVER_ENABLE | ||
225 | |||
226 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
227 | switch (keycode) { | ||
228 | case KC_QWERTY: | ||
229 | if (record->event.pressed) { | ||
230 | set_single_persistent_default_layer(_QWERTY); | ||
231 | } | ||
232 | return false; | ||
233 | case KC_LOWER: | ||
234 | if (record->event.pressed) { | ||
235 | layer_on(_LOWER); | ||
236 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | ||
237 | } else { | ||
238 | layer_off(_LOWER); | ||
239 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | ||
240 | } | ||
241 | return false; | ||
242 | case KC_RAISE: | ||
243 | if (record->event.pressed) { | ||
244 | layer_on(_RAISE); | ||
245 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | ||
246 | } else { | ||
247 | layer_off(_RAISE); | ||
248 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | ||
249 | } | ||
250 | return false; | ||
251 | case KC_ADJUST: | ||
252 | if (record->event.pressed) { | ||
253 | layer_on(_ADJUST); | ||
254 | } else { | ||
255 | layer_off(_ADJUST); | ||
256 | } | ||
257 | return false; | ||
258 | case KC_PRVWD: | ||
259 | if (record->event.pressed) { | ||
260 | if (keymap_config.swap_lctl_lgui) { | ||
261 | register_mods(mod_config(MOD_LALT)); | ||
262 | register_code(KC_LEFT); | ||
263 | } else { | ||
264 | register_mods(mod_config(MOD_LCTL)); | ||
265 | register_code(KC_LEFT); | ||
266 | } | ||
267 | } else { | ||
268 | if (keymap_config.swap_lctl_lgui) { | ||
269 | unregister_mods(mod_config(MOD_LALT)); | ||
270 | unregister_code(KC_LEFT); | ||
271 | } else { | ||
272 | unregister_mods(mod_config(MOD_LCTL)); | ||
273 | unregister_code(KC_LEFT); | ||
274 | } | ||
275 | } | ||
276 | break; | ||
277 | case KC_NXTWD: | ||
278 | if (record->event.pressed) { | ||
279 | if (keymap_config.swap_lctl_lgui) { | ||
280 | register_mods(mod_config(MOD_LALT)); | ||
281 | register_code(KC_RIGHT); | ||
282 | } else { | ||
283 | register_mods(mod_config(MOD_LCTL)); | ||
284 | register_code(KC_RIGHT); | ||
285 | } | ||
286 | } else { | ||
287 | if (keymap_config.swap_lctl_lgui) { | ||
288 | unregister_mods(mod_config(MOD_LALT)); | ||
289 | unregister_code(KC_RIGHT); | ||
290 | } else { | ||
291 | unregister_mods(mod_config(MOD_LCTL)); | ||
292 | unregister_code(KC_RIGHT); | ||
293 | } | ||
294 | } | ||
295 | break; | ||
296 | case KC_LSTRT: | ||
297 | if (record->event.pressed) { | ||
298 | if (keymap_config.swap_lctl_lgui) { | ||
299 | //CMD-arrow on Mac, but we have CTL and GUI swapped | ||
300 | register_mods(mod_config(MOD_LCTL)); | ||
301 | register_code(KC_LEFT); | ||
302 | } else { | ||
303 | register_code(KC_HOME); | ||
304 | } | ||
305 | } else { | ||
306 | if (keymap_config.swap_lctl_lgui) { | ||
307 | unregister_mods(mod_config(MOD_LCTL)); | ||
308 | unregister_code(KC_LEFT); | ||
309 | } else { | ||
310 | unregister_code(KC_HOME); | ||
311 | } | ||
312 | } | ||
313 | break; | ||
314 | case KC_LEND: | ||
315 | if (record->event.pressed) { | ||
316 | if (keymap_config.swap_lctl_lgui) { | ||
317 | //CMD-arrow on Mac, but we have CTL and GUI swapped | ||
318 | register_mods(mod_config(MOD_LCTL)); | ||
319 | register_code(KC_RIGHT); | ||
320 | } else { | ||
321 | register_code(KC_END); | ||
322 | } | ||
323 | } else { | ||
324 | if (keymap_config.swap_lctl_lgui) { | ||
325 | unregister_mods(mod_config(MOD_LCTL)); | ||
326 | unregister_code(KC_RIGHT); | ||
327 | } else { | ||
328 | unregister_code(KC_END); | ||
329 | } | ||
330 | } | ||
331 | break; | ||
332 | case KC_DLINE: | ||
333 | if (record->event.pressed) { | ||
334 | register_mods(mod_config(MOD_LCTL)); | ||
335 | register_code(KC_BSPC); | ||
336 | } else { | ||
337 | unregister_mods(mod_config(MOD_LCTL)); | ||
338 | unregister_code(KC_BSPC); | ||
339 | } | ||
340 | break; | ||
341 | } | ||
342 | return true; | ||
343 | } | ||
344 | |||
345 | #ifdef ENCODER_ENABLE | ||
346 | |||
347 | bool encoder_update_user(uint8_t index, bool clockwise) { | ||
348 | uint8_t temp_mod = get_mods(); | ||
349 | uint8_t temp_osm = get_oneshot_mods(); | ||
350 | bool is_ctrl = (temp_mod | temp_osm) & MOD_MASK_CTRL; | ||
351 | bool is_shift = (temp_mod | temp_osm) & MOD_MASK_SHIFT; | ||
352 | |||
353 | if (is_shift) { | ||
354 | if (index == 0) { /* First encoder */ | ||
355 | if (clockwise) { | ||
356 | rgb_matrix_increase_hue(); | ||
357 | } else { | ||
358 | rgb_matrix_decrease_hue(); | ||
359 | } | ||
360 | } else if (index == 1) { /* Second encoder */ | ||
361 | if (clockwise) { | ||
362 | rgb_matrix_decrease_sat(); | ||
363 | } else { | ||
364 | rgb_matrix_increase_sat(); | ||
365 | } | ||
366 | } | ||
367 | } else if (is_ctrl) { | ||
368 | if (index == 0) { /* First encoder */ | ||
369 | if (clockwise) { | ||
370 | rgb_matrix_increase_val(); | ||
371 | } else { | ||
372 | rgb_matrix_decrease_val(); | ||
373 | } | ||
374 | } else if (index == 1) { /* Second encoder */ | ||
375 | if (clockwise) { | ||
376 | rgb_matrix_increase_speed(); | ||
377 | } else { | ||
378 | rgb_matrix_decrease_speed(); | ||
379 | } | ||
380 | } | ||
381 | } else { | ||
382 | if (index == 1) { /* First encoder */ | ||
383 | if (clockwise) { | ||
384 | tap_code(KC_PGUP); | ||
385 | // tap_code(KC_MS_WH_UP); | ||
386 | } else { | ||
387 | tap_code(KC_PGDOWN); | ||
388 | // tap_code(KC_MS_WH_DOWN); | ||
389 | } | ||
390 | } else if (index == 0) { /* Second encoder */ | ||
391 | uint16_t mapped_code = 0; | ||
392 | if (clockwise) { | ||
393 | mapped_code = KC_VOLD; | ||
394 | } else { | ||
395 | mapped_code = KC_VOLU; | ||
396 | } | ||
397 | tap_code_delay(mapped_code, MEDIA_KEY_DELAY); | ||
398 | } | ||
399 | } | ||
400 | return true; | ||
401 | } | ||
402 | |||
403 | #endif | ||
diff --git a/keyboards/sofle/keymaps/killmaster/readme.md b/keyboards/sofle/keymaps/killmaster/readme.md new file mode 100644 index 000000000..6d6dea228 --- /dev/null +++ b/keyboards/sofle/keymaps/killmaster/readme.md | |||
@@ -0,0 +1,19 @@ | |||
1 |  | ||
2 |  | ||
3 | |||
4 | |||
5 | # Default keymap for Sofle Keyboard | ||
6 | |||
7 | Layout in [Keyboard Layout Editor](http://www.keyboard-layout-editor.com/#/gists/76efb423a46cbbea75465cb468eef7ff) and [adjust layer](http://www.keyboard-layout-editor.com/#/gists/4bcf66f922cfd54da20ba04905d56bd4) | ||
8 | |||
9 | |||
10 | Features: | ||
11 | |||
12 | - Symmetric modifiers (CMD/Super, Alt/Opt, Ctrl, Shift) | ||
13 | - Various modes, can be switched (using Adjust layer and the selected one is stored in EEPROM. | ||
14 | - Modes for Qwerty and Colemak support | ||
15 | - Modes for Mac vs Linux/Win support -> different order of modifiers and different action shortcuts on the "UPPER" layer (the red one in the image). Designed to simplify transtions when switching between operating systems often. | ||
16 | - The OLED on master half shows selected mode and caps lock state and is rotated. | ||
17 | - Left encoder controls volume up/down/mute. Right encoder PGUP/PGDOWN. | ||
18 | |||
19 | |||
diff --git a/keyboards/sofle/keymaps/killmaster/rules.mk b/keyboards/sofle/keymaps/killmaster/rules.mk new file mode 100644 index 000000000..38d611450 --- /dev/null +++ b/keyboards/sofle/keymaps/killmaster/rules.mk | |||
@@ -0,0 +1,4 @@ | |||
1 | EXTRAKEY_ENABLE = yes | ||
2 | LTO_ENABLE = yes | ||
3 | RGB_MATRIX_ENABLE = yes | ||
4 | RGB_MATRIX_DRIVER = WS2812 | ||
diff --git a/keyboards/sofle/rev1/readme.md b/keyboards/sofle/rev1/readme.md new file mode 100644 index 000000000..629d568e6 --- /dev/null +++ b/keyboards/sofle/rev1/readme.md | |||
@@ -0,0 +1,27 @@ | |||
1 | # Sofle Keyboard | ||
2 | |||
3 |  | ||
4 | |||
5 | Sofle is 6×4+5 keys column-staggered split keyboard. Based on Lily58, Corne and Helix keyboards. | ||
6 | |||
7 | More details about the keyboard on my blog: [Let me introduce you SofleKeyboard - a split keyboard based on Lily58 and Crkbd](https://josef-adamcik.cz/electronics/let-me-introduce-you-sofle-keyboard-split-keyboard-based-on-lily58.html) | ||
8 | |||
9 | The current (temporary) build guide and a build log is available here: [SofleKeyboard build log/guide](https://josef-adamcik.cz/electronics/soflekeyboard-build-log-and-build-guide.html) | ||
10 | |||
11 | * Keyboard Maintainer: [Josef Adamcik](https://josef-adamcik.cz) [Twitter:@josefadamcik](https://twitter.com/josefadamcik) | ||
12 | * Hardware Supported: SofleKeyboard PCB, ProMicro | ||
13 | * Hardware Availability: [PCB & Case Data](https://github.com/josefadamcik/SofleKeyboard) | ||
14 | |||
15 | Make example for this keyboard (after setting up your build environment): | ||
16 | |||
17 | make sofle:default | ||
18 | |||
19 | Flashing example for this keyboard: | ||
20 | |||
21 | make sofle:default:flash | ||
22 | |||
23 | Press reset button on he keyboard when asked. | ||
24 | |||
25 | Disconnect the first half, connect the second one and repeat the process. | ||
26 | |||
27 | See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). | ||
diff --git a/keyboards/sofle/rev1/rev1.c b/keyboards/sofle/rev1/rev1.c index bbb014c4d..88a28e6a4 100644 --- a/keyboards/sofle/rev1/rev1.c +++ b/keyboards/sofle/rev1/rev1.c | |||
@@ -1 +1,87 @@ | |||
1 | /* Copyright 2021 Carlos Martins | ||
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 | |||
1 | #include "sofle.h" | 17 | #include "sofle.h" |
18 | |||
19 | #ifdef RGB_MATRIX_ENABLE | ||
20 | // Physical Layout | ||
21 | // Columns | ||
22 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | ||
23 | // ROWS | ||
24 | // 12 13 22 23 32 33 33 32 23 22 13 12 0 | ||
25 | // 02 03 04 04 03 02 | ||
26 | // 11 14 21 24 31 34 34 31 24 21 14 11 1 | ||
27 | // 01 01 | ||
28 | // 10 15 20 25 30 35 35 30 25 20 15 10 2 | ||
29 | // | ||
30 | // 09 16 19 26 29 36 36 29 26 19 16 09 3 | ||
31 | // | ||
32 | // 08 17 18 27 28 28 27 18 17 08 4 | ||
33 | // 07 06 05 05 06 07 | ||
34 | |||
35 | led_config_t g_led_config = { | ||
36 | { | ||
37 | { 11, 12, 21, 22, 31, 32 }, | ||
38 | { 10, 13, 20, 23, 30, 33 }, | ||
39 | { 9, 14, 19, 24, 29, 34}, | ||
40 | { 8, 15, 18, 25, 28, 35}, | ||
41 | { 7, 16, 17, 26, 27, NO_LED }, | ||
42 | { 47, 48, 57, 58, 67, 68}, | ||
43 | { 46, 49, 56, 59, 66, 69}, | ||
44 | { 45, 50, 55, 60, 65, 70}, | ||
45 | { 44, 51, 54, 61, 64, 71}, | ||
46 | { 43, 52, 53, 62, 63, NO_LED } | ||
47 | }, | ||
48 | { | ||
49 | // Left side underglow | ||
50 | {96, 40}, {16, 20}, {48, 10}, {80, 18}, {88, 60}, {56, 57}, {24,60}, | ||
51 | // Left side Matrix | ||
52 | {32, 57}, { 0, 48}, { 0, 36}, { 0, 24}, { 0, 12}, | ||
53 | {16, 12}, {16, 24}, {16, 36}, {16, 48}, {48, 55}, | ||
54 | {64, 57}, {32, 45}, {32, 33}, {32, 21}, {32, 9}, | ||
55 | {48, 7}, {48, 19}, {48, 31}, {48, 43}, {80, 59}, | ||
56 | {96, 64}, {64, 45}, {64, 33}, {64, 21}, {64, 9}, | ||
57 | {80, 10}, {80, 22}, {80, 34}, {80, 47}, | ||
58 | |||
59 | |||
60 | // Right side underglow | ||
61 | {128, 40}, {208, 20}, {176, 10}, {144, 18}, {136, 60}, {168, 57}, {200,60}, | ||
62 | // Right side Matrix | ||
63 | {192, 57}, {224, 48}, {224, 36}, {224, 24}, {224, 12}, | ||
64 | {208, 12}, {208, 24}, {208, 36}, {208, 48}, {176, 55}, | ||
65 | {160, 57}, {192, 45}, {192, 33}, {192, 21}, {192, 9}, | ||
66 | {176, 7}, {176, 19}, {176, 31}, {176, 43}, {144, 59}, | ||
67 | {128, 64}, {160, 45}, {160, 33}, {160, 21}, {160, 9}, | ||
68 | {144, 10}, {144, 22}, {144, 34}, {144, 47}, | ||
69 | }, | ||
70 | { | ||
71 | LED_FLAG_NONE, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, | ||
72 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
73 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
74 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
75 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
76 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
77 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
78 | LED_FLAG_NONE, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, LED_FLAG_UNDERGLOW, | ||
79 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
80 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
81 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
82 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
83 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, | ||
84 | LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT, LED_FLAG_KEYLIGHT | ||
85 | } | ||
86 | }; | ||
87 | #endif | ||
diff --git a/lib/chibios b/lib/chibios | |||
Subproject ffe54d63cb10a355add318f8e922e39f1c3d4bf | Subproject 413e39c5681d181720440f2a8b7391f581788d7 | ||
diff --git a/lib/chibios-contrib b/lib/chibios-contrib | |||
Subproject 61baa6b036138c155f7cfc5646d833d9423f324 | Subproject 9c2bfa6aeba993345f5425d82807c101f8e25e6 | ||
diff --git a/quantum/debounce.h b/quantum/debounce.h index 9ca05c682..504386828 100644 --- a/quantum/debounce.h +++ b/quantum/debounce.h | |||
@@ -9,3 +9,5 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool | |||
9 | bool debounce_active(void); | 9 | bool debounce_active(void); |
10 | 10 | ||
11 | void debounce_init(uint8_t num_rows); | 11 | void debounce_init(uint8_t num_rows); |
12 | |||
13 | void debounce_free(void); | ||
diff --git a/quantum/debounce/none.c b/quantum/debounce/none.c new file mode 100644 index 000000000..b03892bc5 --- /dev/null +++ b/quantum/debounce/none.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 "matrix.h" | ||
18 | #include "quantum.h" | ||
19 | #include <stdlib.h> | ||
20 | |||
21 | void debounce_init(uint8_t num_rows) {} | ||
22 | |||
23 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | ||
24 | for (int i = 0; i < num_rows; i++) { | ||
25 | cooked[i] = raw[i]; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | bool debounce_active(void) { return false; } | ||
30 | |||
31 | void debounce_free(void) {} | ||
diff --git a/quantum/debounce/sym_defer_g.c b/quantum/debounce/sym_defer_g.c index 3ed9055d2..fbefd55ed 100644 --- a/quantum/debounce/sym_defer_g.c +++ b/quantum/debounce/sym_defer_g.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2017 Alex Ong<the.onga@gmail.com> | 2 | Copyright 2017 Alex Ong<the.onga@gmail.com> |
3 | Copyright 2021 Simon Arlott | ||
3 | This program is free software: you can redistribute it and/or modify | 4 | 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 | 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 | the Free Software Foundation, either version 2 of the License, or |
@@ -23,30 +24,29 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state. | |||
23 | # define DEBOUNCE 5 | 24 | # define DEBOUNCE 5 |
24 | #endif | 25 | #endif |
25 | 26 | ||
26 | void debounce_init(uint8_t num_rows) {} | 27 | #if DEBOUNCE > 0 |
27 | static bool debouncing = false; | 28 | static bool debouncing = false; |
29 | static fast_timer_t debouncing_time; | ||
28 | 30 | ||
29 | #if DEBOUNCE > 0 | 31 | void debounce_init(uint8_t num_rows) {} |
30 | static uint16_t debouncing_time; | 32 | |
31 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | 33 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { |
32 | if (changed) { | 34 | if (changed) { |
33 | debouncing = true; | 35 | debouncing = true; |
34 | debouncing_time = timer_read(); | 36 | debouncing_time = timer_read_fast(); |
35 | } | 37 | } |
36 | 38 | ||
37 | if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { | 39 | if (debouncing && timer_elapsed_fast(debouncing_time) >= DEBOUNCE) { |
38 | for (int i = 0; i < num_rows; i++) { | 40 | for (int i = 0; i < num_rows; i++) { |
39 | cooked[i] = raw[i]; | 41 | cooked[i] = raw[i]; |
40 | } | 42 | } |
41 | debouncing = false; | 43 | debouncing = false; |
42 | } | 44 | } |
43 | } | 45 | } |
44 | #else // no debouncing. | ||
45 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | ||
46 | for (int i = 0; i < num_rows; i++) { | ||
47 | cooked[i] = raw[i]; | ||
48 | } | ||
49 | } | ||
50 | #endif | ||
51 | 46 | ||
52 | bool debounce_active(void) { return debouncing; } | 47 | bool debounce_active(void) { return debouncing; } |
48 | |||
49 | void debounce_free(void) {} | ||
50 | #else // no debouncing. | ||
51 | # include "none.c" | ||
52 | #endif | ||
diff --git a/quantum/debounce/sym_defer_pk.c b/quantum/debounce/sym_defer_pk.c index 60513f98e..626a9be84 100644 --- a/quantum/debounce/sym_defer_pk.c +++ b/quantum/debounce/sym_defer_pk.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2017 Alex Ong<the.onga@gmail.com> | 2 | Copyright 2017 Alex Ong<the.onga@gmail.com> |
3 | Copyright 2020 Andrei Purdea<andrei@purdea.ro> | 3 | Copyright 2020 Andrei Purdea<andrei@purdea.ro> |
4 | Copyright 2021 Simon Arlott | ||
4 | This program is free software: you can redistribute it and/or modify | 5 | This program is free software: you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation, either version 2 of the License, or | 7 | the Free Software Foundation, either version 2 of the License, or |
@@ -33,28 +34,25 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state. | |||
33 | # define DEBOUNCE 5 | 34 | # define DEBOUNCE 5 |
34 | #endif | 35 | #endif |
35 | 36 | ||
37 | // Maximum debounce: 255ms | ||
38 | #if DEBOUNCE > UINT8_MAX | ||
39 | # undef DEBOUNCE | ||
40 | # define DEBOUNCE UINT8_MAX | ||
41 | #endif | ||
42 | |||
36 | #define ROW_SHIFTER ((matrix_row_t)1) | 43 | #define ROW_SHIFTER ((matrix_row_t)1) |
37 | 44 | ||
38 | #define debounce_counter_t uint8_t | 45 | typedef uint8_t debounce_counter_t; |
39 | 46 | ||
47 | #if DEBOUNCE > 0 | ||
40 | static debounce_counter_t *debounce_counters; | 48 | static debounce_counter_t *debounce_counters; |
49 | static fast_timer_t last_time; | ||
41 | static bool counters_need_update; | 50 | static bool counters_need_update; |
42 | 51 | ||
43 | #define DEBOUNCE_ELAPSED 251 | 52 | #define DEBOUNCE_ELAPSED 0 |
44 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | ||
45 | |||
46 | static uint8_t wrapping_timer_read(void) { | ||
47 | static uint16_t time = 0; | ||
48 | static uint8_t last_result = 0; | ||
49 | uint16_t new_time = timer_read(); | ||
50 | uint16_t diff = new_time - time; | ||
51 | time = new_time; | ||
52 | last_result = (last_result + diff) % (MAX_DEBOUNCE + 1); | ||
53 | return last_result; | ||
54 | } | ||
55 | 53 | ||
56 | void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); | 54 | static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); |
57 | void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); | 55 | static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); |
58 | 56 | ||
59 | // we use num_rows rather than MATRIX_ROWS to support split keyboards | 57 | // we use num_rows rather than MATRIX_ROWS to support split keyboards |
60 | void debounce_init(uint8_t num_rows) { | 58 | void debounce_init(uint8_t num_rows) { |
@@ -67,27 +65,49 @@ void debounce_init(uint8_t num_rows) { | |||
67 | } | 65 | } |
68 | } | 66 | } |
69 | 67 | ||
68 | void debounce_free(void) { | ||
69 | free(debounce_counters); | ||
70 | debounce_counters = NULL; | ||
71 | } | ||
72 | |||
70 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | 73 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { |
71 | uint8_t current_time = wrapping_timer_read(); | 74 | bool updated_last = false; |
75 | |||
72 | if (counters_need_update) { | 76 | if (counters_need_update) { |
73 | update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, current_time); | 77 | fast_timer_t now = timer_read_fast(); |
78 | fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); | ||
79 | |||
80 | last_time = now; | ||
81 | updated_last = true; | ||
82 | if (elapsed_time > UINT8_MAX) { | ||
83 | elapsed_time = UINT8_MAX; | ||
84 | } | ||
85 | |||
86 | if (elapsed_time > 0) { | ||
87 | update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, elapsed_time); | ||
88 | } | ||
74 | } | 89 | } |
75 | 90 | ||
76 | if (changed) { | 91 | if (changed) { |
77 | start_debounce_counters(raw, cooked, num_rows, current_time); | 92 | if (!updated_last) { |
93 | last_time = timer_read_fast(); | ||
94 | } | ||
95 | |||
96 | start_debounce_counters(raw, cooked, num_rows); | ||
78 | } | 97 | } |
79 | } | 98 | } |
80 | 99 | ||
81 | void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { | 100 | static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) { |
82 | counters_need_update = false; | 101 | counters_need_update = false; |
83 | debounce_counter_t *debounce_pointer = debounce_counters; | 102 | debounce_counter_t *debounce_pointer = debounce_counters; |
84 | for (uint8_t row = 0; row < num_rows; row++) { | 103 | for (uint8_t row = 0; row < num_rows; row++) { |
85 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 104 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
86 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { | 105 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { |
87 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { | 106 | if (*debounce_pointer <= elapsed_time) { |
88 | *debounce_pointer = DEBOUNCE_ELAPSED; | 107 | *debounce_pointer = DEBOUNCE_ELAPSED; |
89 | cooked[row] = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col)); | 108 | cooked[row] = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col)); |
90 | } else { | 109 | } else { |
110 | *debounce_pointer -= elapsed_time; | ||
91 | counters_need_update = true; | 111 | counters_need_update = true; |
92 | } | 112 | } |
93 | } | 113 | } |
@@ -96,14 +116,14 @@ void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix | |||
96 | } | 116 | } |
97 | } | 117 | } |
98 | 118 | ||
99 | void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { | 119 | static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { |
100 | debounce_counter_t *debounce_pointer = debounce_counters; | 120 | debounce_counter_t *debounce_pointer = debounce_counters; |
101 | for (uint8_t row = 0; row < num_rows; row++) { | 121 | for (uint8_t row = 0; row < num_rows; row++) { |
102 | matrix_row_t delta = raw[row] ^ cooked[row]; | 122 | matrix_row_t delta = raw[row] ^ cooked[row]; |
103 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 123 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
104 | if (delta & (ROW_SHIFTER << col)) { | 124 | if (delta & (ROW_SHIFTER << col)) { |
105 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { | 125 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { |
106 | *debounce_pointer = current_time; | 126 | *debounce_pointer = DEBOUNCE; |
107 | counters_need_update = true; | 127 | counters_need_update = true; |
108 | } | 128 | } |
109 | } else { | 129 | } else { |
@@ -115,3 +135,6 @@ void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t | |||
115 | } | 135 | } |
116 | 136 | ||
117 | bool debounce_active(void) { return true; } | 137 | bool debounce_active(void) { return true; } |
138 | #else | ||
139 | # include "none.c" | ||
140 | #endif | ||
diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c index e66cf92d7..15a3242e6 100644 --- a/quantum/debounce/sym_eager_pk.c +++ b/quantum/debounce/sym_eager_pk.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2017 Alex Ong<the.onga@gmail.com> | 2 | Copyright 2017 Alex Ong<the.onga@gmail.com> |
3 | Copyright 2021 Simon Arlott | ||
3 | This program is free software: you can redistribute it and/or modify | 4 | 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 | 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 | the Free Software Foundation, either version 2 of the License, or |
@@ -33,29 +34,26 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred. | |||
33 | # define DEBOUNCE 5 | 34 | # define DEBOUNCE 5 |
34 | #endif | 35 | #endif |
35 | 36 | ||
37 | // Maximum debounce: 255ms | ||
38 | #if DEBOUNCE > UINT8_MAX | ||
39 | # undef DEBOUNCE | ||
40 | # define DEBOUNCE UINT8_MAX | ||
41 | #endif | ||
42 | |||
36 | #define ROW_SHIFTER ((matrix_row_t)1) | 43 | #define ROW_SHIFTER ((matrix_row_t)1) |
37 | 44 | ||
38 | #define debounce_counter_t uint8_t | 45 | typedef uint8_t debounce_counter_t; |
39 | 46 | ||
47 | #if DEBOUNCE > 0 | ||
40 | static debounce_counter_t *debounce_counters; | 48 | static debounce_counter_t *debounce_counters; |
49 | static fast_timer_t last_time; | ||
41 | static bool counters_need_update; | 50 | static bool counters_need_update; |
42 | static bool matrix_need_update; | 51 | static bool matrix_need_update; |
43 | 52 | ||
44 | #define DEBOUNCE_ELAPSED 251 | 53 | #define DEBOUNCE_ELAPSED 0 |
45 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | ||
46 | |||
47 | static uint8_t wrapping_timer_read(void) { | ||
48 | static uint16_t time = 0; | ||
49 | static uint8_t last_result = 0; | ||
50 | uint16_t new_time = timer_read(); | ||
51 | uint16_t diff = new_time - time; | ||
52 | time = new_time; | ||
53 | last_result = (last_result + diff) % (MAX_DEBOUNCE + 1); | ||
54 | return last_result; | ||
55 | } | ||
56 | 54 | ||
57 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time); | 55 | static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); |
58 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); | 56 | static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); |
59 | 57 | ||
60 | // we use num_rows rather than MATRIX_ROWS to support split keyboards | 58 | // we use num_rows rather than MATRIX_ROWS to support split keyboards |
61 | void debounce_init(uint8_t num_rows) { | 59 | void debounce_init(uint8_t num_rows) { |
@@ -68,27 +66,51 @@ void debounce_init(uint8_t num_rows) { | |||
68 | } | 66 | } |
69 | } | 67 | } |
70 | 68 | ||
69 | void debounce_free(void) { | ||
70 | free(debounce_counters); | ||
71 | debounce_counters = NULL; | ||
72 | } | ||
73 | |||
71 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | 74 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { |
72 | uint8_t current_time = wrapping_timer_read(); | 75 | bool updated_last = false; |
76 | |||
73 | if (counters_need_update) { | 77 | if (counters_need_update) { |
74 | update_debounce_counters(num_rows, current_time); | 78 | fast_timer_t now = timer_read_fast(); |
79 | fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); | ||
80 | |||
81 | last_time = now; | ||
82 | updated_last = true; | ||
83 | if (elapsed_time > UINT8_MAX) { | ||
84 | elapsed_time = UINT8_MAX; | ||
85 | } | ||
86 | |||
87 | if (elapsed_time > 0) { | ||
88 | update_debounce_counters(num_rows, elapsed_time); | ||
89 | } | ||
75 | } | 90 | } |
76 | 91 | ||
77 | if (changed || matrix_need_update) { | 92 | if (changed || matrix_need_update) { |
78 | transfer_matrix_values(raw, cooked, num_rows, current_time); | 93 | if (!updated_last) { |
94 | last_time = timer_read_fast(); | ||
95 | } | ||
96 | |||
97 | transfer_matrix_values(raw, cooked, num_rows); | ||
79 | } | 98 | } |
80 | } | 99 | } |
81 | 100 | ||
82 | // If the current time is > debounce counter, set the counter to enable input. | 101 | // If the current time is > debounce counter, set the counter to enable input. |
83 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { | 102 | static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { |
84 | counters_need_update = false; | 103 | counters_need_update = false; |
104 | matrix_need_update = false; | ||
85 | debounce_counter_t *debounce_pointer = debounce_counters; | 105 | debounce_counter_t *debounce_pointer = debounce_counters; |
86 | for (uint8_t row = 0; row < num_rows; row++) { | 106 | for (uint8_t row = 0; row < num_rows; row++) { |
87 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 107 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
88 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { | 108 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { |
89 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { | 109 | if (*debounce_pointer <= elapsed_time) { |
90 | *debounce_pointer = DEBOUNCE_ELAPSED; | 110 | *debounce_pointer = DEBOUNCE_ELAPSED; |
111 | matrix_need_update = true; | ||
91 | } else { | 112 | } else { |
113 | *debounce_pointer -= elapsed_time; | ||
92 | counters_need_update = true; | 114 | counters_need_update = true; |
93 | } | 115 | } |
94 | } | 116 | } |
@@ -98,8 +120,7 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { | |||
98 | } | 120 | } |
99 | 121 | ||
100 | // upload from raw_matrix to final matrix; | 122 | // upload from raw_matrix to final matrix; |
101 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { | 123 | static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { |
102 | matrix_need_update = false; | ||
103 | debounce_counter_t *debounce_pointer = debounce_counters; | 124 | debounce_counter_t *debounce_pointer = debounce_counters; |
104 | for (uint8_t row = 0; row < num_rows; row++) { | 125 | for (uint8_t row = 0; row < num_rows; row++) { |
105 | matrix_row_t delta = raw[row] ^ cooked[row]; | 126 | matrix_row_t delta = raw[row] ^ cooked[row]; |
@@ -108,11 +129,9 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n | |||
108 | matrix_row_t col_mask = (ROW_SHIFTER << col); | 129 | matrix_row_t col_mask = (ROW_SHIFTER << col); |
109 | if (delta & col_mask) { | 130 | if (delta & col_mask) { |
110 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { | 131 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { |
111 | *debounce_pointer = current_time; | 132 | *debounce_pointer = DEBOUNCE; |
112 | counters_need_update = true; | 133 | counters_need_update = true; |
113 | existing_row ^= col_mask; // flip the bit. | 134 | existing_row ^= col_mask; // flip the bit. |
114 | } else { | ||
115 | matrix_need_update = true; | ||
116 | } | 135 | } |
117 | } | 136 | } |
118 | debounce_pointer++; | 137 | debounce_pointer++; |
@@ -122,3 +141,6 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n | |||
122 | } | 141 | } |
123 | 142 | ||
124 | bool debounce_active(void) { return true; } | 143 | bool debounce_active(void) { return true; } |
144 | #else | ||
145 | # include "none.c" | ||
146 | #endif | ||
diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c index 20ccb46f1..2ad592c5a 100644 --- a/quantum/debounce/sym_eager_pr.c +++ b/quantum/debounce/sym_eager_pr.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2019 Alex Ong<the.onga@gmail.com> | 2 | Copyright 2019 Alex Ong<the.onga@gmail.com> |
3 | Copyright 2021 Simon Arlott | ||
3 | This program is free software: you can redistribute it and/or modify | 4 | 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 | 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 | the Free Software Foundation, either version 2 of the License, or |
@@ -33,27 +34,25 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred. | |||
33 | # define DEBOUNCE 5 | 34 | # define DEBOUNCE 5 |
34 | #endif | 35 | #endif |
35 | 36 | ||
36 | #define debounce_counter_t uint8_t | 37 | // Maximum debounce: 255ms |
38 | #if DEBOUNCE > UINT8_MAX | ||
39 | # undef DEBOUNCE | ||
40 | # define DEBOUNCE UINT8_MAX | ||
41 | #endif | ||
42 | |||
43 | typedef uint8_t debounce_counter_t; | ||
44 | |||
45 | #if DEBOUNCE > 0 | ||
37 | static bool matrix_need_update; | 46 | static bool matrix_need_update; |
38 | 47 | ||
39 | static debounce_counter_t *debounce_counters; | 48 | static debounce_counter_t *debounce_counters; |
49 | static fast_timer_t last_time; | ||
40 | static bool counters_need_update; | 50 | static bool counters_need_update; |
41 | 51 | ||
42 | #define DEBOUNCE_ELAPSED 251 | 52 | #define DEBOUNCE_ELAPSED 0 |
43 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | ||
44 | |||
45 | static uint8_t wrapping_timer_read(void) { | ||
46 | static uint16_t time = 0; | ||
47 | static uint8_t last_result = 0; | ||
48 | uint16_t new_time = timer_read(); | ||
49 | uint16_t diff = new_time - time; | ||
50 | time = new_time; | ||
51 | last_result = (last_result + diff) % (MAX_DEBOUNCE + 1); | ||
52 | return last_result; | ||
53 | } | ||
54 | 53 | ||
55 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time); | 54 | static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); |
56 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); | 55 | static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); |
57 | 56 | ||
58 | // we use num_rows rather than MATRIX_ROWS to support split keyboards | 57 | // we use num_rows rather than MATRIX_ROWS to support split keyboards |
59 | void debounce_init(uint8_t num_rows) { | 58 | void debounce_init(uint8_t num_rows) { |
@@ -63,27 +62,50 @@ void debounce_init(uint8_t num_rows) { | |||
63 | } | 62 | } |
64 | } | 63 | } |
65 | 64 | ||
65 | void debounce_free(void) { | ||
66 | free(debounce_counters); | ||
67 | debounce_counters = NULL; | ||
68 | } | ||
69 | |||
66 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | 70 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { |
67 | uint8_t current_time = wrapping_timer_read(); | 71 | bool updated_last = false; |
68 | bool needed_update = counters_need_update; | 72 | |
69 | if (counters_need_update) { | 73 | if (counters_need_update) { |
70 | update_debounce_counters(num_rows, current_time); | 74 | fast_timer_t now = timer_read_fast(); |
75 | fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); | ||
76 | |||
77 | last_time = now; | ||
78 | updated_last = true; | ||
79 | if (elapsed_time > UINT8_MAX) { | ||
80 | elapsed_time = UINT8_MAX; | ||
81 | } | ||
82 | |||
83 | if (elapsed_time > 0) { | ||
84 | update_debounce_counters(num_rows, elapsed_time); | ||
85 | } | ||
71 | } | 86 | } |
72 | 87 | ||
73 | if (changed || (needed_update && !counters_need_update) || matrix_need_update) { | 88 | if (changed || matrix_need_update) { |
74 | transfer_matrix_values(raw, cooked, num_rows, current_time); | 89 | if (!updated_last) { |
90 | last_time = timer_read_fast(); | ||
91 | } | ||
92 | |||
93 | transfer_matrix_values(raw, cooked, num_rows); | ||
75 | } | 94 | } |
76 | } | 95 | } |
77 | 96 | ||
78 | // If the current time is > debounce counter, set the counter to enable input. | 97 | // If the current time is > debounce counter, set the counter to enable input. |
79 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { | 98 | static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { |
80 | counters_need_update = false; | 99 | counters_need_update = false; |
100 | matrix_need_update = false; | ||
81 | debounce_counter_t *debounce_pointer = debounce_counters; | 101 | debounce_counter_t *debounce_pointer = debounce_counters; |
82 | for (uint8_t row = 0; row < num_rows; row++) { | 102 | for (uint8_t row = 0; row < num_rows; row++) { |
83 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { | 103 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { |
84 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { | 104 | if (*debounce_pointer <= elapsed_time) { |
85 | *debounce_pointer = DEBOUNCE_ELAPSED; | 105 | *debounce_pointer = DEBOUNCE_ELAPSED; |
106 | matrix_need_update = true; | ||
86 | } else { | 107 | } else { |
108 | *debounce_pointer -= elapsed_time; | ||
87 | counters_need_update = true; | 109 | counters_need_update = true; |
88 | } | 110 | } |
89 | } | 111 | } |
@@ -92,8 +114,7 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { | |||
92 | } | 114 | } |
93 | 115 | ||
94 | // upload from raw_matrix to final matrix; | 116 | // upload from raw_matrix to final matrix; |
95 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { | 117 | static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { |
96 | matrix_need_update = false; | ||
97 | debounce_counter_t *debounce_pointer = debounce_counters; | 118 | debounce_counter_t *debounce_pointer = debounce_counters; |
98 | for (uint8_t row = 0; row < num_rows; row++) { | 119 | for (uint8_t row = 0; row < num_rows; row++) { |
99 | matrix_row_t existing_row = cooked[row]; | 120 | matrix_row_t existing_row = cooked[row]; |
@@ -102,11 +123,9 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n | |||
102 | // determine new value basd on debounce pointer + raw value | 123 | // determine new value basd on debounce pointer + raw value |
103 | if (existing_row != raw_row) { | 124 | if (existing_row != raw_row) { |
104 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { | 125 | if (*debounce_pointer == DEBOUNCE_ELAPSED) { |
105 | *debounce_pointer = current_time; | 126 | *debounce_pointer = DEBOUNCE; |
106 | cooked[row] = raw_row; | 127 | cooked[row] = raw_row; |
107 | counters_need_update = true; | 128 | counters_need_update = true; |
108 | } else { | ||
109 | matrix_need_update = true; | ||
110 | } | 129 | } |
111 | } | 130 | } |
112 | debounce_pointer++; | 131 | debounce_pointer++; |
@@ -114,3 +133,6 @@ void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t n | |||
114 | } | 133 | } |
115 | 134 | ||
116 | bool debounce_active(void) { return true; } | 135 | bool debounce_active(void) { return true; } |
136 | #else | ||
137 | # include "none.c" | ||
138 | #endif | ||
diff --git a/quantum/debounce/tests/debounce_test_common.cpp b/quantum/debounce/tests/debounce_test_common.cpp new file mode 100644 index 000000000..1c5e7c9f4 --- /dev/null +++ b/quantum/debounce/tests/debounce_test_common.cpp | |||
@@ -0,0 +1,229 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include "debounce_test_common.h" | ||
20 | |||
21 | #include <algorithm> | ||
22 | #include <iomanip> | ||
23 | #include <sstream> | ||
24 | |||
25 | extern "C" { | ||
26 | #include "quantum.h" | ||
27 | #include "timer.h" | ||
28 | #include "debounce.h" | ||
29 | |||
30 | void set_time(uint32_t t); | ||
31 | void advance_time(uint32_t ms); | ||
32 | } | ||
33 | |||
34 | void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { | ||
35 | events_.insert(events_.end(), events.begin(), events.end()); | ||
36 | } | ||
37 | |||
38 | void DebounceTest::runEvents() { | ||
39 | /* Run the test multiple times, from 1kHz to 10kHz scan rate */ | ||
40 | for (extra_iterations_ = 0; extra_iterations_ < 10; extra_iterations_++) { | ||
41 | if (time_jumps_) { | ||
42 | /* Don't advance time smoothly, jump to the next event (some tests require this) */ | ||
43 | auto_advance_time_ = false; | ||
44 | runEventsInternal(); | ||
45 | } else { | ||
46 | /* Run the test with both smooth and irregular time; it must produce the same result */ | ||
47 | auto_advance_time_ = true; | ||
48 | runEventsInternal(); | ||
49 | auto_advance_time_ = false; | ||
50 | runEventsInternal(); | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void DebounceTest::runEventsInternal() { | ||
56 | fast_timer_t previous = 0; | ||
57 | bool first = true; | ||
58 | |||
59 | /* Initialise keyboard with start time (offset to avoid testing at 0) and all keys UP */ | ||
60 | debounce_init(MATRIX_ROWS); | ||
61 | set_time(time_offset_); | ||
62 | std::fill(std::begin(input_matrix_), std::end(input_matrix_), 0); | ||
63 | std::fill(std::begin(output_matrix_), std::end(output_matrix_), 0); | ||
64 | |||
65 | for (auto &event : events_) { | ||
66 | if (!auto_advance_time_) { | ||
67 | /* Jump to the next event */ | ||
68 | set_time(time_offset_ + event.time_); | ||
69 | } else if (!first && event.time_ == previous + 1) { | ||
70 | /* This event immediately follows the previous one, don't make extra debounce() calls */ | ||
71 | advance_time(1); | ||
72 | } else { | ||
73 | /* Fast forward to the time for this event, calling debounce() with no changes */ | ||
74 | ASSERT_LT((time_offset_ + event.time_) - timer_read_fast(), 60000) << "Test tries to advance more than 1 minute of time"; | ||
75 | |||
76 | while (timer_read_fast() != time_offset_ + event.time_) { | ||
77 | runDebounce(false); | ||
78 | checkCookedMatrix(false, "debounce() modified cooked matrix"); | ||
79 | advance_time(1); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | first = false; | ||
84 | previous = event.time_; | ||
85 | |||
86 | /* Prepare input matrix */ | ||
87 | for (auto &input : event.inputs_) { | ||
88 | matrixUpdate(input_matrix_, "input", input); | ||
89 | } | ||
90 | |||
91 | /* Call debounce */ | ||
92 | runDebounce(!event.inputs_.empty()); | ||
93 | |||
94 | /* Prepare output matrix */ | ||
95 | for (auto &output : event.outputs_) { | ||
96 | matrixUpdate(output_matrix_, "output", output); | ||
97 | } | ||
98 | |||
99 | /* Check output matrix has expected change events */ | ||
100 | for (auto &output : event.outputs_) { | ||
101 | EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) | ||
102 | << "Missing event at " << strTime() | ||
103 | << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_) | ||
104 | << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_) | ||
105 | << "\nexpected_matrix:\n" << strMatrix(output_matrix_) | ||
106 | << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); | ||
107 | } | ||
108 | |||
109 | /* Check output matrix has no other changes */ | ||
110 | checkCookedMatrix(!event.inputs_.empty(), "debounce() cooked matrix does not match expected output matrix"); | ||
111 | |||
112 | /* Perform some extra iterations of the matrix scan with no changes */ | ||
113 | for (int i = 0; i < extra_iterations_; i++) { | ||
114 | runDebounce(false); | ||
115 | checkCookedMatrix(false, "debounce() modified cooked matrix"); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | /* Check that no further changes happen for 1 minute */ | ||
120 | for (int i = 0; i < 60000; i++) { | ||
121 | runDebounce(false); | ||
122 | checkCookedMatrix(false, "debounce() modified cooked matrix"); | ||
123 | advance_time(1); | ||
124 | } | ||
125 | |||
126 | debounce_free(); | ||
127 | } | ||
128 | |||
129 | void DebounceTest::runDebounce(bool changed) { | ||
130 | std::copy(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_)); | ||
131 | std::copy(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_)); | ||
132 | |||
133 | debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed); | ||
134 | |||
135 | if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) { | ||
136 | FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() | ||
137 | << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) | ||
138 | << "\nraw_matrix:\n" << strMatrix(raw_matrix_); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) { | ||
143 | if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) { | ||
144 | FAIL() << "Unexpected event: " << error_message << " at " << strTime() | ||
145 | << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) | ||
146 | << "\nexpected_matrix:\n" << strMatrix(output_matrix_) | ||
147 | << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | std::string DebounceTest::strTime() { | ||
152 | std::stringstream text; | ||
153 | |||
154 | text << "time " << (timer_read_fast() - time_offset_) | ||
155 | << " (extra_iterations=" << extra_iterations_ | ||
156 | << ", auto_advance_time=" << auto_advance_time_ << ")"; | ||
157 | |||
158 | return text.str(); | ||
159 | } | ||
160 | |||
161 | std::string DebounceTest::strMatrix(matrix_row_t matrix[]) { | ||
162 | std::stringstream text; | ||
163 | |||
164 | text << "\t" << std::setw(3) << ""; | ||
165 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
166 | text << " " << std::setw(2) << col; | ||
167 | } | ||
168 | text << "\n"; | ||
169 | |||
170 | for (int row = 0; row < MATRIX_ROWS; row++) { | ||
171 | text << "\t" << std::setw(2) << row << ":"; | ||
172 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
173 | text << ((matrix[row] & (1U << col)) ? " XX" : " __"); | ||
174 | } | ||
175 | |||
176 | text << "\n"; | ||
177 | } | ||
178 | |||
179 | return text.str(); | ||
180 | } | ||
181 | |||
182 | bool DebounceTest::directionValue(Direction direction) { | ||
183 | switch (direction) { | ||
184 | case DOWN: | ||
185 | return true; | ||
186 | |||
187 | case UP: | ||
188 | return false; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | std::string DebounceTest::directionLabel(Direction direction) { | ||
193 | switch (direction) { | ||
194 | case DOWN: | ||
195 | return "DOWN"; | ||
196 | |||
197 | case UP: | ||
198 | return "UP"; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /* Modify a matrix and verify that events always specify a change */ | ||
203 | void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) { | ||
204 | ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) | ||
205 | << "Test " << name << " at " << strTime() | ||
206 | << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_) | ||
207 | << " but it is already " << directionLabel(event.direction_) | ||
208 | << "\n" << name << "_matrix:\n" << strMatrix(matrix); | ||
209 | |||
210 | switch (event.direction_) { | ||
211 | case DOWN: | ||
212 | matrix[event.row_] |= (1U << event.col_); | ||
213 | break; | ||
214 | |||
215 | case UP: | ||
216 | matrix[event.row_] &= ~(1U << event.col_); | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | DebounceTestEvent::DebounceTestEvent(fast_timer_t time, | ||
222 | std::initializer_list<MatrixTestEvent> inputs, | ||
223 | std::initializer_list<MatrixTestEvent> outputs) | ||
224 | : time_(time), inputs_(inputs), outputs_(outputs) { | ||
225 | } | ||
226 | |||
227 | MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) | ||
228 | : row_(row), col_(col), direction_(direction) { | ||
229 | } | ||
diff --git a/quantum/debounce/tests/debounce_test_common.h b/quantum/debounce/tests/debounce_test_common.h new file mode 100644 index 000000000..d87e31059 --- /dev/null +++ b/quantum/debounce/tests/debounce_test_common.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include <initializer_list> | ||
20 | #include <list> | ||
21 | #include <string> | ||
22 | |||
23 | extern "C" { | ||
24 | #include "quantum.h" | ||
25 | #include "timer.h" | ||
26 | } | ||
27 | |||
28 | enum Direction { | ||
29 | DOWN, | ||
30 | UP, | ||
31 | }; | ||
32 | |||
33 | class MatrixTestEvent { | ||
34 | public: | ||
35 | MatrixTestEvent(int row, int col, Direction direction); | ||
36 | |||
37 | const int row_; | ||
38 | const int col_; | ||
39 | const Direction direction_; | ||
40 | }; | ||
41 | |||
42 | class DebounceTestEvent { | ||
43 | public: | ||
44 | // 0, {{0, 1, DOWN}}, {{0, 1, DOWN}}) | ||
45 | DebounceTestEvent(fast_timer_t time, | ||
46 | std::initializer_list<MatrixTestEvent> inputs, | ||
47 | std::initializer_list<MatrixTestEvent> outputs); | ||
48 | |||
49 | const fast_timer_t time_; | ||
50 | const std::list<MatrixTestEvent> inputs_; | ||
51 | const std::list<MatrixTestEvent> outputs_; | ||
52 | }; | ||
53 | |||
54 | class DebounceTest : public ::testing::Test { | ||
55 | protected: | ||
56 | void addEvents(std::initializer_list<DebounceTestEvent> events); | ||
57 | void runEvents(); | ||
58 | |||
59 | fast_timer_t time_offset_ = 7777; | ||
60 | bool time_jumps_ = false; | ||
61 | |||
62 | private: | ||
63 | static bool directionValue(Direction direction); | ||
64 | static std::string directionLabel(Direction direction); | ||
65 | |||
66 | void runEventsInternal(); | ||
67 | void runDebounce(bool changed); | ||
68 | void checkCookedMatrix(bool changed, const std::string &error_message); | ||
69 | void matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event); | ||
70 | |||
71 | std::string strTime(); | ||
72 | std::string strMatrix(matrix_row_t matrix[]); | ||
73 | |||
74 | std::list<DebounceTestEvent> events_; | ||
75 | |||
76 | matrix_row_t input_matrix_[MATRIX_ROWS]; | ||
77 | matrix_row_t raw_matrix_[MATRIX_ROWS]; | ||
78 | matrix_row_t cooked_matrix_[MATRIX_ROWS]; | ||
79 | matrix_row_t output_matrix_[MATRIX_ROWS]; | ||
80 | |||
81 | int extra_iterations_; | ||
82 | bool auto_advance_time_; | ||
83 | }; | ||
diff --git a/quantum/debounce/tests/rules.mk b/quantum/debounce/tests/rules.mk new file mode 100644 index 000000000..29fda7889 --- /dev/null +++ b/quantum/debounce/tests/rules.mk | |||
@@ -0,0 +1,39 @@ | |||
1 | # Copyright 2021 Simon Arlott | ||
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 | DEBOUNCE_COMMON_DEFS := -DMATRIX_ROWS=4 -DMATRIX_COLS=10 -DDEBOUNCE=5 | ||
17 | |||
18 | DEBOUNCE_COMMON_SRC := $(QUANTUM_PATH)/debounce/tests/debounce_test_common.cpp \ | ||
19 | $(TMK_PATH)/common/test/timer.c | ||
20 | |||
21 | debounce_sym_defer_g_DEFS := $(DEBOUNCE_COMMON_DEFS) | ||
22 | debounce_sym_defer_g_SRC := $(DEBOUNCE_COMMON_SRC) \ | ||
23 | $(QUANTUM_PATH)/debounce/sym_defer_g.c \ | ||
24 | $(QUANTUM_PATH)/debounce/tests/sym_defer_g_tests.cpp | ||
25 | |||
26 | debounce_sym_defer_pk_DEFS := $(DEBOUNCE_COMMON_DEFS) | ||
27 | debounce_sym_defer_pk_SRC := $(DEBOUNCE_COMMON_SRC) \ | ||
28 | $(QUANTUM_PATH)/debounce/sym_defer_pk.c \ | ||
29 | $(QUANTUM_PATH)/debounce/tests/sym_defer_pk_tests.cpp | ||
30 | |||
31 | debounce_sym_eager_pk_DEFS := $(DEBOUNCE_COMMON_DEFS) | ||
32 | debounce_sym_eager_pk_SRC := $(DEBOUNCE_COMMON_SRC) \ | ||
33 | $(QUANTUM_PATH)/debounce/sym_eager_pk.c \ | ||
34 | $(QUANTUM_PATH)/debounce/tests/sym_eager_pk_tests.cpp | ||
35 | |||
36 | debounce_sym_eager_pr_DEFS := $(DEBOUNCE_COMMON_DEFS) | ||
37 | debounce_sym_eager_pr_SRC := $(DEBOUNCE_COMMON_SRC) \ | ||
38 | $(QUANTUM_PATH)/debounce/sym_eager_pr.c \ | ||
39 | $(QUANTUM_PATH)/debounce/tests/sym_eager_pr_tests.cpp | ||
diff --git a/quantum/debounce/tests/sym_defer_g_tests.cpp b/quantum/debounce/tests/sym_defer_g_tests.cpp new file mode 100644 index 000000000..a56aecd8f --- /dev/null +++ b/quantum/debounce/tests/sym_defer_g_tests.cpp | |||
@@ -0,0 +1,223 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include "debounce_test_common.h" | ||
20 | |||
21 | TEST_F(DebounceTest, OneKeyShort1) { | ||
22 | addEvents({ /* Time, Inputs, Outputs */ | ||
23 | {0, {{0, 1, DOWN}}, {}}, | ||
24 | |||
25 | {5, {}, {{0, 1, DOWN}}}, | ||
26 | /* 0ms delay (fast scan rate) */ | ||
27 | {5, {{0, 1, UP}}, {}}, | ||
28 | |||
29 | {10, {}, {{0, 1, UP}}}, | ||
30 | }); | ||
31 | runEvents(); | ||
32 | } | ||
33 | |||
34 | TEST_F(DebounceTest, OneKeyShort2) { | ||
35 | addEvents({ /* Time, Inputs, Outputs */ | ||
36 | {0, {{0, 1, DOWN}}, {}}, | ||
37 | |||
38 | {5, {}, {{0, 1, DOWN}}}, | ||
39 | /* 1ms delay */ | ||
40 | {6, {{0, 1, UP}}, {}}, | ||
41 | |||
42 | {11, {}, {{0, 1, UP}}}, | ||
43 | }); | ||
44 | runEvents(); | ||
45 | } | ||
46 | |||
47 | TEST_F(DebounceTest, OneKeyShort3) { | ||
48 | addEvents({ /* Time, Inputs, Outputs */ | ||
49 | {0, {{0, 1, DOWN}}, {}}, | ||
50 | |||
51 | {5, {}, {{0, 1, DOWN}}}, | ||
52 | /* 2ms delay */ | ||
53 | {7, {{0, 1, UP}}, {}}, | ||
54 | |||
55 | {12, {}, {{0, 1, UP}}}, | ||
56 | }); | ||
57 | runEvents(); | ||
58 | } | ||
59 | |||
60 | TEST_F(DebounceTest, OneKeyTooQuick1) { | ||
61 | addEvents({ /* Time, Inputs, Outputs */ | ||
62 | {0, {{0, 1, DOWN}}, {}}, | ||
63 | /* Release key exactly on the debounce time */ | ||
64 | {5, {{0, 1, UP}}, {}}, | ||
65 | }); | ||
66 | runEvents(); | ||
67 | } | ||
68 | |||
69 | TEST_F(DebounceTest, OneKeyTooQuick2) { | ||
70 | addEvents({ /* Time, Inputs, Outputs */ | ||
71 | {0, {{0, 1, DOWN}}, {}}, | ||
72 | |||
73 | {5, {}, {{0, 1, DOWN}}}, | ||
74 | {6, {{0, 1, UP}}, {}}, | ||
75 | |||
76 | /* Press key exactly on the debounce time */ | ||
77 | {11, {{0, 1, DOWN}}, {}}, | ||
78 | }); | ||
79 | runEvents(); | ||
80 | } | ||
81 | |||
82 | TEST_F(DebounceTest, OneKeyBouncing1) { | ||
83 | addEvents({ /* Time, Inputs, Outputs */ | ||
84 | {0, {{0, 1, DOWN}}, {}}, | ||
85 | {1, {{0, 1, UP}}, {}}, | ||
86 | {2, {{0, 1, DOWN}}, {}}, | ||
87 | {3, {{0, 1, UP}}, {}}, | ||
88 | {4, {{0, 1, DOWN}}, {}}, | ||
89 | {5, {{0, 1, UP}}, {}}, | ||
90 | {6, {{0, 1, DOWN}}, {}}, | ||
91 | {11, {}, {{0, 1, DOWN}}}, /* 5ms after DOWN at time 7 */ | ||
92 | }); | ||
93 | runEvents(); | ||
94 | } | ||
95 | |||
96 | TEST_F(DebounceTest, OneKeyBouncing2) { | ||
97 | addEvents({ /* Time, Inputs, Outputs */ | ||
98 | {0, {{0, 1, DOWN}}, {}}, | ||
99 | {5, {}, {{0, 1, DOWN}}}, | ||
100 | {6, {{0, 1, UP}}, {}}, | ||
101 | {7, {{0, 1, DOWN}}, {}}, | ||
102 | {8, {{0, 1, UP}}, {}}, | ||
103 | {9, {{0, 1, DOWN}}, {}}, | ||
104 | {10, {{0, 1, UP}}, {}}, | ||
105 | {15, {}, {{0, 1, UP}}}, /* 5ms after UP at time 10 */ | ||
106 | }); | ||
107 | runEvents(); | ||
108 | } | ||
109 | |||
110 | TEST_F(DebounceTest, OneKeyLong) { | ||
111 | addEvents({ /* Time, Inputs, Outputs */ | ||
112 | {0, {{0, 1, DOWN}}, {}}, | ||
113 | |||
114 | {5, {}, {{0, 1, DOWN}}}, | ||
115 | |||
116 | {25, {{0, 1, UP}}, {}}, | ||
117 | |||
118 | {30, {}, {{0, 1, UP}}}, | ||
119 | |||
120 | {50, {{0, 1, DOWN}}, {}}, | ||
121 | |||
122 | {55, {}, {{0, 1, DOWN}}}, | ||
123 | }); | ||
124 | runEvents(); | ||
125 | } | ||
126 | |||
127 | TEST_F(DebounceTest, TwoKeysShort) { | ||
128 | addEvents({ /* Time, Inputs, Outputs */ | ||
129 | {0, {{0, 1, DOWN}}, {}}, | ||
130 | {1, {{0, 2, DOWN}}, {}}, | ||
131 | |||
132 | {6, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
133 | |||
134 | {7, {{0, 1, UP}}, {}}, | ||
135 | {8, {{0, 2, UP}}, {}}, | ||
136 | |||
137 | {13, {}, {{0, 1, UP}, {0, 2, UP}}}, | ||
138 | }); | ||
139 | runEvents(); | ||
140 | } | ||
141 | |||
142 | TEST_F(DebounceTest, TwoKeysSimultaneous1) { | ||
143 | addEvents({ /* Time, Inputs, Outputs */ | ||
144 | {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}}, | ||
145 | |||
146 | {5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
147 | {6, {{0, 1, UP}, {0, 2, UP}}, {}}, | ||
148 | |||
149 | {11, {}, {{0, 1, UP}, {0, 2, UP}}}, | ||
150 | }); | ||
151 | runEvents(); | ||
152 | } | ||
153 | |||
154 | TEST_F(DebounceTest, TwoKeysSimultaneous2) { | ||
155 | addEvents({ /* Time, Inputs, Outputs */ | ||
156 | {0, {{0, 1, DOWN}}, {}}, | ||
157 | {1, {{0, 2, DOWN}}, {}}, | ||
158 | |||
159 | {5, {}, {}}, | ||
160 | {6, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
161 | {7, {{0, 1, UP}}, {}}, | ||
162 | {8, {{0, 2, UP}}, {}}, | ||
163 | |||
164 | {13, {}, {{0, 1, UP}, {0, 2, UP}}}, | ||
165 | }); | ||
166 | runEvents(); | ||
167 | } | ||
168 | |||
169 | TEST_F(DebounceTest, OneKeyDelayedScan1) { | ||
170 | addEvents({ /* Time, Inputs, Outputs */ | ||
171 | {0, {{0, 1, DOWN}}, {}}, | ||
172 | |||
173 | /* Processing is very late */ | ||
174 | {300, {}, {{0, 1, DOWN}}}, | ||
175 | /* Immediately release key */ | ||
176 | {300, {{0, 1, UP}}, {}}, | ||
177 | |||
178 | {305, {}, {{0, 1, UP}}}, | ||
179 | }); | ||
180 | time_jumps_ = true; | ||
181 | runEvents(); | ||
182 | } | ||
183 | |||
184 | TEST_F(DebounceTest, OneKeyDelayedScan2) { | ||
185 | addEvents({ /* Time, Inputs, Outputs */ | ||
186 | {0, {{0, 1, DOWN}}, {}}, | ||
187 | |||
188 | /* Processing is very late */ | ||
189 | {300, {}, {{0, 1, DOWN}}}, | ||
190 | /* Release key after 1ms */ | ||
191 | {301, {{0, 1, UP}}, {}}, | ||
192 | |||
193 | {306, {}, {{0, 1, UP}}}, | ||
194 | }); | ||
195 | time_jumps_ = true; | ||
196 | runEvents(); | ||
197 | } | ||
198 | |||
199 | TEST_F(DebounceTest, OneKeyDelayedScan3) { | ||
200 | addEvents({ /* Time, Inputs, Outputs */ | ||
201 | {0, {{0, 1, DOWN}}, {}}, | ||
202 | |||
203 | /* Release key before debounce expires */ | ||
204 | {300, {{0, 1, UP}}, {}}, | ||
205 | }); | ||
206 | time_jumps_ = true; | ||
207 | runEvents(); | ||
208 | } | ||
209 | |||
210 | TEST_F(DebounceTest, OneKeyDelayedScan4) { | ||
211 | addEvents({ /* Time, Inputs, Outputs */ | ||
212 | {0, {{0, 1, DOWN}}, {}}, | ||
213 | |||
214 | /* Processing is a bit late */ | ||
215 | {50, {}, {{0, 1, DOWN}}}, | ||
216 | /* Release key after 1ms */ | ||
217 | {51, {{0, 1, UP}}, {}}, | ||
218 | |||
219 | {56, {}, {{0, 1, UP}}}, | ||
220 | }); | ||
221 | time_jumps_ = true; | ||
222 | runEvents(); | ||
223 | } | ||
diff --git a/quantum/debounce/tests/sym_defer_pk_tests.cpp b/quantum/debounce/tests/sym_defer_pk_tests.cpp new file mode 100644 index 000000000..1f3061e59 --- /dev/null +++ b/quantum/debounce/tests/sym_defer_pk_tests.cpp | |||
@@ -0,0 +1,225 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include "debounce_test_common.h" | ||
20 | |||
21 | TEST_F(DebounceTest, OneKeyShort1) { | ||
22 | addEvents({ /* Time, Inputs, Outputs */ | ||
23 | {0, {{0, 1, DOWN}}, {}}, | ||
24 | |||
25 | {5, {}, {{0, 1, DOWN}}}, | ||
26 | /* 0ms delay (fast scan rate) */ | ||
27 | {5, {{0, 1, UP}}, {}}, | ||
28 | |||
29 | {10, {}, {{0, 1, UP}}}, | ||
30 | }); | ||
31 | runEvents(); | ||
32 | } | ||
33 | |||
34 | TEST_F(DebounceTest, OneKeyShort2) { | ||
35 | addEvents({ /* Time, Inputs, Outputs */ | ||
36 | {0, {{0, 1, DOWN}}, {}}, | ||
37 | |||
38 | {5, {}, {{0, 1, DOWN}}}, | ||
39 | /* 1ms delay */ | ||
40 | {6, {{0, 1, UP}}, {}}, | ||
41 | |||
42 | {11, {}, {{0, 1, UP}}}, | ||
43 | }); | ||
44 | runEvents(); | ||
45 | } | ||
46 | |||
47 | TEST_F(DebounceTest, OneKeyShort3) { | ||
48 | addEvents({ /* Time, Inputs, Outputs */ | ||
49 | {0, {{0, 1, DOWN}}, {}}, | ||
50 | |||
51 | {5, {}, {{0, 1, DOWN}}}, | ||
52 | /* 2ms delay */ | ||
53 | {7, {{0, 1, UP}}, {}}, | ||
54 | |||
55 | {12, {}, {{0, 1, UP}}}, | ||
56 | }); | ||
57 | runEvents(); | ||
58 | } | ||
59 | |||
60 | TEST_F(DebounceTest, OneKeyTooQuick1) { | ||
61 | addEvents({ /* Time, Inputs, Outputs */ | ||
62 | {0, {{0, 1, DOWN}}, {}}, | ||
63 | /* Release key exactly on the debounce time */ | ||
64 | {5, {{0, 1, UP}}, {}}, | ||
65 | }); | ||
66 | runEvents(); | ||
67 | } | ||
68 | |||
69 | TEST_F(DebounceTest, OneKeyTooQuick2) { | ||
70 | addEvents({ /* Time, Inputs, Outputs */ | ||
71 | {0, {{0, 1, DOWN}}, {}}, | ||
72 | |||
73 | {5, {}, {{0, 1, DOWN}}}, | ||
74 | {6, {{0, 1, UP}}, {}}, | ||
75 | |||
76 | /* Press key exactly on the debounce time */ | ||
77 | {11, {{0, 1, DOWN}}, {}}, | ||
78 | }); | ||
79 | runEvents(); | ||
80 | } | ||
81 | |||
82 | TEST_F(DebounceTest, OneKeyBouncing1) { | ||
83 | addEvents({ /* Time, Inputs, Outputs */ | ||
84 | {0, {{0, 1, DOWN}}, {}}, | ||
85 | {1, {{0, 1, UP}}, {}}, | ||
86 | {2, {{0, 1, DOWN}}, {}}, | ||
87 | {3, {{0, 1, UP}}, {}}, | ||
88 | {4, {{0, 1, DOWN}}, {}}, | ||
89 | {5, {{0, 1, UP}}, {}}, | ||
90 | {6, {{0, 1, DOWN}}, {}}, | ||
91 | {11, {}, {{0, 1, DOWN}}}, /* 5ms after DOWN at time 7 */ | ||
92 | }); | ||
93 | runEvents(); | ||
94 | } | ||
95 | |||
96 | TEST_F(DebounceTest, OneKeyBouncing2) { | ||
97 | addEvents({ /* Time, Inputs, Outputs */ | ||
98 | {0, {{0, 1, DOWN}}, {}}, | ||
99 | {5, {}, {{0, 1, DOWN}}}, | ||
100 | {6, {{0, 1, UP}}, {}}, | ||
101 | {7, {{0, 1, DOWN}}, {}}, | ||
102 | {8, {{0, 1, UP}}, {}}, | ||
103 | {9, {{0, 1, DOWN}}, {}}, | ||
104 | {10, {{0, 1, UP}}, {}}, | ||
105 | {15, {}, {{0, 1, UP}}}, /* 5ms after UP at time 10 */ | ||
106 | }); | ||
107 | runEvents(); | ||
108 | } | ||
109 | |||
110 | TEST_F(DebounceTest, OneKeyLong) { | ||
111 | addEvents({ /* Time, Inputs, Outputs */ | ||
112 | {0, {{0, 1, DOWN}}, {}}, | ||
113 | |||
114 | {5, {}, {{0, 1, DOWN}}}, | ||
115 | |||
116 | {25, {{0, 1, UP}}, {}}, | ||
117 | |||
118 | {30, {}, {{0, 1, UP}}}, | ||
119 | |||
120 | {50, {{0, 1, DOWN}}, {}}, | ||
121 | |||
122 | {55, {}, {{0, 1, DOWN}}}, | ||
123 | }); | ||
124 | runEvents(); | ||
125 | } | ||
126 | |||
127 | TEST_F(DebounceTest, TwoKeysShort) { | ||
128 | addEvents({ /* Time, Inputs, Outputs */ | ||
129 | {0, {{0, 1, DOWN}}, {}}, | ||
130 | {1, {{0, 2, DOWN}}, {}}, | ||
131 | |||
132 | {5, {}, {{0, 1, DOWN}}}, | ||
133 | {6, {}, {{0, 2, DOWN}}}, | ||
134 | |||
135 | {7, {{0, 1, UP}}, {}}, | ||
136 | {8, {{0, 2, UP}}, {}}, | ||
137 | |||
138 | {12, {}, {{0, 1, UP}}}, | ||
139 | {13, {}, {{0, 2, UP}}}, | ||
140 | }); | ||
141 | runEvents(); | ||
142 | } | ||
143 | |||
144 | TEST_F(DebounceTest, TwoKeysSimultaneous1) { | ||
145 | addEvents({ /* Time, Inputs, Outputs */ | ||
146 | {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}}, | ||
147 | |||
148 | {5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
149 | {6, {{0, 1, UP}, {0, 2, UP}}, {}}, | ||
150 | |||
151 | {11, {}, {{0, 1, UP}, {0, 2, UP}}}, | ||
152 | }); | ||
153 | runEvents(); | ||
154 | } | ||
155 | |||
156 | TEST_F(DebounceTest, TwoKeysSimultaneous2) { | ||
157 | addEvents({ /* Time, Inputs, Outputs */ | ||
158 | {0, {{0, 1, DOWN}}, {}}, | ||
159 | {1, {{0, 2, DOWN}}, {}}, | ||
160 | |||
161 | {5, {}, {{0, 1, DOWN}}}, | ||
162 | {6, {{0, 1, UP}}, {{0, 2, DOWN}}}, | ||
163 | {7, {{0, 2, UP}}, {}}, | ||
164 | |||
165 | {11, {}, {{0, 1, UP}}}, | ||
166 | {12, {}, {{0, 2, UP}}}, | ||
167 | }); | ||
168 | runEvents(); | ||
169 | } | ||
170 | |||
171 | TEST_F(DebounceTest, OneKeyDelayedScan1) { | ||
172 | addEvents({ /* Time, Inputs, Outputs */ | ||
173 | {0, {{0, 1, DOWN}}, {}}, | ||
174 | |||
175 | /* Processing is very late */ | ||
176 | {300, {}, {{0, 1, DOWN}}}, | ||
177 | /* Immediately release key */ | ||
178 | {300, {{0, 1, UP}}, {}}, | ||
179 | |||
180 | {305, {}, {{0, 1, UP}}}, | ||
181 | }); | ||
182 | time_jumps_ = true; | ||
183 | runEvents(); | ||
184 | } | ||
185 | |||
186 | TEST_F(DebounceTest, OneKeyDelayedScan2) { | ||
187 | addEvents({ /* Time, Inputs, Outputs */ | ||
188 | {0, {{0, 1, DOWN}}, {}}, | ||
189 | |||
190 | /* Processing is very late */ | ||
191 | {300, {}, {{0, 1, DOWN}}}, | ||
192 | /* Release key after 1ms */ | ||
193 | {301, {{0, 1, UP}}, {}}, | ||
194 | |||
195 | {306, {}, {{0, 1, UP}}}, | ||
196 | }); | ||
197 | time_jumps_ = true; | ||
198 | runEvents(); | ||
199 | } | ||
200 | |||
201 | TEST_F(DebounceTest, OneKeyDelayedScan3) { | ||
202 | addEvents({ /* Time, Inputs, Outputs */ | ||
203 | {0, {{0, 1, DOWN}}, {}}, | ||
204 | |||
205 | /* Release key before debounce expires */ | ||
206 | {300, {{0, 1, UP}}, {}}, | ||
207 | }); | ||
208 | time_jumps_ = true; | ||
209 | runEvents(); | ||
210 | } | ||
211 | |||
212 | TEST_F(DebounceTest, OneKeyDelayedScan4) { | ||
213 | addEvents({ /* Time, Inputs, Outputs */ | ||
214 | {0, {{0, 1, DOWN}}, {}}, | ||
215 | |||
216 | /* Processing is a bit late */ | ||
217 | {50, {}, {{0, 1, DOWN}}}, | ||
218 | /* Release key after 1ms */ | ||
219 | {51, {{0, 1, UP}}, {}}, | ||
220 | |||
221 | {56, {}, {{0, 1, UP}}}, | ||
222 | }); | ||
223 | time_jumps_ = true; | ||
224 | runEvents(); | ||
225 | } | ||
diff --git a/quantum/debounce/tests/sym_eager_pk_tests.cpp b/quantum/debounce/tests/sym_eager_pk_tests.cpp new file mode 100644 index 000000000..e0fc205e3 --- /dev/null +++ b/quantum/debounce/tests/sym_eager_pk_tests.cpp | |||
@@ -0,0 +1,237 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include "debounce_test_common.h" | ||
20 | |||
21 | TEST_F(DebounceTest, OneKeyShort1) { | ||
22 | addEvents({ /* Time, Inputs, Outputs */ | ||
23 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
24 | {1, {{0, 1, UP}}, {}}, | ||
25 | |||
26 | {5, {}, {{0, 1, UP}}}, | ||
27 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
28 | {6, {{0, 1, DOWN}}, {}}, | ||
29 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
30 | }); | ||
31 | runEvents(); | ||
32 | } | ||
33 | |||
34 | TEST_F(DebounceTest, OneKeyShort2) { | ||
35 | addEvents({ /* Time, Inputs, Outputs */ | ||
36 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
37 | {1, {{0, 1, UP}}, {}}, | ||
38 | |||
39 | {5, {}, {{0, 1, UP}}}, | ||
40 | /* Press key again after 2ms delay (debounce has not yet finished) */ | ||
41 | {7, {{0, 1, DOWN}}, {}}, | ||
42 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
43 | }); | ||
44 | runEvents(); | ||
45 | } | ||
46 | |||
47 | TEST_F(DebounceTest, OneKeyShort3) { | ||
48 | addEvents({ /* Time, Inputs, Outputs */ | ||
49 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
50 | {1, {{0, 1, UP}}, {}}, | ||
51 | |||
52 | {5, {}, {{0, 1, UP}}}, | ||
53 | /* Press key again after 3ms delay (debounce has not yet finished) */ | ||
54 | {8, {{0, 1, DOWN}}, {}}, | ||
55 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
56 | }); | ||
57 | runEvents(); | ||
58 | } | ||
59 | |||
60 | TEST_F(DebounceTest, OneKeyShort4) { | ||
61 | addEvents({ /* Time, Inputs, Outputs */ | ||
62 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
63 | {1, {{0, 1, UP}}, {}}, | ||
64 | |||
65 | {5, {}, {{0, 1, UP}}}, | ||
66 | /* Press key again after 4ms delay (debounce has not yet finished) */ | ||
67 | {9, {{0, 1, DOWN}}, {}}, | ||
68 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
69 | }); | ||
70 | runEvents(); | ||
71 | } | ||
72 | |||
73 | TEST_F(DebounceTest, OneKeyShort5) { | ||
74 | addEvents({ /* Time, Inputs, Outputs */ | ||
75 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
76 | {1, {{0, 1, UP}}, {}}, | ||
77 | |||
78 | {5, {}, {{0, 1, UP}}}, | ||
79 | /* Press key again after 5ms delay (debounce has finished) */ | ||
80 | {10, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
81 | }); | ||
82 | runEvents(); | ||
83 | } | ||
84 | |||
85 | TEST_F(DebounceTest, OneKeyShort6) { | ||
86 | addEvents({ /* Time, Inputs, Outputs */ | ||
87 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
88 | {1, {{0, 1, UP}}, {}}, | ||
89 | |||
90 | {5, {}, {{0, 1, UP}}}, | ||
91 | /* Press key after after 6ms delay (debounce has finished) */ | ||
92 | {11, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
93 | }); | ||
94 | runEvents(); | ||
95 | } | ||
96 | |||
97 | TEST_F(DebounceTest, OneKeyBouncing1) { | ||
98 | addEvents({ /* Time, Inputs, Outputs */ | ||
99 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
100 | {1, {{0, 1, UP}}, {}}, | ||
101 | {2, {{0, 1, DOWN}}, {}}, | ||
102 | {3, {{0, 1, UP}}, {}}, | ||
103 | {4, {{0, 1, DOWN}}, {}}, | ||
104 | {5, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
105 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
106 | {6, {{0, 1, DOWN}}, {}}, | ||
107 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
108 | }); | ||
109 | runEvents(); | ||
110 | } | ||
111 | |||
112 | TEST_F(DebounceTest, OneKeyBouncing2) { | ||
113 | addEvents({ /* Time, Inputs, Outputs */ | ||
114 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
115 | /* Change twice in the same time period */ | ||
116 | {1, {{0, 1, UP}}, {}}, | ||
117 | {1, {{0, 1, DOWN}}, {}}, | ||
118 | /* Change three times in the same time period */ | ||
119 | {2, {{0, 1, UP}}, {}}, | ||
120 | {2, {{0, 1, DOWN}}, {}}, | ||
121 | {2, {{0, 1, UP}}, {}}, | ||
122 | /* Change three times in the same time period */ | ||
123 | {3, {{0, 1, DOWN}}, {}}, | ||
124 | {3, {{0, 1, UP}}, {}}, | ||
125 | {3, {{0, 1, DOWN}}, {}}, | ||
126 | /* Change twice in the same time period */ | ||
127 | {4, {{0, 1, UP}}, {}}, | ||
128 | {4, {{0, 1, DOWN}}, {}}, | ||
129 | {5, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
130 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
131 | {6, {{0, 1, DOWN}}, {}}, | ||
132 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
133 | }); | ||
134 | runEvents(); | ||
135 | } | ||
136 | |||
137 | TEST_F(DebounceTest, OneKeyLong) { | ||
138 | addEvents({ /* Time, Inputs, Outputs */ | ||
139 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
140 | |||
141 | {25, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
142 | |||
143 | {50, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
144 | }); | ||
145 | runEvents(); | ||
146 | } | ||
147 | |||
148 | TEST_F(DebounceTest, TwoKeysShort) { | ||
149 | addEvents({ /* Time, Inputs, Outputs */ | ||
150 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
151 | {1, {{0, 1, UP}}, {}}, | ||
152 | {2, {{0, 2, DOWN}}, {{0, 2, DOWN}}}, | ||
153 | {3, {{0, 2, UP}}, {}}, | ||
154 | |||
155 | {5, {}, {{0, 1, UP}}}, | ||
156 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
157 | {6, {{0, 1, DOWN}}, {}}, | ||
158 | {7, {}, {{0, 2, UP}}}, | ||
159 | |||
160 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
161 | {9, {{0, 2, DOWN}}, {}}, | ||
162 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
163 | |||
164 | {12, {}, {{0, 2, DOWN}}}, /* 5ms after UP at time 7 */ | ||
165 | }); | ||
166 | runEvents(); | ||
167 | } | ||
168 | |||
169 | TEST_F(DebounceTest, OneKeyDelayedScan1) { | ||
170 | addEvents({ /* Time, Inputs, Outputs */ | ||
171 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
172 | |||
173 | /* Processing is very late but the change will now be accepted */ | ||
174 | {300, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
175 | }); | ||
176 | time_jumps_ = true; | ||
177 | runEvents(); | ||
178 | } | ||
179 | |||
180 | TEST_F(DebounceTest, OneKeyDelayedScan2) { | ||
181 | addEvents({ /* Time, Inputs, Outputs */ | ||
182 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
183 | |||
184 | /* Processing is very late but the change will now be accepted even with a 1 scan delay */ | ||
185 | {300, {}, {}}, | ||
186 | {300, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
187 | }); | ||
188 | time_jumps_ = true; | ||
189 | runEvents(); | ||
190 | } | ||
191 | |||
192 | TEST_F(DebounceTest, OneKeyDelayedScan3) { | ||
193 | addEvents({ /* Time, Inputs, Outputs */ | ||
194 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
195 | |||
196 | /* Processing is very late but the change will now be accepted even with a 1ms delay */ | ||
197 | {300, {}, {}}, | ||
198 | {301, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
199 | }); | ||
200 | time_jumps_ = true; | ||
201 | runEvents(); | ||
202 | } | ||
203 | |||
204 | TEST_F(DebounceTest, OneKeyDelayedScan4) { | ||
205 | addEvents({ /* Time, Inputs, Outputs */ | ||
206 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
207 | |||
208 | /* Processing is a bit late but the change will now be accepted */ | ||
209 | {50, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
210 | }); | ||
211 | time_jumps_ = true; | ||
212 | runEvents(); | ||
213 | } | ||
214 | |||
215 | TEST_F(DebounceTest, OneKeyDelayedScan5) { | ||
216 | addEvents({ /* Time, Inputs, Outputs */ | ||
217 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
218 | |||
219 | /* Processing is very late but the change will now be accepted even with a 1 scan delay */ | ||
220 | {50, {}, {}}, | ||
221 | {50, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
222 | }); | ||
223 | time_jumps_ = true; | ||
224 | runEvents(); | ||
225 | } | ||
226 | |||
227 | TEST_F(DebounceTest, OneKeyDelayedScan6) { | ||
228 | addEvents({ /* Time, Inputs, Outputs */ | ||
229 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
230 | |||
231 | /* Processing is very late but the change will now be accepted even with a 1ms delay */ | ||
232 | {50, {}, {}}, | ||
233 | {51, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
234 | }); | ||
235 | time_jumps_ = true; | ||
236 | runEvents(); | ||
237 | } | ||
diff --git a/quantum/debounce/tests/sym_eager_pr_tests.cpp b/quantum/debounce/tests/sym_eager_pr_tests.cpp new file mode 100644 index 000000000..2c4bca127 --- /dev/null +++ b/quantum/debounce/tests/sym_eager_pr_tests.cpp | |||
@@ -0,0 +1,280 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | |||
19 | #include "debounce_test_common.h" | ||
20 | |||
21 | TEST_F(DebounceTest, OneKeyShort1) { | ||
22 | addEvents({ /* Time, Inputs, Outputs */ | ||
23 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
24 | {1, {{0, 1, UP}}, {}}, | ||
25 | |||
26 | {5, {}, {{0, 1, UP}}}, | ||
27 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
28 | {6, {{0, 1, DOWN}}, {}}, | ||
29 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
30 | }); | ||
31 | runEvents(); | ||
32 | } | ||
33 | |||
34 | TEST_F(DebounceTest, OneKeyShort2) { | ||
35 | addEvents({ /* Time, Inputs, Outputs */ | ||
36 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
37 | {1, {{0, 1, UP}}, {}}, | ||
38 | |||
39 | {5, {}, {{0, 1, UP}}}, | ||
40 | /* Press key again after 2ms delay (debounce has not yet finished) */ | ||
41 | {7, {{0, 1, DOWN}}, {}}, | ||
42 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
43 | }); | ||
44 | runEvents(); | ||
45 | } | ||
46 | |||
47 | TEST_F(DebounceTest, OneKeyShort3) { | ||
48 | addEvents({ /* Time, Inputs, Outputs */ | ||
49 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
50 | {1, {{0, 1, UP}}, {}}, | ||
51 | |||
52 | {5, {}, {{0, 1, UP}}}, | ||
53 | /* Press key again after 3ms delay (debounce has not yet finished) */ | ||
54 | {8, {{0, 1, DOWN}}, {}}, | ||
55 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
56 | }); | ||
57 | runEvents(); | ||
58 | } | ||
59 | |||
60 | TEST_F(DebounceTest, OneKeyShort4) { | ||
61 | addEvents({ /* Time, Inputs, Outputs */ | ||
62 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
63 | {1, {{0, 1, UP}}, {}}, | ||
64 | |||
65 | {5, {}, {{0, 1, UP}}}, | ||
66 | /* Press key again after 4ms delay (debounce has not yet finished) */ | ||
67 | {9, {{0, 1, DOWN}}, {}}, | ||
68 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
69 | }); | ||
70 | runEvents(); | ||
71 | } | ||
72 | |||
73 | TEST_F(DebounceTest, OneKeyShort5) { | ||
74 | addEvents({ /* Time, Inputs, Outputs */ | ||
75 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
76 | {1, {{0, 1, UP}}, {}}, | ||
77 | |||
78 | {5, {}, {{0, 1, UP}}}, | ||
79 | /* Press key again after 5ms delay (debounce has finished) */ | ||
80 | {10, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
81 | }); | ||
82 | runEvents(); | ||
83 | } | ||
84 | |||
85 | TEST_F(DebounceTest, OneKeyShort6) { | ||
86 | addEvents({ /* Time, Inputs, Outputs */ | ||
87 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
88 | {1, {{0, 1, UP}}, {}}, | ||
89 | |||
90 | {5, {}, {{0, 1, UP}}}, | ||
91 | /* Press key after after 6ms delay (debounce has finished) */ | ||
92 | {11, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
93 | }); | ||
94 | runEvents(); | ||
95 | } | ||
96 | |||
97 | TEST_F(DebounceTest, OneKeyBouncing1) { | ||
98 | addEvents({ /* Time, Inputs, Outputs */ | ||
99 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
100 | {1, {{0, 1, UP}}, {}}, | ||
101 | {2, {{0, 1, DOWN}}, {}}, | ||
102 | {3, {{0, 1, UP}}, {}}, | ||
103 | {4, {{0, 1, DOWN}}, {}}, | ||
104 | {5, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
105 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
106 | {6, {{0, 1, DOWN}}, {}}, | ||
107 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
108 | }); | ||
109 | runEvents(); | ||
110 | } | ||
111 | |||
112 | TEST_F(DebounceTest, OneKeyBouncing2) { | ||
113 | addEvents({ /* Time, Inputs, Outputs */ | ||
114 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
115 | /* Change twice in the same time period */ | ||
116 | {1, {{0, 1, UP}}, {}}, | ||
117 | {1, {{0, 1, DOWN}}, {}}, | ||
118 | /* Change three times in the same time period */ | ||
119 | {2, {{0, 1, UP}}, {}}, | ||
120 | {2, {{0, 1, DOWN}}, {}}, | ||
121 | {2, {{0, 1, UP}}, {}}, | ||
122 | /* Change three times in the same time period */ | ||
123 | {3, {{0, 1, DOWN}}, {}}, | ||
124 | {3, {{0, 1, UP}}, {}}, | ||
125 | {3, {{0, 1, DOWN}}, {}}, | ||
126 | /* Change twice in the same time period */ | ||
127 | {4, {{0, 1, UP}}, {}}, | ||
128 | {4, {{0, 1, DOWN}}, {}}, | ||
129 | {5, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
130 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
131 | {6, {{0, 1, DOWN}}, {}}, | ||
132 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
133 | }); | ||
134 | runEvents(); | ||
135 | } | ||
136 | |||
137 | TEST_F(DebounceTest, OneKeyLong) { | ||
138 | addEvents({ /* Time, Inputs, Outputs */ | ||
139 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
140 | |||
141 | {25, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
142 | |||
143 | {50, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
144 | }); | ||
145 | runEvents(); | ||
146 | } | ||
147 | |||
148 | TEST_F(DebounceTest, TwoRowsShort) { | ||
149 | addEvents({ /* Time, Inputs, Outputs */ | ||
150 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
151 | {1, {{0, 1, UP}}, {}}, | ||
152 | {2, {{2, 0, DOWN}}, {{2, 0, DOWN}}}, | ||
153 | {3, {{2, 0, UP}}, {}}, | ||
154 | |||
155 | {5, {}, {{0, 1, UP}}}, | ||
156 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
157 | {6, {{0, 1, DOWN}}, {}}, | ||
158 | {7, {}, {{2, 0, UP}}}, | ||
159 | |||
160 | /* Press key again after 1ms delay (debounce has not yet finished) */ | ||
161 | {9, {{2, 0, DOWN}}, {}}, | ||
162 | {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */ | ||
163 | |||
164 | {12, {}, {{2, 0, DOWN}}}, /* 5ms after UP at time 7 */ | ||
165 | }); | ||
166 | runEvents(); | ||
167 | } | ||
168 | |||
169 | TEST_F(DebounceTest, TwoKeysOverlap) { | ||
170 | addEvents({ /* Time, Inputs, Outputs */ | ||
171 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
172 | {1, {{0, 1, UP}}, {}}, | ||
173 | /* Press a second key during the first debounce */ | ||
174 | {2, {{0, 2, DOWN}}, {}}, | ||
175 | |||
176 | /* Key registers as soon as debounce finishes, 5ms after time 0 */ | ||
177 | {5, {}, {{0, 1, UP}, {0, 2, DOWN}}}, | ||
178 | {6, {{0, 1, DOWN}}, {}}, | ||
179 | |||
180 | /* Key registers as soon as debounce finishes, 5ms after time 5 */ | ||
181 | {10, {}, {{0, 1, DOWN}}}, | ||
182 | /* Release both keys */ | ||
183 | {11, {{0, 1, UP}}, {}}, | ||
184 | {12, {{0, 2, UP}}, {}}, | ||
185 | |||
186 | /* Keys register as soon as debounce finishes, 5ms after time 10 */ | ||
187 | {15, {}, {{0, 1, UP}, {0, 2, UP}}}, | ||
188 | }); | ||
189 | runEvents(); | ||
190 | } | ||
191 | |||
192 | TEST_F(DebounceTest, TwoKeysSimultaneous1) { | ||
193 | addEvents({ /* Time, Inputs, Outputs */ | ||
194 | {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
195 | {20, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
196 | {21, {{0, 2, UP}}, {}}, | ||
197 | |||
198 | /* Key registers as soon as debounce finishes, 5ms after time 20 */ | ||
199 | {25, {}, {{0, 2, UP}}}, | ||
200 | }); | ||
201 | runEvents(); | ||
202 | } | ||
203 | |||
204 | TEST_F(DebounceTest, TwoKeysSimultaneous2) { | ||
205 | addEvents({ /* Time, Inputs, Outputs */ | ||
206 | {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}}, | ||
207 | {20, {{0, 1, UP}, {0, 2, UP}}, {{0, 1, UP}, {0, 2, UP}}}, | ||
208 | }); | ||
209 | runEvents(); | ||
210 | } | ||
211 | |||
212 | TEST_F(DebounceTest, OneKeyDelayedScan1) { | ||
213 | addEvents({ /* Time, Inputs, Outputs */ | ||
214 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
215 | |||
216 | /* Processing is very late but the change will now be accepted */ | ||
217 | {300, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
218 | }); | ||
219 | time_jumps_ = true; | ||
220 | runEvents(); | ||
221 | } | ||
222 | |||
223 | TEST_F(DebounceTest, OneKeyDelayedScan2) { | ||
224 | addEvents({ /* Time, Inputs, Outputs */ | ||
225 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
226 | |||
227 | /* Processing is very late but the change will now be accepted even with a 1 scan delay */ | ||
228 | {300, {}, {}}, | ||
229 | {300, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
230 | }); | ||
231 | time_jumps_ = true; | ||
232 | runEvents(); | ||
233 | } | ||
234 | |||
235 | TEST_F(DebounceTest, OneKeyDelayedScan3) { | ||
236 | addEvents({ /* Time, Inputs, Outputs */ | ||
237 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
238 | |||
239 | /* Processing is very late but the change will now be accepted even with a 1ms delay */ | ||
240 | {300, {}, {}}, | ||
241 | {301, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
242 | }); | ||
243 | time_jumps_ = true; | ||
244 | runEvents(); | ||
245 | } | ||
246 | |||
247 | TEST_F(DebounceTest, OneKeyDelayedScan4) { | ||
248 | addEvents({ /* Time, Inputs, Outputs */ | ||
249 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
250 | |||
251 | /* Processing is a bit late but the change will now be accepted */ | ||
252 | {50, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
253 | }); | ||
254 | time_jumps_ = true; | ||
255 | runEvents(); | ||
256 | } | ||
257 | |||
258 | TEST_F(DebounceTest, OneKeyDelayedScan5) { | ||
259 | addEvents({ /* Time, Inputs, Outputs */ | ||
260 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
261 | |||
262 | /* Processing is very late but the change will now be accepted even with a 1 scan delay */ | ||
263 | {50, {}, {}}, | ||
264 | {50, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
265 | }); | ||
266 | time_jumps_ = true; | ||
267 | runEvents(); | ||
268 | } | ||
269 | |||
270 | TEST_F(DebounceTest, OneKeyDelayedScan6) { | ||
271 | addEvents({ /* Time, Inputs, Outputs */ | ||
272 | {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, | ||
273 | |||
274 | /* Processing is very late but the change will now be accepted even with a 1ms delay */ | ||
275 | {50, {}, {}}, | ||
276 | {51, {{0, 1, UP}}, {{0, 1, UP}}}, | ||
277 | }); | ||
278 | time_jumps_ = true; | ||
279 | runEvents(); | ||
280 | } | ||
diff --git a/quantum/debounce/tests/testlist.mk b/quantum/debounce/tests/testlist.mk new file mode 100644 index 000000000..16ce8a0a8 --- /dev/null +++ b/quantum/debounce/tests/testlist.mk | |||
@@ -0,0 +1,5 @@ | |||
1 | TEST_LIST += \ | ||
2 | debounce_sym_defer_g \ | ||
3 | debounce_sym_defer_pk \ | ||
4 | debounce_sym_eager_pk \ | ||
5 | debounce_sym_eager_pr | ||
diff --git a/quantum/matrix.c b/quantum/matrix.c index 34d6af2e6..71ef27089 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | #include <stdint.h> | 17 | #include <stdint.h> |
18 | #include <stdbool.h> | 18 | #include <stdbool.h> |
19 | #include <string.h> | ||
19 | #include "util.h" | 20 | #include "util.h" |
20 | #include "matrix.h" | 21 | #include "matrix.h" |
21 | #include "debounce.h" | 22 | #include "debounce.h" |
@@ -24,14 +25,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | #ifdef DIRECT_PINS | 25 | #ifdef DIRECT_PINS |
25 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; | 26 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; |
26 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | 27 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) |
28 | # ifdef MATRIX_ROW_PINS | ||
27 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | 29 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; |
30 | # endif // MATRIX_ROW_PINS | ||
31 | # ifdef MATRIX_COL_PINS | ||
28 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | 32 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; |
33 | # endif // MATRIX_COL_PINS | ||
29 | #endif | 34 | #endif |
30 | 35 | ||
31 | /* matrix state(1:on, 0:off) */ | 36 | /* matrix state(1:on, 0:off) */ |
32 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | 37 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values |
33 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values | 38 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values |
34 | 39 | ||
40 | // user-defined overridable functions | ||
41 | __attribute__((weak)) void matrix_init_pins(void); | ||
42 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); | ||
43 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); | ||
44 | |||
35 | static inline void setPinOutput_writeLow(pin_t pin) { | 45 | static inline void setPinOutput_writeLow(pin_t pin) { |
36 | ATOMIC_BLOCK_FORCEON { | 46 | ATOMIC_BLOCK_FORCEON { |
37 | setPinOutput(pin); | 47 | setPinOutput(pin); |
@@ -47,7 +57,7 @@ static inline void setPinInputHigh_atomic(pin_t pin) { | |||
47 | 57 | ||
48 | #ifdef DIRECT_PINS | 58 | #ifdef DIRECT_PINS |
49 | 59 | ||
50 | static void init_pins(void) { | 60 | __attribute__((weak)) void matrix_init_pins(void) { |
51 | for (int row = 0; row < MATRIX_ROWS; row++) { | 61 | for (int row = 0; row < MATRIX_ROWS; row++) { |
52 | for (int col = 0; col < MATRIX_COLS; col++) { | 62 | for (int col = 0; col < MATRIX_COLS; col++) { |
53 | pin_t pin = direct_pins[row][col]; | 63 | pin_t pin = direct_pins[row][col]; |
@@ -58,7 +68,7 @@ static void init_pins(void) { | |||
58 | } | 68 | } |
59 | } | 69 | } |
60 | 70 | ||
61 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 71 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
62 | // Start with a clear matrix row | 72 | // Start with a clear matrix row |
63 | matrix_row_t current_row_value = 0; | 73 | matrix_row_t current_row_value = 0; |
64 | 74 | ||
@@ -69,16 +79,13 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
69 | } | 79 | } |
70 | } | 80 | } |
71 | 81 | ||
72 | // If the row has changed, store the row and return the changed flag. | 82 | // Update the matrix |
73 | if (current_matrix[current_row] != current_row_value) { | 83 | current_matrix[current_row] = current_row_value; |
74 | current_matrix[current_row] = current_row_value; | ||
75 | return true; | ||
76 | } | ||
77 | return false; | ||
78 | } | 84 | } |
79 | 85 | ||
80 | #elif defined(DIODE_DIRECTION) | 86 | #elif defined(DIODE_DIRECTION) |
81 | # if (DIODE_DIRECTION == COL2ROW) | 87 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) |
88 | # if (DIODE_DIRECTION == COL2ROW) | ||
82 | 89 | ||
83 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } | 90 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } |
84 | 91 | ||
@@ -90,14 +97,14 @@ static void unselect_rows(void) { | |||
90 | } | 97 | } |
91 | } | 98 | } |
92 | 99 | ||
93 | static void init_pins(void) { | 100 | __attribute__((weak)) void matrix_init_pins(void) { |
94 | unselect_rows(); | 101 | unselect_rows(); |
95 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 102 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
96 | setPinInputHigh_atomic(col_pins[x]); | 103 | setPinInputHigh_atomic(col_pins[x]); |
97 | } | 104 | } |
98 | } | 105 | } |
99 | 106 | ||
100 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 107 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
101 | // Start with a clear matrix row | 108 | // Start with a clear matrix row |
102 | matrix_row_t current_row_value = 0; | 109 | matrix_row_t current_row_value = 0; |
103 | 110 | ||
@@ -118,15 +125,11 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
118 | unselect_row(current_row); | 125 | unselect_row(current_row); |
119 | matrix_output_unselect_delay(); // wait for all Col signals to go HIGH | 126 | matrix_output_unselect_delay(); // wait for all Col signals to go HIGH |
120 | 127 | ||
121 | // If the row has changed, store the row and return the changed flag. | 128 | // Update the matrix |
122 | if (current_matrix[current_row] != current_row_value) { | 129 | current_matrix[current_row] = current_row_value; |
123 | current_matrix[current_row] = current_row_value; | ||
124 | return true; | ||
125 | } | ||
126 | return false; | ||
127 | } | 130 | } |
128 | 131 | ||
129 | # elif (DIODE_DIRECTION == ROW2COL) | 132 | # elif (DIODE_DIRECTION == ROW2COL) |
130 | 133 | ||
131 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } | 134 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } |
132 | 135 | ||
@@ -138,59 +141,46 @@ static void unselect_cols(void) { | |||
138 | } | 141 | } |
139 | } | 142 | } |
140 | 143 | ||
141 | static void init_pins(void) { | 144 | __attribute__((weak)) void matrix_init_pins(void) { |
142 | unselect_cols(); | 145 | unselect_cols(); |
143 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | 146 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { |
144 | setPinInputHigh_atomic(row_pins[x]); | 147 | setPinInputHigh_atomic(row_pins[x]); |
145 | } | 148 | } |
146 | } | 149 | } |
147 | 150 | ||
148 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 151 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { |
149 | bool matrix_changed = false; | ||
150 | |||
151 | // Select col | 152 | // Select col |
152 | select_col(current_col); | 153 | select_col(current_col); |
153 | matrix_output_select_delay(); | 154 | matrix_output_select_delay(); |
154 | 155 | ||
155 | // For each row... | 156 | // For each row... |
156 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | 157 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { |
157 | // Store last value of row prior to reading | ||
158 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
159 | matrix_row_t current_row_value = last_row_value; | ||
160 | |||
161 | // Check row pin state | 158 | // Check row pin state |
162 | if (readPin(row_pins[row_index]) == 0) { | 159 | if (readPin(row_pins[row_index]) == 0) { |
163 | // Pin LO, set col bit | 160 | // Pin LO, set col bit |
164 | current_row_value |= (MATRIX_ROW_SHIFTER << current_col); | 161 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); |
165 | } else { | 162 | } else { |
166 | // Pin HI, clear col bit | 163 | // Pin HI, clear col bit |
167 | current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); | 164 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); |
168 | } | ||
169 | |||
170 | // Determine if the matrix changed state | ||
171 | if ((last_row_value != current_row_value)) { | ||
172 | matrix_changed |= true; | ||
173 | current_matrix[row_index] = current_row_value; | ||
174 | } | 165 | } |
175 | } | 166 | } |
176 | 167 | ||
177 | // Unselect col | 168 | // Unselect col |
178 | unselect_col(current_col); | 169 | unselect_col(current_col); |
179 | matrix_output_unselect_delay(); // wait for all Row signals to go HIGH | 170 | matrix_output_unselect_delay(); // wait for all Row signals to go HIGH |
180 | |||
181 | return matrix_changed; | ||
182 | } | 171 | } |
183 | 172 | ||
184 | # else | 173 | # else |
185 | # error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! | 174 | # error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! |
186 | # endif | 175 | # endif |
176 | # endif // defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) | ||
187 | #else | 177 | #else |
188 | # error DIODE_DIRECTION is not defined! | 178 | # error DIODE_DIRECTION is not defined! |
189 | #endif | 179 | #endif |
190 | 180 | ||
191 | void matrix_init(void) { | 181 | void matrix_init(void) { |
192 | // initialize key pins | 182 | // initialize key pins |
193 | init_pins(); | 183 | matrix_init_pins(); |
194 | 184 | ||
195 | // initialize matrix state: all keys off | 185 | // initialize matrix state: all keys off |
196 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 186 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
@@ -204,20 +194,23 @@ void matrix_init(void) { | |||
204 | } | 194 | } |
205 | 195 | ||
206 | uint8_t matrix_scan(void) { | 196 | uint8_t matrix_scan(void) { |
207 | bool changed = false; | 197 | matrix_row_t curr_matrix[MATRIX_ROWS] = {0}; |
208 | 198 | ||
209 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) | 199 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) |
210 | // Set row, read cols | 200 | // Set row, read cols |
211 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | 201 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { |
212 | changed |= read_cols_on_row(raw_matrix, current_row); | 202 | matrix_read_cols_on_row(curr_matrix, current_row); |
213 | } | 203 | } |
214 | #elif (DIODE_DIRECTION == ROW2COL) | 204 | #elif (DIODE_DIRECTION == ROW2COL) |
215 | // Set col, read rows | 205 | // Set col, read rows |
216 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | 206 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { |
217 | changed |= read_rows_on_col(raw_matrix, current_col); | 207 | matrix_read_rows_on_col(curr_matrix, current_col); |
218 | } | 208 | } |
219 | #endif | 209 | #endif |
220 | 210 | ||
211 | bool changed = memcmp(raw_matrix, curr_matrix, sizeof(curr_matrix)) != 0; | ||
212 | if (changed) memcpy(raw_matrix, curr_matrix, sizeof(curr_matrix)); | ||
213 | |||
221 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | 214 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); |
222 | 215 | ||
223 | matrix_scan_quantum(); | 216 | matrix_scan_quantum(); |
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 039e7d977..2cf7b7058 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | #include <stdint.h> | 17 | #include <stdint.h> |
18 | #include <stdbool.h> | 18 | #include <stdbool.h> |
19 | #include <string.h> | ||
19 | #include "util.h" | 20 | #include "util.h" |
20 | #include "matrix.h" | 21 | #include "matrix.h" |
21 | #include "debounce.h" | 22 | #include "debounce.h" |
@@ -31,8 +32,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
31 | #ifdef DIRECT_PINS | 32 | #ifdef DIRECT_PINS |
32 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; | 33 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; |
33 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | 34 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) |
35 | # ifdef MATRIX_ROW_PINS | ||
34 | static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | 36 | static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; |
37 | # endif // MATRIX_ROW_PINS | ||
38 | # ifdef MATRIX_COL_PINS | ||
35 | static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | 39 | static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; |
40 | # endif // MATRIX_COL_PINS | ||
36 | #endif | 41 | #endif |
37 | 42 | ||
38 | /* matrix state(1:on, 0:off) */ | 43 | /* matrix state(1:on, 0:off) */ |
@@ -45,6 +50,9 @@ uint8_t thisHand, thatHand; | |||
45 | // user-defined overridable functions | 50 | // user-defined overridable functions |
46 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } | 51 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } |
47 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | 52 | __attribute__((weak)) void matrix_slave_scan_user(void) {} |
53 | __attribute__((weak)) void matrix_init_pins(void); | ||
54 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); | ||
55 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); | ||
48 | 56 | ||
49 | static inline void setPinOutput_writeLow(pin_t pin) { | 57 | static inline void setPinOutput_writeLow(pin_t pin) { |
50 | ATOMIC_BLOCK_FORCEON { | 58 | ATOMIC_BLOCK_FORCEON { |
@@ -61,7 +69,7 @@ static inline void setPinInputHigh_atomic(pin_t pin) { | |||
61 | 69 | ||
62 | #ifdef DIRECT_PINS | 70 | #ifdef DIRECT_PINS |
63 | 71 | ||
64 | static void init_pins(void) { | 72 | __attribute__((weak)) void matrix_init_pins(void) { |
65 | for (int row = 0; row < MATRIX_ROWS; row++) { | 73 | for (int row = 0; row < MATRIX_ROWS; row++) { |
66 | for (int col = 0; col < MATRIX_COLS; col++) { | 74 | for (int col = 0; col < MATRIX_COLS; col++) { |
67 | pin_t pin = direct_pins[row][col]; | 75 | pin_t pin = direct_pins[row][col]; |
@@ -72,7 +80,7 @@ static void init_pins(void) { | |||
72 | } | 80 | } |
73 | } | 81 | } |
74 | 82 | ||
75 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 83 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
76 | // Start with a clear matrix row | 84 | // Start with a clear matrix row |
77 | matrix_row_t current_row_value = 0; | 85 | matrix_row_t current_row_value = 0; |
78 | 86 | ||
@@ -83,16 +91,13 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
83 | } | 91 | } |
84 | } | 92 | } |
85 | 93 | ||
86 | // If the row has changed, store the row and return the changed flag. | 94 | // Update the matrix |
87 | if (current_matrix[current_row] != current_row_value) { | 95 | current_matrix[current_row] = current_row_value; |
88 | current_matrix[current_row] = current_row_value; | ||
89 | return true; | ||
90 | } | ||
91 | return false; | ||
92 | } | 96 | } |
93 | 97 | ||
94 | #elif defined(DIODE_DIRECTION) | 98 | #elif defined(DIODE_DIRECTION) |
95 | # if (DIODE_DIRECTION == COL2ROW) | 99 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) |
100 | # if (DIODE_DIRECTION == COL2ROW) | ||
96 | 101 | ||
97 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } | 102 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } |
98 | 103 | ||
@@ -104,14 +109,14 @@ static void unselect_rows(void) { | |||
104 | } | 109 | } |
105 | } | 110 | } |
106 | 111 | ||
107 | static void init_pins(void) { | 112 | __attribute__((weak)) void matrix_init_pins(void) { |
108 | unselect_rows(); | 113 | unselect_rows(); |
109 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 114 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
110 | setPinInputHigh_atomic(col_pins[x]); | 115 | setPinInputHigh_atomic(col_pins[x]); |
111 | } | 116 | } |
112 | } | 117 | } |
113 | 118 | ||
114 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 119 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
115 | // Start with a clear matrix row | 120 | // Start with a clear matrix row |
116 | matrix_row_t current_row_value = 0; | 121 | matrix_row_t current_row_value = 0; |
117 | 122 | ||
@@ -132,15 +137,11 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
132 | unselect_row(current_row); | 137 | unselect_row(current_row); |
133 | matrix_output_unselect_delay(); // wait for all Col signals to go HIGH | 138 | matrix_output_unselect_delay(); // wait for all Col signals to go HIGH |
134 | 139 | ||
135 | // If the row has changed, store the row and return the changed flag. | 140 | // Update the matrix |
136 | if (current_matrix[current_row] != current_row_value) { | 141 | current_matrix[current_row] = current_row_value; |
137 | current_matrix[current_row] = current_row_value; | ||
138 | return true; | ||
139 | } | ||
140 | return false; | ||
141 | } | 142 | } |
142 | 143 | ||
143 | # elif (DIODE_DIRECTION == ROW2COL) | 144 | # elif (DIODE_DIRECTION == ROW2COL) |
144 | 145 | ||
145 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } | 146 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } |
146 | 147 | ||
@@ -152,52 +153,39 @@ static void unselect_cols(void) { | |||
152 | } | 153 | } |
153 | } | 154 | } |
154 | 155 | ||
155 | static void init_pins(void) { | 156 | __attribute__((weak)) void matrix_init_pins(void) { |
156 | unselect_cols(); | 157 | unselect_cols(); |
157 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { | 158 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { |
158 | setPinInputHigh_atomic(row_pins[x]); | 159 | setPinInputHigh_atomic(row_pins[x]); |
159 | } | 160 | } |
160 | } | 161 | } |
161 | 162 | ||
162 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 163 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { |
163 | bool matrix_changed = false; | ||
164 | |||
165 | // Select col | 164 | // Select col |
166 | select_col(current_col); | 165 | select_col(current_col); |
167 | matrix_output_select_delay(); | 166 | matrix_output_select_delay(); |
168 | 167 | ||
169 | // For each row... | 168 | // For each row... |
170 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { | 169 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { |
171 | // Store last value of row prior to reading | ||
172 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
173 | matrix_row_t current_row_value = last_row_value; | ||
174 | |||
175 | // Check row pin state | 170 | // Check row pin state |
176 | if (readPin(row_pins[row_index]) == 0) { | 171 | if (readPin(row_pins[row_index]) == 0) { |
177 | // Pin LO, set col bit | 172 | // Pin LO, set col bit |
178 | current_row_value |= (MATRIX_ROW_SHIFTER << current_col); | 173 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); |
179 | } else { | 174 | } else { |
180 | // Pin HI, clear col bit | 175 | // Pin HI, clear col bit |
181 | current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); | 176 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); |
182 | } | ||
183 | |||
184 | // Determine if the matrix changed state | ||
185 | if ((last_row_value != current_row_value)) { | ||
186 | matrix_changed |= true; | ||
187 | current_matrix[row_index] = current_row_value; | ||
188 | } | 177 | } |
189 | } | 178 | } |
190 | 179 | ||
191 | // Unselect col | 180 | // Unselect col |
192 | unselect_col(current_col); | 181 | unselect_col(current_col); |
193 | matrix_output_unselect_delay(); // wait for all Row signals to go HIGH | 182 | matrix_output_unselect_delay(); // wait for all Row signals to go HIGH |
194 | |||
195 | return matrix_changed; | ||
196 | } | 183 | } |
197 | 184 | ||
198 | # else | 185 | # else |
199 | # error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! | 186 | # error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! |
200 | # endif | 187 | # endif |
188 | # endif // defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) | ||
201 | #else | 189 | #else |
202 | # error DIODE_DIRECTION is not defined! | 190 | # error DIODE_DIRECTION is not defined! |
203 | #endif | 191 | #endif |
@@ -233,7 +221,7 @@ void matrix_init(void) { | |||
233 | thatHand = ROWS_PER_HAND - thisHand; | 221 | thatHand = ROWS_PER_HAND - thisHand; |
234 | 222 | ||
235 | // initialize key pins | 223 | // initialize key pins |
236 | init_pins(); | 224 | matrix_init_pins(); |
237 | 225 | ||
238 | // initialize matrix state: all keys off | 226 | // initialize matrix state: all keys off |
239 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 227 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
@@ -288,20 +276,23 @@ bool matrix_post_scan(void) { | |||
288 | } | 276 | } |
289 | 277 | ||
290 | uint8_t matrix_scan(void) { | 278 | uint8_t matrix_scan(void) { |
291 | bool local_changed = false; | 279 | matrix_row_t curr_matrix[MATRIX_ROWS] = {0}; |
292 | 280 | ||
293 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) | 281 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) |
294 | // Set row, read cols | 282 | // Set row, read cols |
295 | for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { | 283 | for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { |
296 | local_changed |= read_cols_on_row(raw_matrix, current_row); | 284 | matrix_read_cols_on_row(curr_matrix, current_row); |
297 | } | 285 | } |
298 | #elif (DIODE_DIRECTION == ROW2COL) | 286 | #elif (DIODE_DIRECTION == ROW2COL) |
299 | // Set col, read rows | 287 | // Set col, read rows |
300 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | 288 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { |
301 | local_changed |= read_rows_on_col(raw_matrix, current_col); | 289 | matrix_read_rows_on_col(curr_matrix, current_col); |
302 | } | 290 | } |
303 | #endif | 291 | #endif |
304 | 292 | ||
293 | bool local_changed = memcmp(raw_matrix, curr_matrix, sizeof(curr_matrix)) != 0; | ||
294 | if (local_changed) memcpy(raw_matrix, curr_matrix, sizeof(curr_matrix)); | ||
295 | |||
305 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); | 296 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); |
306 | 297 | ||
307 | bool remote_changed = matrix_post_scan(); | 298 | bool remote_changed = matrix_post_scan(); |
diff --git a/testlist.mk b/testlist.mk index 0d7609b9f..d256f4c81 100644 --- a/testlist.mk +++ b/testlist.mk | |||
@@ -1,6 +1,7 @@ | |||
1 | TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk))) | 1 | TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk))) |
2 | FULL_TESTS := $(TEST_LIST) | 2 | FULL_TESTS := $(TEST_LIST) |
3 | 3 | ||
4 | include $(ROOT_DIR)/quantum/debounce/tests/testlist.mk | ||
4 | include $(ROOT_DIR)/quantum/sequencer/tests/testlist.mk | 5 | include $(ROOT_DIR)/quantum/sequencer/tests/testlist.mk |
5 | include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk | 6 | include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk |
6 | 7 | ||
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index 521305f1b..2ba193c76 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk | |||
@@ -295,7 +295,7 @@ ifneq ($(strip $(BOOTLOADER)), qmk-dfu) | |||
295 | endif | 295 | endif |
296 | make -C lib/lufa/Bootloaders/DFU/ clean | 296 | make -C lib/lufa/Bootloaders/DFU/ clean |
297 | $(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/DFU/Keyboard.h | 297 | $(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/DFU/Keyboard.h |
298 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) | 298 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) |
299 | $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | 299 | $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0)) |
300 | $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | 300 | $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0)) |
301 | $(eval FLASH_SIZE_KB=$(shell n=`expr $(PROGRAM_SIZE_KB) + $(BOOT_SECTION_SIZE_KB)` && echo $$(($$n)) || echo 0)) | 301 | $(eval FLASH_SIZE_KB=$(shell n=`expr $(PROGRAM_SIZE_KB) + $(BOOT_SECTION_SIZE_KB)` && echo $$(($$n)) || echo 0)) |
diff --git a/tmk_core/common/arm_atsam/_timer.h b/tmk_core/common/arm_atsam/_timer.h new file mode 100644 index 000000000..77402b612 --- /dev/null +++ b/tmk_core/common/arm_atsam/_timer.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | #pragma once | ||
17 | |||
18 | // The platform is 32-bit, so prefer 32-bit timers to avoid overflow | ||
19 | #define FAST_TIMER_T_SIZE 32 | ||
diff --git a/tmk_core/common/avr/_timer.h b/tmk_core/common/avr/_timer.h new file mode 100644 index 000000000..b81e0f68b --- /dev/null +++ b/tmk_core/common/avr/_timer.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | #pragma once | ||
17 | |||
18 | // The platform is 8-bit, so prefer 16-bit timers to reduce code size | ||
19 | #define FAST_TIMER_T_SIZE 16 | ||
diff --git a/tmk_core/common/avr/gpio.h b/tmk_core/common/avr/gpio.h index 231556c29..e9be68491 100644 --- a/tmk_core/common/avr/gpio.h +++ b/tmk_core/common/avr/gpio.h | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | typedef uint8_t pin_t; | 21 | typedef uint8_t pin_t; |
22 | 22 | ||
23 | /* Operation of GPIO by pin. */ | ||
24 | |||
23 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | 25 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) |
24 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | 26 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) |
25 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | 27 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") |
@@ -32,3 +34,16 @@ typedef uint8_t pin_t; | |||
32 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | 34 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) |
33 | 35 | ||
34 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | 36 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) |
37 | |||
38 | /* Operation of GPIO by port. */ | ||
39 | |||
40 | typedef uint8_t port_data_t; | ||
41 | |||
42 | #define readPort(port) PINx_ADDRESS(port) | ||
43 | |||
44 | #define setPortBitInput(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) &= ~_BV((bit)&0xF)) | ||
45 | #define setPortBitInputHigh(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
46 | #define setPortBitOutput(port, bit) (DDRx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
47 | |||
48 | #define writePortBitLow(port, bit) (PORTx_ADDRESS(port) &= ~_BV((bit)&0xF)) | ||
49 | #define writePortBitHigh(port, bit) (PORTx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
diff --git a/tmk_core/common/chibios/_timer.h b/tmk_core/common/chibios/_timer.h new file mode 100644 index 000000000..77402b612 --- /dev/null +++ b/tmk_core/common/chibios/_timer.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 Simon Arlott | ||
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 | #pragma once | ||
17 | |||
18 | // The platform is 32-bit, so prefer 32-bit timers to avoid overflow | ||
19 | #define FAST_TIMER_T_SIZE 32 | ||
diff --git a/tmk_core/common/chibios/gpio.h b/tmk_core/common/chibios/gpio.h index 5d0e142ab..4d057f1ca 100644 --- a/tmk_core/common/chibios/gpio.h +++ b/tmk_core/common/chibios/gpio.h | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | typedef ioline_t pin_t; | 21 | typedef ioline_t pin_t; |
22 | 22 | ||
23 | /* Operation of GPIO by pin. */ | ||
24 | |||
23 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | 25 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) |
24 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | 26 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) |
25 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | 27 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) |
@@ -32,3 +34,17 @@ typedef ioline_t pin_t; | |||
32 | #define readPin(pin) palReadLine(pin) | 34 | #define readPin(pin) palReadLine(pin) |
33 | 35 | ||
34 | #define togglePin(pin) palToggleLine(pin) | 36 | #define togglePin(pin) palToggleLine(pin) |
37 | |||
38 | /* Operation of GPIO by port. */ | ||
39 | |||
40 | typedef uint16_t port_data_t; | ||
41 | |||
42 | #define readPort(pin) palReadPort(PAL_PORT(pin)) | ||
43 | |||
44 | #define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT) | ||
45 | #define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLUP) | ||
46 | #define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLDOWN) | ||
47 | #define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_OUTPUT_PUSHPULL) | ||
48 | |||
49 | #define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
50 | #define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h index 58f637dd9..928811a2b 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> |
3 | Copyright 2021 Simon Arlott | ||
3 | 4 | ||
4 | This program is free software: you can redistribute it and/or modify | 5 | This program is free software: you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 18 | ||
18 | #pragma once | 19 | #pragma once |
19 | 20 | ||
21 | #if __has_include_next("_timer.h") | ||
22 | # include_next "_timer.h" /* Include the platform's _timer.h */ | ||
23 | #endif | ||
24 | |||
20 | #include <stdint.h> | 25 | #include <stdint.h> |
21 | #include <stdbool.h> | 26 | #include <stdbool.h> |
22 | 27 | ||
23 | #if defined(__AVR__) | ||
24 | # include "avr/timer_avr.h" | ||
25 | #endif | ||
26 | |||
27 | #define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) | 28 | #define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) |
28 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) | 29 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) |
29 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) | 30 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) |
@@ -47,6 +48,21 @@ uint32_t timer_elapsed32(uint32_t last); | |||
47 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) | 48 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) |
48 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) | 49 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) |
49 | 50 | ||
51 | // Use an appropriate timer integer size based on architecture (16-bit will overflow sooner) | ||
52 | #if FAST_TIMER_T_SIZE < 32 | ||
53 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_16(a, b) | ||
54 | # define timer_expired_fast(current, future) timer_expired(current, future) | ||
55 | typedef uint16_t fast_timer_t; | ||
56 | fast_timer_t inline timer_read_fast(void) { return timer_read(); } | ||
57 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed(last); } | ||
58 | #else | ||
59 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_32(a, b) | ||
60 | # define timer_expired_fast(current, future) timer_expired32(current, future) | ||
61 | typedef uint32_t fast_timer_t; | ||
62 | fast_timer_t inline timer_read_fast(void) { return timer_read32(); } | ||
63 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed32(last); } | ||
64 | #endif | ||
65 | |||
50 | #ifdef __cplusplus | 66 | #ifdef __cplusplus |
51 | } | 67 | } |
52 | #endif | 68 | #endif |
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index d04302aca..407b8ea75 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c | |||
@@ -903,7 +903,8 @@ static void send_extra(uint8_t report_id, uint16_t data) { | |||
903 | return; | 903 | return; |
904 | } | 904 | } |
905 | 905 | ||
906 | report_extra_t report = {.report_id = report_id, .usage = data}; | 906 | static report_extra_t report; |
907 | report = (report_extra_t){.report_id = report_id, .usage = data}; | ||
907 | 908 | ||
908 | usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t)); | 909 | usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t)); |
909 | osalSysUnlock(); | 910 | osalSysUnlock(); |
@@ -1051,45 +1052,44 @@ void virtser_task(void) { | |||
1051 | #ifdef JOYSTICK_ENABLE | 1052 | #ifdef JOYSTICK_ENABLE |
1052 | 1053 | ||
1053 | void send_joystick_packet(joystick_t *joystick) { | 1054 | void send_joystick_packet(joystick_t *joystick) { |
1054 | joystick_report_t rep = { | 1055 | static joystick_report_t rep; |
1056 | rep = (joystick_report_t) { | ||
1055 | # if JOYSTICK_AXES_COUNT > 0 | 1057 | # if JOYSTICK_AXES_COUNT > 0 |
1056 | .axes = | 1058 | .axes = |
1057 | { | 1059 | { joystick->axes[0], |
1058 | joystick->axes[0], | ||
1059 | 1060 | ||
1060 | # if JOYSTICK_AXES_COUNT >= 2 | 1061 | # if JOYSTICK_AXES_COUNT >= 2 |
1061 | joystick->axes[1], | 1062 | joystick->axes[1], |
1062 | # endif | 1063 | # endif |
1063 | # if JOYSTICK_AXES_COUNT >= 3 | 1064 | # if JOYSTICK_AXES_COUNT >= 3 |
1064 | joystick->axes[2], | 1065 | joystick->axes[2], |
1065 | # endif | 1066 | # endif |
1066 | # if JOYSTICK_AXES_COUNT >= 4 | 1067 | # if JOYSTICK_AXES_COUNT >= 4 |
1067 | joystick->axes[3], | 1068 | joystick->axes[3], |
1068 | # endif | 1069 | # endif |
1069 | # if JOYSTICK_AXES_COUNT >= 5 | 1070 | # if JOYSTICK_AXES_COUNT >= 5 |
1070 | joystick->axes[4], | 1071 | joystick->axes[4], |
1071 | # endif | 1072 | # endif |
1072 | # if JOYSTICK_AXES_COUNT >= 6 | 1073 | # if JOYSTICK_AXES_COUNT >= 6 |
1073 | joystick->axes[5], | 1074 | joystick->axes[5], |
1074 | # endif | 1075 | # endif |
1075 | }, | 1076 | }, |
1076 | # endif // JOYSTICK_AXES_COUNT>0 | 1077 | # endif // JOYSTICK_AXES_COUNT>0 |
1077 | 1078 | ||
1078 | # if JOYSTICK_BUTTON_COUNT > 0 | 1079 | # if JOYSTICK_BUTTON_COUNT > 0 |
1079 | .buttons = | 1080 | .buttons = { |
1080 | { | 1081 | joystick->buttons[0], |
1081 | joystick->buttons[0], | ||
1082 | 1082 | ||
1083 | # if JOYSTICK_BUTTON_COUNT > 8 | 1083 | # if JOYSTICK_BUTTON_COUNT > 8 |
1084 | joystick->buttons[1], | 1084 | joystick->buttons[1], |
1085 | # endif | 1085 | # endif |
1086 | # if JOYSTICK_BUTTON_COUNT > 16 | 1086 | # if JOYSTICK_BUTTON_COUNT > 16 |
1087 | joystick->buttons[2], | 1087 | joystick->buttons[2], |
1088 | # endif | 1088 | # endif |
1089 | # if JOYSTICK_BUTTON_COUNT > 24 | 1089 | # if JOYSTICK_BUTTON_COUNT > 24 |
1090 | joystick->buttons[3], | 1090 | joystick->buttons[3], |
1091 | # endif | 1091 | # endif |
1092 | } | 1092 | } |
1093 | # endif // JOYSTICK_BUTTON_COUNT>0 | 1093 | # endif // JOYSTICK_BUTTON_COUNT>0 |
1094 | }; | 1094 | }; |
1095 | 1095 | ||
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 63619fdb3..4ac079e16 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
@@ -314,45 +314,44 @@ static void Console_Task(void) { | |||
314 | void send_joystick_packet(joystick_t *joystick) { | 314 | void send_joystick_packet(joystick_t *joystick) { |
315 | uint8_t timeout = 255; | 315 | uint8_t timeout = 255; |
316 | 316 | ||
317 | joystick_report_t r = { | 317 | static joystick_report_t; |
318 | r = (joystick_report_t) { | ||
318 | # if JOYSTICK_AXES_COUNT > 0 | 319 | # if JOYSTICK_AXES_COUNT > 0 |
319 | .axes = | 320 | .axes = |
320 | { | 321 | { joystick->axes[0], |
321 | joystick->axes[0], | ||
322 | 322 | ||
323 | # if JOYSTICK_AXES_COUNT >= 2 | 323 | # if JOYSTICK_AXES_COUNT >= 2 |
324 | joystick->axes[1], | 324 | joystick->axes[1], |
325 | # endif | 325 | # endif |
326 | # if JOYSTICK_AXES_COUNT >= 3 | 326 | # if JOYSTICK_AXES_COUNT >= 3 |
327 | joystick->axes[2], | 327 | joystick->axes[2], |
328 | # endif | 328 | # endif |
329 | # if JOYSTICK_AXES_COUNT >= 4 | 329 | # if JOYSTICK_AXES_COUNT >= 4 |
330 | joystick->axes[3], | 330 | joystick->axes[3], |
331 | # endif | 331 | # endif |
332 | # if JOYSTICK_AXES_COUNT >= 5 | 332 | # if JOYSTICK_AXES_COUNT >= 5 |
333 | joystick->axes[4], | 333 | joystick->axes[4], |
334 | # endif | 334 | # endif |
335 | # if JOYSTICK_AXES_COUNT >= 6 | 335 | # if JOYSTICK_AXES_COUNT >= 6 |
336 | joystick->axes[5], | 336 | joystick->axes[5], |
337 | # endif | 337 | # endif |
338 | }, | 338 | }, |
339 | # endif // JOYSTICK_AXES_COUNT>0 | 339 | # endif // JOYSTICK_AXES_COUNT>0 |
340 | 340 | ||
341 | # if JOYSTICK_BUTTON_COUNT > 0 | 341 | # if JOYSTICK_BUTTON_COUNT > 0 |
342 | .buttons = | 342 | .buttons = { |
343 | { | 343 | joystick->buttons[0], |
344 | joystick->buttons[0], | ||
345 | 344 | ||
346 | # if JOYSTICK_BUTTON_COUNT > 8 | 345 | # if JOYSTICK_BUTTON_COUNT > 8 |
347 | joystick->buttons[1], | 346 | joystick->buttons[1], |
348 | # endif | 347 | # endif |
349 | # if JOYSTICK_BUTTON_COUNT > 16 | 348 | # if JOYSTICK_BUTTON_COUNT > 16 |
350 | joystick->buttons[2], | 349 | joystick->buttons[2], |
351 | # endif | 350 | # endif |
352 | # if JOYSTICK_BUTTON_COUNT > 24 | 351 | # if JOYSTICK_BUTTON_COUNT > 24 |
353 | joystick->buttons[3], | 352 | joystick->buttons[3], |
354 | # endif | 353 | # endif |
355 | } | 354 | } |
356 | # endif // JOYSTICK_BUTTON_COUNT>0 | 355 | # endif // JOYSTICK_BUTTON_COUNT>0 |
357 | }; | 356 | }; |
358 | 357 | ||
@@ -768,7 +767,8 @@ static void send_extra(uint8_t report_id, uint16_t data) { | |||
768 | 767 | ||
769 | if (USB_DeviceState != DEVICE_STATE_Configured) return; | 768 | if (USB_DeviceState != DEVICE_STATE_Configured) return; |
770 | 769 | ||
771 | report_extra_t r = {.report_id = report_id, .usage = data}; | 770 | static report_extra_t r; |
771 | r = (report_extra_t){.report_id = report_id, .usage = data}; | ||
772 | Endpoint_SelectEndpoint(SHARED_IN_EPNUM); | 772 | Endpoint_SelectEndpoint(SHARED_IN_EPNUM); |
773 | 773 | ||
774 | /* Check if write ready for a polling interval around 10ms */ | 774 | /* Check if write ready for a polling interval around 10ms */ |
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index ba7760f28..c88aceb6e 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c | |||
@@ -351,7 +351,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { | |||
351 | .Size = sizeof(USB_Descriptor_Device_t), | 351 | .Size = sizeof(USB_Descriptor_Device_t), |
352 | .Type = DTYPE_Device | 352 | .Type = DTYPE_Device |
353 | }, | 353 | }, |
354 | .USBSpecification = VERSION_BCD(1, 1, 0), | 354 | .USBSpecification = VERSION_BCD(2, 0, 0), |
355 | 355 | ||
356 | #if VIRTSER_ENABLE | 356 | #if VIRTSER_ENABLE |
357 | .Class = USB_CSCP_IADDeviceClass, | 357 | .Class = USB_CSCP_IADDeviceClass, |
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 9362fbde7..876a31378 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
@@ -272,7 +272,8 @@ static void send_extra(uint8_t report_id, uint16_t data) { | |||
272 | last_id = report_id; | 272 | last_id = report_id; |
273 | last_data = data; | 273 | last_data = data; |
274 | 274 | ||
275 | report_extra_t report = {.report_id = report_id, .usage = data}; | 275 | static report_extra_t report; |
276 | report = (report_extra_t){.report_id = report_id, .usage = data}; | ||
276 | if (usbInterruptIsReadyShared()) { | 277 | if (usbInterruptIsReadyShared()) { |
277 | usbSetInterruptShared((void *)&report, sizeof(report_extra_t)); | 278 | usbSetInterruptShared((void *)&report, sizeof(report_extra_t)); |
278 | } | 279 | } |
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index fc2dc68be..597f7aa82 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk | |||
@@ -458,7 +458,7 @@ ifeq ($(findstring avr-gcc,$(CC)),avr-gcc) | |||
458 | SIZE_MARGIN = 1024 | 458 | SIZE_MARGIN = 1024 |
459 | 459 | ||
460 | check-size: | 460 | check-size: |
461 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) | 461 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) |
462 | $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi)) | 462 | $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi)) |
463 | $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE))) | 463 | $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE))) |
464 | $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE))) | 464 | $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE))) |