From a1a5869ef871937c2ae7646ab639c4f5ffe59355 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 27 Jun 2025 08:17:45 +0100 Subject: Add MATRIX_MASKED DD config (#25383) --- docs/reference_info_json.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/reference_info_json.md') diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index a64f2992b5..71d1c5c865 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -480,6 +480,9 @@ Configures the [LED Matrix](features/led_matrix) feature. * `io_delay` Number * The amount of time to wait between row/col selection and col/row pin reading, in microseconds. * Default: `30` (30 µs) + * `masked` Boolean + * Whether configured intersections should be ignored. + * Default: `false` * `rows` Array: Pin * A list of GPIO pins connected to the matrix rows. * Example: `["B0", "B1", "B2"]` -- cgit v1.2.3 From 12dc6d1ac80b6919fcdb084d897612559b2f391b Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Sun, 10 Aug 2025 00:14:40 +0200 Subject: Fix serial speed DD configuration & migrate keyboards (#25546) * Fix serial speed DD configuration - Fixes incorrect SOFT_SERIAL_SPEED mapping - Renames key split.soft_serial_speed -> split.serial.speed - Migrates keyoards that configure this, and remove configuration from keyboards that do not differ from the default behaviour - Add deprecation notice and migration support--- data/mappings/info_config.hjson | 2 +- data/schemas/keyboard.jsonschema | 10 +++++--- docs/reference_info_json.md | 6 ++--- keyboards/aleblazer/zodiark/config.h | 19 --------------- keyboards/flxlb/zplit/config.h | 1 - keyboards/giabalanai/config.h | 10 -------- .../dactyl_manuform/6x6/blackpill_f411/config.h | 7 ------ keyboards/handwired/myskeeb/config.h | 1 - keyboards/handwired/split65/promicro/config.h | 2 -- keyboards/handwired/split65/stm32/config.h | 1 - keyboards/manta60/config.h | 2 -- keyboards/momoka_ergo/config.h | 2 -- keyboards/momoka_ergo/keyboard.json | 3 ++- keyboards/omkbd/ergodash/mini/config.h | 10 -------- keyboards/omkbd/ergodash/rev1/config.h | 10 -------- keyboards/omkbd/runner3680/3x6/config.h | 27 ---------------------- keyboards/omkbd/runner3680/3x7/config.h | 27 ---------------------- keyboards/omkbd/runner3680/3x8/config.h | 27 ---------------------- keyboards/omkbd/runner3680/4x6/config.h | 27 ---------------------- keyboards/omkbd/runner3680/4x7/config.h | 27 ---------------------- keyboards/omkbd/runner3680/4x8/config.h | 27 ---------------------- keyboards/omkbd/runner3680/5x6/config.h | 27 ---------------------- keyboards/omkbd/runner3680/5x6_5x8/config.h | 27 ---------------------- keyboards/omkbd/runner3680/5x7/config.h | 27 ---------------------- keyboards/omkbd/runner3680/5x8/config.h | 27 ---------------------- keyboards/redox/rev1/proton_c/config.h | 7 ------ keyboards/tkw/grandiceps/config.h | 2 -- keyboards/unikeyboard/diverge3/config.h | 4 ---- keyboards/unikeyboard/diverge3/keyboard.json | 3 ++- keyboards/zvecr/split_blackpill/config.h | 2 -- keyboards/zvecr/split_blackpill/keyboard.json | 3 ++- keyboards/zvecr/zv48/config.h | 1 - lib/python/qmk/info.py | 3 +++ 33 files changed, 20 insertions(+), 361 deletions(-) delete mode 100644 keyboards/aleblazer/zodiark/config.h delete mode 100644 keyboards/omkbd/runner3680/3x6/config.h delete mode 100644 keyboards/omkbd/runner3680/3x7/config.h delete mode 100644 keyboards/omkbd/runner3680/3x8/config.h delete mode 100644 keyboards/omkbd/runner3680/4x6/config.h delete mode 100644 keyboards/omkbd/runner3680/4x7/config.h delete mode 100644 keyboards/omkbd/runner3680/4x8/config.h delete mode 100644 keyboards/omkbd/runner3680/5x6/config.h delete mode 100644 keyboards/omkbd/runner3680/5x6_5x8/config.h delete mode 100644 keyboards/omkbd/runner3680/5x7/config.h delete mode 100644 keyboards/omkbd/runner3680/5x8/config.h (limited to 'docs/reference_info_json.md') diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index 356dd6ba52..a160e490c7 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson @@ -184,7 +184,7 @@ // Split Keyboard "SOFT_SERIAL_PIN": {"info_key": "split.serial.pin"}, - "SOFT_SERIAL_SPEED": {"info_key": "split.soft_serial_speed"}, + "SELECT_SOFT_SERIAL_SPEED": {"info_key": "split.serial.speed"}, "SPLIT_HAND_MATRIX_GRID": {"info_key": "split.handedness.matrix_grid", "value_type": "array", "to_c": false}, "SPLIT_HAND_PIN": {"info_key": "split.handedness.pin"}, "SPLIT_USB_DETECT": {"info_key": "split.usb_detect.enabled", "value_type": "flag"}, diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 13ceec5afa..3775b66c1a 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -864,8 +864,7 @@ }, "soft_serial_speed": { "type": "integer", - "minimum": 0, - "maximum": 5 + "$comment": "Deprecated: use split.serial.speed instead" }, "serial": { "type": "object", @@ -875,7 +874,12 @@ "type": "string", "enum": ["bitbang", "usart", "vendor"] }, - "pin": {"$ref": "./definitions.jsonschema#/mcu_pin"} + "pin": {"$ref": "./definitions.jsonschema#/mcu_pin"}, + "speed": { + "type": "integer", + "minimum": 0, + "maximum": 5 + } } }, "transport": { diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index c30859955f..cf22317613 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -753,9 +753,9 @@ Configures the [Split Keyboard](features/split_keyboard) feature. * Default: `"bitbang"` * `pin` Pin * The GPIO pin to use for transmit and receive. - * `soft_serial_speed` Number - * The protocol speed, from `0` to `5` (`serial` transport protocol only). - * Default: `1` + * `speed` Number + * The protocol speed, from `0` to `5` (fastest to slowest). + * Default: `1` * `transport` * `protocol` String * The split transport protocol to use. Must be one of `custom`, `i2c`, `serial`. diff --git a/keyboards/aleblazer/zodiark/config.h b/keyboards/aleblazer/zodiark/config.h deleted file mode 100644 index 8230f082b3..0000000000 --- a/keyboards/aleblazer/zodiark/config.h +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2021 Spencer Deven - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 diff --git a/keyboards/flxlb/zplit/config.h b/keyboards/flxlb/zplit/config.h index 832108a54b..af2447eb68 100644 --- a/keyboards/flxlb/zplit/config.h +++ b/keyboards/flxlb/zplit/config.h @@ -18,7 +18,6 @@ along with this program. If not, see . #pragma once -#define SELECT_SOFT_SERIAL_SPEED 1 // #define USE_I2C #define SPLIT_USB_DETECT #define SPLIT_USB_TIMEOUT 500 diff --git a/keyboards/giabalanai/config.h b/keyboards/giabalanai/config.h index bd501c1f76..886df53c18 100644 --- a/keyboards/giabalanai/config.h +++ b/keyboards/giabalanai/config.h @@ -17,16 +17,6 @@ along with this program. If not, see . #pragma once -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps - // Right side has to be the master since 1, LED data is output from right side, and 2, Audio pin is prepared on right side as a reserve. #define MASTER_RIGHT diff --git a/keyboards/handwired/dactyl_manuform/6x6/blackpill_f411/config.h b/keyboards/handwired/dactyl_manuform/6x6/blackpill_f411/config.h index 2258a17c2e..191cd9b224 100644 --- a/keyboards/handwired/dactyl_manuform/6x6/blackpill_f411/config.h +++ b/keyboards/handwired/dactyl_manuform/6x6/blackpill_f411/config.h @@ -25,13 +25,6 @@ #define SERIAL_USART_RX_PIN B7 // USART RX pin #define SERIAL_USART_TX_PIN B6 // USART TX pin -#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5 - // 0: 460800 baud - // 1: 230400 baud (default) - // 2: 115200 baud - // 3: 57600 baud - // 4: 38400 baud - // 5: 19200 baud #define SERIAL_USART_DRIVER SD1 // USART driver of TX and RX pin. default: SD1 #define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7 #define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7 diff --git a/keyboards/handwired/myskeeb/config.h b/keyboards/handwired/myskeeb/config.h index 8c37524a0e..d290d41aee 100644 --- a/keyboards/handwired/myskeeb/config.h +++ b/keyboards/handwired/myskeeb/config.h @@ -2,7 +2,6 @@ // Comunication and Split Detection -#define SELECT_SOFT_SERIAL_SPEED 1 #define SPLIT_USB_DETECT #define EE_HANDS #define SPLIT_USB_TIMEOUT 1000 diff --git a/keyboards/handwired/split65/promicro/config.h b/keyboards/handwired/split65/promicro/config.h index f5c5ee3be2..e6a8650b9b 100644 --- a/keyboards/handwired/split65/promicro/config.h +++ b/keyboards/handwired/split65/promicro/config.h @@ -15,8 +15,6 @@ */ #pragma once -#define SELECT_SOFT_SERIAL_SPEED 1 - // Feature diable options //#define NO_DEBUG //#define NO_PRINT diff --git a/keyboards/handwired/split65/stm32/config.h b/keyboards/handwired/split65/stm32/config.h index 3d48891e7e..bf84e29fba 100644 --- a/keyboards/handwired/split65/stm32/config.h +++ b/keyboards/handwired/split65/stm32/config.h @@ -21,7 +21,6 @@ #define AUDIO_PIN_ALT A4 #define AUDIO_PIN_ALT_AS_NEGATIVE -#define SELECT_SOFT_SERIAL_SPEED 1 #define SERIAL_USART_DRIVER SD1 #define SERIAL_USART_TX_PAL_MODE 7 #define SERIAL_USART_TIMEOUT 100 diff --git a/keyboards/manta60/config.h b/keyboards/manta60/config.h index 3f0a8cf4e1..01a48cb684 100644 --- a/keyboards/manta60/config.h +++ b/keyboards/manta60/config.h @@ -17,8 +17,6 @@ along with this program. If not, see . #pragma once -#define SELECT_SOFT_SERIAL_SPEED 1 - # ifndef IOS_DEVICE_ENABLE # define RGBLIGHT_VAL_STEP 16 # define RGBLIGHT_LIMIT_VAL 128 /* The maximum brightness level */ diff --git a/keyboards/momoka_ergo/config.h b/keyboards/momoka_ergo/config.h index dbd81b1213..6a401e3906 100644 --- a/keyboards/momoka_ergo/config.h +++ b/keyboards/momoka_ergo/config.h @@ -17,7 +17,5 @@ along with this program. If not, see . #pragma once -#define SELECT_SOFT_SERIAL_SPEED 5 - #define SPLIT_USB_DETECT #define EE_HANDS diff --git a/keyboards/momoka_ergo/keyboard.json b/keyboards/momoka_ergo/keyboard.json index 3b2ba6664f..3430932625 100644 --- a/keyboards/momoka_ergo/keyboard.json +++ b/keyboards/momoka_ergo/keyboard.json @@ -28,7 +28,8 @@ "split": { "enabled": true, "serial": { - "pin": "D1" + "pin": "D1", + "speed": 5 } }, "rgblight": { diff --git a/keyboards/omkbd/ergodash/mini/config.h b/keyboards/omkbd/ergodash/mini/config.h index 12b408ff56..373c238afd 100644 --- a/keyboards/omkbd/ergodash/mini/config.h +++ b/keyboards/omkbd/ergodash/mini/config.h @@ -19,13 +19,3 @@ along with this program. If not, see . #pragma once #define AUDIO_PIN C6 - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/ergodash/rev1/config.h b/keyboards/omkbd/ergodash/rev1/config.h index 12b408ff56..373c238afd 100644 --- a/keyboards/omkbd/ergodash/rev1/config.h +++ b/keyboards/omkbd/ergodash/rev1/config.h @@ -19,13 +19,3 @@ along with this program. If not, see . #pragma once #define AUDIO_PIN C6 - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/3x6/config.h b/keyboards/omkbd/runner3680/3x6/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/3x6/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/3x7/config.h b/keyboards/omkbd/runner3680/3x7/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/3x7/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/3x8/config.h b/keyboards/omkbd/runner3680/3x8/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/3x8/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/4x6/config.h b/keyboards/omkbd/runner3680/4x6/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/4x6/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/4x7/config.h b/keyboards/omkbd/runner3680/4x7/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/4x7/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/4x8/config.h b/keyboards/omkbd/runner3680/4x8/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/4x8/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/5x6/config.h b/keyboards/omkbd/runner3680/5x6/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/5x6/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/5x6_5x8/config.h b/keyboards/omkbd/runner3680/5x6_5x8/config.h deleted file mode 100644 index b6f3f5ff86..0000000000 --- a/keyboards/omkbd/runner3680/5x6_5x8/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2021 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/5x7/config.h b/keyboards/omkbd/runner3680/5x7/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/5x7/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/omkbd/runner3680/5x8/config.h b/keyboards/omkbd/runner3680/5x8/config.h deleted file mode 100644 index 2b0210d2be..0000000000 --- a/keyboards/omkbd/runner3680/5x8/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2019 omkbd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define SELECT_SOFT_SERIAL_SPEED 1 -/*Sets the protocol speed when using serial communication*/ -//Speeds: -//0: about 189kbps (Experimental only) -//1: about 137kbps (default) -//2: about 75kbps -//3: about 39kbps -//4: about 26kbps -//5: about 20kbps diff --git a/keyboards/redox/rev1/proton_c/config.h b/keyboards/redox/rev1/proton_c/config.h index 4d28bd2f4a..b151d2b29e 100644 --- a/keyboards/redox/rev1/proton_c/config.h +++ b/keyboards/redox/rev1/proton_c/config.h @@ -13,13 +13,6 @@ #define SERIAL_USART_PIN_SWAP // Swap TX and RX pins if keyboard is master halve. // Check if this feature is necessary with your keyboard design and available on the mcu. -#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5 - // 0: 460800 baud - // 1: 230400 baud (default) - // 2: 115200 baud - // 3: 57600 baud - // 4: 38400 baud - // 5: 19200 baud #define SERIAL_USART_DRIVER SD1 // USART driver of TX and RX pin. default: SD1 #define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7 #define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7 diff --git a/keyboards/tkw/grandiceps/config.h b/keyboards/tkw/grandiceps/config.h index a02e14f91f..04c41e2a11 100644 --- a/keyboards/tkw/grandiceps/config.h +++ b/keyboards/tkw/grandiceps/config.h @@ -15,8 +15,6 @@ */ #pragma once -#define SELECT_SOFT_SERIAL_SPEED 1 - #define WS2812_PWM_DRIVER PWMD3 #define WS2812_PWM_CHANNEL 4 #define WS2812_PWM_PAL_MODE 2 diff --git a/keyboards/unikeyboard/diverge3/config.h b/keyboards/unikeyboard/diverge3/config.h index bdd2b7cbb2..c77a4f1d16 100644 --- a/keyboards/unikeyboard/diverge3/config.h +++ b/keyboards/unikeyboard/diverge3/config.h @@ -17,10 +17,6 @@ along with this program. If not, see . #pragma once -#ifndef SELECT_SOFT_SERIAL_SPEED -#define SELECT_SOFT_SERIAL_SPEED 3 -#endif - /* If defined, GRAVE_ESC will always act as ESC when CTRL is held. * This is useful for the Windows task manager shortcut (ctrl+shift+esc). */ diff --git a/keyboards/unikeyboard/diverge3/keyboard.json b/keyboards/unikeyboard/diverge3/keyboard.json index 187e5dead0..6a4813d115 100644 --- a/keyboards/unikeyboard/diverge3/keyboard.json +++ b/keyboards/unikeyboard/diverge3/keyboard.json @@ -34,7 +34,8 @@ "split": { "enabled": true, "serial": { - "pin": "D0" + "pin": "D0", + "speed": 3 } }, "development_board": "promicro", diff --git a/keyboards/zvecr/split_blackpill/config.h b/keyboards/zvecr/split_blackpill/config.h index efc3bbe66a..59582a9726 100644 --- a/keyboards/zvecr/split_blackpill/config.h +++ b/keyboards/zvecr/split_blackpill/config.h @@ -2,8 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once -#define SELECT_SOFT_SERIAL_SPEED 0 - #define WS2812_PWM_DRIVER PWMD3 #define WS2812_PWM_CHANNEL 1 #define WS2812_PWM_DMA_STREAM STM32_DMA1_STREAM3 diff --git a/keyboards/zvecr/split_blackpill/keyboard.json b/keyboards/zvecr/split_blackpill/keyboard.json index 407314b71a..2884b790d7 100644 --- a/keyboards/zvecr/split_blackpill/keyboard.json +++ b/keyboards/zvecr/split_blackpill/keyboard.json @@ -27,7 +27,8 @@ }, "serial": { "driver": "usart", - "pin": "B6" + "pin": "B6", + "speed": 0 }, "bootmagic": { "matrix": [4, 0] diff --git a/keyboards/zvecr/zv48/config.h b/keyboards/zvecr/zv48/config.h index 9e8c2656a9..ab9ca3355b 100644 --- a/keyboards/zvecr/zv48/config.h +++ b/keyboards/zvecr/zv48/config.h @@ -3,7 +3,6 @@ #pragma once -//#define SELECT_SOFT_SERIAL_SPEED 0 #define SERIAL_USART_SPEED 921600 #define WS2812_PWM_DRIVER PWMD3 diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index b4fa481b1b..f63228b2bc 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -477,6 +477,9 @@ def _extract_split_serial(info_data, config_c): if 'soft_serial_pin' in split: split['serial'] = split.get('serial', {}) split['serial']['pin'] = split.pop('soft_serial_pin') + if 'soft_serial_speed' in split: + split['serial'] = split.get('serial', {}) + split['serial']['speed'] = split.pop('soft_serial_speed') def _extract_split_transport(info_data, config_c): -- cgit v1.2.3 From cc696a2ae838a9639335ca8eb3cb3b794c06bc33 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 17 Aug 2025 01:14:48 +0100 Subject: Refactor battery driver (#25550) --- builddefs/build_test.mk | 1 + builddefs/common_features.mk | 14 ++-- builddefs/generic_features.mk | 1 + builddefs/testlist.mk | 1 + data/mappings/info_config.hjson | 8 ++ data/mappings/info_rules.hjson | 1 + data/schemas/keyboard.jsonschema | 22 +++++ docs/_sidebar.json | 1 + docs/drivers/battery.md | 69 ++++++--------- docs/features/battery.md | 55 ++++++++++++ docs/reference_info_json.md | 26 ++++++ drivers/battery/battery.c | 41 --------- drivers/battery/battery.h | 46 ---------- drivers/battery/battery_adc.c | 25 +++--- .../handwired/onekey/keymaps/battery/config.h | 2 +- .../handwired/onekey/keymaps/battery/keymap.c | 3 - .../handwired/onekey/keymaps/battery/keymap.json | 4 + .../handwired/onekey/keymaps/battery/rules.mk | 1 - keyboards/handwired/promethium/config.h | 2 - keyboards/handwired/promethium/keyboard.json | 7 ++ keyboards/handwired/promethium/rules.mk | 1 - quantum/battery/battery.c | 41 +++++++++ quantum/battery/battery.h | 46 ++++++++++ quantum/battery/tests/battery_tests.cpp | 97 ++++++++++++++++++++++ quantum/battery/tests/rules.mk | 7 ++ quantum/battery/tests/testlist.mk | 2 + quantum/keyboard.c | 6 +- quantum/quantum.h | 4 + 28 files changed, 374 insertions(+), 160 deletions(-) create mode 100644 docs/features/battery.md delete mode 100644 drivers/battery/battery.c delete mode 100644 drivers/battery/battery.h delete mode 100644 keyboards/handwired/onekey/keymaps/battery/rules.mk create mode 100644 quantum/battery/battery.c create mode 100644 quantum/battery/battery.h create mode 100644 quantum/battery/tests/battery_tests.cpp create mode 100644 quantum/battery/tests/rules.mk create mode 100644 quantum/battery/tests/testlist.mk (limited to 'docs/reference_info_json.md') diff --git a/builddefs/build_test.mk b/builddefs/build_test.mk index 0c5c98e2a3..ccdad1b4e7 100644 --- a/builddefs/build_test.mk +++ b/builddefs/build_test.mk @@ -62,6 +62,7 @@ include $(BUILDDEFS_PATH)/common_features.mk include $(BUILDDEFS_PATH)/generic_features.mk include $(PLATFORM_PATH)/common.mk include $(TMK_PATH)/protocol.mk +include $(QUANTUM_PATH)/battery/tests/rules.mk include $(QUANTUM_PATH)/debounce/tests/rules.mk include $(QUANTUM_PATH)/encoder/tests/rules.mk include $(QUANTUM_PATH)/os_detection/tests/rules.mk diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index c122afcff9..1da13997b5 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -945,21 +945,25 @@ ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes) endif endif +ifeq ($(strip $(BATTERY_ENABLE)), yes) + BATTERY_DRIVER_REQUIRED := yes +endif + VALID_BATTERY_DRIVER_TYPES := adc custom vendor -BATTERY_DRIVER ?= adc +BATTERY_DRIVER ?= none ifeq ($(strip $(BATTERY_DRIVER_REQUIRED)), yes) ifeq ($(filter $(BATTERY_DRIVER),$(VALID_BATTERY_DRIVER_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid BATTERY_DRIVER,BATTERY_DRIVER="$(BATTERY_DRIVER)" is not a valid battery driver) endif - OPT_DEFS += -DBATTERY_DRIVER - OPT_DEFS += -DBATTERY_$(strip $(shell echo $(BATTERY_DRIVER) | tr '[:lower:]' '[:upper:]')) + OPT_DEFS += -DBATTERY_DRIVER_$(strip $(shell echo $(BATTERY_DRIVER) | tr '[:lower:]' '[:upper:]')) COMMON_VPATH += $(DRIVER_PATH)/battery - SRC += battery.c - SRC += battery_$(strip $(BATTERY_DRIVER)).c + ifneq ($(strip $(BATTERY_DRIVER)), custom) + SRC += battery_$(strip $(BATTERY_DRIVER)).c + endif # add extra deps ifeq ($(strip $(BATTERY_DRIVER)), adc) diff --git a/builddefs/generic_features.mk b/builddefs/generic_features.mk index c826514431..6d394977bd 100644 --- a/builddefs/generic_features.mk +++ b/builddefs/generic_features.mk @@ -21,6 +21,7 @@ SPACE_CADET_ENABLE ?= yes GENERIC_FEATURES = \ AUTO_SHIFT \ AUTOCORRECT \ + BATTERY \ BOOTMAGIC \ CAPS_WORD \ COMBO \ diff --git a/builddefs/testlist.mk b/builddefs/testlist.mk index 74a794adcd..2e81fe576b 100644 --- a/builddefs/testlist.mk +++ b/builddefs/testlist.mk @@ -1,6 +1,7 @@ TEST_LIST = $(sort $(patsubst %/test.mk,%, $(shell find $(ROOT_DIR)tests -type f -name test.mk))) FULL_TESTS := $(notdir $(TEST_LIST)) +include $(QUANTUM_PATH)/battery/tests/testlist.mk include $(QUANTUM_PATH)/debounce/tests/testlist.mk include $(QUANTUM_PATH)/encoder/tests/testlist.mk include $(QUANTUM_PATH)/os_detection/tests/testlist.mk diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index a160e490c7..4c53aa4339 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson @@ -43,6 +43,14 @@ "BOOTMAGIC_ROW": {"info_key": "bootmagic.matrix.0", "value_type": "int"}, "BOOTMAGIC_ROW_RIGHT": {"info_key": "split.bootmagic.matrix.0", "value_type": "int"}, + // Battery + "BATTERY_SAMPLE_INTERVAL": {"info_key": "battery.sample_interval", "value_type": "int"}, + "BATTERY_ADC_PIN": {"info_key": "battery.adc.pin"}, + "BATTERY_ADC_REF_VOLTAGE_MV": {"info_key": "battery.adc.reference_voltage", "value_type": "int"}, + "BATTERY_ADC_VOLTAGE_DIVIDER_R1": {"info_key": "battery.adc.divider_r1", "value_type": "int"}, + "BATTERY_ADC_VOLTAGE_DIVIDER_R2": {"info_key": "battery.adc.divider_r2", "value_type": "int"}, + "BATTERY_ADC_RESOLUTION": {"info_key": "battery.adc.resolution", "value_type": "int"}, + // Caps Word "BOTH_SHIFTS_TURNS_ON_CAPS_WORD": {"info_key": "caps_word.both_shifts_turns_on", "value_type": "flag"}, "CAPS_WORD_IDLE_TIMEOUT": {"info_key": "caps_word.idle_timeout", "value_type": "int"}, diff --git a/data/mappings/info_rules.hjson b/data/mappings/info_rules.hjson index d43d83c3ea..5ecd5c12b3 100644 --- a/data/mappings/info_rules.hjson +++ b/data/mappings/info_rules.hjson @@ -13,6 +13,7 @@ "AUDIO_DRIVER": {"info_key": "audio.driver"}, "BACKLIGHT_DRIVER": {"info_key": "backlight.driver"}, + "BATTERY_DRIVER": {"info_key": "battery.driver"}, "BLUETOOTH_DRIVER": {"info_key": "bluetooth.driver"}, "BOARD": {"info_key": "board"}, "BOOTLOADER": {"info_key": "bootloader", "warn_duplicate": false}, diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 3775b66c1a..93b1c82b1c 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -188,6 +188,28 @@ "as_caps_lock": {"type": "boolean"} } }, + "battery": { + "type": "object", + "additionalProperties": false, + "properties": { + "driver": { + "type": "string", + "enum": ["adc", "custom", "vendor"] + }, + "adc": { + "type": "object", + "additionalProperties": false, + "properties": { + "pin": {"$ref": "./definitions.jsonschema#/mcu_pin"}, + "reference_voltage": {"type": "integer"}, + "divider_r1": {"type": "integer"}, + "divider_r2": {"type": "integer"}, + "resolution": {"type": "integer"} + } + }, + "sample_interval": {"type": "integer"} + } + }, "bluetooth": { "type": "object", "additionalProperties": false, diff --git a/docs/_sidebar.json b/docs/_sidebar.json index ee4709a650..eec345b788 100644 --- a/docs/_sidebar.json +++ b/docs/_sidebar.json @@ -175,6 +175,7 @@ ] }, { "text": "Audio", "link": "/features/audio" }, + { "text": "Battery", "link": "/features/battery" }, { "text": "Bootmagic", "link": "/features/bootmagic" }, { "text": "Converters", "link": "/feature_converters" }, { "text": "Custom Matrix", "link": "/custom_matrix" }, diff --git a/docs/drivers/battery.md b/docs/drivers/battery.md index e482ffc8b6..ae07668cc0 100644 --- a/docs/drivers/battery.md +++ b/docs/drivers/battery.md @@ -1,6 +1,6 @@ # Battery Driver -This driver provides support for sampling battery level. +This driver provides support for directly sampling battery level. ## Usage @@ -10,21 +10,17 @@ To use this driver, add the following to your `rules.mk`: BATTERY_DRIVER_REQUIRED = yes ``` -## Basic Configuration {#basic-configuration} - -Add the following to your `config.h`: - -|Define |Default |Description | -|--------------------------|--------|--------------------------------------------------| -|`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. | +::::info Note +This is already configured for you if you are using the [Battery](../features/battery) feature. +:::: ## Driver Configuration {#driver-configuration} -Driver selection can be configured in `rules.mk` as `BATTERY_DRIVER`. Valid values are `adc` (default), `vendor`, or `custom`. See below for information on individual drivers. +Driver selection can be configured in `rules.mk` as `BATTERY_DRIVER`. Valid values are `adc`, `vendor`, or `custom`. See below for information on individual drivers. ### ADC Driver {#adc-driver} -This is the default battery driver. The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider. +The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider. ```make BATTERY_DRIVER = adc @@ -32,42 +28,25 @@ BATTERY_DRIVER = adc The following `#define`s apply only to the `adc` driver: -|Define |Default |Description | -|-----------------------------|--------------|--------------------------------------------------------------| -|`BATTERY_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. | -|`BATTERY_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. | -|`BATTERY_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | -|`BATTERY_VOLTAGE_DIVIDER_R2` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | -|`BATTERY_ADC_RESOLUTION` |`10` |The ADC resolution configured for the ADC Driver. | - -## Functions - -### `uint8_t battery_get_percent(void)` {#api-battery-get-percent} - -Sample battery level. - -#### Return Value {#api-battery-get-percent-return} - -The battery percentage, in the range 0-100. +|Define |Default |Description | +|---------------------------------|--------------|--------------------------------------------------------------| +|`BATTERY_ADC_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. | +|`BATTERY_ADC_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. | +|`BATTERY_ADC_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | +|`BATTERY_ADC_VOLTAGE_DIVIDER_R2` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | +|`BATTERY_ADC_RESOLUTION` |`10` |The ADC resolution configured for the ADC Driver. | -## Callbacks +### Custom Driver {#custom-driver} -### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user} +A custom driver is expected to implement the following interface: -User hook called when battery level changed. +```c +void battery_driver_init(void) { + // Perform any initialisation here +} -### Arguments {#api-battery-percent-changed-user-arguments} - - - `uint8_t level` - The battery percentage, in the range 0-100. - ---- - -### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb} - -Keyboard hook called when battery level changed. - -### Arguments {#api-battery-percent-changed-kb-arguments} - - - `uint8_t level` - The battery percentage, in the range 0-100. +uint8_t battery_driver_sample_percent(void) { + // Read and return current state here + return value; +} +``` diff --git a/docs/features/battery.md b/docs/features/battery.md new file mode 100644 index 0000000000..f5c725efb9 --- /dev/null +++ b/docs/features/battery.md @@ -0,0 +1,55 @@ +# Battery + +This feature provides the high level abstraction for sampling battery level. + +## Usage + +To use this driver, add the following to your `rules.mk`: + +```make +BATTERY_ENABLE = yes +``` + +## Basic Configuration {#basic-configuration} + +Add the following to your `config.h`: + +|Define |Default |Description | +|--------------------------|--------|--------------------------------------------------| +|`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. | + +## Driver Configuration {#driver-configuration} + +See the [Battery Driver](../drivers/battery) documentation for more information. + +## Functions + +### `uint8_t battery_get_percent(void)` {#api-battery-get-percent} + +Sample battery level. + +#### Return Value {#api-battery-get-percent-return} + +The battery percentage, in the range 0-100. + +## Callbacks + +### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user} + +User hook called when battery level changed. + +### Arguments {#api-battery-percent-changed-user-arguments} + + - `uint8_t level` + The battery percentage, in the range 0-100. + +--- + +### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb} + +Keyboard hook called when battery level changed. + +### Arguments {#api-battery-percent-changed-kb-arguments} + + - `uint8_t level` + The battery percentage, in the range 0-100. diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index cf22317613..84377ef36c 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -179,6 +179,32 @@ Configures the [Backlight](features/backlight) feature. * `pins` Array: Pin * A list of GPIO pins connected to the backlight LEDs (`software` and `timer` drivers only). +## Battery + +Configures the [Battery](features/battery) feature. + +* `battery` + * `adc` + * `pin` Pin Required + * The GPIO pin connected to the voltage divider. + * `reference_voltage` Number + * The ADC reverence voltage, in millivolts. + * Default: `3300` + * `divider_r1` Number + * The voltage divider resistance, in kOhm. Set to 0 to disable. + * Default: `100` + * `divider_r2` Number + * The voltage divider resistance, in kOhm. Set to 0 to disable. + * Default: `100` + * `resolution` Number + * The ADC resolution configured for the ADC Driver. + * Default: `10` + * `driver` String Required + * The driver to use. Must be one of `adc`, `custom`, `vendor`. + * `sample_interval` Number + * The delay between sampling the battery in milliseconds. + * Default: `30000` (30 s) + ## Wireless/Bluetooth {#bluetooth} Configures the [Wireless](features/wireless) feature. diff --git a/drivers/battery/battery.c b/drivers/battery/battery.c deleted file mode 100644 index faf3c5a214..0000000000 --- a/drivers/battery/battery.c +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2025 QMK -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "battery_driver.h" -#include "battery.h" -#include "timer.h" - -#ifndef BATTERY_SAMPLE_INTERVAL -# define BATTERY_SAMPLE_INTERVAL 30000 -#endif - -static uint8_t last_bat_level = 100; - -void battery_init(void) { - battery_driver_init(); - - last_bat_level = battery_driver_sample_percent(); -} - -__attribute__((weak)) void battery_percent_changed_user(uint8_t level) {} -__attribute__((weak)) void battery_percent_changed_kb(uint8_t level) {} - -static void handle_percent_changed(void) { - battery_percent_changed_user(last_bat_level); - battery_percent_changed_kb(last_bat_level); -} - -void battery_task(void) { - static uint32_t bat_timer = 0; - if (timer_elapsed32(bat_timer) > BATTERY_SAMPLE_INTERVAL) { - last_bat_level = battery_driver_sample_percent(); - - handle_percent_changed(); - - bat_timer = timer_read32(); - } -} - -uint8_t battery_get_percent(void) { - return last_bat_level; -} diff --git a/drivers/battery/battery.h b/drivers/battery/battery.h deleted file mode 100644 index 0985723eaa..0000000000 --- a/drivers/battery/battery.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2025 QMK -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include - -/** - * \file - * - * \defgroup battery Battery API - * - * \brief API to query battery status. - * \{ - */ - -/** - * \brief Initialize the battery driver. - */ -void battery_init(void); - -/** - * \brief Perform housekeeping tasks. - */ -void battery_task(void); - -/** - * \brief Sample battery level. - * - * \return The battery percentage, in the range 0-100. - */ -uint8_t battery_get_percent(void); - -/** - * \brief user hook called when battery level changed. - * - */ -void battery_percent_changed_user(uint8_t level); - -/** - * \brief keyboard hook called when battery level changed. - * - */ -void battery_percent_changed_kb(uint8_t level); - -/** \} */ diff --git a/drivers/battery/battery_adc.c b/drivers/battery/battery_adc.c index cf0e69cb48..145265b5db 100644 --- a/drivers/battery/battery_adc.c +++ b/drivers/battery/battery_adc.c @@ -1,23 +1,24 @@ // Copyright 2025 QMK // SPDX-License-Identifier: GPL-2.0-or-later +#include "battery_driver.h" #include "analog.h" #include "gpio.h" -#ifndef BATTERY_PIN -# error("BATTERY_PIN not configured!") +#ifndef BATTERY_ADC_PIN +# error("BATTERY_ADC_PIN not configured!") #endif -#ifndef BATTERY_REF_VOLTAGE_MV -# define BATTERY_REF_VOLTAGE_MV 3300 +#ifndef BATTERY_ADC_REF_VOLTAGE_MV +# define BATTERY_ADC_REF_VOLTAGE_MV 3300 #endif -#ifndef BATTERY_VOLTAGE_DIVIDER_R1 +#ifndef BATTERY_ADC_VOLTAGE_DIVIDER_R1 # define BATTERY_VOLTAGE_DIVIDER_R1 100 #endif -#ifndef BATTERY_VOLTAGE_DIVIDER_R2 -# define BATTERY_VOLTAGE_DIVIDER_R2 100 +#ifndef BATTERY_ADC_VOLTAGE_DIVIDER_R2 +# define BATTERY_ADC_VOLTAGE_DIVIDER_R2 100 #endif // TODO: infer from adc config? @@ -26,16 +27,16 @@ #endif void battery_driver_init(void) { - gpio_set_pin_input(BATTERY_PIN); + gpio_set_pin_input(BATTERY_ADC_PIN); } uint16_t battery_driver_get_mv(void) { - uint32_t raw = analogReadPin(BATTERY_PIN); + uint32_t raw = analogReadPin(BATTERY_ADC_PIN); - uint32_t bat_mv = raw * BATTERY_REF_VOLTAGE_MV / (1 << BATTERY_ADC_RESOLUTION); + uint32_t bat_mv = raw * BATTERY_ADC_REF_VOLTAGE_MV / (1 << BATTERY_ADC_RESOLUTION); -#if BATTERY_VOLTAGE_DIVIDER_R1 > 0 && BATTERY_VOLTAGE_DIVIDER_R2 > 0 - bat_mv = bat_mv * (BATTERY_VOLTAGE_DIVIDER_R1 + BATTERY_VOLTAGE_DIVIDER_R2) / BATTERY_VOLTAGE_DIVIDER_R2; +#if BATTERY_VOLTAGE_DIVIDER_R1 > 0 && BATTERY_ADC_VOLTAGE_DIVIDER_R2 > 0 + bat_mv = bat_mv * (BATTERY_VOLTAGE_DIVIDER_R1 + BATTERY_ADC_VOLTAGE_DIVIDER_R2) / BATTERY_ADC_VOLTAGE_DIVIDER_R2; #endif return bat_mv; diff --git a/keyboards/handwired/onekey/keymaps/battery/config.h b/keyboards/handwired/onekey/keymaps/battery/config.h index 8a1c05d436..b93bfe9000 100644 --- a/keyboards/handwired/onekey/keymaps/battery/config.h +++ b/keyboards/handwired/onekey/keymaps/battery/config.h @@ -3,4 +3,4 @@ #pragma once -#define BATTERY_PIN ADC_PIN +#define BATTERY_ADC_PIN ADC_PIN diff --git a/keyboards/handwired/onekey/keymaps/battery/keymap.c b/keyboards/handwired/onekey/keymaps/battery/keymap.c index 74191e83fc..793a6ed87e 100644 --- a/keyboards/handwired/onekey/keymaps/battery/keymap.c +++ b/keyboards/handwired/onekey/keymaps/battery/keymap.c @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include QMK_KEYBOARD_H -#include "battery.h" const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { LAYOUT_ortho_1x1(KC_A) @@ -14,8 +13,6 @@ void keyboard_post_init_user(void) { // debug_matrix=false; // debug_keyboard=true; // debug_mouse=false; - - battery_init(); } void housekeeping_task_user(void) { diff --git a/keyboards/handwired/onekey/keymaps/battery/keymap.json b/keyboards/handwired/onekey/keymaps/battery/keymap.json index c641dfe773..7232d6d899 100644 --- a/keyboards/handwired/onekey/keymaps/battery/keymap.json +++ b/keyboards/handwired/onekey/keymaps/battery/keymap.json @@ -1,6 +1,10 @@ { "config": { + "battery": { + "driver": "adc" + }, "features": { + "battery": true, "console": true } } diff --git a/keyboards/handwired/onekey/keymaps/battery/rules.mk b/keyboards/handwired/onekey/keymaps/battery/rules.mk deleted file mode 100644 index 06908179ae..0000000000 --- a/keyboards/handwired/onekey/keymaps/battery/rules.mk +++ /dev/null @@ -1 +0,0 @@ -BATTERY_DRIVER_REQUIRED = yes diff --git a/keyboards/handwired/promethium/config.h b/keyboards/handwired/promethium/config.h index 974a4f951f..c63d3eaead 100644 --- a/keyboards/handwired/promethium/config.h +++ b/keyboards/handwired/promethium/config.h @@ -64,8 +64,6 @@ along with this program. If not, see . #define PS2_MOUSE_INIT_DELAY 2000 -#define BATTERY_PIN B5 - #ifndef __ASSEMBLER__ // assembler doesn't like enum in .h file enum led_sequence { LED_IND_LINUX, diff --git a/keyboards/handwired/promethium/keyboard.json b/keyboards/handwired/promethium/keyboard.json index fa72908039..2e47bd186a 100644 --- a/keyboards/handwired/promethium/keyboard.json +++ b/keyboards/handwired/promethium/keyboard.json @@ -10,6 +10,12 @@ "ws2812": { "pin": "B5" }, + "battery": { + "driver": "adc", + "adc": { + "pin": "B5" + } + }, "bluetooth": { "driver": "bluefruit_le" }, @@ -22,6 +28,7 @@ "nkro": true, "ps2_mouse": true, "ps2": true, + "battery": true, "bluetooth": true }, "build": { diff --git a/keyboards/handwired/promethium/rules.mk b/keyboards/handwired/promethium/rules.mk index 4012f8ca29..ecadca399c 100644 --- a/keyboards/handwired/promethium/rules.mk +++ b/keyboards/handwired/promethium/rules.mk @@ -5,7 +5,6 @@ PS2_DRIVER = interrupt CUSTOM_MATRIX = yes WS2812_DRIVER_REQUIRED = yes -BATTERY_DRIVER_REQUIRED = yes SRC += rgbsps.c SRC += matrix.c diff --git a/quantum/battery/battery.c b/quantum/battery/battery.c new file mode 100644 index 0000000000..faf3c5a214 --- /dev/null +++ b/quantum/battery/battery.c @@ -0,0 +1,41 @@ +// Copyright 2025 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "battery_driver.h" +#include "battery.h" +#include "timer.h" + +#ifndef BATTERY_SAMPLE_INTERVAL +# define BATTERY_SAMPLE_INTERVAL 30000 +#endif + +static uint8_t last_bat_level = 100; + +void battery_init(void) { + battery_driver_init(); + + last_bat_level = battery_driver_sample_percent(); +} + +__attribute__((weak)) void battery_percent_changed_user(uint8_t level) {} +__attribute__((weak)) void battery_percent_changed_kb(uint8_t level) {} + +static void handle_percent_changed(void) { + battery_percent_changed_user(last_bat_level); + battery_percent_changed_kb(last_bat_level); +} + +void battery_task(void) { + static uint32_t bat_timer = 0; + if (timer_elapsed32(bat_timer) > BATTERY_SAMPLE_INTERVAL) { + last_bat_level = battery_driver_sample_percent(); + + handle_percent_changed(); + + bat_timer = timer_read32(); + } +} + +uint8_t battery_get_percent(void) { + return last_bat_level; +} diff --git a/quantum/battery/battery.h b/quantum/battery/battery.h new file mode 100644 index 0000000000..0985723eaa --- /dev/null +++ b/quantum/battery/battery.h @@ -0,0 +1,46 @@ +// Copyright 2025 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +/** + * \file + * + * \defgroup battery Battery API + * + * \brief API to query battery status. + * \{ + */ + +/** + * \brief Initialize the battery driver. + */ +void battery_init(void); + +/** + * \brief Perform housekeeping tasks. + */ +void battery_task(void); + +/** + * \brief Sample battery level. + * + * \return The battery percentage, in the range 0-100. + */ +uint8_t battery_get_percent(void); + +/** + * \brief user hook called when battery level changed. + * + */ +void battery_percent_changed_user(uint8_t level); + +/** + * \brief keyboard hook called when battery level changed. + * + */ +void battery_percent_changed_kb(uint8_t level); + +/** \} */ diff --git a/quantum/battery/tests/battery_tests.cpp b/quantum/battery/tests/battery_tests.cpp new file mode 100644 index 0000000000..ee011be8a8 --- /dev/null +++ b/quantum/battery/tests/battery_tests.cpp @@ -0,0 +1,97 @@ +// Copyright 2025 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +using testing::_; + +class BatteryDriverMock { + public: + virtual ~BatteryDriverMock() {} + + // mock methods + MOCK_METHOD0(battery_driver_init, void(void)); + MOCK_METHOD0(battery_driver_sample_percent, uint8_t(void)); + MOCK_METHOD1(battery_percent_changed_kb, void(uint8_t)); +}; + +class BatteryTest : public ::testing::Test { + public: + BatteryTest() { + _batteryDriverMock.reset(new ::testing::NiceMock()); + } + virtual ~BatteryTest() { + _batteryDriverMock.reset(); + } + + static std::unique_ptr _batteryDriverMock; +}; + +std::unique_ptr BatteryTest::_batteryDriverMock; + +extern "C" { +#include "quantum/battery/battery.h" +#include "timer.h" + +void advance_time(uint32_t ms); + +void battery_driver_init(void) { + if (BatteryTest::_batteryDriverMock) { + BatteryTest::_batteryDriverMock->battery_driver_init(); + } +} + +uint8_t battery_driver_sample_percent(void) { + if (BatteryTest::_batteryDriverMock) { + return BatteryTest::_batteryDriverMock->battery_driver_sample_percent(); + } + return 255; +} + +void battery_percent_changed_kb(uint8_t level) { + if (BatteryTest::_batteryDriverMock) { + BatteryTest::_batteryDriverMock->battery_percent_changed_kb(level); + } +} +} + +TEST_F(BatteryTest, TestInit) { + // init driver and initial sample + EXPECT_CALL(*_batteryDriverMock, battery_driver_init()).Times(1); + EXPECT_CALL(*_batteryDriverMock, battery_driver_sample_percent()).Times(1); + + battery_init(); +} + +TEST_F(BatteryTest, TestSampleCached) { + // sample before timeout + EXPECT_CALL(*_batteryDriverMock, battery_driver_sample_percent()).Times(0); + + advance_time(1); + battery_task(); +} + +TEST_F(BatteryTest, TestSampleNotCached) { + // sample after timeout + EXPECT_CALL(*_batteryDriverMock, battery_driver_sample_percent()).Times(1); + + advance_time(60000); + battery_task(); +} + +TEST_F(BatteryTest, TestGet) { + // sample does not directly sample + EXPECT_CALL(*_batteryDriverMock, battery_driver_sample_percent()).Times(0); + + battery_get_percent(); +} + +TEST_F(BatteryTest, TestChanged) { + // callbacks on value changed + EXPECT_CALL(*_batteryDriverMock, battery_percent_changed_kb(_)).Times(1); + + battery_task(); + advance_time(60000); + battery_task(); +} diff --git a/quantum/battery/tests/rules.mk b/quantum/battery/tests/rules.mk new file mode 100644 index 0000000000..86980f1020 --- /dev/null +++ b/quantum/battery/tests/rules.mk @@ -0,0 +1,7 @@ +VPATH += $(DRIVER_PATH)/battery + +battery_SRC := \ + $(PLATFORM_PATH)/timer.c \ + $(PLATFORM_PATH)/$(PLATFORM_KEY)/timer.c \ + $(QUANTUM_PATH)/battery/battery.c \ + $(QUANTUM_PATH)/battery/tests/battery_tests.cpp \ diff --git a/quantum/battery/tests/testlist.mk b/quantum/battery/tests/testlist.mk new file mode 100644 index 0000000000..e91da865a0 --- /dev/null +++ b/quantum/battery/tests/testlist.mk @@ -0,0 +1,2 @@ +TEST_LIST += \ + battery \ diff --git a/quantum/keyboard.c b/quantum/keyboard.c index bf4890a51d..173c696e2d 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -122,7 +122,7 @@ along with this program. If not, see . #ifdef SPLIT_KEYBOARD # include "split_util.h" #endif -#ifdef BATTERY_DRIVER +#ifdef BATTERY_ENABLE # include "battery.h" #endif #ifdef BLUETOOTH_ENABLE @@ -532,7 +532,7 @@ void keyboard_init(void) { // init after split init pointing_device_init(); #endif -#ifdef BATTERY_DRIVER +#ifdef BATTERY_ENABLE battery_init(); #endif #ifdef BLUETOOTH_ENABLE @@ -779,7 +779,7 @@ void keyboard_task(void) { joystick_task(); #endif -#ifdef BATTERY_DRIVER +#ifdef BATTERY_ENABLE battery_task(); #endif diff --git a/quantum/quantum.h b/quantum/quantum.h index 0036cd784b..176c8a292d 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -63,6 +63,10 @@ # include "bootmagic.h" #endif +#ifdef BATTERY_ENABLE +# include "battery.h" +#endif + #ifdef DEFERRED_EXEC_ENABLE # include "deferred_exec.h" #endif -- cgit v1.2.3