From 46b996a55e370b7c370dc0b092100a61121f9ddd Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 22 Nov 2023 11:14:34 +1100 Subject: [PATCH 1/4] CLI parallel search updates (#22525) --- lib/python/qmk/cli/ci/validate_aliases.py | 7 ++----- lib/python/qmk/cli/generate/api.py | 4 ++-- lib/python/qmk/commands.py | 4 ++-- lib/python/qmk/keyboard.py | 7 ++++++- lib/python/qmk/search.py | 17 ++++++++++++++--- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index a205d03cff9..7f781d43970 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py @@ -1,11 +1,8 @@ """Validates the list of keyboard aliases. """ -from pathlib import Path - from milc import cli -from qmk.json_schema import json_load -from qmk.keyboard import resolve_keyboard, keyboard_folder +from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions def _safe_keyboard_folder(target): @@ -34,7 +31,7 @@ def _target_keyboard_exists(target): @cli.subcommand('Validates the list of keyboard aliases.', hidden=True) def ci_validate_aliases(cli): - aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) + aliases = keyboard_alias_definitions() success = True for alias in aliases.keys(): diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 61a2f9f7329..1948b483a13 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -10,7 +10,7 @@ from qmk.datetime import current_datetime from qmk.info import info_json from qmk.json_schema import json_load from qmk.keymap import list_keymaps -from qmk.keyboard import find_readme, list_keyboards +from qmk.keyboard import find_readme, list_keyboards, keyboard_alias_definitions from qmk.keycodes import load_spec, list_versions, list_languages DATA_PATH = Path('data') @@ -166,7 +166,7 @@ def generate_api(cli): # Generate data for the global files keyboard_list = sorted(kb_all) - keyboard_aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) + keyboard_aliases = keyboard_alias_definitions() keyboard_metadata = { 'last_updated': current_datetime(), 'keyboards': keyboard_list, diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index e5fdbc4f300..519cb4c708e 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -3,12 +3,12 @@ import os import sys import shutil -from pathlib import Path from milc import cli import jsonschema from qmk.json_schema import json_load, validate +from qmk.keyboard import keyboard_alias_definitions def find_make(): @@ -53,7 +53,7 @@ def parse_configurator_json(configurator_file): exit(1) keyboard = user_keymap['keyboard'] - aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) + aliases = keyboard_alias_definitions() while keyboard in aliases: last_keyboard = keyboard diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index 4e525731f74..34257bee8d6 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -70,6 +70,11 @@ class AllKeyboards: base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep +@lru_cache(maxsize=1) +def keyboard_alias_definitions(): + return json_load(Path('data/mappings/keyboard_aliases.hjson')) + + def is_all_keyboards(keyboard): """Returns True if the keyboard is an AllKeyboards object. """ @@ -112,7 +117,7 @@ def keyboard_folder(keyboard): This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. """ - aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) + aliases = keyboard_alias_definitions() while keyboard in aliases: last_keyboard = keyboard diff --git a/lib/python/qmk/search.py b/lib/python/qmk/search.py index 1140abe69df..9b8bb430b5e 100644 --- a/lib/python/qmk/search.py +++ b/lib/python/qmk/search.py @@ -6,7 +6,7 @@ import fnmatch import logging import re from typing import List, Tuple -from dotty_dict import dotty +from dotty_dict import dotty, Dotty from milc import cli from qmk.util import parallel_map @@ -107,13 +107,22 @@ def expand_keymap_targets(targets: List[Tuple[str, str]]) -> List[Tuple[str, str return list(sorted(set(overall_targets))) +def _construct_build_target_kb_km(e): + return KeyboardKeymapBuildTarget(keyboard=e[0], keymap=e[1]) + + +def _construct_build_target_kb_km_json(e): + return KeyboardKeymapBuildTarget(keyboard=e[0], keymap=e[1], json=e[2]) + + def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str] = []) -> List[BuildTarget]: """Filter a list of (keyboard, keymap) tuples based on the supplied filters. Optionally includes the values of the queried info.json keys. """ if len(filters) == 0: - targets = [KeyboardKeymapBuildTarget(keyboard=kb, keymap=km) for kb, km in target_list] + cli.log.info('Preparing target list...') + targets = list(parallel_map(_construct_build_target_kb_km, target_list)) else: cli.log.info('Parsing data for all matching keyboard/keymap combinations...') valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in parallel_map(_load_keymap_info, target_list)] @@ -172,7 +181,9 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str cli.log.warning(f'Unrecognized filter expression: {filter_expr}') continue - targets = [KeyboardKeymapBuildTarget(keyboard=e[0], keymap=e[1], json=e[2]) for e in valid_keymaps] + cli.log.info('Preparing target list...') + valid_keymaps = [(e[0], e[1], e[2].to_dict() if isinstance(e[2], Dotty) else e[2]) for e in valid_keymaps] # need to convert dotty_dict back to dict because it doesn't survive parallelisation + targets = list(parallel_map(_construct_build_target_kb_km_json, list(valid_keymaps))) return targets From 7ae826476e782ff80ac94d4211bb9f7bb6c42040 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 22 Nov 2023 00:41:19 +0000 Subject: [PATCH 2/4] Move BACKLIGHT_PWM_PERIOD to correct docs section (#22480) --- docs/feature_backlight.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md index 89916aa8134..69391fcefe9 100644 --- a/docs/feature_backlight.md +++ b/docs/feature_backlight.md @@ -40,7 +40,6 @@ Add the following to your `config.h`: |`BACKLIGHT_DEFAULT_ON` |`true` |Enable backlight upon clearing the EEPROM | |`BACKLIGHT_DEFAULT_BREATHING`|`false` |Whether to enable backlight breathing upon clearing the EEPROM | |`BACKLIGHT_DEFAULT_LEVEL` |`BACKLIGHT_LEVELS`|The default backlight level to use upon clearing the EEPROM | -|`BACKLIGHT_PWM_PERIOD` |2048Hz |Defaults to `BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048`, which results in a PWM frequency of 2048Hz. | Unless you are designing your own keyboard, you generally should not need to change the `BACKLIGHT_PIN` or `BACKLIGHT_ON_STATE`. @@ -174,11 +173,13 @@ Depending on the ChibiOS board configuration, you may need to enable PWM at the The following `#define`s apply only to the `pwm` driver: -|Define |Default |Description | -|-----------------------|--------|-----------------------------------| -|`BACKLIGHT_PWM_DRIVER` |`PWMD4` |The PWM driver to use | -|`BACKLIGHT_PWM_CHANNEL`|`3` |The PWM channel to use | -|`BACKLIGHT_PAL_MODE` |`2` |The pin alternative function to use| +|Define |Default |Description | +|-----------------------|-------------|---------------------------------------------------------------| +|`BACKLIGHT_PWM_DRIVER` |`PWMD4` |The PWM driver to use | +|`BACKLIGHT_PWM_CHANNEL`|`3` |The PWM channel to use | +|`BACKLIGHT_PAL_MODE` |`2` |The pin alternative function to use | +|`BACKLIGHT_PWM_PERIOD` |*Not defined*|The PWM period in counter ticks - Default is platform dependent| + Refer to the ST datasheet for your particular MCU to determine these values. For example, these defaults are set up for pin `B8` on a Proton-C (STM32F303) using `TIM4_CH3` on AF2. Unless you are designing your own keyboard, you generally should not need to change them. From 0fcd13f55225c4545d828e1898c219ef3cae578f Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 22 Nov 2023 12:08:26 +1100 Subject: [PATCH 3/4] [CLI] Remove duplicates from search results (#22528) --- lib/python/qmk/build_targets.py | 11 +++++++++++ lib/python/qmk/search.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/build_targets.py b/lib/python/qmk/build_targets.py index fc720220499..16a7ef87a22 100644 --- a/lib/python/qmk/build_targets.py +++ b/lib/python/qmk/build_targets.py @@ -31,6 +31,17 @@ class BuildTarget: def __repr__(self): return f'BuildTarget(keyboard={self.keyboard}, keymap={self.keymap})' + def __eq__(self, __value: object) -> bool: + if not isinstance(__value, BuildTarget): + return False + return self.__repr__() == __value.__repr__() + + def __ne__(self, __value: object) -> bool: + return not self.__eq__(__value) + + def __hash__(self) -> int: + return self.__repr__().__hash__() + def configure(self, parallel: int = None, clean: bool = None, compiledb: bool = None) -> None: if parallel is not None: self._parallel = parallel diff --git a/lib/python/qmk/search.py b/lib/python/qmk/search.py index 9b8bb430b5e..84cf6cbe326 100644 --- a/lib/python/qmk/search.py +++ b/lib/python/qmk/search.py @@ -122,7 +122,7 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str """ if len(filters) == 0: cli.log.info('Preparing target list...') - targets = list(parallel_map(_construct_build_target_kb_km, target_list)) + targets = list(set(parallel_map(_construct_build_target_kb_km, target_list))) else: cli.log.info('Parsing data for all matching keyboard/keymap combinations...') valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in parallel_map(_load_keymap_info, target_list)] @@ -183,7 +183,7 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str cli.log.info('Preparing target list...') valid_keymaps = [(e[0], e[1], e[2].to_dict() if isinstance(e[2], Dotty) else e[2]) for e in valid_keymaps] # need to convert dotty_dict back to dict because it doesn't survive parallelisation - targets = list(parallel_map(_construct_build_target_kb_km_json, list(valid_keymaps))) + targets = list(set(parallel_map(_construct_build_target_kb_km_json, list(valid_keymaps)))) return targets From 3a5e4253fcfe840170df5ae1ce623ab72c942d70 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 22 Nov 2023 12:08:52 +1100 Subject: [PATCH 4/4] Add simpler method for relocating functions to RAM. (#21804) --- platforms/arm_atsam/_util.h | 9 +++++++++ platforms/avr/_util.h | 10 ++++++++++ platforms/chibios/_util.h | 9 +++++++++ quantum/util.h | 4 ++++ 4 files changed, 32 insertions(+) create mode 100644 platforms/arm_atsam/_util.h create mode 100644 platforms/avr/_util.h create mode 100644 platforms/chibios/_util.h diff --git a/platforms/arm_atsam/_util.h b/platforms/arm_atsam/_util.h new file mode 100644 index 00000000000..38aa9f44728 --- /dev/null +++ b/platforms/arm_atsam/_util.h @@ -0,0 +1,9 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define RESIDENT_IN_RAM(funcname) __attribute__((section(".ramfunc." #funcname), noinline)) funcname + +#if __has_include_next("_util.h") +# include_next "_util.h" +#endif diff --git a/platforms/avr/_util.h b/platforms/avr/_util.h new file mode 100644 index 00000000000..81b94896ba1 --- /dev/null +++ b/platforms/avr/_util.h @@ -0,0 +1,10 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +// AVR can't actually run anything from RAM, so just no-op the define. +#define RESIDENT_IN_RAM(funcname) funcname + +#if __has_include_next("_util.h") +# include_next "_util.h" +#endif diff --git a/platforms/chibios/_util.h b/platforms/chibios/_util.h new file mode 100644 index 00000000000..64eb62fa151 --- /dev/null +++ b/platforms/chibios/_util.h @@ -0,0 +1,9 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define RESIDENT_IN_RAM(funcname) __attribute__((section(".ram0_init." #funcname), noinline)) funcname + +#if __has_include_next("_util.h") +# include_next "_util.h" +#endif diff --git a/quantum/util.h b/quantum/util.h index 21e3487b282..94d9f223179 100644 --- a/quantum/util.h +++ b/quantum/util.h @@ -50,3 +50,7 @@ #if !defined(PACKED) # define PACKED __attribute__((__packed__)) #endif + +#if __has_include("_util.h") +# include "_util.h" /* Include the platform's _util.h */ +#endif