diff --git a/.clangd b/.clangd new file mode 100644 index 000000000000..2be2d817fc7c --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Add: [-Wno-unknown-attributes, -Wno-maybe-uninitialized, -Wno-unknown-warning-option] + Remove: [-W*, -mcall-prologues] + Compiler: clang diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000000..95eaa49252dd --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,46 @@ +core: + - quantum/**/* + - tmk_core/**/* + - drivers/**/* + - tests/**/* + - util/**/* + - platforms/**/* + - builddefs/**/* + - Makefile + - '*.mk' +dependencies: + - any: + - 'lib/**/*' + - '!lib/python/**/*' +keyboard: + - any: + - 'keyboards/**/*' + - '!keyboards/**/keymaps/**/*' +keymap: + - users/**/* + - layouts/**/* + - keyboards/**/keymaps/**/* +via: + - keyboards/**/keymaps/via/* +cli: + - requirements.txt + - lib/python/**/* +python: + - '**/*.py' +documentation: + - docs/**/* +translation: + - docs/fr-fr/**/* + - docs/es/**/* + - docs/ja/**/* + - docs/he-il/**/* + - docs/pt-br/**/* + - docs/zh-cn/**/* + - docs/de/**/* + - docs/ru-ru/**/* +CI: + - .github/**/* +dd: + - data/constants/**/* + - data/mappings/**/* + - data/schemas/**/* diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 78aaae8a0eb3..11b4a8a9f45d 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -19,13 +19,13 @@ jobs: lint: runs-on: ubuntu-latest - container: qmkfm/qmk_cli + container: ghcr.io/qmk/qmk_cli steps: - name: Disable safe.directory check run : git config --global --add safe.directory '*' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -35,7 +35,7 @@ jobs: - name: Get changed files id: file_changes - uses: tj-actions/changed-files@v35 + uses: tj-actions/changed-files@v38 - name: Run qmk formatters shell: 'bash {0}' diff --git a/.github/workflows/format_push.yml b/.github/workflows/format_push.yml deleted file mode 100644 index 67e70e10ca99..000000000000 --- a/.github/workflows/format_push.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Lint Format - -permissions: - contents: read - -on: - push: - paths-ignore: - - '**.md' - -jobs: - lint: - runs-on: ubuntu-latest - - container: qmkfm/qmk_cli - - steps: - - name: Disable safe.directory check - run : git config --global --add safe.directory '*' - - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Disable automatic eol conversion - run: | - echo "* -text" > .git/info/attributes - - - name: Install dependencies - run: | - pip3 install -r requirements-dev.txt - - - name: Run qmk formatters - shell: 'bash {0}' - run: | - qmk format-c -a - qmk format-python -a - qmk format-text -a - git diff - - - uses: rlespinasse/github-slug-action@v3.x - - - name: Become QMK Bot - run: | - git config user.name 'QMK Bot' - git config user.email 'hello@qmk.fm' - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - if: ${{ github.repository == 'qmk/qmk_firmware'}} - with: - token: ${{ secrets.QMK_BOT_TOKEN }} - delete-branch: true - branch: bugfix/format_${{ env.GITHUB_REF_SLUG }} - author: QMK Bot - committer: QMK Bot - commit-message: Format code according to conventions - title: '[CI] Format code according to conventions' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6b4e266bdea4..e0286b83fc43 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,13 +12,13 @@ jobs: lint: runs-on: ubuntu-latest - container: qmkfm/qmk_cli + container: ghcr.io/qmk/qmk_cli steps: - name: Disable safe.directory check run : git config --global --add safe.directory '*' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -27,7 +27,7 @@ jobs: - name: Get changed files id: file_changes - uses: tj-actions/changed-files@v35 + uses: tj-actions/changed-files@v38 - name: Print info run: | @@ -36,6 +36,7 @@ jobs: echo '${{ steps.file_changes.outputs.all_changed_files}}' - name: Run qmk lint + if: always() shell: 'bash {0}' run: | QMK_CHANGES=$(echo -e '${{ steps.file_changes.outputs.all_changed_files}}' | sed 's/ /\n/g') @@ -72,3 +73,32 @@ jobs: exit 255 fi exit $exit_code + + - name: Verify at most one added keyboard + if: always() + shell: 'bash {0}' + run: | + git reset --hard + git clean -xfd + + # Get the keyboard list and count for the target branch + git checkout -f ${{ github.base_ref }} + git pull --ff-only + QMK_KEYBOARDS_BASE=$(qmk list-keyboards) + QMK_KEYBOARDS_BASE_COUNT=$(qmk list-keyboards | wc -l) + + # Get the keyboard list and count for the PR + git checkout -f ${{ github.head_ref }} + git merge --no-commit --squash ${{ github.base_ref }} + QMK_KEYBOARDS_PR=$(qmk list-keyboards) + QMK_KEYBOARDS_PR_COUNT=$(qmk list-keyboards | wc -l) + + echo "::group::Keyboards changes in this PR" + diff -d -U 0 <(echo "$QMK_KEYBOARDS_BASE") <(echo "$QMK_KEYBOARDS_PR") | grep -vE '^(---|\+\+\+|@@)' | sed -e 's@^-@Removed: @g' -e 's@^+@ Added: @g' + echo "::endgroup::" + + if [[ $QMK_KEYBOARDS_PR_COUNT -gt $(($QMK_KEYBOARDS_BASE_COUNT + 1)) ]]; then + echo "More than one keyboard added in this PR -- see the PR Checklist." + echo "::error::More than one keyboard added in this PR -- see the PR Checklist." + exit 1 + fi diff --git a/.github/workflows/regen.yml b/.github/workflows/regen.yml deleted file mode 100644 index f301000d55e9..000000000000 --- a/.github/workflows/regen.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: PR Regenerate Files - -permissions: - contents: read - -on: - pull_request: - paths: - - 'data/constants/**' - - 'lib/python/**' - -jobs: - regen: - runs-on: ubuntu-latest - - container: qmkfm/qmk_cli - - steps: - - name: Disable safe.directory check - run : git config --global --add safe.directory '*' - - - uses: actions/checkout@v3 - - - name: Run qmk generators - run: | - util/regen.sh - git diff - - - name: Fail when regeneration required - run: | - git diff - for file in $(git diff --name-only); do - echo "File '${file}' Requires Regeneration" - echo "::error file=${file}::Requires Regeneration" - done - test -z "$(git diff --name-only)" diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index aecc34f5d4d1..718ea4a682ff 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -22,10 +22,10 @@ jobs: test: runs-on: ubuntu-latest - container: qmkfm/qmk_cli + container: ghcr.io/qmk/qmk_cli steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - name: Install dependencies diff --git a/.gitignore b/.gitignore index c3ddcf9bc473..9dab8709cc9b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,9 @@ quantum/version.h *.qmk *.uf2 +# DD config at wrong location +/keyboards/**/keymaps/*/info.json + # Old-style QMK Makefiles /keyboards/**/Makefile @@ -45,7 +48,6 @@ quantum/version.h .idea/ .project .settings/ -.vagrant/ # ? .dep @@ -93,6 +95,7 @@ secrets.tar # Python things __pycache__ .python-version +.venv # Prerequisites for updating ChibiOS /util/fmpp* diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e283c8f98a3d..000000000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM qmkfm/qmk_cli - -VOLUME /qmk_firmware -WORKDIR /qmk_firmware - -CMD qmk compile -kb all -km default diff --git a/Makefile b/Makefile index c77eadf97d5d..9f2e4636a4b4 100644 --- a/Makefile +++ b/Makefile @@ -328,7 +328,7 @@ define PARSE_TEST ifeq ($$(TEST_NAME),all) MATCHED_TESTS := $$(TEST_LIST) else - MATCHED_TESTS := $$(foreach TEST, $$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME), $$(notdir $$(TEST))), $$(TEST),)) + MATCHED_TESTS := $$(foreach TEST, $$(TEST_LIST),$$(if $$(findstring x$$(TEST_NAME)x, x$$(notdir $$(TEST))x), $$(TEST),)) endif $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET)))) endef diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 49ee4e8355b1..000000000000 --- a/Vagrantfile +++ /dev/null @@ -1,95 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure(2) do |config| - # define a name instead of just 'default' - config.vm.define "qmk_firmware" - - # VMware/Virtualbox ( and also Hyperv/Parallels) 64 bit - config.vm.box = "generic/debian10" - - config.vm.synced_folder '.', '/vagrant' - - # This section allows you to customize the Virtualbox VM - # settings, ie showing the GUI or upping the memory - # or cores if desired - config.vm.provider "virtualbox" do |vb| - # Hide the VirtualBox GUI when booting the machine - vb.gui = false - # Uncomment the below lines if you want to program - # your Teensy via the VM rather than your host OS - #vb.customize ['modifyvm', :id, '--usb', 'on'] - #vb.customize ['usbfilter', 'add', '0', - # '--target', :id, - # '--name', 'teensy', - # '--vendorid', '0x16c0', - # '--productid','0x0478' - # ] - # Customize the amount of memory on the VM: - vb.memory = "512" - # Uncomment the below lines if you have time sync - # issues with make and incremental builds - #vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ] - end - - # This section allows you to customize the VMware VM - # settings, ie showing the GUI or upping the memory - # or cores if desired - config.vm.provider "vmware_workstation" do |vmw| - # Hide the VMware GUI when booting the machine - vmw.gui = false - - # Customize the amount of memory on the VM: - vmw.memory = "512" - end - - config.vm.provider "vmware_fusion" do |vmf| - # Hide the vmfare GUI when booting the machine - vmf.gui = false - - # Customize the amount of memory on the VM: - vmf.memory = "512" - end - - # Docker provider pulls from hub.docker.com respecting docker.image if - # config.vm.box is nil. In this case, we adhoc build util/vagrant/Dockerfile. - # Note that this bind-mounts from the current dir to - # /vagrant in the guest, so unless your UID is 1000 to match vagrant in the - # image, you'll need to: chmod -R a+rw . - config.vm.provider "docker" do |docker, override| - override.vm.box = nil - docker.build_dir = "util/vagrant" - docker.has_ssh = true - end - - # Unless we are running the docker container directly - # 1. run container detached on vm - # 2. attach on 'vagrant ssh' - ["virtualbox", "vmware_workstation", "vmware_fusion"].each do |type| - config.vm.provider type do |virt, override| - override.vm.provision "docker" do |d| - d.run "qmkfm/qmk_cli", - cmd: "tail -f /dev/null", - args: "--privileged -v /dev:/dev -v '/vagrant:/vagrant'" - end - - override.vm.provision "shell", inline: <<-SHELL - echo 'docker restart qmkfm-qmk_cli && exec docker exec -it qmkfm-qmk_cli /bin/bash -l' >> ~vagrant/.bashrc - SHELL - end - end - - config.vm.post_up_message = <<-EOT - - Log into the environment using 'vagrant ssh'. QMK directory synchronized with - host is located at /vagrant - To compile the .hex files use make command inside this directory, e.g. - cd /vagrant - make :default - - Examples: - make planck/ez:default:flash - make planck/ez:default - - EOT -end diff --git a/builddefs/build_full_test.mk b/builddefs/build_full_test.mk index 964ba773d48c..85ee0898ec2d 100644 --- a/builddefs/build_full_test.mk +++ b/builddefs/build_full_test.mk @@ -17,7 +17,6 @@ $(TEST)_INC := \ tests/test_common/common_config.h $(TEST)_SRC := \ - $(TMK_COMMON_SRC) \ $(QUANTUM_SRC) \ $(SRC) \ $(QUANTUM_PATH)/keymap_introspection.c \ @@ -31,7 +30,7 @@ $(TEST)_SRC := \ tests/test_common/test_logger.cpp \ $(patsubst $(ROOTDIR)/%,%,$(wildcard $(TEST_PATH)/*.cpp)) -$(TEST)_DEFS := $(TMK_COMMON_DEFS) $(OPT_DEFS) "-DKEYMAP_C=\"keymap.c\"" +$(TEST)_DEFS := $(OPT_DEFS) "-DKEYMAP_C=\"keymap.c\"" $(TEST)_CONFIG := $(TEST_PATH)/config.h diff --git a/builddefs/build_keyboard.mk b/builddefs/build_keyboard.mk index 7a5412ccd2be..e93ab97cc134 100644 --- a/builddefs/build_keyboard.mk +++ b/builddefs/build_keyboard.mk @@ -27,7 +27,11 @@ QMK_BIN ?= qmk # Set the filename for the final firmware binary KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD)) TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP) -KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD_FILESAFE) + +ifeq ($(strip $(DUMP_CI_METADATA)),yes) + $(info CI Metadata: KEYBOARD=$(KEYBOARD)) + $(info CI Metadata: KEYMAP=$(KEYMAP)) +endif # Force expansion TARGET := $(TARGET) @@ -39,7 +43,7 @@ endif # Object files and generated keymap directory # To put object files in current directory, use a dot (.), do NOT make # this an empty or blank macro! -KEYMAP_OUTPUT := $(BUILD_DIR)/obj_$(TARGET) +INTERMEDIATE_OUTPUT := $(BUILD_DIR)/obj_$(TARGET) ifdef SKIP_VERSION OPT_DEFS += -DSKIP_VERSION @@ -55,7 +59,7 @@ VERSION_H_FLAGS += --skip-git endif # Generate the board's version.h file. -$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS) -q -o $(KEYMAP_OUTPUT)/src/version.h) +$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS) -q -o $(INTERMEDIATE_OUTPUT)/src/version.h) # Determine which subfolders exist. KEYBOARD_FOLDER_PATH_1 := $(KEYBOARD) @@ -116,7 +120,7 @@ MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP) MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP) # Pull in rules from info.json -INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_rules.mk) +INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_rules.mk) include $(INFO_RULES_MK) # Check for keymap.json first, so we can regenerate keymap.c @@ -156,28 +160,28 @@ endif # Have we found a keymap.json? ifneq ("$(wildcard $(KEYMAP_JSON))", "") - KEYMAP_C := $(KEYMAP_OUTPUT)/src/keymap.c - KEYMAP_H := $(KEYMAP_OUTPUT)/src/config.h + KEYMAP_C := $(INTERMEDIATE_OUTPUT)/src/keymap.c + KEYMAP_H := $(INTERMEDIATE_OUTPUT)/src/config.h # Load the keymap-level rules.mk if exists -include $(KEYMAP_PATH)/rules.mk # Load any rules.mk content from keymap.json - INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --output $(KEYMAP_OUTPUT)/src/rules.mk $(KEYMAP_JSON)) + INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --output $(INTERMEDIATE_OUTPUT)/src/rules.mk $(KEYMAP_JSON)) include $(INFO_RULES_MK) # Add rules to generate the keymap files - indentation here is important -$(KEYMAP_OUTPUT)/src/keymap.c: $(KEYMAP_JSON) +$(INTERMEDIATE_OUTPUT)/src/keymap.c: $(KEYMAP_JSON) @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) $(eval CMD=$(QMK_BIN) json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON)) @$(BUILD_CMD) -$(KEYMAP_OUTPUT)/src/config.h: $(KEYMAP_JSON) +$(INTERMEDIATE_OUTPUT)/src/config.h: $(KEYMAP_JSON) @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) $(eval CMD=$(QMK_BIN) generate-config-h --quiet --output $(KEYMAP_H) $(KEYMAP_JSON)) @$(BUILD_CMD) -generated-files: $(KEYMAP_OUTPUT)/src/config.h $(KEYMAP_OUTPUT)/src/keymap.c +generated-files: $(INTERMEDIATE_OUTPUT)/src/config.h $(INTERMEDIATE_OUTPUT)/src/keymap.c endif @@ -318,25 +322,34 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_5)/info.json)","") INFO_JSON_FILES += $(KEYBOARD_PATH_5)/info.json endif -CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h -KEYBOARD_SRC += $(KEYBOARD_OUTPUT)/src/default_keyboard.c +CONFIG_H += $(INTERMEDIATE_OUTPUT)/src/info_config.h +KEYBOARD_SRC += $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c -$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) +$(INTERMEDIATE_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) - $(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h) + $(eval CMD=$(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_config.h) @$(BUILD_CMD) -$(KEYBOARD_OUTPUT)/src/default_keyboard.c: $(INFO_JSON_FILES) +$(INTERMEDIATE_OUTPUT)/src/default_keyboard.c: $(INFO_JSON_FILES) @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) - $(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.c) + $(eval CMD=$(QMK_BIN) generate-keyboard-c --quiet --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c) @$(BUILD_CMD) -$(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES) +$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES) @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) - $(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h) + $(eval CMD=$(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --include $(FOUND_KEYBOARD_H) --output $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h) @$(BUILD_CMD) -generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.c $(KEYBOARD_OUTPUT)/src/default_keyboard.h +generated-files: $(INTERMEDIATE_OUTPUT)/src/info_config.h $(INTERMEDIATE_OUTPUT)/src/default_keyboard.c $(INTERMEDIATE_OUTPUT)/src/default_keyboard.h + +generated-files: $(INTERMEDIATE_OUTPUT)/src/info_deps.d + +$(INTERMEDIATE_OUTPUT)/src/info_deps.d: + @$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD) + $(eval CMD=$(QMK_BIN) generate-make-dependencies -kb $(KEYBOARD) -km $(KEYMAP) -o $(INTERMEDIATE_OUTPUT)/src/info_deps.d) + @$(BUILD_CMD) + +-include $(INTERMEDIATE_OUTPUT)/src/info_deps.d .INTERMEDIATE : generated-files @@ -409,8 +422,7 @@ VPATH += $(KEYMAP_PATH) VPATH += $(USER_PATH) VPATH += $(KEYBOARD_PATHS) VPATH += $(COMMON_VPATH) -VPATH += $(KEYBOARD_OUTPUT)/src -VPATH += $(KEYMAP_OUTPUT)/src +VPATH += $(INTERMEDIATE_OUTPUT)/src include $(BUILDDEFS_PATH)/common_features.mk include $(BUILDDEFS_PATH)/generic_features.mk @@ -419,19 +431,17 @@ include $(PLATFORM_PATH)/common.mk SRC += $(patsubst %.c,%.clib,$(LIB_SRC)) SRC += $(patsubst %.c,%.clib,$(QUANTUM_LIB_SRC)) -SRC += $(TMK_COMMON_SRC) -OPT_DEFS += $(TMK_COMMON_DEFS) -EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS) -include $(PLATFORM_PATH)/$(PLATFORM_KEY)/bootloader.mk include $(PLATFORM_PATH)/$(PLATFORM_KEY)/platform.mk -include $(PLATFORM_PATH)/$(PLATFORM_KEY)/flash.mk ifneq ($(strip $(PROTOCOL)),) - include $(TMK_PATH)/protocol/$(strip $(shell echo $(PROTOCOL) | tr '[:upper:]' '[:lower:]')).mk +PROTOCOL_KEY = $(strip $(shell echo $(PROTOCOL) | tr '[:upper:]' '[:lower:]')) else - include $(TMK_PATH)/protocol/$(PLATFORM_KEY).mk +PROTOCOL_KEY = $(PLATFORM_KEY) endif +include $(TMK_PATH)/protocol/$(PROTOCOL_KEY)/$(PROTOCOL_KEY).mk # Setup definitions based on the selected MCU $(eval $(call add_qmk_prefix_defs,MCU_ORIG,MCU)) @@ -441,6 +451,14 @@ $(eval $(call add_qmk_prefix_defs,MCU_FAMILY,MCU_FAMILY)) $(eval $(call add_qmk_prefix_defs,MCU_SERIES,MCU_SERIES)) $(eval $(call add_qmk_prefix_defs,BOARD,BOARD)) +# Control whether intermediate file listings are generated +# e.g.: +# make handwired/onekey/blackpill_f411:default KEEP_INTERMEDIATES=yes +# cat .build/obj_handwired_onekey_blackpill_f411_default/quantum/quantum.i | sed -e 's@^#.*@@g' -e 's@^\s*//.*@@g' -e '/^\s*$/d' | clang-format +ifeq ($(strip $(KEEP_INTERMEDIATES)), yes) + OPT_DEFS += -save-temps=obj +endif + # TODO: remove this bodge? PROJECT_DEFS := $(OPT_DEFS) PROJECT_INC := $(VPATH) $(EXTRAINCDIRS) $(KEYBOARD_PATHS) @@ -449,17 +467,14 @@ PROJECT_CONFIG := $(CONFIG_H) CONFIG_H += $(POST_CONFIG_H) ALL_CONFIGS := $(PROJECT_CONFIG) $(CONFIG_H) -OUTPUTS := $(KEYMAP_OUTPUT) $(KEYBOARD_OUTPUT) -$(KEYMAP_OUTPUT)_SRC := $(SRC) -$(KEYMAP_OUTPUT)_DEFS := $(OPT_DEFS) \ --DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYBOARD_H=\"$(KEYBOARD_OUTPUT)/src/default_keyboard.h\" \ --DQMK_KEYMAP=\"$(KEYMAP)\" -DQMK_KEYMAP_H=\"$(KEYMAP).h\" -DQMK_KEYMAP_CONFIG_H=\"$(KEYMAP_PATH)/config.h\" -$(KEYMAP_OUTPUT)_INC := $(VPATH) $(EXTRAINCDIRS) -$(KEYMAP_OUTPUT)_CONFIG := $(CONFIG_H) -$(KEYBOARD_OUTPUT)_SRC := $(PLATFORM_SRC) -$(KEYBOARD_OUTPUT)_DEFS := $(PROJECT_DEFS) -$(KEYBOARD_OUTPUT)_INC := $(PROJECT_INC) -$(KEYBOARD_OUTPUT)_CONFIG := $(PROJECT_CONFIG) +OUTPUTS := $(INTERMEDIATE_OUTPUT) +$(INTERMEDIATE_OUTPUT)_SRC := $(SRC) $(PLATFORM_SRC) +$(INTERMEDIATE_OUTPUT)_DEFS := $(OPT_DEFS) \ + -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYBOARD_H=\"$(INTERMEDIATE_OUTPUT)/src/default_keyboard.h\" \ + -DQMK_KEYMAP=\"$(KEYMAP)\" -DQMK_KEYMAP_H=\"$(KEYMAP).h\" -DQMK_KEYMAP_CONFIG_H=\"$(KEYMAP_PATH)/config.h\" \ + $(PROJECT_DEFS) +$(INTERMEDIATE_OUTPUT)_INC := $(VPATH) $(EXTRAINCDIRS) $(PROJECT_INC) +$(INTERMEDIATE_OUTPUT)_CONFIG := $(CONFIG_H) $(PROJECT_CONFIG) # Default target. all: build check-size diff --git a/builddefs/build_test.mk b/builddefs/build_test.mk index 42305983739f..9eead77beabd 100644 --- a/builddefs/build_test.mk +++ b/builddefs/build_test.mk @@ -75,6 +75,10 @@ $(TEST)_SRC += \ tests/test_common/main.cpp \ $(QUANTUM_PATH)/logging/print.c +ifneq ($(strip $(INTROSPECTION_KEYMAP_C)),) +$(TEST)_DEFS += -DINTROSPECTION_KEYMAP_C=\"$(strip $(INTROSPECTION_KEYMAP_C))\" +endif + $(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) $(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) $(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS) diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 44dbda1fcfef..e9699af80fff 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -134,7 +134,7 @@ ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) SRC += $(QUANTUM_DIR)/mousekey.c endif -VALID_POINTING_DEVICE_DRIVER_TYPES := adns5050 adns9800 analog_joystick cirque_pinnacle_i2c cirque_pinnacle_spi paw3204 pmw3360 pmw3389 pimoroni_trackball custom +VALID_POINTING_DEVICE_DRIVER_TYPES := adns5050 adns9800 analog_joystick cirque_pinnacle_i2c cirque_pinnacle_spi paw3204 pmw3320 pmw3360 pmw3389 pimoroni_trackball custom ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes) ifeq ($(filter $(POINTING_DEVICE_DRIVER),$(VALID_POINTING_DEVICE_DRIVER_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid POINTING_DEVICE_DRIVER,POINTING_DEVICE_DRIVER="$(POINTING_DEVICE_DRIVER)" is not a valid pointing device type) @@ -213,10 +213,10 @@ else SRC += eeprom_driver.c eeprom_spi.c else ifeq ($(strip $(EEPROM_DRIVER)), legacy_stm32_flash) # STM32 Emulated EEPROM, backed by MCU flash (soon to be deprecated) - OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_STM32_FLASH_EMULATED + OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_LEGACY_EMULATED_FLASH COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash COMMON_VPATH += $(DRIVER_PATH)/flash - SRC += eeprom_driver.c eeprom_stm32.c flash_stm32.c + SRC += eeprom_driver.c eeprom_legacy_emulated_flash.c legacy_flash_ops.c else ifeq ($(strip $(EEPROM_DRIVER)), transient) # Transient EEPROM implementation -- no data storage but provides runtime area for it OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_TRANSIENT @@ -317,14 +317,10 @@ ifneq ($(strip $(FLASH_DRIVER)), none) endif RGBLIGHT_ENABLE ?= no -VALID_RGBLIGHT_TYPES := WS2812 APA102 custom - -ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes) - RGBLIGHT_DRIVER ?= custom -endif +VALID_RGBLIGHT_TYPES := ws2812 apa102 custom ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) - RGBLIGHT_DRIVER ?= WS2812 + RGBLIGHT_DRIVER ?= ws2812 ifeq ($(filter $(RGBLIGHT_DRIVER),$(VALID_RGBLIGHT_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid RGBLIGHT_DRIVER,RGBLIGHT_DRIVER="$(RGBLIGHT_DRIVER)" is not a valid RGB type) @@ -338,11 +334,11 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) RGB_KEYCODES_ENABLE := yes endif - ifeq ($(strip $(RGBLIGHT_DRIVER)), WS2812) + ifeq ($(strip $(RGBLIGHT_DRIVER)), ws2812) WS2812_DRIVER_REQUIRED := yes endif - ifeq ($(strip $(RGBLIGHT_DRIVER)), APA102) + ifeq ($(strip $(RGBLIGHT_DRIVER)), apa102) APA102_DRIVER_REQUIRED := yes endif @@ -352,8 +348,8 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) endif LED_MATRIX_ENABLE ?= no -VALID_LED_MATRIX_TYPES := IS31FL3731 IS31FL3742A IS31FL3743A IS31FL3745 IS31FL3746A CKLED2001 custom -# TODO: IS31FL3733 IS31FL3737 IS31FL3741 +VALID_LED_MATRIX_TYPES := is31fl3731 is31fl3742a is31fl3743a is31fl3745 is31fl3746a ckled2001 custom +# TODO: is31fl3733 is31fl3737 is31fl3741 ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),) @@ -367,48 +363,49 @@ endif COMMON_VPATH += $(QUANTUM_DIR)/led_matrix COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations/runners + POST_CONFIG_H += $(QUANTUM_DIR)/led_matrix/post_config.h SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c SRC += $(QUANTUM_DIR)/led_matrix/led_matrix.c SRC += $(QUANTUM_DIR)/led_matrix/led_matrix_drivers.c SRC += $(LIB_PATH)/lib8tion/lib8tion.c CIE1931_CURVE := yes - ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731) + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3731) OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3731-simple.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3742A) + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3742a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3742A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3743A) + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3743a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3743A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3745) + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3745) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3745 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3746A) + ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3746a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3746A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(LED_MATRIX_DRIVER)), CKLED2001) + ifeq ($(strip $(LED_MATRIX_DRIVER)), ckled2001) OPT_DEFS += -DCKLED2001 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led SRC += ckled2001-simple.c @@ -419,7 +416,7 @@ endif RGB_MATRIX_ENABLE ?= no -VALID_RGB_MATRIX_TYPES := AW20216 IS31FL3731 IS31FL3733 IS31FL3737 IS31FL3741 IS31FL3742A IS31FL3743A IS31FL3745 IS31FL3746A CKLED2001 WS2812 custom +VALID_RGB_MATRIX_TYPES := aw20216 is31fl3731 is31fl3733 is31fl3736 is31fl3737 is31fl3741 is31fl3742a is31fl3743a is31fl3745 is31fl3746a ckled2001 ws2812 custom ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) ifeq ($(filter $(RGB_MATRIX_DRIVER),$(VALID_RGB_MATRIX_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid RGB_MATRIX_DRIVER,RGB_MATRIX_DRIVER="$(RGB_MATRIX_DRIVER)" is not a valid matrix type) @@ -432,6 +429,7 @@ endif COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations/runners + POST_CONFIG_H += $(QUANTUM_DIR)/rgb_matrix/post_config.h SRC += $(QUANTUM_DIR)/color.c SRC += $(QUANTUM_DIR)/rgb_matrix/rgb_matrix.c SRC += $(QUANTUM_DIR)/rgb_matrix/rgb_matrix_drivers.c @@ -439,82 +437,89 @@ endif CIE1931_CURVE := yes RGB_KEYCODES_ENABLE := yes - ifeq ($(strip $(RGB_MATRIX_DRIVER)), AW20216) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), aw20216) OPT_DEFS += -DAW20216 -DSTM32_SPI -DHAL_USE_SPI=TRUE COMMON_VPATH += $(DRIVER_PATH)/led SRC += aw20216.c QUANTUM_LIB_SRC += spi_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3731) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3731) OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3731.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3733) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3733) OPT_DEFS += -DIS31FL3733 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3733.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3737) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3736) + OPT_DEFS += -DIS31FL3736 -DSTM32_I2C -DHAL_USE_I2C=TRUE + COMMON_VPATH += $(DRIVER_PATH)/led/issi + SRC += is31fl3736.c + QUANTUM_LIB_SRC += i2c_master.c + endif + + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3737) OPT_DEFS += -DIS31FL3737 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3737.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3741) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3741) OPT_DEFS += -DIS31FL3741 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31fl3741.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3742A) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3742a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3742A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3743A) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3743a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3743A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3745) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3745) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3745 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3746A) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), is31fl3746a) OPT_DEFS += -DIS31FLCOMMON -DIS31FL3746A -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led/issi SRC += is31flcommon.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), CKLED2001) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), ckled2001) OPT_DEFS += -DCKLED2001 -DSTM32_I2C -DHAL_USE_I2C=TRUE COMMON_VPATH += $(DRIVER_PATH)/led SRC += ckled2001.c QUANTUM_LIB_SRC += i2c_master.c endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), WS2812) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), ws2812) OPT_DEFS += -DWS2812 WS2812_DRIVER_REQUIRED := yes endif - ifeq ($(strip $(RGB_MATRIX_DRIVER)), APA102) + ifeq ($(strip $(RGB_MATRIX_DRIVER)), apa102) OPT_DEFS += -DAPA102 APA102_DRIVER_REQUIRED := yes endif @@ -558,23 +563,23 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) endif COMMON_VPATH += $(QUANTUM_DIR)/backlight + COMMON_VPATH += $(DRIVER_PATH)/backlight SRC += $(QUANTUM_DIR)/backlight/backlight.c SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c OPT_DEFS += -DBACKLIGHT_ENABLE - ifeq ($(strip $(BACKLIGHT_DRIVER)), custom) - OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER - else + ifneq ($(strip $(BACKLIGHT_DRIVER)), custom) SRC += $(QUANTUM_DIR)/backlight/backlight_driver_common.c - ifeq ($(strip $(BACKLIGHT_DRIVER)), pwm) - SRC += $(QUANTUM_DIR)/backlight/backlight_$(PLATFORM_KEY).c + + ifeq ($(strip $(BACKLIGHT_DRIVER)), software) + SRC += $(DRIVER_PATH)/backlight/backlight_software.c else - SRC += $(QUANTUM_DIR)/backlight/backlight_$(strip $(BACKLIGHT_DRIVER)).c + SRC += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/backlight_$(strip $(BACKLIGHT_DRIVER)).c endif endif endif -VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c vendor +VALID_WS2812_DRIVER_TYPES := bitbang custom i2c pwm spi vendor WS2812_DRIVER ?= bitbang ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes) @@ -584,15 +589,11 @@ ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes) OPT_DEFS += -DWS2812_DRIVER_$(strip $(shell echo $(WS2812_DRIVER) | tr '[:lower:]' '[:upper:]')) - ifeq ($(strip $(WS2812_DRIVER)), bitbang) - SRC += ws2812.c - else - SRC += ws2812_$(strip $(WS2812_DRIVER)).c + SRC += ws2812_$(strip $(WS2812_DRIVER)).c - ifeq ($(strip $(PLATFORM)), CHIBIOS) - ifeq ($(strip $(WS2812_DRIVER)), pwm) - OPT_DEFS += -DSTM32_DMA_REQUIRED=TRUE - endif + ifeq ($(strip $(PLATFORM)), CHIBIOS) + ifeq ($(strip $(WS2812_DRIVER)), pwm) + OPT_DEFS += -DSTM32_DMA_REQUIRED=TRUE endif endif @@ -724,18 +725,23 @@ ifeq ($(strip $(FNV_ENABLE)), yes) SRC += qmk_fnv_type_validation.c hash_32a.c hash_64a.c endif +VALID_HAPTIC_DRIVER_TYPES := drv2605l solenoid ifeq ($(strip $(HAPTIC_ENABLE)),yes) - COMMON_VPATH += $(DRIVER_PATH)/haptic + ifeq ($(filter $(HAPTIC_DRIVER),$(VALID_HAPTIC_DRIVER_TYPES)),) + $(call CATASTROPHIC_ERROR,Invalid HAPTIC_DRIVER,HAPTIC_DRIVER="$(HAPTIC_DRIVER)" is not a valid Haptic driver) + else + COMMON_VPATH += $(DRIVER_PATH)/haptic - ifneq ($(filter DRV2605L, $(HAPTIC_DRIVER)), ) - SRC += DRV2605L.c - QUANTUM_LIB_SRC += i2c_master.c - OPT_DEFS += -DDRV2605L - endif + ifeq ($(strip $(HAPTIC_DRIVER)), drv2605l) + SRC += drv2605l.c + QUANTUM_LIB_SRC += i2c_master.c + OPT_DEFS += -DHAPTIC_DRV2605L + endif - ifneq ($(filter SOLENOID, $(HAPTIC_DRIVER)), ) - SRC += solenoid.c - OPT_DEFS += -DSOLENOID_ENABLE + ifeq ($(strip $(HAPTIC_DRIVER)), solenoid) + SRC += solenoid.c + OPT_DEFS += -DHAPTIC_SOLENOID + endif endif endif @@ -745,19 +751,30 @@ ifeq ($(strip $(HD44780_ENABLE)), yes) SRC += hd44780.c endif -VALID_OLED_DRIVER_TYPES := SSD1306 custom -OLED_DRIVER ?= SSD1306 +VALID_OLED_DRIVER_TYPES := custom ssd1306 +OLED_DRIVER ?= ssd1306 +VALID_OLED_TRANSPORT_TYPES := i2c spi custom +OLED_TRANSPORT ?= i2c ifeq ($(strip $(OLED_ENABLE)), yes) ifeq ($(filter $(OLED_DRIVER),$(VALID_OLED_DRIVER_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid OLED_DRIVER,OLED_DRIVER="$(OLED_DRIVER)" is not a valid OLED driver) else - OPT_DEFS += -DOLED_ENABLE - COMMON_VPATH += $(DRIVER_PATH)/oled + ifeq ($(filter $(OLED_TRANSPORT),$(VALID_OLED_TRANSPORT_TYPES)),) + $(call CATASTROPHIC_ERROR,Invalid OLED_TRANSPORT,OLED_TRANSPORT="$(OLED_TRANSPORT)" is not a valid OLED transport) + else + OPT_DEFS += -DOLED_ENABLE + COMMON_VPATH += $(DRIVER_PATH)/oled + ifneq ($(strip $(OLED_DRIVER)), custom) + SRC += oled_driver.c + endif - OPT_DEFS += -DOLED_DRIVER_$(strip $(shell echo $(OLED_DRIVER) | tr '[:lower:]' '[:upper:]')) - ifeq ($(strip $(OLED_DRIVER)), SSD1306) - SRC += ssd1306_sh1106.c - QUANTUM_LIB_SRC += i2c_master.c + OPT_DEFS += -DOLED_TRANSPORT_$(strip $(shell echo $(OLED_TRANSPORT) | tr '[:lower:]' '[:upper:]')) + ifeq ($(strip $(OLED_TRANSPORT)), i2c) + QUANTUM_LIB_SRC += i2c_master.c + endif + ifeq ($(strip $(OLED_TRANSPORT)), spi) + QUANTUM_LIB_SRC += spi_master.c + endif endif endif endif @@ -773,13 +790,15 @@ endif ifeq ($(strip $(UCIS_ENABLE)), yes) OPT_DEFS += -DUCIS_ENABLE UNICODE_COMMON := yes - SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c + SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c \ + $(QUANTUM_DIR)/unicode/ucis.c endif ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) OPT_DEFS += -DUNICODEMAP_ENABLE UNICODE_COMMON := yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c + SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c \ + $(QUANTUM_DIR)/unicode/unicodemap.c endif ifeq ($(strip $(UNICODE_ENABLE)), yes) @@ -819,9 +838,9 @@ endif ifeq ($(strip $(PS2_MOUSE_ENABLE)), yes) PS2_ENABLE := yes + MOUSE_ENABLE := yes SRC += ps2_mouse.c OPT_DEFS += -DPS2_MOUSE_ENABLE - OPT_DEFS += -DMOUSE_ENABLE endif VALID_PS2_DRIVER_TYPES := busywait interrupt usart vendor @@ -890,7 +909,7 @@ ifeq ($(strip $(USBPD_ENABLE)), yes) endif BLUETOOTH_ENABLE ?= no -VALID_BLUETOOTH_DRIVER_TYPES := BluefruitLE RN42 custom +VALID_BLUETOOTH_DRIVER_TYPES := bluefruit_le custom rn42 ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) ifeq ($(filter $(strip $(BLUETOOTH_DRIVER)),$(VALID_BLUETOOTH_DRIVER_TYPES)),) $(call CATASTROPHIC_ERROR,Invalid BLUETOOTH_DRIVER,BLUETOOTH_DRIVER="$(BLUETOOTH_DRIVER)" is not a valid Bluetooth driver type) @@ -898,17 +917,19 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) OPT_DEFS += -DBLUETOOTH_ENABLE NO_USB_STARTUP_CHECK := yes COMMON_VPATH += $(DRIVER_PATH)/bluetooth - SRC += outputselect.c bluetooth.c + SRC += outputselect.c - ifeq ($(strip $(BLUETOOTH_DRIVER)), BluefruitLE) + ifeq ($(strip $(BLUETOOTH_DRIVER)), bluefruit_le) OPT_DEFS += -DBLUETOOTH_BLUEFRUIT_LE -DHAL_USE_SPI=TRUE + SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c SRC += $(DRIVER_PATH)/bluetooth/bluefruit_le.cpp QUANTUM_LIB_SRC += analog.c QUANTUM_LIB_SRC += spi_master.c endif - ifeq ($(strip $(BLUETOOTH_DRIVER)), RN42) + ifeq ($(strip $(BLUETOOTH_DRIVER)), rn42) OPT_DEFS += -DBLUETOOTH_RN42 -DHAL_USE_SERIAL=TRUE + SRC += $(DRIVER_PATH)/bluetooth/bluetooth.c SRC += $(DRIVER_PATH)/bluetooth/rn42.c QUANTUM_LIB_SRC += uart.c endif diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index 82ed1c0e1249..b6e1a93d5c53 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -152,6 +152,7 @@ endif # To produce a UF2 file in your build, add to your keyboard's rules.mk: # FIRMWARE_FORMAT = uf2 UF2CONV = $(TOP_DIR)/util/uf2conv.py +UF2CONV_ARGS ?= UF2_FAMILY ?= 0x0 # Compiler flags to generate dependency files. @@ -175,7 +176,7 @@ MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) # For a ChibiOS build, ensure that the board files have the hook overrides injected define BOARDSRC_INJECT_HOOKS -$(KEYBOARD_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): INIT_HOOK_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h +$(INTERMEDIATE_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): INIT_HOOK_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h endef $(foreach LOBJ, $(BOARDSRC), $(eval $(call BOARDSRC_INJECT_HOOKS,$(LOBJ)))) @@ -219,7 +220,7 @@ gccversion : @$(BUILD_CMD) %.uf2: %.elf - $(eval CMD=$(HEX) $< $(BUILD_DIR)/$(TARGET).tmp && $(UF2CONV) $(BUILD_DIR)/$(TARGET).tmp --output $@ --convert --family $(UF2_FAMILY) >/dev/null 2>&1) + $(eval CMD=$(HEX) $< $(BUILD_DIR)/$(TARGET).tmp && $(UF2CONV) $(UF2CONV_ARGS) $(BUILD_DIR)/$(TARGET).tmp --output $@ --convert --family $(UF2_FAMILY) >/dev/null 2>&1) #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" @$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD) @$(BUILD_CMD) diff --git a/builddefs/converters.mk b/builddefs/converters.mk index 17b1c3b6ee95..a3548afd609f 100644 --- a/builddefs/converters.mk +++ b/builddefs/converters.mk @@ -7,7 +7,12 @@ endif # TODO: opt in rather than assume everything uses a pro micro PIN_COMPATIBLE ?= promicro + +# Remove whitespace from any rule.mk provided vars +# - env cannot be overwritten but cannot have whitespace anyway +CONVERT_TO:=$(strip $(CONVERT_TO)) ifneq ($(CONVERT_TO),) + # stash so we can overwrite env provided vars if needed ACTIVE_CONVERTER=$(CONVERT_TO) @@ -23,13 +28,13 @@ ifneq ($(CONVERT_TO),) TARGET := $(TARGET)_$(CONVERT_TO) # Configure any defaults - OPT_DEFS += -DCONVERT_TO_$(strip $(shell echo $(CONVERT_TO) | tr '[:lower:]' '[:upper:]')) - OPT_DEFS += -DCONVERTER_TARGET=\"$(strip $(CONVERT_TO))\" + OPT_DEFS += -DCONVERT_TO_$(shell echo $(CONVERT_TO) | tr '[:lower:]' '[:upper:]') + OPT_DEFS += -DCONVERTER_TARGET=\"$(CONVERT_TO)\" OPT_DEFS += -DCONVERTER_ENABLED VPATH += $(CONVERTER) # Configure for "alias" - worst case it produces an idential define - OPT_DEFS += -DCONVERT_TO_$(strip $(shell echo $(ACTIVE_CONVERTER) | tr '[:lower:]' '[:upper:]')) + OPT_DEFS += -DCONVERT_TO_$(shell echo $(ACTIVE_CONVERTER) | tr '[:lower:]' '[:upper:]') # Finally run any converter specific logic include $(CONVERTER)/converter.mk diff --git a/builddefs/generic_features.mk b/builddefs/generic_features.mk index 5a1ef5c6f0a5..4e058dcd2659 100644 --- a/builddefs/generic_features.mk +++ b/builddefs/generic_features.mk @@ -32,6 +32,7 @@ GENERIC_FEATURES = \ KEY_OVERRIDE \ LEADER \ PROGRAMMABLE_BUTTON \ + REPEAT_KEY \ SECURE \ SPACE_CADET \ SWAP_HANDS \ diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk index 9723b45438a8..563d08988036 100644 --- a/builddefs/show_options.mk +++ b/builddefs/show_options.mk @@ -17,7 +17,7 @@ HARDWARE_OPTION_NAMES = \ BACKLIGHT_ENABLE \ BACKLIGHT_DRIVER \ RGBLIGHT_ENABLE \ - RGBLIGHT_CUSTOM_DRIVER \ + RGBLIGHT_DRIVER \ RGB_MATRIX_ENABLE \ RGB_MATRIX_DRIVER \ CIE1931_CURVE \ @@ -60,7 +60,6 @@ OTHER_OPTION_NAMES = \ ENCODER_ENABLE_CUSTOM \ GERMAN_ENABLE \ HAPTIC_ENABLE \ - HHKB_RN42_ENABLE \ ISSI_ENABLE \ KEYLOGGER_ENABLE \ LCD_BACKLIGHT_ENABLE \ @@ -85,7 +84,8 @@ OTHER_OPTION_NAMES = \ SECURE_ENABLE \ CAPS_WORD_ENABLE \ AUTOCORRECT_ENABLE \ - TRI_LAYER_ENABLE + TRI_LAYER_ENABLE \ + REPEAT_KEY_ENABLE define NAME_ECHO @printf " %-30s = %-16s # %s\\n" "$1" "$($1)" "$(origin $1)" diff --git a/data/constants/keycodes/keycodes_0.0.1_basic.hjson b/data/constants/keycodes/keycodes_0.0.1_basic.hjson index 7141d553b082..430211eccae6 100644 --- a/data/constants/keycodes/keycodes_0.0.1_basic.hjson +++ b/data/constants/keycodes/keycodes_0.0.1_basic.hjson @@ -253,7 +253,7 @@ "0x002F": { "group": "basic", "key": "KC_LEFT_BRACKET", - "label": "]", + "label": "[", "aliases": [ "KC_LBRC" ] @@ -261,7 +261,7 @@ "0x0030": { "group": "basic", "key": "KC_RIGHT_BRACKET", - "label": "[", + "label": "]", "aliases": [ "KC_RBRC" ] @@ -1512,4 +1512,4 @@ ] } } -} \ No newline at end of file +} diff --git a/keyboards/planck/ez/base/rules.mk b/data/constants/keycodes/keycodes_0.0.3.hjson similarity index 100% rename from keyboards/planck/ez/base/rules.mk rename to data/constants/keycodes/keycodes_0.0.3.hjson diff --git a/data/constants/keycodes/keycodes_0.0.3_quantum.hjson b/data/constants/keycodes/keycodes_0.0.3_quantum.hjson new file mode 100644 index 000000000000..23a3c9b06d3b --- /dev/null +++ b/data/constants/keycodes/keycodes_0.0.3_quantum.hjson @@ -0,0 +1,18 @@ +{ + "keycodes": { + "0x7C79": { + "group": "quantum", + "key": "QK_REPEAT_KEY", + "aliases": [ + "QK_REP" + ] + }, + "0x7C7A": { + "group": "quantum", + "key": "QK_ALT_REPEAT_KEY", + "aliases": [ + "QK_AREP" + ] + } + } +} diff --git a/data/mappings/defaults.hjson b/data/mappings/defaults.hjson index 93da6161d66f..2bb00da22362 100644 --- a/data/mappings/defaults.hjson +++ b/data/mappings/defaults.hjson @@ -33,7 +33,7 @@ "blok": { "processor": "RP2040", "bootloader": "rp2040", - "board": "QMK_PM2040" + "board": "QMK_BLOK" }, "michi": { "processor": "RP2040", @@ -74,6 +74,11 @@ "processor": "RP2040", "bootloader": "rp2040", "board": "QMK_PM2040" + }, + "liatris": { + "processor": "RP2040", + "bootloader": "rp2040", + "board": "QMK_PM2040" } } } diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index 46108e6fe6a2..ab9a4a0e4527 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson @@ -10,95 +10,130 @@ // deprecated: Default `false`. Set to `true` to turn on warning when a value exists // invalid: Default `false`. Set to `true` to generate errors when a value exists // replace_with: use with a key marked deprecated or invalid to designate a replacement + + // APA102 + "APA102_CI_PIN": {"info_key": "apa102.clock_pin"}, + "APA102_DEFAULT_BRIGHTNESS": {"info_key": "apa102.default_brightness", "value_type": "int"}, + "APA102_DI_PIN": {"info_key": "apa102.data_pin"}, + + // Audio "AUDIO_VOICES": {"info_key": "audio.voices", "value_type": "bool"}, + "SENDSTRING_BELL": {"info_key": "audio.macro_beep", "value_type": "bool"}, + + // Backlight "BACKLIGHT_BREATHING": {"info_key": "backlight.breathing", "value_type": "bool"}, - "BREATHING_PERIOD": {"info_key": "backlight.breathing_period", "value_type": "int"}, "BACKLIGHT_CAPS_LOCK": {"info_key": "backlight.as_caps_lock", "value_type": "bool"}, "BACKLIGHT_LEVELS": {"info_key": "backlight.levels", "value_type": "int"}, "BACKLIGHT_LIMIT_VAL": {"info_key": "backlight.max_brightness", "value_type": "int"}, "BACKLIGHT_ON_STATE": {"info_key": "backlight.on_state", "value_type": "int"}, "BACKLIGHT_PIN": {"info_key": "backlight.pin"}, "BACKLIGHT_PINS": {"info_key": "backlight.pins", "value_type": "array"}, - "BOOTMAGIC_LITE_ROW": {"info_key": "bootmagic.matrix.0", "value_type": "int"}, + "BREATHING_PERIOD": {"info_key": "backlight.breathing_period", "value_type": "int"}, + + // Bootmagic "BOOTMAGIC_LITE_COLUMN": {"info_key": "bootmagic.matrix.1", "value_type": "int"}, - "BOOTMAGIC_LITE_ROW_RIGHT": {"info_key": "split.bootmagic.matrix.0", "value_type": "int"}, "BOOTMAGIC_LITE_COLUMN_RIGHT": {"info_key": "split.bootmagic.matrix.1", "value_type": "int"}, + "BOOTMAGIC_LITE_ROW": {"info_key": "bootmagic.matrix.0", "value_type": "int"}, + "BOOTMAGIC_LITE_ROW_RIGHT": {"info_key": "split.bootmagic.matrix.0", "value_type": "int"}, + + // Caps Word "BOTH_SHIFTS_TURNS_ON_CAPS_WORD": {"info_key": "caps_word.both_shifts_turns_on", "value_type": "bool"}, "CAPS_WORD_IDLE_TIMEOUT": {"info_key": "caps_word.idle_timeout", "value_type": "int"}, - "COMBO_COUNT": {"info_key": "combo.count", "value_type": "int"}, - "COMBO_TERM": {"info_key": "combo.term", "value_type": "int"}, - "DEBOUNCE": {"info_key": "debounce", "value_type": "int"}, - "DIODE_DIRECTION": {"info_key": "diode_direction"}, + "CAPS_WORD_INVERT_ON_SHIFT": {"info_key": "caps_word.invert_on_shift", "value_type": "bool"}, "DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD": {"info_key": "caps_word.double_tap_shift_turns_on", "value_type": "bool"}, - "FORCE_NKRO": {"info_key": "usb.force_nkro", "value_type": "bool"}, + + // Combos + "COMBO_TERM": {"info_key": "combo.term", "value_type": "int"}, + + // Dynamic Keymap "DYNAMIC_KEYMAP_EEPROM_MAX_ADDR": {"info_key": "dynamic_keymap.eeprom_max_addr", "value_type": "int"}, "DYNAMIC_KEYMAP_LAYER_COUNT": {"info_key": "dynamic_keymap.layer_count", "value_type": "int"}, - "HOLD_ON_OTHER_KEY_PRESS": {"info_key": "tapping.hold_on_other_key_press", "value_type": "bool"}, - "HOLD_ON_OTHER_KEY_PRESS_PER_KEY": {"info_key": "tapping.hold_on_other_key_press_per_key", "value_type": "bool"}, - "LAYOUTS": {"info_key": "layout_aliases", "value_type": "mapping"}, - "LEADER_PER_KEY_TIMING": {"info_key": "leader_key.timing", "value_type": "bool"}, - "LEADER_KEY_STRICT_KEY_PROCESSING": {"info_key": "leader_key.strict_processing", "value_type": "bool"}, - "LEADER_TIMEOUT": {"info_key": "leader_key.timeout", "value_type": "int"}, + + // Indicators "LED_CAPS_LOCK_PIN": {"info_key": "indicators.caps_lock"}, "LED_NUM_LOCK_PIN": {"info_key": "indicators.num_lock"}, "LED_SCROLL_LOCK_PIN": {"info_key": "indicators.scroll_lock"}, "LED_COMPOSE_PIN": {"info_key": "indicators.compose"}, "LED_KANA_PIN": {"info_key": "indicators.kana"}, "LED_PIN_ON_STATE": {"info_key": "indicators.on_state", "value_type": "int"}, + + // Leader Key + "LEADER_PER_KEY_TIMING": {"info_key": "leader_key.timing", "value_type": "bool"}, + "LEADER_KEY_STRICT_KEY_PROCESSING": {"info_key": "leader_key.strict_processing", "value_type": "bool"}, + "LEADER_TIMEOUT": {"info_key": "leader_key.timeout", "value_type": "int"}, + + // LED Matrix "LED_MATRIX_CENTER": {"info_key": "led_matrix.center_point", "value_type": "array.int"}, "LED_MATRIX_MAXIMUM_BRIGHTNESS": {"info_key": "led_matrix.max_brightness", "value_type": "int"}, + "LED_MATRIX_SPD_STEP": {"info_key": "led_matrix.speed_steps", "value_type": "int"}, "LED_MATRIX_SPLIT": {"info_key": "led_matrix.split_count", "value_type": "array.int"}, "LED_MATRIX_TIMEOUT": {"info_key": "led_matrix.timeout", "value_type": "int"}, - "LED_MATRIX_HUE_STEP": {"info_key": "led_matrix.hue_steps", "value_type": "int"}, - "LED_MATRIX_SAT_STEP": {"info_key": "led_matrix.sat_steps", "value_type": "int"}, "LED_MATRIX_VAL_STEP": {"info_key": "led_matrix.val_steps", "value_type": "int"}, - "LED_MATRIX_SPD_STEP": {"info_key": "led_matrix.speed_steps", "value_type": "int"}, + "LED_MATRIX_LED_COUNT": {"info_key": "led_matrix.led_count", "value_type": "int", "to_json": false}, + + // LUFA Bootloader + "QMK_ESC_INPUT": {"info_key": "qmk_lufa_bootloader.esc_input"}, + "QMK_ESC_OUTPUT": {"info_key": "qmk_lufa_bootloader.esc_output"}, + "QMK_LED": {"info_key": "qmk_lufa_bootloader.led"}, + "QMK_SPEAKER": {"info_key": "qmk_lufa_bootloader.speaker"}, + + // Matrix + "DEBOUNCE": {"info_key": "debounce", "value_type": "int"}, + "DIODE_DIRECTION": {"info_key": "diode_direction"}, "MATRIX_HAS_GHOST": {"info_key": "matrix_pins.ghost", "value_type": "bool"}, "MATRIX_INPUT_PRESSED_STATE": {"info_key": "matrix_pins.input_pressed_state", "value_type": "int"}, "MATRIX_IO_DELAY": {"info_key": "matrix_pins.io_delay", "value_type": "int"}, + + // Mouse Keys "MOUSEKEY_DELAY": {"info_key": "mousekey.delay", "value_type": "int"}, "MOUSEKEY_INTERVAL": {"info_key": "mousekey.interval", "value_type": "int"}, "MOUSEKEY_MAX_SPEED": {"info_key": "mousekey.max_speed", "value_type": "int"}, "MOUSEKEY_TIME_TO_MAX": {"info_key": "mousekey.time_to_max", "value_type": "int"}, "MOUSEKEY_WHEEL_DELAY": {"info_key": "mousekey.wheel_delay", "value_type": "int"}, + + // One Shot "ONESHOT_TIMEOUT": {"info_key": "oneshot.timeout", "value_type": "int"}, "ONESHOT_TAP_TOGGLE": {"info_key": "oneshot.tap_toggle", "value_type": "int"}, - "PERMISSIVE_HOLD": {"info_key": "tapping.permissive_hold", "value_type": "bool"}, - "PERMISSIVE_HOLD_PER_KEY": {"info_key": "tapping.permissive_hold_per_key", "value_type": "bool"}, + + // PS/2 "PS2_CLOCK_PIN": {"info_key": "ps2.clock_pin"}, "PS2_DATA_PIN": {"info_key": "ps2.data_pin"}, - "RETRO_TAPPING": {"info_key": "tapping.retro", "value_type": "bool"}, - "RETRO_TAPPING_PER_KEY": {"info_key": "tapping.retro_per_key", "value_type": "bool"}, - "RGB_DI_PIN": {"info_key": "rgblight.pin"}, + + // RGB Matrix + "RGB_MATRIX_CENTER": {"info_key": "rgb_matrix.center_point", "value_type": "array.int"}, + "RGB_MATRIX_HUE_STEP": {"info_key": "rgb_matrix.hue_steps", "value_type": "int"}, + "RGB_MATRIX_MAXIMUM_BRIGHTNESS": {"info_key": "rgb_matrix.max_brightness", "value_type": "int"}, + "RGB_MATRIX_SAT_STEP": {"info_key": "rgb_matrix.sat_steps", "value_type": "int"}, + "RGB_MATRIX_SPD_STEP": {"info_key": "rgb_matrix.speed_steps", "value_type": "int"}, + "RGB_MATRIX_SPLIT": {"info_key": "rgb_matrix.split_count", "value_type": "array.int"}, + "RGB_MATRIX_TIMEOUT": {"info_key": "rgb_matrix.timeout", "value_type": "int"}, + "RGB_MATRIX_VAL_STEP": {"info_key": "rgb_matrix.val_steps", "value_type": "int"}, + "RGB_MATRIX_LED_COUNT": {"info_key": "rgb_matrix.led_count", "value_type": "int", "to_json": false}, + + // RGBLight "RGBLED_NUM": {"info_key": "rgblight.led_count", "value_type": "int"}, "RGBLED_SPLIT": {"info_key": "rgblight.split_count", "value_type": "array.int"}, + "RGBLIGHT_HUE_STEP": {"info_key": "rgblight.hue_steps", "value_type": "int"}, "RGBLIGHT_LAYER_BLINK": {"info_key": "rgblight.layers.blink", "value_type": "bool"}, "RGBLIGHT_LAYERS": {"info_key": "rgblight.layers.enabled", "value_type": "bool"}, "RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF": {"info_key": "rgblight.layers.override_rgb", "value_type": "bool"}, + "RGBLIGHT_LED_MAP": {"info_key": "rgblight.led_map", "value_type": "array.int"}, "RGBLIGHT_LIMIT_VAL": {"info_key": "rgblight.max_brightness", "value_type": "int"}, "RGBLIGHT_MAX_LAYERS": {"info_key": "rgblight.layers.max", "value_type": "int"}, - "RGBLIGHT_HUE_STEP": {"info_key": "rgblight.hue_steps", "value_type": "int"}, "RGBLIGHT_SAT_STEP": {"info_key": "rgblight.saturation_steps", "value_type": "int"}, - "RGBLIGHT_VAL_STEP": {"info_key": "rgblight.brightness_steps", "value_type": "int"}, "RGBLIGHT_SLEEP": {"info_key": "rgblight.sleep", "value_type": "bool"}, "RGBLIGHT_SPLIT": {"info_key": "rgblight.split", "value_type": "bool"}, - "RGB_MATRIX_CENTER": {"info_key": "rgb_matrix.center_point", "value_type": "array.int"}, - "RGB_MATRIX_MAXIMUM_BRIGHTNESS": {"info_key": "rgb_matrix.max_brightness", "value_type": "int"}, - "RGB_MATRIX_SPLIT": {"info_key": "rgb_matrix.split_count", "value_type": "array.int"}, - "RGB_MATRIX_TIMEOUT": {"info_key": "rgb_matrix.timeout", "value_type": "int"}, - "RGB_MATRIX_HUE_STEP": {"info_key": "rgb_matrix.hue_steps", "value_type": "int"}, - "RGB_MATRIX_SAT_STEP": {"info_key": "rgb_matrix.sat_steps", "value_type": "int"}, - "RGB_MATRIX_VAL_STEP": {"info_key": "rgb_matrix.val_steps", "value_type": "int"}, - "RGB_MATRIX_SPD_STEP": {"info_key": "rgb_matrix.speed_steps", "value_type": "int"}, + "RGBLIGHT_VAL_STEP": {"info_key": "rgblight.brightness_steps", "value_type": "int"}, "RGBW": {"info_key": "rgblight.rgbw", "value_type": "bool"}, - "QMK_ESC_OUTPUT": {"info_key": "qmk_lufa_bootloader.esc_output"}, - "QMK_ESC_INPUT": {"info_key": "qmk_lufa_bootloader.esc_input"}, - "QMK_LED": {"info_key": "qmk_lufa_bootloader.led"}, - "QMK_SPEAKER": {"info_key": "qmk_lufa_bootloader.speaker"}, + + // Secure + "SECURE_IDLE_TIMEOUT": {"info_key": "secure.idle_timeout", "value_type": "int"}, "SECURE_UNLOCK_SEQUENCE": {"info_key": "secure.unlock_sequence", "value_type": "array.array.int", "to_json": false}, "SECURE_UNLOCK_TIMEOUT": {"info_key": "secure.unlock_timeout", "value_type": "int"}, - "SECURE_IDLE_TIMEOUT": {"info_key": "secure.idle_timeout", "value_type": "int"}, - "SENDSTRING_BELL": {"info_key": "audio.macro_beep", "value_type": "bool"}, + + // Split Keyboard + "SOFT_SERIAL_PIN": {"info_key": "split.soft_serial_pin"}, + "SOFT_SERIAL_SPEED": {"info_key": "split.soft_serial_speed"}, "SPLIT_MODS_ENABLE": {"info_key": "split.transport.sync_modifiers", "value_type": "bool"}, "SPLIT_TRANSPORT_MIRROR": {"info_key": "split.transport.sync_matrix_state", "value_type": "bool"}, "SPLIT_USB_DETECT": {"info_key": "split.usb_detect.enabled", "value_type": "bool"}, @@ -106,35 +141,53 @@ "SPLIT_USB_TIMEOUT_POLL": {"info_key": "split.usb_detect.polling_interval", "value_type": "int"}, "SPLIT_WATCHDOG_ENABLE": {"info_key": "split.transport.watchdog", "value_type": "bool"}, "SPLIT_WATCHDOG_TIMEOUT": {"info_key": "split.transport.watchdog_timeout", "value_type": "int"}, - "SOFT_SERIAL_PIN": {"info_key": "split.soft_serial_pin"}, - "SOFT_SERIAL_SPEED": {"info_key": "split.soft_serial_speed"}, + + // Tapping + "HOLD_ON_OTHER_KEY_PRESS": {"info_key": "tapping.hold_on_other_key_press", "value_type": "bool"}, + "HOLD_ON_OTHER_KEY_PRESS_PER_KEY": {"info_key": "tapping.hold_on_other_key_press_per_key", "value_type": "bool"}, + "PERMISSIVE_HOLD": {"info_key": "tapping.permissive_hold", "value_type": "bool"}, + "PERMISSIVE_HOLD_PER_KEY": {"info_key": "tapping.permissive_hold_per_key", "value_type": "bool"}, + "RETRO_TAPPING": {"info_key": "tapping.retro", "value_type": "bool"}, + "RETRO_TAPPING_PER_KEY": {"info_key": "tapping.retro_per_key", "value_type": "bool"}, "TAP_CODE_DELAY": {"info_key": "qmk.tap_keycode_delay", "value_type": "int"}, "TAP_HOLD_CAPS_DELAY": {"info_key": "qmk.tap_capslock_delay", "value_type": "int"}, "TAPPING_TERM": {"info_key": "tapping.term", "value_type": "int"}, "TAPPING_TERM_PER_KEY": {"info_key": "tapping.term_per_key", "value_type": "bool"}, "TAPPING_TOGGLE": {"info_key": "tapping.toggle", "value_type": "int"}, + + // USB + "FORCE_NKRO": {"info_key": "usb.force_nkro", "value_type": "bool"}, "USB_MAX_POWER_CONSUMPTION": {"info_key": "usb.max_power", "value_type": "int"}, "USB_POLLING_INTERVAL_MS": {"info_key": "usb.polling_interval", "value_type": "int"}, "USB_SUSPEND_WAKEUP_DELAY": {"info_key": "usb.suspend_wakeup_delay", "value_type": "int"}, + // WS2812 + "WS2812_DI_PIN": {"info_key": "ws2812.pin"}, + "WS2812_I2C_ADDRESS": {"info_key": "ws2812.i2c_address", "value_type": "hex"}, + "WS2812_I2C_TIMEOUT": {"info_key": "ws2812.i2c_timeout", "value_type": "int"}, + + "LAYOUTS": {"info_key": "layout_aliases", "value_type": "mapping"}, + // Items we want flagged in lint - "NO_ACTION_MACRO": {"info_key": "_invalid.no_action_macro", "invalid": true}, - "NO_ACTION_FUNCTION": {"info_key": "_invalid.no_action_function", "invalid": true}, - "DESCRIPTION": {"info_key": "_invalid.usb_description", "invalid": true}, "DEBOUNCING_DELAY": {"info_key": "_invalid.debouncing_delay", "invalid": true, "replace_with": "DEBOUNCE"}, + "DESCRIPTION": {"info_key": "_invalid.usb_description", "invalid": true}, + "IGNORE_MOD_TAP_INTERRUPT": {"info_key": "_invalid.ignore_mod_tap_interrupt", "value_type": "bool", "invalid": true}, + "IGNORE_MOD_TAP_INTERRUPT_PER_KEY": {"info_key": "_invalid.ignore_mod_tap_interrupt_per_key", "invalid": true} + "NO_ACTION_FUNCTION": {"info_key": "_invalid.no_action_function", "invalid": true}, + "NO_ACTION_MACRO": {"info_key": "_invalid.no_action_macro", "invalid": true}, "PREVENT_STUCK_MODIFIERS": {"info_key": "_invalid.prevent_stuck_mods", "invalid": true}, - "UNUSED_PINS": {"info_key": "_invalid.unused_pins", "deprecated": true}, - "RGBLIGHT_ANIMATIONS": {"info_key": "_invalid.rgblight.animations.all", "value_type": "bool", "invalid": true}, "QMK_KEYS_PER_SCAN": {"info_key": "qmk.keys_per_scan", "value_type": "int", "deprecated": true}, + "RGB_DI_PIN": {"info_key": "rgblight.pin", "invalid": true, "replace_with": "WS2812_DI_PIN or APA102_DI_PIN"}, + "RGBLIGHT_ANIMATIONS": {"info_key": "_invalid.rgblight.animations.all", "value_type": "bool", "invalid": true}, "TAPPING_FORCE_HOLD": {"info_key": "tapping.force_hold", "value_type": "bool", "deprecated": true}, "TAPPING_FORCE_HOLD_PER_KEY": {"info_key": "tapping.force_hold_per_key", "value_type": "bool", "deprecated": true}, - "IGNORE_MOD_TAP_INTERRUPT": {"info_key": "_deprecated.ignore_mod_tap_interrupt", "value_type": "bool", "deprecated": true}, - "IGNORE_MOD_TAP_INTERRUPT_PER_KEY": {"info_key": "_invalid.ignore_mod_tap_interrupt_per_key", "invalid": true} + "UNUSED_PINS": {"info_key": "_invalid.unused_pins", "deprecated": true}, + "COMBO_COUNT": {"info_key": "_invalid.combo.count", "invalid": true}, // USB params, need to mark as failure when specified in config.h, rather than deprecated + "DEVICE_VER": {"info_key": "usb.device_version", "value_type": "bcd_version", "deprecated": true, "replace_with": "`usb.device_version` in info.json"}, + "MANUFACTURER": {"info_key": "manufacturer", "value_type": "str", "deprecated": true, "replace_with": "`manufacturer` in info.json"}, + "PRODUCT": {"info_key": "keyboard_name", "warn_duplicate": false, "value_type": "str", "deprecated": true, "replace_with": "`keyboard_name` in info.json"}, "PRODUCT_ID": {"info_key": "usb.pid", "value_type": "hex", "deprecated": true, "replace_with": "`usb.pid` in info.json"}, "VENDOR_ID": {"info_key": "usb.vid", "value_type": "hex", "deprecated": true, "replace_with": "`usb.vid` in info.json"}, - "PRODUCT": {"info_key": "keyboard_name", "warn_duplicate": false, "value_type": "str", "deprecated": true, "replace_with": "`keyboard_name` in info.json"}, - "MANUFACTURER": {"info_key": "manufacturer", "value_type": "str", "deprecated": true, "replace_with": "`manufacturer` in info.json"}, - "DEVICE_VER": {"info_key": "usb.device_version", "value_type": "bcd_version", "deprecated": true, "replace_with": "`usb.device_version` in info.json"} } diff --git a/data/mappings/info_rules.hjson b/data/mappings/info_rules.hjson index 7c3780504c68..07191551da8f 100644 --- a/data/mappings/info_rules.hjson +++ b/data/mappings/info_rules.hjson @@ -10,36 +10,39 @@ // deprecated: Default `false`. Set to `true` to turn on warning when a value exists // invalid: Default `false`. Set to `true` to generate errors when a value exists // replace_with: use with a key marked deprecated or invalid to designate a replacement + + "BACKLIGHT_DRIVER": {"info_key": "backlight.driver"}, + "BLUETOOTH_DRIVER": {"info_key": "bluetooth.driver"}, "BOARD": {"info_key": "board"}, "BOOTLOADER": {"info_key": "bootloader", "warn_duplicate": false}, "BOOTMAGIC_ENABLE": {"info_key": "bootmagic.enabled", "value_type": "bool"}, - "BLUETOOTH_DRIVER": {"info_key": "bluetooth.driver"}, - "BACKLIGHT_DRIVER": {"info_key": "backlight.driver"}, "CAPS_WORD_ENABLE": {"info_key": "caps_word.enabled", "value_type": "bool"}, "DEBOUNCE_TYPE": {"info_key": "build.debounce_type"}, + "EEPROM_DRIVER": {"info_key": "eeprom.driver"}, "ENCODER_ENABLE": {"info_key": "encoder.enabled", "value_type": "bool"}, "FIRMWARE_FORMAT": {"info_key": "build.firmware_format"}, "KEYBOARD_SHARED_EP": {"info_key": "usb.shared_endpoint.keyboard", "value_type": "bool"}, - "MOUSE_SHARED_EP": {"info_key": "usb.shared_endpoint.mouse", "value_type": "bool"}, "LAYOUTS": {"info_key": "community_layouts", "value_type": "list"}, "LED_MATRIX_DRIVER": {"info_key": "led_matrix.driver"}, - "RGB_MATRIX_DRIVER": {"info_key": "rgb_matrix.driver"}, "LTO_ENABLE": {"info_key": "build.lto", "value_type": "bool"}, "MCU": {"info_key": "processor", "warn_duplicate": false}, + "MOUSE_SHARED_EP": {"info_key": "usb.shared_endpoint.mouse", "value_type": "bool"}, "MOUSEKEY_ENABLE": {"info_key": "mouse_key.enabled", "value_type": "bool"}, "NO_USB_STARTUP_CHECK": {"info_key": "usb.no_startup_check", "value_type": "bool"}, "PIN_COMPATIBLE": {"info_key": "pin_compatible"}, + "PLATFORM_KEY": {"info_key": "platform_key", "to_json": false}, + "PS2_DRIVER": {"info_key": "ps2.driver"}, + "PS2_ENABLE": {"info_key": "ps2.enabled", "value_type": "bool"}, + "PS2_MOUSE_ENABLE": {"info_key": "ps2.mouse_enabled", "value_type": "bool"}, + "RGB_MATRIX_DRIVER": {"info_key": "rgb_matrix.driver"}, + "RGBLIGHT_DRIVER": {"info_key": "rgblight.driver"}, "SECURE_ENABLE": {"info_key": "secure.enabled", "value_type": "bool"}, "SPLIT_KEYBOARD": {"info_key": "split.enabled", "value_type": "bool"}, "SPLIT_TRANSPORT": {"info_key": "split.transport.protocol", "to_c": false}, - "WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"}, "STENO_ENABLE": {"info_key": "stenography.enabled", "value_type": "bool"}, "STENO_PROTOCOL": {"info_key": "stenography.protocol"}, - "PS2_ENABLE": {"info_key": "ps2.enabled", "value_type": "bool"}, - "PS2_MOUSE_ENABLE": {"info_key": "ps2.mouse_enabled", "value_type": "bool"}, - "PS2_DRIVER": {"info_key": "ps2.driver"}, - - "PLATFORM_KEY": {"info_key": "platform_key", "to_json": false}, + "WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"}, + "WS2812_DRIVER": {"info_key": "ws2812.driver"}, // Items we want flagged in lint "CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"}, diff --git a/data/mappings/keyboard_aliases.hjson b/data/mappings/keyboard_aliases.hjson index 5fe31c4fb199..60c5deaad5e0 100644 --- a/data/mappings/keyboard_aliases.hjson +++ b/data/mappings/keyboard_aliases.hjson @@ -1,13 +1,9 @@ { // Format for each entry: // "": { - // "target": "", - // "layouts": { - // "": "" - // } + // "target": "" // } // - // Both target and layouts are optional. "2_milk": { "target": "spaceman/2_milk" }, @@ -41,6 +37,9 @@ "angel64": { "target": "angel64/alpha" }, + "ashpil/modelm_usbc": { + "target": "ibm/model_m/ashpil_usbc" + }, "at101_blackheart": { "target": "viktus/at101_bh" }, @@ -113,6 +112,15 @@ "cmm_studio/saka68": { "target": "cmm_studio/saka68/solder" }, + "converter/modelm101": { + "target": "ibm/model_m/teensypp" + }, + "converter/modelm101_teensy2": { + "target": "ibm/model_m/teensy2" + }, + "converter/modelm_ssk": { + "target": "ibm/model_m_ssk/teensypp_ssk" + }, "cospad": { "target": "kprepublic/cospad" }, @@ -128,27 +136,21 @@ "daisy": { "target": "ktec/daisy" }, - "doro67/multi": { - "layouts": { - "LAYOUT_ansi": "LAYOUT_65_ansi_blocker" - } - }, - "doro67/regular": { - "layouts": { - "LAYOUT": "LAYOUT_65_ansi_blocker" - } - }, - "doro67/rgb": { - "layouts": { - "LAYOUT": "LAYOUT_65_ansi_blocker" - } - }, "drakon": { "target": "jagdpietr/drakon" }, "durgod/k320": { "target": "durgod/k3x0/k320" }, + "durgod/hades": { + "target": "durgod/dgk6x/hades_ansi" + }, + "durgod/hades_ansi": { + "target": "durgod/dgk6x/hades_ansi" + }, + "durgod/hades_iso": { + "target": "durgod/dgk6x/hades_iso" + }, "dztech/dz60rgb": { "target": "dztech/dz60rgb/v1" }, @@ -191,12 +193,36 @@ "gmmk/pro/iso": { "target": "gmmk/pro/rev1/iso" }, + "handwired/dactyl_manuform/3x5_3": { + "target": "handwired/dactyl_minidox" + }, + "handwired/dactyl_manuform/6x6_kinesis": { + "target": "handwired/dactyl_kinesis" + }, "handwired/ferris": { "target": "ferris/0_1" }, + "handwired/ibm122m": { + "target": "ibm/model_m_122/ibm122m" + }, "handwired/p1800fl": { "target": "team0110/p1800fl" }, + "handwired/jscotto/scotto9": { + "target": "handwired/scottokeebs/scotto9" + }, + "handwired/jscotto/scotto36": { + "target": "handwired/scottokeebs/scotto36" + }, + "handwired/jscotto/scotto40": { + "target": "handwired/scottokeebs/scotto40" + }, + "handwired/jscotto/scottocmd": { + "target": "handwired/scottokeebs/scottocmd" + }, + "handwired/jscotto/scottostarter": { + "target": "handwired/scottokeebs/scottostarter" + }, "helix/pico/sc/back": { "target": "helix/pico/sc" }, @@ -240,14 +266,14 @@ "target": "keyhive/honeycomb" }, "idb_60": { - "target": "idb/idb_60", - "layouts": { - "LAYOUT": "LAYOUT_all" - } + "target": "idb/idb_60" }, "idobo": { "target": "idobao/id75" }, + "jacky_studio/piggy60": { + "target": "jacky_studio/piggy60/rev1" + }, "jj40": { "target": "kprepublic/jj40" }, @@ -260,18 +286,21 @@ "jones": { "target": "jones/v03_1" }, + "kamigakushi": { + "target": "jaykeeb/kamigakushi" + }, "katana60": { "target": "rominronin/katana60/rev1" }, "kbdfans/kbd67mkiirgb": { - "target": "kbdfans/kbd67/mkiirgb", - "layouts": { - "LAYOUT": "LAYOUT_65_ansi_blocker" - } + "target": "kbdfans/kbd67/mkiirgb" }, "kbdfans/kbd67/mkiirgb": { "target": "kbdfans/kbd67/mkiirgb/v1" }, + "keebio/chocopad": { + "target": "keebio/chocopad/rev1" + }, "keebio/dsp40": { "target": "keebio/dsp40/rev1" }, @@ -407,10 +436,8 @@ "montsinger/rebound": { "target": "montsinger/rebound/rev1" }, - "noxary/268_2": { - "layouts": { - "LAYOUT": "LAYOUT_65_ansi_blocker" - } + "mschwingen/modelm": { + "target": "ibm/model_m/mschwingen" }, "oddball": { "target": "oddball/v1" @@ -436,11 +463,6 @@ "peiorisboards/ixora": { "target": "coarse/ixora" }, - "percent/canoe": { - "layouts": { - "LAYOUT_iso": "LAYOUT_65_iso_blocker" - } - }, "plaid": { "target": "dm9records/plaid" }, @@ -453,21 +475,6 @@ "polilla": { "target": "polilla/rev1" }, - "preonic/rev1": { - "layouts": { - "LAYOUT_preonic_grid": "LAYOUT_ortho_5x12" - } - }, - "preonic/rev2": { - "layouts": { - "LAYOUT_preonic_grid": "LAYOUT_ortho_5x12" - } - }, - "preonic/rev3": { - "layouts": { - "LAYOUT_preonic_grid": "LAYOUT_ortho_5x12" - } - }, "primekb/prime_l": { "target": "primekb/prime_l/v1" }, @@ -559,10 +566,7 @@ "target": "underscore33/rev1" }, "vinta": { - "target": "coarse/vinta", - "layouts": { - "LAYOUT_67_ansi": "LAYOUT_65_ansi_blocker" - } + "target": "coarse/vinta" }, "wasdat": { "target": "maartenwut/wasdat" @@ -832,6 +836,9 @@ "hecomi/alpha": { "target": "takashiski/hecomi/alpha" }, + "hfdkb/keyboard_sw/k83":{ + "target": "inland/kb83" + }, "hid_liber": { "target": "bpiphany/hid_liber" }, @@ -925,6 +932,12 @@ "m3n3van": { "target": "matthewdias/m3n3van" }, + "massdrop/thekey": { + "target": "drop/thekey/v1" + }, + "massdrop/thekey_v2": { + "target": "drop/thekey/v2" + }, "mechmini/v1": { "target": "mechkeys/mechmini/v1" }, @@ -1222,6 +1235,9 @@ "treadstone48/rev2": { "target": "marksard/treadstone48/rev2" }, + "tronguylabs/m122_3270": { + "target": "ibm/model_m_122/m122_3270" + }, "ua62": { "target": "nacly/ua62" }, @@ -1282,6 +1298,9 @@ "ymdk_np21": { "target": "ymdk/np21" }, + "yugo_m/model_m_101": { + "target": "ibm/model_m/yugo_m" + }, "yurei": { "target": "kkatano/yurei" }, diff --git a/data/schemas/definitions.jsonschema b/data/schemas/definitions.jsonschema index 94a94157c0c5..b9c64a55ec44 100644 --- a/data/schemas/definitions.jsonschema +++ b/data/schemas/definitions.jsonschema @@ -71,6 +71,38 @@ "type": "string", "pattern": "^[0-9a-z][0-9a-z_/]*$" }, + "keycode": { + "type": "string", + "minLength": 2, + "maxLength": 50, + "pattern": "^[A-Z][A-Zs_0-9]*$" + }, + "keycode_short": { + "type": "string", + "minLength": 2, + "maxLength": 7, + "pattern": "^[A-Z][A-Zs_0-9]*$" + }, + "keycode_decl": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": {"$ref": "#/keycode"}, + "label": {"$ref": "#/text_identifier"}, + "aliases": { + "type": "array", + "minItems": 1, + "items": {"$ref": "#/keycode_short"} + } + } + }, + "keycode_decl_array": { + "type": "array", + "minItems": 1 + "items": {"$ref": "#/keycode_decl"} + }, "mcu_pin_array": { "type": "array", "items": {"$ref": "#/mcu_pin"} diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 2afc1ed516f1..901caa75fee3 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -35,7 +35,7 @@ }, "development_board": { "type": "string", - "enum": ["promicro", "elite_c", "elite_pi", "proton_c", "kb2040", "promicro_rp2040", "blok", "michi", "bit_c_pro", "stemcell", "bluepill", "blackpill_f401", "blackpill_f411", "bonsai_c4", "helios"] + "enum": ["promicro", "elite_c", "elite_pi", "proton_c", "kb2040", "promicro_rp2040", "blok", "michi", "bit_c_pro", "stemcell", "bluepill", "blackpill_f401", "blackpill_f411", "bonsai_c4", "helios", "liatris"] }, "pin_compatible": { "type": "string", @@ -71,6 +71,8 @@ "STM32F446", "STM32G431", "STM32G474", + "STM32H723", + "STM32H733", "STM32L412", "STM32L422", "STM32L432", @@ -96,6 +98,19 @@ "unknown" ] }, + "apa102": { + "type": "object", + "additionalProperties": false, + "properties": { + "data_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "clock_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "default_brightness": { + "type": "integer", + "minimum": 0, + "maximum": 31 + } + } + }, "audio": { "type": "object", "additionalProperties": false, @@ -133,7 +148,7 @@ "properties": { "driver": { "type": "string", - "enum": ["BluefruitLE", "RN42"] + "enum": ["bluefruit_le", "custom", "rn42"] } } }, @@ -161,6 +176,7 @@ "bootloader": { "type": "string", "enum": [ + "apm32-dfu", "atmel-dfu", "bootloadhid", "caterina", @@ -214,7 +230,8 @@ "enabled": {"type": "boolean"}, "both_shifts_turns_on": {"type": "boolean"}, "double_tap_shift_turns_on": {"type": "boolean"}, - "idle_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"} + "idle_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}, + "invert_on_shift": {"type": "boolean"} } }, "combo": { @@ -228,6 +245,11 @@ "type": "array", "items": {"$ref": "qmk.definitions.v1#/filename"} }, + "eeprom": { + "properties": { + "driver": {"type": "string"} + } + }, "encoder": { "$ref": "#/definitions/encoder_config", "properties": { @@ -246,6 +268,7 @@ "on_state": {"$ref": "qmk.definitions.v1#/bit"} } }, + "keycodes": {"$ref": "qmk.definitions.v1#/keycode_decl_array"}, "layout_aliases": { "type": "object", "additionalProperties": {"$ref": "qmk.definitions.v1#/layout_macro"} @@ -360,8 +383,6 @@ }, "max_brightness": {"$ref": "qmk.definitions.v1#/unsigned_int_8"}, "timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}, - "hue_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, - "sat_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, "val_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, "speed_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, "split_count": { @@ -455,6 +476,10 @@ } }, "brightness_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, + "driver": { + "type": "string", + "enum": ["apa102", "custom", "ws2812"] + }, "hue_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, "layers": { "type": "object", @@ -471,8 +496,16 @@ } }, "led_count": {"$ref": "qmk.definitions.v1#/unsigned_int"}, + "led_map": { + "type": "array", + "minItems": 2, + "items": {"$ref": "qmk.definitions.v1#/unsigned_int"} + }, "max_brightness": {"$ref": "qmk.definitions.v1#/unsigned_int_8"}, - "pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "pin": { + "$ref": "qmk.definitions.v1#/mcu_pin", + "$comment": "Deprecated: use ws2812.pin instead" + }, "rgbw": {"type": "boolean"}, "saturation_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"}, "sleep": {"type": "boolean"}, @@ -686,6 +719,19 @@ "led": {"$ref": "qmk.definitions.v1#/mcu_pin"}, "speaker": {"$ref": "qmk.definitions.v1#/mcu_pin"} } + }, + "ws2812": { + "type": "object", + "additionalProperties": false, + "properties": { + "driver": { + "type": "string", + "enum": ["bitbang", "custom", "i2c", "pwm", "spi", "vendor"] + }, + "pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "i2c_address": {"$ref": "qmk.definitions.v1#/hex_number_2d"}, + "i2c_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"} + } } } } diff --git a/data/schemas/keycodes.jsonschema b/data/schemas/keycodes.jsonschema index 77a8347b3b78..df6ce95a83be 100644 --- a/data/schemas/keycodes.jsonschema +++ b/data/schemas/keycodes.jsonschema @@ -8,11 +8,7 @@ "type": "string", "minLength": 2, "maxLength": 50, - "pattern": "^[A-Zs_0-9]*$" - }, - "hex_number_4d": { - "type": "string", - "pattern": "^0x[0-9A-F]{4}$" + "pattern": "^[A-Z][A-Zs_0-9]*$" } }, "properties": { @@ -34,10 +30,10 @@ "keycodes": { "type": "object", "propertyNames": { - "$ref": "#/definitions/hex_number_4d" + "$ref": "qmk.definitions.v1#/hex_number_4d" }, "additionalProperties": { - "type": "object", + "type": "object", // use 'qmk.definitions.v1#/keycode_decl' when problem keycodes are removed "required": [ "key" ], diff --git a/data/schemas/keymap.jsonschema b/data/schemas/keymap.jsonschema index 73aa7c5c2226..7233e896e940 100644 --- a/data/schemas/keymap.jsonschema +++ b/data/schemas/keymap.jsonschema @@ -67,6 +67,7 @@ } } }, + "keycodes": {"$ref": "qmk.definitions.v1#/keycode_decl_array"}, "config": {"$ref": "qmk.keyboard.v1"}, "notes": { "type": "string" diff --git a/quantum/backlight/backlight_software.c b/drivers/backlight/backlight_software.c similarity index 98% rename from quantum/backlight/backlight_software.c rename to drivers/backlight/backlight_software.c index 27ccbd2c9ff9..f2af3e918e55 100644 --- a/quantum/backlight/backlight_software.c +++ b/drivers/backlight/backlight_software.c @@ -1,6 +1,6 @@ -#include "quantum.h" #include "backlight.h" #include "backlight_driver_common.h" +#include "util.h" #ifdef BACKLIGHT_BREATHING # error "Backlight breathing is not available for software PWM. Please disable." diff --git a/drivers/haptic/DRV2605L.c b/drivers/haptic/DRV2605L.c deleted file mode 100644 index 5a1d2ca0afb3..000000000000 --- a/drivers/haptic/DRV2605L.c +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright 2018 ishtob - * Driver for DRV2605L written for QMK - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "DRV2605L.h" -#include "print.h" -#include -#include -#include - -uint8_t DRV2605L_transfer_buffer[2]; -uint8_t DRV2605L_read_register; - -void DRV_write(uint8_t drv_register, uint8_t settings) { - DRV2605L_transfer_buffer[0] = drv_register; - DRV2605L_transfer_buffer[1] = settings; - i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100); -} - -uint8_t DRV_read(uint8_t regaddress) { - i2c_readReg(DRV2605L_BASE_ADDRESS << 1, regaddress, &DRV2605L_read_register, 1, 100); - - return DRV2605L_read_register; -} - -void DRV_init(void) { - i2c_init(); - /* 0x07 sets DRV2605 into calibration mode */ - DRV_write(DRV_MODE, 0x07); - - // DRV_write(DRV_FEEDBACK_CTRL,0xB6); - -#if FB_ERM_LRA == 0 - /* ERM settings */ - DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE / 21.33) * 1000); -# if ERM_OPEN_LOOP == 0 - DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK * (DRIVE_TIME + BLANKING_TIME + IDISS_TIME)) / 0.02133) / (DRIVE_TIME - 0.0003))); -# elif ERM_OPEN_LOOP == 1 - DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196)); -# endif -#elif FB_ERM_LRA == 1 - DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150 + (SAMPLE_TIME * 50)) * 0.000001)) + 0.0003) * F_LRA) / 0.02071))); -# if LRA_OPEN_LOOP == 0 - DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK / sqrt(1 - (F_LRA * 0.0008)) / 0.02133))); -# elif LRA_OPEN_LOOP == 1 - DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196)); -# endif -#endif - - DRVREG_FBR FB_SET; - FB_SET.Bits.ERM_LRA = FB_ERM_LRA; - FB_SET.Bits.BRAKE_FACTOR = FB_BRAKEFACTOR; - FB_SET.Bits.LOOP_GAIN = FB_LOOPGAIN; - FB_SET.Bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/ - DRV_write(DRV_FEEDBACK_CTRL, (uint8_t)FB_SET.Byte); - DRVREG_CTRL1 C1_SET; - C1_SET.Bits.C1_DRIVE_TIME = DRIVE_TIME; - C1_SET.Bits.C1_AC_COUPLE = AC_COUPLE; - C1_SET.Bits.C1_STARTUP_BOOST = STARTUP_BOOST; - DRV_write(DRV_CTRL_1, (uint8_t)C1_SET.Byte); - DRVREG_CTRL2 C2_SET; - C2_SET.Bits.C2_BIDIR_INPUT = BIDIR_INPUT; - C2_SET.Bits.C2_BRAKE_STAB = BRAKE_STAB; - C2_SET.Bits.C2_SAMPLE_TIME = SAMPLE_TIME; - C2_SET.Bits.C2_BLANKING_TIME = BLANKING_TIME; - C2_SET.Bits.C2_IDISS_TIME = IDISS_TIME; - DRV_write(DRV_CTRL_2, (uint8_t)C2_SET.Byte); - DRVREG_CTRL3 C3_SET; - C3_SET.Bits.C3_LRA_OPEN_LOOP = LRA_OPEN_LOOP; - C3_SET.Bits.C3_N_PWM_ANALOG = N_PWM_ANALOG; - C3_SET.Bits.C3_LRA_DRIVE_MODE = LRA_DRIVE_MODE; - C3_SET.Bits.C3_DATA_FORMAT_RTO = DATA_FORMAT_RTO; - C3_SET.Bits.C3_SUPPLY_COMP_DIS = SUPPLY_COMP_DIS; - C3_SET.Bits.C3_ERM_OPEN_LOOP = ERM_OPEN_LOOP; - C3_SET.Bits.C3_NG_THRESH = NG_THRESH; - DRV_write(DRV_CTRL_3, (uint8_t)C3_SET.Byte); - DRVREG_CTRL4 C4_SET; - C4_SET.Bits.C4_ZC_DET_TIME = ZC_DET_TIME; - C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME; - DRV_write(DRV_CTRL_4, (uint8_t)C4_SET.Byte); - DRV_write(DRV_LIB_SELECTION, LIB_SELECTION); - - DRV_write(DRV_GO, 0x01); - - /* 0x00 sets DRV2605 out of standby and to use internal trigger - * 0x01 sets DRV2605 out of standby and to use external trigger */ - DRV_write(DRV_MODE, 0x00); - - // Play greeting sequence - DRV_write(DRV_GO, 0x00); - DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING); - DRV_write(DRV_GO, 0x01); -} - -void DRV_rtp_init(void) { - DRV_write(DRV_GO, 0x00); - DRV_write(DRV_RTP_INPUT, 20); // 20 is the lowest value I've found where haptics can still be felt. - DRV_write(DRV_MODE, 0x05); - DRV_write(DRV_GO, 0x01); -} - -void DRV_amplitude(uint8_t amplitude) { - DRV_write(DRV_RTP_INPUT, amplitude); -} - -void DRV_pulse(uint8_t sequence) { - DRV_write(DRV_GO, 0x00); - DRV_write(DRV_WAVEFORM_SEQ_1, sequence); - DRV_write(DRV_GO, 0x01); -} diff --git a/drivers/haptic/DRV2605L.h b/drivers/haptic/DRV2605L.h deleted file mode 100644 index 8b8eae38b8e1..000000000000 --- a/drivers/haptic/DRV2605L.h +++ /dev/null @@ -1,406 +0,0 @@ -/* Copyright 2018 ishtob - * Driver for DRV2605L written for QMK - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include "i2c_master.h" - -/* Initialization settings - - * Feedback Control Settings */ -#ifndef FB_ERM_LRA -# define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/ -#endif -#ifndef FB_BRAKEFACTOR -# define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */ -#endif -#ifndef FB_LOOPGAIN -# define FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */ -#endif - -/* LRA specific settings */ -#if FB_ERM_LRA == 1 -# ifndef V_RMS -# define V_RMS 2.0 -# endif -# ifndef V_PEAK -# define V_PEAK 2.1 -# endif -# ifndef F_LRA -# define F_LRA 205 -# endif -# ifndef RATED_VOLTAGE -# define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */ -# endif -#endif - -#ifndef RATED_VOLTAGE -# define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */ -#endif -#ifndef V_PEAK -# define V_PEAK 2.8 -#endif - -/* Library Selection */ -#ifndef LIB_SELECTION -# if FB_ERM_LRA == 1 -# define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */ -# else -# define LIB_SELECTION 1 -# endif -#endif - -#ifndef DRV_GREETING -# define DRV_GREETING alert_750ms -#endif -#ifndef DRV_MODE_DEFAULT -# define DRV_MODE_DEFAULT strong_click1 -#endif - -/* Control 1 register settings */ -#ifndef DRIVE_TIME -# define DRIVE_TIME 25 -#endif -#ifndef AC_COUPLE -# define AC_COUPLE 0 -#endif -#ifndef STARTUP_BOOST -# define STARTUP_BOOST 1 -#endif - -/* Control 2 Settings */ -#ifndef BIDIR_INPUT -# define BIDIR_INPUT 1 -#endif -#ifndef BRAKE_STAB -# define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */ -#endif -#ifndef SAMPLE_TIME -# define SAMPLE_TIME 3 -#endif -#ifndef BLANKING_TIME -# define BLANKING_TIME 1 -#endif -#ifndef IDISS_TIME -# define IDISS_TIME 1 -#endif - -/* Control 3 settings */ -#ifndef NG_THRESH -# define NG_THRESH 2 -#endif -#ifndef ERM_OPEN_LOOP -# define ERM_OPEN_LOOP 1 -#endif -#ifndef SUPPLY_COMP_DIS -# define SUPPLY_COMP_DIS 0 -#endif -#ifndef DATA_FORMAT_RTO -# define DATA_FORMAT_RTO 0 -#endif -#ifndef LRA_DRIVE_MODE -# define LRA_DRIVE_MODE 0 -#endif -#ifndef N_PWM_ANALOG -# define N_PWM_ANALOG 0 -#endif -#ifndef LRA_OPEN_LOOP -# define LRA_OPEN_LOOP 0 -#endif - -/* Control 4 settings */ -#ifndef ZC_DET_TIME -# define ZC_DET_TIME 0 -#endif -#ifndef AUTO_CAL_TIME -# define AUTO_CAL_TIME 3 -#endif - -/* register defines -------------------------------------------------------- */ -#define DRV2605L_BASE_ADDRESS 0x5A /* DRV2605L Base address */ -#define DRV_STATUS 0x00 -#define DRV_MODE 0x01 -#define DRV_RTP_INPUT 0x02 -#define DRV_LIB_SELECTION 0x03 -#define DRV_WAVEFORM_SEQ_1 0x04 -#define DRV_WAVEFORM_SEQ_2 0x05 -#define DRV_WAVEFORM_SEQ_3 0x06 -#define DRV_WAVEFORM_SEQ_4 0x07 -#define DRV_WAVEFORM_SEQ_5 0x08 -#define DRV_WAVEFORM_SEQ_6 0x09 -#define DRV_WAVEFORM_SEQ_7 0x0A -#define DRV_WAVEFORM_SEQ_8 0x0B -#define DRV_GO 0x0C -#define DRV_OVERDRIVE_TIME_OFFSET 0x0D -#define DRV_SUSTAIN_TIME_OFFSET_P 0x0E -#define DRV_SUSTAIN_TIME_OFFSET_N 0x0F -#define DRV_BRAKE_TIME_OFFSET 0x10 -#define DRV_AUDIO_2_VIBE_CTRL 0x11 -#define DRV_AUDIO_2_VIBE_MIN_IN 0x12 -#define DRV_AUDIO_2_VIBE_MAX_IN 0x13 -#define DRV_AUDIO_2_VIBE_MIN_OUTDRV 0x14 -#define DRV_AUDIO_2_VIBE_MAX_OUTDRV 0x15 -#define DRV_RATED_VOLT 0x16 -#define DRV_OVERDRIVE_CLAMP_VOLT 0x17 -#define DRV_AUTO_CALIB_COMP_RESULT 0x18 -#define DRV_AUTO_CALIB_BEMF_RESULT 0x19 -#define DRV_FEEDBACK_CTRL 0x1A -#define DRV_CTRL_1 0x1B -#define DRV_CTRL_2 0x1C -#define DRV_CTRL_3 0x1D -#define DRV_CTRL_4 0x1E -#define DRV_CTRL_5 0x1F -#define DRV_OPEN_LOOP_PERIOD 0x20 -#define DRV_VBAT_VOLT_MONITOR 0x21 -#define DRV_LRA_RESONANCE_PERIOD 0x22 - -void DRV_init(void); -void DRV_write(const uint8_t drv_register, const uint8_t settings); -uint8_t DRV_read(const uint8_t regaddress); -void DRV_rtp_init(void); -void DRV_amplitude(const uint8_t amplitude); -void DRV_pulse(const uint8_t sequence); - -typedef enum DRV_EFFECT { - clear_sequence = 0, - strong_click = 1, - strong_click_60 = 2, - strong_click_30 = 3, - sharp_click = 4, - sharp_click_60 = 5, - sharp_click_30 = 6, - soft_bump = 7, - soft_bump_60 = 8, - soft_bump_30 = 9, - dbl_click = 10, - dbl_click_60 = 11, - trp_click = 12, - soft_fuzz = 13, - strong_buzz = 14, - alert_750ms = 15, - alert_1000ms = 16, - strong_click1 = 17, - strong_click2_80 = 18, - strong_click3_60 = 19, - strong_click4_30 = 20, - medium_click1 = 21, - medium_click2_80 = 22, - medium_click3_60 = 23, - sharp_tick1 = 24, - sharp_tick2_80 = 25, - sharp_tick3_60 = 26, - sh_dblclick_str = 27, - sh_dblclick_str_80 = 28, - sh_dblclick_str_60 = 29, - sh_dblclick_str_30 = 30, - sh_dblclick_med = 31, - sh_dblclick_med_80 = 32, - sh_dblclick_med_60 = 33, - sh_dblsharp_tick = 34, - sh_dblsharp_tick_80 = 35, - sh_dblsharp_tick_60 = 36, - lg_dblclick_str = 37, - lg_dblclick_str_80 = 38, - lg_dblclick_str_60 = 39, - lg_dblclick_str_30 = 40, - lg_dblclick_med = 41, - lg_dblclick_med_80 = 42, - lg_dblclick_med_60 = 43, - lg_dblsharp_tick = 44, - lg_dblsharp_tick_80 = 45, - lg_dblsharp_tick_60 = 46, - buzz = 47, - buzz_80 = 48, - buzz_60 = 49, - buzz_40 = 50, - buzz_20 = 51, - pulsing_strong = 52, - pulsing_strong_80 = 53, - pulsing_medium = 54, - pulsing_medium_80 = 55, - pulsing_sharp = 56, - pulsing_sharp_80 = 57, - transition_click = 58, - transition_click_80 = 59, - transition_click_60 = 60, - transition_click_40 = 61, - transition_click_20 = 62, - transition_click_10 = 63, - transition_hum = 64, - transition_hum_80 = 65, - transition_hum_60 = 66, - transition_hum_40 = 67, - transition_hum_20 = 68, - transition_hum_10 = 69, - transition_rampdown_long_smooth1 = 70, - transition_rampdown_long_smooth2 = 71, - transition_rampdown_med_smooth1 = 72, - transition_rampdown_med_smooth2 = 73, - transition_rampdown_short_smooth1 = 74, - transition_rampdown_short_smooth2 = 75, - transition_rampdown_long_sharp1 = 76, - transition_rampdown_long_sharp2 = 77, - transition_rampdown_med_sharp1 = 78, - transition_rampdown_med_sharp2 = 79, - transition_rampdown_short_sharp1 = 80, - transition_rampdown_short_sharp2 = 81, - transition_rampup_long_smooth1 = 82, - transition_rampup_long_smooth2 = 83, - transition_rampup_med_smooth1 = 84, - transition_rampup_med_smooth2 = 85, - transition_rampup_short_smooth1 = 86, - transition_rampup_short_smooth2 = 87, - transition_rampup_long_sharp1 = 88, - transition_rampup_long_sharp2 = 89, - transition_rampup_med_sharp1 = 90, - transition_rampup_med_sharp2 = 91, - transition_rampup_short_sharp1 = 92, - transition_rampup_short_sharp2 = 93, - transition_rampdown_long_smooth1_50 = 94, - transition_rampdown_long_smooth2_50 = 95, - transition_rampdown_med_smooth1_50 = 96, - transition_rampdown_med_smooth2_50 = 97, - transition_rampdown_short_smooth1_50 = 98, - transition_rampdown_short_smooth2_50 = 99, - transition_rampdown_long_sharp1_50 = 100, - transition_rampdown_long_sharp2_50 = 101, - transition_rampdown_med_sharp1_50 = 102, - transition_rampdown_med_sharp2_50 = 103, - transition_rampdown_short_sharp1_50 = 104, - transition_rampdown_short_sharp2_50 = 105, - transition_rampup_long_smooth1_50 = 106, - transition_rampup_long_smooth2_50 = 107, - transition_rampup_med_smooth1_50 = 108, - transition_rampup_med_smooth2_50 = 109, - transition_rampup_short_smooth1_50 = 110, - transition_rampup_short_smooth2_50 = 111, - transition_rampup_long_sharp1_50 = 112, - transition_rampup_long_sharp2_50 = 113, - transition_rampup_med_sharp1_50 = 114, - transition_rampup_med_sharp2_50 = 115, - transition_rampup_short_sharp1_50 = 116, - transition_rampup_short_sharp2_50 = 117, - long_buzz_for_programmatic_stopping = 118, - smooth_hum1_50 = 119, - smooth_hum2_40 = 120, - smooth_hum3_30 = 121, - smooth_hum4_20 = 122, - smooth_hum5_10 = 123, - drv_effect_max = 124, -} DRV_EFFECT; - -/* Register bit array unions */ - -typedef union DRVREG_STATUS { /* register 0x00 */ - uint8_t Byte; - struct { - uint8_t OC_DETECT : 1; /* set to 1 when overcurrent event is detected */ - uint8_t OVER_TEMP : 1; /* set to 1 when device exceeds temp threshold */ - uint8_t FB_STS : 1; /* set to 1 when feedback controller has timed out */ - /* auto-calibration routine and diagnostic result - * result | auto-calibation | diagnostic | - * 0 | passed | actuator func normal | - * 1 | failed | actuator func fault* | - * * actuator is not present or is shorted, timing out, or giving out–of-range back-EMF */ - uint8_t DIAG_RESULT : 1; - uint8_t : 1; - uint8_t DEVICE_ID : 3; /* Device IDs 3: DRV2605 4: DRV2604 5: DRV2604L 6: DRV2605L */ - } Bits; -} DRVREG_STATUS; - -typedef union DRVREG_MODE { /* register 0x01 */ - uint8_t Byte; - struct { - uint8_t MODE : 3; /* Mode setting */ - uint8_t : 3; - uint8_t STANDBY : 1; /* 0:standby 1:ready */ - } Bits; -} DRVREG_MODE; - -typedef union DRVREG_WAIT { - uint8_t Byte; - struct { - uint8_t WAIT_MODE : 1; /* Set to 1 to interpret as wait for next 7 bits x10ms */ - uint8_t WAIT_TIME : 7; - } Bits; -} DRVREG_WAIT; - -typedef union DRVREG_FBR { /* register 0x1A */ - uint8_t Byte; - struct { - uint8_t BEMF_GAIN : 2; - uint8_t LOOP_GAIN : 2; - uint8_t BRAKE_FACTOR : 3; - uint8_t ERM_LRA : 1; - } Bits; -} DRVREG_FBR; - -typedef union DRVREG_CTRL1 { /* register 0x1B */ - uint8_t Byte; - struct { - uint8_t C1_DRIVE_TIME : 5; - uint8_t C1_AC_COUPLE : 1; - uint8_t : 1; - uint8_t C1_STARTUP_BOOST : 1; - } Bits; -} DRVREG_CTRL1; - -typedef union DRVREG_CTRL2 { /* register 0x1C */ - uint8_t Byte; - struct { - uint8_t C2_IDISS_TIME : 2; - uint8_t C2_BLANKING_TIME : 2; - uint8_t C2_SAMPLE_TIME : 2; - uint8_t C2_BRAKE_STAB : 1; - uint8_t C2_BIDIR_INPUT : 1; - } Bits; -} DRVREG_CTRL2; - -typedef union DRVREG_CTRL3 { /* register 0x1D */ - uint8_t Byte; - struct { - uint8_t C3_LRA_OPEN_LOOP : 1; - uint8_t C3_N_PWM_ANALOG : 1; - uint8_t C3_LRA_DRIVE_MODE : 1; - uint8_t C3_DATA_FORMAT_RTO : 1; - uint8_t C3_SUPPLY_COMP_DIS : 1; - uint8_t C3_ERM_OPEN_LOOP : 1; - uint8_t C3_NG_THRESH : 2; - } Bits; -} DRVREG_CTRL3; - -typedef union DRVREG_CTRL4 { /* register 0x1E */ - uint8_t Byte; - struct { - uint8_t C4_OTP_PROGRAM : 1; - uint8_t : 1; - uint8_t C4_OTP_STATUS : 1; - uint8_t : 1; - uint8_t C4_AUTO_CAL_TIME : 2; - uint8_t C4_ZC_DET_TIME : 2; - } Bits; -} DRVREG_CTRL4; - -typedef union DRVREG_CTRL5 { /* register 0x1F */ - uint8_t Byte; - struct { - uint8_t C5_IDISS_TIME : 2; - uint8_t C5_BLANKING_TIME : 2; - uint8_t C5_PLAYBACK_INTERVAL : 1; - uint8_t C5_LRA_AUTO_OPEN_LOOP : 1; - uint8_t C5_AUTO_OL_CNT : 2; - } Bits; -} DRVREG_CTRL5; diff --git a/drivers/haptic/drv2605l.c b/drivers/haptic/drv2605l.c new file mode 100644 index 000000000000..1ad2ad385f2a --- /dev/null +++ b/drivers/haptic/drv2605l.c @@ -0,0 +1,126 @@ +/* Copyright 2018 ishtob + * Driver for DRV2605L written for QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "drv2605l.h" +#include "i2c_master.h" +#include + +uint8_t drv2605l_write_buffer[2]; +uint8_t drv2605l_read_buffer; + +void drv2605l_write(uint8_t reg_addr, uint8_t data) { + drv2605l_write_buffer[0] = reg_addr; + drv2605l_write_buffer[1] = data; + i2c_transmit(DRV2605L_I2C_ADDRESS << 1, drv2605l_write_buffer, 2, 100); +} + +uint8_t drv2605l_read(uint8_t reg_addr) { + i2c_readReg(DRV2605L_I2C_ADDRESS << 1, reg_addr, &drv2605l_read_buffer, 1, 100); + + return drv2605l_read_buffer; +} + +void drv2605l_init(void) { + i2c_init(); + /* 0x07 sets DRV2605 into calibration mode */ + drv2605l_write(DRV2605L_REG_MODE, 0x07); + + // drv2605l_write(DRV2605L_REG_FEEDBACK_CTRL,0xB6); + +#if DRV2605L_FB_ERM_LRA == 0 + /* ERM settings */ + drv2605l_write(DRV2605L_REG_RATED_VOLTAGE, (DRV2605L_RATED_VOLTAGE / 21.33) * 1000); +# if DRV2605L_ERM_OPEN_LOOP == 0 + drv2605l_write(DRV2605L_REG_OVERDRIVE_CLAMP_VOLTAGE, (((DRV2605L_V_PEAK * (DRV2605L_DRIVE_TIME + DRV2605L_BLANKING_TIME + DRV2605L_IDISS_TIME)) / 0.02133) / (DRV2605L_DRIVE_TIME - 0.0003))); +# elif DRV2605L_ERM_OPEN_LOOP == 1 + drv2605l_write(DRV2605L_REG_OVERDRIVE_CLAMP_VOLTAGE, (DRV2605L_V_PEAK / 0.02196)); +# endif +#elif DRV2605L_FB_ERM_LRA == 1 + drv2605l_write(DRV2605L_REG_RATED_VOLTAGE, ((DRV2605L_V_RMS * sqrt(1 - ((4 * ((150 + (DRV2605L_SAMPLE_TIME * 50)) * 0.000001)) + 0.0003) * DRV2605L_F_LRA) / 0.02071))); +# if DRV2605L_LRA_OPEN_LOOP == 0 + drv2605l_write(DRV2605L_REG_OVERDRIVE_CLAMP_VOLTAGE, ((DRV2605L_V_PEAK / sqrt(1 - (DRV2605L_F_LRA * 0.0008)) / 0.02133))); +# elif DRV2605L_LRA_OPEN_LOOP == 1 + drv2605l_write(DRV2605L_REG_OVERDRIVE_CLAMP_VOLTAGE, (DRV2605L_V_PEAK / 0.02196)); +# endif +#endif + + drv2605l_reg_feedback_ctrl_t reg_feedback_ctrl; + reg_feedback_ctrl.bits.ERM_LRA = DRV2605L_FB_ERM_LRA; + reg_feedback_ctrl.bits.BRAKE_FACTOR = DRV2605L_FB_BRAKEFACTOR; + reg_feedback_ctrl.bits.LOOP_GAIN = DRV2605L_FB_LOOPGAIN; + reg_feedback_ctrl.bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/ + drv2605l_write(DRV2605L_REG_FEEDBACK_CTRL, (uint8_t)reg_feedback_ctrl.raw); + + drv2605l_reg_ctrl1_t reg_ctrl1; + reg_ctrl1.bits.C1_DRIVE_TIME = DRV2605L_DRIVE_TIME; + reg_ctrl1.bits.C1_AC_COUPLE = DRV2605L_AC_COUPLE; + reg_ctrl1.bits.C1_STARTUP_BOOST = DRV2605L_STARTUP_BOOST; + drv2605l_write(DRV2605L_REG_CTRL1, (uint8_t)reg_ctrl1.raw); + + drv2605l_reg_ctrl2_t reg_ctrl2; + reg_ctrl2.bits.C2_BIDIR_INPUT = DRV2605L_BIDIR_INPUT; + reg_ctrl2.bits.C2_BRAKE_STAB = DRV2605L_BRAKE_STAB; + reg_ctrl2.bits.C2_SAMPLE_TIME = DRV2605L_SAMPLE_TIME; + reg_ctrl2.bits.C2_BLANKING_TIME = DRV2605L_BLANKING_TIME; + reg_ctrl2.bits.C2_IDISS_TIME = DRV2605L_IDISS_TIME; + drv2605l_write(DRV2605L_REG_CTRL2, (uint8_t)reg_ctrl2.raw); + + drv2605l_reg_ctrl3_t reg_ctrl3; + reg_ctrl3.bits.C3_LRA_OPEN_LOOP = DRV2605L_LRA_OPEN_LOOP; + reg_ctrl3.bits.C3_N_PWM_ANALOG = DRV2605L_N_PWM_ANALOG; + reg_ctrl3.bits.C3_LRA_DRIVE_MODE = DRV2605L_LRA_DRIVE_MODE; + reg_ctrl3.bits.C3_DATA_FORMAT_RTO = DRV2605L_DATA_FORMAT_RTO; + reg_ctrl3.bits.C3_SUPPLY_COMP_DIS = DRV2605L_SUPPLY_COMP_DIS; + reg_ctrl3.bits.C3_ERM_OPEN_LOOP = DRV2605L_ERM_OPEN_LOOP; + reg_ctrl3.bits.C3_NG_THRESH = DRV2605L_NG_THRESH; + drv2605l_write(DRV2605L_REG_CTRL3, (uint8_t)reg_ctrl3.raw); + + drv2605l_reg_ctrl4_t reg_ctrl4; + reg_ctrl4.bits.C4_ZC_DET_TIME = DRV2605L_ZC_DET_TIME; + reg_ctrl4.bits.C4_AUTO_CAL_TIME = DRV2605L_AUTO_CAL_TIME; + drv2605l_write(DRV2605L_REG_CTRL4, (uint8_t)reg_ctrl4.raw); + + drv2605l_write(DRV2605L_REG_LIBRARY_SELECTION, DRV2605L_LIBRARY); + + drv2605l_write(DRV2605L_REG_GO, 0x01); + + /* 0x00 sets DRV2605 out of standby and to use internal trigger + * 0x01 sets DRV2605 out of standby and to use external trigger */ + drv2605l_write(DRV2605L_REG_MODE, 0x00); + + // Play greeting sequence + drv2605l_write(DRV2605L_REG_GO, 0x00); + drv2605l_write(DRV2605L_REG_WAVEFORM_SEQUENCER_1, DRV2605L_GREETING); + drv2605l_write(DRV2605L_REG_GO, 0x01); +} + +void drv2605l_rtp_init(void) { + drv2605l_write(DRV2605L_REG_GO, 0x00); + drv2605l_write(DRV2605L_REG_RTP_INPUT, 20); // 20 is the lowest value I've found where haptics can still be felt. + drv2605l_write(DRV2605L_REG_MODE, 0x05); + drv2605l_write(DRV2605L_REG_GO, 0x01); +} + +void drv2605l_amplitude(uint8_t amplitude) { + drv2605l_write(DRV2605L_REG_RTP_INPUT, amplitude); +} + +void drv2605l_pulse(uint8_t sequence) { + drv2605l_write(DRV2605L_REG_GO, 0x00); + drv2605l_write(DRV2605L_REG_WAVEFORM_SEQUENCER_1, sequence); + drv2605l_write(DRV2605L_REG_GO, 0x01); +} diff --git a/drivers/haptic/drv2605l.h b/drivers/haptic/drv2605l.h new file mode 100644 index 000000000000..a7cf856a86c1 --- /dev/null +++ b/drivers/haptic/drv2605l.h @@ -0,0 +1,362 @@ +/* Copyright 2018 ishtob + * Driver for DRV2605L written for QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +/* Initialization settings + + * Feedback Control Settings */ +#ifndef DRV2605L_FB_ERM_LRA +# define DRV2605L_FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/ +#endif +#ifndef DRV2605L_FB_BRAKEFACTOR +# define DRV2605L_FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */ +#endif +#ifndef DRV2605L_FB_LOOPGAIN +# define DRV2605L_FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */ +#endif + +/* LRA specific settings */ +#if DRV2605L_FB_ERM_LRA == 1 +# ifndef DRV2605L_V_RMS +# define DRV2605L_V_RMS 2.0 +# endif +# ifndef DRV2605L_V_PEAK +# define DRV2605L_V_PEAK 2.1 +# endif +# ifndef DRV2605L_F_LRA +# define DRV2605L_F_LRA 205 +# endif +# ifndef DRV2605L_RATED_VOLTAGE +# define DRV2605L_RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */ +# endif +#endif + +#ifndef DRV2605L_RATED_VOLTAGE +# define DRV2605L_RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */ +#endif +#ifndef DRV2605L_V_PEAK +# define DRV2605L_V_PEAK 2.8 +#endif + +/* Library Selection */ +#ifndef DRV2605L_LIBRARY +# if DRV2605L_FB_ERM_LRA == 1 +# define DRV2605L_LIBRARY 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */ +# else +# define DRV2605L_LIBRARY 1 +# endif +#endif + +#ifndef DRV2605L_GREETING +# define DRV2605L_GREETING DRV2605L_EFFECT_750_MS_ALERT_100 +#endif +#ifndef DRV2605L_DEFAULT_MODE +# define DRV2605L_DEFAULT_MODE DRV2605L_EFFECT_STRONG_CLICK_1_100 +#endif + +/* Control 1 register settings */ +#ifndef DRV2605L_DRIVE_TIME +# define DRV2605L_DRIVE_TIME 25 +#endif +#ifndef DRV2605L_AC_COUPLE +# define DRV2605L_AC_COUPLE 0 +#endif +#ifndef DRV2605L_STARTUP_BOOST +# define DRV2605L_STARTUP_BOOST 1 +#endif + +/* Control 2 Settings */ +#ifndef DRV2605L_BIDIR_INPUT +# define DRV2605L_BIDIR_INPUT 1 +#endif +#ifndef DRV2605L_BRAKE_STAB +# define DRV2605L_BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */ +#endif +#ifndef DRV2605L_SAMPLE_TIME +# define DRV2605L_SAMPLE_TIME 3 +#endif +#ifndef DRV2605L_BLANKING_TIME +# define DRV2605L_BLANKING_TIME 1 +#endif +#ifndef DRV2605L_IDISS_TIME +# define DRV2605L_IDISS_TIME 1 +#endif + +/* Control 3 settings */ +#ifndef DRV2605L_NG_THRESH +# define DRV2605L_NG_THRESH 2 +#endif +#ifndef DRV2605L_ERM_OPEN_LOOP +# define DRV2605L_ERM_OPEN_LOOP 1 +#endif +#ifndef DRV2605L_SUPPLY_COMP_DIS +# define DRV2605L_SUPPLY_COMP_DIS 0 +#endif +#ifndef DRV2605L_DATA_FORMAT_RTO +# define DRV2605L_DATA_FORMAT_RTO 0 +#endif +#ifndef DRV2605L_LRA_DRIVE_MODE +# define DRV2605L_LRA_DRIVE_MODE 0 +#endif +#ifndef DRV2605L_N_PWM_ANALOG +# define DRV2605L_N_PWM_ANALOG 0 +#endif +#ifndef DRV2605L_LRA_OPEN_LOOP +# define DRV2605L_LRA_OPEN_LOOP 0 +#endif + +/* Control 4 settings */ +#ifndef DRV2605L_ZC_DET_TIME +# define DRV2605L_ZC_DET_TIME 0 +#endif +#ifndef DRV2605L_AUTO_CAL_TIME +# define DRV2605L_AUTO_CAL_TIME 3 +#endif + +#define DRV2605L_I2C_ADDRESS 0x5A + +#define DRV2605L_REG_STATUS 0x00 +#define DRV2605L_REG_MODE 0x01 +#define DRV2605L_REG_RTP_INPUT 0x02 +#define DRV2605L_REG_LIBRARY_SELECTION 0x03 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_1 0x04 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_2 0x05 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_3 0x06 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_4 0x07 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_5 0x08 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_6 0x09 +#define DRV2605L_REG_WAVEFORM_SEQUENCER_7 0x0A +#define DRV2605L_REG_WAVEFORM_SEQUENCER_8 0x0B +#define DRV2605L_REG_GO 0x0C +#define DRV2605L_REG_OVERDRIVE_TIME_OFFSET 0x0D +#define DRV2605L_REG_SUSTAIN_TIME_OFFSET_P 0x0E +#define DRV2605L_REG_SUSTAIN_TIME_OFFSET_N 0x0F +#define DRV2605L_REG_BRAKE_TIME_OFFSET 0x10 +#define DRV2605L_REG_AUDIO_TO_VIBE_CTRL 0x11 +#define DRV2605L_REG_AUDIO_TO_VIBE_MIN_INPUT 0x12 +#define DRV2605L_REG_AUDIO_TO_VIBE_MAX_INPUT 0x13 +#define DRV2605L_REG_AUDIO_TO_VIBE_MIN_OUTPUT_DRIVE 0x14 +#define DRV2605L_REG_AUDIO_TO_VIBE_MAX_OUTPUT_DRIVE 0x15 +#define DRV2605L_REG_RATED_VOLTAGE 0x16 +#define DRV2605L_REG_OVERDRIVE_CLAMP_VOLTAGE 0x17 +#define DRV2605L_REG_AUTO_CALIBRATION_COMPENSATION_RESULT 0x18 +#define DRV2605L_REG_AUTO_CALIBRATION_BACK_EMF_RESULT 0x19 +#define DRV2605L_REG_FEEDBACK_CTRL 0x1A +#define DRV2605L_REG_CTRL1 0x1B +#define DRV2605L_REG_CTRL2 0x1C +#define DRV2605L_REG_CTRL3 0x1D +#define DRV2605L_REG_CTRL4 0x1E +#define DRV2605L_REG_CTRL5 0x1F +#define DRV2605L_REG_LRA_OPEN_LOOP_PERIOD 0x20 +#define DRV2605L_REG_VBAT_VOLTAGE_MONITOR 0x21 +#define DRV2605L_REG_LRA_RESONANCE_PERIOD 0x22 + +void drv2605l_init(void); +void drv2605l_write(const uint8_t reg_addr, const uint8_t data); +uint8_t drv2605l_read(const uint8_t reg_addr); +void drv2605l_rtp_init(void); +void drv2605l_amplitude(const uint8_t amplitude); +void drv2605l_pulse(const uint8_t sequence); + +typedef enum drv2605l_effect_t { + DRV2605L_EFFECT_CLEAR_SEQUENCE, + DRV2605L_EFFECT_STRONG_CLICK_100, + DRV2605L_EFFECT_STRONG_CLICK_60, + DRV2605L_EFFECT_STRONG_CLICK_30, + DRV2605L_EFFECT_SHARP_CLICK_100, + DRV2605L_EFFECT_SHARP_CLICK_60, + DRV2605L_EFFECT_SHARP_CLICK_30, + DRV2605L_EFFECT_SOFT_BUMP_100, + DRV2605L_EFFECT_SOFT_BUMP_60, + DRV2605L_EFFECT_SOFT_BUMP_30, + DRV2605L_EFFECT_DOUBLE_CLICK_100, + DRV2605L_EFFECT_DOUBLE_CLICK_60, + DRV2605L_EFFECT_TRIPLE_CLICK_100, + DRV2605L_EFFECT_SOFT_FUZZ_60, + DRV2605L_EFFECT_STRONG_BUZZ_100, + DRV2605L_EFFECT_750_MS_ALERT_100, + DRV2605L_EFFECT_1000_MS_ALERT_100, + DRV2605L_EFFECT_STRONG_CLICK_1_100, + DRV2605L_EFFECT_STRONG_CLICK_2_80, + DRV2605L_EFFECT_STRONG_CLICK_3_60, + DRV2605L_EFFECT_STRONG_CLICK_4_30, + DRV2605L_EFFECT_MEDIUM_CLICK_1_100, + DRV2605L_EFFECT_MEDIUM_CLICK_2_80, + DRV2605L_EFFECT_MEDIUM_CLICK_3_60, + DRV2605L_EFFECT_SHARP_TICK_1_100, + DRV2605L_EFFECT_SHARP_TICK_2_80, + DRV2605L_EFFECT_SHARP_TICK_3_60, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_STRONG_1_100, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_STRONG_2_80, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_STRONG_3_60, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_STRONG_4_30, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_MEDIUM_1_100, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_MEDIUM_2_80, + DRV2605L_EFFECT_SHORT_DOUBLE_CLICK_MEDIUM_3_60, + DRV2605L_EFFECT_SHORT_DOUBLE_SHARP_TICK_1_100, + DRV2605L_EFFECT_SHORT_DOUBLE_SHARP_TICK_2_80, + DRV2605L_EFFECT_SHORT_DOUBLE_SHARP_TICK_3_60, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_STRONG_1_100, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_STRONG_2_80, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_STRONG_3_60, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_STRONG_4_30, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_MEDIUM_1_100, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_MEDIUM_2_80, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_CLICK_MEDIUM_3_60, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_TICK_1_100, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_TICK_2_80, + DRV2605L_EFFECT_LONG_DOUBLE_SHARP_TICK_3_60, + DRV2605L_EFFECT_BUZZ_1_100, + DRV2605L_EFFECT_BUZZ_2_80, + DRV2605L_EFFECT_BUZZ_3_60, + DRV2605L_EFFECT_BUZZ_4_40, + DRV2605L_EFFECT_BUZZ_5_20, + DRV2605L_EFFECT_PULSING_STRONG_1_100, + DRV2605L_EFFECT_PULSING_STRONG_2_60, + DRV2605L_EFFECT_PULSING_MEDIUM_1_100, + DRV2605L_EFFECT_PULSING_MEDIUM_2_60, + DRV2605L_EFFECT_PULSING_SHARP_1_100, + DRV2605L_EFFECT_PULSING_SHARP_2_60, + DRV2605L_EFFECT_TRANSITION_CLICK_1_100, + DRV2605L_EFFECT_TRANSITION_CLICK_2_80, + DRV2605L_EFFECT_TRANSITION_CLICK_3_60, + DRV2605L_EFFECT_TRANSITION_CLICK_4_40, + DRV2605L_EFFECT_TRANSITION_CLICK_5_20, + DRV2605L_EFFECT_TRANSITION_CLICK_6_10, + DRV2605L_EFFECT_TRANSITION_HUM_1_100, + DRV2605L_EFFECT_TRANSITION_HUM_2_80, + DRV2605L_EFFECT_TRANSITION_HUM_3_60, + DRV2605L_EFFECT_TRANSITION_HUM_4_40, + DRV2605L_EFFECT_TRANSITION_HUM_5_20, + DRV2605L_EFFECT_TRANSITION_HUM_6_10, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SMOOTH_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SMOOTH_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SHARP_1_100, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SHARP_2_100, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_LONG_SHARP_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_MEDIUM_SHARP_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_DOWN_SHORT_SHARP_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SMOOTH_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SMOOTH_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_LONG_SHARP_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_MEDIUM_SHARP_2_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SHARP_1_50, + DRV2605L_EFFECT_TRANSITION_RAMP_UP_SHORT_SHARP_2_50, + DRV2605L_EFFECT_LONG_BUZZ_FOR_PROGRAMMATIC_STOPPING, + DRV2605L_EFFECT_SMOOTH_HUM_1_50, + DRV2605L_EFFECT_SMOOTH_HUM_2_40, + DRV2605L_EFFECT_SMOOTH_HUM_3_30, + DRV2605L_EFFECT_SMOOTH_HUM_4_20, + DRV2605L_EFFECT_SMOOTH_HUM_5_10, + DRV2605L_EFFECT_COUNT +} drv2605l_effect_t; + +/* Register bit array unions */ + +typedef union { /* register 0x1A */ + uint8_t raw; + struct { + uint8_t BEMF_GAIN : 2; + uint8_t LOOP_GAIN : 2; + uint8_t BRAKE_FACTOR : 3; + uint8_t ERM_LRA : 1; + } bits; +} drv2605l_reg_feedback_ctrl_t; + +typedef union { /* register 0x1B */ + uint8_t raw; + struct { + uint8_t C1_DRIVE_TIME : 5; + uint8_t C1_AC_COUPLE : 1; + uint8_t : 1; + uint8_t C1_STARTUP_BOOST : 1; + } bits; +} drv2605l_reg_ctrl1_t; + +typedef union { /* register 0x1C */ + uint8_t raw; + struct { + uint8_t C2_IDISS_TIME : 2; + uint8_t C2_BLANKING_TIME : 2; + uint8_t C2_SAMPLE_TIME : 2; + uint8_t C2_BRAKE_STAB : 1; + uint8_t C2_BIDIR_INPUT : 1; + } bits; +} drv2605l_reg_ctrl2_t; + +typedef union { /* register 0x1D */ + uint8_t raw; + struct { + uint8_t C3_LRA_OPEN_LOOP : 1; + uint8_t C3_N_PWM_ANALOG : 1; + uint8_t C3_LRA_DRIVE_MODE : 1; + uint8_t C3_DATA_FORMAT_RTO : 1; + uint8_t C3_SUPPLY_COMP_DIS : 1; + uint8_t C3_ERM_OPEN_LOOP : 1; + uint8_t C3_NG_THRESH : 2; + } bits; +} drv2605l_reg_ctrl3_t; + +typedef union { /* register 0x1E */ + uint8_t raw; + struct { + uint8_t C4_OTP_PROGRAM : 1; + uint8_t : 1; + uint8_t C4_OTP_STATUS : 1; + uint8_t : 1; + uint8_t C4_AUTO_CAL_TIME : 2; + uint8_t C4_ZC_DET_TIME : 2; + } bits; +} drv2605l_reg_ctrl4_t; diff --git a/drivers/lcd/hd44780.h b/drivers/lcd/hd44780.h index 9e4333934447..402217a547a5 100644 --- a/drivers/lcd/hd44780.h +++ b/drivers/lcd/hd44780.h @@ -21,9 +21,9 @@ along with this program. If not, see . #include /** - * \defgroup hd44780 + * \file * - * HD44780 Character LCD Driver + * \defgroup hd44780 HD44780 Character LCD Driver * \{ */ diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c index f29194897528..766d8cd2eb7e 100644 --- a/drivers/led/apa102.c +++ b/drivers/led/apa102.c @@ -16,18 +16,18 @@ */ #include "apa102.h" -#include "quantum.h" +#include "gpio.h" #ifndef APA102_NOPS # if defined(__AVR__) # define APA102_NOPS 0 // AVR at 16 MHz already spends 62.5 ns per clock, so no extra delay is needed # elif defined(PROTOCOL_CHIBIOS) - # include "hal.h" +# include "chibios_config.h" # if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(GD32VF103) # define APA102_NOPS (100 / (1000000000L / (CPU_CLOCK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns # else -# error("APA102_NOPS configuration required") +# error APA102_NOPS configuration required # define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot # endif # endif @@ -43,14 +43,14 @@ } \ } while (0) -#define APA102_SEND_BIT(byte, bit) \ - do { \ - writePin(RGB_DI_PIN, (byte >> bit) & 1); \ - io_wait; \ - writePinHigh(RGB_CI_PIN); \ - io_wait; \ - writePinLow(RGB_CI_PIN); \ - io_wait; \ +#define APA102_SEND_BIT(byte, bit) \ + do { \ + writePin(APA102_DI_PIN, (byte >> bit) & 1); \ + io_wait; \ + writePinHigh(APA102_CI_PIN); \ + io_wait; \ + writePinLow(APA102_CI_PIN); \ + io_wait; \ } while (0) uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS; @@ -77,11 +77,11 @@ void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { } void static apa102_init(void) { - setPinOutput(RGB_DI_PIN); - setPinOutput(RGB_CI_PIN); + setPinOutput(APA102_DI_PIN); + setPinOutput(APA102_CI_PIN); - writePinLow(RGB_DI_PIN); - writePinLow(RGB_CI_PIN); + writePinLow(APA102_DI_PIN); + writePinLow(APA102_CI_PIN); } void apa102_set_brightness(uint8_t brightness) { diff --git a/drivers/led/aw20216.c b/drivers/led/aw20216.c index cbb0b60774c8..479643add483 100644 --- a/drivers/led/aw20216.c +++ b/drivers/led/aw20216.c @@ -1,4 +1,5 @@ /* Copyright 2021 Jasper Chan + * 2023 Huckies * * 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 @@ -15,6 +16,7 @@ */ #include "aw20216.h" +#include "wait.h" #include "spi_master.h" /* The AW20216 appears to be somewhat similar to the IS31FL743, although quite @@ -34,6 +36,8 @@ #define AW_REG_CONFIGURATION 0x00 // PG0 #define AW_REG_GLOBALCURRENT 0x01 // PG0 +#define AW_REG_RESET 0x2F // PG0 +#define AW_REG_MIXFUNCTION 0x46 // PG0 // Default value of AW_REG_CONFIGURATION // D7:D4 = 1011, SWSEL (SW1~SW12 active) @@ -41,7 +45,10 @@ // D2:D1 = 00, OSDE (open/short detection enable) // D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high) #define AW_CONFIG_DEFAULT 0b10110000 +#define AW_MIXCR_DEFAULT 0b00000000 +#define AW_RESET_CMD 0xAE #define AW_CHIPEN 1 +#define AW_LPEN (0x01 << 1) #define AW_PWM_REGISTER_COUNT 216 @@ -64,7 +71,7 @@ uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; -bool AW20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) { +bool aw20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) { static uint8_t s_spi_transfer_buffer[2] = {0}; if (!spi_start(cs_pin, false, AW_SPI_MODE, AW_SPI_DIVISOR)) { @@ -89,58 +96,73 @@ bool AW20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8 return true; } -static inline bool AW20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) { +static inline bool aw20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) { // Little wrapper so callers need not care about sending a buffer - return AW20216_write(cs_pin, page, reg, &value, 1); + return aw20216_write(cs_pin, page, reg, &value, 1); } -static void AW20216_init_scaling(pin_t cs_pin) { +void aw20216_soft_reset(pin_t cs_pin) { + aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_RESET, AW_RESET_CMD); +} + +static void aw20216_init_scaling(pin_t cs_pin) { // Set constant current to the max, control brightness with PWM for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) { - AW20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX); + aw20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX); } } -static inline void AW20216_init_current_limit(pin_t cs_pin) { +static inline void aw20216_init_current_limit(pin_t cs_pin) { // Push config - AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX); + aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX); } -static inline void AW20216_soft_enable(pin_t cs_pin) { +static inline void aw20216_soft_enable(pin_t cs_pin) { // Push config - AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); + aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); +} + +static inline void aw20216_auto_lowpower(pin_t cs_pin) { + aw20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_MIXFUNCTION, AW_MIXCR_DEFAULT | AW_LPEN); } -void AW20216_init(pin_t cs_pin, pin_t en_pin) { +void aw20216_init(pin_t cs_pin, pin_t en_pin) { setPinOutput(en_pin); writePinHigh(en_pin); + aw20216_soft_reset(cs_pin); + wait_ms(2); + // Drivers should start with all scaling and PWM registers as off - AW20216_init_current_limit(cs_pin); - AW20216_init_scaling(cs_pin); + aw20216_init_current_limit(cs_pin); + aw20216_init_scaling(cs_pin); - AW20216_soft_enable(cs_pin); + aw20216_soft_enable(cs_pin); + aw20216_auto_lowpower(cs_pin); } -void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void aw20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { aw_led led; memcpy_P(&led, (&g_aw_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; g_pwm_buffer_update_required[led.driver] = true; } -void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void aw20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - AW20216_set_color(i, red, green, blue); + aw20216_set_color(i, red, green, blue); } } -void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) { +void aw20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - AW20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT); + aw20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT); } g_pwm_buffer_update_required[index] = false; } diff --git a/drivers/led/aw20216.h b/drivers/led/aw20216.h index c6e71b4b4e21..e342cb6bacdf 100644 --- a/drivers/led/aw20216.h +++ b/drivers/led/aw20216.h @@ -30,10 +30,10 @@ typedef struct aw_led { extern const aw_led PROGMEM g_aw_leds[RGB_MATRIX_LED_COUNT]; -void AW20216_init(pin_t cs_pin, pin_t en_pin); -void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index); +void aw20216_init(pin_t cs_pin, pin_t en_pin); +void aw20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void aw20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void aw20216_update_pwm_buffers(pin_t cs_pin, uint8_t index); #define CS1_SW1 0x00 #define CS2_SW1 0x01 diff --git a/drivers/led/ckled2001-simple.c b/drivers/led/ckled2001-simple.c index 6c4ffd398e56..c4d4c0a4cc27 100644 --- a/drivers/led/ckled2001-simple.c +++ b/drivers/led/ckled2001-simple.c @@ -42,7 +42,7 @@ uint8_t g_twi_transfer_buffer[20]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in CKLED2001_write_pwm_buffer() but it's +// buffers and the transfers in ckled2001_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; @@ -50,7 +50,7 @@ bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; -bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -69,7 +69,7 @@ bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { return true; } -bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Assumes PG1 is already selected. // If any of the transactions fails function returns false. // Transmit PWM registers in 12 transfers of 16 bytes. @@ -100,69 +100,72 @@ bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } -void CKLED2001_init(uint8_t addr) { +void ckled2001_init(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to shutdown mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); // Setting internal channel pulldown/pullup - CKLED2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); + ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); // Select number of scan phase - CKLED2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); + ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); // Setting PWM Delay Phase - CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); + ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); // Setting Driving/Sinking Channel Slew Rate - CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); + ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); // Setting Iref - CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); + ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); // Set LED CONTROL PAGE (Page 0) - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0x00); + ckled2001_write_register(addr, i, 0x00); } // Set PWM PAGE (Page 1) - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0x00); + ckled2001_write_register(addr, i, 0x00); } // Set CURRENT PAGE (Page 4) uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - CKLED2001_write_register(addr, i, current_tuen_reg_list[i]); + ckled2001_write_register(addr, i, current_tuen_reg_list[i]); } // Enable LEDs ON/OFF - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0xFF); + ckled2001_write_register(addr, i, 0xFF); } // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to normal mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); } -void CKLED2001_set_value(int index, uint8_t value) { +void ckled2001_set_value(int index, uint8_t value) { ckled2001_led led; if (index >= 0 && index < LED_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.v] == value) { + return; + } g_pwm_buffer[led.driver][led.v] = value; g_pwm_buffer_update_required[led.driver] = true; } } -void CKLED2001_set_value_all(uint8_t value) { +void ckled2001_set_value_all(uint8_t value) { for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) { - CKLED2001_set_value(i, value); + ckled2001_set_value(i, value); } } -void CKLED2001_set_led_control_register(uint8_t index, bool value) { +void ckled2001_set_led_control_register(uint8_t index, bool value) { ckled2001_led led; memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led)); @@ -178,41 +181,41 @@ void CKLED2001_set_led_control_register(uint8_t index, bool value) { g_led_control_registers_update_required[led.driver] = true; } -void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index) { +void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. - if (!CKLED2001_write_pwm_buffer(addr, g_pwm_buffer[index])) { + if (!ckled2001_write_pwm_buffer(addr, g_pwm_buffer[index])) { g_led_control_registers_update_required[index] = true; } } g_pwm_buffer_update_required[index] = false; } -void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index) { +void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < 24; i++) { - CKLED2001_write_register(addr, i, g_led_control_registers[index][i]); + ckled2001_write_register(addr, i, g_led_control_registers[index][i]); } } g_led_control_registers_update_required[index] = false; } -void CKLED2001_sw_return_normal(uint8_t addr) { +void ckled2001_sw_return_normal(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to normal mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); } -void CKLED2001_sw_shutdown(uint8_t addr) { +void ckled2001_sw_shutdown(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to shutdown mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); // Write SW Sleep Register - CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); + ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); } diff --git a/drivers/led/ckled2001-simple.h b/drivers/led/ckled2001-simple.h index a56cad3461bb..c94df62dd2ee 100644 --- a/drivers/led/ckled2001-simple.h +++ b/drivers/led/ckled2001-simple.h @@ -27,24 +27,24 @@ typedef struct ckled2001_led { extern const ckled2001_led PROGMEM g_ckled2001_leds[LED_MATRIX_LED_COUNT]; -void CKLED2001_init(uint8_t addr); -bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void ckled2001_init(uint8_t addr); +bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void CKLED2001_set_value(int index, uint8_t value); -void CKLED2001_set_value_all(uint8_t value); +void ckled2001_set_value(int index, uint8_t value); +void ckled2001_set_value_all(uint8_t value); -void CKLED2001_set_led_control_register(uint8_t index, bool value); +void ckled2001_set_led_control_register(uint8_t index, bool value); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index); -void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index); +void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index); +void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index); -void CKLED2001_sw_return_normal(uint8_t addr); -void CKLED2001_sw_shutdown(uint8_t addr); +void ckled2001_sw_return_normal(uint8_t addr); +void ckled2001_sw_shutdown(uint8_t addr); // Registers Page Define #define CONFIGURE_CMD_PAGE 0xFD diff --git a/drivers/led/ckled2001.c b/drivers/led/ckled2001.c index a99b479d1cbb..6ababf55e906 100644 --- a/drivers/led/ckled2001.c +++ b/drivers/led/ckled2001.c @@ -42,7 +42,7 @@ uint8_t g_twi_transfer_buffer[65]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in CKLED2001_write_pwm_buffer() but it's +// buffers and the transfers in ckled2001_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; @@ -50,7 +50,7 @@ bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; -bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -69,7 +69,7 @@ bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) { return true; } -bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Assumes PG1 is already selected. // If any of the transactions fails function returns false. // Transmit PWM registers in 3 transfers of 64 bytes. @@ -99,57 +99,60 @@ bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } -void CKLED2001_init(uint8_t addr) { +void ckled2001_init(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to shutdown mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); // Setting internal channel pulldown/pullup - CKLED2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); + ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL); // Select number of scan phase - CKLED2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); + ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL); // Setting PWM Delay Phase - CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); + ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE); // Setting Driving/Sinking Channel Slew Rate - CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); + ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE); // Setting Iref - CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); + ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE); // Set LED CONTROL PAGE (Page 0) - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0x00); + ckled2001_write_register(addr, i, 0x00); } // Set PWM PAGE (Page 1) - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0x00); + ckled2001_write_register(addr, i, 0x00); } // Set CURRENT PAGE (Page 4) uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE; - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE); for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) { - CKLED2001_write_register(addr, i, current_tuen_reg_list[i]); + ckled2001_write_register(addr, i, current_tuen_reg_list[i]); } // Enable LEDs ON/OFF - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) { - CKLED2001_write_register(addr, i, 0xFF); + ckled2001_write_register(addr, i, 0xFF); } // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to normal mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); } -void CKLED2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void ckled2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { ckled2001_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; @@ -157,13 +160,13 @@ void CKLED2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { } } -void CKLED2001_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void ckled2001_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - CKLED2001_set_color(i, red, green, blue); + ckled2001_set_color(i, red, green, blue); } } -void CKLED2001_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void ckled2001_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { ckled2001_led led; memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led)); @@ -193,41 +196,41 @@ void CKLED2001_set_led_control_register(uint8_t index, bool red, bool green, boo g_led_control_registers_update_required[led.driver] = true; } -void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index) { +void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. - if (!CKLED2001_write_pwm_buffer(addr, g_pwm_buffer[index])) { + if (!ckled2001_write_pwm_buffer(addr, g_pwm_buffer[index])) { g_led_control_registers_update_required[index] = true; } } g_pwm_buffer_update_required[index] = false; } -void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index) { +void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE); for (int i = 0; i < 24; i++) { - CKLED2001_write_register(addr, i, g_led_control_registers[index][i]); + ckled2001_write_register(addr, i, g_led_control_registers[index][i]); } } g_led_control_registers_update_required[index] = false; } -void CKLED2001_sw_return_normal(uint8_t addr) { +void ckled2001_sw_return_normal(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to normal mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE); } -void CKLED2001_sw_shutdown(uint8_t addr) { +void ckled2001_sw_shutdown(uint8_t addr) { // Select to function page - CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); + ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE); // Setting LED driver to shutdown mode - CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); + ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE); // Write SW Sleep Register - CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); + ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE); } diff --git a/drivers/led/ckled2001.h b/drivers/led/ckled2001.h index aa70a0623f93..32da137fb7ac 100644 --- a/drivers/led/ckled2001.h +++ b/drivers/led/ckled2001.h @@ -29,24 +29,24 @@ typedef struct ckled2001_led { extern const ckled2001_led PROGMEM g_ckled2001_leds[RGB_MATRIX_LED_COUNT]; -void CKLED2001_init(uint8_t addr); -bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void ckled2001_init(uint8_t addr); +bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void CKLED2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void CKLED2001_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void ckled2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void ckled2001_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void CKLED2001_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void ckled2001_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index); -void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index); +void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index); +void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index); -void CKLED2001_sw_return_normal(uint8_t addr); -void CKLED2001_sw_shutdown(uint8_t addr); +void ckled2001_sw_return_normal(uint8_t addr); +void ckled2001_sw_shutdown(uint8_t addr); // Registers Page Define #define CONFIGURE_CMD_PAGE 0xFD diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c index d43863ac4bee..970e9a0be98a 100644 --- a/drivers/led/issi/is31fl3218.c +++ b/drivers/led/issi/is31fl3218.c @@ -37,60 +37,61 @@ uint8_t g_twi_transfer_buffer[20]; uint8_t g_pwm_buffer[18]; bool g_pwm_buffer_update_required = false; -void IS31FL3218_write_register(uint8_t reg, uint8_t data) { +void is31fl3218_write_register(uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); } -void IS31FL3218_write_pwm_buffer(uint8_t *pwm_buffer) { +void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) { g_twi_transfer_buffer[0] = ISSI_REG_PWM; - for (int i = 0; i < 18; i++) { - g_twi_transfer_buffer[1 + i] = pwm_buffer[i]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18); i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT); } -void IS31FL3218_init(void) { +void is31fl3218_init(void) { // In case we ever want to reinitialize (?) - IS31FL3218_write_register(ISSI_REG_RESET, 0x00); + is31fl3218_write_register(ISSI_REG_RESET, 0x00); // Turn off software shutdown - IS31FL3218_write_register(ISSI_REG_SHUTDOWN, 0x01); + is31fl3218_write_register(ISSI_REG_SHUTDOWN, 0x01); // Set all PWM values to zero for (uint8_t i = 0; i < 18; i++) { - IS31FL3218_write_register(ISSI_REG_PWM + i, 0x00); + is31fl3218_write_register(ISSI_REG_PWM + i, 0x00); } // Enable all channels for (uint8_t i = 0; i < 3; i++) { - IS31FL3218_write_register(ISSI_REG_CONTROL + i, 0b00111111); + is31fl3218_write_register(ISSI_REG_CONTROL + i, 0b00111111); } // Load PWM registers and LED Control register data - IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); } -void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + if (g_pwm_buffer[index * 3 + 0] == red && g_pwm_buffer[index * 3 + 1] == green && g_pwm_buffer[index * 3 + 2] == blue) { + return; + } g_pwm_buffer[index * 3 + 0] = red; g_pwm_buffer[index * 3 + 1] = green; g_pwm_buffer[index * 3 + 2] = blue; g_pwm_buffer_update_required = true; } -void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < 6; i++) { - IS31FL3218_set_color(i, red, green, blue); + is31fl3218_set_color(i, red, green, blue); } } -void IS31FL3218_update_pwm_buffers(void) { +void is31fl3218_update_pwm_buffers(void) { if (g_pwm_buffer_update_required) { - IS31FL3218_write_pwm_buffer(g_pwm_buffer); + is31fl3218_write_pwm_buffer(g_pwm_buffer); // Load PWM registers and LED Control register data - IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); } g_pwm_buffer_update_required = false; } diff --git a/drivers/led/issi/is31fl3218.h b/drivers/led/issi/is31fl3218.h index fa760da191dc..2fe37684320f 100644 --- a/drivers/led/issi/is31fl3218.h +++ b/drivers/led/issi/is31fl3218.h @@ -18,8 +18,9 @@ #include #include +#include -void IS31FL3218_init(void); -void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3218_update_pwm_buffers(void); +void is31fl3218_init(void); +void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3218_update_pwm_buffers(void); diff --git a/drivers/led/issi/is31fl3731-simple.c b/drivers/led/issi/is31fl3731-simple.c index 84060f942644..f7f6980a3b68 100644 --- a/drivers/led/issi/is31fl3731-simple.c +++ b/drivers/led/issi/is31fl3731-simple.c @@ -64,7 +64,7 @@ uint8_t g_twi_transfer_buffer[20]; // These buffers match the IS31FL3731 PWM registers 0x24-0xB3. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144]; bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; @@ -95,7 +95,7 @@ bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false}; // 0x0E - R17,G15,G14,G13,G12,G11,G10,G09 // 0x10 - R16,R15,R14,R13,R12,R11,R10,R09 -void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -110,7 +110,7 @@ void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } -void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // assumes bank is already selected // transmit PWM registers in 9 transfers of 16 bytes @@ -123,9 +123,7 @@ void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // copy the data from i to i+15 // device will auto-increment register for data after the first byte // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -137,79 +135,83 @@ void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { } } -void IS31FL3731_init(uint8_t addr) { +void is31fl3731_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, first enable software shutdown, // then set up the mode and other settings, clear the PWM registers, // then disable software shutdown. // select "function register" bank - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); // enable software shutdown - IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); + is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); #ifdef ISSI_3731_DEGHOST // set to enable de-ghosting of the array - IS31FL3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); + is31fl3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); #endif // this delay was copied from other drivers, might not be needed wait_ms(10); // picture mode - IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); + is31fl3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); // display frame 0 - IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); + is31fl3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); // audio sync off - IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); + is31fl3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); // select bank 0 - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register for (int i = 0x00; i <= 0x11; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // turn off all LEDs in the blink control register (not really needed) for (int i = 0x12; i <= 0x23; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // set PWM on all LEDs to 0 for (int i = 0x24; i <= 0xB3; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // select "function register" bank - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); // disable software shutdown - IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); + is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); // select bank 0 and leave it selected. // most usage after initialization is just writing PWM buffers in bank 0 // as there's not much point in double-buffering - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); } -void IS31FL3731_set_value(int index, uint8_t value) { +void is31fl3731_set_value(int index, uint8_t value) { is31_led led; if (index >= 0 && index < LED_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); // Subtract 0x24 to get the second index of g_pwm_buffer + + if (g_pwm_buffer[led.driver][led.v - 0x24] == value) { + return; + } g_pwm_buffer[led.driver][led.v - 0x24] = value; g_pwm_buffer_update_required[led.driver] = true; } } -void IS31FL3731_set_value_all(uint8_t value) { +void is31fl3731_set_value_all(uint8_t value) { for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) { - IS31FL3731_set_value(i, value); + is31fl3731_set_value(i, value); } } -void IS31FL3731_set_led_control_register(uint8_t index, bool value) { +void is31fl3731_set_led_control_register(uint8_t index, bool value) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -225,17 +227,17 @@ void IS31FL3731_set_led_control_register(uint8_t index, bool value) { g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]); + is31fl3731_write_pwm_buffer(addr, g_pwm_buffer[index]); g_pwm_buffer_update_required[index] = false; } } -void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { for (int i = 0; i < 18; i++) { - IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]); + is31fl3731_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; } diff --git a/drivers/led/issi/is31fl3731-simple.h b/drivers/led/issi/is31fl3731-simple.h index 1ddadd520903..69fba14a0b38 100644 --- a/drivers/led/issi/is31fl3731-simple.h +++ b/drivers/led/issi/is31fl3731-simple.h @@ -20,6 +20,7 @@ #include #include +#include #include "progmem.h" typedef struct is31_led { @@ -29,21 +30,21 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT]; -void IS31FL3731_init(uint8_t addr); -void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data); -void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3731_init(uint8_t addr); +void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data); +void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3731_set_value(int index, uint8_t value); -void IS31FL3731_set_value_all(uint8_t value); +void is31fl3731_set_value(int index, uint8_t value); +void is31fl3731_set_value_all(uint8_t value); -void IS31FL3731_set_led_control_register(uint8_t index, bool value); +void is31fl3731_set_led_control_register(uint8_t index, bool value); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index); -void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index); #define C1_1 0x24 #define C1_2 0x25 diff --git a/drivers/led/issi/is31fl3731.c b/drivers/led/issi/is31fl3731.c index fed5354145c7..15a01b6d75c6 100644 --- a/drivers/led/issi/is31fl3731.c +++ b/drivers/led/issi/is31fl3731.c @@ -63,7 +63,7 @@ uint8_t g_twi_transfer_buffer[20]; // These buffers match the IS31FL3731 PWM registers 0x24-0xB3. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][144]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; @@ -85,7 +85,7 @@ bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; // 0x0E - R17,G15,G14,G13,G12,G11,G10,G09 // 0x10 - R16,R15,R14,R13,R12,R11,R10,R09 -void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -98,7 +98,7 @@ void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } -void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // assumes bank is already selected // transmit PWM registers in 9 transfers of 16 bytes @@ -111,9 +111,7 @@ void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // copy the data from i to i+15 // device will auto-increment register for data after the first byte // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -125,67 +123,70 @@ void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { } } -void IS31FL3731_init(uint8_t addr) { +void is31fl3731_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, first enable software shutdown, // then set up the mode and other settings, clear the PWM registers, // then disable software shutdown. // select "function register" bank - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); // enable software shutdown - IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); + is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00); #ifdef ISSI_3731_DEGHOST // set to enable de-ghosting of the array - IS31FL3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); + is31fl3731_write_register(addr, ISSI_REG_GHOST_IMAGE_PREVENTION, 0x10); #endif // this delay was copied from other drivers, might not be needed wait_ms(10); // picture mode - IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); + is31fl3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); // display frame 0 - IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); + is31fl3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00); // audio sync off - IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); + is31fl3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00); // select bank 0 - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register for (int i = 0x00; i <= 0x11; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // turn off all LEDs in the blink control register (not really needed) for (int i = 0x12; i <= 0x23; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // set PWM on all LEDs to 0 for (int i = 0x24; i <= 0xB3; i++) { - IS31FL3731_write_register(addr, i, 0x00); + is31fl3731_write_register(addr, i, 0x00); } // select "function register" bank - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG); // disable software shutdown - IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); + is31fl3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01); // select bank 0 and leave it selected. // most usage after initialization is just writing PWM buffers in bank 0 // as there's not much point in double-buffering - IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0); + is31fl3731_write_register(addr, ISSI_COMMANDREGISTER, 0); } -void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); // Subtract 0x24 to get the second index of g_pwm_buffer + if (g_pwm_buffer[led.driver][led.r - 0x24] == red && g_pwm_buffer[led.driver][led.g - 0x24] == green && g_pwm_buffer[led.driver][led.b - 0x24] == blue) { + return; + } g_pwm_buffer[led.driver][led.r - 0x24] = red; g_pwm_buffer[led.driver][led.g - 0x24] = green; g_pwm_buffer[led.driver][led.b - 0x24] = blue; @@ -193,13 +194,13 @@ void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { } } -void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - IS31FL3731_set_color(i, red, green, blue); + is31fl3731_set_color(i, red, green, blue); } } -void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -229,17 +230,17 @@ void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bo g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]); + is31fl3731_write_pwm_buffer(addr, g_pwm_buffer[index]); } g_pwm_buffer_update_required[index] = false; } -void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { for (int i = 0; i < 18; i++) { - IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]); + is31fl3731_write_register(addr, i, g_led_control_registers[index][i]); } } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3731.h b/drivers/led/issi/is31fl3731.h index 6791289c9e6d..bdf03de1ee16 100644 --- a/drivers/led/issi/is31fl3731.h +++ b/drivers/led/issi/is31fl3731.h @@ -19,6 +19,7 @@ #include #include +#include #include "progmem.h" typedef struct is31_led { @@ -30,21 +31,21 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; -void IS31FL3731_init(uint8_t addr); -void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data); -void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3731_init(uint8_t addr); +void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data); +void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index); -void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index); #define C1_1 0x24 #define C1_2 0x25 diff --git a/drivers/led/issi/is31fl3733-simple.c b/drivers/led/issi/is31fl3733-simple.c index 1e0994d780c7..f9a0a271a89c 100644 --- a/drivers/led/issi/is31fl3733-simple.c +++ b/drivers/led/issi/is31fl3733-simple.c @@ -81,7 +81,7 @@ uint8_t g_twi_transfer_buffer[20]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[LED_DRIVER_COUNT][192]; bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false}; @@ -98,7 +98,7 @@ uint8_t g_led_control_registers[LED_DRIVER_COUNT][24] = {{0}, {0}, {0}, {0}}; #endif bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false}; -bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -117,7 +117,7 @@ bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { return true; } -bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Assumes PG1 is already selected. // If any of the transactions fails function returns false. // Transmit PWM registers in 12 transfers of 16 bytes. @@ -129,9 +129,7 @@ bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer. - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -148,7 +146,7 @@ bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } -void IS31FL3733_init(uint8_t addr, uint8_t sync) { +void is31fl3733_init(uint8_t addr, uint8_t sync) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, @@ -156,61 +154,66 @@ void IS31FL3733_init(uint8_t addr, uint8_t sync) { // Sync is passed so set it according to the datasheet. // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { - IS31FL3733_write_register(addr, i, 0x00); + is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { - IS31FL3733_write_register(addr, i, 0x00); + is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - IS31FL3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - IS31FL3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); // Set global current to maximum. - IS31FL3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); // Disable software shutdown. - IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); } -void IS31FL3733_set_value(int index, uint8_t value) { +void is31fl3733_set_value(int index, uint8_t value) { + is31_led led; if (index >= 0 && index < LED_MATRIX_LED_COUNT) { - is31_led led = g_is31_leds[index]; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.v] == value) { + return; + } g_pwm_buffer[led.driver][led.v] = value; g_pwm_buffer_update_required[led.driver] = true; } } -void IS31FL3733_set_value_all(uint8_t value) { +void is31fl3733_set_value_all(uint8_t value) { for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) { - IS31FL3733_set_value(i, value); + is31fl3733_set_value(i, value); } } -void IS31FL3733_set_led_control_register(uint8_t index, bool value) { - is31_led led = g_is31_leds[index]; +void is31fl3733_set_led_control_register(uint8_t index, bool value) { + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); uint8_t control_register = led.v / 8; uint8_t bit_value = led.v % 8; @@ -224,28 +227,28 @@ void IS31FL3733_set_led_control_register(uint8_t index, bool value) { g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. - if (!IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index])) { + if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) { g_led_control_registers_update_required[index] = true; } g_pwm_buffer_update_required[index] = false; } } -void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { - IS31FL3733_write_register(addr, i, g_led_control_registers[index][i]); + is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; } diff --git a/drivers/led/issi/is31fl3733-simple.h b/drivers/led/issi/is31fl3733-simple.h index f0ea3adca053..1458f7ac8dd4 100644 --- a/drivers/led/issi/is31fl3733-simple.h +++ b/drivers/led/issi/is31fl3733-simple.h @@ -22,6 +22,7 @@ #include #include +#include #include "progmem.h" typedef struct is31_led { @@ -29,23 +30,23 @@ typedef struct is31_led { uint8_t v; } __attribute__((packed)) is31_led; -extern const is31_led __flash g_is31_leds[LED_MATRIX_LED_COUNT]; +extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT]; -void IS31FL3733_init(uint8_t addr, uint8_t sync); -bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3733_init(uint8_t addr, uint8_t sync); +bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3733_set_value(int index, uint8_t value); -void IS31FL3733_set_value_all(uint8_t value); +void is31fl3733_set_value(int index, uint8_t value); +void is31fl3733_set_value_all(uint8_t value); -void IS31FL3733_set_led_control_register(uint8_t index, bool value); +void is31fl3733_set_led_control_register(uint8_t index, bool value); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index); -void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index); #define PUR_0R 0x00 // No PUR resistor #define PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL diff --git a/drivers/led/issi/is31fl3733.c b/drivers/led/issi/is31fl3733.c index 379eaa0ae305..ca431838ef53 100644 --- a/drivers/led/issi/is31fl3733.c +++ b/drivers/led/issi/is31fl3733.c @@ -80,7 +80,7 @@ uint8_t g_twi_transfer_buffer[20]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; @@ -88,7 +88,7 @@ bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; -bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -107,7 +107,7 @@ bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { return true; } -bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Assumes PG1 is already selected. // If any of the transactions fails function returns false. // Transmit PWM registers in 12 transfers of 16 bytes. @@ -138,7 +138,7 @@ bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } -void IS31FL3733_init(uint8_t addr, uint8_t sync) { +void is31fl3733_init(uint8_t addr, uint8_t sync) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, @@ -146,49 +146,52 @@ void IS31FL3733_init(uint8_t addr, uint8_t sync) { // Sync is passed so set it according to the datasheet. // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { - IS31FL3733_write_register(addr, i, 0x00); + is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { - IS31FL3733_write_register(addr, i, 0x00); + is31fl3733_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - IS31FL3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3733_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - IS31FL3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3733_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); // Set global current to maximum. - IS31FL3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3733_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); // Disable software shutdown. - IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3733_write_register(addr, ISSI_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); } -void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; @@ -196,13 +199,13 @@ void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { } } -void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - IS31FL3733_set_color(i, red, green, blue); + is31fl3733_set_color(i, red, green, blue); } } -void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -232,28 +235,28 @@ void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bo g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1. - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // If any of the transactions fail we risk writing dirty PG0, // refresh page 0 just in case. - if (!IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index])) { + if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) { g_led_control_registers_update_required[index] = true; } } g_pwm_buffer_update_required[index] = false; } -void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { - IS31FL3733_write_register(addr, i, g_led_control_registers[index][i]); + is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3733.h b/drivers/led/issi/is31fl3733.h index 29441846acc5..f37a58de0f90 100644 --- a/drivers/led/issi/is31fl3733.h +++ b/drivers/led/issi/is31fl3733.h @@ -32,21 +32,21 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; -void IS31FL3733_init(uint8_t addr, uint8_t sync); -bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3733_init(uint8_t addr, uint8_t sync); +bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index); -void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index); #define PUR_0R 0x00 // No PUR resistor #define PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL diff --git a/drivers/led/issi/is31fl3736.c b/drivers/led/issi/is31fl3736.c index 82e7ee3d18ad..0de8b3bbaef4 100644 --- a/drivers/led/issi/is31fl3736.c +++ b/drivers/led/issi/is31fl3736.c @@ -74,15 +74,15 @@ uint8_t g_twi_transfer_buffer[20]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3736_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required = false; +bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; bool g_led_control_registers_update_required = false; -void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -95,7 +95,7 @@ void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } -void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // assumes PG1 is already selected // transmit PWM registers in 12 transfers of 16 bytes @@ -107,9 +107,7 @@ void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // copy the data from i to i+15 // device will auto-increment register for data after the first byte // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -121,70 +119,73 @@ void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { } } -void IS31FL3736_init(uint8_t addr) { +void is31fl3736_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. // Unlock the command register. - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { - IS31FL3736_write_register(addr, i, 0x00); + is31fl3736_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { - IS31FL3736_write_register(addr, i, 0x00); + is31fl3736_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - IS31FL3736_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3736_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - IS31FL3736_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3736_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); // Set global current to maximum. - IS31FL3736_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3736_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); // Disable software shutdown. - IS31FL3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); + is31fl3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); } -void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); - g_pwm_buffer[led.driver][led.r] = red; - g_pwm_buffer[led.driver][led.g] = green; - g_pwm_buffer[led.driver][led.b] = blue; - g_pwm_buffer_update_required = true; + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } + g_pwm_buffer[led.driver][led.r] = red; + g_pwm_buffer[led.driver][led.g] = green; + g_pwm_buffer[led.driver][led.b] = blue; + g_pwm_buffer_update_required[led.driver] = true; } } -void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - IS31FL3736_set_color(i, red, green, blue); + is31fl3736_set_color(i, red, green, blue); } } -void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -228,23 +229,23 @@ void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bo g_led_control_registers_update_required = true; } -void IS31FL3736_mono_set_brightness(int index, uint8_t value) { +void is31fl3736_mono_set_brightness(int index, uint8_t value) { if (index >= 0 && index < 96) { // Index in range 0..95 -> A1..A8, B1..B8, etc. // Map index 0..95 to registers 0x00..0xBE (interleaved) - uint8_t pwm_register = index * 2; - g_pwm_buffer[0][pwm_register] = value; - g_pwm_buffer_update_required = true; + uint8_t pwm_register = index * 2; + g_pwm_buffer[0][pwm_register] = value; + g_pwm_buffer_update_required[0] = true; } } -void IS31FL3736_mono_set_brightness_all(uint8_t value) { +void is31fl3736_mono_set_brightness_all(uint8_t value) { for (int i = 0; i < 96; i++) { - IS31FL3736_mono_set_brightness(i, value); + is31fl3736_mono_set_brightness(i, value); } } -void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled) { +void is31fl3736_mono_set_led_control_register(uint8_t index, bool enabled) { // Index in range 0..95 -> A1..A8, B1..B8, etc. // Map index 0..95 to registers 0x00..0xBE (interleaved) @@ -262,26 +263,25 @@ void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled) { g_led_control_registers_update_required = true; } -void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2) { - if (g_pwm_buffer_update_required) { +void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) { + if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1 - IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); - IS31FL3736_write_pwm_buffer(addr1, g_pwm_buffer[0]); - // IS31FL3736_write_pwm_buffer(addr2, g_pwm_buffer[1]); + is31fl3736_write_pwm_buffer(addr, g_pwm_buffer[index]); } - g_pwm_buffer_update_required = false; + g_pwm_buffer_update_required[index] = false; } -void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) { +void is31fl3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) { if (g_led_control_registers_update_required) { // Firstly we need to unlock the command register and select PG0 - IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { - IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i]); - // IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i]); + is31fl3736_write_register(addr1, i, g_led_control_registers[0][i]); + // is31fl3736_write_register(addr2, i, g_led_control_registers[1][i]); } g_led_control_registers_update_required = false; } diff --git a/drivers/led/issi/is31fl3736.h b/drivers/led/issi/is31fl3736.h index ccb19afbcccd..32bdef4a8082 100644 --- a/drivers/led/issi/is31fl3736.h +++ b/drivers/led/issi/is31fl3736.h @@ -19,6 +19,7 @@ #include #include +#include #include "progmem.h" // Simple interface option. @@ -41,25 +42,25 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; -void IS31FL3736_init(uint8_t addr); -void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data); -void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3736_init(uint8_t addr); +void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data); +void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue); -void IS31FL3736_mono_set_brightness(int index, uint8_t value); -void IS31FL3736_mono_set_brightness_all(uint8_t value); -void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled); +void is31fl3736_mono_set_brightness(int index, uint8_t value); +void is31fl3736_mono_set_brightness_all(uint8_t value); +void is31fl3736_mono_set_led_control_register(uint8_t index, bool enabled); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2); -void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2); +void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index); #define PUR_0R 0x00 // No PUR resistor #define PUR_05KR 0x01 // 0.5k Ohm resistor diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c index 45a20018c56e..947c0a1d1ace 100644 --- a/drivers/led/issi/is31fl3737.c +++ b/drivers/led/issi/is31fl3737.c @@ -80,7 +80,7 @@ uint8_t g_twi_transfer_buffer[20]; // The control buffers match the PG0 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; @@ -89,7 +89,7 @@ bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; -void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -102,7 +102,7 @@ void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } -void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { +void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // assumes PG1 is already selected // transmit PWM registers in 12 transfers of 16 bytes @@ -114,9 +114,7 @@ void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // copy the data from i to i+15 // device will auto-increment register for data after the first byte // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer - for (int j = 0; j < 16; j++) { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } + memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16); #if ISSI_PERSISTENCE > 0 for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { @@ -128,56 +126,59 @@ void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { } } -void IS31FL3737_init(uint8_t addr) { +void is31fl3737_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. // Unlock the command register. - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG0 - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); // Turn off all LEDs. for (int i = 0x00; i <= 0x17; i++) { - IS31FL3737_write_register(addr, i, 0x00); + is31fl3737_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG1 - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0x00; i <= 0xBF; i++) { - IS31FL3737_write_register(addr, i, 0x00); + is31fl3737_write_register(addr, i, 0x00); } // Unlock the command register. - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG3 - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); // Set de-ghost pull-up resistors (SWx) - IS31FL3737_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); + is31fl3737_write_register(addr, ISSI_REG_SWPULLUP, ISSI_SWPULLUP); // Set de-ghost pull-down resistors (CSx) - IS31FL3737_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); + is31fl3737_write_register(addr, ISSI_REG_CSPULLUP, ISSI_CSPULLUP); // Set global current to maximum. - IS31FL3737_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3737_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); // Disable software shutdown. - IS31FL3737_write_register(addr, ISSI_REG_CONFIGURATION, ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); + is31fl3737_write_register(addr, ISSI_REG_CONFIGURATION, ((ISSI_PWM_FREQUENCY & 0b111) << 3) | 0x01); // Wait 10ms to ensure the device has woken up. wait_ms(10); } -void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; @@ -185,13 +186,13 @@ void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { } } -void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - IS31FL3737_set_color(i, red, green, blue); + is31fl3737_set_color(i, red, green, blue); } } -void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -221,24 +222,24 @@ void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bo g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3737_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { // Firstly we need to unlock the command register and select PG1 - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); - IS31FL3737_write_pwm_buffer(addr, g_pwm_buffer[index]); + is31fl3737_write_pwm_buffer(addr, g_pwm_buffer[index]); } g_pwm_buffer_update_required[index] = false; } -void IS31FL3737_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { // Firstly we need to unlock the command register and select PG0 - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); for (int i = 0; i < 24; i++) { - IS31FL3737_write_register(addr, i, g_led_control_registers[index][i]); + is31fl3737_write_register(addr, i, g_led_control_registers[index][i]); } } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3737.h b/drivers/led/issi/is31fl3737.h index fb0c33420c0e..e7fc97872c50 100644 --- a/drivers/led/issi/is31fl3737.h +++ b/drivers/led/issi/is31fl3737.h @@ -21,6 +21,7 @@ #include #include +#include #include "progmem.h" typedef struct is31_led { @@ -32,21 +33,21 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; -void IS31FL3737_init(uint8_t addr); -void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data); -void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3737_init(uint8_t addr); +void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data); +void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2); -void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2); +void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index); #define PUR_0R 0x00 // No PUR resistor #define PUR_05KR 0x01 // 0.5k Ohm resistor in t_NOL diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c index c2cdd4c46f9f..70671c2a40fc 100644 --- a/drivers/led/issi/is31fl3741.c +++ b/drivers/led/issi/is31fl3741.c @@ -82,7 +82,7 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // The scaling buffers match the PG2 and PG3 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3741_write_pwm_buffer() but it's +// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; @@ -90,7 +90,7 @@ bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS]; -void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { +void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; @@ -103,16 +103,14 @@ void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } -bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // unlock the command register and select PG2 - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM0); +bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { + // Assume PG0 is already selected for (int i = 0; i < 342; i += 18) { if (i == 180) { - // unlock the command register and select PG2 - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM1); + // unlock the command register and select PG1 + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM1); } g_twi_transfer_buffer[0] = i % 180; @@ -150,7 +148,7 @@ bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { return true; } -void IS31FL3741_init(uint8_t addr) { +void is31fl3741_init(uint8_t addr) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, @@ -158,44 +156,47 @@ void IS31FL3741_init(uint8_t addr) { // Unlock the command register. // Unlock the command register. - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); // Select PG4 - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); // Set to Normal operation - IS31FL3741_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); + is31fl3741_write_register(addr, ISSI_REG_CONFIGURATION, 0x01); // Set Golbal Current Control Register - IS31FL3741_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); + is31fl3741_write_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT); // Set Pull up & Down for SWx CSy - IS31FL3741_write_register(addr, ISSI_REG_PULLDOWNUP, ((ISSI_CSPULLUP << 4) | ISSI_SWPULLUP)); + is31fl3741_write_register(addr, ISSI_REG_PULLDOWNUP, ((ISSI_CSPULLUP << 4) | ISSI_SWPULLUP)); - // IS31FL3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF); + // is31fl3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF); // Wait 10ms to ensure the device has woken up. wait_ms(10); } -void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { is31_led led; if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) { + return; + } + g_pwm_buffer_update_required[led.driver] = true; g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; - g_pwm_buffer_update_required[led.driver] = true; } } -void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) { - IS31FL3741_set_color(i, red, green, blue); + is31fl3741_set_color(i, red, green, blue); } } -void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { +void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { is31_led led; memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); @@ -220,15 +221,19 @@ void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bo g_scaling_registers_update_required[led.driver] = true; } -void IS31FL3741_update_pwm_buffers(uint8_t addr, uint8_t index) { +void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - IS31FL3741_write_pwm_buffer(addr, g_pwm_buffer[index]); + // unlock the command register and select PG2 + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM0); + + is31fl3741_write_pwm_buffer(addr, g_pwm_buffer[index]); } g_pwm_buffer_update_required[index] = false; } -void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { g_pwm_buffer[pled->driver][pled->r] = red; g_pwm_buffer[pled->driver][pled->g] = green; g_pwm_buffer[pled->driver][pled->b] = blue; @@ -236,31 +241,31 @@ void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, g_pwm_buffer_update_required[pled->driver] = true; } -void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index) { +void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { // unlock the command register and select PG2 - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0); // CS1_SW1 to CS30_SW6 are on PG2 for (int i = CS1_SW1; i <= CS30_SW6; ++i) { - IS31FL3741_write_register(addr, i, g_scaling_registers[0][i]); + is31fl3741_write_register(addr, i, g_scaling_registers[index][i]); } // unlock the command register and select PG3 - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); - IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); + is31fl3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1); // CS1_SW7 to CS39_SW9 are on PG3 for (int i = CS1_SW7; i <= CS39_SW9; ++i) { - IS31FL3741_write_register(addr, i - CS1_SW7, g_scaling_registers[0][i]); + is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]); } g_scaling_registers_update_required[index] = false; } } -void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { g_scaling_registers[pled->driver][pled->r] = red; g_scaling_registers[pled->driver][pled->g] = green; g_scaling_registers[pled->driver][pled->b] = blue; diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h index b0089ea5babf..4ae84dc3c65a 100644 --- a/drivers/led/issi/is31fl3741.h +++ b/drivers/led/issi/is31fl3741.h @@ -32,24 +32,24 @@ typedef struct is31_led { extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; -void IS31FL3741_init(uint8_t addr); -void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data); -bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); +void is31fl3741_init(uint8_t addr); +void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data); +bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer); -void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue); +void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue); // This should not be called from an interrupt // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3741_update_pwm_buffers(uint8_t addr, uint8_t index); -void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index); -void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index); +void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index); +void is31fl3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); -void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); +void is31fl3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); #define PUR_0R 0x00 // No PUR resistor #define PUR_05KR 0x01 // 0.5k Ohm resistor diff --git a/drivers/led/issi/is31flcommon.c b/drivers/led/issi/is31flcommon.c index 106890a8bf0c..4b78947ada3a 100644 --- a/drivers/led/issi/is31flcommon.c +++ b/drivers/led/issi/is31flcommon.c @@ -133,19 +133,28 @@ void IS31FL_common_update_pwm_register(uint8_t addr, uint8_t index) { #ifdef ISSI_MANUAL_SCALING void IS31FL_set_manual_scaling_buffer(void) { + is31_led led; + is31_led scale; for (int i = 0; i < ISSI_MANUAL_SCALING; i++) { - is31_led scale = g_is31_scaling[i]; + memcpy_P(&scale, (&g_is31_scaling[i]), sizeof(scale)); + # ifdef RGB_MATRIX_ENABLE if (scale.driver >= 0 && scale.driver < RGB_MATRIX_LED_COUNT) { - is31_led led = g_is31_leds[scale.driver]; + memcpy_P(&led, (&g_is31_leds[scale.driver]), sizeof(led)); + if (g_scaling_buffer[led.driver][led.r] = scale.r && g_scaling_buffer[led.driver][led.g] = scale.g && g_scaling_buffer[led.driver][led.b] = scale.b) { + return; + } g_scaling_buffer[led.driver][led.r] = scale.r; g_scaling_buffer[led.driver][led.g] = scale.g; g_scaling_buffer[led.driver][led.b] = scale.b; # elif defined(LED_MATRIX_ENABLE) if (scale.driver >= 0 && scale.driver < LED_MATRIX_LED_COUNT) { - is31_led led = g_is31_leds[scale.driver]; + memcpy_P(&led, (&g_is31_leds[scale.driver]), sizeof(led)); + if (g_scaling_buffer[led.driver][led.v] == scale.v) { + return; + } g_scaling_buffer[led.driver][led.v] = scale.v; # endif g_scaling_buffer_update_required[led.driver] = true; @@ -169,7 +178,8 @@ void IS31FL_common_update_scaling_register(uint8_t addr, uint8_t index) { // Colour is set by adjusting PWM register void IS31FL_RGB_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { if (index >= 0 && index < RGB_MATRIX_LED_COUNT) { - is31_led led = g_is31_leds[index]; + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; @@ -186,7 +196,8 @@ void IS31FL_RGB_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { // Setup Scaling register that decides the peak current of each LED void IS31FL_RGB_set_scaling_buffer(uint8_t index, bool red, bool green, bool blue) { - is31_led led = g_is31_leds[index]; + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); if (red) { g_scaling_buffer[led.driver][led.r] = ISSI_SCAL_RED; } else { @@ -208,7 +219,8 @@ void IS31FL_RGB_set_scaling_buffer(uint8_t index, bool red, bool green, bool blu #elif defined(LED_MATRIX_ENABLE) // LED Matrix Specific scripts void IS31FL_simple_set_scaling_buffer(uint8_t index, bool value) { - is31_led led = g_is31_leds[index]; + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); if (value) { g_scaling_buffer[led.driver][led.v] = ISSI_SCAL_LED; } else { @@ -219,7 +231,9 @@ void IS31FL_simple_set_scaling_buffer(uint8_t index, bool value) { void IS31FL_simple_set_brightness(int index, uint8_t value) { if (index >= 0 && index < LED_MATRIX_LED_COUNT) { - is31_led led = g_is31_leds[index]; + is31_led led; + memcpy_P(&led, (&g_is31_leds[index]), sizeof(led)); + g_pwm_buffer[led.driver][led.v] = value; g_pwm_buffer_update_required[led.driver] = true; } diff --git a/drivers/led/issi/is31flcommon.h b/drivers/led/issi/is31flcommon.h index 18432ffc312a..4b3add558b6b 100644 --- a/drivers/led/issi/is31flcommon.h +++ b/drivers/led/issi/is31flcommon.h @@ -43,7 +43,7 @@ typedef struct is31_led { uint8_t b; } __attribute__((packed)) is31_led; -extern const is31_led __flash g_is31_leds[RGB_MATRIX_LED_COUNT]; +extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT]; #elif defined(LED_MATRIX_ENABLE) typedef struct is31_led { @@ -51,11 +51,11 @@ typedef struct is31_led { uint8_t v; } __attribute__((packed)) is31_led; -extern const is31_led __flash g_is31_leds[LED_MATRIX_LED_COUNT]; +extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT]; #endif #ifdef ISSI_MANUAL_SCALING -extern const is31_led __flash g_is31_scaling[]; +extern const is31_led PROGMEM g_is31_scaling[]; void IS31FL_set_manual_scaling_buffer(void); #endif diff --git a/drivers/oled/ssd1306_sh1106.c b/drivers/oled/oled_driver.c similarity index 71% rename from drivers/oled/ssd1306_sh1106.c rename to drivers/oled/oled_driver.c index 342920572e3a..8ff6e0426cb9 100644 --- a/drivers/oled/ssd1306_sh1106.c +++ b/drivers/oled/oled_driver.c @@ -14,20 +14,23 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "i2c_master.h" + +#if defined(OLED_TRANSPORT_SPI) +# include "spi_master.h" +#elif defined(OLED_TRANSPORT_I2C) +# include "i2c_master.h" +#endif #include "oled_driver.h" #include OLED_FONT_H #include "timer.h" #include "print.h" - #include - #include "progmem.h" - -#include "keyboard.h" +#include "wait.h" // Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf // for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf +// for SH1107: https://www.displayfuture.com/Display/datasheet/controller/SH1107.pdf // Fundamental Commands #define CONTRAST 0x81 @@ -82,6 +85,11 @@ along with this program. If not, see . // Charge Pump Commands #define CHARGE_PUMP 0x8D +// Commands specific to the SH1107 chip +#define SH1107_DISPLAY_START_LINE 0xDC +#define SH1107_MEMORY_MODE_PAGE 0x20 +#define SH1107_MEMORY_MODE_VERTICAL 0x21 + // Misc defines #ifndef OLED_BLOCK_COUNT # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) @@ -89,19 +97,42 @@ along with this program. If not, see . #ifndef OLED_BLOCK_SIZE # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) #endif +// Default display clock +#if !defined(OLED_DISPLAY_CLOCK) +# define OLED_DISPLAY_CLOCK 0x80 +#endif +// Default VCOMH deselect value +#if !defined(OLED_VCOM_DETECT) +# define OLED_VCOM_DETECT 0x20 +#endif +#if !defined(OLED_PRE_CHARGE_PERIOD) +# define OLED_PRE_CHARGE_PERIOD 0xF1 +#endif #define OLED_ALL_BLOCKS_MASK (((((OLED_BLOCK_TYPE)1 << (OLED_BLOCK_COUNT - 1)) - 1) << 1) | 1) +#define OLED_IC_HAS_HORIZONTAL_MODE (OLED_IC == OLED_IC_SSD1306) +#define OLED_IC_COM_PINS_ARE_COLUMNS (OLED_IC == OLED_IC_SH1107) + +#ifndef OLED_COM_PIN_COUNT +# if OLED_IC == OLED_IC_SSD1306 +# define OLED_COM_PIN_COUNT 64 +# elif OLED_IC == OLED_IC_SH1106 +# define OLED_COM_PIN_COUNT 64 +# elif OLED_IC == OLED_IC_SH1107 +# define OLED_COM_PIN_COUNT 128 +# else +# error Invalid OLED_IC value +# endif +#endif + +#ifndef OLED_COM_PIN_OFFSET +# define OLED_COM_PIN_OFFSET 0 +#endif + // i2c defines #define I2C_CMD 0x00 #define I2C_DATA 0x40 -#if defined(__AVR__) -# define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) -#else // defined(__AVR__) -# define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) -#endif // defined(__AVR__) -#define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) -#define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, OLED_I2C_TIMEOUT) #define HAS_FLAGS(bits, flags) ((bits & flags) == flags) @@ -132,24 +163,118 @@ uint32_t oled_scroll_timeout; uint16_t oled_update_timeout; #endif -// Internal variables to reduce math instructions +#if defined(OLED_TRANSPORT_SPI) +# ifndef OLED_DC_PIN +# error "The OLED driver in SPI needs a D/C pin defined" +# endif +# ifndef OLED_CS_PIN +# error "The OLED driver in SPI needs a CS pin defined" +# endif +# ifndef OLED_SPI_MODE +# define OLED_SPI_MODE 3 +# endif +# ifndef OLED_SPI_DIVISOR +# define OLED_SPI_DIVISOR 2 +# endif +#elif defined(OLED_TRANSPORT_I2C) +# if !defined(OLED_DISPLAY_ADDRESS) +# define OLED_DISPLAY_ADDRESS 0x3C +# endif +#endif + +// Transmit/Write Funcs. +__attribute__((weak)) bool oled_send_cmd(const uint8_t *data, uint16_t size) { +#if defined(OLED_TRANSPORT_SPI) + if (!spi_start(OLED_CS_PIN, false, OLED_SPI_MODE, OLED_SPI_DIVISOR)) { + return false; + } + // Command Mode + writePinLow(OLED_DC_PIN); + // Send the commands + if (spi_transmit(&data[1], size - 1) != SPI_STATUS_SUCCESS) { + spi_stop(); + return false; + } + spi_stop(); + return true; +#elif defined(OLED_TRANSPORT_I2C) + i2c_status_t status = i2c_transmit((OLED_DISPLAY_ADDRESS << 1), data, size, OLED_I2C_TIMEOUT); + return (status == I2C_STATUS_SUCCESS); +#endif +} + +__attribute__((weak)) bool oled_send_cmd_P(const uint8_t *data, uint16_t size) { #if defined(__AVR__) -// identical to i2c_transmit, but for PROGMEM since all initialization is in PROGMEM arrays currently -// probably should move this into i2c_master... -static i2c_status_t i2c_transmit_P(uint8_t address, const uint8_t *data, uint16_t length, uint16_t timeout) { - i2c_status_t status = i2c_start(address | I2C_WRITE, timeout); +# if defined(OLED_TRANSPORT_SPI) + if (!spi_start(OLED_CS_PIN, false, OLED_SPI_MODE, OLED_SPI_DIVISOR)) { + return false; + } + spi_status_t status = SPI_STATUS_SUCCESS; + // Command Mode + writePinLow(OLED_DC_PIN); + // Send the commands + for (uint16_t i = 1; i < size && status >= 0; i++) { + status = spi_write(pgm_read_byte((const char *)&data[i])); + } + spi_stop(); + return (status >= 0); +# elif defined(OLED_TRANSPORT_I2C) + i2c_status_t status = i2c_start((OLED_DISPLAY_ADDRESS << 1) | I2C_WRITE, OLED_I2C_TIMEOUT); - for (uint16_t i = 0; i < length && status >= 0; i++) { - status = i2c_write(pgm_read_byte((const char *)data++), timeout); - if (status) break; + for (uint16_t i = 0; i < size && status >= 0; i++) { + status = i2c_write(pgm_read_byte((const char *)data++), OLED_I2C_TIMEOUT); } i2c_stop(); - return status; + return (status == I2C_STATUS_SUCCESS); +# endif +#else + return oled_send_cmd(data, size); +#endif } + +__attribute__((weak)) bool oled_send_data(const uint8_t *data, uint16_t size) { +#if defined(OLED_TRANSPORT_SPI) + if (!spi_start(OLED_CS_PIN, false, OLED_SPI_MODE, OLED_SPI_DIVISOR)) { + return false; + } + // Data Mode + writePinHigh(OLED_DC_PIN); + // Send the commands + if (spi_transmit(data, size) != SPI_STATUS_SUCCESS) { + spi_stop(); + return false; + } + spi_stop(); + return true; +#elif defined(OLED_TRANSPORT_I2C) + i2c_status_t status = i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), I2C_DATA, data, size, OLED_I2C_TIMEOUT); + return (status == I2C_STATUS_SUCCESS); #endif +} + +__attribute__((weak)) void oled_driver_init(void) { +#if defined(OLED_TRANSPORT_SPI) + spi_init(); + setPinOutput(OLED_CS_PIN); + writePinHigh(OLED_CS_PIN); + + setPinOutput(OLED_DC_PIN); + writePinLow(OLED_DC_PIN); +# ifdef OLED_RST_PIN + /* Reset device */ + setPinOutput(OLED_RST_PIN); + writePinLow(OLED_RST_PIN); + wait_ms(20); + writePinHigh(OLED_RST_PIN); + wait_ms(20); +# endif +#elif defined(OLED_TRANSPORT_I2C) + i2c_init(); +#endif +} // Flips the rendering bits for a character at the current cursor position static void InvertCharacter(uint8_t *cursor) { @@ -161,7 +286,7 @@ static void InvertCharacter(uint8_t *cursor) { } bool oled_init(oled_rotation_t rotation) { -#if defined(USE_I2C) && defined(SPLIT_KEYBOARD) +#if defined(USE_I2C) && defined(SPLIT_KEYBOARD) && defined(OLED_TRANSPORT_I2C) if (!is_keyboard_master()) { return true; } @@ -173,47 +298,61 @@ bool oled_init(oled_rotation_t rotation) { } else { oled_rotation_width = OLED_DISPLAY_HEIGHT; } - i2c_init(); + oled_driver_init(); static const uint8_t PROGMEM display_setup1[] = { I2C_CMD, DISPLAY_OFF, DISPLAY_CLOCK, - 0x80, + OLED_DISPLAY_CLOCK, MULTIPLEX_RATIO, +#if OLED_IC_COM_PINS_ARE_COLUMNS + OLED_DISPLAY_WIDTH - 1, +#else OLED_DISPLAY_HEIGHT - 1, - DISPLAY_OFFSET, +#endif +#if OLED_IC == OLED_IC_SH1107 + SH1107_DISPLAY_START_LINE, 0x00, +#else DISPLAY_START_LINE | 0x00, +#endif CHARGE_PUMP, 0x14, -#if (OLED_IC != OLED_IC_SH1106) +#if OLED_IC_HAS_HORIZONTAL_MODE // MEMORY_MODE is unsupported on SH1106 (Page Addressing only) MEMORY_MODE, 0x00, // Horizontal addressing mode +#elif OLED_IC == OLED_IC_SH1107 + // Page addressing mode + SH1107_MEMORY_MODE_PAGE, #endif }; - if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_setup1, ARRAY_SIZE(display_setup1))) { print("oled_init cmd set 1 failed\n"); return false; } if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_180)) { - static const uint8_t PROGMEM display_normal[] = {I2C_CMD, SEGMENT_REMAP_INV, COM_SCAN_DEC}; - if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) { + static const uint8_t PROGMEM display_normal[] = { + I2C_CMD, SEGMENT_REMAP_INV, COM_SCAN_DEC, DISPLAY_OFFSET, OLED_COM_PIN_OFFSET, + }; + if (!oled_send_cmd_P(display_normal, ARRAY_SIZE(display_normal))) { print("oled_init cmd normal rotation failed\n"); return false; } } else { - static const uint8_t PROGMEM display_flipped[] = {I2C_CMD, SEGMENT_REMAP, COM_SCAN_INC}; - if (I2C_TRANSMIT_P(display_flipped) != I2C_STATUS_SUCCESS) { + static const uint8_t PROGMEM display_flipped[] = { + I2C_CMD, SEGMENT_REMAP, COM_SCAN_INC, DISPLAY_OFFSET, (OLED_COM_PIN_COUNT - OLED_COM_PIN_OFFSET) % OLED_COM_PIN_COUNT, + }; + if (!oled_send_cmd_P(display_flipped, ARRAY_SIZE(display_flipped))) { print("display_flipped failed\n"); return false; } } - static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, OLED_BRIGHTNESS, PRE_CHARGE_PERIOD, 0xF1, VCOM_DETECT, 0x20, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON}; - if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) { + static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, OLED_BRIGHTNESS, PRE_CHARGE_PERIOD, OLED_PRE_CHARGE_PERIOD, VCOM_DETECT, OLED_VCOM_DETECT, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON}; + if (!oled_send_cmd_P(display_setup2, ARRAY_SIZE(display_setup2))) { print("display_setup2 failed\n"); return false; } @@ -249,30 +388,49 @@ static void calc_bounds(uint8_t update_start, uint8_t *cmd_array) { // Calculate commands to set memory addressing bounds. uint8_t start_page = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_WIDTH; uint8_t start_column = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_WIDTH; -#if (OLED_IC == OLED_IC_SH1106) +#if !OLED_IC_HAS_HORIZONTAL_MODE // Commands for Page Addressing Mode. Sets starting page and column; has no end bound. // Column value must be split into high and low nybble and sent as two commands. cmd_array[0] = PAM_PAGE_ADDR | start_page; cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f); cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f); - cmd_array[3] = NOP; - cmd_array[4] = NOP; - cmd_array[5] = NOP; #else // Commands for use in Horizontal Addressing mode. - cmd_array[1] = start_column; + cmd_array[1] = start_column + OLED_COLUMN_OFFSET; cmd_array[4] = start_page; cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) % OLED_DISPLAY_WIDTH + cmd_array[1]; - cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) / OLED_DISPLAY_WIDTH - 1; + cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) / OLED_DISPLAY_WIDTH - 1 + cmd_array[4]; #endif } static void calc_bounds_90(uint8_t update_start, uint8_t *cmd_array) { - cmd_array[1] = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8; - cmd_array[4] = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT; + // Block numbering starts from the bottom left corner, going up and then to + // the right. The controller needs the page and column numbers for the top + // left and bottom right corners of that block. + + // Total number of pages across the screen height. + const uint8_t height_in_pages = OLED_DISPLAY_HEIGHT / 8; + + // Difference of starting page numbers for adjacent blocks; may be 0 if + // blocks are large enough to occupy one or more whole 8px columns. + const uint8_t page_inc_per_block = OLED_BLOCK_SIZE % OLED_DISPLAY_HEIGHT / 8; + + // Top page number for a block which is at the bottom edge of the screen. + const uint8_t bottom_block_top_page = (height_in_pages - page_inc_per_block) % height_in_pages; + +#if !OLED_IC_HAS_HORIZONTAL_MODE + // Only the Page Addressing Mode is supported + uint8_t start_page = bottom_block_top_page - (OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT / 8); + uint8_t start_column = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8; + cmd_array[0] = PAM_PAGE_ADDR | start_page; + cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f); + cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f); +#else + cmd_array[1] = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8 + OLED_COLUMN_OFFSET; + cmd_array[4] = bottom_block_top_page - (OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT / 8); cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8 - 1 + cmd_array[1]; - ; - cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) % OLED_DISPLAY_HEIGHT / 8; + cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) % OLED_DISPLAY_HEIGHT / 8 + cmd_array[4]; +#endif } uint8_t crot(uint8_t a, int8_t n) { @@ -309,7 +467,11 @@ void oled_render(void) { } // Set column & page position +#if OLED_IC_HAS_HORIZONTAL_MODE static uint8_t display_start[] = {I2C_CMD, COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1, PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1}; +#else + static uint8_t display_start[] = {I2C_CMD, PAM_PAGE_ADDR, PAM_SETCOLUMN_LSB, PAM_SETCOLUMN_MSB}; +#endif if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start } else { @@ -317,14 +479,14 @@ void oled_render(void) { } // Send column & page position - if (I2C_TRANSMIT(display_start) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd(display_start, ARRAY_SIZE(display_start))) { print("oled_render offset command failed\n"); return; } if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { // Send render data chunk as is - if (I2C_WRITE_REG(I2C_DATA, &oled_buffer[OLED_BLOCK_SIZE * update_start], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) { + if (!oled_send_data(&oled_buffer[OLED_BLOCK_SIZE * update_start], OLED_BLOCK_SIZE)) { print("oled_render data failed\n"); return; } @@ -339,11 +501,32 @@ void oled_render(void) { rotate_90(&oled_buffer[OLED_BLOCK_SIZE * update_start + source_map[i]], &temp_buffer[target_map[i]]); } +#if OLED_IC_HAS_HORIZONTAL_MODE // Send render data chunk after rotating - if (I2C_WRITE_REG(I2C_DATA, &temp_buffer[0], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) { + if (!oled_send_data(&temp_buffer[0], OLED_BLOCK_SIZE)) { print("oled_render90 data failed\n"); return; } +#else + // For SH1106 or SH1107 the data chunk must be split into separate pieces for each page + const uint8_t columns_in_block = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8; + const uint8_t num_pages = OLED_BLOCK_SIZE / columns_in_block; + for (uint8_t i = 0; i < num_pages; ++i) { + // Send column & page position for all pages except the first one + if (i > 0) { + display_start[1]++; + if (!oled_send_cmd(display_start, ARRAY_SIZE(display_start))) { + print("oled_render offset command failed\n"); + return; + } + } + // Send data for the page + if (!oled_send_data(&temp_buffer[columns_in_block * i], columns_in_block)) { + print("oled_render90 data failed\n"); + return; + } + } +#endif } // Clear dirty flag of just rendered block @@ -568,7 +751,7 @@ bool oled_on(void) { #endif if (!oled_active) { - if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_on, ARRAY_SIZE(display_on))) { print("oled_on cmd failed\n"); return oled_active; } @@ -590,7 +773,7 @@ bool oled_off(void) { #endif if (oled_active) { - if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_off, ARRAY_SIZE(display_off))) { print("oled_off cmd failed\n"); return oled_active; } @@ -610,7 +793,7 @@ uint8_t oled_set_brightness(uint8_t level) { uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level}; if (oled_brightness != level) { - if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd(set_contrast, ARRAY_SIZE(set_contrast))) { print("set_brightness cmd failed\n"); return oled_brightness; } @@ -657,7 +840,7 @@ bool oled_scroll_right(void) { // This prevents scrolling of bad data from starting the scroll too early after init if (!oled_dirty && !oled_scrolling) { uint8_t display_scroll_right[] = {I2C_CMD, SCROLL_RIGHT, 0x00, oled_scroll_start, oled_scroll_speed, oled_scroll_end, 0x00, 0xFF, ACTIVATE_SCROLL}; - if (I2C_TRANSMIT(display_scroll_right) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd(display_scroll_right, ARRAY_SIZE(display_scroll_right))) { print("oled_scroll_right cmd failed\n"); return oled_scrolling; } @@ -675,7 +858,7 @@ bool oled_scroll_left(void) { // This prevents scrolling of bad data from starting the scroll too early after init if (!oled_dirty && !oled_scrolling) { uint8_t display_scroll_left[] = {I2C_CMD, SCROLL_LEFT, 0x00, oled_scroll_start, oled_scroll_speed, oled_scroll_end, 0x00, 0xFF, ACTIVATE_SCROLL}; - if (I2C_TRANSMIT(display_scroll_left) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd(display_scroll_left, ARRAY_SIZE(display_scroll_left))) { print("oled_scroll_left cmd failed\n"); return oled_scrolling; } @@ -691,7 +874,7 @@ bool oled_scroll_off(void) { if (oled_scrolling) { static const uint8_t PROGMEM display_scroll_off[] = {I2C_CMD, DEACTIVATE_SCROLL}; - if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_scroll_off, ARRAY_SIZE(display_scroll_off))) { print("oled_scroll_off cmd failed\n"); return oled_scrolling; } @@ -712,14 +895,14 @@ bool oled_invert(bool invert) { if (invert && !oled_inverted) { static const uint8_t PROGMEM display_inverted[] = {I2C_CMD, INVERT_DISPLAY}; - if (I2C_TRANSMIT_P(display_inverted) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_inverted, ARRAY_SIZE(display_inverted))) { print("oled_invert cmd failed\n"); return oled_inverted; } oled_inverted = true; } else if (!invert && oled_inverted) { static const uint8_t PROGMEM display_normal[] = {I2C_CMD, NORMAL_DISPLAY}; - if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) { + if (!oled_send_cmd_P(display_normal, ARRAY_SIZE(display_normal))) { print("oled_invert cmd failed\n"); return oled_inverted; } diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h index 291049e36bd7..627a3da0ba59 100644 --- a/drivers/oled/oled_driver.h +++ b/drivers/oled/oled_driver.h @@ -22,6 +22,7 @@ along with this program. If not, see . // an enumeration of the chips this driver supports #define OLED_IC_SSD1306 0 #define OLED_IC_SH1106 1 +#define OLED_IC_SH1107 2 #if defined(OLED_DISPLAY_CUSTOM) // Expected user to implement the necessary defines @@ -68,6 +69,152 @@ along with this program. If not, see . // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 } // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 } + +#elif defined(OLED_DISPLAY_64X32) +# ifndef OLED_DISPLAY_WIDTH +# define OLED_DISPLAY_WIDTH 64 +# endif +# ifndef OLED_DISPLAY_HEIGHT +# define OLED_DISPLAY_HEIGHT 32 +# endif +# ifndef OLED_COLUMN_OFFSET +# define OLED_COLUMN_OFFSET 32 +# endif +# ifndef OLED_MATRIX_SIZE +# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) +# endif +# ifndef OLED_BLOCK_TYPE +# define OLED_BLOCK_TYPE uint8_t +# endif +# ifndef OLED_BLOCK_COUNT +# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 8 (compile time mathed) +# endif +# ifndef OLED_BLOCK_SIZE +# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) +# endif +# ifndef OLED_COM_PINS +# define OLED_COM_PINS COM_PINS_ALT +# endif + +# ifndef OLED_SOURCE_MAP +# define OLED_SOURCE_MAP \ + { 0, 8, 16, 24 } +# endif +# ifndef OLED_TARGET_MAP +# define OLED_TARGET_MAP \ + { 24, 16, 8, 0 } +# endif + +#elif defined(OLED_DISPLAY_64X48) +# ifndef OLED_DISPLAY_WIDTH +# define OLED_DISPLAY_WIDTH 64 +# endif +# ifndef OLED_DISPLAY_HEIGHT +# define OLED_DISPLAY_HEIGHT 48 +# endif +# ifndef OLED_COLUMN_OFFSET +# define OLED_COLUMN_OFFSET 32 +# endif +# ifndef OLED_MATRIX_SIZE +# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) +# endif +# ifndef OLED_BLOCK_TYPE +# define OLED_BLOCK_TYPE uint32_t +# endif +# ifndef OLED_BLOCK_COUNT +# define OLED_BLOCK_COUNT 24 +# endif +# ifndef OLED_BLOCK_SIZE +# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) +# endif +# ifndef OLED_COM_PINS +# define OLED_COM_PINS COM_PINS_ALT +# endif + +# ifndef OLED_SOURCE_MAP +# define OLED_SOURCE_MAP \ + { 0, 8 } +# endif +# ifndef OLED_TARGET_MAP +# define OLED_TARGET_MAP \ + { 8, 0 } +# endif + +#elif defined(OLED_DISPLAY_64X128) +# ifndef OLED_DISPLAY_WIDTH +# define OLED_DISPLAY_WIDTH 64 +# endif +# ifndef OLED_DISPLAY_HEIGHT +# define OLED_DISPLAY_HEIGHT 128 +# endif +# ifndef OLED_IC +# define OLED_IC OLED_IC_SH1107 +# endif +# ifndef OLED_COM_PIN_OFFSET +# define OLED_COM_PIN_OFFSET 32 +# endif +# ifndef OLED_MATRIX_SIZE +# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) +# endif +# ifndef OLED_BLOCK_TYPE +# define OLED_BLOCK_TYPE uint16_t +# endif +# ifndef OLED_BLOCK_COUNT +# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) +# endif +# ifndef OLED_BLOCK_SIZE +# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) +# endif +# ifndef OLED_COM_PINS +# define OLED_COM_PINS COM_PINS_ALT +# endif + +# ifndef OLED_SOURCE_MAP +# define OLED_SOURCE_MAP \ + { 0, 8, 16, 24, 32, 40, 48, 56 } +# endif +# ifndef OLED_TARGET_MAP +# define OLED_TARGET_MAP \ + { 56, 48, 40, 32, 24, 16, 8, 0 } +# endif + +#elif defined(OLED_DISPLAY_128X128) +// Quad height 128x128 +# ifndef OLED_DISPLAY_WIDTH +# define OLED_DISPLAY_WIDTH 128 +# endif +# ifndef OLED_DISPLAY_HEIGHT +# define OLED_DISPLAY_HEIGHT 128 +# endif +# ifndef OLED_IC +# define OLED_IC OLED_IC_SH1107 +# endif +# ifndef OLED_MATRIX_SIZE +# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 2048 (compile time mathed) +# endif +# ifndef OLED_BLOCK_TYPE +# define OLED_BLOCK_TYPE uint32_t +# endif +# ifndef OLED_BLOCK_COUNT +# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed) +# endif +# ifndef OLED_BLOCK_SIZE +# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 64 (compile time mathed) +# endif +# ifndef OLED_COM_PINS +# define OLED_COM_PINS COM_PINS_ALT +# endif + +// For 90 degree rotation, we map our internal matrix to oled matrix using fixed arrays +// The OLED writes to it's memory horizontally, starting top left, but our memory starts bottom left in this mode +# ifndef OLED_SOURCE_MAP +# define OLED_SOURCE_MAP \ + { 0, 8, 16, 24, 32, 40, 48, 56 } +# endif +# ifndef OLED_TARGET_MAP +# define OLED_TARGET_MAP \ + { 56, 48, 40, 32, 24, 16, 8, 0 } +# endif #else // defined(OLED_DISPLAY_128X64) // Default 128x32 # ifndef OLED_DISPLAY_WIDTH @@ -191,6 +338,12 @@ typedef enum { // Returns true if the OLED was initialized successfully bool oled_init(oled_rotation_t rotation); +// Send commands and data to screen +bool oled_send_cmd(const uint8_t *data, uint16_t size); +bool oled_send_cmd_P(const uint8_t *data, uint16_t size); +bool oled_send_data(const uint8_t *data, uint16_t size); +void oled_driver_init(void); + // Called at the start of oled_init, weak function overridable by the user // rotation - the value passed into oled_init // Return new oled_rotation_t if you want to override default rotation diff --git a/drivers/painter/comms/qp_comms_spi.c b/drivers/painter/comms/qp_comms_spi.c index e644ba9f8449..7534e844d838 100644 --- a/drivers/painter/comms/qp_comms_spi.c +++ b/drivers/painter/comms/qp_comms_spi.c @@ -10,8 +10,8 @@ // Base SPI support bool qp_comms_spi_init(painter_device_t device) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config; // Initialize the SPI peripheral spi_init(); @@ -24,8 +24,8 @@ bool qp_comms_spi_init(painter_device_t device) { } bool qp_comms_spi_start(painter_device_t device) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config; return spi_start(comms_config->chip_select_pin, comms_config->lsb_first, comms_config->mode, comms_config->divisor); } @@ -33,8 +33,10 @@ bool qp_comms_spi_start(painter_device_t device) { uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint32_t byte_count) { uint32_t bytes_remaining = byte_count; const uint8_t *p = (const uint8_t *)data; + const uint32_t max_msg_length = 1024; + while (bytes_remaining > 0) { - uint32_t bytes_this_loop = bytes_remaining < 1024 ? bytes_remaining : 1024; + uint32_t bytes_this_loop = QP_MIN(bytes_remaining, max_msg_length); spi_transmit(p, bytes_this_loop); p += bytes_this_loop; bytes_remaining -= bytes_this_loop; @@ -44,13 +46,13 @@ uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint3 } void qp_comms_spi_stop(painter_device_t device) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config; spi_stop(); writePinHigh(comms_config->chip_select_pin); } -const struct painter_comms_vtable_t spi_comms_vtable = { +const painter_comms_vtable_t spi_comms_vtable = { .comms_init = qp_comms_spi_init, .comms_start = qp_comms_spi_start, .comms_send = qp_comms_spi_send_data, @@ -67,8 +69,8 @@ bool qp_comms_spi_dc_reset_init(painter_device_t device) { return false; } - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config; // Set up D/C as output low, if specified if (comms_config->dc_pin != NO_PIN) { @@ -89,15 +91,15 @@ bool qp_comms_spi_dc_reset_init(painter_device_t device) { } uint32_t qp_comms_spi_dc_reset_send_data(painter_device_t device, const void *data, uint32_t byte_count) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config; writePinHigh(comms_config->dc_pin); return qp_comms_spi_send_data(device, data, byte_count); } void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config; + painter_driver_t * driver = (painter_driver_t *)device; + qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config; writePinLow(comms_config->dc_pin); spi_write(cmd); } @@ -118,7 +120,7 @@ void qp_comms_spi_dc_reset_bulk_command_sequence(painter_device_t device, const } } -const struct painter_comms_with_command_vtable_t spi_comms_with_dc_vtable = { +const painter_comms_with_command_vtable_t spi_comms_with_dc_vtable = { .base = { .comms_init = qp_comms_spi_dc_reset_init, diff --git a/drivers/painter/comms/qp_comms_spi.h b/drivers/painter/comms/qp_comms_spi.h index 99899873272c..b3da86d5733f 100644 --- a/drivers/painter/comms/qp_comms_spi.h +++ b/drivers/painter/comms/qp_comms_spi.h @@ -13,36 +13,36 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Base SPI support -struct qp_comms_spi_config_t { +typedef struct qp_comms_spi_config_t { pin_t chip_select_pin; uint16_t divisor; bool lsb_first; int8_t mode; -}; +} qp_comms_spi_config_t; bool qp_comms_spi_init(painter_device_t device); bool qp_comms_spi_start(painter_device_t device); uint32_t qp_comms_spi_send_data(painter_device_t device, const void* data, uint32_t byte_count); void qp_comms_spi_stop(painter_device_t device); -extern const struct painter_comms_vtable_t spi_comms_vtable; +extern const painter_comms_vtable_t spi_comms_vtable; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SPI with D/C and RST pins # ifdef QUANTUM_PAINTER_SPI_DC_RESET_ENABLE -struct qp_comms_spi_dc_reset_config_t { - struct qp_comms_spi_config_t spi_config; - pin_t dc_pin; - pin_t reset_pin; -}; +typedef struct qp_comms_spi_dc_reset_config_t { + qp_comms_spi_config_t spi_config; + pin_t dc_pin; + pin_t reset_pin; +} qp_comms_spi_dc_reset_config_t; void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd); uint32_t qp_comms_spi_dc_reset_send_data(painter_device_t device, const void* data, uint32_t byte_count); void qp_comms_spi_dc_reset_bulk_command_sequence(painter_device_t device, const uint8_t* sequence, size_t sequence_len); -extern const struct painter_comms_with_command_vtable_t spi_comms_with_dc_vtable; +extern const painter_comms_with_command_vtable_t spi_comms_with_dc_vtable; # endif // QUANTUM_PAINTER_SPI_DC_RESET_ENABLE diff --git a/drivers/painter/gc9a01/qp_gc9a01.c b/drivers/painter/gc9a01/qp_gc9a01.c index 5d079435c60f..a2eb2cf57c03 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.c +++ b/drivers/painter/gc9a01/qp_gc9a01.c @@ -1,4 +1,5 @@ // Copyright 2021 Paul Cotter (@gr1mr3aver) +// Copyright 2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -93,7 +94,7 @@ __attribute__((weak)) bool qp_gc9a01_init(painter_device_t device, painter_rotat // Driver vtable //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -const struct tft_panel_dc_reset_painter_driver_vtable_t gc9a01_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t gc9a01_driver_vtable = { .base = { .init = qp_gc9a01_init, @@ -124,8 +125,8 @@ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_ for (uint32_t i = 0; i < GC9A01_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &gc9a01_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&gc9a01_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&gc9a01_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.native_bits_per_pixel = 16; // RGB565 driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; @@ -141,6 +142,12 @@ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_ driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/generic/qp_rgb565_surface.c b/drivers/painter/generic/qp_rgb565_surface.c index 474c86feec32..9c283e06872d 100644 --- a/drivers/painter/generic/qp_rgb565_surface.c +++ b/drivers/painter/generic/qp_rgb565_surface.c @@ -9,7 +9,7 @@ // Device definition typedef struct rgb565_surface_painter_device_t { - struct painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type + painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type // The target buffer uint16_t *buffer; @@ -95,7 +95,7 @@ static inline void stream_pixdata(rgb565_surface_painter_device_t *surface, cons // Driver vtable static bool qp_rgb565_surface_init(painter_device_t device, painter_rotation_t rotation) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; + painter_driver_t * driver = (painter_driver_t *)device; rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver; memset(surface->buffer, 0, driver->panel_width * driver->panel_height * driver->native_bits_per_pixel / 8); return true; @@ -107,13 +107,13 @@ static bool qp_rgb565_surface_power(painter_device_t device, bool power_on) { } static bool qp_rgb565_surface_clear(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; driver->driver_vtable->init(device, driver->rotation); // Re-init the surface return true; } static bool qp_rgb565_surface_flush(painter_device_t device) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; + painter_driver_t * driver = (painter_driver_t *)device; rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver; surface->dirty_l = surface->dirty_t = UINT16_MAX; surface->dirty_r = surface->dirty_b = 0; @@ -122,7 +122,7 @@ static bool qp_rgb565_surface_flush(painter_device_t device) { } static bool qp_rgb565_surface_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; + painter_driver_t * driver = (painter_driver_t *)device; rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver; // Set the viewport locations @@ -139,7 +139,7 @@ static bool qp_rgb565_surface_viewport(painter_device_t device, uint16_t left, u // Stream pixel data to the current write position in GRAM static bool qp_rgb565_surface_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; + painter_driver_t * driver = (painter_driver_t *)device; rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver; stream_pixdata(surface, (const uint16_t *)pixel_data, native_pixel_count); return true; @@ -170,7 +170,7 @@ static bool qp_rgb565_surface_append_pixdata(painter_device_t device, uint8_t *t return true; } -const struct painter_driver_vtable_t rgb565_surface_driver_vtable = { +const painter_driver_vtable_t rgb565_surface_driver_vtable = { .init = qp_rgb565_surface_init, .power = qp_rgb565_surface_power, .clear = qp_rgb565_surface_clear, @@ -201,7 +201,7 @@ uint32_t qp_rgb565_surface_comms_send(painter_device_t device, const void *data, return byte_count; } -struct painter_comms_vtable_t rgb565_surface_driver_comms_vtable = { +painter_comms_vtable_t rgb565_surface_driver_comms_vtable = { // These are all effective no-op's because they're not actually needed. .comms_init = qp_rgb565_surface_comms_init, .comms_start = qp_rgb565_surface_comms_start, @@ -234,7 +234,7 @@ painter_device_t qp_rgb565_make_surface(uint16_t panel_width, uint16_t panel_hei // Drawing routine to copy out the dirty region and send it to another device bool qp_rgb565_surface_draw(painter_device_t surface, painter_device_t display, uint16_t x, uint16_t y) { - struct painter_driver_t * surface_driver = (struct painter_driver_t *)surface; + painter_driver_t * surface_driver = (painter_driver_t *)surface; rgb565_surface_painter_device_t *surface_handle = (rgb565_surface_painter_device_t *)surface_driver; // If we're not dirty... we're done. diff --git a/drivers/painter/ili9xxx/qp_ili9163.c b/drivers/painter/ili9xxx/qp_ili9163.c index af37686631fe..a75be5790486 100644 --- a/drivers/painter/ili9xxx/qp_ili9163.c +++ b/drivers/painter/ili9xxx/qp_ili9163.c @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -58,7 +58,7 @@ __attribute__((weak)) bool qp_ili9163_init(painter_device_t device, painter_rota //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t ili9163_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t ili9163_driver_vtable = { .base = { .init = qp_ili9163_init, @@ -93,8 +93,8 @@ painter_device_t qp_ili9163_make_spi_device(uint16_t panel_width, uint16_t panel for (uint32_t i = 0; i < ILI9163_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &ili9163_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9163_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9163_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; driver->base.rotation = QP_ROTATION_0; @@ -110,6 +110,12 @@ painter_device_t qp_ili9163_make_spi_device(uint16_t panel_width, uint16_t panel driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/ili9xxx/qp_ili9341.c b/drivers/painter/ili9xxx/qp_ili9341.c index aca380991225..4130271f71b4 100644 --- a/drivers/painter/ili9xxx/qp_ili9341.c +++ b/drivers/painter/ili9xxx/qp_ili9341.c @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -65,7 +65,7 @@ __attribute__((weak)) bool qp_ili9341_init(painter_device_t device, painter_rota //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t ili9341_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t ili9341_driver_vtable = { .base = { .init = qp_ili9341_init, @@ -100,8 +100,8 @@ painter_device_t qp_ili9341_make_spi_device(uint16_t panel_width, uint16_t panel for (uint32_t i = 0; i < ILI9341_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &ili9341_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9341_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9341_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.native_bits_per_pixel = 16; // RGB565 driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; @@ -117,6 +117,12 @@ painter_device_t qp_ili9341_make_spi_device(uint16_t panel_width, uint16_t panel driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/ili9xxx/qp_ili9488.c b/drivers/painter/ili9xxx/qp_ili9488.c index e51f0e1d5133..a8da52132e0f 100644 --- a/drivers/painter/ili9xxx/qp_ili9488.c +++ b/drivers/painter/ili9xxx/qp_ili9488.c @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -58,7 +58,7 @@ __attribute__((weak)) bool qp_ili9488_init(painter_device_t device, painter_rota //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t ili9488_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t ili9488_driver_vtable = { .base = { .init = qp_ili9488_init, @@ -93,8 +93,8 @@ painter_device_t qp_ili9488_make_spi_device(uint16_t panel_width, uint16_t panel for (uint32_t i = 0; i < ILI9488_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &ili9488_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9488_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9488_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.native_bits_per_pixel = 24; // RGB888 driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; @@ -110,6 +110,12 @@ painter_device_t qp_ili9488_make_spi_device(uint16_t panel_width, uint16_t panel driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h b/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h index 47bb70364898..f57e638e0348 100644 --- a/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h +++ b/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h @@ -19,8 +19,8 @@ #define ILI9XXX_CMD_SLEEP_OFF 0x11 // Exist sleep mode #define ILI9XXX_CMD_PARTIAL_ON 0x12 // Enter partial mode #define ILI9XXX_CMD_PARTIAL_OFF 0x13 // Exit partial mode -#define ILI9XXX_CMD_INVERT_ON 0x20 // Enter inverted mode -#define ILI9XXX_CMD_INVERT_OFF 0x21 // Exit inverted mode +#define ILI9XXX_CMD_INVERT_OFF 0x20 // Exit inverted mode +#define ILI9XXX_CMD_INVERT_ON 0x21 // Enter inverted mode #define ILI9XXX_SET_GAMMA 0x26 // Set gamma params #define ILI9XXX_CMD_DISPLAY_OFF 0x28 // Disable display #define ILI9XXX_CMD_DISPLAY_ON 0x29 // Enable display diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c index 548785a1bd00..434b7f032781 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.c +++ b/drivers/painter/ssd1351/qp_ssd1351.c @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -62,7 +62,7 @@ __attribute__((weak)) bool qp_ssd1351_init(painter_device_t device, painter_rota //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable = { .base = { .init = qp_ssd1351_init, @@ -97,8 +97,8 @@ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel for (uint32_t i = 0; i < SSD1351_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &ssd1351_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ssd1351_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&ssd1351_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; driver->base.rotation = QP_ROTATION_0; @@ -114,6 +114,12 @@ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/st77xx/qp_st7735.c b/drivers/painter/st77xx/qp_st7735.c index 7ee5a6b562ca..98baf400abfb 100644 --- a/drivers/painter/st77xx/qp_st7735.c +++ b/drivers/painter/st77xx/qp_st7735.c @@ -1,5 +1,5 @@ // Copyright 2021 Paul Cotter (@gr1mr3aver) -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // Copyright 2022 David Hoelscher (@customMK) // SPDX-License-Identifier: GPL-2.0-or-later @@ -25,7 +25,7 @@ tft_panel_dc_reset_painter_device_t st7735_drivers[ST7735_NUM_DEVICES] = {0}; #ifndef ST7735_NO_AUTOMATIC_OFFSETS static inline void st7735_automatic_viewport_offsets(painter_device_t device, painter_rotation_t rotation) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; // clang-format off const struct { @@ -82,7 +82,7 @@ __attribute__((weak)) bool qp_st7735_init(painter_device_t device, painter_rotat //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t st7735_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t st7735_driver_vtable = { .base = { .init = qp_st7735_init, @@ -117,8 +117,8 @@ painter_device_t qp_st7735_make_spi_device(uint16_t panel_width, uint16_t panel_ for (uint32_t i = 0; i < ST7735_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &st7735_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&st7735_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&st7735_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; driver->base.rotation = QP_ROTATION_0; @@ -134,6 +134,12 @@ painter_device_t qp_st7735_make_spi_device(uint16_t panel_width, uint16_t panel_ driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/st77xx/qp_st7789.c b/drivers/painter/st77xx/qp_st7789.c index 9f474369d6b0..f9065f5178b0 100644 --- a/drivers/painter/st77xx/qp_st7789.c +++ b/drivers/painter/st77xx/qp_st7789.c @@ -1,5 +1,5 @@ // Copyright 2021 Paul Cotter (@gr1mr3aver) -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -24,7 +24,7 @@ tft_panel_dc_reset_painter_device_t st7789_drivers[ST7789_NUM_DEVICES] = {0}; #ifndef ST7789_NO_AUTOMATIC_OFFSETS static inline void st7789_automatic_viewport_offsets(painter_device_t device, painter_rotation_t rotation) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; // clang-format off const struct { @@ -81,7 +81,7 @@ __attribute__((weak)) bool qp_st7789_init(painter_device_t device, painter_rotat //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable -const struct tft_panel_dc_reset_painter_driver_vtable_t st7789_driver_vtable = { +const tft_panel_dc_reset_painter_driver_vtable_t st7789_driver_vtable = { .base = { .init = qp_st7789_init, @@ -116,8 +116,8 @@ painter_device_t qp_st7789_make_spi_device(uint16_t panel_width, uint16_t panel_ for (uint32_t i = 0; i < ST7789_NUM_DEVICES; ++i) { tft_panel_dc_reset_painter_device_t *driver = &st7789_drivers[i]; if (!driver->base.driver_vtable) { - driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&st7789_driver_vtable; - driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable; + driver->base.driver_vtable = (const painter_driver_vtable_t *)&st7789_driver_vtable; + driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable; driver->base.panel_width = panel_width; driver->base.panel_height = panel_height; driver->base.rotation = QP_ROTATION_0; @@ -133,6 +133,12 @@ painter_device_t qp_st7789_make_spi_device(uint16_t panel_width, uint16_t panel_ driver->spi_dc_reset_config.spi_config.mode = spi_mode; driver->spi_dc_reset_config.dc_pin = dc_pin; driver->spi_dc_reset_config.reset_pin = reset_pin; + + if (!qp_internal_register_device((painter_device_t)driver)) { + memset(driver, 0, sizeof(tft_panel_dc_reset_painter_device_t)); + return NULL; + } + return (painter_device_t)driver; } } diff --git a/drivers/painter/tft_panel/qp_tft_panel.c b/drivers/painter/tft_panel/qp_tft_panel.c index 4a24cf9953d7..16dba9d6a639 100644 --- a/drivers/painter/tft_panel/qp_tft_panel.c +++ b/drivers/painter/tft_panel/qp_tft_panel.c @@ -12,15 +12,15 @@ // Power control bool qp_tft_panel_power(painter_device_t device, bool power_on) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct tft_panel_dc_reset_painter_driver_vtable_t *vtable = (struct tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable; + painter_driver_t * driver = (painter_driver_t *)device; + tft_panel_dc_reset_painter_driver_vtable_t *vtable = (tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable; qp_comms_command(device, power_on ? vtable->opcodes.display_on : vtable->opcodes.display_off); return true; } // Screen clear bool qp_tft_panel_clear(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; driver->driver_vtable->init(device, driver->rotation); // Re-init the LCD return true; } @@ -33,8 +33,8 @@ bool qp_tft_panel_flush(painter_device_t device) { // Viewport to draw to bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct tft_panel_dc_reset_painter_driver_vtable_t *vtable = (struct tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable; + painter_driver_t * driver = (painter_driver_t *)device; + tft_panel_dc_reset_painter_driver_vtable_t *vtable = (tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable; // Fix up the drawing location if required left += driver->offset_x; @@ -80,7 +80,7 @@ bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, // Stream pixel data to the current write position in GRAM bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; qp_comms_send(device, pixel_data, native_pixel_count * driver->native_bits_per_pixel / 8); return true; } diff --git a/drivers/painter/tft_panel/qp_tft_panel.h b/drivers/painter/tft_panel/qp_tft_panel.h index 83b8dd54068c..67168645b7e2 100644 --- a/drivers/painter/tft_panel/qp_tft_panel.h +++ b/drivers/painter/tft_panel/qp_tft_panel.h @@ -12,8 +12,8 @@ // Common TFT panel implementation using D/C, and RST pins. // Driver vtable with extras -struct tft_panel_dc_reset_painter_driver_vtable_t { - struct painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type +typedef struct tft_panel_dc_reset_painter_driver_vtable_t { + painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type // Number of bytes for transmitting x/y coordinates uint8_t num_window_bytes; @@ -29,16 +29,16 @@ struct tft_panel_dc_reset_painter_driver_vtable_t { uint8_t set_row_address; uint8_t enable_writes; } opcodes; -}; +} tft_panel_dc_reset_painter_driver_vtable_t; // Device definition typedef struct tft_panel_dc_reset_painter_device_t { - struct painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type + painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type union { #ifdef QUANTUM_PAINTER_SPI_ENABLE // SPI-based configurables - struct qp_comms_spi_dc_reset_config_t spi_dc_reset_config; + qp_comms_spi_dc_reset_config_t spi_dc_reset_config; #endif // QUANTUM_PAINTER_SPI_ENABLE // TODO: I2C/parallel etc. diff --git a/drivers/ps2/ps2_interrupt.c b/drivers/ps2/ps2_interrupt.c index 2810a0f1267b..f7400564ef9e 100644 --- a/drivers/ps2/ps2_interrupt.c +++ b/drivers/ps2/ps2_interrupt.c @@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. // chibiOS headers # include "ch.h" # include "hal.h" +# include "gpio.h" #endif #include "ps2.h" diff --git a/drivers/ps2/ps2_mouse.c b/drivers/ps2/ps2_mouse.c index b32ad1e222d4..ae594c94bc5e 100644 --- a/drivers/ps2/ps2_mouse.c +++ b/drivers/ps2/ps2_mouse.c @@ -81,10 +81,10 @@ void ps2_mouse_task(void) { rcv = ps2_host_send(PS2_MOUSE_READ_DATA); if (rcv == PS2_ACK) { mouse_report.buttons = ps2_host_recv_response(); - mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER; - mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER; + mouse_report.x = ps2_host_recv_response(); + mouse_report.y = ps2_host_recv_response(); # ifdef PS2_MOUSE_ENABLE_SCROLLING - mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER; + mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK); # endif } else { if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); @@ -92,10 +92,10 @@ void ps2_mouse_task(void) { #else if (pbuf_has_data()) { mouse_report.buttons = ps2_host_recv_response(); - mouse_report.x = ps2_host_recv_response() * PS2_MOUSE_X_MULTIPLIER; - mouse_report.y = ps2_host_recv_response() * PS2_MOUSE_Y_MULTIPLIER; + mouse_report.x = ps2_host_recv_response(); + mouse_report.y = ps2_host_recv_response(); # ifdef PS2_MOUSE_ENABLE_SCROLLING - mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK) * PS2_MOUSE_V_MULTIPLIER; + mouse_report.v = -(ps2_host_recv_response() & PS2_MOUSE_SCROLL_MASK); # endif } else { if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); @@ -168,6 +168,7 @@ void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate) { #define X_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_X_OVFLW)) #define Y_IS_OVF (mouse_report->buttons & (1 << PS2_MOUSE_Y_OVFLW)) static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) { +#ifndef MOUSE_EXTENDED_REPORT // PS/2 mouse data is '9-bit integer'(-256 to 255) which is comprised of sign-bit and 8-bit value. // bit: 8 7 ... 0 // sign \8-bit/ @@ -175,18 +176,27 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) // Meanwhile USB HID mouse indicates 8bit data(-127 to 127), note that -128 is not used. // // This converts PS/2 data into HID value. Use only -127-127 out of PS/2 9-bit. + mouse_report->x *= PS2_MOUSE_X_MULTIPLIER; + mouse_report->y *= PS2_MOUSE_Y_MULTIPLIER; mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127); mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127); +#else + // Sign extend if negative, otherwise leave positive 8-bits as-is + mouse_report->x = X_IS_NEG ? (mouse_report->x | ~0xFF) : mouse_report->x; + mouse_report->y = Y_IS_NEG ? (mouse_report->y | ~0xFF) : mouse_report->y; + mouse_report->x *= PS2_MOUSE_X_MULTIPLIER; + mouse_report->y *= PS2_MOUSE_Y_MULTIPLIER; +#endif + mouse_report->v *= PS2_MOUSE_V_MULTIPLIER; #ifdef PS2_MOUSE_INVERT_BUTTONS // swap left & right buttons - uint8_t needs_left = mouse_report->buttons & PS2_MOUSE_BTN_RIGHT; - uint8_t needs_right = mouse_report->buttons & PS2_MOUSE_BTN_LEFT; - mouse_report->buttons = (mouse_report->buttons & ~(PS2_MOUSE_BTN_MASK)) | (needs_left ? PS2_MOUSE_BTN_LEFT : 0) | (needs_right ? PS2_MOUSE_BTN_RIGHT : 0); -#else + bool needs_left = mouse_report->buttons & (1 << PS2_MOUSE_BTN_RIGHT); + bool needs_right = mouse_report->buttons & (1 << PS2_MOUSE_BTN_LEFT); + mouse_report->buttons = (mouse_report->buttons & ~((1 << PS2_MOUSE_BTN_LEFT) | (1 << PS2_MOUSE_BTN_RIGHT))) | (needs_left << PS2_MOUSE_BTN_LEFT) | (needs_right << PS2_MOUSE_BTN_RIGHT); +#endif // remove sign and overflow flags mouse_report->buttons &= PS2_MOUSE_BTN_MASK; -#endif #ifdef PS2_MOUSE_INVERT_X mouse_report->x = -mouse_report->x; @@ -197,8 +207,8 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) #endif #ifdef PS2_MOUSE_ROTATE - int8_t x = mouse_report->x; - int8_t y = mouse_report->y; + mouse_xy_report_t x = mouse_report->x; + mouse_xy_report_t y = mouse_report->y; # if PS2_MOUSE_ROTATE == 90 mouse_report->x = y; mouse_report->y = -x; diff --git a/drivers/sensors/pmw3320.c b/drivers/sensors/pmw3320.c new file mode 100644 index 000000000000..a4648ef425b0 --- /dev/null +++ b/drivers/sensors/pmw3320.c @@ -0,0 +1,192 @@ +/* Copyright 2021 Colin Lam (Ploopy Corporation) + * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * Copyright 2019 Sunjun Kim + * Copyright 2019 Hiroyuki Okada + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "pmw3320.h" +#include "wait.h" +#include "debug.h" +#include "gpio.h" + +void pmw3320_init(void) { + // Initialize sensor serial pins. + setPinOutput(PMW3320_SCLK_PIN); + setPinOutput(PMW3320_SDIO_PIN); + setPinOutput(PMW3320_CS_PIN); + + // reboot the sensor. + pmw3320_write_reg(REG_Power_Up_Reset, 0x5a); + + // wait maximum time before sensor is ready. + // this ensures that the sensor is actually ready after reset. + wait_ms(55); + + // read a burst from the sensor and then discard it. + // gets the sensor ready for write commands + // (for example, setting the dpi). + pmw3320_read_burst(); + + // Pretty sure that this shouldn't be in the driver. + // Probably device specific? + // Set rest mode to default + pmw3320_write_reg(REG_Rest_Mode_Status, 0x00); + // Set LED to be always on + pmw3320_write_reg(REG_Led_Control, 0x4); + // Disable rest mode + pmw3320_write_reg(REG_Performance, 0x80); +} + +// Perform a synchronization with sensor. +// Just as with the serial protocol, this is used by the slave to send a +// synchronization signal to the master. +void pmw3320_sync(void) { + writePinLow(PMW3320_CS_PIN); + wait_us(1); + writePinHigh(PMW3320_CS_PIN); +} + +void pmw3320_cs_select(void) { + writePinLow(PMW3320_CS_PIN); +} + +void pmw3320_cs_deselect(void) { + writePinHigh(PMW3320_CS_PIN); +} + +uint8_t pmw3320_serial_read(void) { + setPinInput(PMW3320_SDIO_PIN); + uint8_t byte = 0; + + for (uint8_t i = 0; i < 8; ++i) { + writePinLow(PMW3320_SCLK_PIN); + wait_us(1); + + byte = (byte << 1) | readPin(PMW3320_SDIO_PIN); + + writePinHigh(PMW3320_SCLK_PIN); + wait_us(1); + } + + return byte; +} + +void pmw3320_serial_write(uint8_t data) { + setPinOutput(PMW3320_SDIO_PIN); + + for (int8_t b = 7; b >= 0; b--) { + writePinLow(PMW3320_SCLK_PIN); + + if (data & (1 << b)) + writePinHigh(PMW3320_SDIO_PIN); + else + writePinLow(PMW3320_SDIO_PIN); + + wait_us(2); + + writePinHigh(PMW3320_SCLK_PIN); + } + + // This was taken from ADNS5050 driver. + // There's no any info in PMW3320 datasheet about this... + // tSWR. See page 15 of the ADNS5050 spec sheet. + // Technically, this is only necessary if the next operation is an SDIO + // read. This is not guaranteed to be the case, but we're being lazy. + wait_us(4); + + // Note that tSWW is never necessary. All write operations require at + // least 32us, which exceeds tSWW, so there's never a need to wait for it. +} + +// Read a byte of data from a register on the sensor. +uint8_t pmw3320_read_reg(uint8_t reg_addr) { + pmw3320_cs_select(); + + pmw3320_serial_write(reg_addr); + + uint8_t byte = pmw3320_serial_read(); + + // This was taken directly from ADNS5050 driver... + // tSRW & tSRR. See page 15 of the ADNS5050 spec sheet. + // Technically, this is only necessary if the next operation is an SDIO + // read or write. This is not guaranteed to be the case. + // Honestly, this wait could probably be removed. + wait_us(1); + + pmw3320_cs_deselect(); + + return byte; +} + +void pmw3320_write_reg(uint8_t reg_addr, uint8_t data) { + pmw3320_cs_select(); + pmw3320_serial_write(0b10000000 | reg_addr); + pmw3320_serial_write(data); + pmw3320_cs_deselect(); +} + +report_pmw3320_t pmw3320_read_burst(void) { + pmw3320_cs_select(); + + report_pmw3320_t data; + data.dx = 0; + data.dy = 0; + + pmw3320_serial_write(REG_Motion_Burst); + + uint8_t x = pmw3320_serial_read(); + uint8_t y = pmw3320_serial_read(); + + // Probably burst mode may include contents of delta_xy register, + // which contain HI parts of x/y deltas, but I had no luck finding it. + // Probably it's required to activate 12-bit mode to access this data. + // So we end burst mode early to not read unneeded information. + pmw3320_cs_deselect(); + + data.dx = convert_twoscomp(x); + data.dy = convert_twoscomp(y); + + return data; +} + +// Convert a two's complement byte from an unsigned data type into a signed +// data type. +int8_t convert_twoscomp(uint8_t data) { + if ((data & 0x80) == 0x80) + return -128 + (data & 0x7F); + else + return data; +} + +uint16_t pmw3320_get_cpi(void) { + uint8_t cpival = pmw3320_read_reg(REG_Resolution); + // 0x1F is an inversion of 0x20 which is 0b100000 + return (uint16_t)((cpival & 0x1F) * PMW3320_CPI_STEP); +} + +void pmw3320_set_cpi(uint16_t cpi) { + uint8_t cpival = constrain((cpi / PMW3320_CPI_STEP) - 1U, 0, (PMW3320_CPI_MAX / PMW3320_CPI_STEP) - 1U); + // Fifth bit is probably a control bit. + // PMW3320 datasheet don't have any info on this, so this is a pure guess. + pmw3320_write_reg(REG_Resolution, 0x20 | cpival); +} + +bool pmw3320_check_signature(void) { + uint8_t pid = pmw3320_read_reg(REG_Product_ID); + uint8_t pid2 = pmw3320_read_reg(REG_Inverse_Product_ID); + + return (pid == 0x3b && pid2 == 0xc4); +} diff --git a/drivers/sensors/pmw3320.h b/drivers/sensors/pmw3320.h new file mode 100644 index 000000000000..a1fd5469196a --- /dev/null +++ b/drivers/sensors/pmw3320.h @@ -0,0 +1,119 @@ +/* Copyright 2021 Colin Lam (Ploopy Corporation) + * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * Copyright 2019 Sunjun Kim + * Copyright 2019 Hiroyuki Okada + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) + +// Definitions for the PMW3320 serial line. +#ifndef PMW3320_SCLK_PIN +# ifdef POINTING_DEVICE_SCLK_PIN +# define PMW3320_SCLK_PIN POINTING_DEVICE_SCLK_PIN +# else +# error "No clock pin defined -- missing POINTING_DEVICE_SCLK_PIN or PMW3320_SCLK_PIN" +# endif +#endif + +#ifndef PMW3320_SDIO_PIN +# ifdef POINTING_DEVICE_SDIO_PIN +# define PMW3320_SDIO_PIN POINTING_DEVICE_SDIO_PIN +# else +# error "No data pin defined -- missing POINTING_DEVICE_SDIO_PIN or PMW3320_SDIO_PIN" +# endif +#endif + +#ifndef PMW3320_CS_PIN +# ifdef POINTING_DEVICE_CS_PIN +# define PMW3320_CS_PIN POINTING_DEVICE_CS_PIN +# else +# error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or PMW3320_CS_PIN define" +# endif +#endif + +typedef struct { + int8_t dx; + int8_t dy; +} report_pmw3320_t; + +// A bunch of functions to implement the PMW3320-specific serial protocol. +// Mostly taken from ADNS5050 driver. +// Note that the "serial.h" driver is insufficient, because it does not +// manually manipulate a serial clock signal. +void pmw3320_init(void); +void pmw3320_sync(void); +uint8_t pmw3320_serial_read(void); +void pmw3320_serial_write(uint8_t data); +uint8_t pmw3320_read_reg(uint8_t reg_addr); +void pmw3320_write_reg(uint8_t reg_addr, uint8_t data); +report_pmw3320_t pmw3320_read_burst(void); +void pmw3320_set_cpi(uint16_t cpi); +uint16_t pmw3320_get_cpi(void); +int8_t convert_twoscomp(uint8_t data); +bool pmw3320_check_signature(void); + +#if !defined(PMW3320_CPI) +# define PMW3320_CPI 1000 +#endif + +#define PMW3320_CPI_STEP 250 +#define PMW3320_CPI_MIN 250 +#define PMW3320_CPI_MAX 3500 + +// PMW3320 register addresses +// clang-format off +#define REG_Product_ID 0x00 +#define REG_Revision_ID 0x01 +#define REG_Motion 0x02 +#define REG_Delta_X 0x03 +#define REG_Delta_Y 0x04 +#define REG_SQUAL 0x05 +#define REG_Shutter_Upper 0x06 +#define REG_Shutter_Lower 0x07 +#define REG_Maximum_Pixel 0x08 +#define REG_Pixel_Accum 0x09 +#define REG_Minimum_Pixel 0x0a +#define REG_Pixel_Grab 0x0b +#define REG_Delta_XY 0x0c +#define REG_Resolution 0x0d +#define REG_Run_Downshift 0x0e +#define REG_Rest1_Period 0x0f +#define REG_Rest1_Downshift 0x10 +#define REG_Rest2_Preiod 0x11 +#define REG_Rest2_Downshift 0x12 +#define REG_Rest3_Period 0x13 +#define REG_Min_SQ_Run 0x17 +#define REG_Axis_Control 0x1a +#define REG_Performance 0x22 +#define REG_Low_Motion_Jitter 0x23 +#define REG_Shutter_Max_HI 0x36 +#define REG_Shutter_Max_LO 0x37 +#define REG_Frame_Rate 0x39 +#define REG_Power_Up_Reset 0x3a +#define REG_Shutdown 0x3b +#define REG_Inverse_Revision_ID 0x3f +#define REG_Led_Control 0x40 +#define REG_Motion_Control 0x41 +#define REG_Burst_Read_First 0x42 +#define REG_Rest_Mode_Status 0x45 +#define REG_Inverse_Product_ID 0x4f +#define REG_Motion_Burst 0x63 +// clang-format on diff --git a/drivers/sensors/pmw33xx_common.h b/drivers/sensors/pmw33xx_common.h index 88523b8420ac..b30ee3d59667 100644 --- a/drivers/sensors/pmw33xx_common.h +++ b/drivers/sensors/pmw33xx_common.h @@ -10,7 +10,7 @@ #pragma once -#include "quantum.h" //to get is_keyboard_left +#include "keyboard.h" #include #include "spi_master.h" #include "util.h" diff --git a/keyboards/ergodox_ez/190hotfix.sh b/keyboards/ergodox_ez/190hotfix.sh deleted file mode 100644 index bdc3adce2257..000000000000 --- a/keyboards/ergodox_ez/190hotfix.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -#a tool to fix broken keymaps as a result of pull request #190 -#changing the declaration of matrix_scan_user() and matrix_init_user() -# -#This script will save a copy of the specified keymap as keymap.c.bak -#and then create a new keymap.c with the definion corrected. -#this script must be run from the ergodox_ez directory -if [ $# -ne 1 ]; then - echo $0: usage: ./190hotfix keymap_name - exit 1 -fi - -echo Saving backup as ./keymaps/$1/keymap.c.bak ... -mv ./keymaps/$1/keymap.c ./keymaps/$1/keymap.c.bak - -echo Modifying ./keymaps/$1/keymap.c ... -cat ./keymaps/$1/keymap.c.bak | sed -r 's/^void \* matrix_/void matrix_/'>./keymaps/$1/keymap.c - -echo Complete! diff --git a/keyboards/ergodox_ez/config.h b/keyboards/ergodox_ez/config.h index 92014d8b0c8d..b837192a390f 100644 --- a/keyboards/ergodox_ez/config.h +++ b/keyboards/ergodox_ez/config.h @@ -44,10 +44,10 @@ along with this program. If not, see . #define MOUSEKEY_WHEEL_MAX_SPEED MOUSEKEY_MAX_SPEED #define MOUSEKEY_WHEEL_TIME_TO_MAX MOUSEKEY_TIME_TO_MAX -#define TAPPING_TOGGLE 1 - -#define TAPPING_TERM 200 -#define IGNORE_MOD_TAP_INTERRUPT // this makes it possible to do rolling combos (zx) with keys that convert to other keys on hold (z becomes ctrl when you hold it, and when this option isn't enabled, z rapidly followed by x actually sends Ctrl-x. That's bad.) +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE /* key combination for command */ #define IS_COMMAND() ( \ @@ -63,22 +63,6 @@ along with this program. If not, see . #endif #define LED_BRIGHTNESS_DEFAULT (LED_BRIGHTNESS_HI) -/* ws2812 RGB LED */ -#define RGB_DI_PIN D7 -#define RGBLIGHT_EFFECT_BREATHING -#define RGBLIGHT_EFFECT_RAINBOW_MOOD -#define RGBLIGHT_EFFECT_RAINBOW_SWIRL -#define RGBLIGHT_EFFECT_SNAKE -#define RGBLIGHT_EFFECT_KNIGHT -#define RGBLIGHT_EFFECT_CHRISTMAS -#define RGBLIGHT_EFFECT_STATIC_GRADIENT -#define RGBLIGHT_EFFECT_RGB_TEST -#define RGBLIGHT_EFFECT_ALTERNATING -#define RGBLIGHT_EFFECT_TWINKLE -#define RGBLIGHT_HUE_STEP 12 -#define RGBLIGHT_SAT_STEP 255 -#define RGBLIGHT_VAL_STEP 12 - // Pick one of the modes // Defaults to 15 mirror, for legacy behavior @@ -91,8 +75,6 @@ along with this program. If not, see . #define RGBW -#define RGBLIGHT_SLEEP - /* * The debounce filtering reports a key/switch change directly, * without any extra delay. After that the debounce logic will filter @@ -153,21 +135,21 @@ along with this program. If not, see . #define ENABLE_RGB_MATRIX_PIXEL_FLOW #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL // enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined -#define ENABLE_RGB_MATRIX_TYPING_HEATMAP -#define ENABLE_RGB_MATRIX_DIGITAL_RAIN +// #define ENABLE_RGB_MATRIX_TYPING_HEATMAP +// #define ENABLE_RGB_MATRIX_DIGITAL_RAIN // enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -#define ENABLE_RGB_MATRIX_SPLASH -#define ENABLE_RGB_MATRIX_MULTISPLASH -#define ENABLE_RGB_MATRIX_SOLID_SPLASH -#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +// #define ENABLE_RGB_MATRIX_SPLASH +// #define ENABLE_RGB_MATRIX_MULTISPLASH +// #define ENABLE_RGB_MATRIX_SOLID_SPLASH +// #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH #define TAPPING_TOGGLE 1 diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index 0f95e7cf96c4..d7c7c35d05fc 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -398,7 +398,7 @@ static bool is_on = false; static bool is_dynamic_recording = false; static uint16_t dynamic_loop_timer; -void dynamic_macro_record_start_user(void) { +void dynamic_macro_record_start_user(int8_t direction) { is_dynamic_recording = true; dynamic_loop_timer = timer_read(); ergodox_right_led_1_on(); diff --git a/keyboards/ergodox_ez/ergodox_ez.h b/keyboards/ergodox_ez/ergodox_ez.h index b8b4667ef054..de32d70f40bf 100644 --- a/keyboards/ergodox_ez/ergodox_ez.h +++ b/keyboards/ergodox_ez/ergodox_ez.h @@ -25,12 +25,6 @@ along with this program. If not, see . #include #include "i2c_master.h" -#if defined(KEYBOARD_ergodox_ez_glow) -# include "glow.h" -#elif defined(KEYBOARD_ergodox_ez_shine) -# include "shine.h" -#endif - // I2C aliases and register addresses (see "mcp23018.md") #define I2C_ADDR 0b0100000 #define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE ) @@ -143,171 +137,3 @@ typedef union { } keyboard_config_t; extern keyboard_config_t keyboard_config; - -/* - * LEFT HAND: LINES 115-122 - * RIGHT HAND: LINES 124-131 - */ -#define LAYOUT_ergodox( \ - \ - k00,k01,k02,k03,k04,k05,k06, \ - k10,k11,k12,k13,k14,k15,k16, \ - k20,k21,k22,k23,k24,k25, \ - k30,k31,k32,k33,k34,k35,k36, \ - k40,k41,k42,k43,k44, \ - k55,k56, \ - k54, \ - k53,k52,k51, \ - \ - k07,k08,k09,k0A,k0B,k0C,k0D, \ - k17,k18,k19,k1A,k1B,k1C,k1D, \ - k28,k29,k2A,k2B,k2C,k2D, \ - k37,k38,k39,k3A,k3B,k3C,k3D, \ - k49,k4A,k4B,k4C,k4D, \ - k57,k58, \ - k59, \ - k5C,k5B,k5A ) \ - \ - /* matrix positions */ \ - { \ - { k00, k10, k20, k30, k40, KC_NO }, \ - { k01, k11, k21, k31, k41, k51 }, \ - { k02, k12, k22, k32, k42, k52 }, \ - { k03, k13, k23, k33, k43, k53 }, \ - { k04, k14, k24, k34, k44, k54 }, \ - { k05, k15, k25, k35, KC_NO, k55 }, \ - { k06, k16, KC_NO, k36, KC_NO, k56 }, \ - \ - { k07, k17, KC_NO, k37,KC_NO, k57 }, \ - { k08, k18, k28, k38,KC_NO, k58 }, \ - { k09, k19, k29, k39, k49, k59 }, \ - { k0A, k1A, k2A, k3A, k4A, k5A }, \ - { k0B, k1B, k2B, k3B, k4B, k5B }, \ - { k0C, k1C, k2C, k3C, k4C, k5C }, \ - { k0D, k1D, k2D, k3D, k4D, KC_NO } \ - } - -/* - * LEFT HAND: LINES 158-165 - * RIGHT HAND: LINES 167-174 - */ -#define LAYOUT_ergodox_80( \ - \ - k00,k01,k02,k03,k04,k05,k06, \ - k10,k11,k12,k13,k14,k15,k16, \ - k20,k21,k22,k23,k24,k25, \ - k30,k31,k32,k33,k34,k35,k36, \ - k40,k41,k42,k43,k44, \ - k55,k56, \ - k45,k46,k54, \ - k53,k52,k51, \ - \ - k07,k08,k09,k0A,k0B,k0C,k0D, \ - k17,k18,k19,k1A,k1B,k1C,k1D, \ - k28,k29,k2A,k2B,k2C,k2D, \ - k37,k38,k39,k3A,k3B,k3C,k3D, \ - k49,k4A,k4B,k4C,k4D, \ - k57,k58, \ - k59,k47,k48, \ - k5C,k5B,k5A ) \ - \ - /* matrix positions */ \ - { \ - { k00, k10, k20, k30, k40, KC_NO }, \ - { k01, k11, k21, k31, k41, k51 }, \ - { k02, k12, k22, k32, k42, k52 }, \ - { k03, k13, k23, k33, k43, k53 }, \ - { k04, k14, k24, k34, k44, k54 }, \ - { k05, k15, k25, k35, k45, k55 }, \ - { k06, k16, KC_NO, k36, k46, k56 }, \ - \ - { k07, k17, KC_NO, k37, k47, k57 }, \ - { k08, k18, k28, k38, k48, k58 }, \ - { k09, k19, k29, k39, k49, k59 }, \ - { k0A, k1A, k2A, k3A, k4A, k5A }, \ - { k0B, k1B, k2B, k3B, k4B, k5B }, \ - { k0C, k1C, k2C, k3C, k4C, k5C }, \ - { k0D, k1D, k2D, k3D, k4D, KC_NO } \ - } - -/* ---------- LEFT HAND ----------- ---------- RIGHT HAND ---------- */ -#define LAYOUT_ergodox_pretty( \ - L00,L01,L02,L03,L04,L05,L06, R00,R01,R02,R03,R04,R05,R06, \ - L10,L11,L12,L13,L14,L15,L16, R10,R11,R12,R13,R14,R15,R16, \ - L20,L21,L22,L23,L24,L25, R21,R22,R23,R24,R25,R26, \ - L30,L31,L32,L33,L34,L35,L36, R30,R31,R32,R33,R34,R35,R36, \ - L40,L41,L42,L43,L44, R42,R43,R44,R45,R46, \ - L55,L56, R50,R51, \ - L54, R52, \ - L53,L52,L51, R55,R54,R53 ) \ - \ - /* matrix positions */ \ - { \ - { L00, L10, L20, L30, L40, KC_NO }, \ - { L01, L11, L21, L31, L41, L51 }, \ - { L02, L12, L22, L32, L42, L52 }, \ - { L03, L13, L23, L33, L43, L53 }, \ - { L04, L14, L24, L34, L44, L54 }, \ - { L05, L15, L25, L35, KC_NO, L55 }, \ - { L06, L16, KC_NO, L36, KC_NO, L56 }, \ - \ - { R00, R10, KC_NO, R30,KC_NO, R50 }, \ - { R01, R11, R21, R31,KC_NO, R51 }, \ - { R02, R12, R22, R32, R42, R52 }, \ - { R03, R13, R23, R33, R43, R53 }, \ - { R04, R14, R24, R34, R44, R54 }, \ - { R05, R15, R25, R35, R45, R55 }, \ - { R06, R16, R26, R36, R46, KC_NO } \ - } - -/* ---------- LEFT HAND ----------- ---------- RIGHT HAND ---------- */ -#define LAYOUT_ergodox_pretty_80( \ - L00,L01,L02,L03,L04,L05,L06, R00,R01,R02,R03,R04,R05,R06, \ - L10,L11,L12,L13,L14,L15,L16, R10,R11,R12,R13,R14,R15,R16, \ - L20,L21,L22,L23,L24,L25, R21,R22,R23,R24,R25,R26, \ - L30,L31,L32,L33,L34,L35,L36, R30,R31,R32,R33,R34,R35,R36, \ - L40,L41,L42,L43,L44, R42,R43,R44,R45,R46, \ - L55,L56, R50,R51, \ - L45,L46,L54, R52,R40,R41, \ - L53,L52,L51, R55,R54,R53 ) \ - \ - /* matrix positions */ \ - { \ - { L00, L10, L20, L30, L40, KC_NO }, \ - { L01, L11, L21, L31, L41, L51 }, \ - { L02, L12, L22, L32, L42, L52 }, \ - { L03, L13, L23, L33, L43, L53 }, \ - { L04, L14, L24, L34, L44, L54 }, \ - { L05, L15, L25, L35, L45, L55 }, \ - { L06, L16, KC_NO, L36, L46, L56 }, \ - \ - { R00, R10, KC_NO, R30, R40, R50 }, \ - { R01, R11, R21, R31, R41, R51 }, \ - { R02, R12, R22, R32, R42, R52 }, \ - { R03, R13, R23, R33, R43, R53 }, \ - { R04, R14, R24, R34, R44, R54 }, \ - { R05, R15, R25, R35, R45, R55 }, \ - { R06, R16, R26, R36, R46, KC_NO } \ - } - -/* ---- LEFT HAND ---- ---- RIGHT HAND ---- */ -#define LED_LAYOUT_ergodox_pretty( \ - L01,L02,L03,L04,L05, R01,R02,R03,R04,R05, \ - L11,L12,L13,L14,L15, R11,R12,R13,R14,R15, \ - L21,L22,L23,L24,L25, R21,R22,R23,R24,R25, \ - L31,L32,L33,L34,L35, R31,R32,R33,R34,R35, \ - L41,L42,L43,L44, R42,R43,R44,R45 ) \ - \ - /* matrix positions */ \ - { R01, R02, R03, R04, R05, \ - R11, R12, R13, R14, R15, \ - R21, R22, R23, R24, R25, \ - R31, R32, R33, R34, R35, \ - R42, R43, R44, R45, \ - \ - L05, L04, L03, L02, L01, \ - L15, L14, L13, L12, L11, \ - L25, L24, L23, L22, L21, \ - L35, L34, L33, L32, L31, \ - L44, L43, L42, L41 \ - } diff --git a/keyboards/ergodox_ez/glow/glow.h b/keyboards/ergodox_ez/glow/glow.h deleted file mode 100644 index da7a6073efcc..000000000000 --- a/keyboards/ergodox_ez/glow/glow.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2012 Jun Wako -Copyright 2013 Oleg Kostyuk -Copyright 2015 ZSA Technology Labs Inc (@zsa) -Copyright 2020 Christopher Courtney (@drashna) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#include "ergodox_ez.h" diff --git a/keyboards/ergodox_ez/info.json b/keyboards/ergodox_ez/info.json index cfef8426170e..1b2942cd4288 100644 --- a/keyboards/ergodox_ez/info.json +++ b/keyboards/ergodox_ez/info.json @@ -6,104 +6,422 @@ "vid": "0x3297", "device_version": "0.0.1" }, + "rgblight": { + "hue_steps": 12, + "brightness_steps": 12, + "sleep": true, + "animations": { + "breathing": true, + "rainbow_mood": true, + "rainbow_swirl": true, + "snake": true, + "knight": true, + "christmas": true, + "static_gradient": true, + "rgb_test": true, + "alternating": true, + "twinkle": true + } + }, + "build": { + "debounce_type": "sym_eager_pr" + }, + "ws2812": { + "pin": "D7" + }, + "rgb_matrix": { + "driver": "is31fl3731" + }, "processor": "atmega32u4", "bootloader": "halfkay", "debounce": 30, + "tapping": { + "toggle": 1 + }, "community_layouts": ["ergodox"], "layouts": { "LAYOUT_ergodox": { "layout": [ - {"x":0, "y":0.375, "w":1.5}, {"x":1.5, "y":0.375}, {"x":2.5, "y":0.125}, {"x":3.5, "y":0}, {"x":4.5, "y":0.125}, {"x":5.5, "y":0.25}, {"x":6.5, "y":0.25}, - {"x":0, "y":1.375, "w":1.5}, {"x":1.5, "y":1.375}, {"x":2.5, "y":1.125}, {"x":3.5, "y":1}, {"x":4.5, "y":1.125}, {"x":5.5, "y":1.25}, {"x":6.5, "y":1.25, "h":1.5}, - {"x":0, "y":2.375, "w":1.5}, {"x":1.5, "y":2.375}, {"x":2.5, "y":2.125}, {"x":3.5, "y":2}, {"x":4.5, "y":2.125}, {"x":5.5, "y":2.25}, - {"x":0, "y":3.375, "w":1.5}, {"x":1.5, "y":3.375}, {"x":2.5, "y":3.125}, {"x":3.5, "y":3}, {"x":4.5, "y":3.125}, {"x":5.5, "y":3.25}, {"x":6.5, "y":2.75, "h":1.5}, - {"x":0.5, "y":4.375}, {"x":1.5, "y":4.375}, {"x":2.5, "y":4.125}, {"x":3.5, "y":4}, {"x":4.5, "y":4.125}, + {"matrix": [0, 0], "x": 0, "y": 0.375, "w": 1.5}, + {"matrix": [1, 0], "x": 1.5, "y": 0.375}, + {"matrix": [2, 0], "x": 2.5, "y": 0.125}, + {"matrix": [3, 0], "x": 3.5, "y": 0}, + {"matrix": [4, 0], "x": 4.5, "y": 0.125}, + {"matrix": [5, 0], "x": 5.5, "y": 0.25}, + {"matrix": [6, 0], "x": 6.5, "y": 0.25}, + + {"matrix": [0, 1], "x": 0, "y": 1.375, "w": 1.5}, + {"matrix": [1, 1], "x": 1.5, "y": 1.375}, + {"matrix": [2, 1], "x": 2.5, "y": 1.125}, + {"matrix": [3, 1], "x": 3.5, "y": 1}, + {"matrix": [4, 1], "x": 4.5, "y": 1.125}, + {"matrix": [5, 1], "x": 5.5, "y": 1.25}, + {"matrix": [6, 1], "x": 6.5, "y": 1.25, "h": 1.5}, + + {"matrix": [0, 2], "x": 0, "y": 2.375, "w": 1.5}, + {"matrix": [1, 2], "x": 1.5, "y": 2.375}, + {"matrix": [2, 2], "x": 2.5, "y": 2.125}, + {"matrix": [3, 2], "x": 3.5, "y": 2}, + {"matrix": [4, 2], "x": 4.5, "y": 2.125}, + {"matrix": [5, 2], "x": 5.5, "y": 2.25}, - {"x":6, "y":5}, {"x":7, "y":5}, - {"x":7, "y":6}, - {"x":5, "y":6, "h":2}, {"x":6, "y":6, "h":2}, {"x":7, "y":7}, + {"matrix": [0, 3], "x": 0, "y": 3.375, "w": 1.5}, + {"matrix": [1, 3], "x": 1.5, "y": 3.375}, + {"matrix": [2, 3], "x": 2.5, "y": 3.125}, + {"matrix": [3, 3], "x": 3.5, "y": 3}, + {"matrix": [4, 3], "x": 4.5, "y": 3.125}, + {"matrix": [5, 3], "x": 5.5, "y": 3.25}, + {"matrix": [6, 3], "x": 6.5, "y": 2.75, "h": 1.5}, + {"matrix": [0, 4], "x": 0.5, "y": 4.375}, + {"matrix": [1, 4], "x": 1.5, "y": 4.375}, + {"matrix": [2, 4], "x": 2.5, "y": 4.125}, + {"matrix": [3, 4], "x": 3.5, "y": 4}, + {"matrix": [4, 4], "x": 4.5, "y": 4.125}, - {"x":9.5, "y":0.25}, {"x":10.5, "y":0.25}, {"x":11.5, "y":0.125}, {"x":12.5, "y":0}, {"x":13.5, "y":0.125}, {"x":14.5, "y":0.375}, {"x":15.5, "y":0.375, "w":1.5}, - {"x":9.5, "y":1.25, "h":1.5}, {"x":10.5, "y":1.25}, {"x":11.5, "y":1.125}, {"x":12.5, "y":1}, {"x":13.5, "y":1.125}, {"x":14.5, "y":1.375}, {"x":15.5, "y":1.375, "w":1.5}, - {"x":10.5, "y":2.25}, {"x":11.5, "y":2.125}, {"x":12.5, "y":2}, {"x":13.5, "y":2.125}, {"x":14.5, "y":2.375}, {"x":15.5, "y":2.375, "w":1.5}, - {"x":9.5, "y":2.75, "h":1.5}, {"x":10.5, "y":3.25}, {"x":11.5, "y":3.125}, {"x":12.5, "y":3}, {"x":13.5, "y":3.125}, {"x":14.5, "y":3.375}, {"x":15.5, "y":3.375, "w":1.5}, - {"x":11.5, "y":4.125}, {"x":12.5, "y":4}, {"x":13.5, "y":4.125}, {"x":14.5, "y":4.375}, {"x":15.5, "y":4.375}, + {"matrix": [5, 5], "x": 6, "y": 5}, + {"matrix": [6, 5], "x": 7, "y": 5}, + {"matrix": [4, 5], "x": 7, "y": 6}, + {"matrix": [3, 5], "x": 5, "y": 6, "h": 2}, + {"matrix": [2, 5], "x": 6, "y": 6, "h": 2}, + {"matrix": [1, 5], "x": 7, "y": 7}, + {"matrix": [7, 0], "x": 9.5, "y": 0.25}, + {"matrix": [8, 0], "x": 10.5, "y": 0.25}, + {"matrix": [9, 0], "x": 11.5, "y": 0.125}, + {"matrix": [10, 0], "x": 12.5, "y": 0}, + {"matrix": [11, 0], "x": 13.5, "y": 0.125}, + {"matrix": [12, 0], "x": 14.5, "y": 0.375}, + {"matrix": [13, 0], "x": 15.5, "y": 0.375, "w": 1.5}, - {"x":9, "y":5}, {"x":10, "y":5}, - {"x":9, "y":6}, - {"x":9, "y":7}, {"x":10, "y":6, "h":2}, {"x":11, "y":6, "h":2} + {"matrix": [7, 1], "x": 9.5, "y": 1.25, "h": 1.5}, + {"matrix": [8, 1], "x": 10.5, "y": 1.25}, + {"matrix": [9, 1], "x": 11.5, "y": 1.125}, + {"matrix": [10, 1], "x": 12.5, "y": 1}, + {"matrix": [11, 1], "x": 13.5, "y": 1.125}, + {"matrix": [12, 1], "x": 14.5, "y": 1.375}, + {"matrix": [13, 1], "x": 15.5, "y": 1.375, "w": 1.5}, + + {"matrix": [8, 2], "x": 10.5, "y": 2.25}, + {"matrix": [9, 2], "x": 11.5, "y": 2.125}, + {"matrix": [10, 2], "x": 12.5, "y": 2}, + {"matrix": [11, 2], "x": 13.5, "y": 2.125}, + {"matrix": [12, 2], "x": 14.5, "y": 2.375}, + {"matrix": [13, 2], "x": 15.5, "y": 2.375, "w": 1.5}, + {"matrix": [7, 3], "x": 9.5, "y": 2.75, "h": 1.5}, + + {"matrix": [8, 3], "x": 10.5, "y": 3.25}, + {"matrix": [9, 3], "x": 11.5, "y": 3.125}, + {"matrix": [10, 3], "x": 12.5, "y": 3}, + {"matrix": [11, 3], "x": 13.5, "y": 3.125}, + {"matrix": [12, 3], "x": 14.5, "y": 3.375}, + {"matrix": [13, 3], "x": 15.5, "y": 3.375, "w": 1.5}, + + {"matrix": [9, 4], "x": 11.5, "y": 4.125}, + {"matrix": [10, 4], "x": 12.5, "y": 4}, + {"matrix": [11, 4], "x": 13.5, "y": 4.125}, + {"matrix": [12, 4], "x": 14.5, "y": 4.375}, + {"matrix": [13, 4], "x": 15.5, "y": 4.375}, + + {"matrix": [7, 5], "x": 9, "y": 5}, + {"matrix": [8, 5], "x": 10, "y": 5}, + {"matrix": [9, 5], "x": 9, "y": 6}, + {"matrix": [12, 5], "x": 9, "y": 7}, + {"matrix": [11, 5], "x": 10, "y": 6, "h": 2}, + {"matrix": [10, 5], "x": 11, "y": 6, "h": 2} ] }, "LAYOUT_ergodox_pretty": { "layout": [ - {"x":0, "y":0.375, "w":1.5}, {"x":1.5, "y":0.375}, {"x":2.5, "y":0.125}, {"x":3.5, "y":0}, {"x":4.5, "y":0.125}, {"x":5.5, "y":0.25}, {"x":6.5, "y":0.25}, - {"x":9.5, "y":0.25}, {"x":10.5, "y":0.25}, {"x":11.5, "y":0.125}, {"x":12.5, "y":0}, {"x":13.5, "y":0.125}, {"x":14.5, "y":0.375}, {"x":15.5, "y":0.375, "w":1.5}, + {"matrix": [0, 0], "x": 0, "y": 0.375, "w": 1.5}, + {"matrix": [1, 0], "x": 1.5, "y": 0.375}, + {"matrix": [2, 0], "x": 2.5, "y": 0.125}, + {"matrix": [3, 0], "x": 3.5, "y": 0}, + {"matrix": [4, 0], "x": 4.5, "y": 0.125}, + {"matrix": [5, 0], "x": 5.5, "y": 0.25}, + {"matrix": [6, 0], "x": 6.5, "y": 0.25}, + + {"matrix": [7, 0], "x": 9.5, "y": 0.25}, + {"matrix": [8, 0], "x": 10.5, "y": 0.25}, + {"matrix": [9, 0], "x": 11.5, "y": 0.125}, + {"matrix": [10, 0], "x": 12.5, "y": 0}, + {"matrix": [11, 0], "x": 13.5, "y": 0.125}, + {"matrix": [12, 0], "x": 14.5, "y": 0.375}, + {"matrix": [13, 0], "x": 15.5, "y": 0.375, "w": 1.5}, + + {"matrix": [0, 1], "x": 0, "y": 1.375, "w": 1.5}, + {"matrix": [1, 1], "x": 1.5, "y": 1.375}, + {"matrix": [2, 1], "x": 2.5, "y": 1.125}, + {"matrix": [3, 1], "x": 3.5, "y": 1}, + {"matrix": [4, 1], "x": 4.5, "y": 1.125}, + {"matrix": [5, 1], "x": 5.5, "y": 1.25}, + {"matrix": [6, 1], "x": 6.5, "y": 1.25, "h": 1.5}, - {"x":0, "y":1.375, "w":1.5}, {"x":1.5, "y":1.375}, {"x":2.5, "y":1.125}, {"x":3.5, "y":1}, {"x":4.5, "y":1.125}, {"x":5.5, "y":1.25}, {"x":6.5, "y":1.25, "h":1.5}, - {"x":9.5, "y":1.25, "h":1.5}, {"x":10.5, "y":1.25}, {"x":11.5, "y":1.125}, {"x":12.5, "y":1}, {"x":13.5, "y":1.125}, {"x":14.5, "y":1.375}, {"x":15.5, "y":1.375, "w":1.5}, + {"matrix": [7, 1], "x": 9.5, "y": 1.25, "h": 1.5}, + {"matrix": [8, 1], "x": 10.5, "y": 1.25}, + {"matrix": [9, 1], "x": 11.5, "y": 1.125}, + {"matrix": [10, 1], "x": 12.5, "y": 1}, + {"matrix": [11, 1], "x": 13.5, "y": 1.125}, + {"matrix": [12, 1], "x": 14.5, "y": 1.375}, + {"matrix": [13, 1], "x": 15.5, "y": 1.375, "w": 1.5}, - {"x":0, "y":2.375, "w":1.5}, {"x":1.5, "y":2.375}, {"x":2.5, "y":2.125}, {"x":3.5, "y":2}, {"x":4.5, "y":2.125}, {"x":5.5, "y":2.25}, - {"x":10.5, "y":2.25}, {"x":11.5, "y":2.125}, {"x":12.5, "y":2}, {"x":13.5, "y":2.125}, {"x":14.5, "y":2.375}, {"x":15.5, "y":2.375, "w":1.5}, + {"matrix": [0, 2], "x": 0, "y": 2.375, "w": 1.5}, + {"matrix": [1, 2], "x": 1.5, "y": 2.375}, + {"matrix": [2, 2], "x": 2.5, "y": 2.125}, + {"matrix": [3, 2], "x": 3.5, "y": 2}, + {"matrix": [4, 2], "x": 4.5, "y": 2.125}, + {"matrix": [5, 2], "x": 5.5, "y": 2.25}, - {"x":0, "y":3.375, "w":1.5}, {"x":1.5, "y":3.375}, {"x":2.5, "y":3.125}, {"x":3.5, "y":3}, {"x":4.5, "y":3.125}, {"x":5.5, "y":3.25}, {"x":6.5, "y":2.75, "h":1.5}, - {"x":9.5, "y":2.75, "h":1.5}, {"x":10.5, "y":3.25}, {"x":11.5, "y":3.125}, {"x":12.5, "y":3}, {"x":13.5, "y":3.125}, {"x":14.5, "y":3.375}, {"x":15.5, "y":3.375, "w":1.5}, + {"matrix": [8, 2], "x": 10.5, "y": 2.25}, + {"matrix": [9, 2], "x": 11.5, "y": 2.125}, + {"matrix": [10, 2], "x": 12.5, "y": 2}, + {"matrix": [11, 2], "x": 13.5, "y": 2.125}, + {"matrix": [12, 2], "x": 14.5, "y": 2.375}, + {"matrix": [13, 2], "x": 15.5, "y": 2.375, "w": 1.5}, - {"x":0.5, "y":4.375}, {"x":1.5, "y":4.375}, {"x":2.5, "y":4.125}, {"x":3.5, "y":4}, {"x":4.5, "y":4.125}, - {"x":11.5, "y":4.125}, {"x":12.5, "y":4}, {"x":13.5, "y":4.125}, {"x":14.5, "y":4.375}, {"x":15.5, "y":4.375}, + {"matrix": [0, 3], "x": 0, "y": 3.375, "w": 1.5}, + {"matrix": [1, 3], "x": 1.5, "y": 3.375}, + {"matrix": [2, 3], "x": 2.5, "y": 3.125}, + {"matrix": [3, 3], "x": 3.5, "y": 3}, + {"matrix": [4, 3], "x": 4.5, "y": 3.125}, + {"matrix": [5, 3], "x": 5.5, "y": 3.25}, + {"matrix": [6, 3], "x": 6.5, "y": 2.75, "h": 1.5}, - {"x":6, "y":5}, {"x":7, "y":5}, {"x":9, "y":5}, {"x":10, "y":5}, - {"x":7, "y":6}, {"x":9, "y":6}, - {"x":5, "y":6, "h":2}, {"x":6, "y":6, "h":2}, {"x":7, "y":7}, {"x":9, "y":7}, {"x":10, "y":6, "h":2}, {"x":11, "y":6, "h":2} + {"matrix": [7, 3], "x": 9.5, "y": 2.75, "h": 1.5}, + {"matrix": [8, 3], "x": 10.5, "y": 3.25}, + {"matrix": [9, 3], "x": 11.5, "y": 3.125}, + {"matrix": [10, 3], "x": 12.5, "y": 3}, + {"matrix": [11, 3], "x": 13.5, "y": 3.125}, + {"matrix": [12, 3], "x": 14.5, "y": 3.375}, + {"matrix": [13, 3], "x": 15.5, "y": 3.375, "w": 1.5}, + + {"matrix": [0, 4], "x": 0.5, "y": 4.375}, + {"matrix": [1, 4], "x": 1.5, "y": 4.375}, + {"matrix": [2, 4], "x": 2.5, "y": 4.125}, + {"matrix": [3, 4], "x": 3.5, "y": 4}, + {"matrix": [4, 4], "x": 4.5, "y": 4.125}, + + {"matrix": [9, 4], "x": 11.5, "y": 4.125}, + {"matrix": [10, 4], "x": 12.5, "y": 4}, + {"matrix": [11, 4], "x": 13.5, "y": 4.125}, + {"matrix": [12, 4], "x": 14.5, "y": 4.375}, + {"matrix": [13, 4], "x": 15.5, "y": 4.375}, + + {"matrix": [5, 5], "x": 6, "y": 5}, + {"matrix": [6, 5], "x": 7, "y": 5}, + + {"matrix": [7, 5], "x": 9, "y": 5}, + {"matrix": [8, 5], "x": 10, "y": 5}, + + {"matrix": [4, 5], "x": 7, "y": 6}, + {"matrix": [9, 5], "x": 9, "y": 6}, + + {"matrix": [3, 5], "x": 5, "y": 6, "h": 2}, + {"matrix": [2, 5], "x": 6, "y": 6, "h": 2}, + {"matrix": [1, 5], "x": 7, "y": 7}, + + {"matrix": [12, 5], "x": 9, "y": 7}, + {"matrix": [11, 5], "x": 10, "y": 6, "h": 2}, + {"matrix": [10, 5], "x": 11, "y": 6, "h": 2} ] }, "LAYOUT_ergodox_80": { - "layout": [ - {"x":0, "y":0.375, "w":1.5}, {"x":1.5, "y":0.375}, {"x":2.5, "y":0.125}, {"x":3.5, "y":0}, {"x":4.5, "y":0.125}, {"x":5.5, "y":0.25}, {"x":6.5, "y":0.25}, - {"x":0, "y":1.375, "w":1.5}, {"x":1.5, "y":1.375}, {"x":2.5, "y":1.125}, {"x":3.5, "y":1}, {"x":4.5, "y":1.125}, {"x":5.5, "y":1.25}, {"x":6.5, "y":1.25, "h":1.5}, - {"x":0, "y":2.375, "w":1.5}, {"x":1.5, "y":2.375}, {"x":2.5, "y":2.125}, {"x":3.5, "y":2}, {"x":4.5, "y":2.125}, {"x":5.5, "y":2.25}, - {"x":0, "y":3.375, "w":1.5}, {"x":1.5, "y":3.375}, {"x":2.5, "y":3.125}, {"x":3.5, "y":3}, {"x":4.5, "y":3.125}, {"x":5.5, "y":3.25}, {"x":6.5, "y":2.75, "h":1.5}, - {"x":0.5, "y":4.375}, {"x":1.5, "y":4.375}, {"x":2.5, "y":4.125}, {"x":3.5, "y":4}, {"x":4.5, "y":4.125}, - - {"x":6, "y":5}, {"x":7, "y":5}, - {"x":5, "y":6}, {"x":6, "y":6}, {"x":7, "y":6}, - {"x":5, "y":7}, {"x":6, "y":7}, {"x":7, "y":7}, - - - {"x":9.5, "y":0.25}, {"x":10.5, "y":0.25}, {"x":11.5, "y":0.125}, {"x":12.5, "y":0}, {"x":13.5, "y":0.125}, {"x":14.5, "y":0.375}, {"x":15.5, "y":0.375, "w":1.5}, - {"x":9.5, "y":1.25, "h":1.5}, {"x":10.5, "y":1.25}, {"x":11.5, "y":1.125}, {"x":12.5, "y":1}, {"x":13.5, "y":1.125}, {"x":14.5, "y":1.375}, {"x":15.5, "y":1.375, "w":1.5}, - {"x":10.5, "y":2.25}, {"x":11.5, "y":2.125}, {"x":12.5, "y":2}, {"x":13.5, "y":2.125}, {"x":14.5, "y":2.375}, {"x":15.5, "y":2.375, "w":1.5}, - {"x":9.5, "y":2.75, "h":1.5}, {"x":10.5, "y":3.25}, {"x":11.5, "y":3.125}, {"x":12.5, "y":3}, {"x":13.5, "y":3.125}, {"x":14.5, "y":3.375}, {"x":15.5, "y":3.375, "w":1.5}, - {"x":11.5, "y":4.125}, {"x":12.5, "y":4}, {"x":13.5, "y":4.125}, {"x":14.5, "y":4.375}, {"x":15.5, "y":4.375}, - - - {"x":9, "y":5}, {"x":10, "y":5}, - {"x":9, "y":6}, {"x":10, "y":6}, {"x":11, "y":6}, - {"x":9, "y":7}, {"x":10, "y":7}, {"x":11, "y":7} - ] - }, + "layout": [ + {"matrix": [0, 0], "x": 0, "y": 0.375, "w": 1.5}, + {"matrix": [1, 0], "x": 1.5, "y": 0.375}, + {"matrix": [2, 0], "x": 2.5, "y": 0.125}, + {"matrix": [3, 0], "x": 3.5, "y": 0}, + {"matrix": [4, 0], "x": 4.5, "y": 0.125}, + {"matrix": [5, 0], "x": 5.5, "y": 0.25}, + {"matrix": [6, 0], "x": 6.5, "y": 0.25}, + + {"matrix": [0, 1], "x": 0, "y": 1.375, "w": 1.5}, + {"matrix": [1, 1], "x": 1.5, "y": 1.375}, + {"matrix": [2, 1], "x": 2.5, "y": 1.125}, + {"matrix": [3, 1], "x": 3.5, "y": 1}, + {"matrix": [4, 1], "x": 4.5, "y": 1.125}, + {"matrix": [5, 1], "x": 5.5, "y": 1.25}, + {"matrix": [6, 1], "x": 6.5, "y": 1.25, "h": 1.5}, + + {"matrix": [0, 2], "x": 0, "y": 2.375, "w": 1.5}, + {"matrix": [1, 2], "x": 1.5, "y": 2.375}, + {"matrix": [2, 2], "x": 2.5, "y": 2.125}, + {"matrix": [3, 2], "x": 3.5, "y": 2}, + {"matrix": [4, 2], "x": 4.5, "y": 2.125}, + {"matrix": [5, 2], "x": 5.5, "y": 2.25}, + + {"matrix": [0, 3], "x": 0, "y": 3.375, "w": 1.5}, + {"matrix": [1, 3], "x": 1.5, "y": 3.375}, + {"matrix": [2, 3], "x": 2.5, "y": 3.125}, + {"matrix": [3, 3], "x": 3.5, "y": 3}, + {"matrix": [4, 3], "x": 4.5, "y": 3.125}, + {"matrix": [5, 3], "x": 5.5, "y": 3.25}, + {"matrix": [6, 3], "x": 6.5, "y": 2.75, "h": 1.5}, + + {"matrix": [0, 4], "x": 0.5, "y": 4.375}, + {"matrix": [1, 4], "x": 1.5, "y": 4.375}, + {"matrix": [2, 4], "x": 2.5, "y": 4.125}, + {"matrix": [3, 4], "x": 3.5, "y": 4}, + {"matrix": [4, 4], "x": 4.5, "y": 4.125}, + + {"matrix": [5, 5], "x": 6, "y": 5}, + {"matrix": [6, 5], "x": 7, "y": 5}, + + {"matrix": [5, 4], "x": 5, "y": 6}, + {"matrix": [6, 4], "x": 6, "y": 6}, + {"matrix": [4, 5], "x": 7, "y": 6}, + + {"matrix": [3, 5], "x": 5, "y": 7}, + {"matrix": [2, 5], "x": 6, "y": 7}, + {"matrix": [1, 5], "x": 7, "y": 7}, + + {"matrix": [7, 0], "x": 9.5, "y": 0.25}, + {"matrix": [8, 0], "x": 10.5, "y": 0.25}, + {"matrix": [9, 0], "x": 11.5, "y": 0.125}, + {"matrix": [10, 0], "x": 12.5, "y": 0}, + {"matrix": [11, 0], "x": 13.5, "y": 0.125}, + {"matrix": [12, 0], "x": 14.5, "y": 0.375}, + {"matrix": [13, 0], "x": 15.5, "y": 0.375, "w": 1.5}, + + {"matrix": [7, 1], "x": 9.5, "y": 1.25, "h": 1.5}, + {"matrix": [8, 1], "x": 10.5, "y": 1.25}, + {"matrix": [9, 1], "x": 11.5, "y": 1.125}, + {"matrix": [10, 1], "x": 12.5, "y": 1}, + {"matrix": [11, 1], "x": 13.5, "y": 1.125}, + {"matrix": [12, 1], "x": 14.5, "y": 1.375}, + {"matrix": [13, 1], "x": 15.5, "y": 1.375, "w": 1.5}, + + {"matrix": [8, 2], "x": 10.5, "y": 2.25}, + {"matrix": [9, 2], "x": 11.5, "y": 2.125}, + {"matrix": [10, 2], "x": 12.5, "y": 2}, + {"matrix": [11, 2], "x": 13.5, "y": 2.125}, + {"matrix": [12, 2], "x": 14.5, "y": 2.375}, + {"matrix": [13, 2], "x": 15.5, "y": 2.375, "w": 1.5}, + {"matrix": [7, 3], "x": 9.5, "y": 2.75, "h": 1.5}, + + {"matrix": [8, 3], "x": 10.5, "y": 3.25}, + {"matrix": [9, 3], "x": 11.5, "y": 3.125}, + {"matrix": [10, 3], "x": 12.5, "y": 3}, + {"matrix": [11, 3], "x": 13.5, "y": 3.125}, + {"matrix": [12, 3], "x": 14.5, "y": 3.375}, + {"matrix": [13, 3], "x": 15.5, "y": 3.375, "w": 1.5}, + + {"matrix": [9, 4], "x": 11.5, "y": 4.125}, + {"matrix": [10, 4], "x": 12.5, "y": 4}, + {"matrix": [11, 4], "x": 13.5, "y": 4.125}, + {"matrix": [12, 4], "x": 14.5, "y": 4.375}, + {"matrix": [13, 4], "x": 15.5, "y": 4.375}, + + {"matrix": [7, 5], "x": 9, "y": 5}, + {"matrix": [8, 5], "x": 10, "y": 5}, + + {"matrix": [9, 5], "x": 9, "y": 6}, + {"matrix": [7, 4], "x": 10, "y": 6}, + {"matrix": [8, 4], "x": 11, "y": 6}, + + {"matrix": [12, 5], "x": 9, "y": 7}, + {"matrix": [11, 5], "x": 10, "y": 7}, + {"matrix": [10, 5], "x": 11, "y": 7} + ] + }, "LAYOUT_ergodox_pretty_80": { - "layout": [ - {"x":0, "y":0.375, "w":1.5}, {"x":1.5, "y":0.375}, {"x":2.5, "y":0.125}, {"x":3.5, "y":0}, {"x":4.5, "y":0.125}, {"x":5.5, "y":0.25}, {"x":6.5, "y":0.25}, - {"x":9.5, "y":0.25}, {"x":10.5, "y":0.25}, {"x":11.5, "y":0.125}, {"x":12.5, "y":0}, {"x":13.5, "y":0.125}, {"x":14.5, "y":0.375}, {"x":15.5, "y":0.375, "w":1.5}, + "layout": [ + {"matrix": [0, 0], "x": 0, "y": 0.375, "w": 1.5}, + {"matrix": [1, 0], "x": 1.5, "y": 0.375}, + {"matrix": [2, 0], "x": 2.5, "y": 0.125}, + {"matrix": [3, 0], "x": 3.5, "y": 0}, + {"matrix": [4, 0], "x": 4.5, "y": 0.125}, + {"matrix": [5, 0], "x": 5.5, "y": 0.25}, + {"matrix": [6, 0], "x": 6.5, "y": 0.25}, + + {"matrix": [7, 0], "x": 9.5, "y": 0.25}, + {"matrix": [8, 0], "x": 10.5, "y": 0.25}, + {"matrix": [9, 0], "x": 11.5, "y": 0.125}, + {"matrix": [10, 0], "x": 12.5, "y": 0}, + {"matrix": [11, 0], "x": 13.5, "y": 0.125}, + {"matrix": [12, 0], "x": 14.5, "y": 0.375}, + {"matrix": [13, 0], "x": 15.5, "y": 0.375, "w": 1.5}, + + {"matrix": [0, 1], "x": 0, "y": 1.375, "w": 1.5}, + {"matrix": [1, 1], "x": 1.5, "y": 1.375}, + {"matrix": [2, 1], "x": 2.5, "y": 1.125}, + {"matrix": [3, 1], "x": 3.5, "y": 1}, + {"matrix": [4, 1], "x": 4.5, "y": 1.125}, + {"matrix": [5, 1], "x": 5.5, "y": 1.25}, + {"matrix": [6, 1], "x": 6.5, "y": 1.25, "h": 1.5}, + + {"matrix": [7, 1], "x": 9.5, "y": 1.25, "h": 1.5}, + {"matrix": [8, 1], "x": 10.5, "y": 1.25}, + {"matrix": [9, 1], "x": 11.5, "y": 1.125}, + {"matrix": [10, 1], "x": 12.5, "y": 1}, + {"matrix": [11, 1], "x": 13.5, "y": 1.125}, + {"matrix": [12, 1], "x": 14.5, "y": 1.375}, + {"matrix": [13, 1], "x": 15.5, "y": 1.375, "w": 1.5}, + + {"matrix": [0, 2], "x": 0, "y": 2.375, "w": 1.5}, + {"matrix": [1, 2], "x": 1.5, "y": 2.375}, + {"matrix": [2, 2], "x": 2.5, "y": 2.125}, + {"matrix": [3, 2], "x": 3.5, "y": 2}, + {"matrix": [4, 2], "x": 4.5, "y": 2.125}, + {"matrix": [5, 2], "x": 5.5, "y": 2.25}, + + {"matrix": [8, 2], "x": 10.5, "y": 2.25}, + {"matrix": [9, 2], "x": 11.5, "y": 2.125}, + {"matrix": [10, 2], "x": 12.5, "y": 2}, + {"matrix": [11, 2], "x": 13.5, "y": 2.125}, + {"matrix": [12, 2], "x": 14.5, "y": 2.375}, + {"matrix": [13, 2], "x": 15.5, "y": 2.375, "w": 1.5}, - {"x":0, "y":1.375, "w":1.5}, {"x":1.5, "y":1.375}, {"x":2.5, "y":1.125}, {"x":3.5, "y":1}, {"x":4.5, "y":1.125}, {"x":5.5, "y":1.25}, {"x":6.5, "y":1.25, "h":1.5}, - {"x":9.5, "y":1.25, "h":1.5}, {"x":10.5, "y":1.25}, {"x":11.5, "y":1.125}, {"x":12.5, "y":1}, {"x":13.5, "y":1.125}, {"x":14.5, "y":1.375}, {"x":15.5, "y":1.375, "w":1.5}, + {"matrix": [0, 3], "x": 0, "y": 3.375, "w": 1.5}, + {"matrix": [1, 3], "x": 1.5, "y": 3.375}, + {"matrix": [2, 3], "x": 2.5, "y": 3.125}, + {"matrix": [3, 3], "x": 3.5, "y": 3}, + {"matrix": [4, 3], "x": 4.5, "y": 3.125}, + {"matrix": [5, 3], "x": 5.5, "y": 3.25}, + {"matrix": [6, 3], "x": 6.5, "y": 2.75, "h": 1.5}, - {"x":0, "y":2.375, "w":1.5}, {"x":1.5, "y":2.375}, {"x":2.5, "y":2.125}, {"x":3.5, "y":2}, {"x":4.5, "y":2.125}, {"x":5.5, "y":2.25}, - {"x":10.5, "y":2.25}, {"x":11.5, "y":2.125}, {"x":12.5, "y":2}, {"x":13.5, "y":2.125}, {"x":14.5, "y":2.375}, {"x":15.5, "y":2.375, "w":1.5}, + {"matrix": [7, 3], "x": 9.5, "y": 2.75, "h": 1.5}, + {"matrix": [8, 3], "x": 10.5, "y": 3.25}, + {"matrix": [9, 3], "x": 11.5, "y": 3.125}, + {"matrix": [10, 3], "x": 12.5, "y": 3}, + {"matrix": [11, 3], "x": 13.5, "y": 3.125}, + {"matrix": [12, 3], "x": 14.5, "y": 3.375}, + {"matrix": [13, 3], "x": 15.5, "y": 3.375, "w": 1.5}, - {"x":0, "y":3.375, "w":1.5}, {"x":1.5, "y":3.375}, {"x":2.5, "y":3.125}, {"x":3.5, "y":3}, {"x":4.5, "y":3.125}, {"x":5.5, "y":3.25}, {"x":6.5, "y":2.75, "h":1.5}, - {"x":9.5, "y":2.75, "h":1.5}, {"x":10.5, "y":3.25}, {"x":11.5, "y":3.125}, {"x":12.5, "y":3}, {"x":13.5, "y":3.125}, {"x":14.5, "y":3.375}, {"x":15.5, "y":3.375, "w":1.5}, + {"matrix": [0, 4], "x": 0.5, "y": 4.375}, + {"matrix": [1, 4], "x": 1.5, "y": 4.375}, + {"matrix": [2, 4], "x": 2.5, "y": 4.125}, + {"matrix": [3, 4], "x": 3.5, "y": 4}, + {"matrix": [4, 4], "x": 4.5, "y": 4.125}, - {"x":0.5, "y":4.375}, {"x":1.5, "y":4.375}, {"x":2.5, "y":4.125}, {"x":3.5, "y":4}, {"x":4.5, "y":4.125}, - {"x":11.5, "y":4.125}, {"x":12.5, "y":4}, {"x":13.5, "y":4.125}, {"x":14.5, "y":4.375}, {"x":15.5, "y":4.375}, + {"matrix": [9, 4], "x": 11.5, "y": 4.125}, + {"matrix": [10, 4], "x": 12.5, "y": 4}, + {"matrix": [11, 4], "x": 13.5, "y": 4.125}, + {"matrix": [12, 4], "x": 14.5, "y": 4.375}, + {"matrix": [13, 4], "x": 15.5, "y": 4.375}, - {"x":6, "y":5}, {"x":7, "y":5}, {"x":9, "y":5}, {"x":10, "y":5}, - {"x":5, "y":6}, {"x":6, "y":6}, {"x":7, "y":6}, {"x":9, "y":6}, {"x":10, "y":6}, {"x":11, "y":6}, - {"x":5, "y":7}, {"x":6, "y":7}, {"x":7, "y":7}, {"x":9, "y":7}, {"x":10, "y":7}, {"x":11, "y":7} - ] - } + {"matrix": [5, 5], "x": 6, "y": 5}, + {"matrix": [6, 5], "x": 7, "y": 5}, + + {"matrix": [7, 5], "x": 9, "y": 5}, + {"matrix": [8, 5], "x": 10, "y": 5}, + + {"matrix": [5, 4], "x": 5, "y": 6}, + {"matrix": [6, 4], "x": 6, "y": 6}, + {"matrix": [4, 5], "x": 7, "y": 6}, + + {"matrix": [9, 5], "x": 9, "y": 6}, + {"matrix": [7, 4], "x": 10, "y": 6}, + {"matrix": [8, 4], "x": 11, "y": 6}, + + {"matrix": [3, 5], "x": 5, "y": 7}, + {"matrix": [2, 5], "x": 6, "y": 7}, + {"matrix": [1, 5], "x": 7, "y": 7}, + + {"matrix": [12, 5], "x": 9, "y": 7}, + {"matrix": [11, 5], "x": 10, "y": 7}, + {"matrix": [10, 5], "x": 11, "y": 7} + ] + } } } diff --git a/keyboards/ergodox_ez/rules.mk b/keyboards/ergodox_ez/rules.mk index 3f55a971a226..d4196b315c32 100644 --- a/keyboards/ergodox_ez/rules.mk +++ b/keyboards/ergodox_ez/rules.mk @@ -19,8 +19,6 @@ SWAP_HANDS_ENABLE= no # Allow swapping hands of keyboard GRAVE_ESC_ENABLE = no RGB_MATRIX_ENABLE = no # enable later -RGB_MATRIX_DRIVER = IS31FL3731 -DEBOUNCE_TYPE = sym_eager_pr # project specific files SRC += matrix.c \ diff --git a/keyboards/ergodox_ez/shine/shine.h b/keyboards/ergodox_ez/shine/shine.h deleted file mode 100644 index da7a6073efcc..000000000000 --- a/keyboards/ergodox_ez/shine/shine.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2012 Jun Wako -Copyright 2013 Oleg Kostyuk -Copyright 2015 ZSA Technology Labs Inc (@zsa) -Copyright 2020 Christopher Courtney (@drashna) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#include "ergodox_ez.h" diff --git a/keyboards/moonlander/info.json b/keyboards/moonlander/info.json index 3492713a6aa7..acbb278a332f 100644 --- a/keyboards/moonlander/info.json +++ b/keyboards/moonlander/info.json @@ -8,27 +8,97 @@ "pid": "0x1969", "device_version": "0.0.1" }, + "rgb_matrix": { + "driver": "is31fl3731" + }, "processor": "STM32F303", "bootloader": "stm32-dfu", "layouts": { "LAYOUT_moonlander": { "layout": [ - {"x":0, "y":0.375}, {"x":1, "y":0.375}, {"x":2, "y":0.125}, {"x":3, "y":0}, {"x":4, "y":0.125}, {"x":5, "y":0.25}, {"x":6, "y":0.25}, - {"x":10, "y":0.25}, {"x":11, "y":0.25}, {"x":12, "y":0.125}, {"x":13, "y":0}, {"x":14, "y":0.125}, {"x":15, "y":0.375}, {"x":16, "y":0.375}, + {"matrix": [0, 0], "x": 0, "y": 0.375}, + {"matrix": [0, 1], "x": 1, "y": 0.375}, + {"matrix": [0, 2], "x": 2, "y": 0.125}, + {"matrix": [0, 3], "x": 3, "y": 0}, + {"matrix": [0, 4], "x": 4, "y": 0.125}, + {"matrix": [0, 5], "x": 5, "y": 0.25}, + {"matrix": [0, 6], "x": 6, "y": 0.25}, + + {"matrix": [6, 0], "x": 10, "y": 0.25}, + {"matrix": [6, 1], "x": 11, "y": 0.25}, + {"matrix": [6, 2], "x": 12, "y": 0.125}, + {"matrix": [6, 3], "x": 13, "y": 0}, + {"matrix": [6, 4], "x": 14, "y": 0.125}, + {"matrix": [6, 5], "x": 15, "y": 0.375}, + {"matrix": [6, 6], "x": 16, "y": 0.375}, + + {"matrix": [1, 0], "x": 0, "y": 1.375}, + {"matrix": [1, 1], "x": 1, "y": 1.375}, + {"matrix": [1, 2], "x": 2, "y": 1.125}, + {"matrix": [1, 3], "x": 3, "y": 1}, + {"matrix": [1, 4], "x": 4, "y": 1.125}, + {"matrix": [1, 5], "x": 5, "y": 1.25}, + {"matrix": [1, 6], "x": 6, "y": 1.25}, + + {"matrix": [7, 0], "x": 10, "y": 1.25}, + {"matrix": [7, 1], "x": 11, "y": 1.25}, + {"matrix": [7, 2], "x": 12, "y": 1.125}, + {"matrix": [7, 3], "x": 13, "y": 1}, + {"matrix": [7, 4], "x": 14, "y": 1.125}, + {"matrix": [7, 5], "x": 15, "y": 1.375}, + {"matrix": [7, 6], "x": 16, "y": 1.375}, + + {"matrix": [2, 0], "x": 0, "y": 2.375}, + {"matrix": [2, 1], "x": 1, "y": 2.375}, + {"matrix": [2, 2], "x": 2, "y": 2.125}, + {"matrix": [2, 3], "x": 3, "y": 2}, + {"matrix": [2, 4], "x": 4, "y": 2.125}, + {"matrix": [2, 5], "x": 5, "y": 2.25}, + {"matrix": [2, 6], "x": 6, "y": 2.25}, + + {"matrix": [8, 0], "x": 10, "y": 2.25}, + {"matrix": [8, 1], "x": 11, "y": 2.25}, + {"matrix": [8, 2], "x": 12, "y": 2.125}, + {"matrix": [8, 3], "x": 13, "y": 2}, + {"matrix": [8, 4], "x": 14, "y": 2.125}, + {"matrix": [8, 5], "x": 15, "y": 2.375}, + {"matrix": [8, 6], "x": 16, "y": 2.375}, + + {"matrix": [3, 0], "x": 0, "y": 3.375}, + {"matrix": [3, 1], "x": 1, "y": 3.375}, + {"matrix": [3, 2], "x": 2, "y": 3.125}, + {"matrix": [3, 3], "x": 3, "y": 3}, + {"matrix": [3, 4], "x": 4, "y": 3.125}, + {"matrix": [3, 5], "x": 5, "y": 3.25}, - {"x":0, "y":1.375}, {"x":1, "y":1.375}, {"x":2, "y":1.125}, {"x":3, "y":1}, {"x":4, "y":1.125}, {"x":5, "y":1.25}, {"x":6, "y":1.25}, - {"x":10, "y":1.25}, {"x":11, "y":1.25}, {"x":12, "y":1.125}, {"x":13, "y":1}, {"x":14, "y":1.125}, {"x":15, "y":1.375}, {"x":16, "y":1.375}, + {"matrix": [9, 1], "x": 11, "y": 3.25}, + {"matrix": [9, 2], "x": 12, "y": 3.125}, + {"matrix": [9, 3], "x": 13, "y": 3}, + {"matrix": [9, 4], "x": 14, "y": 3.125}, + {"matrix": [9, 5], "x": 15, "y": 3.375}, + {"matrix": [9, 6], "x": 16, "y": 3.375}, - {"x":0, "y":2.375}, {"x":1, "y":2.375}, {"x":2, "y":2.125}, {"x":3, "y":2}, {"x":4, "y":2.125}, {"x":5, "y":2.25}, {"x":6, "y":2.25}, - {"x":10, "y":2.25}, {"x":11, "y":2.25}, {"x":12, "y":2.125}, {"x":13, "y":2}, {"x":14, "y":2.125}, {"x":15, "y":2.375}, {"x":16, "y":2.375}, + {"matrix": [4, 0], "x": 0, "y": 4.375}, + {"matrix": [4, 1], "x": 1, "y": 4.375}, + {"matrix": [4, 2], "x": 2, "y": 4.125}, + {"matrix": [4, 3], "x": 3, "y": 4}, + {"matrix": [4, 4], "x": 4, "y": 4.125}, + {"matrix": [5, 3], "x": 5, "y": 4.5, "w": 2}, - {"x":0, "y":3.375}, {"x":1, "y":3.375}, {"x":2, "y":3.125}, {"x":3, "y":3}, {"x":4, "y":3.125}, {"x":5, "y":3.25}, - {"x":11, "y":3.25}, {"x":12, "y":3.125}, {"x":13, "y":3}, {"x":14, "y":3.125}, {"x":15, "y":3.375}, {"x":16, "y":3.375}, + {"matrix": [11, 3], "x": 10, "y": 4.5, "w": 2}, + {"matrix": [10, 2], "x": 12, "y": 4.125}, + {"matrix": [10, 3], "x": 13, "y": 4}, + {"matrix": [10, 4], "x": 14, "y": 4.125}, + {"matrix": [10, 5], "x": 15, "y": 4.375}, + {"matrix": [10, 6], "x": 16, "y": 4.375}, - {"x":0, "y":4.375}, {"x":1, "y":4.375}, {"x":2, "y":4.125}, {"x":3, "y":4}, {"x":4, "y":4.125}, {"x":5, "y":4.5, "w":2}, - {"x":10, "y":4.5, "w":2}, {"x":12, "y":4.125}, {"x":13, "y":4}, {"x":14, "y":4.125}, {"x":15, "y":4.375}, {"x":16, "y":4.375}, + {"matrix": [5, 0], "x": 5, "y": 5.5, "h": 1.5}, + {"matrix": [5, 1], "x": 6, "y": 5.5, "h": 1.5}, + {"matrix": [5, 2], "x": 7, "y": 5.5, "h": 1.5}, - {"x":5, "y":5.5, "h":1.5}, {"x":6, "y":5.5, "h":1.5}, {"x":7, "y":5.5, "h":1.5}, {"x":9, "y":5.5, "h":1.5}, {"x":10, "y":5.5, "h":1.5}, {"x":11, "y":5.5, "h":1.5} + {"matrix": [11, 4], "x": 9, "y": 5.5, "h": 1.5}, + {"matrix": [11, 5], "x": 10, "y": 5.5, "h": 1.5}, + {"matrix": [11, 6], "x": 11, "y": 5.5, "h": 1.5} ] } } diff --git a/keyboards/moonlander/moonlander.c b/keyboards/moonlander/moonlander.c index 7eab3eea5add..e3788cee7221 100644 --- a/keyboards/moonlander/moonlander.c +++ b/keyboards/moonlander/moonlander.c @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - */ +*/ #include "moonlander.h" #include "raw_hid.h" @@ -27,9 +27,7 @@ bool is_launching = false; #ifdef DYNAMIC_MACRO_ENABLE static bool is_dynamic_recording = false; -void dynamic_macro_record_start_user(void) { - is_dynamic_recording = true; -} +void dynamic_macro_record_start_user(int8_t direction) { is_dynamic_recording = true; } void dynamic_macro_record_end_user(int8_t direction) { is_dynamic_recording = false; @@ -372,24 +370,29 @@ void keyboard_post_init_kb(void) { #ifdef HALFMOON __attribute__ ((weak)) const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = LAYOUT_halfmoon( - 29, 30, 31, 32, 33, 34, 35, - 22, 23, 24, 25, 26, 27, 28, - 15, 16, 17, 18, 19, 20, 21, - 9, 10, 11, 12, 13, 14, - 4, 5, 6, 7, 8, 3, - 0, 1, 2 + { 29, 30, 31, 32, 33, 34, 35 }, + { 22, 23, 24, 25, 26, 27, 28 }, + { 15, 16, 17, 18, 19, 20, 21 }, + { 9, 10, 11, 12, 13, 14, 0 }, + { 4, 5, 6, 7, 8, 0, 3 }, + { 0, 0, 0, 0, 0, 1, 2 }, ); #else __attribute__ ((weak)) -const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = LAYOUT_moonlander( - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 8, 9, 10, 11, 12, 3, 4, 13, 14, 15, 16, 17, - 0, 1, 2, 5, 6, 7 -); -#endif +const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = { + {58, 59, 60, 61, 62, 63, 64}, + {44, 45, 46, 47, 48, 49, 50}, + {30, 31, 32, 33, 34, 35, 36}, + {18, 19, 20, 21, 22, 23, 0}, + { 8, 9, 10, 11, 12, 0, 0}, + { 0, 1, 2, 3, 0, 0, 0}, + {65, 66, 67, 68, 69, 70, 71}, + {51, 52, 53, 54, 55, 56, 57}, + {37, 38, 39, 40, 41, 42, 43}, + { 0, 24, 25, 26, 27, 28, 29}, + { 0, 0, 13, 14, 15, 16, 17}, + { 0, 0, 0, 4, 5, 6, 7} +}; // clang-format on #endif diff --git a/keyboards/moonlander/moonlander.h b/keyboards/moonlander/moonlander.h index 4aacacccc22b..5222317d5ff0 100644 --- a/keyboards/moonlander/moonlander.h +++ b/keyboards/moonlander/moonlander.h @@ -33,54 +33,6 @@ extern bool mcp23018_leds[]; #define ML_LED_6(status) mcp23018_leds[2] = (bool)status // clang-format off -#define LAYOUT_halfmoon( \ - k00, k01, k02, k03, k04, k05, k06, \ - k07, k08, k09, k10, k11, k12, k13, \ - k14, k15, k16, k17, k18, k19, k20, \ - k21, k22, k23, k24, k25, k26, \ - k27, k28, k29, k30, k31, k32, \ - k33, k34, k35 \ -) \ -{ \ - { k00, k01, k02, k03, k04, k05, k06 }, \ - { k07, k08, k09, k10, k11, k12, k13 }, \ - { k14, k15, k16, k17, k18, k19, k20 }, \ - { k21, k22, k23, k24, k25, k26, KC_NO }, \ - { k27, k28, k29, k30, k31, KC_NO, KC_NO }, \ - { k33, k34, k35, k32, KC_NO, KC_NO, KC_NO }, \ - \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ - { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \ -} - -#define LAYOUT_moonlander( \ - k00, k01, k02, k03, k04, k05, k06, k60, k61, k62, k63, k64, k65, k66, \ - k10, k11, k12, k13, k14, k15, k16, k70, k71, k72, k73, k74, k75, k76, \ - k20, k21, k22, k23, k24, k25, k26, k80, k81, k82, k83, k84, k85, k86, \ - k30, k31, k32, k33, k34, k35, k91, k92, k93, k94, k95, k96, \ - k40, k41, k42, k43, k44, k53, kb3, ka2, ka3, ka4, ka5, ka6, \ - k50, k51, k52, kb4, kb5, kb6 \ -) \ -{ \ - { k00, k01, k02, k03, k04, k05, k06 }, \ - { k10, k11, k12, k13, k14, k15, k16 }, \ - { k20, k21, k22, k23, k24, k25, k26 }, \ - { k30, k31, k32, k33, k34, k35, KC_NO }, \ - { k40, k41, k42, k43, k44, KC_NO, KC_NO }, \ - { k50, k51, k52, k53, KC_NO, KC_NO, KC_NO }, \ -\ - { k60, k61, k62, k63, k64, k65, k66 }, \ - { k70, k71, k72, k73, k74, k75, k76 }, \ - { k80, k81, k82, k83, k84, k85, k86 }, \ - { KC_NO, k91, k92, k93, k94, k95, k96 }, \ - { KC_NO, KC_NO, ka2, ka3, ka4, ka5, ka6 }, \ - { KC_NO, KC_NO, KC_NO, kb3, kb4, kb5, kb6 } \ -} - #define LED_LAYOUT_moonlander( \ l00, l01, l02, l03, l04, l05, l06, l60, l61, l62, l63, l64, l65, l66, \ l10, l11, l12, l13, l14, l15, l16, l70, l71, l72, l73, l74, l75, l76, \ diff --git a/keyboards/moonlander/rules.mk b/keyboards/moonlander/rules.mk index b505ca2638b7..2f920fc3cd77 100644 --- a/keyboards/moonlander/rules.mk +++ b/keyboards/moonlander/rules.mk @@ -14,7 +14,6 @@ AUDIO_DRIVER = dac_additive CUSTOM_MATRIX = lite SWAP_HANDS_ENABLE = yes RGB_MATRIX_ENABLE = yes -RGB_MATRIX_DRIVER = IS31FL3731 EEPROM_DRIVER = i2c MOUSE_SHARED_EP = no diff --git a/keyboards/planck/config.h b/keyboards/planck/config.h index ff4b7bb3aa69..84c2fd11dcbb 100644 --- a/keyboards/planck/config.h +++ b/keyboards/planck/config.h @@ -17,17 +17,9 @@ along with this program. If not, see . #pragma once - -/* Planck PCB default pin-out */ -#define MATRIX_ROW_PINS { D0, D5, B5, B6 } -#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 } - #define AUDIO_VOICES #define AUDIO_PIN C6 -/* COL2ROW or ROW2COL */ -#define DIODE_DIRECTION COL2ROW - /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE /* Locking resynchronize hack */ diff --git a/keyboards/planck/ez/base/info.json b/keyboards/planck/ez/base/info.json deleted file mode 100644 index 07167a8c2a30..000000000000 --- a/keyboards/planck/ez/base/info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "keyboard_name": "Planck EZ", - "usb": { - "pid": "0xC6CE" - } -} diff --git a/keyboards/planck/ez/config.h b/keyboards/planck/ez/config.h index 93153d0ed05c..40bab50cc766 100644 --- a/keyboards/planck/ez/config.h +++ b/keyboards/planck/ez/config.h @@ -18,23 +18,6 @@ #pragma once -/* - * Keyboard Matrix Assignments - * - * Change this to how you wired your keyboard - * COLS: AVR pins used for columns, left to right - * ROWS: AVR pins used for rows, top to bottom - * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) - * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) - * -*/ - -#undef MATRIX_ROW_PINS -#undef MATRIX_COL_PINS - -#define MATRIX_ROW_PINS { A10, A9, A8, B15, C13, C14, C15, A2 } -#define MATRIX_COL_PINS { B11, B10, B2, B1, A7, B0 } - #define MUSIC_MAP #undef AUDIO_VOICES #undef AUDIO_PIN @@ -119,10 +102,6 @@ #define ENABLE_RGB_MATRIX_SOLID_SPLASH #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH -#define IGNORE_MOD_TAP_INTERRUPT - -#define TAPPING_TOGGLE 1 - #define MOUSEKEY_INTERVAL 20 #define MOUSEKEY_DELAY 0 #define MOUSEKEY_TIME_TO_MAX 60 diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index fb36f6094728..14dbc1c44f55 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -397,3 +397,14 @@ const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS] = {0}; # endif #endif + +const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = { + {36, 37, 38, 39, 40, 41}, + {24, 25, 26, 27, 28, 29}, + {12, 13, 14, 15, 16, 17}, + { 0, 1, 2, 10, 11, 6}, + {42, 43, 44, 45, 46, 47}, + {30, 31, 32, 33, 34, 35}, + {18, 19, 20, 21, 22, 23}, + { 7, 8, 9, 3, 4, 5} +}; diff --git a/keyboards/planck/ez/ez.h b/keyboards/planck/ez/ez.h index acadf1bc7152..e7bd92735c4d 100644 --- a/keyboards/planck/ez/ez.h +++ b/keyboards/planck/ez/ez.h @@ -17,48 +17,7 @@ */ #pragma once -#include "planck.h" - -#ifdef KEYBOARD_planck_ez_glow -# include "glow.h" -#endif - -#define LAYOUT_planck_1x2uC( \ - k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ - k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ - k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ - k30, k31, k32, k33, k34, k35, k37, k38, k39, k3a, k3b \ -) \ -{ \ - { k00, k01, k02, k03, k04, k05 }, \ - { k10, k11, k12, k13, k14, k15 }, \ - { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k3a, k3b, KC_NO }, \ - { k06, k07, k08, k09, k0a, k0b }, \ - { k16, k17, k18, k19, k1a, k1b }, \ - { k26, k27, k28, k29, k2a, k2b }, \ - { k37, k38, k39, k33, k34, k35 } \ -} - -#define LAYOUT_ortho_4x12( \ - k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ - k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ - k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ - k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b \ -) \ -{ \ - { k00, k01, k02, k03, k04, k05 }, \ - { k10, k11, k12, k13, k14, k15 }, \ - { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k3a, k3b, KC_NO }, \ - { k06, k07, k08, k09, k0a, k0b }, \ - { k16, k17, k18, k19, k1a, k1b }, \ - { k26, k27, k28, k29, k2a, k2b }, \ - { k37, k38, k39, k33, k34, k35 } \ -} - -#define LAYOUT_planck_mit LAYOUT_planck_1x2uC -#define LAYOUT_planck_grid LAYOUT_ortho_4x12 +#include "quantum.h" void planck_ez_right_led_on(void); void planck_ez_right_led_off(void); diff --git a/keyboards/planck/ez/glow/glow.c b/keyboards/planck/ez/glow/glow.c deleted file mode 100644 index c6733bbe502d..000000000000 --- a/keyboards/planck/ez/glow/glow.c +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright 2018 Jack Humbert - * Copyright 2015 ZSA Technology Labs Inc (@zsa) - * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "glow.h" diff --git a/keyboards/planck/ez/glow/glow.h b/keyboards/planck/ez/glow/glow.h deleted file mode 100644 index cfc26b5e0371..000000000000 --- a/keyboards/planck/ez/glow/glow.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2018 Jack Humbert - * Copyright 2015 ZSA Technology Labs Inc (@zsa) - * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "ez.h" diff --git a/keyboards/planck/ez/info.json b/keyboards/planck/ez/info.json index ae67be691dde..6848239279fb 100644 --- a/keyboards/planck/ez/info.json +++ b/keyboards/planck/ez/info.json @@ -6,6 +6,14 @@ "vid": "0x3297", "device_version": "0.0.1" }, + "rgb_matrix": { + "driver": "is31fl3737" + }, + "matrix_pins": { + "cols": ["B11", "B10", "B2", "B1", "A7", "B0"], + "rows": ["A10", "A9", "A8", "B15", "C13", "C14", "C15", "A2"] + }, + "diode_direction": "COL2ROW", "encoder": { "rotary": [ {"pin_a": "B12", "pin_b": "B13"} @@ -13,109 +21,122 @@ }, "processor": "STM32F303", "bootloader": "stm32-dfu", + "tapping": { + "toggle": 1 + }, "community_layouts": ["ortho_4x12", "planck_mit"], + "layout_aliases": { + "LAYOUT_planck_grid": "LAYOUT_ortho_4x12", + "LAYOUT_planck_mit": "LAYOUT_planck_1x2uC" + }, "layouts": { "LAYOUT_planck_1x2uC": { "layout": [ - { "x": 0, "y": 0 }, - { "x": 1, "y": 0 }, - { "x": 2, "y": 0 }, - { "x": 3, "y": 0 }, - { "x": 4, "y": 0 }, - { "x": 5, "y": 0 }, - { "x": 6, "y": 0 }, - { "x": 7, "y": 0 }, - { "x": 8, "y": 0 }, - { "x": 9, "y": 0 }, - { "x": 10, "y": 0 }, - { "x": 11, "y": 0 }, - { "x": 0, "y": 1 }, - { "x": 1, "y": 1 }, - { "x": 2, "y": 1 }, - { "x": 3, "y": 1 }, - { "x": 4, "y": 1 }, - { "x": 5, "y": 1 }, - { "x": 6, "y": 1 }, - { "x": 7, "y": 1 }, - { "x": 8, "y": 1 }, - { "x": 9, "y": 1 }, - { "x": 10, "y": 1 }, - { "x": 11, "y": 1 }, - { "x": 0, "y": 2 }, - { "x": 1, "y": 2 }, - { "x": 2, "y": 2 }, - { "x": 3, "y": 2 }, - { "x": 4, "y": 2 }, - { "x": 5, "y": 2 }, - { "x": 6, "y": 2 }, - { "x": 7, "y": 2 }, - { "x": 8, "y": 2 }, - { "x": 9, "y": 2 }, - { "x": 10, "y": 2 }, - { "x": 11, "y": 2 }, - { "x": 0, "y": 3 }, - { "x": 1, "y": 3 }, - { "x": 2, "y": 3 }, - { "x": 3, "y": 3 }, - { "x": 4, "y": 3 }, - { "x": 5, "y": 3, "w": 2 }, - { "x": 7, "y": 3 }, - { "x": 8, "y": 3 }, - { "x": 9, "y": 3 }, - { "x": 10, "y": 3 }, - { "x": 11, "y": 3 } + {"matrix": [0, 0], "x": 0, "y": 0}, + {"matrix": [0, 1], "x": 1, "y": 0}, + {"matrix": [0, 2], "x": 2, "y": 0}, + {"matrix": [0, 3], "x": 3, "y": 0}, + {"matrix": [0, 4], "x": 4, "y": 0}, + {"matrix": [0, 5], "x": 5, "y": 0}, + {"matrix": [4, 0], "x": 6, "y": 0}, + {"matrix": [4, 1], "x": 7, "y": 0}, + {"matrix": [4, 2], "x": 8, "y": 0}, + {"matrix": [4, 3], "x": 9, "y": 0}, + {"matrix": [4, 4], "x": 10, "y": 0}, + {"matrix": [4, 5], "x": 11, "y": 0}, + + {"matrix": [1, 0], "x": 0, "y": 1}, + {"matrix": [1, 1], "x": 1, "y": 1}, + {"matrix": [1, 2], "x": 2, "y": 1}, + {"matrix": [1, 3], "x": 3, "y": 1}, + {"matrix": [1, 4], "x": 4, "y": 1}, + {"matrix": [1, 5], "x": 5, "y": 1}, + {"matrix": [5, 0], "x": 6, "y": 1}, + {"matrix": [5, 1], "x": 7, "y": 1}, + {"matrix": [5, 2], "x": 8, "y": 1}, + {"matrix": [5, 3], "x": 9, "y": 1}, + {"matrix": [5, 4], "x": 10, "y": 1}, + {"matrix": [5, 5], "x": 11, "y": 1}, + + {"matrix": [2, 0], "x": 0, "y": 2}, + {"matrix": [2, 1], "x": 1, "y": 2}, + {"matrix": [2, 2], "x": 2, "y": 2}, + {"matrix": [2, 3], "x": 3, "y": 2}, + {"matrix": [2, 4], "x": 4, "y": 2}, + {"matrix": [2, 5], "x": 5, "y": 2}, + {"matrix": [6, 0], "x": 6, "y": 2}, + {"matrix": [6, 1], "x": 7, "y": 2}, + {"matrix": [6, 2], "x": 8, "y": 2}, + {"matrix": [6, 3], "x": 9, "y": 2}, + {"matrix": [6, 4], "x": 10, "y": 2}, + {"matrix": [6, 5], "x": 11, "y": 2}, + + {"matrix": [3, 0], "x": 0, "y": 3}, + {"matrix": [3, 1], "x": 1, "y": 3}, + {"matrix": [3, 2], "x": 2, "y": 3}, + {"matrix": [7, 3], "x": 3, "y": 3}, + {"matrix": [7, 4], "x": 4, "y": 3}, + {"matrix": [7, 5], "x": 5, "y": 3, "w": 2}, + {"matrix": [7, 0], "x": 7, "y": 3}, + {"matrix": [7, 1], "x": 8, "y": 3}, + {"matrix": [7, 2], "x": 9, "y": 3}, + {"matrix": [3, 3], "x": 10, "y": 3}, + {"matrix": [3, 4], "x": 11, "y": 3} ] }, "LAYOUT_ortho_4x12": { "layout": [ - { "x": 0, "y": 0 }, - { "x": 1, "y": 0 }, - { "x": 2, "y": 0 }, - { "x": 3, "y": 0 }, - { "x": 4, "y": 0 }, - { "x": 5, "y": 0 }, - { "x": 6, "y": 0 }, - { "x": 7, "y": 0 }, - { "x": 8, "y": 0 }, - { "x": 9, "y": 0 }, - { "x": 10, "y": 0 }, - { "x": 11, "y": 0 }, - { "x": 0, "y": 1 }, - { "x": 1, "y": 1 }, - { "x": 2, "y": 1 }, - { "x": 3, "y": 1 }, - { "x": 4, "y": 1 }, - { "x": 5, "y": 1 }, - { "x": 6, "y": 1 }, - { "x": 7, "y": 1 }, - { "x": 8, "y": 1 }, - { "x": 9, "y": 1 }, - { "x": 10, "y": 1 }, - { "x": 11, "y": 1 }, - { "x": 0, "y": 2 }, - { "x": 1, "y": 2 }, - { "x": 2, "y": 2 }, - { "x": 3, "y": 2 }, - { "x": 4, "y": 2 }, - { "x": 5, "y": 2 }, - { "x": 6, "y": 2 }, - { "x": 7, "y": 2 }, - { "x": 8, "y": 2 }, - { "x": 9, "y": 2 }, - { "x": 10, "y": 2 }, - { "x": 11, "y": 2 }, - { "x": 0, "y": 3 }, - { "x": 1, "y": 3 }, - { "x": 2, "y": 3 }, - { "x": 3, "y": 3 }, - { "x": 4, "y": 3 }, - { "x": 5, "y": 3 }, - { "x": 6, "y": 3 }, - { "x": 7, "y": 3 }, - { "x": 8, "y": 3 }, - { "x": 9, "y": 3 }, - { "x": 10, "y": 3 }, - { "x": 11, "y": 3 } + {"matrix": [0, 0], "x": 0, "y": 0}, + {"matrix": [0, 1], "x": 1, "y": 0}, + {"matrix": [0, 2], "x": 2, "y": 0}, + {"matrix": [0, 3], "x": 3, "y": 0}, + {"matrix": [0, 4], "x": 4, "y": 0}, + {"matrix": [0, 5], "x": 5, "y": 0}, + {"matrix": [4, 0], "x": 6, "y": 0}, + {"matrix": [4, 1], "x": 7, "y": 0}, + {"matrix": [4, 2], "x": 8, "y": 0}, + {"matrix": [4, 3], "x": 9, "y": 0}, + {"matrix": [4, 4], "x": 10, "y": 0}, + {"matrix": [4, 5], "x": 11, "y": 0}, + + {"matrix": [1, 0], "x": 0, "y": 1}, + {"matrix": [1, 1], "x": 1, "y": 1}, + {"matrix": [1, 2], "x": 2, "y": 1}, + {"matrix": [1, 3], "x": 3, "y": 1}, + {"matrix": [1, 4], "x": 4, "y": 1}, + {"matrix": [1, 5], "x": 5, "y": 1}, + {"matrix": [5, 0], "x": 6, "y": 1}, + {"matrix": [5, 1], "x": 7, "y": 1}, + {"matrix": [5, 2], "x": 8, "y": 1}, + {"matrix": [5, 3], "x": 9, "y": 1}, + {"matrix": [5, 4], "x": 10, "y": 1}, + {"matrix": [5, 5], "x": 11, "y": 1}, + + {"matrix": [2, 0], "x": 0, "y": 2}, + {"matrix": [2, 1], "x": 1, "y": 2}, + {"matrix": [2, 2], "x": 2, "y": 2}, + {"matrix": [2, 3], "x": 3, "y": 2}, + {"matrix": [2, 4], "x": 4, "y": 2}, + {"matrix": [2, 5], "x": 5, "y": 2}, + {"matrix": [6, 0], "x": 6, "y": 2}, + {"matrix": [6, 1], "x": 7, "y": 2}, + {"matrix": [6, 2], "x": 8, "y": 2}, + {"matrix": [6, 3], "x": 9, "y": 2}, + {"matrix": [6, 4], "x": 10, "y": 2}, + {"matrix": [6, 5], "x": 11, "y": 2}, + + {"matrix": [3, 0], "x": 0, "y": 3}, + {"matrix": [3, 1], "x": 1, "y": 3}, + {"matrix": [3, 2], "x": 2, "y": 3}, + {"matrix": [7, 3], "x": 3, "y": 3}, + {"matrix": [7, 4], "x": 4, "y": 3}, + {"matrix": [7, 5], "x": 5, "y": 3}, + {"matrix": [3, 5], "x": 6, "y": 3}, + {"matrix": [7, 0], "x": 7, "y": 3}, + {"matrix": [7, 1], "x": 8, "y": 3}, + {"matrix": [7, 2], "x": 9, "y": 3}, + {"matrix": [3, 3], "x": 10, "y": 3}, + {"matrix": [3, 4], "x": 11, "y": 3} ] } } diff --git a/keyboards/planck/ez/rules.mk b/keyboards/planck/ez/rules.mk index 6d8e88d3c8d9..0656b8d435b5 100755 --- a/keyboards/planck/ez/rules.mk +++ b/keyboards/planck/ez/rules.mk @@ -13,7 +13,6 @@ AUDIO_DRIVER = dac_additive RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. ENCODER_ENABLE = yes -RGB_MATRIX_DRIVER = IS31FL3737 LAYOUTS_HAS_RGB = no diff --git a/keyboards/planck/info.json b/keyboards/planck/info.json index cc57b6da6045..3f92fa168d4f 100644 --- a/keyboards/planck/info.json +++ b/keyboards/planck/info.json @@ -1,107 +1,4 @@ { "url": "https://olkb.com/planck", - "maintainer": "jackhumbert", - "layouts": { - "LAYOUT_planck_1x2uC": { - "layout": [ - { "w": 1, "x": 0, "y": 0 }, - { "w": 1, "x": 1, "y": 0 }, - { "w": 1, "x": 2, "y": 0 }, - { "w": 1, "x": 3, "y": 0 }, - { "w": 1, "x": 4, "y": 0 }, - { "w": 1, "x": 5, "y": 0 }, - { "w": 1, "x": 6, "y": 0 }, - { "w": 1, "x": 7, "y": 0 }, - { "w": 1, "x": 8, "y": 0 }, - { "w": 1, "x": 9, "y": 0 }, - { "w": 1, "x": 10, "y": 0 }, - { "w": 1, "x": 11, "y": 0 }, - { "w": 1, "x": 0, "y": 1 }, - { "w": 1, "x": 1, "y": 1 }, - { "w": 1, "x": 2, "y": 1 }, - { "w": 1, "x": 3, "y": 1 }, - { "w": 1, "x": 4, "y": 1 }, - { "w": 1, "x": 5, "y": 1 }, - { "w": 1, "x": 6, "y": 1 }, - { "w": 1, "x": 7, "y": 1 }, - { "w": 1, "x": 8, "y": 1 }, - { "w": 1, "x": 9, "y": 1 }, - { "w": 1, "x": 10, "y": 1 }, - { "w": 1, "x": 11, "y": 1 }, - { "w": 1, "x": 0, "y": 2 }, - { "w": 1, "x": 1, "y": 2 }, - { "w": 1, "x": 2, "y": 2 }, - { "w": 1, "x": 3, "y": 2 }, - { "w": 1, "x": 4, "y": 2 }, - { "w": 1, "x": 5, "y": 2 }, - { "w": 1, "x": 6, "y": 2 }, - { "w": 1, "x": 7, "y": 2 }, - { "w": 1, "x": 8, "y": 2 }, - { "w": 1, "x": 9, "y": 2 }, - { "w": 1, "x": 10, "y": 2 }, - { "w": 1, "x": 11, "y": 2 }, - { "w": 1, "x": 0, "y": 3 }, - { "w": 1, "x": 1, "y": 3 }, - { "w": 1, "x": 2, "y": 3 }, - { "w": 1, "x": 3, "y": 3 }, - { "w": 1, "x": 4, "y": 3 }, - { "w": 2, "x": 5, "y": 3 }, - { "w": 1, "x": 7, "y": 3 }, - { "w": 1, "x": 8, "y": 3 }, - { "w": 1, "x": 9, "y": 3 }, - { "w": 1, "x": 10, "y": 3 }, - { "w": 1, "x": 11, "y": 3 } ] - }, - "LAYOUT_ortho_4x12": { - "layout": [ - { "w": 1, "x": 0, "y": 0 }, - { "w": 1, "x": 1, "y": 0 }, - { "w": 1, "x": 2, "y": 0 }, - { "w": 1, "x": 3, "y": 0 }, - { "w": 1, "x": 4, "y": 0 }, - { "w": 1, "x": 5, "y": 0 }, - { "w": 1, "x": 6, "y": 0 }, - { "w": 1, "x": 7, "y": 0 }, - { "w": 1, "x": 8, "y": 0 }, - { "w": 1, "x": 9, "y": 0 }, - { "w": 1, "x": 10, "y": 0 }, - { "w": 1, "x": 11, "y": 0 }, - { "w": 1, "x": 0, "y": 1 }, - { "w": 1, "x": 1, "y": 1 }, - { "w": 1, "x": 2, "y": 1 }, - { "w": 1, "x": 3, "y": 1 }, - { "w": 1, "x": 4, "y": 1 }, - { "w": 1, "x": 5, "y": 1 }, - { "w": 1, "x": 6, "y": 1 }, - { "w": 1, "x": 7, "y": 1 }, - { "w": 1, "x": 8, "y": 1 }, - { "w": 1, "x": 9, "y": 1 }, - { "w": 1, "x": 10, "y": 1 }, - { "w": 1, "x": 11, "y": 1 }, - { "w": 1, "x": 0, "y": 2 }, - { "w": 1, "x": 1, "y": 2 }, - { "w": 1, "x": 2, "y": 2 }, - { "w": 1, "x": 3, "y": 2 }, - { "w": 1, "x": 4, "y": 2 }, - { "w": 1, "x": 5, "y": 2 }, - { "w": 1, "x": 6, "y": 2 }, - { "w": 1, "x": 7, "y": 2 }, - { "w": 1, "x": 8, "y": 2 }, - { "w": 1, "x": 9, "y": 2 }, - { "w": 1, "x": 10, "y": 2 }, - { "w": 1, "x": 11, "y": 2 }, - { "w": 1, "x": 0, "y": 3 }, - { "w": 1, "x": 1, "y": 3 }, - { "w": 1, "x": 2, "y": 3 }, - { "w": 1, "x": 3, "y": 3 }, - { "w": 1, "x": 4, "y": 3 }, - { "w": 1, "x": 5, "y": 3 }, - { "w": 1, "x": 6, "y": 3 }, - { "w": 1, "x": 7, "y": 3 }, - { "w": 1, "x": 8, "y": 3 }, - { "w": 1, "x": 9, "y": 3 }, - { "w": 1, "x": 10, "y": 3 }, - { "w": 1, "x": 11, "y": 3 } ] - } - } + "maintainer": "jackhumbert" } diff --git a/keyboards/planck/planck.c b/keyboards/planck/planck.c index 20db22055c58..660be55babec 100644 --- a/keyboards/planck/planck.c +++ b/keyboards/planck/planck.c @@ -1,4 +1,4 @@ -#include "planck.h" +#include "quantum.h" __attribute__ ((weak)) void matrix_init_kb(void) { @@ -11,13 +11,6 @@ void matrix_init_kb(void) { matrix_init_user(); } -const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = LAYOUT_planck_grid( - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 -); - #ifdef ENCODER_ENABLE bool encoder_update_kb(uint8_t index, bool clockwise) { if (!encoder_update_user(index, clockwise)) { return false; } diff --git a/keyboards/planck/planck.h b/keyboards/planck/planck.h deleted file mode 100644 index 0d5c14fdacea..000000000000 --- a/keyboards/planck/planck.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2018 Jack Humbert - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "quantum.h" - -#if defined(KEYBOARD_planck_ez) -# include "ez.h" -#endif // Planck revisions diff --git a/keyboards/planck/readme.md b/keyboards/planck/readme.md index 748c2514788a..797774dc0a15 100644 --- a/keyboards/planck/readme.md +++ b/keyboards/planck/readme.md @@ -6,7 +6,7 @@ Planck A compact 40% (12x4) ortholinear keyboard kit made and sold by OLKB and Massdrop. [More info on qmk.fm](http://qmk.fm/planck/) Keyboard Maintainer: [Jack Humbert](https://github.com/jackhumbert) -Hardware Supported: Planck PCB rev1, rev2, rev3, rev4, rev5, rev6; Planck Light, Planck EZ +Hardware Supported: Planck PCB rev1, rev2, rev3, rev4, rev5, rev6, rev7; Planck Light, Planck EZ Hardware Availability: [OLKB.com](https://olkb.com), [Massdrop](https://www.massdrop.com/buy/planck-mechanical-keyboard?mode=guest_open), [Ergodox (Planck EZ)](https://ergodox-ez.com/pages/planck) Make example for this keyboard (after setting up your build environment): diff --git a/lib/chibios b/lib/chibios index 0062927e3058..11edb1610980 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 0062927e3058a8b5ef587234bbd98d42fb4e595e +Subproject commit 11edb1610980f213b9f83161e1715a46fb7e4c51 diff --git a/lib/chibios-contrib b/lib/chibios-contrib index a224be155ae1..da78eb3759b8 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit a224be155ae18d38deccf33a6c1d259b9a5ad8d3 +Subproject commit da78eb3759b8d1779b237657c7667baa4aa95ca1 diff --git a/lib/python/qmk/c_parse.py b/lib/python/qmk/c_parse.py index 83ab1d1e6d63..08d23cf5ba9f 100644 --- a/lib/python/qmk/c_parse.py +++ b/lib/python/qmk/c_parse.py @@ -11,7 +11,7 @@ from qmk.comment_remover import comment_remover -default_key_entry = {'x': -1, 'y': 0, 'w': 1} +default_key_entry = {'x': -1, 'y': 0} single_comment_regex = re.compile(r'\s+/[/*].*$') multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE) layout_macro_define_regex = re.compile(r'^#\s*define') @@ -90,8 +90,10 @@ def find_layouts(file): cli.log.error('Invalid LAYOUT macro in %s: Empty parameter name in macro %s at pos %s.', file, macro_name, i) elif key['label'] not in matrix_locations: cli.log.error('Invalid LAYOUT macro in %s: Key %s in macro %s has no matrix position!', file, key['label'], macro_name) + elif len(matrix_locations.get(key['label'])) > 1: + cli.log.error('Invalid LAYOUT macro in %s: Key %s in macro %s has multiple matrix positions (%s)', file, key['label'], macro_name, ', '.join(str(x) for x in matrix_locations[key['label']])) else: - key['matrix'] = matrix_locations[key['label']] + key['matrix'] = matrix_locations[key['label']][0] parsed_layouts[macro_name] = { 'layout': parsed_layout, @@ -186,7 +188,9 @@ def _parse_matrix_locations(matrix, file, macro_name): row = row.replace('{', '').replace('}', '') for col_num, identifier in enumerate(row.split(',')): if identifier != 'KC_NO': - matrix_locations[identifier] = [row_num, col_num] + if identifier not in matrix_locations: + matrix_locations[identifier] = [] + matrix_locations[identifier].append([row_num, col_num]) return matrix_locations @@ -213,10 +217,13 @@ def _coerce_led_token(_type, value): return value_map[value] -def _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags): +def _validate_led_config(matrix, matrix_rows, matrix_cols, matrix_indexes, position, position_raw, flags): # TODO: Improve crude parsing/validation if len(matrix) != matrix_rows and len(matrix) != (matrix_rows / 2): raise ValueError("Unable to parse g_led_config matrix data") + for index, row in enumerate(matrix): + if len(row) != matrix_cols: + raise ValueError(f"Number of columns in row {index} ({len(row)}) does not match matrix ({matrix_cols})") if len(position) != len(flags): raise ValueError(f"Number of g_led_config physical positions ({len(position)}) does not match number of flags ({len(flags)})") if len(matrix_indexes) and (max(matrix_indexes) >= len(flags)): @@ -230,32 +237,44 @@ def _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position def _parse_led_config(file, matrix_cols, matrix_rows): """Return any 'raw' led/rgb matrix config """ - matrix_raw = [] + matrix = [] position_raw = [] flags = [] - found_led_config = False + found_led_config_t = False + found_g_led_config = False bracket_count = 0 section = 0 + current_row_index = 0 + current_row = [] + for _type, value in lex(_preprocess_c_file(file), CLexer()): - # Assume g_led_config..stuff..; - if value == 'g_led_config': - found_led_config = True + if not found_g_led_config: + # Check for type + if value == 'led_config_t': + found_led_config_t = True + # Type found, now check for name + elif found_led_config_t and value == 'g_led_config': + found_g_led_config = True elif value == ';': - found_led_config = False - elif found_led_config: + found_g_led_config = False + else: # Assume bracket count hints to section of config we are within if value == '{': bracket_count += 1 if bracket_count == 2: section += 1 elif value == '}': + if section == 1 and bracket_count == 3: + matrix.append(current_row) + current_row = [] + current_row_index += 1 bracket_count -= 1 else: # Assume any non whitespace value here is important enough to stash if _type in [Token.Literal.Number.Integer, Token.Literal.Number.Float, Token.Literal.Number.Hex, Token.Name]: if section == 1 and bracket_count == 3: - matrix_raw.append(_coerce_led_token(_type, value)) + current_row.append(_coerce_led_token(_type, value)) if section == 2 and bracket_count == 3: position_raw.append(_coerce_led_token(_type, value)) if section == 3 and bracket_count == 2: @@ -265,16 +284,15 @@ def _parse_led_config(file, matrix_cols, matrix_rows): return None # Slightly better intrim format - matrix = list(_get_chunks(matrix_raw, matrix_cols)) position = list(_get_chunks(position_raw, 2)) - matrix_indexes = list(filter(lambda x: x is not None, matrix_raw)) + matrix_indexes = list(filter(lambda x: x is not None, sum(matrix, []))) # If we have not found anything - bail with no error if not section: return None # Throw any validation errors - _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags) + _validate_led_config(matrix, matrix_rows, matrix_cols, matrix_indexes, position, position_raw, flags) return (matrix, position, flags) diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 778eccada896..9c3decf4f76a 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py @@ -39,6 +39,7 @@ 'qmk.cli.compile', 'qmk.cli.docs', 'qmk.cli.doctor', + 'qmk.cli.find', 'qmk.cli.flash', 'qmk.cli.format.c', 'qmk.cli.format.json', @@ -56,6 +57,7 @@ 'qmk.cli.generate.keyboard_h', 'qmk.cli.generate.keycodes', 'qmk.cli.generate.keycodes_tests', + 'qmk.cli.generate.make_dependencies', 'qmk.cli.generate.rgb_breathe_table', 'qmk.cli.generate.rules_mk', 'qmk.cli.generate.version_h', diff --git a/lib/python/qmk/cli/c2json.py b/lib/python/qmk/cli/c2json.py index 43110a93875a..7f6aca070a1d 100644 --- a/lib/python/qmk/cli/c2json.py +++ b/lib/python/qmk/cli/c2json.py @@ -57,7 +57,7 @@ def c2json(cli): cli.args.output.parent.mkdir(parents=True, exist_ok=True) if cli.args.output.exists(): cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak')) - cli.args.output.write_text(json.dumps(keymap_json, cls=InfoJSONEncoder)) + cli.args.output.write_text(json.dumps(keymap_json, cls=InfoJSONEncoder, sort_keys=True)) if not cli.args.quiet: cli.log.info('Wrote keymap to %s.', cli.args.output) diff --git a/lib/python/qmk/cli/find.py b/lib/python/qmk/cli/find.py new file mode 100644 index 000000000000..2836eb8a5421 --- /dev/null +++ b/lib/python/qmk/cli/find.py @@ -0,0 +1,31 @@ +"""Command to search through all keyboards and keymaps for a given search criteria. +""" +from milc import cli +from qmk.search import search_keymap_targets + + +@cli.argument( + '-f', + '--filter', + arg_only=True, + action='append', + default=[], + help= # noqa: `format-python` and `pytest` don't agree here. + "Filter the list of keyboards based on their info.json data. Accepts the formats key=value, function(key), or function(key,value), eg. 'features.rgblight=true'. Valid functions are 'absent', 'contains', 'exists' and 'length'. May be passed multiple times; all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here. +) +@cli.argument('-p', '--print', arg_only=True, action='append', default=[], help="For each matched target, print the value of the supplied info.json key. May be passed multiple times.") +@cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.") +@cli.subcommand('Find builds which match supplied search criteria.') +def find(cli): + """Search through all keyboards and keymaps for a given search criteria. + """ + + if len(cli.args.filter) == 0 and len(cli.args.print) > 0: + cli.log.warning('No filters supplied -- keymaps not parsed, unable to print requested values.') + + targets = search_keymap_targets(cli.args.keymap, cli.args.filter, cli.args.print) + for keyboard, keymap, print_vals in targets: + print(f'{keyboard}:{keymap}') + + for key, val in print_vals: + print(f' {key}={val}') diff --git a/lib/python/qmk/cli/format/json.py b/lib/python/qmk/cli/format/json.py index 19d504491f12..058b61329424 100755 --- a/lib/python/qmk/cli/format/json.py +++ b/lib/python/qmk/cli/format/json.py @@ -62,4 +62,4 @@ def format_json(cli): json_file['layers'][layer_num] = current_layer # Display the results - print(json.dumps(json_file, cls=json_encoder)) + print(json.dumps(json_file, cls=json_encoder, sort_keys=True)) diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index 008622cac163..e7b545109f20 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py @@ -7,7 +7,7 @@ from qmk.path import normpath py_file_suffixes = ('py',) -py_dirs = ['lib/python'] +py_dirs = ['lib/python', 'util/ci'] def yapf_run(files): diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 11d4616199d3..61a2f9f7329c 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -8,7 +8,6 @@ from qmk.datetime import current_datetime from qmk.info import info_json -from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load from qmk.keymap import list_keymaps from qmk.keyboard import find_readme, list_keyboards @@ -43,14 +42,14 @@ def _resolve_keycode_specs(output_folder): overall = load_spec(version) output_file = output_folder / f'constants/keycodes_{version}.json' - output_file.write_text(json.dumps(overall), encoding='utf-8') + output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8') for lang in list_languages(): for version in list_versions(lang): overall = load_spec(version, lang) output_file = output_folder / f'constants/keycodes_{lang}_{version}.json' - output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8') + output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8') # Purge files consumed by 'load_spec' shutil.rmtree(output_folder / 'constants/keycodes/') @@ -64,6 +63,12 @@ def _filtered_copy(src, dst): data = json_load(src) dst = dst.with_suffix('.json') + dst.write_text(json.dumps(data, separators=(',', ':')), encoding='utf-8') + return dst + + if dst.suffix == '.jsonschema': + data = json_load(src) + dst.write_text(json.dumps(data), encoding='utf-8') return dst @@ -130,7 +135,7 @@ def generate_api(cli): } keyboard_dir.mkdir(parents=True, exist_ok=True) - keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}) + keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}, separators=(',', ':')) if not cli.args.dry_run: keyboard_info.write_text(keyboard_json, encoding='utf-8') cli.log.debug('Wrote file %s', keyboard_info) @@ -144,7 +149,7 @@ def generate_api(cli): keymap_hjson = kb_json['keymaps'][keymap]['path'] keymap_json = v1_dir / keymap_hjson keymap_json.parent.mkdir(parents=True, exist_ok=True) - keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson))), encoding='utf-8') + keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson)), separators=(',', ':')), encoding='utf-8') cli.log.debug('Wrote keymap %s', keymap_json) if 'usb' in kb_json: @@ -173,12 +178,12 @@ def generate_api(cli): _resolve_keycode_specs(v1_dir) # Write the global JSON files - keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder) - usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder) - keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder) - keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder) - keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder) - constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) + keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, separators=(',', ':')) + usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, separators=(',', ':')) + keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, separators=(',', ':')) + keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, separators=(',', ':')) + keyboard_metadata_json = json.dumps(keyboard_metadata, separators=(',', ':')) + constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}, separators=(',', ':')) if not cli.args.dry_run: keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8') diff --git a/lib/python/qmk/cli/generate/autocorrect_data.py b/lib/python/qmk/cli/generate/autocorrect_data.py index 5b70e0cb4e16..b11c66d95d21 100644 --- a/lib/python/qmk/cli/generate/autocorrect_data.py +++ b/lib/python/qmk/cli/generate/autocorrect_data.py @@ -63,7 +63,13 @@ def parse_file(file_name: str) -> List[Tuple[str, str]]: """ try: + import english_words + correct_words = english_words.get_english_words_set(['web2'], lower=True, alpha=True) + except AttributeError: from english_words import english_words_lower_alpha_set as correct_words + if not cli.args.quiet: + cli.echo('The english_words package is outdated, update by running:') + cli.echo(' {fg_cyan}python3 -m pip install english_words --upgrade') except ImportError: if not cli.args.quiet: cli.echo('Autocorrection will falsely trigger when a typo is a substring of a correctly spelled word.') diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 7ac0f740fe92..5e1a18a69b27 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -15,6 +15,8 @@ from qmk.commands import create_make_command from qmk.constants import QMK_FIRMWARE from qmk.decorators import automagic_keyboard, automagic_keymap +from qmk.keyboard import keyboard_completer, keyboard_folder +from qmk.keymap import keymap_completer @lru_cache(maxsize=10) @@ -74,8 +76,8 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]: return records -@cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') -@cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard\'s name') +@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap\'s name') @cli.subcommand('Create a compilation database.') @automagic_keyboard @automagic_keymap @@ -104,7 +106,7 @@ def generate_compilation_database(cli: MILC) -> Union[bool, int]: if not command: cli.log.error('You must supply both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.') - cli.echo('usage: qmk compiledb [-kb KEYBOARD] [-km KEYMAP]') + cli.echo('usage: qmk generate-compilation-database [-kb KEYBOARD] [-km KEYMAP]') return False # remove any environment variable overrides which could trip us up diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index c256ec453101..64d4db6ffe14 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -119,7 +119,9 @@ def generate_encoder_config(encoder_json, config_h_lines, postfix=''): config_h_lines.append(generate_define(f'ENCODERS_PAD_B{postfix}', f'{{ {", ".join(b_pads)} }}')) if None in resolutions: - cli.log.debug("Unable to generate ENCODER_RESOLUTION configuration") + cli.log.debug(f"Unable to generate ENCODER_RESOLUTION{postfix} configuration") + elif len(resolutions) == 0: + cli.log.debug(f"Skipping ENCODER_RESOLUTION{postfix} configuration") elif len(set(resolutions)) == 1: config_h_lines.append(generate_define(f'ENCODER_RESOLUTION{postfix}', resolutions[0])) else: diff --git a/lib/python/qmk/cli/generate/info_json.py b/lib/python/qmk/cli/generate/info_json.py index 0dc80f10ccce..08c294146bc4 100755 --- a/lib/python/qmk/cli/generate/info_json.py +++ b/lib/python/qmk/cli/generate/info_json.py @@ -76,7 +76,7 @@ def generate_info_json(cli): # Build the info.json file kb_info_json = info_json(cli.config.generate_info_json.keyboard) strip_info_json(kb_info_json) - info_json_text = json.dumps(kb_info_json, indent=4, cls=InfoJSONEncoder) + info_json_text = json.dumps(kb_info_json, indent=4, cls=InfoJSONEncoder, sort_keys=True) if cli.args.output: # Write to a file diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py index 152921bdce60..b9e89032b9e2 100755 --- a/lib/python/qmk/cli/generate/keyboard_h.py +++ b/lib/python/qmk/cli/generate/keyboard_h.py @@ -11,12 +11,9 @@ from qmk.constants import COL_LETTERS, ROW_LETTERS, GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE -def _generate_layouts(keyboard): - """Generates the layouts.h file. +def _generate_layouts(keyboard, kb_info_json): + """Generates the layouts macros. """ - # Build the info.json file - kb_info_json = info_json(keyboard) - if 'matrix_size' not in kb_info_json: cli.log.error(f'{keyboard}: Invalid matrix config.') return [] @@ -40,14 +37,19 @@ def _generate_layouts(keyboard): row, col = key_data['matrix'] identifier = f'k{ROW_LETTERS[row]}{COL_LETTERS[col]}' - try: - layout_matrix[row][col] = identifier - layout_keys.append(identifier) - except IndexError: + if row >= row_num or col >= col_num: key_name = key_data.get('label', identifier) - cli.log.error(f'{keyboard}/{layout_name}: Matrix data out of bounds at index {index} ({key_name}): [{row}, {col}]') + if row >= row_num: + cli.log.error(f'{keyboard}/{layout_name}: Matrix row for key {index} ({key_name}) is {row} but must be less than {row_num}') + + if col >= col_num: + cli.log.error(f'{keyboard}/{layout_name}: Matrix column for key {index} ({key_name}) is {col} but must be less than {col_num}') + return [] + layout_matrix[row][col] = identifier + layout_keys.append(identifier) + lines.append('') lines.append(f'#define {layout_name}({", ".join(layout_keys)}) {{ \\') @@ -65,6 +67,32 @@ def _generate_layouts(keyboard): return lines +def _generate_keycodes(kb_info_json): + """Generates keyboard level keycodes. + """ + if 'keycodes' not in kb_info_json: + return [] + + lines = [] + lines.append('enum keyboard_keycodes {') + + for index, item in enumerate(kb_info_json.get('keycodes')): + key = item["key"] + if index == 0: + lines.append(f' {key} = QK_KB_0,') + else: + lines.append(f' {key},') + + lines.append('};') + + for item in kb_info_json.get('keycodes', []): + key = item["key"] + for alias in item.get("aliases", []): + lines.append(f'#define {alias} {key}') + + return lines + + @cli.argument('-i', '--include', nargs='?', arg_only=True, help='Optional file to include') @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") @@ -73,8 +101,12 @@ def _generate_layouts(keyboard): def generate_keyboard_h(cli): """Generates the keyboard.h file. """ + # Build the info.json file + kb_info_json = info_json(cli.args.keyboard) + keyboard_h = cli.args.include - dd_layouts = _generate_layouts(cli.args.keyboard) + dd_layouts = _generate_layouts(cli.args.keyboard, kb_info_json) + dd_keycodes = _generate_keycodes(kb_info_json) valid_config = dd_layouts or keyboard_h # Build the layouts.h file. @@ -87,6 +119,11 @@ def generate_keyboard_h(cli): if keyboard_h: keyboard_h_lines.append(f'#include "{Path(keyboard_h).name}"') + keyboard_h_lines.append('') + keyboard_h_lines.append('// Keycode content') + if dd_keycodes: + keyboard_h_lines.extend(dd_keycodes) + # Protect against poorly configured keyboards if not valid_config: keyboard_h_lines.append('#error(".h is required unless your keyboard uses data-driven configuration. Please rename your keyboard\'s header file to .h")') diff --git a/lib/python/qmk/cli/generate/keycodes.py b/lib/python/qmk/cli/generate/keycodes.py index 17503bac637a..ed8b6827bdfe 100644 --- a/lib/python/qmk/cli/generate/keycodes.py +++ b/lib/python/qmk/cli/generate/keycodes.py @@ -96,6 +96,11 @@ def _generate_helpers(lines, keycodes): def _generate_aliases(lines, keycodes): + # Work around ChibiOS ch.h include guard + if 'CH_H' in [value['key'] for value in keycodes['aliases'].values()]: + lines.append('') + lines.append('#undef CH_H') + lines.append('') lines.append('// Aliases') for key, value in keycodes["aliases"].items(): @@ -143,7 +148,7 @@ def generate_keycode_extras(cli): """ # Build the header file. - keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keymap.h"', '// clang-format off'] + keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keycodes.h"', '// clang-format off'] keycodes = load_spec(cli.args.version, cli.args.lang) diff --git a/lib/python/qmk/cli/generate/make_dependencies.py b/lib/python/qmk/cli/generate/make_dependencies.py new file mode 100755 index 000000000000..9b695e907de5 --- /dev/null +++ b/lib/python/qmk/cli/generate/make_dependencies.py @@ -0,0 +1,55 @@ +"""Used by the make system to generate dependency lists for each of the generated files. +""" +from pathlib import Path +from milc import cli + +from argcomplete.completers import FilesCompleter + +from qmk.commands import dump_lines +from qmk.keyboard import keyboard_completer, keyboard_folder +from qmk.keymap import keymap_completer, locate_keymap +from qmk.path import normpath, FileType + + +@cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON.') +@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') +@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") +@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate dependency file for.') +@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') +@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True) +def generate_make_dependencies(cli): + """Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard. + """ + interesting_files = [ + 'info.json', + 'rules.mk', + 'post_rules.mk', + 'config.h', + 'post_config.h', + ] + + check_files = [] + + # Walk up the keyboard's directory tree looking for the files we're interested in + keyboards_root = Path('keyboards') + parent_path = Path('keyboards') / cli.args.keyboard + while parent_path != keyboards_root: + for file in interesting_files: + check_files.append(parent_path / file) + parent_path = parent_path.parent + + # Find the keymap and include any of the interesting files + if cli.args.keymap is not None: + km = locate_keymap(cli.args.keyboard, cli.args.keymap) + if km is not None: + # keymap.json is only valid for the keymap, so check this one separately + check_files.append(km.parent / 'keymap.json') + # Add all the interesting files + for file in interesting_files: + check_files.append(km.parent / file) + + # If we have a matching userspace, include those too + for file in interesting_files: + check_files.append(Path('users') / cli.args.keymap / file) + + dump_lines(cli.args.output, [f'generated-files: $(wildcard {found})\n' for found in check_files]) diff --git a/lib/python/qmk/cli/git/submodule.py b/lib/python/qmk/cli/git/submodule.py index 9f354c021e00..ef116ea1248e 100644 --- a/lib/python/qmk/cli/git/submodule.py +++ b/lib/python/qmk/cli/git/submodule.py @@ -7,14 +7,21 @@ REMOVE_DIRS = [ 'lib/ugfx', - 'lib/pico-sdk', 'lib/chibios-contrib/ext/mcux-sdk', - 'lib/lvgl', +] + +IGNORE_DIRS = [ + 'lib/arm_atsam', + 'lib/fnv', + 'lib/lib8tion', + 'lib/python', + 'lib/usbhost', ] @cli.argument('--check', arg_only=True, action='store_true', help='Check if the submodules are dirty, and display a warning if they are.') @cli.argument('--sync', arg_only=True, action='store_true', help='Shallow clone any missing submodules.') +@cli.argument('-f', '--force', action='store_true', help='Flag to remove unexpected directories') @cli.subcommand('Git Submodule actions.') def git_submodule(cli): """Git Submodule actions @@ -29,7 +36,15 @@ def git_submodule(cli): cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False) return True - for folder in REMOVE_DIRS: + # can be the default behavior with: qmk config git_submodule.force=True + remove_dirs = REMOVE_DIRS + if cli.config.git_submodule.force: + # Also trash everything that isnt marked as "safe" + for path in normpath('lib').iterdir(): + if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS): + remove_dirs.append(path) + + for folder in map(normpath, remove_dirs): if normpath(folder).is_dir(): print(f"Removing '{folder}'") shutil.rmtree(folder) diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index fa5729bcc9b8..e662407474e9 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py @@ -18,6 +18,33 @@ UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf') +def _strip_api_content(info_json): + # Ideally this would only be added in the API pathway. + info_json.pop('platform', None) + info_json.pop('platform_key', None) + info_json.pop('processor_type', None) + info_json.pop('protocol', None) + info_json.pop('config_h_features', None) + info_json.pop('keymaps', None) + info_json.pop('keyboard_folder', None) + info_json.pop('parse_errors', None) + info_json.pop('parse_warnings', None) + + for layout in info_json.get('layouts', {}).values(): + layout.pop('filename', None) + layout.pop('c_macro', None) + layout.pop('json_layout', None) + + if 'matrix_pins' in info_json: + info_json.pop('matrix_size', None) + + for feature in ['rgb_matrix', 'led_matrix']: + if info_json.get(feature, {}).get("layout", None): + info_json[feature].pop('led_count', None) + + return info_json + + def show_keymap(kb_info_json, title_caps=True): """Render the keymap in ascii art. """ @@ -81,7 +108,6 @@ def print_friendly_output(kb_info_json): cli.echo('{fg_blue}Maintainer{fg_reset}: QMK Community') else: cli.echo('{fg_blue}Maintainer{fg_reset}: %s', kb_info_json['maintainer']) - cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', kb_info_json.get('keyboard_folder', 'Unknown')) cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) @@ -141,6 +167,7 @@ def print_parsed_rules_mk(keyboard_name): @cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') @cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') @cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.') +@cli.argument('-a', '--api', action='store_true', help='Show fully processed info intended for API consumption.') @cli.subcommand('Keyboard information.') @automagic_keyboard @automagic_keymap @@ -171,9 +198,12 @@ def info(cli): else: kb_info_json = info_json(cli.config.info.keyboard) + if not cli.args.api: + kb_info_json = _strip_api_content(kb_info_json) + # Output in the requested format if cli.args.format == 'json': - print(json.dumps(kb_info_json, cls=InfoJSONEncoder)) + print(json.dumps(kb_info_json, cls=InfoJSONEncoder, sort_keys=True)) return True elif cli.args.format == 'text': print_dotted_output(kb_info_json) diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py index 2873a9bfd3d4..a2db31494745 100755 --- a/lib/python/qmk/cli/json2c.py +++ b/lib/python/qmk/cli/json2c.py @@ -5,7 +5,7 @@ import qmk.keymap import qmk.path -from qmk.commands import parse_configurator_json +from qmk.commands import dump_lines, parse_configurator_json @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') @@ -21,21 +21,8 @@ def json2c(cli): # Parse the configurator from json file (or stdin) user_keymap = parse_configurator_json(cli.args.filename) - # Environment processing - if cli.args.output and cli.args.output.name == '-': - cli.args.output = None - # Generate the keymap keymap_c = qmk.keymap.generate_c(user_keymap) - if cli.args.output: - cli.args.output.parent.mkdir(parents=True, exist_ok=True) - if cli.args.output.exists(): - cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak')) - cli.args.output.write_text(keymap_c) - - if not cli.args.quiet: - cli.log.info('Wrote keymap to %s.', cli.args.output) - - else: - print(keymap_c) + # Show the results + dump_lines(cli.args.output, keymap_c.split('\n'), cli.args.quiet) diff --git a/lib/python/qmk/cli/mass_compile.py b/lib/python/qmk/cli/mass_compile.py index 2821a60c8794..ddd946a32bc6 100755 --- a/lib/python/qmk/cli/mass_compile.py +++ b/lib/python/qmk/cli/mass_compile.py @@ -2,54 +2,18 @@ This will compile everything in parallel, for testing purposes. """ -import fnmatch -import logging -import multiprocessing import os -import re from pathlib import Path from subprocess import DEVNULL -from dotty_dict import dotty from milc import cli from qmk.constants import QMK_FIRMWARE from qmk.commands import _find_make, get_make_parallel_args -from qmk.info import keymap_json -import qmk.keyboard -import qmk.keymap - - -def _set_log_level(level): - cli.acquire_lock() - old = cli.log_level - cli.log_level = level - cli.log.setLevel(level) - logging.root.setLevel(level) - cli.release_lock() - return old - - -def _all_keymaps(keyboard): - old = _set_log_level(logging.CRITICAL) - keymaps = qmk.keymap.list_keymaps(keyboard) - _set_log_level(old) - return (keyboard, keymaps) - - -def _keymap_exists(keyboard, keymap): - old = _set_log_level(logging.CRITICAL) - ret = keyboard if qmk.keymap.locate_keymap(keyboard, keymap) is not None else None - _set_log_level(old) - return ret - - -def _load_keymap_info(keyboard, keymap): - old = _set_log_level(logging.CRITICAL) - ret = (keyboard, keymap, keymap_json(keyboard, keymap)) - _set_log_level(old) - return ret +from qmk.keyboard import resolve_keyboard +from qmk.search import search_keymap_targets +@cli.argument('builds', nargs='*', arg_only=True, help="List of builds in form : to compile in parallel. Specifying this overrides all other target search options.") @cli.argument('-t', '--no-temp', arg_only=True, action='store_true', help="Remove temporary files during build.") @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.") @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") @@ -75,55 +39,10 @@ def mass_compile(cli): builddir = Path(QMK_FIRMWARE) / '.build' makefile = builddir / 'parallel_kb_builds.mk' - targets = [] - - with multiprocessing.Pool() as pool: - cli.log.info(f'Retrieving list of keyboards with keymap "{cli.args.keymap}"...') - target_list = [] - if cli.args.keymap == 'all': - kb_to_kms = pool.map(_all_keymaps, qmk.keyboard.list_keyboards()) - for targets in kb_to_kms: - keyboard = targets[0] - keymaps = targets[1] - target_list.extend([(keyboard, keymap) for keymap in keymaps]) - else: - target_list = [(kb, cli.args.keymap) for kb in filter(lambda kb: kb is not None, pool.starmap(_keymap_exists, [(kb, cli.args.keymap) for kb in qmk.keyboard.list_keyboards()]))] - - if len(cli.args.filter) == 0: - targets = 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 pool.starmap(_load_keymap_info, target_list)] - - equals_re = re.compile(r'^(?P[a-zA-Z0-9_\.]+)\s*=\s*(?P[^#]+)$') - exists_re = re.compile(r'^exists\((?P[a-zA-Z0-9_\.]+)\)$') - for filter_txt in cli.args.filter: - f = equals_re.match(filter_txt) - if f is not None: - key = f.group('key') - value = f.group('value') - cli.log.info(f'Filtering on condition ("{key}" == "{value}")...') - - def _make_filter(k, v): - expr = fnmatch.translate(v) - rule = re.compile(expr, re.IGNORECASE) - - def f(e): - lhs = e[2].get(k) - lhs = str(False if lhs is None else lhs) - return rule.search(lhs) is not None - - return f - - valid_keymaps = filter(_make_filter(key, value), valid_keymaps) - - f = exists_re.match(filter_txt) - if f is not None: - key = f.group('key') - cli.log.info(f'Filtering on condition (exists: "{key}")...') - valid_keymaps = filter(lambda e: e[2].get(key) is not None, valid_keymaps) - - targets = [(e[0], e[1]) for e in valid_keymaps] + if len(cli.args.builds) > 0: + targets = list(sorted(set([(resolve_keyboard(e[0]), e[1]) for e in [b.split(':') for b in cli.args.builds]]))) + else: + targets = search_keymap_targets(cli.args.keymap, cli.args.filter) if len(targets) == 0: return @@ -134,20 +53,22 @@ def f(e): keyboard_name = target[0] keymap_name = target[1] keyboard_safe = keyboard_name.replace('/', '_') + build_log = f"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" + failed_log = f"{QMK_FIRMWARE}/.build/failed.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" # yapf: disable f.write( f"""\ all: {keyboard_safe}_{keymap_name}_binary {keyboard_safe}_{keymap_name}_binary: - @rm -f "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}.{keymap_name}" || true - @echo "Compiling QMK Firmware for target: '{keyboard_name}:{keymap_name}'..." >>"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" + @rm -f "{build_log}" || true + @echo "Compiling QMK Firmware for target: '{keyboard_name}:{keymap_name}'..." >>"{build_log}" +@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/builddefs/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="{keymap_name}" COLOR=true SILENT=false {' '.join(cli.args.env)} \\ - >>"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" 2>&1 \\ - || cp "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" "{QMK_FIRMWARE}/.build/failed.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" - @{{ grep '\[ERRORS\]' "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:{keymap_name}" ; }} \\ - || {{ grep '\[WARNINGS\]' "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" >/dev/null 2>&1 && printf "Build %-64s \e[1;33m[WARNINGS]\e[0m\\n" "{keyboard_name}:{keymap_name}" ; }} \\ + >>"{build_log}" 2>&1 \\ + || cp "{build_log}" "{failed_log}" + @{{ grep '\[ERRORS\]' "{build_log}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:{keymap_name}" ; }} \\ + || {{ grep '\[WARNINGS\]' "{build_log}" >/dev/null 2>&1 && printf "Build %-64s \e[1;33m[WARNINGS]\e[0m\\n" "{keyboard_name}:{keymap_name}" ; }} \\ || printf "Build %-64s \e[1;32m[OK]\e[0m\\n" "{keyboard_name}:{keymap_name}" - @rm -f "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" || true + @rm -f "{build_log}" || true """# noqa ) # yapf: enable @@ -158,10 +79,6 @@ def f(e): f"""\ @rm -rf "{QMK_FIRMWARE}/.build/{keyboard_safe}_{keymap_name}.elf" 2>/dev/null || true @rm -rf "{QMK_FIRMWARE}/.build/{keyboard_safe}_{keymap_name}.map" 2>/dev/null || true - @rm -rf "{QMK_FIRMWARE}/.build/{keyboard_safe}_{keymap_name}.hex" 2>/dev/null || true - @rm -rf "{QMK_FIRMWARE}/.build/{keyboard_safe}_{keymap_name}.bin" 2>/dev/null || true - @rm -rf "{QMK_FIRMWARE}/.build/{keyboard_safe}_{keymap_name}.uf2" 2>/dev/null || true - @rm -rf "{QMK_FIRMWARE}/.build/obj_{keyboard_safe}" || true @rm -rf "{QMK_FIRMWARE}/.build/obj_{keyboard_safe}_{keymap_name}" || true """# noqa ) diff --git a/lib/python/qmk/cli/migrate.py b/lib/python/qmk/cli/migrate.py index 4164f9c8adfa..c1b1ad1ea9da 100644 --- a/lib/python/qmk/cli/migrate.py +++ b/lib/python/qmk/cli/migrate.py @@ -75,7 +75,7 @@ def migrate(cli): # Finally write out updated info.json cli.log.info(f' Updating {target_info}') - target_info.write_text(json.dumps(info_data.to_dict(), cls=InfoJSONEncoder)) + target_info.write_text(json.dumps(info_data.to_dict(), cls=InfoJSONEncoder, sort_keys=True)) cli.log.info(f'{{fg_green}}Migration of keyboard {{fg_cyan}}{cli.args.keyboard}{{fg_green}} complete!{{fg_reset}}') cli.log.info(f"Verify build with {{fg_yellow}}qmk compile -kb {cli.args.keyboard} -km default{{fg_reset}}.") diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index f6951a7115ce..81dab63d1f9e 100644 --- a/lib/python/qmk/cli/new/keyboard.py +++ b/lib/python/qmk/cli/new/keyboard.py @@ -102,7 +102,7 @@ def augment_community_info(src, dest): item["matrix"] = [int(item["y"]), int(item["x"])] # finally write out the updated info.json - dest.write_text(json.dumps(info, cls=InfoJSONEncoder)) + dest.write_text(json.dumps(info, cls=InfoJSONEncoder, sort_keys=True)) def _question(*args, **kwargs): diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index e7823bc46dd2..9b0ac221a4ae 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py @@ -5,7 +5,7 @@ from milc import cli from milc.questions import question -from qmk.path import is_keyboard, keymap +from qmk.path import is_keyboard, keymaps, keymap from qmk.git import git_get_username from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.keyboard import keyboard_completer, keyboard_folder @@ -50,9 +50,9 @@ def new_keymap(cli): return False # generate keymap paths - km_path = keymap(kb_name) - keymap_path_default = km_path / 'default' - keymap_path_new = km_path / user_name + keymaps_dirs = keymaps(kb_name) + keymap_path_default = keymap(kb_name, 'default') + keymap_path_new = keymaps_dirs[0] / user_name if not keymap_path_default.exists(): cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!') diff --git a/lib/python/qmk/cli/via2json.py b/lib/python/qmk/cli/via2json.py index 6edc9dfbe5ed..77823b5d9d78 100755 --- a/lib/python/qmk/cli/via2json.py +++ b/lib/python/qmk/cli/via2json.py @@ -141,5 +141,5 @@ def via2json(cli): # Generate the keymap.json keymap_json = generate_json(cli.args.keymap, cli.args.keyboard, keymap_layout, keymap_data, macro_data) - keymap_lines = [json.dumps(keymap_json, cls=KeymapJSONEncoder)] + keymap_lines = [json.dumps(keymap_json, cls=KeymapJSONEncoder, sort_keys=True)] dump_lines(cli.args.output, keymap_lines, cli.args.quiet) diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 5561a354c5cc..660b2ff72e60 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -9,7 +9,7 @@ from milc import cli import jsonschema -from qmk.constants import KEYBOARD_OUTPUT_PREFIX +from qmk.constants import INTERMEDIATE_OUTPUT_PREFIX from qmk.json_schema import json_load, validate @@ -51,6 +51,9 @@ def create_make_target(target, dry_run=False, parallel=1, **env_vars): for key, value in env_vars.items(): env.append(f'{key}={value}') + if cli.config.general.verbose: + env.append('VERBOSE=true') + return [make_cmd, *(['-n'] if dry_run else []), *get_make_parallel_args(parallel), *env, target] @@ -131,16 +134,13 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, clean=Fa keyboard_filesafe = user_keymap['keyboard'].replace('/', '_') target = f'{keyboard_filesafe}_{user_keymap["keymap"]}' - keyboard_output = Path(f'{KEYBOARD_OUTPUT_PREFIX}{keyboard_filesafe}') - keymap_output = Path(f'{keyboard_output}_{user_keymap["keymap"]}') - keymap_dir = keymap_output / 'src' + intermediate_output = Path(f'{INTERMEDIATE_OUTPUT_PREFIX}{keyboard_filesafe}_{user_keymap["keymap"]}') + keymap_dir = intermediate_output / 'src' keymap_json = keymap_dir / 'keymap.json' if clean: - if keyboard_output.exists(): - shutil.rmtree(keyboard_output) - if keymap_output.exists(): - shutil.rmtree(keymap_output) + if intermediate_output.exists(): + shutil.rmtree(intermediate_output) # begin with making the deepest folder in the tree keymap_dir.mkdir(exist_ok=True, parents=True) @@ -175,21 +175,17 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, clean=Fa if bootloader: make_command.append(bootloader) - for key, value in env_vars.items(): - make_command.append(f'{key}={value}') - make_command.extend([ f'KEYBOARD={user_keymap["keyboard"]}', f'KEYMAP={user_keymap["keymap"]}', f'KEYBOARD_FILESAFE={keyboard_filesafe}', f'TARGET={target}', - f'KEYBOARD_OUTPUT={keyboard_output}', - f'KEYMAP_OUTPUT={keymap_output}', - f'MAIN_KEYMAP_PATH_1={keymap_output}', - f'MAIN_KEYMAP_PATH_2={keymap_output}', - f'MAIN_KEYMAP_PATH_3={keymap_output}', - f'MAIN_KEYMAP_PATH_4={keymap_output}', - f'MAIN_KEYMAP_PATH_5={keymap_output}', + f'INTERMEDIATE_OUTPUT={intermediate_output}', + f'MAIN_KEYMAP_PATH_1={intermediate_output}', + f'MAIN_KEYMAP_PATH_2={intermediate_output}', + f'MAIN_KEYMAP_PATH_3={intermediate_output}', + f'MAIN_KEYMAP_PATH_4={intermediate_output}', + f'MAIN_KEYMAP_PATH_5={intermediate_output}', f'KEYMAP_JSON={keymap_json}', f'KEYMAP_PATH={keymap_dir}', f'VERBOSE={verbose}', @@ -198,6 +194,9 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, clean=Fa 'QMK_BIN="qmk"', ]) + for key, value in env_vars.items(): + make_command.append(f'{key}={value}') + return make_command @@ -220,9 +219,6 @@ def parse_configurator_json(configurator_file): if 'target' in aliases[orig_keyboard]: user_keymap['keyboard'] = aliases[orig_keyboard]['target'] - if 'layouts' in aliases[orig_keyboard] and user_keymap['layout'] in aliases[orig_keyboard]['layouts']: - user_keymap['layout'] = aliases[orig_keyboard]['layouts'][user_keymap['layout']] - return user_keymap diff --git a/lib/python/qmk/constants.py b/lib/python/qmk/constants.py index 8a13029a8a8f..97bd84aa2344 100644 --- a/lib/python/qmk/constants.py +++ b/lib/python/qmk/constants.py @@ -14,7 +14,7 @@ MAX_KEYBOARD_SUBFOLDERS = 5 # Supported processor types -CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95' +CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32H723', 'STM32H733', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95' LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' @@ -36,6 +36,8 @@ "STM32F446": "stm32-dfu", "STM32G431": "stm32-dfu", "STM32G474": "stm32-dfu", + "STM32H723": "stm32-dfu", + "STM32H733": "stm32-dfu", "STM32L412": "stm32-dfu", "STM32L422": "stm32-dfu", "STM32L432": "stm32-dfu", @@ -82,6 +84,7 @@ }, 'apm32-dfu': {("314b", "0106")}, 'gd32v-dfu': {("28e9", "0189")}, + 'wb32-dfu': {("342d", "dfa0")}, 'bootloadhid': {("16c0", "05df")}, 'usbasploader': {("16c0", "05dc")}, 'usbtinyisp': {("1782", "0c9f")}, @@ -123,7 +126,7 @@ # Constants that should match their counterparts in make BUILD_DIR = environ.get('BUILD_DIR', '.build') -KEYBOARD_OUTPUT_PREFIX = f'{BUILD_DIR}/obj_' +INTERMEDIATE_OUTPUT_PREFIX = f'{BUILD_DIR}/obj_' # Headers for generated files GPL2_HEADER_C_LIKE = f'''\ diff --git a/lib/python/qmk/flashers.py b/lib/python/qmk/flashers.py index f83665d9accf..9ecb5e4b9c8f 100644 --- a/lib/python/qmk/flashers.py +++ b/lib/python/qmk/flashers.py @@ -96,7 +96,7 @@ def _find_bootloader(): details = 'halfkay' else: details = 'qmk-hid' - elif bl == 'stm32-dfu' or bl == 'apm32-dfu' or bl == 'gd32v-dfu' or bl == 'kiibohd': + elif bl in {'apm32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: details = (vid, pid) else: details = None @@ -181,9 +181,18 @@ def _flash_dfu_util(details, file): cli.run(['dfu-util', '-a', '0', '-d', f'{details[0]}:{details[1]}', '-s', '0x08000000:leave', '-D', file], capture_output=False) +def _flash_wb32_dfu_updater(file): + if shutil.which('wb32-dfu-updater_cli'): + cmd = 'wb32-dfu-updater_cli' + else: + return True + + cli.run([cmd, '-t', '-s', '0x08000000', '-D', file], capture_output=False) + + def _flash_isp(mcu, programmer, file): programmer = 'usbasp' if programmer == 'usbasploader' else 'usbtiny' - # Check if the provide mcu has an avrdude-specific name, otherwise pass on what the user provided + # Check if the provided mcu has an avrdude-specific name, otherwise pass on what the user provided mcu = AVRDUDE_MCU.get(mcu, mcu) cli.run(['avrdude', '-p', mcu, '-c', programmer, '-U', f'flash:w:{file}:i'], capture_output=False) @@ -211,8 +220,11 @@ def flasher(mcu, file): return (True, "Please make sure 'teensy_loader_cli' or 'hid_bootloader_cli' is available on your system.") else: return (True, "Specifying the MCU with '-m' is necessary for HalfKay/HID bootloaders!") - elif bl == 'stm32-dfu' or bl == 'apm32-dfu' or bl == 'gd32v-dfu' or bl == 'kiibohd': + elif bl in {'apm32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: _flash_dfu_util(details, file) + elif bl == 'wb32-dfu': + if _flash_wb32_dfu_updater(file): + return (True, "Please make sure 'wb32-dfu-updater_cli' is available on your system.") elif bl == 'usbasploader' or bl == 'usbtinyisp': if mcu: _flash_isp(mcu, bl, file) diff --git a/lib/python/qmk/importers.py b/lib/python/qmk/importers.py index 307c66ee3ccd..8c449a719406 100644 --- a/lib/python/qmk/importers.py +++ b/lib/python/qmk/importers.py @@ -5,7 +5,7 @@ from qmk.git import git_get_username from qmk.json_schema import validate -from qmk.path import keyboard, keymap +from qmk.path import keyboard, keymaps from qmk.constants import MCU2BOOTLOADER, LEGACY_KEYCODES from qmk.json_encoders import InfoJSONEncoder, KeymapJSONEncoder from qmk.json_schema import deep_update, json_load @@ -84,14 +84,14 @@ def import_keymap(keymap_data): kb_name = keymap_data['keyboard'] km_name = keymap_data['keymap'] - km_folder = keymap(kb_name) / km_name + km_folder = keymaps(kb_name)[0] / km_name keyboard_keymap = km_folder / 'keymap.json' # This is the deepest folder in the expected tree keyboard_keymap.parent.mkdir(parents=True, exist_ok=True) # Dump out all those lovely files - keyboard_keymap.write_text(json.dumps(keymap_data, cls=KeymapJSONEncoder)) + keyboard_keymap.write_text(json.dumps(keymap_data, cls=KeymapJSONEncoder, sort_keys=True)) return (kb_name, km_name) @@ -139,8 +139,8 @@ def import_keyboard(info_data, keymap_data=None): temp = json_load(keyboard_info) deep_update(temp, info_data) - keyboard_info.write_text(json.dumps(temp, cls=InfoJSONEncoder)) - keyboard_keymap.write_text(json.dumps(keymap_data, cls=KeymapJSONEncoder)) + keyboard_info.write_text(json.dumps(temp, cls=InfoJSONEncoder, sort_keys=True)) + keyboard_keymap.write_text(json.dumps(keymap_data, cls=KeymapJSONEncoder, sort_keys=True)) return kb_name diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 152e6ce7b6d0..9c8521a2a3ee 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -50,18 +50,14 @@ def _valid_community_layout(layout): return (Path('layouts/default') / layout).exists() -def _validate(keyboard, info_data): - """Perform various validation on the provided info.json data - """ - # First validate against the jsonschema - try: - validate(info_data, 'qmk.api.keyboard.v1') +def _get_key_left_position(key): + # Special case for ISO enter + return key['x'] - 0.25 if key.get('h', 1) == 2 and key.get('w', 1) == 1.25 else key['x'] - except jsonschema.ValidationError as e: - json_path = '.'.join([str(p) for p in e.absolute_path]) - cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message) - exit(1) +def _additional_validation(keyboard, info_data): + """Non schema checks + """ layouts = info_data.get('layouts', {}) layout_aliases = info_data.get('layout_aliases', {}) community_layouts = info_data.get('community_layouts', []) @@ -71,6 +67,16 @@ def _validate(keyboard, info_data): if len(layouts) == 0 or all(not layout.get('json_layout', False) for layout in layouts.values()): _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in info.json.') + # Warn if physical positions are offset (at least one key should be at x=0, and at least one key at y=0) + for layout_name, layout_data in layouts.items(): + offset_x = min([_get_key_left_position(k) for k in layout_data['layout']]) + if offset_x > 0: + _log_warning(info_data, f'Layout "{layout_name}" is offset on X axis by {offset_x}') + + offset_y = min([k['y'] for k in layout_data['layout']]) + if offset_y > 0: + _log_warning(info_data, f'Layout "{layout_name}" is offset on Y axis by {offset_y}') + # Providing only LAYOUT_all "because I define my layouts in a 3rd party tool" if len(layouts) == 1 and 'LAYOUT_all' in layouts: _log_warning(info_data, '"LAYOUT_all" should be "LAYOUT" unless additional layouts are provided.') @@ -93,6 +99,27 @@ def _validate(keyboard, info_data): if layout_name not in layouts and layout_name not in layout_aliases: _log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name)) + # keycodes with length > 7 must have short forms for visualisation purposes + for decl in info_data.get('keycodes', []): + if len(decl["key"]) > 7: + if not decl.get("aliases", []): + _log_error(info_data, f'Keycode {decl["key"]} has no short form alias') + + +def _validate(keyboard, info_data): + """Perform various validation on the provided info.json data + """ + # First validate against the jsonschema + try: + validate(info_data, 'qmk.api.keyboard.v1') + + _additional_validation(keyboard, info_data) + + except jsonschema.ValidationError as e: + json_path = '.'.join([str(p) for p in e.absolute_path]) + cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message) + exit(1) + def info_json(keyboard): """Generate the info.json data for a specific keyboard. @@ -679,6 +706,9 @@ def _extract_led_config(info_data, keyboard): except Exception as e: _log_warning(info_data, f'led_config: {file.name}: {e}') + if info_data[feature].get("layout", None) and not info_data[feature].get("led_count", None): + info_data[feature]["led_count"] = len(info_data[feature]["layout"]) + return info_data diff --git a/lib/python/qmk/json_encoders.py b/lib/python/qmk/json_encoders.py index f968b3dbb2d3..1e90f6a28808 100755 --- a/lib/python/qmk/json_encoders.py +++ b/lib/python/qmk/json_encoders.py @@ -27,30 +27,56 @@ def encode_decimal(self, obj): return float(obj) - def encode_list(self, obj): + def encode_dict(self, obj, path): + """Encode a dict-like object. + """ + if obj: + self.indentation_level += 1 + + items = sorted(obj.items(), key=self.sort_dict) if self.sort_keys else obj.items() + output = [self.indent_str + f"{json.dumps(key)}: {self.encode(value, path + [key])}" for key, value in items] + + self.indentation_level -= 1 + + return "{\n" + ",\n".join(output) + "\n" + self.indent_str + "}" + else: + return "{}" + + def encode_dict_single_line(self, obj, path): + """Encode a dict-like object onto a single line. + """ + return "{" + ", ".join(f"{json.dumps(key)}: {self.encode(value, path + [key])}" for key, value in sorted(obj.items(), key=self.sort_layout)) + "}" + + def encode_list(self, obj, path): """Encode a list-like object. """ if self.primitives_only(obj): - return "[" + ", ".join(self.encode(element) for element in obj) + "]" + return "[" + ", ".join(self.encode(value, path + [index]) for index, value in enumerate(obj)) + "]" else: self.indentation_level += 1 - output = [self.indent_str + self.encode(element) for element in obj] + + if path[-1] in ('layout', 'rotary'): + # These are part of a LED layout or encoder config, put them on a single line + output = [self.indent_str + self.encode_dict_single_line(value, path + [index]) for index, value in enumerate(obj)] + else: + output = [self.indent_str + self.encode(value, path + [index]) for index, value in enumerate(obj)] + self.indentation_level -= 1 return "[\n" + ",\n".join(output) + "\n" + self.indent_str + "]" - def encode(self, obj): - """Encode keymap.json objects for QMK. + def encode(self, obj, path=[]): + """Encode JSON objects for QMK. """ if isinstance(obj, Decimal): return self.encode_decimal(obj) elif isinstance(obj, (list, tuple)): - return self.encode_list(obj) + return self.encode_list(obj, path) elif isinstance(obj, dict): - return self.encode_dict(obj) + return self.encode_dict(obj, path) else: return super().encode(obj) @@ -71,30 +97,42 @@ def indent_str(self): class InfoJSONEncoder(QMKJSONEncoder): """Custom encoder to make info.json's a little nicer to work with. """ - def encode_dict(self, obj): - """Encode info.json dictionaries. + def sort_layout(self, item): + """Sorts the hashes in a nice way. """ - if obj: - if set(("x", "y")).issubset(obj.keys()): - # These are part of a layout/led_config, put them on a single line. - return "{ " + ", ".join(f"{self.encode(key)}: {self.encode(element)}" for key, element in sorted(obj.items())) + " }" + key = item[0] - else: - self.indentation_level += 1 - output = [self.indent_str + f"{json.dumps(key)}: {self.encode(value)}" for key, value in sorted(obj.items(), key=self.sort_dict)] - self.indentation_level -= 1 - return "{\n" + ",\n".join(output) + "\n" + self.indent_str + "}" - else: - return "{}" + if key == 'label': + return '00label' + + elif key == 'matrix': + return '01matrix' + + elif key == 'x': + return '02x' + + elif key == 'y': + return '03y' + + elif key == 'w': + return '04w' + + elif key == 'h': + return '05h' + + elif key == 'flags': + return '06flags' + + return key - def sort_dict(self, key): + def sort_dict(self, item): """Forces layout to the back of the sort order. """ - key = key[0] + key = item[0] if self.indentation_level == 1: if key == 'manufacturer': - return '10keyboard_name' + return '10manufacturer' elif key == 'keyboard_name': return '11keyboard_name' @@ -120,21 +158,7 @@ def sort_dict(self, key): class KeymapJSONEncoder(QMKJSONEncoder): """Custom encoder to make keymap.json's a little nicer to work with. """ - def encode_dict(self, obj): - """Encode dictionary objects for keymap.json. - """ - if obj: - self.indentation_level += 1 - output_lines = [f"{self.indent_str}{json.dumps(key)}: {self.encode(value)}" for key, value in sorted(obj.items(), key=self.sort_dict)] - output = ',\n'.join(output_lines) - self.indentation_level -= 1 - - return f"{{\n{output}\n{self.indent_str}}}" - - else: - return "{}" - - def encode_list(self, obj): + def encode_list(self, obj, path): """Encode a list-like object. """ if self.indentation_level == 2: @@ -168,10 +192,10 @@ def encode_list(self, obj): return "[\n" + ",\n".join(output) + "\n" + self.indent_str + "]" - def sort_dict(self, key): + def sort_dict(self, item): """Sorts the hashes in a nice way. """ - key = key[0] + key = item[0] if self.indentation_level == 1: if key == 'version': diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index 0c980faf2b88..235b62640c20 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -182,7 +182,7 @@ def render_layout(layout_data, render_ascii, key_labels=None): if x >= 0.25 and w == 1.25 and h == 2: render_key_isoenter(textpad, x, y, w, h, label, style) - elif w == 2.25 and h == 2: + elif w == 1.5 and h == 2: render_key_baenter(textpad, x, y, w, h, label, style) else: render_key_rect(textpad, x, y, w, h, label, style) @@ -275,7 +275,7 @@ def render_key_baenter(textpad, x, y, w, h, label, style): w = ceil(w * 4) h = ceil(h * 3) - label_len = w - 2 + label_len = w + 1 label_leftover = label_len - len(label) if len(label) > label_len: @@ -292,9 +292,9 @@ def render_key_baenter(textpad, x, y, w, h, label, style): lab_line = array('u', box_chars['v'] + label_middle + box_chars['v']) bot_line = array('u', box_chars['bl'] + label_border_bottom + box_chars['br']) - textpad[y][x + 3:x + w] = top_line - textpad[y + 1][x + 3:x + w] = mid_line - textpad[y + 2][x + 3:x + w] = mid_line - textpad[y + 3][x:x + w] = crn_line - textpad[y + 4][x:x + w] = lab_line - textpad[y + 5][x:x + w] = bot_line + textpad[y][x:x + w] = top_line + textpad[y + 1][x:x + w] = mid_line + textpad[y + 2][x:x + w] = mid_line + textpad[y + 3][x - 3:x + w] = crn_line + textpad[y + 4][x - 3:x + w] = lab_line + textpad[y + 5][x - 3:x + w] = bot_line diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index dddf6449a7bc..11e8d39dadf5 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -25,13 +25,14 @@ * This file was generated by qmk json2c. You may or may not want to * edit it directly. */ +__KEYCODE_OUTPUT_GOES_HERE__ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { __KEYMAP_GOES_HERE__ }; #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) -const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { __ENCODER_MAP_GOES_HERE__ }; #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) @@ -123,6 +124,29 @@ def _generate_macros_function(keymap_json): return macro_txt +def _generate_keycodes_function(keymap_json): + """Generates keymap level keycodes. + """ + lines = [] + lines.append('enum keymap_keycodes {') + + for index, item in enumerate(keymap_json.get('keycodes', [])): + key = item["key"] + if index == 0: + lines.append(f' {key} = QK_USER_0,') + else: + lines.append(f' {key},') + + lines.append('};') + + for item in keymap_json.get('keycodes', []): + key = item["key"] + for alias in item.get("aliases", []): + lines.append(f'#define {alias} {key}') + + return lines + + def template_json(keyboard): """Returns a `keymap.json` template for a keyboard. @@ -317,6 +341,12 @@ def generate_c(keymap_json): hostlang = f'#include "keymap_{keymap_json["host_language"]}.h"\n#include "sendstring_{keymap_json["host_language"]}.h"\n' new_keymap = new_keymap.replace('__INCLUDES__', hostlang) + keycodes = '' + if 'keycodes' in keymap_json and keymap_json['keycodes'] is not None: + keycodes_txt = _generate_keycodes_function(keymap_json) + keycodes = '\n'.join(keycodes_txt) + new_keymap = new_keymap.replace('__KEYCODE_OUTPUT_GOES_HERE__', keycodes) + return new_keymap @@ -349,7 +379,7 @@ def write_json(keyboard, keymap, layout, layers, macros=None): """ keymap_json = generate_json(keyboard, keymap, layout, layers, macros=None) keymap_content = json.dumps(keymap_json) - keymap_file = qmk.path.keymap(keyboard) / keymap / 'keymap.json' + keymap_file = qmk.path.keymaps(keyboard)[0] / keymap / 'keymap.json' return write_file(keymap_file, keymap_content) @@ -376,7 +406,7 @@ def write(keymap_json): A list of macros for this keymap. """ keymap_content = generate_c(keymap_json) - keymap_file = qmk.path.keymap(keymap_json['keyboard']) / keymap_json['keymap'] / 'keymap.c' + keymap_file = qmk.path.keymaps(keymap_json['keyboard'])[0] / keymap_json['keymap'] / 'keymap.c' return write_file(keymap_file, keymap_content) diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py index 02c2e70050c3..ae95abbf2368 100644 --- a/lib/python/qmk/makefile.py +++ b/lib/python/qmk/makefile.py @@ -18,7 +18,7 @@ def parse_rules_mk_file(file, rules_mk=None): file = Path(file) if file.exists(): - rules_mk_lines = file.read_text().split("\n") + rules_mk_lines = file.read_text(encoding='utf-8').split("\n") for line in rules_mk_lines: # Filter out comments diff --git a/lib/python/qmk/painter.py b/lib/python/qmk/painter.py index 7ecdc55404a6..381a9964431c 100644 --- a/lib/python/qmk/painter.py +++ b/lib/python/qmk/painter.py @@ -158,37 +158,45 @@ def convert_requested_format(im, format): ncolors = format["num_colors"] image_format = format["image_format"] + # -- Check if ncolors is valid + # Formats accepting several options + if image_format in ['IMAGE_FORMAT_GRAYSCALE', 'IMAGE_FORMAT_PALETTE']: + valid = [2, 4, 8, 16, 256] + + # Formats expecting a particular number + else: + # Read number from specs dict, instead of hardcoding + for _, fmt in valid_formats.items(): + if fmt["image_format"] == image_format: + # has to be an iterable, to use `in` + valid = [fmt["num_colors"]] + break + + if ncolors not in valid: + raise ValueError(f"Number of colors must be: {', '.join(valid)}.") + # Work out where we're getting the bytes from if image_format == 'IMAGE_FORMAT_GRAYSCALE': - # Ensure we have a valid number of colors for the palette - if ncolors <= 0 or ncolors > 256 or (ncolors & (ncolors - 1) != 0): - raise ValueError("Number of colors must be 2, 4, 16, or 256.") # If mono, convert input to grayscale, then to RGB, then grab the raw bytes corresponding to the intensity of the red channel im = ImageOps.grayscale(im) im = im.convert("RGB") elif image_format == 'IMAGE_FORMAT_PALETTE': - # Ensure we have a valid number of colors for the palette - if ncolors <= 0 or ncolors > 256 or (ncolors & (ncolors - 1) != 0): - raise ValueError("Number of colors must be 2, 4, 16, or 256.") # If color, convert input to RGB, palettize based on the supplied number of colors, then get the raw palette bytes im = im.convert("RGB") im = im.convert("P", palette=Image.ADAPTIVE, colors=ncolors) - elif image_format == 'IMAGE_FORMAT_RGB565': - # Ensure we have a valid number of colors for the palette - if ncolors != 65536: - raise ValueError("Number of colors must be 65536.") - # If color, convert input to RGB - im = im.convert("RGB") - elif image_format == 'IMAGE_FORMAT_RGB888': - # Ensure we have a valid number of colors for the palette - if ncolors != 1677216: - raise ValueError("Number of colors must be 16777216.") - # If color, convert input to RGB + elif image_format in ['IMAGE_FORMAT_RGB565', 'IMAGE_FORMAT_RGB888']: + # Convert input to RGB im = im.convert("RGB") return im +def rgb_to565(r, g, b): + msb = ((r >> 3 & 0x1F) << 3) + (g >> 5 & 0x07) + lsb = ((g >> 2 & 0x07) << 5) + (b >> 3 & 0x1F) + return [msb, lsb] + + def convert_image_bytes(im, format): """Convert the supplied image to the equivalent bytes required by the QMK firmware. """ @@ -246,41 +254,25 @@ def convert_image_bytes(im, format): if image_format == 'IMAGE_FORMAT_RGB565': # Take the red, green, and blue channels - image_bytes_red = im.tobytes("raw", "R") - image_bytes_green = im.tobytes("raw", "G") - image_bytes_blue = im.tobytes("raw", "B") - image_pixels_len = len(image_bytes_red) + red = im.tobytes("raw", "R") + green = im.tobytes("raw", "G") + blue = im.tobytes("raw", "B") # No palette palette = None - bytearray = [] - for x in range(image_pixels_len): - # 5 bits of red, 3 MSb of green - byte = ((image_bytes_red[x] >> 3 & 0x1F) << 3) + (image_bytes_green[x] >> 5 & 0x07) - bytearray.append(byte) - # 3 LSb of green, 5 bits of blue - byte = ((image_bytes_green[x] >> 2 & 0x07) << 5) + (image_bytes_blue[x] >> 3 & 0x1F) - bytearray.append(byte) + bytearray = [byte for r, g, b in zip(red, green, blue) for byte in rgb_to565(r, g, b)] if image_format == 'IMAGE_FORMAT_RGB888': # Take the red, green, and blue channels - image_bytes_red = im.tobytes("raw", "R") - image_bytes_green = im.tobytes("raw", "G") - image_bytes_blue = im.tobytes("raw", "B") - image_pixels_len = len(image_bytes_red) + red = im.tobytes("raw", "R") + green = im.tobytes("raw", "G") + blue = im.tobytes("raw", "B") # No palette palette = None - bytearray = [] - for x in range(image_pixels_len): - byte = image_bytes_red[x] - bytearray.append(byte) - byte = image_bytes_green[x] - bytearray.append(byte) - byte = image_bytes_blue[x] - bytearray.append(byte) + bytearray = [byte for r, g, b in zip(red, green, blue) for byte in (r, g, b)] if len(bytearray) != expected_byte_count: raise Exception(f"Wrong byte count, was {len(bytearray)}, expected {expected_byte_count}") diff --git a/lib/python/qmk/painter_qgf.py b/lib/python/qmk/painter_qgf.py index 71ce1f5a02ce..2b8edfb04db3 100644 --- a/lib/python/qmk/painter_qgf.py +++ b/lib/python/qmk/painter_qgf.py @@ -372,8 +372,8 @@ def rgb888_to_qmk_hsv888(e): delta_descriptor = QGFFrameDeltaDescriptorV1() delta_descriptor.left = location[0] delta_descriptor.top = location[1] - delta_descriptor.right = location[0] + size[0] - delta_descriptor.bottom = location[1] + size[1] + delta_descriptor.right = location[0] + size[0] - 1 + delta_descriptor.bottom = location[1] + size[1] - 1 # Write the delta frame to the output vprint(f'{f"Frame {idx:3d} delta":26s} {fp.tell():5d}d / {fp.tell():04X}h') diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 556d0eefc858..9d248451b86f 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -36,8 +36,8 @@ def keyboard(keyboard_name): return Path('keyboards') / keyboard_name -def keymap(keyboard_name): - """Locate the correct directory for storing a keymap. +def keymaps(keyboard_name): + """Returns all of the `keymaps/` directories for a given keyboard. Args: @@ -45,17 +45,36 @@ def keymap(keyboard_name): The name of the keyboard. Example: clueboard/66/rev3 """ keyboard_folder = keyboard(keyboard_name) + found_dirs = [] for _ in range(MAX_KEYBOARD_SUBFOLDERS): if (keyboard_folder / 'keymaps').exists(): - return (keyboard_folder / 'keymaps').resolve() + found_dirs.append((keyboard_folder / 'keymaps').resolve()) keyboard_folder = keyboard_folder.parent + if len(found_dirs) > 0: + return found_dirs + logging.error('Could not find the keymaps directory!') raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard_name) +def keymap(keyboard_name, keymap_name): + """Locate the directory of a given keymap. + + Args: + + keyboard_name + The name of the keyboard. Example: clueboard/66/rev3 + keymap_name + The name of the keymap. Example: default + """ + for keymap_dir in keymaps(keyboard_name): + if (keymap_dir / keymap_name).exists(): + return (keymap_dir / keymap_name).resolve() + + def normpath(path): """Returns a `pathlib.Path()` object for a given path. diff --git a/lib/python/qmk/search.py b/lib/python/qmk/search.py new file mode 100644 index 000000000000..2bbbc7806fc6 --- /dev/null +++ b/lib/python/qmk/search.py @@ -0,0 +1,125 @@ +"""Functions for searching through QMK keyboards and keymaps. +""" +import contextlib +import fnmatch +import logging +import multiprocessing +import re +from dotty_dict import dotty +from milc import cli + +from qmk.info import keymap_json +import qmk.keyboard +import qmk.keymap + + +def _set_log_level(level): + cli.acquire_lock() + old = cli.log_level + cli.log_level = level + cli.log.setLevel(level) + logging.root.setLevel(level) + cli.release_lock() + return old + + +@contextlib.contextmanager +def ignore_logging(): + old = _set_log_level(logging.CRITICAL) + yield + _set_log_level(old) + + +def _all_keymaps(keyboard): + with ignore_logging(): + return (keyboard, qmk.keymap.list_keymaps(keyboard)) + + +def _keymap_exists(keyboard, keymap): + with ignore_logging(): + return keyboard if qmk.keymap.locate_keymap(keyboard, keymap) is not None else None + + +def _load_keymap_info(keyboard, keymap): + with ignore_logging(): + return (keyboard, keymap, keymap_json(keyboard, keymap)) + + +def search_keymap_targets(keymap='default', filters=[], print_vals=[]): + targets = [] + + with multiprocessing.Pool() as pool: + cli.log.info(f'Retrieving list of keyboards with keymap "{keymap}"...') + target_list = [] + if keymap == 'all': + kb_to_kms = pool.map(_all_keymaps, qmk.keyboard.list_keyboards()) + for targets in kb_to_kms: + keyboard = targets[0] + keymaps = targets[1] + target_list.extend([(keyboard, keymap) for keymap in keymaps]) + else: + target_list = [(kb, keymap) for kb in filter(lambda kb: kb is not None, pool.starmap(_keymap_exists, [(kb, keymap) for kb in qmk.keyboard.list_keyboards()]))] + + if len(filters) == 0: + targets = [(kb, km, {}) for kb, km in 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 pool.starmap(_load_keymap_info, target_list)] + + function_re = re.compile(r'^(?P[a-zA-Z]+)\((?P[a-zA-Z0-9_\.]+)(,\s*(?P[^#]+))?\)$') + equals_re = re.compile(r'^(?P[a-zA-Z0-9_\.]+)\s*=\s*(?P[^#]+)$') + + for filter_expr in filters: + function_match = function_re.match(filter_expr) + equals_match = equals_re.match(filter_expr) + + if function_match is not None: + func_name = function_match.group('function').lower() + key = function_match.group('key') + value = function_match.group('value') + + if value is not None: + if func_name == 'length': + valid_keymaps = filter(lambda e, key=key, value=value: key in e[2] and len(e[2].get(key)) == int(value), valid_keymaps) + elif func_name == 'contains': + valid_keymaps = filter(lambda e, key=key, value=value: key in e[2] and value in e[2].get(key), valid_keymaps) + else: + cli.log.warning(f'Unrecognized filter expression: {function_match.group(0)}') + continue + + cli.log.info(f'Filtering on condition: {{fg_green}}{func_name}{{fg_reset}}({{fg_cyan}}{key}{{fg_reset}}, {{fg_cyan}}{value}{{fg_reset}})...') + else: + if func_name == 'exists': + valid_keymaps = filter(lambda e, key=key: key in e[2], valid_keymaps) + elif func_name == 'absent': + valid_keymaps = filter(lambda e, key=key: key not in e[2], valid_keymaps) + else: + cli.log.warning(f'Unrecognized filter expression: {function_match.group(0)}') + continue + + cli.log.info(f'Filtering on condition: {{fg_green}}{func_name}{{fg_reset}}({{fg_cyan}}{key}{{fg_reset}})...') + + elif equals_match is not None: + key = equals_match.group('key') + value = equals_match.group('value') + cli.log.info(f'Filtering on condition: {{fg_cyan}}{key}{{fg_reset}} == {{fg_cyan}}{value}{{fg_reset}}...') + + def _make_filter(k, v): + expr = fnmatch.translate(v) + rule = re.compile(f'^{expr}$', re.IGNORECASE) + + def f(e): + lhs = e[2].get(k) + lhs = str(False if lhs is None else lhs) + return rule.search(lhs) is not None + + return f + + valid_keymaps = filter(_make_filter(key, value), valid_keymaps) + else: + cli.log.warning(f'Unrecognized filter expression: {filter_expr}') + continue + + targets = [(e[0], e[1], [(p, e[2].get(p)) for p in print_vals]) for e in valid_keymaps] + + return targets diff --git a/lib/python/qmk/tests/minimal_info.json b/lib/python/qmk/tests/minimal_info.json index 3aae4722bfec..7f5ec1f9830c 100644 --- a/lib/python/qmk/tests/minimal_info.json +++ b/lib/python/qmk/tests/minimal_info.json @@ -4,7 +4,7 @@ "layouts": { "LAYOUT": { "layout": [ - { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 } + {"label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0} ] } } diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 85a02ebf113c..a2c923b5f6f8 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -144,7 +144,7 @@ def test_list_keymaps_no_keyboard_found(): def test_json2c(): result = check_subcommand('json2c', 'keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json') check_returncode(result) - assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n' + assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n\n' def test_json2c_macros(): @@ -158,7 +158,7 @@ def test_json2c_macros(): def test_json2c_stdin(): result = check_subcommand_stdin('keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json', 'json2c', '-') check_returncode(result) - assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n' + assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n\n' def test_json2c_wrong_json(): @@ -168,7 +168,7 @@ def test_json2c_wrong_json(): def test_json2c_no_json(): - result = check_subcommand('json2c', 'keyboards/handwired/pytest/pytest.h') + result = check_subcommand('json2c', 'keyboards/handwired/pytest/basic/keymaps/default/keymap.c') check_returncode(result, [1]) assert 'Invalid JSON encountered' in result.stdout @@ -188,7 +188,11 @@ def test_info_keyboard_render(): assert 'Keyboard Name: pytest' in result.stdout assert 'Processor: atmega32u4' in result.stdout assert 'Layouts:' in result.stdout - assert 'k0' in result.stdout + + if is_windows: + assert '| |' in result.stdout + else: + assert '│ │' in result.stdout def test_info_keymap_render(): @@ -291,7 +295,7 @@ def test_generate_version_h(): def test_format_json_keyboard(): result = check_subcommand('format-json', '--format', 'keyboard', 'lib/python/qmk/tests/minimal_info.json') check_returncode(result) - assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n' + assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n {"label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0}\n ]\n }\n }\n}\n' def test_format_json_keymap(): @@ -303,7 +307,7 @@ def test_format_json_keymap(): def test_format_json_keyboard_auto(): result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_info.json') check_returncode(result) - assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n' + assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n {"label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0}\n ]\n }\n }\n}\n' def test_format_json_keymap_auto(): diff --git a/lib/python/qmk/tests/test_qmk_path.py b/lib/python/qmk/tests/test_qmk_path.py index 4b5132f13d32..cc068e39dad8 100644 --- a/lib/python/qmk/tests/test_qmk_path.py +++ b/lib/python/qmk/tests/test_qmk_path.py @@ -5,8 +5,8 @@ def test_keymap_pytest_basic(): - path = qmk.path.keymap('handwired/pytest/basic') - assert path.samefile('keyboards/handwired/pytest/basic/keymaps') + path = qmk.path.keymap('handwired/pytest/basic', 'default') + assert path.samefile('keyboards/handwired/pytest/basic/keymaps/default') def test_normpath(): diff --git a/platforms/arm_atsam/eeprom_samd.c b/platforms/arm_atsam/eeprom_samd.c index 1c1e031e5da3..9c42041f2da4 100644 --- a/platforms/arm_atsam/eeprom_samd.c +++ b/platforms/arm_atsam/eeprom_samd.c @@ -15,15 +15,12 @@ */ #include "eeprom.h" #include "debug.h" +#include "util.h" #include "samd51j18a.h" #include "core_cm4.h" #include "component/nvmctrl.h" #include "eeprom_samd.h" -#ifndef MAX -# define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) -#endif - #ifndef BUSY_RETRIES # define BUSY_RETRIES 10000 #endif diff --git a/platforms/avr/_wait.h b/platforms/avr/_wait.h index c1a598a428a8..39cbf618d213 100644 --- a/platforms/avr/_wait.h +++ b/platforms/avr/_wait.h @@ -15,7 +15,11 @@ */ #pragma once +// Need to disable GCC's "maybe-uninitialized" warning for this file, as it causes issues when running `KEEP_INTERMEDIATES=yes`. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #include +#pragma GCC diagnostic pop // http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf // page 22: Table 4-2. Arithmetic and Logic Instructions diff --git a/platforms/avr/drivers/audio_pwm_hardware.c b/platforms/avr/drivers/audio_pwm_hardware.c index 2fc448ea5808..6799cf2fddef 100644 --- a/platforms/avr/drivers/audio_pwm_hardware.c +++ b/platforms/avr/drivers/audio_pwm_hardware.c @@ -15,13 +15,9 @@ * along with this program. If not, see . */ -#if defined(__AVR__) -# include -# include -# include -#endif - #include "audio.h" +#include "gpio.h" +#include extern bool playing_note; extern bool playing_melody; diff --git a/quantum/backlight/backlight_avr.c b/platforms/avr/drivers/backlight_pwm.c similarity index 63% rename from quantum/backlight/backlight_avr.c rename to platforms/avr/drivers/backlight_pwm.c index 474e0a86f5e0..74d25753a4e6 100644 --- a/quantum/backlight/backlight_avr.c +++ b/platforms/avr/drivers/backlight_pwm.c @@ -1,23 +1,15 @@ -#include "quantum.h" #include "backlight.h" -#include "backlight_driver_common.h" -#include "debug.h" +#include "gpio.h" +#include "progmem.h" +#include +#include // Maximum duty cycle limit #ifndef BACKLIGHT_LIMIT_VAL # define BACKLIGHT_LIMIT_VAL 255 #endif -// This logic is a bit complex, we support 3 setups: -// -// 1. Hardware PWM when backlight is wired to a PWM pin. -// Depending on this pin, we use a different output compare unit. -// 2. Software PWM with hardware timers, but the used timer -// depends on the Audio setup (Audio wins over Backlight). -// 3. Full software PWM, driven by the matrix scan, if both timers are used by Audio. - #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == B5 || BACKLIGHT_PIN == B6 || BACKLIGHT_PIN == B7) -# define HARDWARE_PWM # define ICRx ICR1 # define TCCRxA TCCR1A # define TCCRxB TCCR1B @@ -39,7 +31,6 @@ # define OCRxx OCR1C # endif #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) && (BACKLIGHT_PIN == C4 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) -# define HARDWARE_PWM # define ICRx ICR3 # define TCCRxA TCCR3A # define TCCRxB TCCR3B @@ -69,7 +60,6 @@ # define OCRxx OCR3A # endif #elif (defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)) && (BACKLIGHT_PIN == B7 || BACKLIGHT_PIN == C5 || BACKLIGHT_PIN == C6) -# define HARDWARE_PWM # define ICRx ICR1 # define TCCRxA TCCR1A # define TCCRxB TCCR1B @@ -91,7 +81,6 @@ # define OCRxx OCR1A # endif #elif defined(__AVR_ATmega32A__) && (BACKLIGHT_PIN == D4 || BACKLIGHT_PIN == D5) -# define HARDWARE_PWM # define ICRx ICR1 # define TCCRxA TCCR1A # define TCCRxB TCCR1B @@ -109,7 +98,6 @@ # define OCRxx OCR1A # endif #elif (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)) && (BACKLIGHT_PIN == B1 || BACKLIGHT_PIN == B2) -# define HARDWARE_PWM # define ICRx ICR1 # define TCCRxA TCCR1A # define TCCRxB TCCR1B @@ -126,112 +114,34 @@ # define COMxx1 COM1B1 # define OCRxx OCR1B # endif -#elif (AUDIO_PIN != B5) && (AUDIO_PIN != B6) && (AUDIO_PIN != B7) && (AUDIO_PIN_ALT != B5) && (AUDIO_PIN_ALT != B6) && (AUDIO_PIN_ALT != B7) -// Timer 1 is not in use by Audio feature, Backlight can use it -# pragma message "Using hardware timer 1 with software PWM" -# define HARDWARE_PWM -# define BACKLIGHT_PWM_TIMER -# define ICRx ICR1 -# define TCCRxA TCCR1A -# define TCCRxB TCCR1B -# define TIMERx_COMPA_vect TIMER1_COMPA_vect -# define TIMERx_OVF_vect TIMER1_OVF_vect -# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register -# define TIMSKx TIMSK -# else -# define TIMSKx TIMSK1 -# endif -# define TOIEx TOIE1 +#endif -# define OCIExA OCIE1A -# define OCRxx OCR1A -#elif (AUDIO_PIN != C4) && (AUDIO_PIN != C5) && (AUDIO_PIN != C6) -# pragma message "Using hardware timer 3 with software PWM" -// Timer 3 is not in use by Audio feature, Backlight can use it -# define HARDWARE_PWM -# define BACKLIGHT_PWM_TIMER -# define ICRx ICR1 -# define TCCRxA TCCR3A -# define TCCRxB TCCR3B -# define TIMERx_COMPA_vect TIMER3_COMPA_vect -# define TIMERx_OVF_vect TIMER3_OVF_vect -# define TIMSKx TIMSK3 -# define TOIEx TOIE3 +#ifndef BACKLIGHT_RESOLUTION +# define BACKLIGHT_RESOLUTION 0xFFFFU +#endif -# define OCIExA OCIE3A -# define OCRxx OCR3A -#elif defined(BACKLIGHT_CUSTOM_DRIVER) -error("Please set 'BACKLIGHT_DRIVER = custom' within rules.mk") -#else -error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk") +#if (BACKLIGHT_RESOLUTION > 0xFFFF || BACKLIGHT_RESOLUTION < 0x00FF) +# error "Backlight resolution must be between 0x00FF and 0xFFFF" #endif -#ifndef BACKLIGHT_PWM_TIMER // pwm through software +#define BREATHING_SCALE_FACTOR F_CPU / BACKLIGHT_RESOLUTION / 120 static inline void enable_pwm(void) { -# if BACKLIGHT_ON_STATE == 1 +#if BACKLIGHT_ON_STATE == 1 TCCRxA |= _BV(COMxx1); -# else +#else TCCRxA |= _BV(COMxx1) | _BV(COMxx0); -# endif +#endif } static inline void disable_pwm(void) { -# if BACKLIGHT_ON_STATE == 1 +#if BACKLIGHT_ON_STATE == 1 TCCRxA &= ~(_BV(COMxx1)); -# else +#else TCCRxA &= ~(_BV(COMxx1) | _BV(COMxx0)); -# endif -} - #endif - -#ifdef BACKLIGHT_PWM_TIMER - -// The idea of software PWM assisted by hardware timers is the following -// we use the hardware timer in fast PWM mode like for hardware PWM, but -// instead of letting the Output Match Comparator control the led pin -// (which is not possible since the backlight is not wired to PWM pins on the -// CPU), we do the LED on/off by oursleves. -// The timer is setup to count up to 0xFFFF, and we set the Output Compare -// register to the current 16bits backlight level (after CIE correction). -// This means the CPU will trigger a compare match interrupt when the counter -// reaches the backlight level, where we turn off the LEDs, -// but also an overflow interrupt when the counter rolls back to 0, -// in which we're going to turn on the LEDs. -// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz, -// or F_CPU/BACKLIGHT_CUSTOM_RESOLUTION if used. - -// Triggered when the counter reaches the OCRx value -ISR(TIMERx_COMPA_vect) { - backlight_pins_off(); } -// Triggered when the counter reaches the TOP value -// this one triggers at F_CPU/ICRx = 16MHz/65536 =~ 244 Hz -ISR(TIMERx_OVF_vect) { -# ifdef BACKLIGHT_BREATHING - if (is_breathing()) { - breathing_task(); - } -# endif - // for very small values of OCRxx (or backlight level) - // we can't guarantee this whole code won't execute - // at the same time as the compare match interrupt - // which means that we might turn on the leds while - // trying to turn them off, leading to flickering - // artifacts (especially while breathing, because breathing_task - // takes many computation cycles). - // so better not turn them on while the counter TOP is very low. - if (OCRxx > ICRx / 250 + 5) { - backlight_pins_on(); - } -} - -#endif - -#define TIMER_TOP 0xFFFFU - // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max @@ -264,26 +174,11 @@ void backlight_set(uint8_t level) { if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; if (level == 0) { -#ifdef BACKLIGHT_PWM_TIMER - if (OCRxx) { - TIMSKx &= ~(_BV(OCIExA)); - TIMSKx &= ~(_BV(TOIEx)); - } -#else // Turn off PWM control on backlight pin disable_pwm(); -#endif - backlight_pins_off(); } else { -#ifdef BACKLIGHT_PWM_TIMER - if (!OCRxx) { - TIMSKx |= _BV(OCIExA); - TIMSKx |= _BV(TOIEx); - } -#else // Turn on PWM control of backlight pin enable_pwm(); -#endif } // Set the brightness set_pwm(cie_lightness(rescale_limit_val(ICRx * (uint32_t)level / BACKLIGHT_LEVELS))); @@ -292,7 +187,6 @@ void backlight_set(uint8_t level) { void backlight_task(void) {} #ifdef BACKLIGHT_BREATHING - # define BREATHING_NO_HALT 0 # define BREATHING_HALT_OFF 1 # define BREATHING_HALT_ON 2 @@ -303,39 +197,20 @@ static uint16_t breathing_counter = 0; static uint8_t breath_scale_counter = 1; /* Run the breathing loop at ~120Hz*/ -const uint8_t breathing_ISR_frequency = 120; -static uint16_t breathing_freq_scale_factor = 2; - -# ifdef BACKLIGHT_PWM_TIMER -static bool breathing = false; - -bool is_breathing(void) { - return breathing; -} - -# define breathing_interrupt_enable() \ - do { \ - breathing = true; \ - } while (0) -# define breathing_interrupt_disable() \ - do { \ - breathing = false; \ - } while (0) -# else +const uint8_t breathing_ISR_frequency = 120; bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); } -# define breathing_interrupt_enable() \ - do { \ - TIMSKx |= _BV(TOIEx); \ - } while (0) -# define breathing_interrupt_disable() \ - do { \ - TIMSKx &= ~_BV(TOIEx); \ - } while (0) -# endif +# define breathing_interrupt_enable() \ + do { \ + TIMSKx |= _BV(TOIEx); \ + } while (0) +# define breathing_interrupt_disable() \ + do { \ + TIMSKx &= ~_BV(TOIEx); \ + } while (0) # define breathing_min() \ do { \ @@ -384,20 +259,14 @@ static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } -# ifdef BACKLIGHT_PWM_TIMER -void breathing_task(void) -# else /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run * about 244 times per second. * * The following ISR runs at F_CPU/ISRx. With a 16MHz clock and default pwm resolution, that means 244Hz */ -ISR(TIMERx_OVF_vect) -# endif -{ - +ISR(TIMERx_OVF_vect) { // Only run this ISR at ~120 Hz - if (breath_scale_counter++ == breathing_freq_scale_factor) { + if (breath_scale_counter++ == BREATHING_SCALE_FACTOR) { breath_scale_counter = 1; } else { return; @@ -422,19 +291,17 @@ ISR(TIMERx_OVF_vect) #endif // BACKLIGHT_BREATHING void backlight_init_ports(void) { - // Setup backlight pin as output and output to on state. - backlight_pins_init(); + setPinOutput(BACKLIGHT_PIN); +#if BACKLIGHT_ON_STATE == 1 + writePinLow(BACKLIGHT_PIN); +#else + writePinHigh(BACKLIGHT_PIN); +#endif // I could write a wall of text here to explain... but TL;DW // Go read the ATmega32u4 datasheet. // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on -#ifdef BACKLIGHT_PWM_TIMER - // TimerX setup, Fast PWM mode count to TOP set in ICRx - TCCRxA = _BV(WGM11); // = 0b00000010; - // clock select clk/1 - TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; -#else // hardware PWM // Pin PB7 = OCR1C (Timer 1, Channel C) // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 // (i.e. start high, go low when counter matches.) @@ -448,23 +315,10 @@ void backlight_init_ports(void) { */ TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; -#endif - -#ifdef BACKLIGHT_CUSTOM_RESOLUTION -# if (BACKLIGHT_CUSTOM_RESOLUTION > 0xFFFF || BACKLIGHT_CUSTOM_RESOLUTION < 1) -# error "This out of range of the timer capabilities" -# elif (BACKLIGHT_CUSTOM_RESOLUTION < 0xFF) -# warning "Resolution lower than 0xFF isn't recommended" -# endif -# ifdef BACKLIGHT_BREATHING - breathing_freq_scale_factor = F_CPU / BACKLIGHT_CUSTOM_RESOLUTION / 120; -# endif - ICRx = BACKLIGHT_CUSTOM_RESOLUTION; -#else - ICRx = TIMER_TOP; -#endif + ICRx = BACKLIGHT_RESOLUTION; backlight_init(); + #ifdef BACKLIGHT_BREATHING if (is_backlight_breathing()) { breathing_enable(); diff --git a/platforms/avr/drivers/backlight_timer.c b/platforms/avr/drivers/backlight_timer.c new file mode 100644 index 000000000000..e1f4286557f4 --- /dev/null +++ b/platforms/avr/drivers/backlight_timer.c @@ -0,0 +1,267 @@ +#include "backlight.h" +#include "backlight_driver_common.h" +#include "progmem.h" +#include +#include + +// Maximum duty cycle limit +#ifndef BACKLIGHT_LIMIT_VAL +# define BACKLIGHT_LIMIT_VAL 255 +#endif + +#ifndef BACKLIGHT_PWM_TIMER +# define BACKLIGHT_PWM_TIMER 1 +#endif + +#if BACKLIGHT_PWM_TIMER == 1 +# define ICRx ICR1 +# define TCCRxA TCCR1A +# define TCCRxB TCCR1B +# define TIMERx_COMPA_vect TIMER1_COMPA_vect +# define TIMERx_OVF_vect TIMER1_OVF_vect +# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register +# define TIMSKx TIMSK +# else +# define TIMSKx TIMSK1 +# endif +# define TOIEx TOIE1 + +# define OCIExA OCIE1A +# define OCRxx OCR1A +#elif BACKLIGHT_PWM_TIMER == 3 +# define ICRx ICR1 +# define TCCRxA TCCR3A +# define TCCRxB TCCR3B +# define TIMERx_COMPA_vect TIMER3_COMPA_vect +# define TIMERx_OVF_vect TIMER3_OVF_vect +# define TIMSKx TIMSK3 +# define TOIEx TOIE3 + +# define OCIExA OCIE3A +# define OCRxx OCR3A +#else +# error Invalid backlight PWM timer! +#endif + +#ifndef BACKLIGHT_RESOLUTION +# define BACKLIGHT_RESOLUTION 0xFFFFU +#endif + +#if (BACKLIGHT_RESOLUTION > 0xFFFF || BACKLIGHT_RESOLUTION < 0x00FF) +# error "Backlight resolution must be between 0x00FF and 0xFFFF" +#endif + +#define BREATHING_SCALE_FACTOR F_CPU / BACKLIGHT_RESOLUTION / 120 + +// The idea of software PWM assisted by hardware timers is the following +// we use the hardware timer in fast PWM mode like for hardware PWM, but +// instead of letting the Output Match Comparator control the led pin +// (which is not possible since the backlight is not wired to PWM pins on the +// CPU), we do the LED on/off by oursleves. +// The timer is setup to count up to 0xFFFF, and we set the Output Compare +// register to the current 16bits backlight level (after CIE correction). +// This means the CPU will trigger a compare match interrupt when the counter +// reaches the backlight level, where we turn off the LEDs, +// but also an overflow interrupt when the counter rolls back to 0, +// in which we're going to turn on the LEDs. +// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz, +// or F_CPU/BACKLIGHT_RESOLUTION if used. + +// Triggered when the counter reaches the OCRx value +ISR(TIMERx_COMPA_vect) { + backlight_pins_off(); +} + +// Triggered when the counter reaches the TOP value +// this one triggers at F_CPU/ICRx = 16MHz/65536 =~ 244 Hz +ISR(TIMERx_OVF_vect) { +#ifdef BACKLIGHT_BREATHING + if (is_breathing()) { + breathing_task(); + } +#endif + // for very small values of OCRxx (or backlight level) + // we can't guarantee this whole code won't execute + // at the same time as the compare match interrupt + // which means that we might turn on the leds while + // trying to turn them off, leading to flickering + // artifacts (especially while breathing, because breathing_task + // takes many computation cycles). + // so better not turn them on while the counter TOP is very low. + if (OCRxx > ICRx / 250 + 5) { + backlight_pins_on(); + } +} + +// See http://jared.geek.nz/2013/feb/linear-led-pwm +static uint16_t cie_lightness(uint16_t v) { + if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max + { + return v / 9; // Same as dividing by 900% + } else { + // In the next two lines values are bit-shifted. This is to avoid loosing decimals in integer math. + uint32_t y = (((uint32_t)v + (uint32_t)ICRx / 6) << 5) / ((uint32_t)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) + uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing) + + if (out > ICRx) // Avoid overflows + { + out = ICRx; + } + return (uint16_t)out; + } +} + +// rescale the supplied backlight value to be in terms of the value limit // range for val is [0..ICRx]. PWM pin is high while the timer count is below val. +static uint32_t rescale_limit_val(uint32_t val) { + return (val * (BACKLIGHT_LIMIT_VAL + 1)) / 256; +} + +// range for val is [0..ICRx]. PWM pin is high while the timer count is below val. +static inline void set_pwm(uint16_t val) { + OCRxx = val; +} + +void backlight_set(uint8_t level) { + if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; + + if (level == 0) { + if (OCRxx) { + TIMSKx &= ~(_BV(OCIExA)); + TIMSKx &= ~(_BV(TOIEx)); + } + backlight_pins_off(); + } else { + if (!OCRxx) { + TIMSKx |= _BV(OCIExA); + TIMSKx |= _BV(TOIEx); + } + } + // Set the brightness + set_pwm(cie_lightness(rescale_limit_val(ICRx * (uint32_t)level / BACKLIGHT_LEVELS))); +} + +void backlight_task(void) {} + +#ifdef BACKLIGHT_BREATHING +# define BREATHING_NO_HALT 0 +# define BREATHING_HALT_OFF 1 +# define BREATHING_HALT_ON 2 +# define BREATHING_STEPS 128 + +static uint8_t breathing_halt = BREATHING_NO_HALT; +static uint16_t breathing_counter = 0; + +static uint8_t breath_scale_counter = 1; +/* Run the breathing loop at ~120Hz*/ +const uint8_t breathing_ISR_frequency = 120; + +static bool breathing = false; + +bool is_breathing(void) { + return breathing; +} + +# define breathing_interrupt_enable() \ + do { \ + breathing = true; \ + } while (0) +# define breathing_interrupt_disable() \ + do { \ + breathing = false; \ + } while (0) + +# define breathing_min() \ + do { \ + breathing_counter = 0; \ + } while (0) +# define breathing_max() \ + do { \ + breathing_counter = get_breathing_period() * breathing_ISR_frequency / 2; \ + } while (0) + +void breathing_enable(void) { + breathing_counter = 0; + breathing_halt = BREATHING_NO_HALT; + breathing_interrupt_enable(); +} + +void breathing_pulse(void) { + if (get_backlight_level() == 0) + breathing_min(); + else + breathing_max(); + breathing_halt = BREATHING_HALT_ON; + breathing_interrupt_enable(); +} + +void breathing_disable(void) { + breathing_interrupt_disable(); + // Restore backlight level + backlight_set(get_backlight_level()); +} + +void breathing_self_disable(void) { + if (get_backlight_level() == 0) + breathing_halt = BREATHING_HALT_OFF; + else + breathing_halt = BREATHING_HALT_ON; +} + +/* To generate breathing curve in python: + * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] + */ +static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +// Use this before the cie_lightness function. +static inline uint16_t scale_backlight(uint16_t v) { + return v / BACKLIGHT_LEVELS * get_backlight_level(); +} + +void breathing_task(void) { + // Only run this ISR at ~120 Hz + if (breath_scale_counter++ == BREATHING_SCALE_FACTOR) { + breath_scale_counter = 1; + } else { + return; + } + uint16_t interval = (uint16_t)get_breathing_period() * breathing_ISR_frequency / BREATHING_STEPS; + // resetting after one period to prevent ugly reset at overflow. + breathing_counter = (breathing_counter + 1) % (get_breathing_period() * breathing_ISR_frequency); + uint8_t index = breathing_counter / interval; + // limit index to max step value + if (index >= BREATHING_STEPS) { + index = BREATHING_STEPS - 1; + } + + if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) { + breathing_interrupt_disable(); + } + + // Set PWM to a brightnessvalue scaled to the configured resolution + set_pwm(cie_lightness(rescale_limit_val(scale_backlight((uint32_t)pgm_read_byte(&breathing_table[index]) * ICRx / 255)))); +} + +#endif // BACKLIGHT_BREATHING + +void backlight_init_ports(void) { + // Setup backlight pin as output and output to on state. + backlight_pins_init(); + + // I could write a wall of text here to explain... but TL;DW + // Go read the ATmega32u4 datasheet. + // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on + + // TimerX setup, Fast PWM mode count to TOP set in ICRx + TCCRxA = _BV(WGM11); // = 0b00000010; + // clock select clk/1 + TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; + ICRx = BACKLIGHT_RESOLUTION; + + backlight_init(); + +#ifdef BACKLIGHT_BREATHING + if (is_backlight_breathing()) { + breathing_enable(); + } +#endif +} diff --git a/platforms/avr/drivers/i2c_master.c b/platforms/avr/drivers/i2c_master.c index 524494c99d79..58939f3e00e5 100644 --- a/platforms/avr/drivers/i2c_master.c +++ b/platforms/avr/drivers/i2c_master.c @@ -23,6 +23,7 @@ #include "i2c_master.h" #include "timer.h" #include "wait.h" +#include "util.h" #ifndef F_SCL # define F_SCL 400000UL // SCL frequency @@ -37,8 +38,6 @@ #define TWBR_val (((F_CPU / F_SCL) - 16) / 2) -#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) - void i2c_init(void) { TWSR = 0; /* no prescaler */ TWBR = (uint8_t)TWBR_val; diff --git a/platforms/avr/drivers/ws2812.c b/platforms/avr/drivers/ws2812_bitbang.c similarity index 95% rename from platforms/avr/drivers/ws2812.c rename to platforms/avr/drivers/ws2812_bitbang.c index 5c0cb3b718dc..aad10d86b0b0 100644 --- a/platforms/avr/drivers/ws2812.c +++ b/platforms/avr/drivers/ws2812_bitbang.c @@ -38,10 +38,10 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi); void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) { - DDRx_ADDRESS(RGB_DI_PIN) |= pinmask(RGB_DI_PIN); + DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN); - uint8_t masklo = ~(pinmask(RGB_DI_PIN)) & PORTx_ADDRESS(RGB_DI_PIN); - uint8_t maskhi = pinmask(RGB_DI_PIN) | PORTx_ADDRESS(RGB_DI_PIN); + uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN); + uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN); ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(LED_TYPE), masklo, maskhi); @@ -165,7 +165,7 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t " dec %0 \n\t" // '1' [+2] '0' [+2] " brne loop%=\n\t" // '1' [+3] '0' [+4] : "=&d"(ctr) - : "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(RGB_DI_PIN))), "r"(maskhi), "r"(masklo)); + : "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(WS2812_DI_PIN))), "r"(maskhi), "r"(masklo)); } SREG = sreg_prev; diff --git a/platforms/avr/drivers/ws2812_i2c.c b/platforms/avr/drivers/ws2812_i2c.c index 709f3822547f..f4a2fbe0b309 100644 --- a/platforms/avr/drivers/ws2812_i2c.c +++ b/platforms/avr/drivers/ws2812_i2c.c @@ -5,12 +5,12 @@ # error "RGBW not supported" #endif -#ifndef WS2812_ADDRESS -# define WS2812_ADDRESS 0xb0 +#ifndef WS2812_I2C_ADDRESS +# define WS2812_I2C_ADDRESS 0xB0 #endif -#ifndef WS2812_TIMEOUT -# define WS2812_TIMEOUT 100 +#ifndef WS2812_I2C_TIMEOUT +# define WS2812_I2C_TIMEOUT 100 #endif void ws2812_init(void) { @@ -25,5 +25,5 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { s_init = true; } - i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT); + i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_I2C_TIMEOUT); } diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 39a11b28e47f..09028d80af36 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -12,8 +12,7 @@ HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) BIN = -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -ifneq ($(findstring 12.,$(shell avr-gcc --version 2>/dev/null)),) +ifeq ("$(shell echo "int main(){}" | $(CC) --param=min-pagesize=0 -x c - -o /dev/null 2>&1)", "") COMPILEFLAGS += --param=min-pagesize=0 endif diff --git a/platforms/avr/printf.mk b/platforms/avr/printf.mk index 060ad88c57c9..c6490169d83d 100644 --- a/platforms/avr/printf.mk +++ b/platforms/avr/printf.mk @@ -1,2 +1,2 @@ -TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S -TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c +SRC += $(PLATFORM_COMMON_DIR)/xprintf.S +SRC += $(PLATFORM_COMMON_DIR)/printf.c diff --git a/platforms/avr/sleep_led.c b/platforms/avr/sleep_led.c index b05431633ba3..ad6253be93f4 100644 --- a/platforms/avr/sleep_led.c +++ b/platforms/avr/sleep_led.c @@ -109,16 +109,19 @@ ISR(TIMERx_COMPA_vect) { uint8_t duration : 2; uint8_t index : 6; } pwm; - } timer = {.row = 0}; + } timer = {.row = 0}; + static led_t led_state = {0}; timer.row++; // LED on if (timer.pwm.count == 0) { - led_set(1 << USB_LED_CAPS_LOCK); + led_state.caps_lock = true; + led_set(led_state.raw); } // LED off if (timer.pwm.count == pgm_read_byte(&breathing_table[timer.pwm.index])) { - led_set(0); + led_state.caps_lock = false; + led_set(led_state.raw); } } diff --git a/platforms/chibios/boards/BONSAI_C4/configs/config.h b/platforms/chibios/boards/BONSAI_C4/configs/config.h index e412f73d3d71..c5dbb25c4510 100644 --- a/platforms/chibios/boards/BONSAI_C4/configs/config.h +++ b/platforms/chibios/boards/BONSAI_C4/configs/config.h @@ -67,8 +67,8 @@ // WS2812-style LED control on pin A10 #ifdef WS2812_DRIVER_PWM -# ifndef RGB_DI_PIN -# define RGB_DI_PIN PAL_LINE(GPIOA, 10) +# ifndef WS2812_DI_PIN +# define WS2812_DI_PIN PAL_LINE(GPIOA, 10) # endif # ifndef WS2812_PWM_DRIVER # define WS2812_PWM_DRIVER PWMD1 diff --git a/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h index ab293c0b4045..8621807cbbc6 100644 --- a/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h @@ -106,7 +106,6 @@ #define RP_USB_USE_USBD0 TRUE #define RP_USB_FORCE_VBUS_DETECT TRUE #define RP_USE_EXTERNAL_VBUS_DETECT FALSE -#define RP_USB_USE_SOF_INTR TRUE #define RP_USB_USE_ERROR_DATA_SEQ_INTR FALSE #endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h index b91d76241994..902f9b5005b7 100644 --- a/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h @@ -106,7 +106,6 @@ #define RP_USB_USE_USBD0 TRUE #define RP_USB_FORCE_VBUS_DETECT TRUE #define RP_USE_EXTERNAL_VBUS_DETECT FALSE -#define RP_USB_USE_SOF_INTR TRUE #define RP_USB_USE_ERROR_DATA_SEQ_INTR FALSE #endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/GENERIC_STM32_H723XG/board/board.mk b/platforms/chibios/boards/GENERIC_STM32_H723XG/board/board.mk new file mode 100644 index 000000000000..3511f752a91d --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_H723XG/board/board.mk @@ -0,0 +1,12 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H723ZG/board.c + +# Extra files +BOARDSRC += $(BOARD_PATH)/board/extra.c + +# Required include directories +BOARDINC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_H723ZG + +# Shared variables +ALLCSRC += $(BOARDSRC) +ALLINC += $(BOARDINC) diff --git a/platforms/chibios/boards/GENERIC_STM32_H723XG/board/extra.c b/platforms/chibios/boards/GENERIC_STM32_H723XG/board/extra.c new file mode 100755 index 000000000000..fce0b4abad1c --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_H723XG/board/extra.c @@ -0,0 +1,36 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#define BOOTLOADER_MAGIC 0xDEADBEEF + +//////////////////////////////////////////////////////////////////////////////// +// Different signalling for bootloader entry +// - RAM is cleared on reset, so we can't use the usual __ram0_end__ symbol. +// - Use backup registers in the RTC peripheral to store the magic value instead. + +static inline void enable_backup_register_access(void) { + PWR->CR1 |= PWR_CR1_DBP; +} + +static inline void disable_backup_register_access(void) { + PWR->CR1 &= ~PWR_CR1_DBP; +} + +void bootloader_marker_enable(void) { + enable_backup_register_access(); + RTC->BKP0R = BOOTLOADER_MAGIC; + disable_backup_register_access(); +} + +bool bootloader_marker_active(void) { + enable_backup_register_access(); + bool ret = RTC->BKP0R == BOOTLOADER_MAGIC; + disable_backup_register_access(); + return ret; +} + +void bootloader_marker_disable(void) { + enable_backup_register_access(); + RTC->BKP0R = 0; + disable_backup_register_access(); +} diff --git a/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/config.h new file mode 100644 index 000000000000..f43df29b54a6 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/config.h @@ -0,0 +1,9 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define USB_DRIVER USBD2 + +#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP +# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE +#endif diff --git a/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/mcuconf.h new file mode 100644 index 000000000000..0239ec5273b5 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_H723XG/configs/mcuconf.h @@ -0,0 +1,511 @@ +/* + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef MCUCONF_H +#define MCUCONF_H + +/* + * STM32H723/33/25/35 drivers configuration. + * The following settings override the default settings present in + * the various device driver implementation headers. + * Note that the settings for each driver only have effect if the whole + * driver is enabled in halconf.h. + * + * IRQ priorities: + * 15...0 Lowest...Highest. + * + * DMA priorities: + * 0...3 Lowest...Highest. + */ + +#define STM32H7xx_MCUCONF +#define STM32H723_MCUCONF +#define STM32H733_MCUCONF +#define STM32H725_MCUCONF +#define STM32H735_MCUCONF + +/* + * General settings. + */ +#define STM32_NO_INIT FALSE + +/* + * Memory attributes settings. + */ +#define STM32_NOCACHE_ENABLE FALSE +#define STM32_NOCACHE_MPU_REGION MPU_REGION_6 +#define STM32_NOCACHE_RBAR 0x24000000U +#define STM32_NOCACHE_RASR MPU_RASR_SIZE_16K + +/* + * PWR system settings. + * Reading STM32 Reference Manual is required, settings in PWR_CR3 are + * very critical. + * Register constants are taken from the ST header. + */ +#define STM32_VOS STM32_VOS_SCALE0 +#define STM32_PWR_CR1 (PWR_CR1_SVOS_1 | PWR_CR1_SVOS_0) +#define STM32_PWR_CR2 (PWR_CR2_BREN) +#define STM32_PWR_CR3 (PWR_CR3_LDOEN | PWR_CR3_USB33DEN) +#define STM32_PWR_CPUCR 0 + +/* + * Clock tree static settings. + * Reading STM32 Reference Manual is required. + */ +#define STM32_HSI_ENABLED TRUE +#define STM32_LSI_ENABLED FALSE +#define STM32_CSI_ENABLED FALSE +#define STM32_HSI48_ENABLED TRUE +#define STM32_HSE_ENABLED TRUE +#define STM32_LSE_ENABLED FALSE +#define STM32_HSIDIV STM32_HSIDIV_DIV1 + +/* + * PLLs static settings. + * Reading STM32 Reference Manual is required. + */ +#define STM32_PLLSRC STM32_PLLSRC_HSE_CK +#define STM32_PLLCFGR_MASK ~0 +#define STM32_PLL1_ENABLED TRUE +#define STM32_PLL1_P_ENABLED TRUE +#define STM32_PLL1_Q_ENABLED TRUE +#define STM32_PLL1_R_ENABLED TRUE +#define STM32_PLL1_DIVM_VALUE 4 +#define STM32_PLL1_DIVN_VALUE 275 +#define STM32_PLL1_FRACN_VALUE 0 +#define STM32_PLL1_DIVP_VALUE 1 +#define STM32_PLL1_DIVQ_VALUE 10 +#define STM32_PLL1_DIVR_VALUE 4 +#define STM32_PLL2_ENABLED TRUE +#define STM32_PLL2_P_ENABLED TRUE +#define STM32_PLL2_Q_ENABLED TRUE +#define STM32_PLL2_R_ENABLED TRUE +#define STM32_PLL2_DIVM_VALUE 4 +#define STM32_PLL2_DIVN_VALUE 400 +#define STM32_PLL2_FRACN_VALUE 0 +#define STM32_PLL2_DIVP_VALUE 40 +#define STM32_PLL2_DIVQ_VALUE 8 +#define STM32_PLL2_DIVR_VALUE 8 +#define STM32_PLL3_ENABLED TRUE +#define STM32_PLL3_P_ENABLED TRUE +#define STM32_PLL3_Q_ENABLED TRUE +#define STM32_PLL3_R_ENABLED TRUE +#define STM32_PLL3_DIVM_VALUE 4 +#define STM32_PLL3_DIVN_VALUE 240 +#define STM32_PLL3_FRACN_VALUE 0 +#define STM32_PLL3_DIVP_VALUE 10 +#define STM32_PLL3_DIVQ_VALUE 10 +#define STM32_PLL3_DIVR_VALUE 10 + +/* + * Core clocks dynamic settings (can be changed at runtime). + * Reading STM32 Reference Manual is required. + */ +#define STM32_SW STM32_SW_PLL1_P_CK +#define STM32_RTCSEL STM32_RTCSEL_LSI_CK +#define STM32_D1CPRE STM32_D1CPRE_DIV1 +#define STM32_D1HPRE STM32_D1HPRE_DIV2 +#define STM32_D1PPRE3 STM32_D1PPRE3_DIV2 +#define STM32_D2PPRE1 STM32_D2PPRE1_DIV2 +#define STM32_D2PPRE2 STM32_D2PPRE2_DIV2 +#define STM32_D3PPRE4 STM32_D3PPRE4_DIV2 + +/* + * Peripherals clocks static settings. + * Reading STM32 Reference Manual is required. + */ +#define STM32_MCO1SEL STM32_MCO1SEL_HSI_CK +#define STM32_MCO1PRE_VALUE 4 +#define STM32_MCO2SEL STM32_MCO2SEL_SYS_CK +#define STM32_MCO2PRE_VALUE 4 +#define STM32_TIMPRE_ENABLE TRUE +#define STM32_HRTIMSEL 0 +#define STM32_STOPKERWUCK 0 +#define STM32_STOPWUCK 0 +#define STM32_RTCPRE_VALUE 8 +#define STM32_CKPERSEL STM32_CKPERSEL_HSE_CK +#define STM32_SDMMCSEL STM32_SDMMCSEL_PLL1_Q_CK +#define STM32_OCTOSPISEL STM32_OCTOSPISEL_HCLK +#define STM32_FMCSEL STM32_FMCSEL_HCLK +#define STM32_SWPSEL STM32_SWPSEL_PCLK1 +#define STM32_FDCANSEL STM32_FDCANSEL_HSE_CK +#define STM32_DFSDM1SEL STM32_DFSDM1SEL_PCLK2 +#define STM32_SPDIFSEL STM32_SPDIFSEL_PLL1_Q_CK +#define STM32_SPI45SEL STM32_SPI45SEL_PCLK2 +#define STM32_SPI123SEL STM32_SPI123SEL_PLL1_Q_CK +#define STM32_SAI1SEL STM32_SAI1SEL_PLL1_Q_CK +#define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1 +#define STM32_CECSEL STM32_CECSEL_LSE_CK +#define STM32_USBSEL STM32_USBSEL_PLL3_Q_CK +#define STM32_I2C1235SEL STM32_I2C1235SEL_PCLK1 +#define STM32_RNGSEL STM32_RNGSEL_PLL1_Q_CK +#define STM32_USART16910SEL STM32_USART16910SEL_PCLK2 +#define STM32_USART234578SEL STM32_USART234578SEL_PCLK1 +#define STM32_SPI6SEL STM32_SPI6SEL_PCLK4 +#define STM32_SAI4BSEL STM32_SAI4BSEL_PLL1_Q_CK +#define STM32_SAI4ASEL STM32_SAI4ASEL_PLL1_Q_CK +#define STM32_ADCSEL STM32_ADCSEL_PLL2_P_CK +#define STM32_LPTIM345SEL STM32_LPTIM345SEL_PCLK4 +#define STM32_LPTIM2SEL STM32_LPTIM2SEL_PCLK4 +#define STM32_I2C4SEL STM32_I2C4SEL_PCLK4 +#define STM32_LPUART1SEL STM32_LPUART1SEL_PCLK4 + +/* + * IRQ system settings. + */ +#define STM32_IRQ_EXTI0_PRIORITY 6 +#define STM32_IRQ_EXTI1_PRIORITY 6 +#define STM32_IRQ_EXTI2_PRIORITY 6 +#define STM32_IRQ_EXTI3_PRIORITY 6 +#define STM32_IRQ_EXTI4_PRIORITY 6 +#define STM32_IRQ_EXTI5_9_PRIORITY 6 +#define STM32_IRQ_EXTI10_15_PRIORITY 6 +#define STM32_IRQ_EXTI16_PRIORITY 6 +#define STM32_IRQ_EXTI17_PRIORITY 6 +#define STM32_IRQ_EXTI18_PRIORITY 6 +#define STM32_IRQ_EXTI19_PRIORITY 6 +#define STM32_IRQ_EXTI20_21_PRIORITY 6 + +#define STM32_IRQ_FDCAN1_PRIORITY 10 +#define STM32_IRQ_FDCAN2_PRIORITY 10 + +#define STM32_IRQ_MDMA_PRIORITY 9 + +#define STM32_IRQ_OCTOSPI1_PRIORITY 10 +#define STM32_IRQ_OCTOSPI2_PRIORITY 10 + +#define STM32_IRQ_SDMMC1_PRIORITY 9 +#define STM32_IRQ_SDMMC2_PRIORITY 9 + +#define STM32_IRQ_TIM1_UP_PRIORITY 7 +#define STM32_IRQ_TIM1_CC_PRIORITY 7 +#define STM32_IRQ_TIM2_PRIORITY 7 +#define STM32_IRQ_TIM3_PRIORITY 7 +#define STM32_IRQ_TIM4_PRIORITY 7 +#define STM32_IRQ_TIM5_PRIORITY 7 +#define STM32_IRQ_TIM6_PRIORITY 7 +#define STM32_IRQ_TIM7_PRIORITY 7 +#define STM32_IRQ_TIM8_BRK_TIM12_PRIORITY 7 +#define STM32_IRQ_TIM8_UP_TIM13_PRIORITY 7 +#define STM32_IRQ_TIM8_TRGCO_TIM14_PRIORITY 7 +#define STM32_IRQ_TIM8_CC_PRIORITY 7 +#define STM32_IRQ_TIM15_PRIORITY 7 +#define STM32_IRQ_TIM16_PRIORITY 7 +#define STM32_IRQ_TIM17_PRIORITY 7 + +#define STM32_IRQ_USART1_PRIORITY 12 +#define STM32_IRQ_USART2_PRIORITY 12 +#define STM32_IRQ_USART3_PRIORITY 12 +#define STM32_IRQ_UART4_PRIORITY 12 +#define STM32_IRQ_UART5_PRIORITY 12 +#define STM32_IRQ_USART6_PRIORITY 12 +#define STM32_IRQ_UART7_PRIORITY 12 +#define STM32_IRQ_UART8_PRIORITY 12 +#define STM32_IRQ_UART9_PRIORITY 12 +#define STM32_IRQ_USART10_PRIORITY 12 +#define STM32_IRQ_LPUART1_PRIORITY 12 + +/* + * ADC driver system settings. + */ +#define STM32_ADC_DUAL_MODE FALSE +#define STM32_ADC_SAMPLES_SIZE 16 +#define STM32_ADC_USE_ADC12 FALSE +#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_ADC_ADC12_DMA_PRIORITY 2 +#define STM32_ADC_ADC12_IRQ_PRIORITY 5 +#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV4 + +/* + * CAN driver system settings. + */ +#define STM32_CAN_USE_FDCAN1 FALSE +#define STM32_CAN_USE_FDCAN2 FALSE + +/* + * DAC driver system settings. + */ +#define STM32_DAC_DUAL_MODE FALSE +#define STM32_DAC_USE_DAC1_CH1 FALSE +#define STM32_DAC_USE_DAC1_CH2 FALSE +#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10 +#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10 +#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2 +#define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2 +#define STM32_DAC_DAC1_CH1_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID_ANY + +/* + * GPT driver system settings. + */ +#define STM32_GPT_USE_TIM1 FALSE +#define STM32_GPT_USE_TIM2 FALSE +#define STM32_GPT_USE_TIM3 FALSE +#define STM32_GPT_USE_TIM4 FALSE +#define STM32_GPT_USE_TIM5 FALSE +#define STM32_GPT_USE_TIM6 FALSE +#define STM32_GPT_USE_TIM7 FALSE +#define STM32_GPT_USE_TIM8 FALSE +#define STM32_GPT_USE_TIM12 FALSE +#define STM32_GPT_USE_TIM13 FALSE +#define STM32_GPT_USE_TIM14 FALSE +#define STM32_GPT_USE_TIM15 FALSE +#define STM32_GPT_USE_TIM16 FALSE +#define STM32_GPT_USE_TIM17 FALSE + +/* + * I2C driver system settings. + */ +#define STM32_I2C_USE_I2C1 FALSE +#define STM32_I2C_USE_I2C2 FALSE +#define STM32_I2C_USE_I2C3 FALSE +#define STM32_I2C_USE_I2C4 FALSE +#define STM32_I2C_BUSY_TIMEOUT 50 +#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_I2C_I2C4_RX_BDMA_STREAM STM32_BDMA_STREAM_ID_ANY +#define STM32_I2C_I2C4_TX_BDMA_STREAM STM32_BDMA_STREAM_ID_ANY +#define STM32_I2C_I2C1_IRQ_PRIORITY 5 +#define STM32_I2C_I2C2_IRQ_PRIORITY 5 +#define STM32_I2C_I2C3_IRQ_PRIORITY 5 +#define STM32_I2C_I2C4_IRQ_PRIORITY 5 +#define STM32_I2C_I2C1_DMA_PRIORITY 3 +#define STM32_I2C_I2C2_DMA_PRIORITY 3 +#define STM32_I2C_I2C3_DMA_PRIORITY 3 +#define STM32_I2C_I2C4_DMA_PRIORITY 3 +#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure") + +/* + * ICU driver system settings. + */ +#define STM32_ICU_USE_TIM1 FALSE +#define STM32_ICU_USE_TIM2 FALSE +#define STM32_ICU_USE_TIM3 FALSE +#define STM32_ICU_USE_TIM4 FALSE +#define STM32_ICU_USE_TIM5 FALSE +#define STM32_ICU_USE_TIM8 FALSE +#define STM32_ICU_USE_TIM12 FALSE +#define STM32_ICU_USE_TIM13 FALSE +#define STM32_ICU_USE_TIM14 FALSE +#define STM32_ICU_USE_TIM15 FALSE +#define STM32_ICU_USE_TIM16 FALSE +#define STM32_ICU_USE_TIM17 FALSE + +/* + * MAC driver system settings. + */ +#define STM32_MAC_TRANSMIT_BUFFERS 2 +#define STM32_MAC_RECEIVE_BUFFERS 4 +#define STM32_MAC_BUFFERS_SIZE 1522 +#define STM32_MAC_PHY_TIMEOUT 100 +#define STM32_MAC_ETH1_CHANGE_PHY_STATE TRUE +#define STM32_MAC_ETH1_IRQ_PRIORITY 13 +#define STM32_MAC_IP_CHECKSUM_OFFLOAD 0 + +/* + * PWM driver system settings. + */ +#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM2 FALSE +#define STM32_PWM_USE_TIM3 FALSE +#define STM32_PWM_USE_TIM4 FALSE +#define STM32_PWM_USE_TIM5 FALSE +#define STM32_PWM_USE_TIM8 FALSE +#define STM32_PWM_USE_TIM12 FALSE +#define STM32_PWM_USE_TIM13 FALSE +#define STM32_PWM_USE_TIM14 FALSE +#define STM32_PWM_USE_TIM15 FALSE +#define STM32_PWM_USE_TIM16 FALSE +#define STM32_PWM_USE_TIM17 FALSE + +/* + * RTC driver system settings. + */ +#define STM32_RTC_PRESA_VALUE 32 +#define STM32_RTC_PRESS_VALUE 1024 +#define STM32_RTC_CR_INIT 0 +#define STM32_RTC_TAMPCR_INIT 0 + +/* + * SDC driver system settings. + */ +#define STM32_SDC_USE_SDMMC1 FALSE +#define STM32_SDC_USE_SDMMC2 FALSE +#define STM32_SDC_SDMMC_UNALIGNED_SUPPORT TRUE +#define STM32_SDC_SDMMC_WRITE_TIMEOUT 10000 +#define STM32_SDC_SDMMC_READ_TIMEOUT 10000 +#define STM32_SDC_SDMMC_CLOCK_DELAY 10 +#define STM32_SDC_SDMMC_PWRSAV TRUE + +/* + * SERIAL driver system settings. + */ +#define STM32_SERIAL_USE_USART1 FALSE +#define STM32_SERIAL_USE_USART2 FALSE +#define STM32_SERIAL_USE_USART3 FALSE +#define STM32_SERIAL_USE_UART4 FALSE +#define STM32_SERIAL_USE_UART5 FALSE +#define STM32_SERIAL_USE_USART6 FALSE +#define STM32_SERIAL_USE_UART7 FALSE +#define STM32_SERIAL_USE_UART8 FALSE +#define STM32_SERIAL_USE_UART9 FALSE +#define STM32_SERIAL_USE_USART10 FALSE +#define STM32_SERIAL_USE_LPUART1 FALSE + +/* + * SIO driver system settings. + */ +#define STM32_SIO_USE_USART1 FALSE +#define STM32_SIO_USE_USART2 FALSE +#define STM32_SIO_USE_USART3 FALSE +#define STM32_SIO_USE_UART4 FALSE +#define STM32_SIO_USE_UART5 FALSE +#define STM32_SIO_USE_USART6 FALSE +#define STM32_SIO_USE_UART7 FALSE +#define STM32_SIO_USE_UART8 FALSE +#define STM32_SIO_USE_UART9 FALSE +#define STM32_SIO_USE_USART10 FALSE +#define STM32_SIO_USE_LPUART1 FALSE + +/* + * SPI driver system settings. + */ +#define STM32_SPI_USE_SPI1 FALSE +#define STM32_SPI_USE_SPI2 FALSE +#define STM32_SPI_USE_SPI3 FALSE +#define STM32_SPI_USE_SPI4 FALSE +#define STM32_SPI_USE_SPI5 FALSE +#define STM32_SPI_USE_SPI6 FALSE +#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI4_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI4_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI5_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI5_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_SPI_SPI6_RX_BDMA_STREAM STM32_BDMA_STREAM_ID_ANY +#define STM32_SPI_SPI6_TX_BDMA_STREAM STM32_BDMA_STREAM_ID_ANY +#define STM32_SPI_SPI1_DMA_PRIORITY 1 +#define STM32_SPI_SPI2_DMA_PRIORITY 1 +#define STM32_SPI_SPI3_DMA_PRIORITY 1 +#define STM32_SPI_SPI4_DMA_PRIORITY 1 +#define STM32_SPI_SPI5_DMA_PRIORITY 1 +#define STM32_SPI_SPI6_DMA_PRIORITY 1 +#define STM32_SPI_SPI1_IRQ_PRIORITY 10 +#define STM32_SPI_SPI2_IRQ_PRIORITY 10 +#define STM32_SPI_SPI3_IRQ_PRIORITY 10 +#define STM32_SPI_SPI4_IRQ_PRIORITY 10 +#define STM32_SPI_SPI5_IRQ_PRIORITY 10 +#define STM32_SPI_SPI6_IRQ_PRIORITY 10 +#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure") + +/* + * ST driver system settings. + */ +#define STM32_ST_IRQ_PRIORITY 8 +#define STM32_ST_USE_TIMER 2 + +/* + * TRNG driver system settings. + */ +#define STM32_TRNG_USE_RNG1 FALSE + +/* + * UART driver system settings. + */ +#define STM32_UART_USE_USART1 FALSE +#define STM32_UART_USE_USART2 FALSE +#define STM32_UART_USE_USART3 FALSE +#define STM32_UART_USE_UART4 FALSE +#define STM32_UART_USE_UART5 FALSE +#define STM32_UART_USE_USART6 FALSE +#define STM32_UART_USE_UART7 FALSE +#define STM32_UART_USE_UART8 FALSE +#define STM32_UART_USE_UART9 FALSE +#define STM32_UART_USE_USART10 FALSE +#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART7_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART7_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART8_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART8_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART9_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_UART9_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART10_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART10_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY +#define STM32_UART_USART1_DMA_PRIORITY 0 +#define STM32_UART_USART2_DMA_PRIORITY 0 +#define STM32_UART_USART3_DMA_PRIORITY 0 +#define STM32_UART_UART4_DMA_PRIORITY 0 +#define STM32_UART_UART5_DMA_PRIORITY 0 +#define STM32_UART_USART6_DMA_PRIORITY 0 +#define STM32_UART_UART7_DMA_PRIORITY 0 +#define STM32_UART_UART8_DMA_PRIORITY 0 +#define STM32_UART_UART9_DMA_PRIORITY 0 +#define STM32_UART_USART10_DMA_PRIORITY 0 +#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure") + +/* + * USB driver system settings. + */ +#define STM32_USB_USE_OTG2 TRUE +#define STM32_USB_OTG2_IRQ_PRIORITY 14 +#define STM32_USB_OTG2_RX_FIFO_SIZE 1024 +#define STM32_USB_HOST_WAKEUP_DURATION 2 + +/* + * WDG driver system settings. + */ +#define STM32_WDG_USE_IWDG FALSE + +/* + * WSPI driver system settings. + */ +#define STM32_WSPI_USE_OCTOSPI1 FALSE +#define STM32_WSPI_USE_OCTOSPI2 FALSE +#define STM32_WSPI_OCTOSPI1_PRESCALER_VALUE 1 +#define STM32_WSPI_OCTOSPI2_PRESCALER_VALUE 1 +#define STM32_WSPI_OCTOSPI1_SSHIFT FALSE +#define STM32_WSPI_OCTOSPI2_SSHIFT FALSE +#define STM32_WSPI_OCTOSPI1_DHQC FALSE +#define STM32_WSPI_OCTOSPI2_DHQC FALSE +#define STM32_WSPI_OCTOSPI1_MDMA_CHANNEL STM32_MDMA_CHANNEL_ID_ANY +#define STM32_WSPI_OCTOSPI2_MDMA_CHANNEL STM32_MDMA_CHANNEL_ID_ANY +#define STM32_WSPI_OCTOSPI1_MDMA_PRIORITY 1 +#define STM32_WSPI_OCTOSPI2_MDMA_PRIORITY 1 +#define STM32_WSPI_OCTOSPI1_MDMA_IRQ_PRIORITY 10 +#define STM32_WSPI_OCTOSPI2_MDMA_IRQ_PRIORITY 10 +#define STM32_WSPI_DMA_ERROR_HOOK(wspip) osalSysHalt("MDMA failure") + +#endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/IC_TEENSY_3_1/board/board.c b/platforms/chibios/boards/IC_TEENSY_3_1/board/board.c index 424e0c975b40..189d90952d8d 100644 --- a/platforms/chibios/boards/IC_TEENSY_3_1/board/board.c +++ b/platforms/chibios/boards/IC_TEENSY_3_1/board/board.c @@ -147,5 +147,5 @@ void boardInit(void) {} void restart_usb_driver(USBDriver *usbp) { - // Do nothing. Restarting the USB driver on these boards breaks it. + // Do nothing. Restarting the USB driver on these boards breaks it. } diff --git a/platforms/chibios/boards/QMK_BLOK/board/board.mk b/platforms/chibios/boards/QMK_BLOK/board/board.mk new file mode 100644 index 000000000000..911cc5a05868 --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/board/board.mk @@ -0,0 +1,9 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS)/os/hal/boards/RP_PICO_RP2040/board.c + +# Required include directories +BOARDINC = $(CHIBIOS)/os/hal/boards/RP_PICO_RP2040 + +# Shared variables +ALLCSRC += $(BOARDSRC) +ALLINC += $(BOARDINC) diff --git a/platforms/chibios/boards/QMK_BLOK/configs/board.h b/platforms/chibios/boards/QMK_BLOK/configs/board.h new file mode 100644 index 000000000000..d0e23902aa41 --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/configs/board.h @@ -0,0 +1,12 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include_next + +#undef BOARD_RP_PICO_RP2040 +#define BOARD_PM2040 + +#undef BOARD_NAME +#define BOARD_NAME "Blok" diff --git a/platforms/chibios/boards/QMK_BLOK/configs/chconf.h b/platforms/chibios/boards/QMK_BLOK/configs/chconf.h new file mode 100644 index 000000000000..d53f57edd943 --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/configs/chconf.h @@ -0,0 +1,13 @@ +// Copyright 2022 Stefan Kerkmann +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#define CH_CFG_SMP_MODE TRUE +#define CH_CFG_ST_RESOLUTION 32 +#define CH_CFG_ST_FREQUENCY 1000000 +#define CH_CFG_INTERVALS_SIZE 32 +#define CH_CFG_TIME_TYPES_SIZE 32 +#define CH_CFG_ST_TIMEDELTA 20 + +#include_next diff --git a/platforms/chibios/boards/QMK_BLOK/configs/config.h b/platforms/chibios/boards/QMK_BLOK/configs/config.h new file mode 100644 index 000000000000..168afb1fc46f --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/configs/config.h @@ -0,0 +1,21 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#ifndef I2C_DRIVER +# define I2C_DRIVER I2CD0 +#endif +#ifndef I2C1_SDA_PIN +# define I2C1_SDA_PIN D1 +#endif +#ifndef I2C1_SCL_PIN +# define I2C1_SCL_PIN D0 +#endif + +#ifndef RP2040_BOOTLOADER_DOUBLE_TAP_RESET +# define RP2040_BOOTLOADER_DOUBLE_TAP_RESET +#endif +#ifndef RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT +# define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U +#endif diff --git a/platforms/chibios/boards/QMK_BLOK/configs/halconf.h b/platforms/chibios/boards/QMK_BLOK/configs/halconf.h new file mode 100644 index 000000000000..131386bc34f7 --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/configs/halconf.h @@ -0,0 +1,10 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#define HAL_USE_ADC TRUE +#define HAL_USE_I2C TRUE +#define HAL_USE_SPI TRUE + +#include_next diff --git a/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h b/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h new file mode 100644 index 000000000000..0c2ef592d6f6 --- /dev/null +++ b/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h @@ -0,0 +1,111 @@ +/* + ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef MCUCONF_H +#define MCUCONF_H + +/* + * RP2040_MCUCONF drivers configuration. + * + * IRQ priorities: + * 3...0 Lowest...Highest. + * + * DMA priorities: + * 0...1 Lowest...Highest. + */ + +#define RP2040_MCUCONF + +/* + * HAL driver system settings. + */ +#define RP_NO_INIT FALSE +#define RP_CORE1_START FALSE +#define RP_CORE1_VECTORS_TABLE _vectors +#define RP_CORE1_ENTRY_POINT _crt0_c1_entry +#define RP_CORE1_STACK_END __c1_main_stack_end__ + +/* + * IRQ system settings. + */ +#define RP_IRQ_SYSTICK_PRIORITY 2 +#define RP_IRQ_TIMER_ALARM0_PRIORITY 2 +#define RP_IRQ_TIMER_ALARM1_PRIORITY 2 +#define RP_IRQ_TIMER_ALARM2_PRIORITY 2 +#define RP_IRQ_TIMER_ALARM3_PRIORITY 2 +#define RP_IRQ_ADC1_PRIORITY 3 +#define RP_IRQ_UART0_PRIORITY 3 +#define RP_IRQ_UART1_PRIORITY 3 +#define RP_IRQ_SPI0_PRIORITY 2 +#define RP_IRQ_SPI1_PRIORITY 2 +#define RP_IRQ_USB0_PRIORITY 3 +#define RP_IRQ_I2C0_PRIORITY 2 +#define RP_IRQ_I2C1_PRIORITY 2 + +/* + * ADC driver system settings. + */ +#define RP_ADC_USE_ADC1 TRUE + +/* + * SIO driver system settings. + */ +#define RP_SIO_USE_UART0 FALSE +#define RP_SIO_USE_UART1 FALSE + +/* + * SPI driver system settings. + */ +#define RP_SPI_USE_SPI0 TRUE +#define RP_SPI_USE_SPI1 FALSE +#define RP_SPI_SPI0_RX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY +#define RP_SPI_SPI0_TX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY +#define RP_SPI_SPI1_RX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY +#define RP_SPI_SPI1_TX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY +#define RP_SPI_SPI0_DMA_PRIORITY 1 +#define RP_SPI_SPI1_DMA_PRIORITY 1 +#define RP_SPI_DMA_ERROR_HOOK(spip) + +/* + * PWM driver system settings. + */ +#define RP_PWM_USE_PWM0 FALSE +#define RP_PWM_USE_PWM1 FALSE +#define RP_PWM_USE_PWM2 FALSE +#define RP_PWM_USE_PWM3 FALSE +#define RP_PWM_USE_PWM4 FALSE +#define RP_PWM_USE_PWM5 FALSE +#define RP_PWM_USE_PWM6 FALSE +#define RP_PWM_USE_PWM7 FALSE +#define RP_PWM_IRQ_WRAP_NUMBER_PRIORITY 3 + +/* + * I2C driver system settings. + */ +#define RP_I2C_USE_I2C0 TRUE +#define RP_I2C_USE_I2C1 FALSE +#define RP_I2C_BUSY_TIMEOUT 50 +#define RP_I2C_ADDRESS_MODE_10BIT FALSE + +/* + * USB driver system settings. + */ +#define RP_USB_USE_USBD0 TRUE +#define RP_USB_FORCE_VBUS_DETECT TRUE +#define RP_USE_EXTERNAL_VBUS_DETECT FALSE +#define RP_USB_USE_ERROR_DATA_SEQ_INTR FALSE + +#endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h b/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h index f19f08e93c0f..493dcf643427 100644 --- a/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h +++ b/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h @@ -106,7 +106,6 @@ #define RP_USB_USE_USBD0 TRUE #define RP_USB_FORCE_VBUS_DETECT TRUE #define RP_USE_EXTERNAL_VBUS_DETECT FALSE -#define RP_USB_USE_SOF_INTR TRUE #define RP_USB_USE_ERROR_DATA_SEQ_INTR FALSE #endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino.ld similarity index 100% rename from platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld rename to platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino.ld diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino.ld similarity index 100% rename from platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld rename to platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino.ld diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino.ld similarity index 100% rename from platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld rename to platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino.ld diff --git a/platforms/chibios/boards/common/ld/STM32F103x8_uf2boot.ld b/platforms/chibios/boards/common/ld/STM32F103x8_uf2boot.ld new file mode 100644 index 000000000000..adf43c362a5a --- /dev/null +++ b/platforms/chibios/boards/common/ld/STM32F103x8_uf2boot.ld @@ -0,0 +1,88 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * ST32F103x8 memory setup. + */ +MEMORY +{ + flash0 (rx) : org = 0x08000000 + 16K, len = 64k - 16K + flash1 (rx) : org = 0x00000000, len = 0 + flash2 (rx) : org = 0x00000000, len = 0 + flash3 (rx) : org = 0x00000000, len = 0 + flash4 (rx) : org = 0x00000000, len = 0 + flash5 (rx) : org = 0x00000000, len = 0 + flash6 (rx) : org = 0x00000000, len = 0 + flash7 (rx) : org = 0x00000000, len = 0 + ram0 (wx) : org = 0x20000000, len = 20k + ram1 (wx) : org = 0x00000000, len = 0 + ram2 (wx) : org = 0x00000000, len = 0 + ram3 (wx) : org = 0x00000000, len = 0 + ram4 (wx) : org = 0x00000000, len = 0 + ram5 (wx) : org = 0x00000000, len = 0 + ram6 (wx) : org = 0x00000000, len = 0 + ram7 (wx) : org = 0x00000000, len = 0 +} + +/* For each data/text section two region are defined, a virtual region + and a load region (_LMA suffix).*/ + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("VECTORS_FLASH", flash0); +REGION_ALIAS("VECTORS_FLASH_LMA", flash0); + +/* Flash region to be used for constructors and destructors.*/ +REGION_ALIAS("XTORS_FLASH", flash0); +REGION_ALIAS("XTORS_FLASH_LMA", flash0); + +/* Flash region to be used for code text.*/ +REGION_ALIAS("TEXT_FLASH", flash0); +REGION_ALIAS("TEXT_FLASH_LMA", flash0); + +/* Flash region to be used for read only data.*/ +REGION_ALIAS("RODATA_FLASH", flash0); +REGION_ALIAS("RODATA_FLASH_LMA", flash0); + +/* Flash region to be used for various.*/ +REGION_ALIAS("VARIOUS_FLASH", flash0); +REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); + +/* Flash region to be used for RAM(n) initialization data.*/ +REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts.*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); +REGION_ALIAS("DATA_RAM_LMA", flash0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld + +/* Bootloader reset support */ +_board_magic_reg = ORIGIN(ram0) + 16k; /* this is based off the code within backup.c */ diff --git a/platforms/chibios/bootloader.mk b/platforms/chibios/bootloader.mk index 481241234402..fc898e769936 100644 --- a/platforms/chibios/bootloader.mk +++ b/platforms/chibios/bootloader.mk @@ -93,7 +93,6 @@ ifeq ($(strip $(BOOTLOADER)), kiibohd) endif ifeq ($(strip $(BOOTLOADER)), stm32duino) OPT_DEFS += -DBOOTLOADER_STM32DUINO - MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader BOARD = STM32_F103_STM32DUINO BOOTLOADER_TYPE = stm32duino diff --git a/platforms/chibios/bootloaders/rp2040.c b/platforms/chibios/bootloaders/rp2040.c index bedc00f32ea5..524d13e636f0 100644 --- a/platforms/chibios/bootloaders/rp2040.c +++ b/platforms/chibios/bootloaders/rp2040.c @@ -1,9 +1,10 @@ // Copyright 2022 Stefan Kerkmann // SPDX-License-Identifier: GPL-2.0-or-later -#include "quantum.h" #include "hal.h" #include "bootloader.h" +#include "gpio.h" +#include "wait.h" #include "pico/bootrom.h" #if !defined(RP2040_BOOTLOADER_DOUBLE_TAP_RESET_LED) diff --git a/platforms/chibios/bootloaders/stm32_dfu.c b/platforms/chibios/bootloaders/stm32_dfu.c index f845bf21e921..fba3086e7af6 100644 --- a/platforms/chibios/bootloaders/stm32_dfu.c +++ b/platforms/chibios/bootloaders/stm32_dfu.c @@ -1,4 +1,4 @@ -/* Copyright 2021 QMK +/* Copyright 2021-2023 QMK * * 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 @@ -15,12 +15,17 @@ */ #include "bootloader.h" +#include "util.h" #include #include #include "wait.h" -extern uint32_t __ram0_end__; +#ifndef STM32_BOOTLOADER_RAM_SYMBOL +# define STM32_BOOTLOADER_RAM_SYMBOL __ram0_end__ +#endif + +extern uint32_t STM32_BOOTLOADER_RAM_SYMBOL; #ifndef STM32_BOOTLOADER_DUAL_BANK # define STM32_BOOTLOADER_DUAL_BANK FALSE @@ -72,10 +77,25 @@ void enter_bootloader_mode_if_requested(void) {} /* This code should be checked whether it runs correctly on platforms */ # define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) # define BOOTLOADER_MAGIC 0xDEADBEEF -# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4) +# define MAGIC_ADDR (unsigned long *)(SYMVAL(STM32_BOOTLOADER_RAM_SYMBOL) - 4) + +__attribute__((weak)) void bootloader_marker_enable(void) { + uint32_t *marker = (uint32_t *)MAGIC_ADDR; + *marker = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader +} + +__attribute__((weak)) bool bootloader_marker_active(void) { + const uint32_t *marker = (const uint32_t *)MAGIC_ADDR; + return (*marker == BOOTLOADER_MAGIC) ? true : false; +} + +__attribute__((weak)) void bootloader_marker_disable(void) { + uint32_t *marker = (uint32_t *)MAGIC_ADDR; + *marker = 0; +} __attribute__((weak)) void bootloader_jump(void) { - *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader + bootloader_marker_enable(); NVIC_SystemReset(); } @@ -84,18 +104,44 @@ __attribute__((weak)) void mcu_reset(void) { } void enter_bootloader_mode_if_requested(void) { - unsigned long *check = MAGIC_ADDR; - if (*check == BOOTLOADER_MAGIC) { - *check = 0; + if (bootloader_marker_active()) { + bootloader_marker_disable(); + + struct system_memory_vector_t { + uint32_t stack_top; + void (*entrypoint)(void); + }; + const struct system_memory_vector_t *bootloader = (const struct system_memory_vector_t *)(STM32_BOOTLOADER_ADDRESS); + + __disable_irq(); + +# if defined(QMK_MCU_ARCH_CORTEX_M7) + SCB_DisableDCache(); + SCB_DisableICache(); +# endif + +# if defined(__MPU_PRESENT) && (__MPU_PRESENT == 1U) + ARM_MPU_Disable(); +# endif + + SysTick->CTRL = 0; + SysTick->VAL = 0; + SysTick->LOAD = 0; + + // Clear interrupt enable and interrupt pending registers + for (int i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) { + NVIC->ICER[i] = 0xFFFFFFFF; + NVIC->ICPR[i] = 0xFFFFFFFF; + } + __set_CONTROL(0); - __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS); + __set_MSP(bootloader->stack_top); __enable_irq(); - typedef void (*BootJump_t)(void); - BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4); - boot_jump(); - while (1) - ; + // Jump to bootloader + bootloader->entrypoint(); + while (true) { + } } } #endif diff --git a/platforms/chibios/chibios_config.h b/platforms/chibios/chibios_config.h index 4c8333f07bb3..1f8a7842fe2d 100644 --- a/platforms/chibios/chibios_config.h +++ b/platforms/chibios/chibios_config.h @@ -33,31 +33,49 @@ # define RP2040_PWM_CHANNEL_A 1U # define RP2040_PWM_CHANNEL_B 2U -# define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) +# ifndef BACKLIGHT_PAL_MODE +# define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) +# endif # define BACKLIGHT_PWM_COUNTER_FREQUENCY 1000000 # define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048 -# define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) +# ifndef AUDIO_PWM_PAL_MODE +# define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) +# endif # define AUDIO_PWM_COUNTER_FREQUENCY 500000 # define usb_lld_endpoint_fields -# define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4) -# define I2C1_SDA_PAL_MODE I2C1_SCL_PAL_MODE +# ifndef I2C1_SCL_PAL_MODE +# define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4) +# endif +# ifndef I2C1_SDA_PAL_MODE +# define I2C1_SDA_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4) +# endif # define USE_I2CV1_CONTRIB # if !defined(I2C1_CLOCK_SPEED) # define I2C1_CLOCK_SPEED 400000 # endif -# define SPI_SCK_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) -# define SPI_MOSI_PAL_MODE SPI_SCK_PAL_MODE -# define SPI_MISO_PAL_MODE SPI_SCK_PAL_MODE +# ifndef SPI_SCK_PAL_MODE +# define SPI_SCK_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) +# endif +# ifndef SPI_MOSI_PAL_MODE +# define SPI_MOSI_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) +# endif +# ifndef SPI_MISO_PAL_MODE +# define SPI_MISO_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) +# endif #endif // STM32 compatibility #if defined(MCU_STM32) -# define CPU_CLOCK STM32_SYSCLK +# if defined(STM32_CORE_CK) +# define CPU_CLOCK STM32_CORE_CK +# else +# define CPU_CLOCK STM32_SYSCLK +# endif # if defined(STM32F1XX) # define USE_GPIOV1 diff --git a/platforms/chibios/config.h b/platforms/chibios/config.h new file mode 100644 index 000000000000..006415a5dc52 --- /dev/null +++ b/platforms/chibios/config.h @@ -0,0 +1,7 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#ifndef CORTEX_ENABLE_WFI_IDLE +# define CORTEX_ENABLE_WFI_IDLE TRUE +#endif // CORTEX_ENABLE_WFI_IDLE diff --git a/platforms/chibios/converters/elite_c_to_liatris/pre_converter.mk b/platforms/chibios/converters/elite_c_to_liatris/pre_converter.mk new file mode 100644 index 000000000000..b38823fa5fea --- /dev/null +++ b/platforms/chibios/converters/elite_c_to_liatris/pre_converter.mk @@ -0,0 +1,2 @@ +CONVERTER:=platforms/chibios/converters/elite_c_to_rp2040_ce +ACTIVE_CONVERTER:=rp2040_ce diff --git a/platforms/chibios/converters/promicro_to_blok/converter.mk b/platforms/chibios/converters/promicro_to_blok/converter.mk index 5106e411f4e7..2435dd3407e4 100644 --- a/platforms/chibios/converters/promicro_to_blok/converter.mk +++ b/platforms/chibios/converters/promicro_to_blok/converter.mk @@ -1,6 +1,6 @@ # Boardsource Blok MCU settings for converting AVR projects MCU := RP2040 -BOARD := QMK_PM2040 +BOARD := QMK_BLOK BOOTLOADER := rp2040 # These are defaults based on what has been implemented for RP2040 boards diff --git a/platforms/chibios/converters/promicro_to_liatris/pre_converter.mk b/platforms/chibios/converters/promicro_to_liatris/pre_converter.mk new file mode 100644 index 000000000000..7b3130a5e98c --- /dev/null +++ b/platforms/chibios/converters/promicro_to_liatris/pre_converter.mk @@ -0,0 +1,2 @@ +CONVERTER:=platforms/chibios/converters/promicro_to_rp2040_ce +ACTIVE_CONVERTER:=rp2040_ce diff --git a/platforms/chibios/drivers/audio_dac_additive.c b/platforms/chibios/drivers/audio_dac_additive.c index 68ce13788ec4..22e4fa2608f0 100644 --- a/platforms/chibios/drivers/audio_dac_additive.c +++ b/platforms/chibios/drivers/audio_dac_additive.c @@ -16,8 +16,13 @@ */ #include "audio.h" -#include -#include +#include "gpio.h" +#include +#include "util.h" + +// Need to disable GCC's "tautological-compare" warning for this file, as it causes issues when running `KEEP_INTERMEDIATES=yes`. Corresponding pop at the end of the file. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtautological-compare" /* Audio Driver: DAC @@ -61,7 +66,7 @@ static const dacsample_t dac_buffer_triangle[AUDIO_DAC_BUFFER_SIZE] = { #endif // AUDIO_DAC_SAMPLE_WAVEFORM_TRIANGLE #ifdef AUDIO_DAC_SAMPLE_WAVEFORM_SQUARE static const dacsample_t dac_buffer_square[AUDIO_DAC_BUFFER_SIZE] = { - [0 ... AUDIO_DAC_BUFFER_SIZE / 2 - 1] = 0, // first and + [0 ... AUDIO_DAC_BUFFER_SIZE / 2 - 1] = AUDIO_DAC_OFF_VALUE, // first and [AUDIO_DAC_BUFFER_SIZE / 2 ... AUDIO_DAC_BUFFER_SIZE - 1] = AUDIO_DAC_SAMPLE_MAX, // second half }; #endif // AUDIO_DAC_SAMPLE_WAVEFORM_SQUARE @@ -84,7 +89,7 @@ static dacsample_t dac_buffer_empty[AUDIO_DAC_BUFFER_SIZE] = {AUDIO_DAC_OFF_VALU /* keep track of the sample position for for each frequency */ static float dac_if[AUDIO_MAX_SIMULTANEOUS_TONES] = {0.0}; -static float active_tones_snapshot[AUDIO_MAX_SIMULTANEOUS_TONES] = {0, 0}; +static float active_tones_snapshot[AUDIO_MAX_SIMULTANEOUS_TONES] = {0}; static uint8_t active_tones_snapshot_length = 0; typedef enum { @@ -130,7 +135,7 @@ __attribute__((weak)) uint16_t dac_value_generate(void) { * timer runs with 3*AUDIO_DAC_SAMPLE_RATE; and the DAC callback * is called twice per conversion.*/ - dac_if[i] = fmod(dac_if[i], AUDIO_DAC_BUFFER_SIZE); + dac_if[i] = fmodf(dac_if[i], AUDIO_DAC_BUFFER_SIZE); // Wavetable generation/lookup uint16_t dac_i = (uint16_t)dac_if[i]; @@ -335,3 +340,5 @@ void audio_driver_start(void) { active_tones_snapshot_length = 0; state = OUTPUT_SHOULD_START; } + +#pragma GCC diagnostic pop diff --git a/platforms/chibios/drivers/audio_dac_basic.c b/platforms/chibios/drivers/audio_dac_basic.c index 5f0cbf8f8418..9a3f3fea1f39 100644 --- a/platforms/chibios/drivers/audio_dac_basic.c +++ b/platforms/chibios/drivers/audio_dac_basic.c @@ -16,8 +16,11 @@ */ #include "audio.h" -#include "ch.h" -#include "hal.h" +#include "gpio.h" + +// Need to disable GCC's "tautological-compare" warning for this file, as it causes issues when running `KEEP_INTERMEDIATES=yes`. Corresponding pop at the end of the file. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtautological-compare" /* Audio Driver: DAC @@ -247,3 +250,5 @@ void audio_driver_start(void) { } gptStartContinuous(&AUDIO_STATE_TIMER, 2U); } + +#pragma GCC diagnostic pop diff --git a/platforms/chibios/drivers/audio_pwm_hardware.c b/platforms/chibios/drivers/audio_pwm_hardware.c index 54dac4660582..40d891326fd5 100644 --- a/platforms/chibios/drivers/audio_pwm_hardware.c +++ b/platforms/chibios/drivers/audio_pwm_hardware.c @@ -12,8 +12,7 @@ // function. #include "audio.h" -#include "ch.h" -#include "hal.h" +#include "gpio.h" #if !defined(AUDIO_PIN) # error "Audio feature enabled, but no pin selected - see docs/feature_audio under the ARM PWM settings" diff --git a/platforms/chibios/drivers/audio_pwm_software.c b/platforms/chibios/drivers/audio_pwm_software.c index e01f86ea5265..663a9eca165a 100644 --- a/platforms/chibios/drivers/audio_pwm_software.c +++ b/platforms/chibios/drivers/audio_pwm_software.c @@ -25,8 +25,7 @@ this driver uses the chibios-PWM system to produce a square-wave on any given ou */ #include "audio.h" -#include "ch.h" -#include "hal.h" +#include "gpio.h" #if !defined(AUDIO_PIN) # error "Audio feature enabled, but no pin selected - see docs/feature_audio under the ARM PWM settings" diff --git a/quantum/backlight/backlight_chibios.c b/platforms/chibios/drivers/backlight_pwm.c similarity index 98% rename from quantum/backlight/backlight_chibios.c rename to platforms/chibios/drivers/backlight_pwm.c index 30e95bd5c80d..01e6f71307a4 100644 --- a/quantum/backlight/backlight_chibios.c +++ b/platforms/chibios/drivers/backlight_pwm.c @@ -1,7 +1,7 @@ -#include "quantum.h" #include "backlight.h" +#include "gpio.h" +#include "wait.h" #include -#include "debug.h" // Maximum duty cycle limit #ifndef BACKLIGHT_LIMIT_VAL @@ -13,7 +13,7 @@ # define BACKLIGHT_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL # else // GPIOV2 && GPIOV3 -# define BACKLIGHT_PAL_MODE 5 +# define BACKLIGHT_PAL_MODE 2 # endif #endif diff --git a/quantum/backlight/backlight_timer.c b/platforms/chibios/drivers/backlight_timer.c similarity index 99% rename from quantum/backlight/backlight_timer.c rename to platforms/chibios/drivers/backlight_timer.c index 82fb6a6a83e7..0fabee93b1c8 100644 --- a/quantum/backlight/backlight_timer.c +++ b/platforms/chibios/drivers/backlight_timer.c @@ -1,7 +1,6 @@ -#include "quantum.h" #include "backlight.h" #include "backlight_driver_common.h" -#include "debug.h" +#include "wait.h" #ifndef BACKLIGHT_GPT_DRIVER # define BACKLIGHT_GPT_DRIVER GPTD15 diff --git a/platforms/chibios/drivers/i2c_master.c b/platforms/chibios/drivers/i2c_master.c index 4c7a5daa1712..7c49f9d00594 100644 --- a/platforms/chibios/drivers/i2c_master.c +++ b/platforms/chibios/drivers/i2c_master.c @@ -24,8 +24,10 @@ * STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. Pins B6 and B7 are used * but using any other I2C pins should be trivial. */ -#include "quantum.h" + #include "i2c_master.h" +#include "gpio.h" +#include "chibios_config.h" #include #include #include diff --git a/platforms/chibios/drivers/ps2/ps2_io.c b/platforms/chibios/drivers/ps2/ps2_io.c index 906d85d84840..9eb56d63da2c 100644 --- a/platforms/chibios/drivers/ps2/ps2_io.c +++ b/platforms/chibios/drivers/ps2/ps2_io.c @@ -4,6 +4,7 @@ // chibiOS headers #include "ch.h" #include "hal.h" +#include "gpio.h" /* Check port settings for clock and data line */ #if !(defined(PS2_CLOCK_PIN)) diff --git a/platforms/chibios/drivers/serial.c b/platforms/chibios/drivers/serial.c index 0dd8e71ae823..f087d0c2edf6 100644 --- a/platforms/chibios/drivers/serial.c +++ b/platforms/chibios/drivers/serial.c @@ -2,8 +2,8 @@ * WARNING: be careful changing this code, it is very timing dependent */ -#include "quantum.h" #include "serial.h" +#include "gpio.h" #include "wait.h" #include "synchronization_util.h" diff --git a/platforms/chibios/drivers/serial_protocol.c b/platforms/chibios/drivers/serial_protocol.c index ccaf73282dd2..e0f583ccde65 100644 --- a/platforms/chibios/drivers/serial_protocol.c +++ b/platforms/chibios/drivers/serial_protocol.c @@ -3,10 +3,8 @@ #include -#include "quantum.h" #include "serial.h" #include "serial_protocol.h" -#include "printf.h" #include "synchronization_util.h" static inline bool initiate_transaction(uint8_t transaction_id); diff --git a/platforms/chibios/drivers/serial_usart.c b/platforms/chibios/drivers/serial_usart.c index 6ebbf7c8ca1f..767ef8726fc3 100644 --- a/platforms/chibios/drivers/serial_usart.c +++ b/platforms/chibios/drivers/serial_usart.c @@ -5,6 +5,7 @@ #include "serial_usart.h" #include "serial_protocol.h" #include "synchronization_util.h" +#include "chibios_config.h" #if defined(SERIAL_USART_CONFIG) static QMKSerialConfig serial_config = SERIAL_USART_CONFIG; diff --git a/platforms/chibios/drivers/serial_usart.h b/platforms/chibios/drivers/serial_usart.h index fa062cd736b4..dec8a292e98b 100644 --- a/platforms/chibios/drivers/serial_usart.h +++ b/platforms/chibios/drivers/serial_usart.h @@ -3,7 +3,6 @@ #pragma once -#include "quantum.h" #include "serial.h" #include diff --git a/platforms/chibios/drivers/uart.c b/platforms/chibios/drivers/uart.c index 34f77232b6c8..39a59dd44508 100644 --- a/platforms/chibios/drivers/uart.c +++ b/platforms/chibios/drivers/uart.c @@ -16,8 +16,6 @@ #include "uart.h" -#include "quantum.h" - #if defined(MCU_KINETIS) static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE}; #elif defined(WB32F3G71xx) || defined(WB32FQ95xx) diff --git a/platforms/chibios/drivers/uart.h b/platforms/chibios/drivers/uart.h index e9e3b0855b3f..d1917bfc8006 100644 --- a/platforms/chibios/drivers/uart.h +++ b/platforms/chibios/drivers/uart.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include diff --git a/platforms/chibios/drivers/usbpd_stm32g4.c b/platforms/chibios/drivers/usbpd_stm32g4.c index 0096f22f077c..21b8f6db95a3 100644 --- a/platforms/chibios/drivers/usbpd_stm32g4.c +++ b/platforms/chibios/drivers/usbpd_stm32g4.c @@ -22,8 +22,6 @@ // Initialises the USBPD subsystem __attribute__((weak)) void usbpd_init(void) { - // Disable dead-battery signals - PWR->CR3 |= PWR_CR3_UCPD_DBDIS; // Enable the clock for the UCPD1 peripheral RCC->APB1ENR2 |= RCC_APB1ENR2_UCPD1EN; @@ -46,6 +44,11 @@ __attribute__((weak)) void usbpd_init(void) { CR |= UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk; // Apply the changes UCPD1->CR = CR; + + // Disable dead-battery signals only after UCPD1 is configured to ensure + // that the transition does not go through any intermediate state without + // any pull-down resistance. + PWR->CR3 |= PWR_CR3_UCPD_DBDIS; } // Gets the current state of the USBPD allowance diff --git a/platforms/chibios/drivers/vendor/RP/RP2040/ps2_vendor.c b/platforms/chibios/drivers/vendor/RP/RP2040/ps2_vendor.c new file mode 100644 index 000000000000..d775ec29d59b --- /dev/null +++ b/platforms/chibios/drivers/vendor/RP/RP2040/ps2_vendor.c @@ -0,0 +1,269 @@ +// Copyright 2022 Marek Kraus (@gamelaster) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "hardware/pio.h" +#include "hardware/clocks.h" +#include "ps2.h" +#include "debug.h" + +#if !defined(MCU_RP) +# error PIO Driver is only available for Raspberry Pi 2040 MCUs! +#endif + +#if defined(PS2_ENABLE) +# if defined(PS2_MOUSE_ENABLE) +# if !defined(PS2_MOUSE_USE_REMOTE_MODE) +# define BUFFERED_MODE_ENABLE +# endif +# else // PS2 Keyboard +# define BUFFERED_MODE_ENABLE +# endif +#endif + +#if PS2_DATA_PIN + 1 != PS2_CLOCK_PIN +# error PS/2 Clock pin must be followed by data pin! +#endif + +static inline void pio_serve_interrupt(void); + +#if defined(PS2_PIO_USE_PIO1) +static const PIO pio = pio1; + +OSAL_IRQ_HANDLER(RP_PIO1_IRQ_0_HANDLER) { + OSAL_IRQ_PROLOGUE(); + pio_serve_interrupt(); + OSAL_IRQ_EPILOGUE(); +} +#else +static const PIO pio = pio0; + +OSAL_IRQ_HANDLER(RP_PIO0_IRQ_0_HANDLER) { + OSAL_IRQ_PROLOGUE(); + pio_serve_interrupt(); + OSAL_IRQ_EPILOGUE(); +} +#endif + +#define PS2_WRAP_TARGET 0 +#define PS2_WRAP 20 + +// clang-format off +static const uint16_t ps2_program_instructions[] = { + // .wrap_target + 0x00c7, // 0: jmp pin, 7 + 0xe02a, // 1: set x, 10 + 0x2021, // 2: wait 0 pin, 1 + 0x4001, // 3: in pins, 1 + 0x20a1, // 4: wait 1 pin, 1 + 0x0042, // 5: jmp x--, 2 + 0x0000, // 6: jmp 0 + 0x00e9, // 7: jmp !osre, 9 + 0x0000, // 8: jmp 0 + 0xff81, // 9: set pindirs, 1 [31] + 0xe280, // 10: set pindirs, 0 [2] + 0xe082, // 11: set pindirs, 2 + 0x2021, // 12: wait 0 pin, 1 + 0xe029, // 13: set x, 9 + 0x6081, // 14: out pindirs, 1 + 0x20a1, // 15: wait 1 pin, 1 + 0x2021, // 16: wait 0 pin, 1 + 0x004e, // 17: jmp x--, 14 + 0xe083, // 18: set pindirs, 3 + 0x2021, // 19: wait 0 pin, 1 + 0x20a1, // 20: wait 1 pin, 1 + // .wrap +}; +// clang-format on + +static const struct pio_program ps2_program = { + .instructions = ps2_program_instructions, + .length = 21, + .origin = -1, +}; + +static int state_machine = -1; +static thread_reference_t tx_thread = NULL; + +#define BUFFER_SIZE 32 +static input_buffers_queue_t pio_rx_queue; +static __attribute__((aligned(4))) uint8_t pio_rx_buffer[BQ_BUFFER_SIZE(BUFFER_SIZE, sizeof(uint32_t))]; + +uint8_t ps2_error = PS2_ERR_NONE; + +void pio_serve_interrupt(void) { + uint32_t irqs = pio->ints0; + + if (irqs & (PIO_IRQ0_INTF_SM0_RXNEMPTY_BITS << state_machine)) { + osalSysLockFromISR(); + uint32_t* frame_buffer = (uint32_t*)ibqGetEmptyBufferI(&pio_rx_queue); + if (frame_buffer == NULL) { + osalSysUnlockFromISR(); + return; + } + *frame_buffer = pio_sm_get(pio, state_machine); + ibqPostFullBufferI(&pio_rx_queue, sizeof(uint32_t)); + osalSysUnlockFromISR(); + } + + if (irqs & (PIO_IRQ0_INTF_SM0_TXNFULL_BITS << state_machine)) { + pio_set_irq0_source_enabled(pio, pis_sm0_tx_fifo_not_full + state_machine, false); + osalSysLockFromISR(); + osalThreadResumeI(&tx_thread, MSG_OK); + osalSysUnlockFromISR(); + } +} + +void ps2_host_init(void) { + ibqObjectInit(&pio_rx_queue, false, pio_rx_buffer, sizeof(uint32_t), BUFFER_SIZE, NULL, NULL); + uint pio_idx = pio_get_index(pio); + + hal_lld_peripheral_unreset(pio_idx == 0 ? RESETS_ALLREG_PIO0 : RESETS_ALLREG_PIO1); + + state_machine = pio_claim_unused_sm(pio, true); + if (state_machine < 0) { + dprintln("ERROR: Failed to acquire state machine for PS/2!"); + ps2_error = PS2_ERR_NODATA; + return; + } + + uint offset = pio_add_program(pio, &ps2_program); + + pio_sm_config c = pio_get_default_sm_config(); + sm_config_set_wrap(&c, offset + PS2_WRAP_TARGET, offset + PS2_WRAP); + + // Set pindirs to input (output enable is inverted below) + pio_sm_set_consecutive_pindirs(pio, state_machine, PS2_DATA_PIN, 2, true); + sm_config_set_clkdiv(&c, (float)clock_get_hz(clk_sys) / (200.0f * KHZ)); + sm_config_set_set_pins(&c, PS2_DATA_PIN, 2); + sm_config_set_out_pins(&c, PS2_DATA_PIN, 1); + sm_config_set_out_shift(&c, true, true, 10); + sm_config_set_in_shift(&c, true, true, 11); + sm_config_set_jmp_pin(&c, PS2_CLOCK_PIN); + sm_config_set_in_pins(&c, PS2_DATA_PIN); + + // clang-format off + iomode_t pin_mode = PAL_RP_PAD_IE | + PAL_RP_GPIO_OE | + PAL_RP_PAD_SLEWFAST | + PAL_RP_PAD_DRIVE12 | + // Invert output enable so that pindirs=1 means input + // and indirs=0 means output. This way, out pindirs + // works correctly with the open-drain PS/2 interface. + // Setting pindirs=1 effectively pulls the line high, + // due to the pull-up resistor, while pindirs=0 pulls + // the line low. + PAL_RP_IOCTRL_OEOVER_DRVINVPERI | + (pio_idx == 0 ? PAL_MODE_ALTERNATE_PIO0 : PAL_MODE_ALTERNATE_PIO1); + // clang-format on + + palSetLineMode(PS2_DATA_PIN, pin_mode); + palSetLineMode(PS2_CLOCK_PIN, pin_mode); + + pio_set_irq0_source_enabled(pio, pis_sm0_rx_fifo_not_empty + state_machine, true); + pio_sm_init(pio, state_machine, offset, &c); + +#if defined(PS2_PIO_USE_PIO1) + nvicEnableVector(RP_PIO1_IRQ_0_NUMBER, CORTEX_MAX_KERNEL_PRIORITY); +#else + nvicEnableVector(RP_PIO0_IRQ_0_NUMBER, CORTEX_MAX_KERNEL_PRIORITY); +#endif + + pio_sm_set_enabled(pio, state_machine, true); +} + +static int bit_parity(int x) { + return !__builtin_parity(x); +} + +uint8_t ps2_host_send(uint8_t data) { + uint32_t frame = 0b1000000000; + frame = frame | data; + + if (bit_parity(data)) { + frame = frame | (1 << 8); + } + + pio_sm_put(pio, state_machine, frame); + + msg_t msg = MSG_OK; + osalSysLock(); + while (pio_sm_is_tx_fifo_full(pio, state_machine)) { + pio_set_irq0_source_enabled(pio, pis_sm0_tx_fifo_not_full + state_machine, true); + msg = osalThreadSuspendTimeoutS(&tx_thread, TIME_MS2I(100)); + if (msg < MSG_OK) { + pio_set_irq0_source_enabled(pio, pis_sm0_tx_fifo_not_full + state_machine, false); + ps2_error = PS2_ERR_NODATA; + osalSysUnlock(); + return 0; + } + } + osalSysUnlock(); + + return ps2_host_recv_response(); +} + +static uint8_t ps2_get_data_from_frame(uint32_t frame) { + uint8_t data = (frame >> 22) & 0xFF; + uint32_t start_bit = (frame & 0b00000000001000000000000000000000) ? 1 : 0; + uint32_t parity_bit = (frame & 0b01000000000000000000000000000000) ? 1 : 0; + uint32_t stop_bit = (frame & 0b10000000001000000000000000000000) ? 1 : 0; + + if (start_bit != 0) { + ps2_error = PS2_ERR_STARTBIT1; + return 0; + } + + if (parity_bit != bit_parity(data)) { + ps2_error = PS2_ERR_PARITY; + return 0; + } + + if (stop_bit != 1) { + ps2_error = PS2_ERR_STARTBIT2; + return 0; + } + + return data; +} + +uint8_t ps2_host_recv_response(void) { + uint32_t frame = 0; + msg_t msg = MSG_OK; + + msg = ibqReadTimeout(&pio_rx_queue, (uint8_t*)&frame, sizeof(uint32_t), TIME_MS2I(100)); + if (msg < MSG_OK) { + ps2_error = PS2_ERR_NODATA; + return 0; + } + + return ps2_get_data_from_frame(frame); +} + +#ifdef BUFFERED_MODE_ENABLE + +bool pbuf_has_data(void) { + osalSysLock(); + bool has_data = !ibqIsEmptyI(&pio_rx_queue); + osalSysUnlock(); + return has_data; +} + +uint8_t ps2_host_recv(void) { + uint32_t frame = 0; + msg_t msg = MSG_OK; + + uint8_t has_data = pbuf_has_data(); + if (has_data) { + msg = ibqReadTimeout(&pio_rx_queue, (uint8_t*)&frame, sizeof(uint32_t), TIME_MS2I(100)); + if (msg < MSG_OK) { + ps2_error = PS2_ERR_NODATA; + return 0; + } + } else { + ps2_error = PS2_ERR_NODATA; + } + + return frame != 0 ? ps2_get_data_from_frame(frame) : 0; +} + +#endif diff --git a/platforms/chibios/drivers/vendor/RP/RP2040/serial_vendor.c b/platforms/chibios/drivers/vendor/RP/RP2040/serial_vendor.c index dd4723a086d9..3aa8e1165fac 100644 --- a/platforms/chibios/drivers/vendor/RP/RP2040/serial_vendor.c +++ b/platforms/chibios/drivers/vendor/RP/RP2040/serial_vendor.c @@ -1,11 +1,12 @@ // Copyright 2022 Stefan Kerkmann // SPDX-License-Identifier: GPL-2.0-or-later -#include "quantum.h" #include "serial_usart.h" #include "serial_protocol.h" #include "hardware/pio.h" #include "hardware/clocks.h" +#include "wait.h" +#include "debug.h" #if !defined(MCU_RP) # error PIO Driver is only available for Raspberry Pi 2040 MCUs! diff --git a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c index a46b0991954d..8d59e13bb252 100644 --- a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c +++ b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c @@ -2,13 +2,19 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "ws2812.h" -#include "hardware/timer.h" -#include "hardware/clocks.h" + // Keep this exact include order otherwise we run into naming conflicts between // pico-sdk and rp2040.h which we don't control. -#include "quantum.h" +#include "hardware/timer.h" +#include "hardware/clocks.h" +#include #include "hardware/pio.h" +#include "gpio.h" +#include "debug.h" +#include "wait.h" +#include "util.h" + #if !defined(MCU_RP) # error PIO Driver is only available for Raspberry Pi 2040 MCUs! #endif @@ -185,7 +191,7 @@ bool ws2812_init(void) { (pio_idx == 0 ? PAL_MODE_ALTERNATE_PIO0 : PAL_MODE_ALTERNATE_PIO1); // clang-format on - palSetLineMode(RGB_DI_PIN, rgb_pin_mode); + palSetLineMode(WS2812_DI_PIN, rgb_pin_mode); STATE_MACHINE = pio_claim_unused_sm(pio, true); if (STATE_MACHINE < 0) { @@ -195,11 +201,11 @@ bool ws2812_init(void) { uint offset = pio_add_program(pio, &ws2812_program); - pio_sm_set_consecutive_pindirs(pio, STATE_MACHINE, RGB_DI_PIN, 1, true); + pio_sm_set_consecutive_pindirs(pio, STATE_MACHINE, WS2812_DI_PIN, 1, true); pio_sm_config config = pio_get_default_sm_config(); sm_config_set_wrap(&config, offset + WS2812_WRAP_TARGET, offset + WS2812_WRAP); - sm_config_set_sideset_pins(&config, RGB_DI_PIN); + sm_config_set_sideset_pins(&config, WS2812_DI_PIN); sm_config_set_fifo_join(&config, PIO_FIFO_JOIN_TX); #if defined(WS2812_EXTERNAL_PULLUP) diff --git a/platforms/chibios/drivers/ws2812.c b/platforms/chibios/drivers/ws2812_bitbang.c similarity index 92% rename from platforms/chibios/drivers/ws2812.c rename to platforms/chibios/drivers/ws2812_bitbang.c index 55ac333b1e8f..c55e0f654c29 100644 --- a/platforms/chibios/drivers/ws2812.c +++ b/platforms/chibios/drivers/ws2812_bitbang.c @@ -1,7 +1,7 @@ -#include "quantum.h" #include "ws2812.h" -#include -#include + +#include "gpio.h" +#include "chibios_config.h" /* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */ @@ -53,22 +53,22 @@ void sendByte(uint8_t byte) { // using something like wait_ns(is_one ? T1L : T0L) here throws off timings if (is_one) { // 1 - writePinHigh(RGB_DI_PIN); + writePinHigh(WS2812_DI_PIN); wait_ns(WS2812_T1H); - writePinLow(RGB_DI_PIN); + writePinLow(WS2812_DI_PIN); wait_ns(WS2812_T1L); } else { // 0 - writePinHigh(RGB_DI_PIN); + writePinHigh(WS2812_DI_PIN); wait_ns(WS2812_T0H); - writePinLow(RGB_DI_PIN); + writePinLow(WS2812_DI_PIN); wait_ns(WS2812_T0L); } } } void ws2812_init(void) { - palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); + palSetLineMode(WS2812_DI_PIN, WS2812_OUTPUT_MODE); } // Setleds for standard RGB diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c index c4a591c10b4b..cfee547a822d 100644 --- a/platforms/chibios/drivers/ws2812_pwm.c +++ b/platforms/chibios/drivers/ws2812_pwm.c @@ -1,6 +1,6 @@ #include "ws2812.h" -#include "quantum.h" -#include +#include "gpio.h" +#include "chibios_config.h" /* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */ @@ -308,7 +308,7 @@ void ws2812_init(void) { for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero - palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); + palSetLineMode(WS2812_DI_PIN, WS2812_OUTPUT_MODE); // PWM Configuration //#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config diff --git a/platforms/chibios/drivers/ws2812_spi.c b/platforms/chibios/drivers/ws2812_spi.c index 03ffbd7f82e9..f188576e046c 100644 --- a/platforms/chibios/drivers/ws2812_spi.c +++ b/platforms/chibios/drivers/ws2812_spi.c @@ -1,5 +1,7 @@ -#include "quantum.h" #include "ws2812.h" +#include "gpio.h" +#include "util.h" +#include "chibios_config.h" /* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */ @@ -136,7 +138,7 @@ static void set_led_color_rgb(LED_TYPE color, int pos) { } void ws2812_init(void) { - palSetLineMode(RGB_DI_PIN, WS2812_MOSI_OUTPUT_MODE); + palSetLineMode(WS2812_DI_PIN, WS2812_MOSI_OUTPUT_MODE); #ifdef WS2812_SPI_SCK_PIN palSetLineMode(WS2812_SPI_SCK_PIN, WS2812_SCK_OUTPUT_MODE); @@ -150,8 +152,8 @@ void ws2812_init(void) { WS2812_SPI_BUFFER_MODE, # endif NULL, // end_cb - PAL_PORT(RGB_DI_PIN), - PAL_PAD(RGB_DI_PIN), + PAL_PORT(WS2812_DI_PIN), + PAL_PAD(WS2812_DI_PIN), # if defined(WB32F3G71xx) || defined(WB32FQ95xx) 0, 0, @@ -170,8 +172,8 @@ void ws2812_init(void) { # endif NULL, // data_cb NULL, // error_cb - PAL_PORT(RGB_DI_PIN), - PAL_PAD(RGB_DI_PIN), + PAL_PORT(WS2812_DI_PIN), + PAL_PAD(WS2812_DI_PIN), WS2812_SPI_DIVISOR_CR1_BR_X, 0 #endif diff --git a/platforms/chibios/drivers/wt_rgb_backlight.c b/platforms/chibios/drivers/wt_rgb_backlight.c index 1cd00ae41f6d..6c57416622cb 100644 --- a/platforms/chibios/drivers/wt_rgb_backlight.c +++ b/platforms/chibios/drivers/wt_rgb_backlight.c @@ -1771,36 +1771,36 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led ) void backlight_update_pwm_buffers(void) { #if defined(RGB_BACKLIGHT_M6_B) - IS31FL3218_update_pwm_buffers(); + is31fl3218_update_pwm_buffers(); #elif defined(RGB_BACKLIGHT_PORTICO75) - IS31FL3741_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3741_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3741_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3741_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_M10_C) - IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_HS60) - IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_KW_MEGA) - IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_pwm_buffers( ISSI_ADDR_2, 1 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3733_update_pwm_buffers( ISSI_ADDR_2, 1 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_2, 1 ); #elif defined(RGB_BACKLIGHT_NEBULA12) - IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_U80_A) static uint8_t driver = 0; switch ( driver ) { case 0: - IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); break; case 1: - IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); break; case 2: - IS31FL3731_update_pwm_buffers( ISSI_ADDR_3, 2 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_3, 2 ); break; } if ( ++driver > 2 ) @@ -1808,31 +1808,31 @@ void backlight_update_pwm_buffers(void) driver = 0; } #else - IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); - IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); - IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); + is31fl3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_2, 1 ); #endif } void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { #if defined(RGB_BACKLIGHT_M6_B) - IS31FL3218_set_color( index, red, green, blue ); + is31fl3218_set_color( index, red, green, blue ); #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA) - IS31FL3733_set_color( index, red, green, blue ); + is31fl3733_set_color( index, red, green, blue ); #elif defined (RGB_BACKLIGHT_PORTICO) - IS31FL3731_set_color( index, red, green, blue ); + is31fl3731_set_color( index, red, green, blue ); #elif defined (RGB_BACKLIGHT_PORTICO75) - IS31FL3741_set_color( index, red, green, blue ); + is31fl3741_set_color( index, red, green, blue ); #elif defined(RGB_BACKLIGHT_NK87) // This is done to avoid indicator LEDs being set if (( index != 63+64-1 ) && ( index != 48+64-1 )) { - IS31FL3733_set_color( index, red, green, blue ); + is31fl3733_set_color( index, red, green, blue ); } #elif defined(RGB_BACKLIGHT_DAWN60) if( index < RGB_MATRIX_LED_COUNT ) { - IS31FL3731_set_color( index, red, green, blue ); + is31fl3731_set_color( index, red, green, blue ); } else { g_ws2812_leds[index - RGB_MATRIX_LED_COUNT].r = red; g_ws2812_leds[index - RGB_MATRIX_LED_COUNT].g = green; @@ -1840,38 +1840,38 @@ void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL); } #else - IS31FL3731_set_color( index, red, green, blue ); + is31fl3731_set_color( index, red, green, blue ); #endif } void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { #if defined(RGB_BACKLIGHT_M6_B) - IS31FL3218_set_color_all( red, green, blue ); + is31fl3218_set_color_all( red, green, blue ); #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA) // This is done to avoid indicator LEDs being set for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) { - IS31FL3733_set_color(i, red, green, blue); + is31fl3733_set_color(i, red, green, blue); } #elif defined (RGB_BACKLIGHT_PORTICO) // This is done to avoid indicator LEDs being set for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) { - IS31FL3731_set_color(i, red, green, blue); + is31fl3731_set_color(i, red, green, blue); } #elif defined (RGB_BACKLIGHT_PORTICO75) // This is done to avoid indicator LEDs being set for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) { - IS31FL3741_set_color(i, red, green, blue); + is31fl3741_set_color(i, red, green, blue); } #elif defined(RGB_BACKLIGHT_NK87) // This is done to avoid indicator LEDs being set for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) { if (( i != 63+64-1 ) && ( i != 48+64-1 )) { - IS31FL3733_set_color(i, red, green, blue); + is31fl3733_set_color(i, red, green, blue); } } #elif defined(RGB_BACKLIGHT_DAWN60) - IS31FL3731_set_color_all( red, green, blue ); + is31fl3731_set_color_all( red, green, blue ); for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) { g_ws2812_leds[i].r = red; g_ws2812_leds[i].g = green; @@ -1879,7 +1879,7 @@ void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) } ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL); #else - IS31FL3731_set_color_all( red, green, blue ); + is31fl3731_set_color_all( red, green, blue ); #endif } @@ -2914,9 +2914,9 @@ void backlight_init_drivers(void) i2c_init(); #if defined(RGB_BACKLIGHT_M6_B) - IS31FL3218_init(); + is31fl3218_init(); #elif defined(RGB_BACKLIGHT_HS60) - IS31FL3733_init( ISSI_ADDR_1, 0 ); + is31fl3733_init( ISSI_ADDR_1, 0 ); for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { @@ -2932,28 +2932,28 @@ void backlight_init_drivers(void) ( index == 61-1 ) ); //LA61 #endif // This only caches it for later - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3733_set_led_control_register( index, enabled, enabled, enabled ); } // This actually updates the LED drivers - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_NK65) - IS31FL3733_init( ISSI_ADDR_1, 0 ); - IS31FL3733_init( ISSI_ADDR_2, 0 ); + is31fl3733_init( ISSI_ADDR_1, 0 ); + is31fl3733_init( ISSI_ADDR_2, 0 ); for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { bool enabled = !( ( index == 61-1 ) || //LA61 ( index > 6+64-1 ) ); //LB7-LB64 // This only caches it for later - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3733_set_led_control_register( index, enabled, enabled, enabled ); } - IS31FL3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators + is31fl3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators // This actually updates the LED drivers - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_2, 1 ); #elif defined(RGB_BACKLIGHT_NK87) - IS31FL3733_init( ISSI_ADDR_1, 0 ); - IS31FL3733_init( ISSI_ADDR_2, 0 ); + is31fl3733_init( ISSI_ADDR_1, 0 ); + is31fl3733_init( ISSI_ADDR_2, 0 ); for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { @@ -2975,59 +2975,59 @@ void backlight_init_drivers(void) ( index == 58+64-1 ) || ( index == 62+64-1 ) ); // This only caches it for later - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3733_set_led_control_register( index, enabled, enabled, enabled ); } - IS31FL3733_set_led_control_register( 48+64-1, 0, 0, 1 ); //Enable LB48 blue enable for indicators + is31fl3733_set_led_control_register( 48+64-1, 0, 0, 1 ); //Enable LB48 blue enable for indicators // This actually updates the LED drivers - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_2, 1 ); #elif defined(RGB_BACKLIGHT_NEBULA68) - IS31FL3733_init( ISSI_ADDR_1, 0 ); - IS31FL3733_init( ISSI_ADDR_2, 0 ); + is31fl3733_init( ISSI_ADDR_1, 0 ); + is31fl3733_init( ISSI_ADDR_2, 0 ); for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { bool enabled = !( ( index == 61-1 ) || //LA61 ( index > 5+64-1 ) ); //LB6-LB64 // This only caches it for later - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3733_set_led_control_register( index, enabled, enabled, enabled ); } // This actually updates the LED drivers - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_2, 1 ); #elif defined(RGB_BACKLIGHT_PORTICO75) - IS31FL3741_init( ISSI_ADDR_1 ); + is31fl3741_init( ISSI_ADDR_1 ); bool enabled = true; for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { - IS31FL3741_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3741_set_led_control_register( index, enabled, enabled, enabled ); } // This actually updates the LED drivers - IS31FL3741_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3741_update_led_control_registers( ISSI_ADDR_1, 0 ); #elif defined(RGB_BACKLIGHT_KW_MEGA) - IS31FL3733_init( ISSI_ADDR_1, 0 ); - IS31FL3733_init( ISSI_ADDR_2, 0 ); + is31fl3733_init( ISSI_ADDR_1, 0 ); + is31fl3733_init( ISSI_ADDR_2, 0 ); for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ ) { bool enabled = !( ( index == 61-1 ) || //LA61 ( index > 6+64-1 ) ); //LB7-LB64 // This only caches it for later - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3733_set_led_control_register( index, enabled, enabled, enabled ); } // This actually updates the LED drivers - IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3733_update_led_control_registers( ISSI_ADDR_2, 1 ); #else // Init the #1 driver - IS31FL3731_init( ISSI_ADDR_1 ); + is31fl3731_init( ISSI_ADDR_1 ); // Init the #2 driver (if used) #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C) - IS31FL3731_init( ISSI_ADDR_2 ); + is31fl3731_init( ISSI_ADDR_2 ); #endif // Init the #3 driver (if used) #if defined(RGB_BACKLIGHT_U80_A) - IS31FL3731_init( ISSI_ADDR_3 ); + is31fl3731_init( ISSI_ADDR_3 ); #endif // Experimental feature, not in configuration yet @@ -3156,16 +3156,16 @@ void backlight_init_drivers(void) bool enabled = true; #endif // This only caches it for later - IS31FL3731_set_led_control_register( index, enabled, enabled, enabled ); + is31fl3731_set_led_control_register( index, enabled, enabled, enabled ); } // This actually updates the LED drivers // TODO: refactor this to use DRIVER_COUNT - IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_1, 0 ); #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C) - IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_2, 1 ); #endif #if defined(RGB_BACKLIGHT_U80_A) - IS31FL3731_update_led_control_registers( ISSI_ADDR_3, 2 ); + is31fl3731_update_led_control_registers( ISSI_ADDR_3, 2 ); #endif #endif @@ -3399,11 +3399,11 @@ void backlight_test_led( uint8_t index, bool red, bool green, bool blue ) { if ( i == index ) { - IS31FL3731_set_led_control_register( i, red, green, blue ); + is31fl3731_set_led_control_register( i, red, green, blue ); } else { - IS31FL3731_set_led_control_register( i, false, false, false ); + is31fl3731_set_led_control_register( i, false, false, false ); } } } diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk index ac842e8d62cd..525f177f9ebb 100644 --- a/platforms/chibios/flash.mk +++ b/platforms/chibios/flash.mk @@ -42,15 +42,7 @@ dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter $(call EXEC_DFU_UTIL) define EXEC_UF2_UTIL_DEPLOY - if ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; then \ - printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\ - sleep $(BOOTLOADER_RETRY_TIME) ;\ - while ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; do \ - printf "." ;\ - sleep $(BOOTLOADER_RETRY_TIME) ;\ - done ;\ - printf "\n" ;\ - fi + $(UF2CONV) --wait --deploy $(BUILD_DIR)/$(TARGET).uf2 endef # TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS diff --git a/platforms/chibios/mcu_selection.mk b/platforms/chibios/mcu_selection.mk index 6b6488466b68..5122ed4634e4 100644 --- a/platforms/chibios/mcu_selection.mk +++ b/platforms/chibios/mcu_selection.mk @@ -273,11 +273,7 @@ ifneq ($(findstring STM32F103, $(MCU)),) # Linker script to use # - it should exist either in /os/common/startup/ARMCMx/compilers/GCC/ld/ # or /ld/ - ifeq ($(strip $(BOOTLOADER)), uf2boot) - MCU_LDSCRIPT ?= STM32F103xB_uf2boot - else - MCU_LDSCRIPT ?= STM32F103x8 - endif + MCU_LDSCRIPT ?= STM32F103x8 # Startup code to use # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ @@ -311,11 +307,7 @@ ifneq ($(findstring STM32F303, $(MCU)),) # Linker script to use # - it should exist either in /os/common/startup/ARMCMx/compilers/GCC/ld/ # or /ld/ - ifeq ($(strip $(BOOTLOADER)), tinyuf2) - MCU_LDSCRIPT ?= STM32F303xC_tinyuf2 - else - MCU_LDSCRIPT ?= STM32F303xC - endif + MCU_LDSCRIPT ?= STM32F303xC # Startup code to use # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ @@ -352,11 +344,7 @@ ifneq ($(findstring STM32F401, $(MCU)),) # Linker script to use # - it should exist either in /os/common/startup/ARMCMx/compilers/GCC/ld/ # or /ld/ - ifeq ($(strip $(BOOTLOADER)), tinyuf2) - MCU_LDSCRIPT ?= STM32F401xC_tinyuf2 - else - MCU_LDSCRIPT ?= STM32F401xC - endif + MCU_LDSCRIPT ?= STM32F401xC # Startup code to use # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ @@ -373,10 +361,6 @@ ifneq ($(findstring STM32F401, $(MCU)),) # Bootloader address for STM32 DFU STM32_BOOTLOADER_ADDRESS ?= 0x1FFF0000 - - # Revert to legacy wear-leveling driver until ChibiOS's EFL driver is fixed with 128kB and 384kB variants. - EEPROM_DRIVER ?= wear_leveling - WEAR_LEVELING_DRIVER ?= legacy endif ifneq ($(findstring STM32F405, $(MCU)),) @@ -471,11 +455,7 @@ ifneq ($(findstring STM32F411, $(MCU)),) # Linker script to use # - it should exist either in /os/common/startup/ARMCMx/compilers/GCC/ld/ # or /ld/ - ifeq ($(strip $(BOOTLOADER)), tinyuf2) - MCU_LDSCRIPT ?= STM32F411xE_tinyuf2 - else - MCU_LDSCRIPT ?= STM32F411xE - endif + MCU_LDSCRIPT ?= STM32F411xE # Startup code to use # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ @@ -566,6 +546,9 @@ ifneq ($(findstring STM32G431, $(MCU)),) # Bootloader address for STM32 DFU STM32_BOOTLOADER_ADDRESS ?= 0x1FFF0000 + + # Default to transient driver as ChibiOS EFL is currently broken for single-bank G4xx devices + EEPROM_DRIVER ?= transient endif ifneq ($(findstring STM32G474, $(MCU)),) @@ -722,6 +705,45 @@ ifneq (,$(filter $(MCU),STM32L412 STM32L422)) STM32_BOOTLOADER_ADDRESS ?= 0x1FFF0000 endif +ifneq (,$(filter $(MCU),STM32H723 STM32H733)) + # Cortex version + MCU = cortex-m7 + + # ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 + ARMV = 7 + + ## chip/board settings + # - the next two should match the directories in + # /os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # /os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + MCU_FAMILY = STM32 + MCU_SERIES = STM32H7xx + + # Linker script to use + # - it should exist either in /os/common/startup/ARMCMx/compilers/GCC/ld/ + # or /ld/ + MCU_LDSCRIPT ?= STM32H723xG_ITCM64k + + # Startup code to use + # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ + MCU_STARTUP ?= stm32h7xx + + # Board: it should exist either in /os/hal/boards/, + # /boards/, or drivers/boards/ + BOARD ?= GENERIC_STM32_H723XG + + PLATFORM_NAME ?= platform_type2 + + USE_FPU ?= yes + + # UF2 settings + UF2_FAMILY ?= STM32H7 + + # Bootloader address for STM32 DFU + STM32_BOOTLOADER_ADDRESS ?= 0x1FF09800 +endif + ifneq ($(findstring WB32F3G71, $(MCU)),) # Cortex version MCU = cortex-m3 diff --git a/platforms/chibios/platform.mk b/platforms/chibios/platform.mk index fd4c6bd2e571..081b001e6da9 100644 --- a/platforms/chibios/platform.mk +++ b/platforms/chibios/platform.mk @@ -235,6 +235,11 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld)","") LDSCRIPT = $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld)","") LDSCRIPT = $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld +else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld/$(MCU_LDSCRIPT)_$(BOOTLOADER).ld)","") + LDFLAGS += -L$(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld + LDSCRIPT = $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld/$(MCU_LDSCRIPT)_$(BOOTLOADER).ld +else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/common/ld/$(MCU_LDSCRIPT)_$(BOOTLOADER).ld)","") + LDSCRIPT = $(TOP_DIR)/platforms/chibios/boards/common/ld/$(MCU_LDSCRIPT)_$(BOOTLOADER).ld else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld/$(MCU_LDSCRIPT).ld)","") LDFLAGS += -L$(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld LDSCRIPT = $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/ld/$(MCU_LDSCRIPT).ld @@ -427,6 +432,15 @@ else endif endif +# Extra config.h files for the platform +ifneq ("$(wildcard $(PLATFORM_COMMON_DIR)/vendors/$(MCU_FAMILY)/$(MCU_SERIES)/config.h)","") + CONFIG_H += $(PLATFORM_COMMON_DIR)/vendors/$(MCU_FAMILY)/$(MCU_SERIES)/config.h +endif +ifneq ("$(wildcard $(PLATFORM_COMMON_DIR)/vendors/$(MCU_FAMILY)/config.h)","") + CONFIG_H += $(PLATFORM_COMMON_DIR)/vendors/$(MCU_FAMILY)/config.h +endif +CONFIG_H += $(PLATFORM_COMMON_DIR)/config.h + # Assembler flags ASFLAGS += $(SHARED_ASFLAGS) $(TOOLCHAIN_ASFLAGS) diff --git a/platforms/chibios/sleep_led.c b/platforms/chibios/sleep_led.c index a777d60468bb..a35514bf2e9c 100644 --- a/platforms/chibios/sleep_led.c +++ b/platforms/chibios/sleep_led.c @@ -41,17 +41,20 @@ void sleep_led_timer_callback(void) { uint8_t duration : 2; uint8_t index : 6; } pwm; - } timer = {.row = 0}; + } timer = {.row = 0}; + static led_t led_state = {0}; timer.row++; // LED on if (timer.pwm.count == 0) { - led_set(1 << USB_LED_CAPS_LOCK); + led_state.caps_lock = true; + led_set(led_state.raw); } // LED off if (timer.pwm.count == breathing_table[timer.pwm.index]) { - led_set(0); + led_state.caps_lock = false; + led_set(led_state.raw); } } @@ -190,7 +193,7 @@ void sleep_led_toggle(void) { void sleep_led_init(void) {} void sleep_led_enable(void) { - led_set(1 << USB_LED_CAPS_LOCK); + led_set(2); // Caps Lock } void sleep_led_disable(void) { diff --git a/platforms/chibios/vendors/RP/pico_sdk_shims.c b/platforms/chibios/vendors/RP/pico_sdk_shims.c index 239155c08653..caab4005316c 100644 --- a/platforms/chibios/vendors/RP/pico_sdk_shims.c +++ b/platforms/chibios/vendors/RP/pico_sdk_shims.c @@ -2,7 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include + +extern void chSysHalt(const char *reason) __attribute__((noreturn)); void panic(const char *fmt, ...) { chSysHalt(fmt); diff --git a/platforms/chibios/wait.c b/platforms/chibios/wait.c index 88cb5e6d549d..7fe6d477b8c9 100644 --- a/platforms/chibios/wait.c +++ b/platforms/chibios/wait.c @@ -21,7 +21,7 @@ #ifdef WAIT_US_TIMER void wait_us(uint16_t duration) { - static const GPTConfig gpt_cfg = {1000000, NULL, 0, 0}; /* 1MHz timer, no callback */ + static const GPTConfig gpt_cfg = {.frequency = 1000000}; /* 1MHz timer, no callback */ if (duration == 0) { duration = 1; diff --git a/platforms/common.mk b/platforms/common.mk index da0697e3b097..bbbe71ea1262 100644 --- a/platforms/common.mk +++ b/platforms/common.mk @@ -1,6 +1,6 @@ PLATFORM_COMMON_DIR = $(PLATFORM_PATH)/$(PLATFORM_KEY) -TMK_COMMON_SRC += \ +SRC += \ $(PLATFORM_PATH)/suspend.c \ $(PLATFORM_PATH)/synchronization_util.c \ $(PLATFORM_PATH)/timer.c \ diff --git a/platforms/test/drivers/audio_pwm.h b/platforms/test/drivers/audio_pwm.h new file mode 100644 index 000000000000..9a3fa88cec30 --- /dev/null +++ b/platforms/test/drivers/audio_pwm.h @@ -0,0 +1,16 @@ +// Copyright 2023 Google LLC +// +// 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 diff --git a/platforms/test/drivers/audio_pwm_hardware.c b/platforms/test/drivers/audio_pwm_hardware.c new file mode 100644 index 000000000000..336e4f58449d --- /dev/null +++ b/platforms/test/drivers/audio_pwm_hardware.c @@ -0,0 +1,20 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "audio.h" + +void audio_driver_initialize(void) {} +void audio_driver_start() {} +void audio_driver_stop() {} diff --git a/quantum/action.c b/quantum/action.c index 21dbc29b1f8d..1c86b173c461 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -19,7 +19,6 @@ along with this program. If not, see . #include "host.h" #include "keycode.h" #include "keyboard.h" -#include "keymap.h" #include "mousekey.h" #include "programmable_button.h" #include "command.h" @@ -30,6 +29,8 @@ along with this program. If not, see . #include "action.h" #include "wait.h" #include "keycode_config.h" +#include "debug.h" +#include "quantum.h" #ifdef BACKLIGHT_ENABLE # include "backlight.h" @@ -39,6 +40,10 @@ along with this program. If not, see . # include "pointing_device.h" #endif +#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) && defined(SWAP_HANDS_ENABLE) +# include "encoder.h" +#endif + int tp_buttons; #if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) @@ -61,10 +66,6 @@ __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *reco } #endif -__attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { - return true; -} - /** \brief Called to execute an action. * * FIXME: Needs documentation. @@ -161,6 +162,18 @@ void set_swap_hands_state(size_t index, uint8_t *swap_state, bool on) { } } +void swap_hands_on(void) { + swap_hands = true; +} + +void swap_hands_off(void) { + swap_hands = false; +} + +void swap_hands_toggle(void) { + swap_hands = !swap_hands; +} + bool is_swap_hands_on(void) { return swap_hands; } @@ -171,7 +184,7 @@ bool is_swap_hands_on(void) { */ void process_hand_swap(keyevent_t *event) { keypos_t pos = event->key; - if (pos.row < MATRIX_ROWS && pos.col < MATRIX_COLS) { + if (IS_KEYEVENT(*event) && pos.row < MATRIX_ROWS && pos.col < MATRIX_COLS) { static uint8_t matrix_swap_state[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)]; size_t index = (size_t)(pos.row * MATRIX_COLS) + pos.col; bool do_swap = should_swap_hands(index, matrix_swap_state, event->pressed); @@ -184,7 +197,7 @@ void process_hand_swap(keyevent_t *event) { } } # ifdef ENCODER_MAP_ENABLE - else if (pos.row == KEYLOC_ENCODER_CW || pos.row == KEYLOC_ENCODER_CCW) { + else if (IS_ENCODEREVENT(*event) && (pos.row == KEYLOC_ENCODER_CW || pos.row == KEYLOC_ENCODER_CCW)) { static uint8_t encoder_swap_state[((NUM_ENCODERS) + (CHAR_BIT)-1) / (CHAR_BIT)]; size_t index = pos.col; bool do_swap = should_swap_hands(index, encoder_swap_state, event->pressed); @@ -226,6 +239,10 @@ __attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {} * FIXME: Needs documentation. */ void process_record_tap_hint(keyrecord_t *record) { + if (!IS_KEYEVENT(record->event)) { + return; + } + action_t action = layer_switch_get_action(record->event.key); switch (action.kind.id) { @@ -268,7 +285,7 @@ void process_record(keyrecord_t *record) { } void process_record_handler(keyrecord_t *record) { -#ifdef COMBO_ENABLE +#if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE) action_t action; if (record->keycode) { action = action_for_keycode(record->keycode); @@ -435,39 +452,32 @@ void process_action(keyrecord_t *record, action_t action) { } else { if (event.pressed) { if (tap_count == 0) { + // Not a tap, but a hold: register the held mod ac_dprintf("MODS_TAP: Oneshot: 0\n"); - register_mods(mods | get_oneshot_mods()); + register_mods(mods); } else if (tap_count == 1) { ac_dprintf("MODS_TAP: Oneshot: start\n"); - set_oneshot_mods(mods | get_oneshot_mods()); + add_oneshot_mods(mods); # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 } else if (tap_count == ONESHOT_TAP_TOGGLE) { ac_dprintf("MODS_TAP: Toggling oneshot"); register_mods(mods); - clear_oneshot_mods(); - set_oneshot_locked_mods(mods | get_oneshot_locked_mods()); + del_oneshot_mods(mods); + add_oneshot_locked_mods(mods); # endif - } else { - register_mods(mods | get_oneshot_mods()); } } else { if (tap_count == 0) { - clear_oneshot_mods(); + // Release hold: unregister the held mod and its variants unregister_mods(mods); - } else if (tap_count == 1) { - // Retain Oneshot mods + del_oneshot_mods(mods); + del_oneshot_locked_mods(mods); # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 - if (mods & get_mods()) { - unregister_mods(mods); - clear_oneshot_mods(); - set_oneshot_locked_mods(~mods & get_oneshot_locked_mods()); - } - } else if (tap_count == ONESHOT_TAP_TOGGLE) { - // Toggle Oneshot Layer -# endif - } else { + } else if (tap_count == 1 && (mods & get_mods())) { unregister_mods(mods); - clear_oneshot_mods(); + del_oneshot_mods(mods); + del_oneshot_locked_mods(mods); +# endif } } } @@ -487,7 +497,7 @@ void process_action(keyrecord_t *record, action_t action) { default: if (event.pressed) { if (tap_count > 0) { -# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) +# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY if ( # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY get_hold_on_other_key_press(get_event_keycode(record->event, false), record) && @@ -518,6 +528,13 @@ void process_action(keyrecord_t *record, action_t action) { unregister_code(action.key.code); } else { ac_dprintf("MODS_TAP: No tap: add_mods\n"); +# if defined(RETRO_TAPPING) && defined(DUMMY_MOD_NEUTRALIZER_KEYCODE) + // Send a dummy keycode to neutralize flashing modifiers + // if the key was held and then released with no interruptions. + if (retro_tapping_counter == 2) { + neutralize_flashing_modifiers(get_mods()); + } +# endif unregister_mods(mods); } } @@ -872,7 +889,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is on - if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; + if (host_keyboard_led_state().caps_lock) return; # endif add_key(KC_CAPS_LOCK); send_keyboard_report(); @@ -882,7 +899,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; + if (host_keyboard_led_state().num_lock) return; # endif add_key(KC_NUM_LOCK); send_keyboard_report(); @@ -892,7 +909,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; + if (host_keyboard_led_state().scroll_lock) return; # endif add_key(KC_SCROLL_LOCK); send_keyboard_report(); @@ -942,7 +959,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is off - if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; + if (!host_keyboard_led_state().caps_lock) return; # endif add_key(KC_CAPS_LOCK); send_keyboard_report(); @@ -951,7 +968,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; + if (!host_keyboard_led_state().num_lock) return; # endif add_key(KC_NUM_LOCK); send_keyboard_report(); @@ -960,7 +977,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; + if (!host_keyboard_led_state().scroll_lock) return; # endif add_key(KC_SCROLL_LOCK); send_keyboard_report(); @@ -1100,7 +1117,7 @@ bool is_tap_record(keyrecord_t *record) { return false; } -#ifdef COMBO_ENABLE +#if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE) action_t action; if (record->keycode) { action = action_for_keycode(record->keycode); diff --git a/quantum/action.h b/quantum/action.h index 8ef6db6781ad..d5b15c6f1732 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -50,7 +50,7 @@ typedef struct { #ifndef NO_ACTION_TAPPING tap_t tap; #endif -#ifdef COMBO_ENABLE +#if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE) uint16_t keycode; #endif } keyrecord_t; @@ -84,6 +84,18 @@ typedef uint32_t swap_state_row_t; # error "MATRIX_COLS: invalid value" # endif +/** + * @brief Enable swap hands + */ +void swap_hands_on(void); +/** + * @brief Disable swap hands + */ +void swap_hands_off(void); +/** + * @brief Toggle swap hands enable state + */ +void swap_hands_toggle(void); /** * @brief Get the swap hands enable state * @@ -91,6 +103,7 @@ typedef uint32_t swap_state_row_t; * @return false */ bool is_swap_hands_on(void); + void process_hand_swap(keyevent_t *record); #endif diff --git a/quantum/action_code.h b/quantum/action_code.h index 58d929016d63..d9a575b51838 100644 --- a/quantum/action_code.h +++ b/quantum/action_code.h @@ -17,6 +17,8 @@ along with this program. If not, see . #pragma once +#include "modifiers.h" + /** \brief Action codes * * 16bit code: action_kind(4bit) + action_parameter(12bit) @@ -160,28 +162,6 @@ typedef union { #define ACTION_TRANSPARENT 1 #define ACTION(kind, param) ((kind) << 12 | (param)) -/** \brief Key Actions - * - * Mod bits: 43210 - * bit 0 ||||+- Control - * bit 1 |||+-- Shift - * bit 2 ||+--- Alt - * bit 3 |+---- Gui - * bit 4 +----- LR flag(Left:0, Right:1) - */ -enum mods_bit { - MOD_LCTL = 0x01, - MOD_LSFT = 0x02, - MOD_LALT = 0x04, - MOD_LGUI = 0x08, - MOD_RCTL = 0x11, - MOD_RSFT = 0x12, - MOD_RALT = 0x14, - MOD_RGUI = 0x18, -}; -#define MOD_HYPR (MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI) -#define MOD_MEH (MOD_LCTL | MOD_LSFT | MOD_LALT) - enum mods_codes { MODS_ONESHOT = 0x00, MODS_TAP_TOGGLE = 0x01, diff --git a/quantum/action_layer.c b/quantum/action_layer.c index 00abbc83e630..df15835db702 100644 --- a/quantum/action_layer.c +++ b/quantum/action_layer.c @@ -5,8 +5,8 @@ #endif #include "keyboard.h" -#include "keymap.h" #include "action.h" +#include "encoder.h" #include "util.h" #include "action_layer.h" diff --git a/quantum/action_layer.h b/quantum/action_layer.h index ff783bb3e7fc..a2410d49a5ea 100644 --- a/quantum/action_layer.h +++ b/quantum/action_layer.h @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include "keyboard.h" #include "action.h" +#include "bitwise.h" #ifdef DYNAMIC_KEYMAP_ENABLE # ifndef DYNAMIC_KEYMAP_LAYER_COUNT diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index 5a38bf96e335..f94e5e6f693c 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c @@ -11,20 +11,14 @@ # if defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY) # error "IGNORE_MOD_TAP_INTERRUPT_PER_KEY has been removed; the code needs to be ported to use HOLD_ON_OTHER_KEY_PRESS_PER_KEY instead." -# elif !defined(IGNORE_MOD_TAP_INTERRUPT) -# if !defined(PERMISSIVE_HOLD) && !defined(PERMISSIVE_HOLD_PER_KEY) && !defined(HOLD_ON_OTHER_KEY_PRESS) && !defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) -# pragma message "The default behavior of mod-taps will change to mimic IGNORE_MOD_TAP_INTERRUPT in the future.\nIf you wish to keep the old default behavior of mod-taps, please use HOLD_ON_OTHER_KEY_PRESS." -# endif +# elif defined(IGNORE_MOD_TAP_INTERRUPT) +# error "IGNORE_MOD_TAP_INTERRUPT is no longer necessary as it is now the default behavior of mod-tap keys. Please remove it from your config." # endif -# define IS_TAPPING() IS_EVENT(tapping_key.event) -# define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) -# define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) -# define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) # ifndef COMBO_ENABLE -# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key))) +# define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key))) # else -# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) +# define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) # endif # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_TAPPING_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) # define WITHIN_QUICK_TAP_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_QUICK_TAP_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) @@ -96,7 +90,7 @@ void action_tapping_process(keyrecord_t record) { ac_dprintf("OVERFLOW: CLEAR ALL STATES\n"); clear_keyboard(); waiting_buffer_clear(); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; } } @@ -123,7 +117,7 @@ void action_tapping_process(keyrecord_t record) { * conditional uses of it are hidden inside macros named TAP_... */ # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) -# define TAP_DEFINE_KEYCODE uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) +# define TAP_DEFINE_KEYCODE const uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) # else # define TAP_DEFINE_KEYCODE # endif @@ -162,12 +156,6 @@ void action_tapping_process(keyrecord_t record) { # define TAP_GET_HOLD_ON_OTHER_KEY_PRESS false # endif -# if defined(IGNORE_MOD_TAP_INTERRUPT) -# define TAP_GET_IGNORE_MOD_TAP_INTERRUPT true -# else -# define TAP_GET_IGNORE_MOD_TAP_INTERRUPT false -# endif - /** \brief Tapping * * Rule: Tap key is typed(pressed and released) within TAPPING_TERM. @@ -175,12 +163,39 @@ void action_tapping_process(keyrecord_t record) { */ /* return true when key event is processed or consumed. */ bool process_tapping(keyrecord_t *keyp) { - keyevent_t event = keyp->event; + const keyevent_t event = keyp->event; + + // state machine is in the "reset" state, no tapping key is to be + // processed + if (IS_NOEVENT(tapping_key.event)) { + if (!IS_EVENT(event)) { + // early return for tick events + } else if (event.pressed && is_tap_record(keyp)) { + // the currently pressed key is a tapping key, therefore transition + // into the "pressed" tapping key state + ac_dprintf("Tapping: Start(Press tap key).\n"); + tapping_key = *keyp; + process_record_tap_hint(&tapping_key); + waiting_buffer_scan_tap(); + debug_tapping_key(); + } else { + // the current key is just a regular key, pass it on for regular + // processing + process_record(keyp); + } + + return true; + } + TAP_DEFINE_KEYCODE; - // if tapping - if (IS_TAPPING_PRESSED()) { + // process "pressed" tapping key state + if (tapping_key.event.pressed) { if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { + if (IS_NOEVENT(event)) { + // early return for tick events + return true; + } if (tapping_key.tap.count == 0) { if (IS_TAPPING_RECORD(keyp) && !event.pressed) { # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) @@ -204,7 +219,7 @@ bool process_tapping(keyrecord_t *keyp) { // clang-format off else if ( ( - IS_RELEASED(event) && waiting_buffer_typed(event) && + !event.pressed && waiting_buffer_typed(event) && TAP_GET_PERMISSIVE_HOLD ) // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT @@ -217,13 +232,12 @@ bool process_tapping(keyrecord_t *keyp) { (TAP_IS_MT && TAP_GET_HOLD_ON_OTHER_KEY_PRESS) ) ) - // Makes Retro Shift ignore [IGNORE_MOD_TAP_INTERRUPT's - // effects on nested taps for MTs and the default - // behavior of LTs] below TAPPING_TERM or RETRO_SHIFT. + // Makes Retro Shift ignore the default behavior of + // MTs and LTs on nested taps below TAPPING_TERM or RETRO_SHIFT || ( TAP_IS_RETRO && (event.key.col != tapping_key.event.key.col || event.key.row != tapping_key.event.key.row) - && IS_RELEASED(event) && waiting_buffer_typed(event) + && !event.pressed && waiting_buffer_typed(event) ) ) ) @@ -231,7 +245,7 @@ bool process_tapping(keyrecord_t *keyp) { // clang-format on ac_dprintf("Tapping: End. No tap. Interfered by typing key\n"); process_record(&tapping_key); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; debug_tapping_key(); // enqueue return false; @@ -240,7 +254,7 @@ bool process_tapping(keyrecord_t *keyp) { * Without this unexpected repeating will occur with having fast repeating setting * https://github.com/tmk/tmk_keyboard/issues/60 */ - else if (IS_RELEASED(event) && !waiting_buffer_typed(event)) { + else if (!event.pressed && !waiting_buffer_typed(event)) { // Modifier/Layer should be retained till end of this tapping. action_t action = layer_switch_get_action(event.key); switch (action.kind.id) { @@ -276,7 +290,7 @@ bool process_tapping(keyrecord_t *keyp) { if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS) { ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); process_record(&tapping_key); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; debug_tapping_key(); // enqueue return false; @@ -304,6 +318,7 @@ bool process_tapping(keyrecord_t *keyp) { .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, + .event.type = tapping_key.event.type, # ifdef COMBO_ENABLE .keycode = tapping_key.keycode, # endif @@ -316,9 +331,7 @@ bool process_tapping(keyrecord_t *keyp) { debug_tapping_key(); return true; } else { - if (IS_EVENT(event)) { - ac_dprintf("Tapping: key event while last tap(>0).\n"); - } + ac_dprintf("Tapping: key event while last tap(>0).\n"); process_record(keyp); return true; } @@ -331,15 +344,18 @@ bool process_tapping(keyrecord_t *keyp) { debug_event(event); ac_dprintf("\n"); process_record(&tapping_key); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; debug_tapping_key(); return false; } else { + if (IS_NOEVENT(event)) { + return true; + } if (IS_TAPPING_RECORD(keyp) && !event.pressed) { ac_dprintf("Tapping: End. last timeout tap release(>0)."); keyp->tap = tapping_key.tap; process_record(keyp); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; return true; } else if (is_tap_record(keyp) && event.pressed) { if (tapping_key.tap.count > 1) { @@ -350,6 +366,7 @@ bool process_tapping(keyrecord_t *keyp) { .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, + .event.type = tapping_key.event.type, # ifdef COMBO_ENABLE .keycode = tapping_key.keycode, # endif @@ -362,16 +379,20 @@ bool process_tapping(keyrecord_t *keyp) { debug_tapping_key(); return true; } else { - if (IS_EVENT(event)) { - ac_dprintf("Tapping: key event while last timeout tap(>0).\n"); - } + ac_dprintf("Tapping: key event while last timeout tap(>0).\n"); process_record(keyp); return true; } } } - } else if (IS_TAPPING_RELEASED()) { + } + // process "released" tapping key state + else { if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { + if (IS_NOEVENT(event)) { + // early return for tick events + return true; + } if (event.pressed) { if (IS_TAPPING_RECORD(keyp)) { if (WITHIN_QUICK_TAP_TERM(event) && !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { @@ -402,35 +423,20 @@ bool process_tapping(keyrecord_t *keyp) { return true; } } else { - if (IS_EVENT(event)) ac_dprintf("Tapping: other key just after tap.\n"); + ac_dprintf("Tapping: other key just after tap.\n"); process_record(keyp); return true; } } else { - // FIX: process_action here? - // timeout. no sequential tap. + // Timeout - reset state machine. ac_dprintf("Tapping: End(Timeout after releasing last tap): "); debug_event(event); ac_dprintf("\n"); - tapping_key = (keyrecord_t){}; + tapping_key = (keyrecord_t){0}; debug_tapping_key(); return false; } } - // not tapping state - else { - if (event.pressed && is_tap_record(keyp)) { - ac_dprintf("Tapping: Start(Press tap key).\n"); - tapping_key = *keyp; - process_record_tap_hint(&tapping_key); - waiting_buffer_scan_tap(); - debug_tapping_key(); - return true; - } else { - process_record(keyp); - return true; - } - } } /** \brief Waiting buffer enq @@ -493,15 +499,18 @@ __attribute__((unused)) bool waiting_buffer_has_anykey_pressed(void) { * FIXME: Needs docs */ void waiting_buffer_scan_tap(void) { - // tapping already is settled - if (tapping_key.tap.count > 0) return; - // invalid state: tapping_key released && tap.count == 0 - if (!tapping_key.event.pressed) return; + // early return if: + // - tapping already is settled + // - invalid state: tapping_key released && tap.count == 0 + if ((tapping_key.tap.count > 0) || !tapping_key.event.pressed) { + return; + } for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { - if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && !waiting_buffer[i].event.pressed && WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { - tapping_key.tap.count = 1; - waiting_buffer[i].tap.count = 1; + keyrecord_t *candidate = &waiting_buffer[i]; + if (IS_EVENT(candidate->event) && KEYEQ(candidate->event.key, tapping_key.event.key) && !candidate->event.pressed && WITHIN_TAPPING_TERM(candidate->event)) { + tapping_key.tap.count = 1; + candidate->tap.count = 1; process_record(&tapping_key); ac_dprintf("waiting_buffer_scan_tap: found at [%u]\n", i); diff --git a/quantum/action_tapping.h b/quantum/action_tapping.h index 6099d80d6d05..6b518b829880 100644 --- a/quantum/action_tapping.h +++ b/quantum/action_tapping.h @@ -43,7 +43,6 @@ void action_tapping_process(keyrecord_t record); uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); uint16_t get_quick_tap_term(uint16_t keycode, keyrecord_t *record); bool get_permissive_hold(uint16_t keycode, keyrecord_t *record); -bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record); bool get_retro_tapping(uint16_t keycode, keyrecord_t *record); bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/action_util.c b/quantum/action_util.c index 7f7d32887b6a..909dea059594 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -46,6 +46,12 @@ static uint8_t oneshot_locked_mods = 0; uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } +void add_oneshot_locked_mods(uint8_t mods) { + if ((oneshot_locked_mods & mods) != mods) { + oneshot_locked_mods |= mods; + oneshot_locked_mods_changed_kb(oneshot_locked_mods); + } +} void set_oneshot_locked_mods(uint8_t mods) { if (mods != oneshot_locked_mods) { oneshot_locked_mods = mods; @@ -58,6 +64,12 @@ void clear_oneshot_locked_mods(void) { oneshot_locked_mods_changed_kb(oneshot_locked_mods); } } +void del_oneshot_locked_mods(uint8_t mods) { + if (oneshot_locked_mods & mods) { + oneshot_locked_mods &= ~mods; + oneshot_locked_mods_changed_kb(oneshot_locked_mods); + } +} # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_time = 0; bool has_oneshot_mods_timed_out(void) { @@ -78,7 +90,7 @@ bool has_oneshot_mods_timed_out(void) { * L => are layer bits * S => oneshot state bits */ -static int8_t oneshot_layer_data = 0; +static uint8_t oneshot_layer_data = 0; inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; @@ -488,3 +500,28 @@ __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { uint8_t has_anymod(void) { return bitpop(real_mods); } + +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE +/** \brief Send a dummy keycode in between the register and unregister event of a modifier key, to neutralize the "flashing modifiers" phenomenon. + * + * \param active_mods 8-bit packed bit-array describing the currently active modifiers (in the format GASCGASC). + * + * Certain QMK features like key overrides or retro tap must unregister a previously + * registered modifier before sending another keycode but this can trigger undesired + * keyboard shortcuts if the clean tap of a single modifier key is bound to an action + * on the host OS, as is for example the case for the left GUI key on Windows, which + * opens the Start Menu when tapped. + */ +void neutralize_flashing_modifiers(uint8_t active_mods) { + // In most scenarios, the flashing modifiers phenomenon is a problem + // only for a subset of modifier masks. + const static uint8_t mods_to_neutralize[] = MODS_TO_NEUTRALIZE; + const static uint8_t n_mods = ARRAY_SIZE(mods_to_neutralize); + for (uint8_t i = 0; i < n_mods; ++i) { + if (active_mods == mods_to_neutralize[i]) { + tap_code(DUMMY_MOD_NEUTRALIZER_KEYCODE); + break; + } + } +} +#endif diff --git a/quantum/action_util.h b/quantum/action_util.h index 6f1f09c4bd1c..831caf3c0a16 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -19,6 +19,7 @@ along with this program. If not, see . #include #include "report.h" +#include "modifiers.h" #ifdef __cplusplus extern "C" { @@ -64,8 +65,10 @@ void clear_oneshot_mods(void); bool has_oneshot_mods_timed_out(void); uint8_t get_oneshot_locked_mods(void); +void add_oneshot_locked_mods(uint8_t mods); void set_oneshot_locked_mods(uint8_t mods); void clear_oneshot_locked_mods(void); +void del_oneshot_locked_mods(uint8_t mods); typedef enum { ONESHOT_PRESSED = 0b01, ONESHOT_OTHER_KEY_PRESSED = 0b10, ONESHOT_START = 0b11, ONESHOT_TOGGLED = 0b100 } oneshot_fullfillment_t; void set_oneshot_layer(uint8_t layer, uint8_t state); @@ -99,6 +102,19 @@ void use_oneshot_swaphands(void); void clear_oneshot_swaphands(void); #endif +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE +// KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes +// internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`. +# if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX) +# error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!" +# endif +void neutralize_flashing_modifiers(uint8_t active_mods); +#endif +#ifndef MODS_TO_NEUTRALIZE +# define MODS_TO_NEUTRALIZE \ + { MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI) } +#endif + #ifdef __cplusplus } #endif diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index ca78a483ad8f..28c826751723 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -18,6 +18,7 @@ #include "eeconfig.h" #include "timer.h" #include "wait.h" +#include "util.h" /* audio system: * @@ -112,6 +113,10 @@ static bool audio_initialized = false; static bool audio_driver_stopped = true; audio_config_t audio_config; +void eeconfig_update_audio_current(void) { + eeconfig_update_audio(audio_config.raw); +} + void audio_init(void) { if (audio_initialized) { return; @@ -306,6 +311,10 @@ void audio_play_melody(float (*np)[][2], uint16_t n_count, bool n_repeat) { return; } + if (n_count == 0) { + return; + } + if (!audio_initialized) { audio_init(); } @@ -542,20 +551,42 @@ void audio_decrease_tempo(uint8_t tempo_change) { note_tempo -= tempo_change; } -// TODO in the int-math version are some bugs; songs sometimes abruptly end - maybe an issue with the timer/system-tick wrapping around? +/** + * Converts from units of 1/64ths of a beat to milliseconds. + * + * Round-off error is at most 1 millisecond. + * + * Conversion will never overflow for duration_bpm <= 699, provided that + * note_tempo is at least 10. This is quite a long duration, over ten beats. + * + * Beware that for duration_bpm > 699, the result may overflow uint16_t range + * when duration_bpm is large compared to note_tempo: + * + * duration_bpm * 60 * 1000 / (64 * note_tempo) > UINT16_MAX + * + * duration_bpm > (2 * 65535 / 1875) * note_tempo + * = 69.904 * note_tempo. + */ uint16_t audio_duration_to_ms(uint16_t duration_bpm) { -#if defined(__AVR__) - // doing int-math saves us some bytes in the overall firmware size, but the intermediate result is less accurate before being cast to/returned as uint - return ((uint32_t)duration_bpm * 60 * 1000) / (64 * note_tempo); - // NOTE: beware of uint16_t overflows when note_tempo is low and/or the duration is long -#else - return ((float)duration_bpm * 60) / (64 * note_tempo) * 1000; -#endif + return ((uint32_t)duration_bpm * 1875) / ((uint_fast16_t)note_tempo * 2); } + +/** + * Converts from units of milliseconds to 1/64ths of a beat. + * + * Round-off error is at most 1/64th of a beat. + * + * This conversion never overflows: since duration_ms <= UINT16_MAX = 65535 + * and note_tempo <= 255, the result is always in uint16_t range: + * + * duration_ms * 64 * note_tempo / 60 / 1000 + * <= 65535 * 2 * 255 / 1875 + * = 17825.52 + * <= UINT16_MAX. + */ uint16_t audio_ms_to_duration(uint16_t duration_ms) { -#if defined(__AVR__) - return ((uint32_t)duration_ms * 64 * note_tempo) / 60 / 1000; -#else - return ((float)duration_ms * 64 * note_tempo) / 60 / 1000; -#endif + return ((uint32_t)duration_ms * 2 * note_tempo) / 1875; } + +__attribute__((weak)) void audio_on_user(void) {} +__attribute__((weak)) void audio_off_user(void) {} diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index fe23cf3ed1a8..a4a908b43c5b 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -21,12 +21,6 @@ #include "musical_notes.h" #include "song_list.h" #include "voices.h" -#include "quantum.h" -#include - -#if defined(__AVR__) -# include -#endif #if defined(AUDIO_DRIVER_PWM) # include "audio_pwm.h" @@ -43,10 +37,7 @@ typedef union { }; } audio_config_t; -// AVR/LUFA has a MIN, arm/chibios does not -#ifndef MIN -# define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif +_Static_assert(sizeof(audio_config_t) == sizeof(uint8_t), "Audio EECONFIG out of spec."); /* * a 'musical note' is represented by pitch and duration; a 'musical tone' adds intensity and timbre @@ -63,6 +54,11 @@ typedef struct { // public interface +/** + * @brief Save the current choices to the eeprom + */ +void eeconfig_update_audio_current(void); + /** * @brief one-time initialization called by quantum/quantum.c * @details usually done lazy, when some tones are to be played @@ -278,3 +274,6 @@ bool audio_update_state(void); #define increase_tempo(t) audio_increase_tempo(t) #define decrease_tempo(t) audio_decrease_tempo(t) // vibrato functions are not used in any keyboards + +void audio_on_user(void); +void audio_off_user(void); diff --git a/quantum/audio/muse.c b/quantum/audio/muse.c index 01b95671fdca..4c23cd734840 100644 --- a/quantum/audio/muse.c +++ b/quantum/audio/muse.c @@ -1,5 +1,7 @@ #include "muse.h" +#include + enum { MUSE_OFF, MUSE_ON, MUSE_C_1_2, MUSE_C1, MUSE_C2, MUSE_C4, MUSE_C8, MUSE_C3, MUSE_C6, MUSE_B1, MUSE_B2, MUSE_B3, MUSE_B4, MUSE_B5, MUSE_B6, MUSE_B7, MUSE_B8, MUSE_B9, MUSE_B10, MUSE_B11, MUSE_B12, MUSE_B13, MUSE_B14, MUSE_B15, MUSE_B16, MUSE_B17, MUSE_B18, MUSE_B19, MUSE_B20, MUSE_B21, MUSE_B22, MUSE_B23, MUSE_B24, MUSE_B25, MUSE_B26, MUSE_B27, MUSE_B28, MUSE_B29, MUSE_B30, MUSE_B31 }; bool number_of_ones_to_bool[16] = {1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1}; diff --git a/quantum/audio/muse.h b/quantum/audio/muse.h index ad2f96e43af6..7b289cac6c1e 100644 --- a/quantum/audio/muse.h +++ b/quantum/audio/muse.h @@ -1,6 +1,5 @@ #pragma once -#include "quantum.h" -#include "process_audio.h" +#include uint8_t muse_clock_pulse(void); diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 44e707ab96c2..d0e3e023c604 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -16,7 +16,9 @@ */ #include "voices.h" #include "audio.h" +#include "timer.h" #include +#include uint8_t note_timbre = TIMBRE_DEFAULT; bool glissando = false; diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 52ec086bb093..9d9f944f5db4 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "quantum.h" #include "backlight.h" #include "eeprom.h" #include "eeconfig.h" diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index ff9c8de420ce..85812bff3a5e 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h @@ -44,6 +44,8 @@ typedef union { }; } backlight_config_t; +_Static_assert(sizeof(backlight_config_t) == sizeof(uint8_t), "Backlight EECONFIG out of spec."); + void backlight_init(void); void backlight_toggle(void); void backlight_enable(void); diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c index 1eb8969084e8..8c3fe461d7ca 100644 --- a/quantum/backlight/backlight_driver_common.c +++ b/quantum/backlight/backlight_driver_common.c @@ -1,6 +1,7 @@ -#include "quantum.h" #include "backlight.h" #include "backlight_driver_common.h" +#include "gpio.h" +#include "util.h" #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS) # error "Backlight pin/pins not defined. Please configure." diff --git a/quantum/basic_profiling.h b/quantum/basic_profiling.h new file mode 100644 index 000000000000..d371acd6f002 --- /dev/null +++ b/quantum/basic_profiling.h @@ -0,0 +1,69 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +/* + This API allows for basic profiling information to be printed out over console. + + Usage example: + + #include "basic_profiling.h" + + // Original code: + matrix_task(); + + // Delete the original, replace with the following (variant 1, automatic naming): + PROFILE_CALL(1000, matrix_task()); + + // Delete the original, replace with the following (variant 2, explicit naming): + PROFILE_CALL_NAMED(1000, "matrix_task", { + matrix_task(); + }); +*/ + +#if defined(PROTOCOL_LUFA) || defined(PROTOCOL_VUSB) +# define TIMESTAMP_GETTER TCNT0 +#elif defined(PROTOCOL_CHIBIOS) +# define TIMESTAMP_GETTER chSysGetRealtimeCounterX() +#elif defined(PROTOCOL_ARM_ATSAM) +# error arm_atsam not currently supported +#else +# error Unknown protocol in use +#endif + +#ifndef CONSOLE_ENABLE +// Can't do anything if we don't have console output enabled. +# define PROFILE_CALL_NAMED(count, name, call) \ + do { \ + } while (0) +#else +# define PROFILE_CALL_NAMED(count, name, call) \ + do { \ + static uint64_t inner_sum = 0; \ + static uint64_t outer_sum = 0; \ + uint32_t start_ts; \ + static uint32_t end_ts; \ + static uint32_t write_location = 0; \ + start_ts = TIMESTAMP_GETTER; \ + if (write_location > 0) { \ + outer_sum += start_ts - end_ts; \ + } \ + do { \ + call; \ + } while (0); \ + end_ts = TIMESTAMP_GETTER; \ + inner_sum += end_ts - start_ts; \ + ++write_location; \ + if (write_location >= ((uint32_t)count)) { \ + uint32_t inner_avg = inner_sum / (((uint32_t)count) - 1); \ + uint32_t outer_avg = outer_sum / (((uint32_t)count) - 1); \ + dprintf("%s -- Percentage time spent: %d%%\n", (name), (int)(inner_avg * 100 / (inner_avg + outer_avg))); \ + inner_sum = 0; \ + outer_sum = 0; \ + write_location = 0; \ + } \ + } while (0) + +#endif // CONSOLE_ENABLE + +#define PROFILE_CALL(count, call) PROFILE_CALL_NAMED(count, #call, call) diff --git a/quantum/bootmagic/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c index f63c71fc6b16..efce6bfd121b 100644 --- a/quantum/bootmagic/bootmagic_lite.c +++ b/quantum/bootmagic/bootmagic_lite.c @@ -13,7 +13,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "quantum.h" +#include "bootmagic.h" +#include "matrix.h" +#include "keyboard.h" +#include "wait.h" +#include "eeconfig.h" +#include "bootloader.h" /** \brief Reset eeprom * diff --git a/quantum/bootmagic/magic.c b/quantum/bootmagic/magic.c index f1cb11c39576..d68df3fa5884 100644 --- a/quantum/bootmagic/magic.c +++ b/quantum/bootmagic/magic.c @@ -19,7 +19,7 @@ #include "matrix.h" #include "bootloader.h" #include "debug.h" -#include "keymap.h" +#include "keycode_config.h" #include "host.h" #include "action_layer.h" #include "eeconfig.h" diff --git a/quantum/color.c b/quantum/color.c index c80078dbf215..767155c9db9b 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -17,6 +17,7 @@ #include "color.h" #include "led_tables.h" #include "progmem.h" +#include "util.h" RGB hsv_to_rgb_impl(HSV hsv, bool use_cie) { RGB rgb; @@ -109,9 +110,6 @@ RGB hsv_to_rgb_nocie(HSV hsv) { } #ifdef RGBW -# ifndef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -# endif void convert_rgb_to_rgbw(LED_TYPE *led) { // Determine lowest value in all three colors, put that into // the white channel and then shift all colors by that amount diff --git a/quantum/command.c b/quantum/command.c index 84757b9b01c6..aa64b75064f6 100644 --- a/quantum/command.c +++ b/quantum/command.c @@ -19,7 +19,6 @@ along with this program. If not, see . #include "wait.h" #include "keycode.h" #include "host.h" -#include "keymap.h" #include "print.h" #include "debug.h" #include "util.h" diff --git a/quantum/config_common.h b/quantum/config_common.h deleted file mode 100644 index 6c70b00b536c..000000000000 --- a/quantum/config_common.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright 2015-2018 Jack Humbert - * - * 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 - -#pragma message("'config_common.h' should no longer be included!") diff --git a/quantum/debounce.h b/quantum/debounce.h index a8629654c20f..cea1f2b5260b 100644 --- a/quantum/debounce.h +++ b/quantum/debounce.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include "matrix.h" + /** * @brief Debounce raw matrix events according to the choosen debounce algorithm. * diff --git a/quantum/debounce/asym_eager_defer_pk.c b/quantum/debounce/asym_eager_defer_pk.c index 4745c6f4654f..954d43536c0e 100644 --- a/quantum/debounce/asym_eager_defer_pk.c +++ b/quantum/debounce/asym_eager_defer_pk.c @@ -22,9 +22,8 @@ Basic symmetric per-key algorithm. Uses an 8-bit counter per key. When no state changes have occured for DEBOUNCE milliseconds, we push the state. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifdef PROTOCOL_CHIBIOS @@ -144,6 +143,8 @@ static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { debounce_counter_t *debounce_pointer = debounce_counters; + matrix_need_update = false; + for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t delta = raw[row] ^ cooked[row]; for (uint8_t col = 0; col < MATRIX_COLS; col++) { diff --git a/quantum/debounce/none.c b/quantum/debounce/none.c index 4cff5e05e260..1b8b1dc13a3a 100644 --- a/quantum/debounce/none.c +++ b/quantum/debounce/none.c @@ -14,9 +14,7 @@ * along with this program. If not, see . */ -#include "matrix.h" -#include "quantum.h" -#include +#include "debounce.h" #include void debounce_init(uint8_t num_rows) {} diff --git a/quantum/debounce/sym_defer_g.c b/quantum/debounce/sym_defer_g.c index d04310a76151..25e18890affc 100644 --- a/quantum/debounce/sym_defer_g.c +++ b/quantum/debounce/sym_defer_g.c @@ -17,9 +17,8 @@ along with this program. If not, see . Basic global debounce algorithm. Used in 99% of keyboards at time of implementation When no state changes have occured for DEBOUNCE milliseconds, we push the state. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifndef DEBOUNCE # define DEBOUNCE 5 diff --git a/quantum/debounce/sym_defer_pk.c b/quantum/debounce/sym_defer_pk.c index 7b59b5e10076..156535a37338 100644 --- a/quantum/debounce/sym_defer_pk.c +++ b/quantum/debounce/sym_defer_pk.c @@ -19,9 +19,8 @@ Basic symmetric per-key algorithm. Uses an 8-bit counter per key. When no state changes have occured for DEBOUNCE milliseconds, we push the state. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifdef PROTOCOL_CHIBIOS diff --git a/quantum/debounce/sym_defer_pr.c b/quantum/debounce/sym_defer_pr.c index 452c4599d0a7..d6222af5b298 100644 --- a/quantum/debounce/sym_defer_pr.c +++ b/quantum/debounce/sym_defer_pr.c @@ -17,9 +17,8 @@ Symmetric per-row debounce algorithm. Changes only apply when DEBOUNCE milliseconds have elapsed since the last change. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifndef DEBOUNCE diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c index f736d1645cd4..b359e79287ec 100644 --- a/quantum/debounce/sym_eager_pk.c +++ b/quantum/debounce/sym_eager_pk.c @@ -19,9 +19,8 @@ After pressing a key, it immediately changes state, and sets a counter. No further inputs are accepted until DEBOUNCE milliseconds have occurred. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifdef PROTOCOL_CHIBIOS @@ -125,6 +124,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { // upload from raw_matrix to final matrix; static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t delta = raw[row] ^ cooked[row]; diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c index aad5ca351b89..ccc5d20fa2c0 100644 --- a/quantum/debounce/sym_eager_pr.c +++ b/quantum/debounce/sym_eager_pr.c @@ -19,9 +19,8 @@ After pressing a key, it immediately changes state, and sets a counter. No further inputs are accepted until DEBOUNCE milliseconds have occurred. */ -#include "matrix.h" +#include "debounce.h" #include "timer.h" -#include "quantum.h" #include #ifdef PROTOCOL_CHIBIOS @@ -119,6 +118,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { // upload from raw_matrix to final matrix; static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t existing_row = cooked[row]; diff --git a/quantum/debounce/tests/debounce_test_common.cpp b/quantum/debounce/tests/debounce_test_common.cpp index bd98e329554a..b11378b286ac 100644 --- a/quantum/debounce/tests/debounce_test_common.cpp +++ b/quantum/debounce/tests/debounce_test_common.cpp @@ -23,9 +23,8 @@ #include extern "C" { -#include "quantum.h" -#include "timer.h" #include "debounce.h" +#include "timer.h" void set_time(uint32_t t); void advance_time(uint32_t ms); diff --git a/quantum/debounce/tests/debounce_test_common.h b/quantum/debounce/tests/debounce_test_common.h index b7becb378260..7319abfbf3f3 100644 --- a/quantum/debounce/tests/debounce_test_common.h +++ b/quantum/debounce/tests/debounce_test_common.h @@ -21,7 +21,7 @@ #include extern "C" { -#include "quantum.h" +#include "matrix.h" #include "timer.h" } diff --git a/quantum/digitizer.h b/quantum/digitizer.h index b826ba8ac870..6a9c24ed34df 100644 --- a/quantum/digitizer.h +++ b/quantum/digitizer.h @@ -13,17 +13,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#pragma once -#include "quantum.h" +#pragma once #include -#include /** - * \defgroup digitizer + * \file * - * HID Digitizer + * defgroup digitizer HID Digitizer * \{ */ diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 5f1f78e46dcf..3c22bbd4457f 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -14,17 +14,19 @@ * along with this program. If not, see . */ -#include "keymap.h" // to get keymaps[][][] -#include "eeprom.h" -#include "progmem.h" // to read default from flash -#include "quantum.h" // for send_string() -#include "eeconfig.h" #include "dynamic_keymap.h" +#include "keymap_introspection.h" +#include "action.h" +#include "eeprom.h" +#include "progmem.h" +#include "send_string.h" +#include "keycodes.h" #ifdef VIA_ENABLE -# include "via.h" // for VIA_EEPROM_CONFIG_END +# include "via.h" # define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END) #else +# include "eeconfig.h" # define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE) #endif @@ -153,22 +155,13 @@ void dynamic_keymap_reset(void) { for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { for (int row = 0; row < MATRIX_ROWS; row++) { for (int column = 0; column < MATRIX_COLS; column++) { - if (layer < keymap_layer_count()) { - dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column)); - } else { - dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT); - } + dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column)); } } #ifdef ENCODER_MAP_ENABLE for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) { - if (layer < encodermap_layer_count()) { - dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true)); - dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false)); - } else { - dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT); - dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT); - } + dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true)); + dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false)); } #endif // ENCODER_MAP_ENABLE } diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 21bcce265450..84de025f0e65 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -46,6 +46,7 @@ void eeconfig_init_quantum(void) { #if defined(EEPROM_DRIVER) eeprom_driver_erase(); #endif + eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_byte(EECONFIG_DEBUG, 0); eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); @@ -55,19 +56,15 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default eeprom_update_dword(EECONFIG_RGBLIGHT, 0); + eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0); + eeprom_update_byte(EECONFIG_VELOCIKEY, 0); + eeprom_update_byte(EECONFIG_UNICODEMODE, 0); eeprom_update_byte(EECONFIG_STENOMODE, 0); + uint64_t dummy = 0; + eeprom_update_block(&dummy, EECONFIG_RGB_MATRIX, sizeof(uint64_t)); eeprom_update_dword(EECONFIG_HAPTIC, 0); - eeprom_update_byte(EECONFIG_VELOCIKEY, 0); - eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); - eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0); - #if defined(HAPTIC_ENABLE) haptic_reset(); -#else - // this is used in case haptic is disabled, but we still want sane defaults - // in the haptic configuration eeprom. All zero will trigger a haptic_reset - // when a haptic-enabled firmware is loaded onto the keyboard. - eeprom_update_dword(EECONFIG_HAPTIC, 0); #endif #if (EECONFIG_KB_DATA_SIZE) > 0 diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index ee8e9add8b12..85e80226b6ff 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h @@ -21,7 +21,7 @@ along with this program. If not, see . #include #ifndef EECONFIG_MAGIC_NUMBER -# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE7 // When changing, decrement this value to avoid future re-init issues +# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE6 // When changing, decrement this value to avoid future re-init issues #endif #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF @@ -40,18 +40,15 @@ along with this program. If not, see . #define EECONFIG_KEYBOARD (uint32_t *)15 #define EECONFIG_USER (uint32_t *)19 #define EECONFIG_VELOCIKEY (uint8_t *)23 - -#define EECONFIG_HAPTIC (uint32_t *)24 - // Mutually exclusive -#define EECONFIG_LED_MATRIX (uint32_t *)28 -#define EECONFIG_RGB_MATRIX (uint32_t *)28 -// Speed & Flags -#define EECONFIG_LED_MATRIX_EXTENDED (uint16_t *)32 -#define EECONFIG_RGB_MATRIX_EXTENDED (uint16_t *)32 +#define EECONFIG_LED_MATRIX (uint32_t *)24 +#define EECONFIG_RGB_MATRIX (uint64_t *)24 + +#define EECONFIG_HAPTIC (uint32_t *)32 +#define EECONFIG_RGBLIGHT_EXTENDED (uint8_t *)36 // Size of EEPROM being used for core data storage -#define EECONFIG_BASE_SIZE 34 +#define EECONFIG_BASE_SIZE 37 // Size of EEPROM dedicated to keyboard- and user-specific data #ifndef EECONFIG_KB_DATA_SIZE diff --git a/quantum/encoder.c b/quantum/encoder.c index 3aee3402499e..7ab194ed5290 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -16,6 +16,11 @@ */ #include "encoder.h" +#include "keyboard.h" +#include "action.h" +#include "keycodes.h" +#include "wait.h" + #ifdef SPLIT_KEYBOARD # include "split_util.h" #endif @@ -77,7 +82,29 @@ __attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { } __attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { - return encoder_update_user(index, clockwise); + bool res = encoder_update_user(index, clockwise); +#if !defined(ENCODER_TESTS) + if (res) { + if (clockwise) { +# if defined(EXTRAKEY_ENABLE) + tap_code_delay(KC_VOLU, 10); +# elif defined(MOUSEKEY_ENABLE) + tap_code_delay(KC_MS_WH_UP, 10); +# else + tap_code_delay(KC_PGDN, 10); +# endif + } else { +# if defined(EXTRAKEY_ENABLE) + tap_code_delay(KC_VOLD, 10); +# elif defined(MOUSEKEY_ENABLE) + tap_code_delay(KC_MS_WH_DOWN, 10); +# else + tap_code_delay(KC_PGUP, 10); +# endif + } + } +#endif // ENCODER_TESTS + return res; } __attribute__((weak)) bool should_process_encoder(void) { @@ -147,12 +174,12 @@ void encoder_init(void) { #ifdef ENCODER_MAP_ENABLE static void encoder_exec_mapping(uint8_t index, bool clockwise) { // The delays below cater for Windows and its wonderful requirements. - action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true)); + action_exec(clockwise ? MAKE_ENCODER_CW_EVENT(index, true) : MAKE_ENCODER_CCW_EVENT(index, true)); # if ENCODER_MAP_KEY_DELAY > 0 wait_ms(ENCODER_MAP_KEY_DELAY); # endif // ENCODER_MAP_KEY_DELAY > 0 - action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false)); + action_exec(clockwise ? MAKE_ENCODER_CW_EVENT(index, false) : MAKE_ENCODER_CCW_EVENT(index, false)); # if ENCODER_MAP_KEY_DELAY > 0 wait_ms(ENCODER_MAP_KEY_DELAY); # endif // ENCODER_MAP_KEY_DELAY > 0 diff --git a/quantum/encoder.h b/quantum/encoder.h index 4eb67fa25dda..1cbac98cb57a 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -17,7 +17,9 @@ #pragma once -#include "quantum.h" +#include +#include +#include "gpio.h" #include "util.h" void encoder_init(void); @@ -57,7 +59,8 @@ void encoder_update_raw(uint8_t* slave_state); #define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT) #ifdef ENCODER_MAP_ENABLE +# define NUM_DIRECTIONS 2 # define ENCODER_CCW_CW(ccw, cw) \ { (cw), (ccw) } -extern const uint16_t encoder_map[][NUM_ENCODERS][2]; +extern const uint16_t encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS]; #endif // ENCODER_MAP_ENABLE diff --git a/quantum/encoder/tests/encoder_tests_split_role.cpp b/quantum/encoder/tests/encoder_tests_split_role.cpp index 02264067f4c6..0ab7bfc2a783 100644 --- a/quantum/encoder/tests/encoder_tests_split_role.cpp +++ b/quantum/encoder/tests/encoder_tests_split_role.cpp @@ -22,6 +22,7 @@ extern "C" { #include "encoder.h" +#include "keyboard.h" #include "encoder/tests/mock_split.h" } diff --git a/quantum/haptic.c b/quantum/haptic.c index c151547fcafc..5a700dca388e 100644 --- a/quantum/haptic.c +++ b/quantum/haptic.c @@ -14,17 +14,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "haptic.h" #include "eeconfig.h" #include "debug.h" #include "usb_device_state.h" #include "gpio.h" -#ifdef DRV2605L -# include "DRV2605L.h" + +#ifdef HAPTIC_DRV2605L +# include "drv2605l.h" #endif -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID # include "solenoid.h" #endif + #if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) extern uint8_t split_haptic_play; #endif @@ -59,11 +62,11 @@ void haptic_init(void) { eeconfig_init(); } haptic_config.raw = eeconfig_read_haptic(); -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID solenoid_set_dwell(haptic_config.dwell); #endif if ((haptic_config.raw == 0) -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID || (haptic_config.dwell == 0) #endif ) { @@ -77,12 +80,12 @@ void haptic_init(void) { // This is to execute any side effects of the configuration. set_haptic_config_enable(haptic_config.enable); } -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID solenoid_setup(); dprintf("Solenoid driver initialized\n"); #endif -#ifdef DRV2605L - DRV_init(); +#ifdef HAPTIC_DRV2605L + drv2605l_init(); dprintf("DRV2605 driver initialized\n"); #endif eeconfig_debug_haptic(); @@ -95,7 +98,7 @@ void haptic_init(void) { } void haptic_task(void) { -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID solenoid_check(); #endif } @@ -108,13 +111,13 @@ void eeconfig_debug_haptic(void) { void haptic_enable(void) { set_haptic_config_enable(true); - xprintf("haptic_config.enable = %u\n", haptic_config.enable); + dprintf("haptic_config.enable = %u\n", haptic_config.enable); eeconfig_update_haptic(haptic_config.raw); } void haptic_disable(void) { set_haptic_config_enable(false); - xprintf("haptic_config.enable = %u\n", haptic_config.enable); + dprintf("haptic_config.enable = %u\n", haptic_config.enable); eeconfig_update_haptic(haptic_config.raw); } @@ -130,7 +133,7 @@ void haptic_toggle(void) { void haptic_feedback_toggle(void) { haptic_config.feedback++; if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX) haptic_config.feedback = KEY_PRESS; - xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback); + dprintf("haptic_config.feedback = %u\n", !haptic_config.feedback); eeconfig_update_haptic(haptic_config.raw); } @@ -142,8 +145,8 @@ void haptic_buzz_toggle(void) { void haptic_mode_increase(void) { uint8_t mode = haptic_config.mode + 1; -#ifdef DRV2605L - if (haptic_config.mode >= drv_effect_max) { +#ifdef HAPTIC_DRV2605L + if (haptic_config.mode >= DRV2605L_EFFECT_COUNT) { mode = 1; } #endif @@ -152,16 +155,16 @@ void haptic_mode_increase(void) { void haptic_mode_decrease(void) { uint8_t mode = haptic_config.mode - 1; -#ifdef DRV2605L +#ifdef HAPTIC_DRV2605L if (haptic_config.mode < 1) { - mode = (drv_effect_max - 1); + mode = (DRV2605L_EFFECT_COUNT - 1); } #endif haptic_set_mode(mode); } void haptic_dwell_increase(void) { -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE; if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { // if it's already at max, we wrap back to min @@ -178,7 +181,7 @@ void haptic_dwell_increase(void) { } void haptic_dwell_decrease(void) { -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE; if (haptic_config.dwell <= SOLENOID_MIN_DWELL) { // if it's already at min, we wrap to max @@ -196,13 +199,13 @@ void haptic_dwell_decrease(void) { void haptic_reset(void) { set_haptic_config_enable(true); - uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT; + uint8_t feedback = HAPTIC_DEFAULT_FEEDBACK; haptic_config.feedback = feedback; -#ifdef DRV2605L - uint8_t mode = HAPTIC_MODE_DEFAULT; +#ifdef HAPTIC_DRV2605L + uint8_t mode = HAPTIC_DEFAULT_MODE; haptic_config.mode = mode; #endif -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID uint8_t dwell = SOLENOID_DEFAULT_DWELL; haptic_config.dwell = dwell; haptic_config.buzz = SOLENOID_DEFAULT_BUZZ; @@ -213,41 +216,41 @@ void haptic_reset(void) { haptic_config.buzz = 0; #endif eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); - xprintf("haptic_config.mode = %u\n", haptic_config.mode); + dprintf("haptic_config.feedback = %u\n", haptic_config.feedback); + dprintf("haptic_config.mode = %u\n", haptic_config.mode); } void haptic_set_feedback(uint8_t feedback) { haptic_config.feedback = feedback; eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); + dprintf("haptic_config.feedback = %u\n", haptic_config.feedback); } void haptic_set_mode(uint8_t mode) { haptic_config.mode = mode; eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.mode = %u\n", haptic_config.mode); + dprintf("haptic_config.mode = %u\n", haptic_config.mode); } void haptic_set_amplitude(uint8_t amp) { haptic_config.amplitude = amp; eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude); -#ifdef DRV2605L - DRV_amplitude(amp); + dprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude); +#ifdef HAPTIC_DRV2605L + drv2605l_amplitude(amp); #endif } void haptic_set_buzz(uint8_t buzz) { haptic_config.buzz = buzz; eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.buzz = %u\n", haptic_config.buzz); + dprintf("haptic_config.buzz = %u\n", haptic_config.buzz); } void haptic_set_dwell(uint8_t dwell) { haptic_config.dwell = dwell; eeconfig_update_haptic(haptic_config.raw); - xprintf("haptic_config.dwell = %u\n", haptic_config.dwell); + dprintf("haptic_config.dwell = %u\n", haptic_config.dwell); } uint8_t haptic_get_enable(void) { @@ -277,19 +280,19 @@ uint8_t haptic_get_dwell(void) { void haptic_enable_continuous(void) { haptic_config.cont = 1; - xprintf("haptic_config.cont = %u\n", haptic_config.cont); + dprintf("haptic_config.cont = %u\n", haptic_config.cont); eeconfig_update_haptic(haptic_config.raw); -#ifdef DRV2605L - DRV_rtp_init(); +#ifdef HAPTIC_DRV2605L + drv2605l_rtp_init(); #endif } void haptic_disable_continuous(void) { haptic_config.cont = 0; - xprintf("haptic_config.cont = %u\n", haptic_config.cont); + dprintf("haptic_config.cont = %u\n", haptic_config.cont); eeconfig_update_haptic(haptic_config.raw); -#ifdef DRV2605L - DRV_write(DRV_MODE, 0x00); +#ifdef HAPTIC_DRV2605L + drv2605l_write(DRV2605L_REG_MODE, 0x00); #endif } @@ -318,15 +321,15 @@ void haptic_cont_decrease(void) { } void haptic_play(void) { -#ifdef DRV2605L +#ifdef HAPTIC_DRV2605L uint8_t play_eff = 0; play_eff = haptic_config.mode; - DRV_pulse(play_eff); + drv2605l_pulse(play_eff); # if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) split_haptic_play = haptic_config.mode; # endif #endif -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID solenoid_fire_handler(); # if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) split_haptic_play = 1; @@ -335,7 +338,7 @@ void haptic_play(void) { } void haptic_shutdown(void) { -#ifdef SOLENOID_ENABLE +#ifdef HAPTIC_SOLENOID solenoid_shutdown(); #endif } diff --git a/quantum/haptic.h b/quantum/haptic.h index 7d70a013337a..5bd1a71916db 100644 --- a/quantum/haptic.h +++ b/quantum/haptic.h @@ -16,14 +16,15 @@ */ #pragma once + #include #include -#ifndef HAPTIC_FEEDBACK_DEFAULT -# define HAPTIC_FEEDBACK_DEFAULT 0 +#ifndef HAPTIC_DEFAULT_FEEDBACK +# define HAPTIC_DEFAULT_FEEDBACK 0 #endif -#ifndef HAPTIC_MODE_DEFAULT -# define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT +#ifndef HAPTIC_DEFAULT_MODE +# define HAPTIC_DEFAULT_MODE DRV2605L_DEFAULT_MODE #endif /* EEPROM config settings */ @@ -31,16 +32,18 @@ typedef union { uint32_t raw; struct { bool enable : 1; - uint8_t feedback : 2; uint8_t mode : 7; bool buzz : 1; uint8_t dwell : 7; - bool cont : 1; uint8_t amplitude : 8; + uint8_t feedback : 2; + bool cont : 1; uint8_t reserved : 5; }; } haptic_config_t; +_Static_assert(sizeof(haptic_config_t) == sizeof(uint32_t), "Haptic EECONFIG out of spec."); + typedef enum HAPTIC_FEEDBACK { KEY_PRESS, KEY_PRESS_RELEASE, diff --git a/quantum/joystick.h b/quantum/joystick.h index 0ac99aa590d0..5de4ba66c6ab 100644 --- a/quantum/joystick.h +++ b/quantum/joystick.h @@ -22,9 +22,9 @@ #include "gpio.h" /** - * \defgroup joystick + * \file * - * HID Joystick + * \defgroup joystick HID Joystick * \{ */ diff --git a/quantum/keyboard.c b/quantum/keyboard.c index ec2f2e4496ff..c2ca15d52def 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -16,10 +16,10 @@ along with this program. If not, see . */ #include -#include "quantum.h" #include "keyboard.h" +#include "keycode_config.h" #include "matrix.h" -#include "keymap.h" +#include "keymap_introspection.h" #include "magic.h" #include "host.h" #include "led.h" @@ -33,6 +33,12 @@ along with this program. If not, see . #include "sendchar.h" #include "eeconfig.h" #include "action_layer.h" +#ifdef AUDIO_ENABLE +# include "audio.h" +#endif +#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) +# include "process_music.h" +#endif #ifdef BACKLIGHT_ENABLE # include "backlight.h" #endif @@ -54,9 +60,27 @@ along with this program. If not, see . #ifdef ENCODER_ENABLE # include "encoder.h" #endif +#ifdef HAPTIC_ENABLE +# include "haptic.h" +#endif +#ifdef AUTO_SHIFT_ENABLE +# include "process_auto_shift.h" +#endif +#ifdef COMBO_ENABLE +# include "process_combo.h" +#endif +#ifdef TAP_DANCE_ENABLE +# include "process_tap_dance.h" +#endif #ifdef STENO_ENABLE # include "process_steno.h" #endif +#ifdef KEY_OVERRIDE_ENABLE +# include "process_key_override.h" +#endif +#ifdef SECURE_ENABLE +# include "secure.h" +#endif #ifdef POINTING_DEVICE_ENABLE # include "pointing_device.h" #endif @@ -64,7 +88,7 @@ along with this program. If not, see . # include "process_midi.h" #endif #ifdef JOYSTICK_ENABLE -# include "process_joystick.h" +# include "joystick.h" #endif #ifdef HD44780_ENABLE # include "hd44780.h" @@ -108,13 +132,19 @@ along with this program. If not, see . #ifdef LEADER_ENABLE # include "leader.h" #endif +#ifdef UNICODE_COMMON_ENABLE +# include "unicode.h" +#endif +#ifdef WPM_ENABLE +# include "wpm.h" +#endif static uint32_t last_input_modification_time = 0; uint32_t last_input_activity_time(void) { return last_input_modification_time; } uint32_t last_input_activity_elapsed(void) { - return timer_elapsed32(last_input_modification_time); + return sync_timer_elapsed32(last_input_modification_time); } static uint32_t last_matrix_modification_time = 0; @@ -122,10 +152,10 @@ uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; } uint32_t last_matrix_activity_elapsed(void) { - return timer_elapsed32(last_matrix_modification_time); + return sync_timer_elapsed32(last_matrix_modification_time); } void last_matrix_activity_trigger(void) { - last_matrix_modification_time = last_input_modification_time = timer_read32(); + last_matrix_modification_time = last_input_modification_time = sync_timer_read32(); } static uint32_t last_encoder_modification_time = 0; @@ -133,10 +163,28 @@ uint32_t last_encoder_activity_time(void) { return last_encoder_modification_time; } uint32_t last_encoder_activity_elapsed(void) { - return timer_elapsed32(last_encoder_modification_time); + return sync_timer_elapsed32(last_encoder_modification_time); } void last_encoder_activity_trigger(void) { - last_encoder_modification_time = last_input_modification_time = timer_read32(); + last_encoder_modification_time = last_input_modification_time = sync_timer_read32(); +} + +static uint32_t last_pointing_device_modification_time = 0; +uint32_t last_pointing_device_activity_time(void) { + return last_pointing_device_modification_time; +} +uint32_t last_pointing_device_activity_elapsed(void) { + return sync_timer_elapsed32(last_pointing_device_modification_time); +} +void last_pointing_device_activity_trigger(void) { + last_pointing_device_modification_time = last_input_modification_time = sync_timer_read32(); +} + +void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp) { + last_matrix_modification_time = matrix_timestamp; + last_encoder_modification_time = encoder_timestamp; + last_pointing_device_modification_time = pointing_device_timestamp; + last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp)); } // Only enable this if console is enabled to print to @@ -171,9 +219,9 @@ static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) { matrix_row_t out = 0; for (uint8_t col = 0; col < MATRIX_COLS; col++) { // read each key in the row data and check if the keymap defines it as a real key - if (keycode_at_keymap_location(0, row, col) && (rowdata & (1 << col))) { + if (keycode_at_keymap_location(0, row, col) && (rowdata & (((matrix_row_t)1) << col))) { // this creates new row data, if a key is defined in the keymap, it will be set here - out |= 1 << col; + out |= ((matrix_row_t)1) << col; } } return out; @@ -444,7 +492,7 @@ static inline void generate_tick_event(void) { static uint16_t last_tick = 0; const uint16_t now = timer_read(); if (TIMER_DIFF_16(now, last_tick) != 0) { - action_exec(TICK_EVENT); + action_exec(MAKE_TICK_EVENT); last_tick = now; } } @@ -592,9 +640,10 @@ void quantum_task(void) { /** \brief Main task that is repeatedly called as fast as possible. */ void keyboard_task(void) { - const bool matrix_changed = matrix_task(); - if (matrix_changed) { + __attribute__((unused)) bool activity_has_occurred = false; + if (matrix_task()) { last_matrix_activity_trigger(); + activity_has_occurred = true; } quantum_task(); @@ -621,9 +670,16 @@ void keyboard_task(void) { #endif #ifdef ENCODER_ENABLE - const bool encoders_changed = encoder_read(); - if (encoders_changed) { + if (encoder_read()) { last_encoder_activity_trigger(); + activity_has_occurred = true; + } +#endif + +#ifdef POINTING_DEVICE_ENABLE + if (pointing_device_task()) { + last_pointing_device_activity_trigger(); + activity_has_occurred = true; } #endif @@ -631,11 +687,7 @@ void keyboard_task(void) { oled_task(); # if OLED_TIMEOUT > 0 // Wake up oled if user is using those fabulous keys or spinning those encoders! -# ifdef ENCODER_ENABLE - if (matrix_changed || encoders_changed) oled_on(); -# else - if (matrix_changed) oled_on(); -# endif + if (activity_has_occurred) oled_on(); # endif #endif @@ -643,11 +695,7 @@ void keyboard_task(void) { st7565_task(); # if ST7565_TIMEOUT > 0 // Wake up display if user is using those fabulous keys or spinning those encoders! -# ifdef ENCODER_ENABLE - if (matrix_changed || encoders_changed) st7565_on(); -# else - if (matrix_changed) st7565_on(); -# endif + if (activity_has_occurred) st7565_on(); # endif #endif @@ -660,10 +708,6 @@ void keyboard_task(void) { ps2_mouse_task(); #endif -#ifdef POINTING_DEVICE_ENABLE - pointing_device_task(); -#endif - #ifdef MIDI_ENABLE midi_task(); #endif diff --git a/quantum/keyboard.h b/quantum/keyboard.h index d0b52dd13a0d..5ea57815a719 100644 --- a/quantum/keyboard.h +++ b/quantum/keyboard.h @@ -20,6 +20,8 @@ along with this program. If not, see . #include #include +#include "timer.h" + #ifdef __cplusplus extern "C" { #endif @@ -30,65 +32,64 @@ typedef struct { uint8_t row; } keypos_t; +typedef enum keyevent_type_t { TICK_EVENT = 0, KEY_EVENT = 1, ENCODER_CW_EVENT = 2, ENCODER_CCW_EVENT = 3, COMBO_EVENT = 4 } keyevent_type_t; + /* key event */ typedef struct { - keypos_t key; - bool pressed; - uint16_t time; + keypos_t key; + uint16_t time; + keyevent_type_t type; + bool pressed; } keyevent_t; /* equivalent test of keypos_t */ #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) /* special keypos_t entries */ -#define KEYLOC_TICK 255 -#define KEYLOC_COMBO 254 #define KEYLOC_ENCODER_CW 253 #define KEYLOC_ENCODER_CCW 252 -/* Rules for No Event: - * 1) (time == 0) to handle (keyevent_t){} as empty event - * 2) Matrix(255, 255) to make TICK event available - */ -static inline bool IS_NOEVENT(keyevent_t event) { - return event.time == 0 || (event.key.row == KEYLOC_TICK && event.key.col == KEYLOC_TICK); +static inline bool IS_NOEVENT(const keyevent_t event) { + return event.type == TICK_EVENT; } -static inline bool IS_EVENT(keyevent_t event) { - return !IS_NOEVENT(event); +static inline bool IS_EVENT(const keyevent_t event) { + return event.type != TICK_EVENT; } -static inline bool IS_KEYEVENT(keyevent_t event) { - return event.key.row < MATRIX_ROWS && event.key.col < MATRIX_COLS; +static inline bool IS_KEYEVENT(const keyevent_t event) { + return event.type == KEY_EVENT; } -static inline bool IS_COMBOEVENT(keyevent_t event) { - return event.key.row == KEYLOC_COMBO; +static inline bool IS_COMBOEVENT(const keyevent_t event) { + return event.type == COMBO_EVENT; } -static inline bool IS_ENCODEREVENT(keyevent_t event) { - return event.key.row == KEYLOC_ENCODER_CW || event.key.row == KEYLOC_ENCODER_CCW; -} -static inline bool IS_PRESSED(keyevent_t event) { - return IS_EVENT(event) && event.pressed; -} -static inline bool IS_RELEASED(keyevent_t event) { - return IS_EVENT(event) && !event.pressed; +static inline bool IS_ENCODEREVENT(const keyevent_t event) { + return event.type == ENCODER_CW_EVENT || event.type == ENCODER_CCW_EVENT; } -/* Common keyevent object factory */ +/* Common keypos_t object factory */ #define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)}) +/* Common keyevent_t object factory */ +#define MAKE_EVENT(row_num, col_num, press, event_type) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = timer_read(), .type = (event_type)}) + /** * @brief Constructs a key event for a pressed or released key. */ -#define MAKE_KEYEVENT(row_num, col_num, press) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = (timer_read() | 1)}) +#define MAKE_KEYEVENT(row_num, col_num, press) MAKE_EVENT((row_num), (col_num), (press), KEY_EVENT) + +/** + * @brief Constructs a combo event. + */ +#define MAKE_COMBOEVENT(press) MAKE_EVENT(0, 0, (press), COMBO_EVENT) /** * @brief Constructs a internal tick event that is used to drive the internal QMK state machine. */ -#define TICK_EVENT MAKE_KEYEVENT(KEYLOC_TICK, KEYLOC_TICK, false) +#define MAKE_TICK_EVENT MAKE_EVENT(0, 0, false, TICK_EVENT) #ifdef ENCODER_MAP_ENABLE /* Encoder events */ -# define ENCODER_CW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CW, (enc_id), (press)) -# define ENCODER_CCW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CCW, (enc_id), (press)) +# define MAKE_ENCODER_CW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CW, (enc_id), (press), ENCODER_CW_EVENT) +# define MAKE_ENCODER_CCW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CCW, (enc_id), (press), ENCODER_CCW_EVENT) #endif // ENCODER_MAP_ENABLE /* it runs once at early stage of startup before keyboard_init. */ @@ -111,8 +112,8 @@ void housekeeping_task(void); // To be executed by the main loop in each ba void housekeeping_task_kb(void); // To be overridden by keyboard-level code void housekeeping_task_user(void); // To be overridden by user/keymap-level code -uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity -uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity +uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder or pointing device activity +uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder or pointing device activity uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity @@ -120,6 +121,11 @@ uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity +uint32_t last_pointing_device_activity_time(void); // Timestamp of the last pointing device activity +uint32_t last_pointing_device_activity_elapsed(void); // Number of milliseconds since the last pointing device activity + +void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp); // Set the timestamps of the last matrix and encoder activity + uint32_t get_matrix_scan_rate(void); #ifdef __cplusplus diff --git a/quantum/keycode.h b/quantum/keycode.h index 701c078ad00b..df1452d2965c 100644 --- a/quantum/keycode.h +++ b/quantum/keycode.h @@ -34,26 +34,10 @@ along with this program. If not, see . #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) -#define MOD_BIT(code) (1 << MOD_INDEX(code)) -#define MOD_INDEX(code) ((code)&0x07) - -#define MOD_MASK_CTRL (MOD_BIT(KC_LEFT_CTRL) | MOD_BIT(KC_RIGHT_CTRL)) -#define MOD_MASK_SHIFT (MOD_BIT(KC_LEFT_SHIFT) | MOD_BIT(KC_RIGHT_SHIFT)) -#define MOD_MASK_ALT (MOD_BIT(KC_LEFT_ALT) | MOD_BIT(KC_RIGHT_ALT)) -#define MOD_MASK_GUI (MOD_BIT(KC_LEFT_GUI) | MOD_BIT(KC_RIGHT_GUI)) -#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) -#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) -#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) -#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) -#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) -#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) -#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) -#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) -#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) -#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) -#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_BIT(code) (1 << ((code)&0x07)) // clang-format off // TODO: dd keycodes #include "keycodes.h" +#include "modifiers.h" diff --git a/quantum/keycode_config.c b/quantum/keycode_config.c index 9dd7097c861a..864488a65c97 100644 --- a/quantum/keycode_config.c +++ b/quantum/keycode_config.c @@ -122,40 +122,36 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) { */ __attribute__((weak)) uint8_t mod_config(uint8_t mod) { + /** + * Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods. + * More info about the mods can be seen in modifiers.h. + */ if (keymap_config.swap_lalt_lgui) { - if ((mod & MOD_RGUI) == MOD_LGUI) { - mod &= ~MOD_LGUI; - mod |= MOD_LALT; - } else if ((mod & MOD_RALT) == MOD_LALT) { - mod &= ~MOD_LALT; - mod |= MOD_LGUI; + /** If both modifiers pressed or neither pressed, do nothing + * Otherwise swap the values + * Note: The left mods are ANDed with the right-hand values to check + * if they were pressed with the right hand bit set + */ + if (((mod & MOD_RALT) == MOD_LALT) ^ ((mod & MOD_RGUI) == MOD_LGUI)) { + mod ^= (MOD_LALT | MOD_LGUI); } } if (keymap_config.swap_ralt_rgui) { - if ((mod & MOD_RGUI) == MOD_RGUI) { - mod &= ~MOD_RGUI; - mod |= MOD_RALT; - } else if ((mod & MOD_RALT) == MOD_RALT) { - mod &= ~MOD_RALT; - mod |= MOD_RGUI; + if (((mod & MOD_RALT) == MOD_RALT) ^ ((mod & MOD_RGUI) == MOD_RGUI)) { + /* lefthand values to preserve the right hand bit */ + mod ^= (MOD_LALT | MOD_LGUI); } } if (keymap_config.swap_lctl_lgui) { - if ((mod & MOD_RGUI) == MOD_LGUI) { - mod &= ~MOD_LGUI; - mod |= MOD_LCTL; - } else if ((mod & MOD_RCTL) == MOD_LCTL) { - mod &= ~MOD_LCTL; - mod |= MOD_LGUI; + /* left mods ANDed with right-hand values to check for right hand bit */ + if (((mod & MOD_RCTL) == MOD_LCTL) ^ ((mod & MOD_RGUI) == MOD_LGUI)) { + mod ^= (MOD_LCTL | MOD_LGUI); } } if (keymap_config.swap_rctl_rgui) { - if ((mod & MOD_RGUI) == MOD_RGUI) { - mod &= ~MOD_RGUI; - mod |= MOD_RCTL; - } else if ((mod & MOD_RCTL) == MOD_RCTL) { - mod &= ~MOD_RCTL; - mod |= MOD_RGUI; + if (((mod & MOD_RCTL) == MOD_RCTL) ^ ((mod & MOD_RGUI) == MOD_RGUI)) { + /* lefthand values to preserve the right hand bit */ + mod ^= (MOD_LCTL | MOD_LGUI); } } if (keymap_config.no_gui) { diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index eef048d95cdd..d1352c302ea0 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -16,6 +16,10 @@ #pragma once +#ifdef __cplusplus +# define _Static_assert static_assert +#endif + #include "eeconfig.h" #include "keycode.h" #include "action_code.h" @@ -43,4 +47,6 @@ typedef union { }; } keymap_config_t; +_Static_assert(sizeof(keymap_config_t) == sizeof(uint16_t), "Keycode (magic) EECONFIG out of spec."); + extern keymap_config_t keymap_config; diff --git a/quantum/keycodes.h b/quantum/keycodes.h index 34b13c29af52..bbf10da36d97 100644 --- a/quantum/keycodes.h +++ b/quantum/keycodes.h @@ -721,6 +721,8 @@ enum qk_keycode_defines { QK_AUTOCORRECT_TOGGLE = 0x7C76, QK_TRI_LAYER_LOWER = 0x7C77, QK_TRI_LAYER_UPPER = 0x7C78, + QK_REPEAT_KEY = 0x7C79, + QK_ALT_REPEAT_KEY = 0x7C7A, QK_KB_0 = 0x7E00, QK_KB_1 = 0x7E01, QK_KB_2 = 0x7E02, @@ -1362,6 +1364,8 @@ enum qk_keycode_defines { AC_TOGG = QK_AUTOCORRECT_TOGGLE, TL_LOWR = QK_TRI_LAYER_LOWER, TL_UPPR = QK_TRI_LAYER_UPPER, + QK_REP = QK_REPEAT_KEY, + QK_AREP = QK_ALT_REPEAT_KEY, }; // Range Helpers @@ -1413,6 +1417,6 @@ enum qk_keycode_defines { #define IS_MACRO_KEYCODE(code) ((code) >= QK_MACRO_0 && (code) <= QK_MACRO_31) #define IS_BACKLIGHT_KEYCODE(code) ((code) >= QK_BACKLIGHT_ON && (code) <= QK_BACKLIGHT_TOGGLE_BREATHING) #define IS_RGB_KEYCODE(code) ((code) >= RGB_TOG && (code) <= RGB_MODE_TWINKLE) -#define IS_QUANTUM_KEYCODE(code) ((code) >= QK_BOOTLOADER && (code) <= QK_TRI_LAYER_UPPER) +#define IS_QUANTUM_KEYCODE(code) ((code) >= QK_BOOTLOADER && (code) <= QK_ALT_REPEAT_KEY) #define IS_KB_KEYCODE(code) ((code) >= QK_KB_0 && (code) <= QK_KB_31) #define IS_USER_KEYCODE(code) ((code) >= QK_USER_0 && (code) <= QK_USER_31) diff --git a/quantum/keymap.h b/quantum/keymap.h deleted file mode 100644 index 0225f533626a..000000000000 --- a/quantum/keymap.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2012-2016 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#include -#include -#include "platform_deps.h" -#include "action.h" -#include "keycode.h" -#include "report.h" -#include "host.h" -#include "debug.h" -#include "keycode_config.h" -#include "gpio.h" // for pin_t - -#include "quantum_keycodes.h" - -// translates key to keycode -uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); - -#ifdef ENCODER_MAP_ENABLE -// Ensure we have a forward declaration for the encoder map -# include "encoder.h" -#endif - -#include "keymap_introspection.h" diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 6fcebc3242f9..9a67fad278c2 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -15,13 +15,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "keymap.h" +#include "keymap_common.h" +#include "keymap_introspection.h" #include "report.h" #include "keycode.h" #include "action_layer.h" #include "action.h" #include "debug.h" -#include "quantum.h" +#include "keycode_config.h" +#include "quantum_keycodes.h" + +#ifdef ENCODER_MAP_ENABLE +# include "encoder.h" +#endif #ifdef BACKLIGHT_ENABLE # include "backlight.h" diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h new file mode 100644 index 000000000000..fca4fc9ba334 --- /dev/null +++ b/quantum/keymap_common.h @@ -0,0 +1,10 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include "keyboard.h" + +// translates key to keycode +uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); diff --git a/quantum/keymap_extras/keymap_belgian.h b/quantum/keymap_extras/keymap_belgian.h index 1bf9549c5a7d..6851c6b4e82e 100644 --- a/quantum/keymap_extras/keymap_belgian.h +++ b/quantum/keymap_extras/keymap_belgian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_bepo.h b/quantum/keymap_extras/keymap_bepo.h index 12026ce6496f..448727deceac 100644 --- a/quantum/keymap_extras/keymap_bepo.h +++ b/quantum/keymap_extras/keymap_bepo.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_brazilian_abnt2.h b/quantum/keymap_extras/keymap_brazilian_abnt2.h index 70a09a52beb1..8fac7666c2ac 100644 --- a/quantum/keymap_extras/keymap_brazilian_abnt2.h +++ b/quantum/keymap_extras/keymap_brazilian_abnt2.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_canadian_multilingual.h b/quantum/keymap_extras/keymap_canadian_multilingual.h index 44009f3aa2b6..5b9b03babb1d 100644 --- a/quantum/keymap_extras/keymap_canadian_multilingual.h +++ b/quantum/keymap_extras/keymap_canadian_multilingual.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_colemak.h b/quantum/keymap_extras/keymap_colemak.h index 5cb86bf441e2..d63309f010b6 100644 --- a/quantum/keymap_extras/keymap_colemak.h +++ b/quantum/keymap_extras/keymap_colemak.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_croatian.h b/quantum/keymap_extras/keymap_croatian.h index 1115592e17e8..3e7c681ced91 100644 --- a/quantum/keymap_extras/keymap_croatian.h +++ b/quantum/keymap_extras/keymap_croatian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_czech.h b/quantum/keymap_extras/keymap_czech.h index 02692002e310..351c51ad411b 100644 --- a/quantum/keymap_extras/keymap_czech.h +++ b/quantum/keymap_extras/keymap_czech.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_danish.h b/quantum/keymap_extras/keymap_danish.h index 18107ccd53b1..cea9444896b3 100644 --- a/quantum/keymap_extras/keymap_danish.h +++ b/quantum/keymap_extras/keymap_danish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_dvorak.h b/quantum/keymap_extras/keymap_dvorak.h index 5767530b3bf1..9205a72057f5 100644 --- a/quantum/keymap_extras/keymap_dvorak.h +++ b/quantum/keymap_extras/keymap_dvorak.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_dvorak_fr.h b/quantum/keymap_extras/keymap_dvorak_fr.h index 60675fbf1338..b206767614e9 100644 --- a/quantum/keymap_extras/keymap_dvorak_fr.h +++ b/quantum/keymap_extras/keymap_dvorak_fr.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_dvorak_programmer.h b/quantum/keymap_extras/keymap_dvorak_programmer.h index 6e1ae17807d4..19187ed13b09 100644 --- a/quantum/keymap_extras/keymap_dvorak_programmer.h +++ b/quantum/keymap_extras/keymap_dvorak_programmer.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_estonian.h b/quantum/keymap_extras/keymap_estonian.h index 462bcde429a9..ea9c56c12ac5 100644 --- a/quantum/keymap_extras/keymap_estonian.h +++ b/quantum/keymap_extras/keymap_estonian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_finnish.h b/quantum/keymap_extras/keymap_finnish.h index 7e94896e2e88..c0dc1af81ec2 100644 --- a/quantum/keymap_extras/keymap_finnish.h +++ b/quantum/keymap_extras/keymap_finnish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_french.h b/quantum/keymap_extras/keymap_french.h index da9467a475dd..03dbb7bc40d0 100644 --- a/quantum/keymap_extras/keymap_french.h +++ b/quantum/keymap_extras/keymap_french.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_french_afnor.h b/quantum/keymap_extras/keymap_french_afnor.h index 259e0a30f462..869984c4d2e1 100644 --- a/quantum/keymap_extras/keymap_french_afnor.h +++ b/quantum/keymap_extras/keymap_french_afnor.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_french_mac_iso.h b/quantum/keymap_extras/keymap_french_mac_iso.h index 9a8ed726045c..e5f7514a8026 100644 --- a/quantum/keymap_extras/keymap_french_mac_iso.h +++ b/quantum/keymap_extras/keymap_french_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_german.h b/quantum/keymap_extras/keymap_german.h index 251491fb8161..38b0c685ba67 100644 --- a/quantum/keymap_extras/keymap_german.h +++ b/quantum/keymap_extras/keymap_german.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_german_mac_iso.h b/quantum/keymap_extras/keymap_german_mac_iso.h index de7b60546b73..efa9099f2011 100644 --- a/quantum/keymap_extras/keymap_german_mac_iso.h +++ b/quantum/keymap_extras/keymap_german_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_greek.h b/quantum/keymap_extras/keymap_greek.h index b4f5b5c5b31a..01779cf2e859 100644 --- a/quantum/keymap_extras/keymap_greek.h +++ b/quantum/keymap_extras/keymap_greek.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_hebrew.h b/quantum/keymap_extras/keymap_hebrew.h index 372d7f2e9386..284562072dc6 100644 --- a/quantum/keymap_extras/keymap_hebrew.h +++ b/quantum/keymap_extras/keymap_hebrew.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_hungarian.h b/quantum/keymap_extras/keymap_hungarian.h index 591d71c09cb3..fbc31ed15562 100644 --- a/quantum/keymap_extras/keymap_hungarian.h +++ b/quantum/keymap_extras/keymap_hungarian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_icelandic.h b/quantum/keymap_extras/keymap_icelandic.h index 800899b51521..3bd71c19f280 100644 --- a/quantum/keymap_extras/keymap_icelandic.h +++ b/quantum/keymap_extras/keymap_icelandic.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_irish.h b/quantum/keymap_extras/keymap_irish.h index 2cd63a48e3b8..6e161628c864 100644 --- a/quantum/keymap_extras/keymap_irish.h +++ b/quantum/keymap_extras/keymap_irish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_italian.h b/quantum/keymap_extras/keymap_italian.h index 95f3348f63ac..8092dc130188 100644 --- a/quantum/keymap_extras/keymap_italian.h +++ b/quantum/keymap_extras/keymap_italian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_italian_mac_ansi.h b/quantum/keymap_extras/keymap_italian_mac_ansi.h index 5e7e2a37e873..ae1281be262b 100644 --- a/quantum/keymap_extras/keymap_italian_mac_ansi.h +++ b/quantum/keymap_extras/keymap_italian_mac_ansi.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_italian_mac_iso.h b/quantum/keymap_extras/keymap_italian_mac_iso.h index 1d30451376ea..f3f01839c32a 100644 --- a/quantum/keymap_extras/keymap_italian_mac_iso.h +++ b/quantum/keymap_extras/keymap_italian_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_japanese.h b/quantum/keymap_extras/keymap_japanese.h index 286863deea74..947317833ed2 100644 --- a/quantum/keymap_extras/keymap_japanese.h +++ b/quantum/keymap_extras/keymap_japanese.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_korean.h b/quantum/keymap_extras/keymap_korean.h index 073647de7f43..440a6b3b4dfc 100644 --- a/quantum/keymap_extras/keymap_korean.h +++ b/quantum/keymap_extras/keymap_korean.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_latvian.h b/quantum/keymap_extras/keymap_latvian.h index e3ac1cd433c3..2f26b1d8afa5 100644 --- a/quantum/keymap_extras/keymap_latvian.h +++ b/quantum/keymap_extras/keymap_latvian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_lithuanian_azerty.h b/quantum/keymap_extras/keymap_lithuanian_azerty.h index 11de3ad03073..f6dd94f0ca77 100644 --- a/quantum/keymap_extras/keymap_lithuanian_azerty.h +++ b/quantum/keymap_extras/keymap_lithuanian_azerty.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_lithuanian_qwerty.h b/quantum/keymap_extras/keymap_lithuanian_qwerty.h index c27389971e54..03c6b7a2af5c 100644 --- a/quantum/keymap_extras/keymap_lithuanian_qwerty.h +++ b/quantum/keymap_extras/keymap_lithuanian_qwerty.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_neo2.h b/quantum/keymap_extras/keymap_neo2.h index e8352ffa08a5..bc9445892f9a 100644 --- a/quantum/keymap_extras/keymap_neo2.h +++ b/quantum/keymap_extras/keymap_neo2.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_nordic.h b/quantum/keymap_extras/keymap_nordic.h index e3369167130c..6464966c7119 100644 --- a/quantum/keymap_extras/keymap_nordic.h +++ b/quantum/keymap_extras/keymap_nordic.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_norman.h b/quantum/keymap_extras/keymap_norman.h index 1f773bb4107d..1a3a0bc53a42 100644 --- a/quantum/keymap_extras/keymap_norman.h +++ b/quantum/keymap_extras/keymap_norman.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_norwegian.h b/quantum/keymap_extras/keymap_norwegian.h index 33193d6a4d4c..af16fec8d6a1 100644 --- a/quantum/keymap_extras/keymap_norwegian.h +++ b/quantum/keymap_extras/keymap_norwegian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_plover.h b/quantum/keymap_extras/keymap_plover.h index b51e44b8bbc3..c0e3311e90bf 100644 --- a/quantum/keymap_extras/keymap_plover.h +++ b/quantum/keymap_extras/keymap_plover.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_plover_dvorak.h b/quantum/keymap_extras/keymap_plover_dvorak.h index f8341f8cbcab..7feb52a25c7b 100644 --- a/quantum/keymap_extras/keymap_plover_dvorak.h +++ b/quantum/keymap_extras/keymap_plover_dvorak.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_polish.h b/quantum/keymap_extras/keymap_polish.h index 6b37d77a0aa8..40870ec2378d 100644 --- a/quantum/keymap_extras/keymap_polish.h +++ b/quantum/keymap_extras/keymap_polish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_portuguese.h b/quantum/keymap_extras/keymap_portuguese.h index 17da9a6c117f..b4570ad922d0 100644 --- a/quantum/keymap_extras/keymap_portuguese.h +++ b/quantum/keymap_extras/keymap_portuguese.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_portuguese_mac_iso.h b/quantum/keymap_extras/keymap_portuguese_mac_iso.h index 3d34a39ae5f3..57a27d04e9b6 100644 --- a/quantum/keymap_extras/keymap_portuguese_mac_iso.h +++ b/quantum/keymap_extras/keymap_portuguese_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_romanian.h b/quantum/keymap_extras/keymap_romanian.h index fb48a0fda788..cf4c17125f13 100644 --- a/quantum/keymap_extras/keymap_romanian.h +++ b/quantum/keymap_extras/keymap_romanian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_russian.h b/quantum/keymap_extras/keymap_russian.h index 36437184448a..fd3a1604c8e0 100644 --- a/quantum/keymap_extras/keymap_russian.h +++ b/quantum/keymap_extras/keymap_russian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_serbian.h b/quantum/keymap_extras/keymap_serbian.h index dd1bda753318..732e2e939d1e 100644 --- a/quantum/keymap_extras/keymap_serbian.h +++ b/quantum/keymap_extras/keymap_serbian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_serbian_latin.h b/quantum/keymap_extras/keymap_serbian_latin.h index 83495b63bead..5151696a1031 100644 --- a/quantum/keymap_extras/keymap_serbian_latin.h +++ b/quantum/keymap_extras/keymap_serbian_latin.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_slovak.h b/quantum/keymap_extras/keymap_slovak.h index 10714f1be925..81a88fa25c0e 100644 --- a/quantum/keymap_extras/keymap_slovak.h +++ b/quantum/keymap_extras/keymap_slovak.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_slovenian.h b/quantum/keymap_extras/keymap_slovenian.h index 30910530e00f..1e17342c2734 100644 --- a/quantum/keymap_extras/keymap_slovenian.h +++ b/quantum/keymap_extras/keymap_slovenian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_spanish.h b/quantum/keymap_extras/keymap_spanish.h index cac16c08a595..bcdd5af0c257 100644 --- a/quantum/keymap_extras/keymap_spanish.h +++ b/quantum/keymap_extras/keymap_spanish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_spanish_dvorak.h b/quantum/keymap_extras/keymap_spanish_dvorak.h index 1feab96b8c39..fb033df770a1 100644 --- a/quantum/keymap_extras/keymap_spanish_dvorak.h +++ b/quantum/keymap_extras/keymap_spanish_dvorak.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_steno.h b/quantum/keymap_extras/keymap_steno.h index 07d96b746563..852b2f71211d 100644 --- a/quantum/keymap_extras/keymap_steno.h +++ b/quantum/keymap_extras/keymap_steno.h @@ -16,7 +16,7 @@ #pragma once -#include "keymap.h" +#include "keycodes.h" // List of keycodes for the steno keyboard. To prevent // errors, this must be <= 42 total entries in order to diff --git a/quantum/keymap_extras/keymap_swedish.h b/quantum/keymap_extras/keymap_swedish.h index 4cdf4879c3ca..acb49f77738b 100644 --- a/quantum/keymap_extras/keymap_swedish.h +++ b/quantum/keymap_extras/keymap_swedish.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_swedish_mac_ansi.h b/quantum/keymap_extras/keymap_swedish_mac_ansi.h index 9649f59dd086..ef48a9e493e4 100644 --- a/quantum/keymap_extras/keymap_swedish_mac_ansi.h +++ b/quantum/keymap_extras/keymap_swedish_mac_ansi.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_swedish_mac_iso.h b/quantum/keymap_extras/keymap_swedish_mac_iso.h index 068c81b020e5..2eaef5e60ca5 100644 --- a/quantum/keymap_extras/keymap_swedish_mac_iso.h +++ b/quantum/keymap_extras/keymap_swedish_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_swedish_pro_mac_ansi.h b/quantum/keymap_extras/keymap_swedish_pro_mac_ansi.h index c0692ababde6..d33a25902354 100644 --- a/quantum/keymap_extras/keymap_swedish_pro_mac_ansi.h +++ b/quantum/keymap_extras/keymap_swedish_pro_mac_ansi.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_swedish_pro_mac_iso.h b/quantum/keymap_extras/keymap_swedish_pro_mac_iso.h index e01f0a7dc395..680bd1db9e26 100644 --- a/quantum/keymap_extras/keymap_swedish_pro_mac_iso.h +++ b/quantum/keymap_extras/keymap_swedish_pro_mac_iso.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_swiss_de.h b/quantum/keymap_extras/keymap_swiss_de.h index 0a6e6e49184c..c22191dd4e7a 100644 --- a/quantum/keymap_extras/keymap_swiss_de.h +++ b/quantum/keymap_extras/keymap_swiss_de.h @@ -24,9 +24,11 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off +#undef CH_H + // Aliases #define CH_SECT KC_GRV // § #define CH_1 KC_1 // 1 diff --git a/quantum/keymap_extras/keymap_swiss_fr.h b/quantum/keymap_extras/keymap_swiss_fr.h index 05a4a4c279d8..e0e8e52c9cef 100644 --- a/quantum/keymap_extras/keymap_swiss_fr.h +++ b/quantum/keymap_extras/keymap_swiss_fr.h @@ -24,9 +24,11 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off +#undef CH_H + // Aliases #define CH_SECT KC_GRV // § #define CH_1 KC_1 // 1 diff --git a/quantum/keymap_extras/keymap_turkish_f.h b/quantum/keymap_extras/keymap_turkish_f.h index 0dfc0236e80b..4fdcf3f7462c 100644 --- a/quantum/keymap_extras/keymap_turkish_f.h +++ b/quantum/keymap_extras/keymap_turkish_f.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_turkish_q.h b/quantum/keymap_extras/keymap_turkish_q.h index cc64300b1892..5a9362acb4c8 100644 --- a/quantum/keymap_extras/keymap_turkish_q.h +++ b/quantum/keymap_extras/keymap_turkish_q.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_uk.h b/quantum/keymap_extras/keymap_uk.h index ff6f8c9c2eaf..71e5f38f55a9 100644 --- a/quantum/keymap_extras/keymap_uk.h +++ b/quantum/keymap_extras/keymap_uk.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_ukrainian.h b/quantum/keymap_extras/keymap_ukrainian.h index b954bb239877..3f3ec4cec2b5 100644 --- a/quantum/keymap_extras/keymap_ukrainian.h +++ b/quantum/keymap_extras/keymap_ukrainian.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_us.h b/quantum/keymap_extras/keymap_us.h index 38df8c633666..6101c8d8ba88 100644 --- a/quantum/keymap_extras/keymap_us.h +++ b/quantum/keymap_extras/keymap_us.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_us_extended.h b/quantum/keymap_extras/keymap_us_extended.h index c4f627c30d7d..90da98c756a7 100644 --- a/quantum/keymap_extras/keymap_us_extended.h +++ b/quantum/keymap_extras/keymap_us_extended.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_us_international.h b/quantum/keymap_extras/keymap_us_international.h index 1f2bc3347609..bd5f21ec8c60 100644 --- a/quantum/keymap_extras/keymap_us_international.h +++ b/quantum/keymap_extras/keymap_us_international.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_us_international_linux.h b/quantum/keymap_extras/keymap_us_international_linux.h index 16d072cc5b9e..4551cbe29ffa 100644 --- a/quantum/keymap_extras/keymap_us_international_linux.h +++ b/quantum/keymap_extras/keymap_us_international_linux.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_workman.h b/quantum/keymap_extras/keymap_workman.h index 5fe9d36b1610..808caec054cd 100644 --- a/quantum/keymap_extras/keymap_workman.h +++ b/quantum/keymap_extras/keymap_workman.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/keymap_workman_zxcvm.h b/quantum/keymap_extras/keymap_workman_zxcvm.h index 757f98e912dd..f8645ac4cfbe 100644 --- a/quantum/keymap_extras/keymap_workman_zxcvm.h +++ b/quantum/keymap_extras/keymap_workman_zxcvm.h @@ -24,7 +24,7 @@ *******************************************************************************/ #pragma once -#include "keymap.h" +#include "keycodes.h" // clang-format off // Aliases diff --git a/quantum/keymap_extras/sendstring_belgian.h b/quantum/keymap_extras/sendstring_belgian.h index 9ff92f010d3f..2a40cef3fc68 100644 --- a/quantum/keymap_extras/sendstring_belgian.h +++ b/quantum/keymap_extras/sendstring_belgian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_belgian.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_bepo.h b/quantum/keymap_extras/sendstring_bepo.h index be442070dc3d..aa7b82c950ec 100644 --- a/quantum/keymap_extras/sendstring_bepo.h +++ b/quantum/keymap_extras/sendstring_bepo.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_bepo.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_brazilian_abnt2.h b/quantum/keymap_extras/sendstring_brazilian_abnt2.h index b52ce4958ab7..ca908353ab4c 100644 --- a/quantum/keymap_extras/sendstring_brazilian_abnt2.h +++ b/quantum/keymap_extras/sendstring_brazilian_abnt2.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_brazilian_abnt2.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_canadian_multilingual.h b/quantum/keymap_extras/sendstring_canadian_multilingual.h index 92b588c82e40..63bca96de9e3 100644 --- a/quantum/keymap_extras/sendstring_canadian_multilingual.h +++ b/quantum/keymap_extras/sendstring_canadian_multilingual.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_canadian_multilingual.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_colemak.h b/quantum/keymap_extras/sendstring_colemak.h index 8564ec1dea7a..58a002171b9e 100644 --- a/quantum/keymap_extras/sendstring_colemak.h +++ b/quantum/keymap_extras/sendstring_colemak.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_colemak.h" const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_croatian.h b/quantum/keymap_extras/sendstring_croatian.h index bf51c81a8842..e43b54713d4a 100644 --- a/quantum/keymap_extras/sendstring_croatian.h +++ b/quantum/keymap_extras/sendstring_croatian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_croatian.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_czech.h b/quantum/keymap_extras/sendstring_czech.h index 03ae74dd6cd5..0df5120c9329 100644 --- a/quantum/keymap_extras/sendstring_czech.h +++ b/quantum/keymap_extras/sendstring_czech.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_czech.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_danish.h b/quantum/keymap_extras/sendstring_danish.h index 0ec5b108a576..cbec654fa2e6 100644 --- a/quantum/keymap_extras/sendstring_danish.h +++ b/quantum/keymap_extras/sendstring_danish.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_danish.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_dvorak.h b/quantum/keymap_extras/sendstring_dvorak.h index 3ddb00b11261..2edeb284678f 100644 --- a/quantum/keymap_extras/sendstring_dvorak.h +++ b/quantum/keymap_extras/sendstring_dvorak.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_dvorak.h" const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_dvorak_fr.h b/quantum/keymap_extras/sendstring_dvorak_fr.h index 98d0577afa72..0031c0e29132 100644 --- a/quantum/keymap_extras/sendstring_dvorak_fr.h +++ b/quantum/keymap_extras/sendstring_dvorak_fr.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_dvorak_fr.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_dvorak_programmer.h b/quantum/keymap_extras/sendstring_dvorak_programmer.h index f19bb6f4b215..372ee5726b32 100644 --- a/quantum/keymap_extras/sendstring_dvorak_programmer.h +++ b/quantum/keymap_extras/sendstring_dvorak_programmer.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_dvorak_programmer.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_estonian.h b/quantum/keymap_extras/sendstring_estonian.h index 24d853fb5960..1bfe31f2421c 100644 --- a/quantum/keymap_extras/sendstring_estonian.h +++ b/quantum/keymap_extras/sendstring_estonian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_estonian.h" -#include "quantum" // clang-format off diff --git a/quantum/keymap_extras/sendstring_finnish.h b/quantum/keymap_extras/sendstring_finnish.h index cf23483843fa..34b59f150c1d 100644 --- a/quantum/keymap_extras/sendstring_finnish.h +++ b/quantum/keymap_extras/sendstring_finnish.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_finnish.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_french.h b/quantum/keymap_extras/sendstring_french.h index 9b7f5e8ed7b1..cfa8e0499209 100644 --- a/quantum/keymap_extras/sendstring_french.h +++ b/quantum/keymap_extras/sendstring_french.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_french.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_french_afnor.h b/quantum/keymap_extras/sendstring_french_afnor.h index 1408634a266b..55b90b32046e 100644 --- a/quantum/keymap_extras/sendstring_french_afnor.h +++ b/quantum/keymap_extras/sendstring_french_afnor.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_french_afnor.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_french_mac_iso.h b/quantum/keymap_extras/sendstring_french_mac_iso.h index 1033c3991fe4..9a1700789866 100644 --- a/quantum/keymap_extras/sendstring_french_mac_iso.h +++ b/quantum/keymap_extras/sendstring_french_mac_iso.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_french_mac_iso.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_german.h b/quantum/keymap_extras/sendstring_german.h index 639c22b3a76f..17fb67e9c2c4 100644 --- a/quantum/keymap_extras/sendstring_german.h +++ b/quantum/keymap_extras/sendstring_german.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_german.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_german_mac_iso.h b/quantum/keymap_extras/sendstring_german_mac_iso.h index 8345dbaaa145..711ba7d05bf0 100644 --- a/quantum/keymap_extras/sendstring_german_mac_iso.h +++ b/quantum/keymap_extras/sendstring_german_mac_iso.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_german_mac_iso.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_hungarian.h b/quantum/keymap_extras/sendstring_hungarian.h index 29dc3ccb8c08..fae40f6dea9e 100644 --- a/quantum/keymap_extras/sendstring_hungarian.h +++ b/quantum/keymap_extras/sendstring_hungarian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_hungarian.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_icelandic.h b/quantum/keymap_extras/sendstring_icelandic.h index 867eb8743c85..f87438a98bb0 100644 --- a/quantum/keymap_extras/sendstring_icelandic.h +++ b/quantum/keymap_extras/sendstring_icelandic.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_icelandic.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_italian.h b/quantum/keymap_extras/sendstring_italian.h index dad4902d34de..322da2ac1b81 100644 --- a/quantum/keymap_extras/sendstring_italian.h +++ b/quantum/keymap_extras/sendstring_italian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_italian.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_italian_mac_ansi.h b/quantum/keymap_extras/sendstring_italian_mac_ansi.h index 97b5164e23b3..2961316de692 100644 --- a/quantum/keymap_extras/sendstring_italian_mac_ansi.h +++ b/quantum/keymap_extras/sendstring_italian_mac_ansi.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_italian_mac_ansi.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_italian_mac_iso.h b/quantum/keymap_extras/sendstring_italian_mac_iso.h index d82e8bbddf1f..25eb2549bda1 100644 --- a/quantum/keymap_extras/sendstring_italian_mac_iso.h +++ b/quantum/keymap_extras/sendstring_italian_mac_iso.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_italian_mac_iso.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_japanese.h b/quantum/keymap_extras/sendstring_japanese.h index 13628d702388..043446acbf6e 100644 --- a/quantum/keymap_extras/sendstring_japanese.h +++ b/quantum/keymap_extras/sendstring_japanese.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_japanese.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_latvian.h b/quantum/keymap_extras/sendstring_latvian.h index 61f788693ce6..9a0cb72b69a6 100644 --- a/quantum/keymap_extras/sendstring_latvian.h +++ b/quantum/keymap_extras/sendstring_latvian.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_latvian.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_lithuanian_azerty.h b/quantum/keymap_extras/sendstring_lithuanian_azerty.h index 7498a3dc4def..05aa2887bcac 100644 --- a/quantum/keymap_extras/sendstring_lithuanian_azerty.h +++ b/quantum/keymap_extras/sendstring_lithuanian_azerty.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_lithuanian_azerty.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_lithuanian_qwerty.h b/quantum/keymap_extras/sendstring_lithuanian_qwerty.h index 69cb94de7135..676930e9d3cc 100644 --- a/quantum/keymap_extras/sendstring_lithuanian_qwerty.h +++ b/quantum/keymap_extras/sendstring_lithuanian_qwerty.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_lithuanian_qwerty.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_norman.h b/quantum/keymap_extras/sendstring_norman.h index e52afc2a6a47..778d7fc5facf 100644 --- a/quantum/keymap_extras/sendstring_norman.h +++ b/quantum/keymap_extras/sendstring_norman.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_norman.h" const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_norwegian.h b/quantum/keymap_extras/sendstring_norwegian.h index d3478f8301f5..846cf7d29e90 100644 --- a/quantum/keymap_extras/sendstring_norwegian.h +++ b/quantum/keymap_extras/sendstring_norwegian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_norwegian.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_portuguese.h b/quantum/keymap_extras/sendstring_portuguese.h index bec9b2c680c3..32250342d67d 100644 --- a/quantum/keymap_extras/sendstring_portuguese.h +++ b/quantum/keymap_extras/sendstring_portuguese.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_portuguese.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_portuguese_mac_iso.h b/quantum/keymap_extras/sendstring_portuguese_mac_iso.h index 5d43c66279be..cda5541a50fa 100644 --- a/quantum/keymap_extras/sendstring_portuguese_mac_iso.h +++ b/quantum/keymap_extras/sendstring_portuguese_mac_iso.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_portuguese_mac_iso.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_romanian.h b/quantum/keymap_extras/sendstring_romanian.h index 9b5bee4a13e6..16d913710230 100644 --- a/quantum/keymap_extras/sendstring_romanian.h +++ b/quantum/keymap_extras/sendstring_romanian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_romanian.h" -#include "quantum" // clang-format off diff --git a/quantum/keymap_extras/sendstring_serbian_latin.h b/quantum/keymap_extras/sendstring_serbian_latin.h index 40e2a9ea0c22..cd196e541335 100644 --- a/quantum/keymap_extras/sendstring_serbian_latin.h +++ b/quantum/keymap_extras/sendstring_serbian_latin.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_serbian_latin.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_slovak.h b/quantum/keymap_extras/sendstring_slovak.h index 72eeb86a5397..5aeb06a4a0cb 100644 --- a/quantum/keymap_extras/sendstring_slovak.h +++ b/quantum/keymap_extras/sendstring_slovak.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_slovak.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_slovenian.h b/quantum/keymap_extras/sendstring_slovenian.h index adf7ea47db99..d6b1a52d093b 100644 --- a/quantum/keymap_extras/sendstring_slovenian.h +++ b/quantum/keymap_extras/sendstring_slovenian.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_slovenian.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_spanish.h b/quantum/keymap_extras/sendstring_spanish.h index 03c8fe748369..eab78324d8e4 100644 --- a/quantum/keymap_extras/sendstring_spanish.h +++ b/quantum/keymap_extras/sendstring_spanish.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_spanish.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_spanish_dvorak.h b/quantum/keymap_extras/sendstring_spanish_dvorak.h index 87d582491c18..ff7015cc6f2d 100644 --- a/quantum/keymap_extras/sendstring_spanish_dvorak.h +++ b/quantum/keymap_extras/sendstring_spanish_dvorak.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_spanish_dvorak.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_swedish.h b/quantum/keymap_extras/sendstring_swedish.h index 8b07d423019c..ae9766b48a11 100644 --- a/quantum/keymap_extras/sendstring_swedish.h +++ b/quantum/keymap_extras/sendstring_swedish.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_swedish.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_swiss_de.h b/quantum/keymap_extras/sendstring_swiss_de.h index f6aa19210c63..b352ab0b379c 100644 --- a/quantum/keymap_extras/sendstring_swiss_de.h +++ b/quantum/keymap_extras/sendstring_swiss_de.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_swiss_de.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_swiss_fr.h b/quantum/keymap_extras/sendstring_swiss_fr.h index 665be6d7b469..1559b5efa43e 100644 --- a/quantum/keymap_extras/sendstring_swiss_fr.h +++ b/quantum/keymap_extras/sendstring_swiss_fr.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_swiss_fr.h" -#include "quantum.h" // clang-format off @@ -33,10 +33,10 @@ const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 1), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), - KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_turkish_f.h b/quantum/keymap_extras/sendstring_turkish_f.h index 8d6dc778fd9f..1c61e78daa4f 100644 --- a/quantum/keymap_extras/sendstring_turkish_f.h +++ b/quantum/keymap_extras/sendstring_turkish_f.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_turkish_f.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_turkish_q.h b/quantum/keymap_extras/sendstring_turkish_q.h index 1a409c1e03f8..f3cfeb15dd33 100644 --- a/quantum/keymap_extras/sendstring_turkish_q.h +++ b/quantum/keymap_extras/sendstring_turkish_q.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_turkish_q.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_uk.h b/quantum/keymap_extras/sendstring_uk.h index 1319c8164d19..c819e70ce5d0 100644 --- a/quantum/keymap_extras/sendstring_uk.h +++ b/quantum/keymap_extras/sendstring_uk.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_uk.h" -#include "quantum.h" const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_us_international.h b/quantum/keymap_extras/sendstring_us_international.h index d1694ff0f0fb..9b13a2fcf7d7 100644 --- a/quantum/keymap_extras/sendstring_us_international.h +++ b/quantum/keymap_extras/sendstring_us_international.h @@ -18,8 +18,8 @@ #pragma once +#include "send_string.h" #include "keymap_us_international.h" -#include "quantum.h" // clang-format off diff --git a/quantum/keymap_extras/sendstring_workman.h b/quantum/keymap_extras/sendstring_workman.h index 6e7f17b965ed..b18ce8c110f0 100644 --- a/quantum/keymap_extras/sendstring_workman.h +++ b/quantum/keymap_extras/sendstring_workman.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_workman.h" const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_workman_zxcvm.h b/quantum/keymap_extras/sendstring_workman_zxcvm.h index e7605d7cce13..791268fdebd9 100644 --- a/quantum/keymap_extras/sendstring_workman_zxcvm.h +++ b/quantum/keymap_extras/sendstring_workman_zxcvm.h @@ -18,6 +18,7 @@ #pragma once +#include "send_string.h" #include "keymap_workman_zxcvm.h" // clang-format off diff --git a/quantum/keymap_introspection.c b/quantum/keymap_introspection.c index 2459ad0df53f..e4a01d2e9a0a 100644 --- a/quantum/keymap_introspection.c +++ b/quantum/keymap_introspection.c @@ -46,7 +46,7 @@ __attribute__((weak)) uint16_t keycode_at_keymap_location(uint8_t layer_num, uin #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) -# define NUM_ENCODERMAP_LAYERS_RAW ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (2) * sizeof(uint16_t)))) +# define NUM_ENCODERMAP_LAYERS_RAW ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (NUM_DIRECTIONS) * sizeof(uint16_t)))) uint8_t encodermap_layer_count_raw(void) { return NUM_ENCODERMAP_LAYERS_RAW; @@ -70,3 +70,24 @@ __attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num, } #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Combos + +#if defined(COMBO_ENABLE) + +uint16_t combo_count_raw(void) { + return sizeof(key_combos) / sizeof(combo_t); +} +__attribute__((weak)) uint16_t combo_count(void) { + return combo_count_raw(); +} + +combo_t* combo_get_raw(uint16_t combo_idx) { + return &key_combos[combo_idx]; +} +__attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) { + return combo_get_raw(combo_idx); +} + +#endif // defined(COMBO_ENABLE) diff --git a/quantum/keymap_introspection.h b/quantum/keymap_introspection.h index a8df3928a619..2012a2b8cc6c 100644 --- a/quantum/keymap_introspection.h +++ b/quantum/keymap_introspection.h @@ -3,6 +3,7 @@ #pragma once #include +#include //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Key mapping @@ -33,3 +34,24 @@ uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_i uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise); #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Combos + +#if defined(COMBO_ENABLE) + +// Forward declaration of combo_t so we don't need to deal with header reordering +struct combo_t; +typedef struct combo_t combo_t; + +// Get the number of combos defined in the user's keymap, stored in firmware rather than any other persistent storage +uint16_t combo_count_raw(void); +// Get the number of combos defined in the user's keymap, potentially stored dynamically +uint16_t combo_count(void); + +// Get the keycode for the encoder mapping location, stored in firmware rather than any other persistent storage +combo_t* combo_get_raw(uint16_t combo_idx); +// Get the keycode for the encoder mapping location, potentially stored dynamically +combo_t* combo_get(uint16_t combo_idx); + +#endif // defined(COMBO_ENABLE) diff --git a/quantum/leader.h b/quantum/leader.h index 1999006c566f..3177fcd1962c 100644 --- a/quantum/leader.h +++ b/quantum/leader.h @@ -5,9 +5,9 @@ #include /** - * \defgroup leader + * \file * - * Leader Key + * \defgroup leader Leader Key * \{ */ diff --git a/quantum/led.c b/quantum/led.c index 42144566fdd6..8d86374a6f22 100644 --- a/quantum/led.c +++ b/quantum/led.c @@ -153,14 +153,14 @@ __attribute__((weak)) void led_set(uint8_t usb_led) { /** \brief Trigger behaviour on transition to suspend */ void led_suspend(void) { - uint8_t leds_off = 0; + led_t leds_off = {0}; #ifdef BACKLIGHT_CAPS_LOCK if (is_backlight_enabled()) { // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off - leds_off |= (1 << USB_LED_CAPS_LOCK); + leds_off.caps_lock = true; } #endif - led_set(leds_off); + led_set(leds_off.raw); } /** \brief Trigger behaviour on transition from suspend diff --git a/quantum/led.h b/quantum/led.h index b9ad7ed9ae7c..b9fad670aeba 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -22,13 +22,6 @@ along with this program. If not, see . /* FIXME: Add doxygen comments here. */ -/* keyboard LEDs */ -#define USB_LED_NUM_LOCK 0 -#define USB_LED_CAPS_LOCK 1 -#define USB_LED_SCROLL_LOCK 2 -#define USB_LED_COMPOSE 3 -#define USB_LED_KANA 4 - #ifdef __cplusplus extern "C" { #endif diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 828d61641a1b..1676a60aa35d 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -20,8 +20,13 @@ #include "led_matrix.h" #include "progmem.h" #include "eeprom.h" +#include "eeconfig.h" +#include "keyboard.h" +#include "sync_timer.h" +#include "debug.h" #include #include +#include #include "led_tables.h" #include @@ -366,7 +371,10 @@ void led_matrix_task(void) { case RENDERING: led_task_render(effect); if (effect) { - led_matrix_indicators(); + // Only run the basic indicators in the last render iteration (default there are 5 iterations) + if (led_effect_params.iter == LED_MATRIX_LED_PROCESS_MAX_ITERATIONS) { + led_matrix_indicators(); + } led_matrix_indicators_advanced(&led_effect_params); } break; diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index c7d360f366dc..c2533ca49cbc 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -23,7 +23,7 @@ #include #include #include "led_matrix_types.h" -#include "quantum.h" +#include "keyboard.h" #ifdef IS31FL3731 # include "is31fl3731-simple.h" @@ -42,8 +42,9 @@ #endif #ifndef LED_MATRIX_LED_PROCESS_LIMIT -# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5 +# define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5) #endif +#define LED_MATRIX_LED_PROCESS_MAX_ITERATIONS ((LED_MATRIX_LED_COUNT + LED_MATRIX_LED_PROCESS_LIMIT - 1) / LED_MATRIX_LED_PROCESS_LIMIT) #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT # if defined(LED_MATRIX_SPLIT) diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c index 2c09ba82b1f0..13c8935d112f 100644 --- a/quantum/led_matrix/led_matrix_drivers.c +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -32,13 +32,13 @@ static void init(void) { i2c_init(); # if defined(IS31FL3731) - IS31FL3731_init(LED_DRIVER_ADDR_1); + is31fl3731_init(LED_DRIVER_ADDR_1); # if defined(LED_DRIVER_ADDR_2) - IS31FL3731_init(LED_DRIVER_ADDR_2); + is31fl3731_init(LED_DRIVER_ADDR_2); # if defined(LED_DRIVER_ADDR_3) - IS31FL3731_init(LED_DRIVER_ADDR_3); + is31fl3731_init(LED_DRIVER_ADDR_3); # if defined(LED_DRIVER_ADDR_4) - IS31FL3731_init(LED_DRIVER_ADDR_4); + is31fl3731_init(LED_DRIVER_ADDR_4); # endif # endif # endif @@ -47,22 +47,22 @@ static void init(void) { # if !defined(LED_DRIVER_SYNC_1) # define LED_DRIVER_SYNC_1 0 # endif - IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1); + is31fl3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1); # if defined(LED_DRIVER_ADDR_2) # if !defined(LED_DRIVER_SYNC_2) # define LED_DRIVER_SYNC_2 0 # endif - IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); + is31fl3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); # if defined(LED_DRIVER_ADDR_3) # if !defined(LED_DRIVER_SYNC_3) # define LED_DRIVER_SYNC_3 0 # endif - IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); + is31fl3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); # if defined(LED_DRIVER_ADDR_4) # if !defined(LED_DRIVER_SYNC_4) # define LED_DRIVER_SYNC_4 0 # endif - IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); + is31fl3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); # endif # endif # endif @@ -84,13 +84,13 @@ static void init(void) { writePinHigh(LED_DRIVER_SHUTDOWN_PIN); # endif - CKLED2001_init(DRIVER_ADDR_1); + ckled2001_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) - CKLED2001_init(DRIVER_ADDR_2); + ckled2001_init(DRIVER_ADDR_2); # if defined(DRIVER_ADDR_3) - CKLED2001_init(DRIVER_ADDR_3); + ckled2001_init(DRIVER_ADDR_3); # if defined(DRIVER_ADDR_4) - CKLED2001_init(DRIVER_ADDR_4); + ckled2001_init(DRIVER_ADDR_4); # endif # endif # endif @@ -98,37 +98,37 @@ static void init(void) { for (int index = 0; index < LED_MATRIX_LED_COUNT; index++) { # if defined(IS31FL3731) - IS31FL3731_set_led_control_register(index, true); + is31fl3731_set_led_control_register(index, true); # elif defined(IS31FL3733) - IS31FL3733_set_led_control_register(index, true); + is31fl3733_set_led_control_register(index, true); # elif defined(IS31FLCOMMON) IS31FL_simple_set_scaling_buffer(index, true); # elif defined(CKLED2001) - CKLED2001_set_led_control_register(index, true); + ckled2001_set_led_control_register(index, true); # endif } // This actually updates the LED drivers # if defined(IS31FL3731) - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); + is31fl3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); # if defined(LED_DRIVER_ADDR_2) - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); + is31fl3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); # if defined(LED_DRIVER_ADDR_3) - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); + is31fl3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); # if defined(LED_DRIVER_ADDR_4) - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); + is31fl3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); # endif # endif # endif # elif defined(IS31FL3733) - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); + is31fl3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); # if defined(LED_DRIVER_ADDR_2) - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); + is31fl3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); # if defined(LED_DRIVER_ADDR_3) - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); + is31fl3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); # if defined(LED_DRIVER_ADDR_4) - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); + is31fl3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); # endif # endif # endif @@ -148,13 +148,13 @@ static void init(void) { # endif # endif # elif defined(CKLED2001) - CKLED2001_update_led_control_registers(DRIVER_ADDR_1, 0); + ckled2001_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - CKLED2001_update_led_control_registers(DRIVER_ADDR_2, 1); + ckled2001_update_led_control_registers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - CKLED2001_update_led_control_registers(DRIVER_ADDR_3, 2); + ckled2001_update_led_control_registers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - CKLED2001_update_led_control_registers(DRIVER_ADDR_4, 3); + ckled2001_update_led_control_registers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -163,13 +163,13 @@ static void init(void) { # if defined(IS31FL3731) static void flush(void) { - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); + is31fl3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); # if defined(LED_DRIVER_ADDR_2) - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); + is31fl3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); # if defined(LED_DRIVER_ADDR_3) - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); + is31fl3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); # if defined(LED_DRIVER_ADDR_4) - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); + is31fl3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); # endif # endif # endif @@ -178,19 +178,19 @@ static void flush(void) { const led_matrix_driver_t led_matrix_driver = { .init = init, .flush = flush, - .set_value = IS31FL3731_set_value, - .set_value_all = IS31FL3731_set_value_all, + .set_value = is31fl3731_set_value, + .set_value_all = is31fl3731_set_value_all, }; # elif defined(IS31FL3733) static void flush(void) { - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); + is31fl3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); # if defined(LED_DRIVER_ADDR_2) - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); + is31fl3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); # if defined(LED_DRIVER_ADDR_3) - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); + is31fl3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); # if defined(LED_DRIVER_ADDR_4) - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); + is31fl3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); # endif # endif # endif @@ -199,8 +199,8 @@ static void flush(void) { const led_matrix_driver_t led_matrix_driver = { .init = init, .flush = flush, - .set_value = IS31FL3733_set_value, - .set_value_all = IS31FL3733_set_value_all, + .set_value = is31fl3733_set_value, + .set_value_all = is31fl3733_set_value_all, }; # elif defined(IS31FLCOMMON) @@ -225,13 +225,13 @@ const led_matrix_driver_t led_matrix_driver = { }; # elif defined(CKLED2001) static void flush(void) { - CKLED2001_update_pwm_buffers(DRIVER_ADDR_1, 0); + ckled2001_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_2, 1); + ckled2001_update_pwm_buffers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_3, 2); + ckled2001_update_pwm_buffers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_4, 3); + ckled2001_update_pwm_buffers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -240,8 +240,8 @@ static void flush(void) { const led_matrix_driver_t led_matrix_driver = { .init = init, .flush = flush, - .set_value = CKLED2001_set_value, - .set_value_all = CKLED2001_set_value_all, + .set_value = ckled2001_set_value, + .set_value_all = ckled2001_set_value_all, }; # endif #endif diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h index 6d79a3592dff..6709a558bb94 100644 --- a/quantum/led_matrix/led_matrix_types.h +++ b/quantum/led_matrix/led_matrix_types.h @@ -85,13 +85,14 @@ typedef union { struct PACKED { uint8_t enable : 2; uint8_t mode : 6; - uint16_t reserved; uint8_t val; - uint8_t speed; // EECONFIG needs to be increased to support this + uint8_t speed; led_flags_t flags; }; } led_eeconfig_t; +_Static_assert(sizeof(led_eeconfig_t) == sizeof(uint32_t), "LED Matrix EECONFIG out of spec."); + #if defined(_MSC_VER) # pragma pack(pop) #endif diff --git a/quantum/led_matrix/post_config.h b/quantum/led_matrix/post_config.h new file mode 100644 index 000000000000..b6770b9ee1c8 --- /dev/null +++ b/quantum/led_matrix/post_config.h @@ -0,0 +1,19 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +// clang-format off + +// reactive +#if defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || \ + defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) || \ + defined(ENABLE_LED_MATRIX_SOLID_SPLASH) || \ + defined(ENABLE_LED_MATRIX_SOLID_MULTISPLASH) +# define LED_MATRIX_KEYPRESSES +#endif diff --git a/quantum/matrix.c b/quantum/matrix.c index 97d41caedded..f087a215d46f 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -20,7 +20,8 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" #include "debounce.h" -#include "quantum.h" +#include "atomic_util.h" + #ifdef SPLIT_KEYBOARD # include "split_common/split_util.h" # include "split_common/transactions.h" diff --git a/quantum/matrix_common.c b/quantum/matrix_common.c index 3173351888dd..d02c527caa8b 100644 --- a/quantum/matrix_common.c +++ b/quantum/matrix_common.c @@ -1,9 +1,9 @@ -#include "quantum.h" #include "matrix.h" #include "debounce.h" #include "wait.h" #include "print.h" #include "debug.h" + #ifdef SPLIT_KEYBOARD # include "split_common/split_util.h" # include "split_common/transactions.h" diff --git a/quantum/midi/midi.c b/quantum/midi/midi.c index 1ba3e73a4020..1c481f2f0b38 100644 --- a/quantum/midi/midi.c +++ b/quantum/midi/midi.c @@ -18,10 +18,7 @@ #include "midi.h" #include //for memcpy - -#ifndef MIN -# define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif +#include "util.h" #ifndef NULL # define NULL 0 diff --git a/quantum/midi/qmk_midi.c b/quantum/midi/qmk_midi.c index f6a5d9228124..6b8831fb589d 100644 --- a/quantum/midi/qmk_midi.c +++ b/quantum/midi/qmk_midi.c @@ -5,6 +5,11 @@ #include "usb_descriptor.h" #include "process_midi.h" +#ifdef AUDIO_ENABLE +# include "audio.h" +# include +#endif + /******************************************************************************* * MIDI ******************************************************************************/ @@ -103,10 +108,10 @@ static void fallthrough_callback(MidiDevice* device, uint16_t cnt, uint8_t byte0 if (cnt == 3) { switch (byte0 & 0xF0) { case MIDI_NOTEON: - play_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0), (byte2 & 0x7F) / 8); + play_note(440.0f * powf(2.0f, ((byte1 & 0x7F) - 57) / 12.0f), (byte2 & 0x7F) / 8); break; case MIDI_NOTEOFF: - stop_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0)); + stop_note(440.0f * powf(2.0f, ((byte1 & 0x7F) - 57) / 12.0f)); break; } } diff --git a/quantum/modifiers.h b/quantum/modifiers.h new file mode 100644 index 000000000000..45bcd6508d8c --- /dev/null +++ b/quantum/modifiers.h @@ -0,0 +1,54 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +/** \brief 5-bit packed modifiers + * + * Mod bits: 43210 + * bit 0 ||||+- Control + * bit 1 |||+-- Shift + * bit 2 ||+--- Alt + * bit 3 |+---- Gui + * bit 4 +----- LR flag(Left:0, Right:1) + */ +enum mods_5bit { + MOD_LCTL = 0x01, + MOD_LSFT = 0x02, + MOD_LALT = 0x04, + MOD_LGUI = 0x08, + MOD_RCTL = 0x11, + MOD_RSFT = 0x12, + MOD_RALT = 0x14, + MOD_RGUI = 0x18, +}; +#define MOD_HYPR (MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI) +#define MOD_MEH (MOD_LCTL | MOD_LSFT | MOD_LALT) + +/** \brief 8-bit packed modifiers + */ +enum mods_8bit { + MOD_BIT_LCTRL = 0b00000001, + MOD_BIT_LSHIFT = 0b00000010, + MOD_BIT_LALT = 0b00000100, + MOD_BIT_LGUI = 0b00001000, + MOD_BIT_RCTRL = 0b00010000, + MOD_BIT_RSHIFT = 0b00100000, + MOD_BIT_RALT = 0b01000000, + MOD_BIT_RGUI = 0b10000000, +}; +#define MOD_MASK_CTRL (MOD_BIT_LCTRL | MOD_BIT_RCTRL) +#define MOD_MASK_SHIFT (MOD_BIT_LSHIFT | MOD_BIT_RSHIFT) +#define MOD_MASK_ALT (MOD_BIT_LALT | MOD_BIT_RALT) +#define MOD_MASK_GUI (MOD_BIT_LGUI | MOD_BIT_RGUI) +#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) +#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) +#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) +#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) diff --git a/quantum/mousekey.c b/quantum/mousekey.c index df8aa613bea4..c982a2f40b42 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -25,11 +25,16 @@ #include "mousekey.h" static inline int8_t times_inv_sqrt2(int8_t x) { - // 181/256 is pretty close to 1/sqrt(2) - // 0.70703125 0.707106781 - // 1 too small for x=99 and x=198 - // This ends up being a mult and discard lower 8 bits - return (x * 181) >> 8; + // 181/256 (0.70703125) is used as an approximation for 1/sqrt(2) + // because it is close to the exact value which is 0.707106781 + const int16_t n = x * 181; + const uint16_t d = 256; + + // To ensure that the integer result is rounded accurately after + // division, check the sign of the numerator: + // If negative, subtract half of the denominator before dividing + // Otherwise, add half of the denominator before dividing + return n < 0 ? (n - d / 2) / d : (n + d / 2) / d; } static report_mouse_t mouse_report = {0}; @@ -74,7 +79,7 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; /* milliseconds between repeated motion events (0-255) */ # ifdef MK_KINETIC_SPEED -float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; +uint16_t mk_wheel_interval = 1000U / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; # else uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; # endif @@ -175,7 +180,7 @@ static uint8_t wheel_unit(void) { /* * Kinetic movement acceleration algorithm * - * current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B + * current speed = I + A * T/50 + A * (T/50)^2 * 1/2 | maximum B * * T: time since the mouse movement started * E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the @@ -190,39 +195,48 @@ const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED; const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED; static uint8_t move_unit(void) { - float speed = mk_initial_speed; + uint16_t speed = mk_initial_speed; - if (mousekey_accel & ((1 << 0) | (1 << 2))) { - speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed; + if (mousekey_accel & (1 << 0)) { + speed = mk_decelerated_speed; + } else if (mousekey_accel & (1 << 2)) { + speed = mk_accelerated_speed; } else if (mousekey_repeat && mouse_timer) { - const float time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed; - - speed = speed > mk_base_speed ? mk_base_speed : speed; + const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; + speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + (MOUSEKEY_MOVE_DELTA * time_elapsed * time_elapsed) / 2; + if (speed > mk_base_speed) { + speed = mk_base_speed; + } } - /* convert speed to USB mouse speed 1 to 127 */ - speed = (uint8_t)(speed / (1000.0f / mk_interval)); - speed = speed < 1 ? 1 : speed; + speed = (uint8_t)(speed / (1000U / mk_interval)); - return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed; + if (speed > MOUSEKEY_MOVE_MAX) { + speed = MOUSEKEY_MOVE_MAX; + } else if (speed < 1) { + speed = 1; + } + return speed; } static uint8_t wheel_unit(void) { - float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; + uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; - if (mousekey_accel & ((1 << 0) | (1 << 2))) { - speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; + if (mousekey_accel & (1 << 0)) { + speed = MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; + } else if (mousekey_accel & (1 << 2)) { + speed = MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS; } else if (mousekey_wheel_repeat && mouse_timer) { if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) { - const float time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; + const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; + speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + (1 * time_elapsed * time_elapsed) / 2; + } + if (speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS) { + speed = MOUSEKEY_WHEEL_BASE_MOVEMENTS; } - speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed; } - mk_wheel_interval = 1000.0f / speed; - - return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1; + mk_wheel_interval = 1000U / speed; + return 1; } # endif /* #ifndef MK_KINETIC_SPEED */ diff --git a/quantum/mousekey.h b/quantum/mousekey.h index e968e000c027..73380b743a7b 100644 --- a/quantum/mousekey.h +++ b/quantum/mousekey.h @@ -44,9 +44,6 @@ along with this program. If not, see . # define MOUSEKEY_MOVE_DELTA 8 # endif # endif -# ifndef MOUSEKEY_WHEEL_DELTA -# define MOUSEKEY_WHEEL_DELTA 1 -# endif # ifndef MOUSEKEY_DELAY # if defined(MK_KINETIC_SPEED) # define MOUSEKEY_DELAY 5 @@ -85,6 +82,9 @@ along with this program. If not, see . # ifndef MOUSEKEY_WHEEL_INTERVAL # define MOUSEKEY_WHEEL_INTERVAL 80 # endif +# ifndef MOUSEKEY_WHEEL_DELTA +# define MOUSEKEY_WHEEL_DELTA 1 +# endif # ifndef MOUSEKEY_WHEEL_MAX_SPEED # define MOUSEKEY_WHEEL_MAX_SPEED 8 # endif diff --git a/quantum/os_detection.c b/quantum/os_detection.c index b1511afb149a..e606227136af 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -31,53 +31,53 @@ uint16_t usb_setups[STORED_USB_SETUPS]; #ifdef OS_DETECTION_ENABLE struct setups_data_t { - uint8_t count; - uint8_t cnt_02; - uint8_t cnt_04; - uint8_t cnt_ff; - uint16_t last_wlength; - os_variant_t detected_os; + uint8_t count; + uint8_t cnt_02; + uint8_t cnt_04; + uint8_t cnt_ff; + uint16_t last_wlength; }; struct setups_data_t setups_data = { - .count = 0, - .cnt_02 = 0, - .cnt_04 = 0, - .cnt_ff = 0, - .detected_os = OS_UNSURE, + .count = 0, + .cnt_02 = 0, + .cnt_04 = 0, + .cnt_ff = 0, }; +os_variant_t detected_os = OS_UNSURE; + // Some collected sequences of wLength can be found in tests. void make_guess(void) { if (setups_data.count < 3) { return; } if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1) { - setups_data.detected_os = OS_WINDOWS; + detected_os = OS_WINDOWS; return; } if (setups_data.count == setups_data.cnt_ff) { // Linux has 3 packets with 0xFF. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) { - setups_data.detected_os = OS_MACOS; + detected_os = OS_MACOS; return; } if (setups_data.count == 4 && setups_data.cnt_ff == 0 && setups_data.cnt_02 == 2) { // iOS and iPadOS don't have the last 0xFF packet. - setups_data.detected_os = OS_IOS; + detected_os = OS_IOS; return; } if (setups_data.cnt_ff == 0 && setups_data.cnt_02 == 3 && setups_data.cnt_04 == 1) { // This is actually PS5. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } if (setups_data.cnt_ff >= 1 && setups_data.cnt_02 == 0 && setups_data.cnt_04 == 0) { // This is actually Quest 2 or Nintendo Switch. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } } @@ -99,13 +99,20 @@ void process_wlength(const uint16_t w_length) { } os_variant_t detected_host_os(void) { - return setups_data.detected_os; + return detected_os; } void erase_wlength_data(void) { memset(&setups_data, 0, sizeof(setups_data)); + detected_os = OS_UNSURE; +} + +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +void slave_update_detected_host_os(os_variant_t os) { + detected_os = os; } -#endif // OS_DETECTION_ENABLE +# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +#endif // OS_DETECTION_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE void print_stored_setups(void) { diff --git a/quantum/os_detection.h b/quantum/os_detection.h index e643dcd27fab..3496ea0ed219 100644 --- a/quantum/os_detection.h +++ b/quantum/os_detection.h @@ -30,6 +30,10 @@ typedef enum { void process_wlength(const uint16_t w_length); os_variant_t detected_host_os(void); void erase_wlength_data(void); + +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +void slave_update_detected_host_os(os_variant_t os); +# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #endif #ifdef OS_DETECTION_DEBUG_ENABLE diff --git a/quantum/painter/lvgl/qp_lvgl.c b/quantum/painter/lvgl/qp_lvgl.c index c6dd08ef97ee..280aeaf91f53 100644 --- a/quantum/painter/lvgl/qp_lvgl.c +++ b/quantum/painter/lvgl/qp_lvgl.c @@ -60,8 +60,8 @@ bool qp_lvgl_attach(painter_device_t device) { qp_dprintf("qp_lvgl_start: entry\n"); qp_lvgl_detach(); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n"); qp_lvgl_detach(); return false; @@ -112,9 +112,6 @@ bool qp_lvgl_attach(painter_device_t device) { uint16_t panel_width, panel_height, offset_x, offset_y; qp_get_geometry(selected_display, &panel_width, &panel_height, NULL, &offset_x, &offset_y); - panel_width -= offset_x; - panel_height -= offset_y; - // Setting up display driver static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ diff --git a/quantum/painter/qff.h b/quantum/painter/qff.h index 6f1a1fd81560..d1d629582f57 100644 --- a/quantum/painter/qff.h +++ b/quantum/painter/qff.h @@ -21,7 +21,7 @@ #define QFF_FONT_DESCRIPTOR_TYPEID 0x00 -typedef struct __attribute__((packed)) qff_font_descriptor_v1_t { +typedef struct QP_PACKED qff_font_descriptor_v1_t { qgf_block_header_v1_t header; // = { .type_id = 0x00, .neg_type_id = (~0x00), .length = 20 } uint32_t magic : 24; // constant, equal to 0x464651 ("QFF") uint8_t qff_version; // constant, equal to 0x01 @@ -50,13 +50,13 @@ _Static_assert(sizeof(qff_font_descriptor_v1_t) == (sizeof(qgf_block_header_v1_t #define QFF_GLYPH_OFFSET_BITS 18 #define QFF_GLYPH_OFFSET_MASK (((1 << QFF_GLYPH_OFFSET_BITS) - 1) << QFF_GLYPH_WIDTH_BITS) -typedef struct __attribute__((packed)) qff_ascii_glyph_v1_t { +typedef struct QP_PACKED qff_ascii_glyph_v1_t { uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined } qff_ascii_glyph_v1_t; _Static_assert(sizeof(qff_ascii_glyph_v1_t) == 3, "qff_ascii_glyph_v1_t must be 3 bytes in v1 of QFF"); -typedef struct __attribute__((packed)) qff_ascii_glyph_table_v1_t { +typedef struct QP_PACKED qff_ascii_glyph_table_v1_t { qgf_block_header_v1_t header; // = { .type_id = 0x01, .neg_type_id = (~0x01), .length = 285 } qff_ascii_glyph_v1_t glyph[95]; // 95 glyphs, 0x20..0x7E } qff_ascii_glyph_table_v1_t; @@ -68,14 +68,14 @@ _Static_assert(sizeof(qff_ascii_glyph_table_v1_t) == (sizeof(qgf_block_header_v1 #define QFF_UNICODE_GLYPH_DESCRIPTOR_TYPEID 0x02 -typedef struct __attribute__((packed)) qff_unicode_glyph_v1_t { +typedef struct QP_PACKED qff_unicode_glyph_v1_t { uint32_t code_point : 24; uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined } qff_unicode_glyph_v1_t; _Static_assert(sizeof(qff_unicode_glyph_v1_t) == 6, "qff_unicode_glyph_v1_t must be 6 bytes in v1 of QFF"); -typedef struct __attribute__((packed)) qff_unicode_glyph_table_v1_t { +typedef struct QP_PACKED qff_unicode_glyph_table_v1_t { qgf_block_header_v1_t header; // = { .type_id = 0x02, .neg_type_id = (~0x02), .length = (N * 6) } qff_unicode_glyph_v1_t glyph[0]; // Extent of '0' signifies that this struct is immediately followed by the glyph data } qff_unicode_glyph_table_v1_t; diff --git a/quantum/painter/qp.c b/quantum/painter/qp.c index de36dee2c10c..f27bb7892add 100644 --- a/quantum/painter/qp.c +++ b/quantum/painter/qp.c @@ -11,15 +11,15 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Internal driver validation -static bool validate_driver_vtable(struct painter_driver_t *driver) { +static bool validate_driver_vtable(painter_driver_t *driver) { return (driver->driver_vtable && driver->driver_vtable->init && driver->driver_vtable->power && driver->driver_vtable->clear && driver->driver_vtable->viewport && driver->driver_vtable->pixdata && driver->driver_vtable->palette_convert && driver->driver_vtable->append_pixels && driver->driver_vtable->append_pixdata) ? true : false; } -static bool validate_comms_vtable(struct painter_driver_t *driver) { +static bool validate_comms_vtable(painter_driver_t *driver) { return (driver->comms_vtable && driver->comms_vtable->comms_init && driver->comms_vtable->comms_start && driver->comms_vtable->comms_stop && driver->comms_vtable->comms_send) ? true : false; } -static bool validate_driver_integrity(struct painter_driver_t *driver) { +static bool validate_driver_integrity(painter_driver_t *driver) { return validate_driver_vtable(driver) && validate_comms_vtable(driver); } @@ -28,7 +28,12 @@ static bool validate_driver_integrity(struct painter_driver_t *driver) { bool qp_init(painter_device_t device, painter_rotation_t rotation) { qp_dprintf("qp_init: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver) { + qp_dprintf("qp_init: fail (pointer to NULL)\n"); + return false; + } driver->validate_ok = false; if (!validate_driver_integrity(driver)) { @@ -64,8 +69,8 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) { bool qp_power(painter_device_t device, bool power_on) { qp_dprintf("qp_power: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_power: fail (validation_ok == false)\n"); return false; } @@ -86,8 +91,8 @@ bool qp_power(painter_device_t device, bool power_on) { bool qp_clear(painter_device_t device) { qp_dprintf("qp_clear: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_clear: fail (validation_ok == false)\n"); return false; } @@ -108,8 +113,8 @@ bool qp_clear(painter_device_t device) { bool qp_flush(painter_device_t device) { qp_dprintf("qp_flush: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_flush: fail (validation_ok == false)\n"); return false; } @@ -129,8 +134,13 @@ bool qp_flush(painter_device_t device) { // Quantum Painter External API: qp_get_geometry void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, painter_rotation_t *rotation, uint16_t *offset_x, uint16_t *offset_y) { - qp_dprintf("qp_geometry: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; + qp_dprintf("qp_get_geometry: entry\n"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver) { + qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n"); + return; + } switch (driver->rotation) { default: @@ -166,7 +176,7 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, *offset_y = driver->offset_y; } - qp_dprintf("qp_geometry: ok\n"); + qp_dprintf("qp_get_geometry: ok\n"); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -174,7 +184,12 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_t offset_y) { qp_dprintf("qp_set_viewport_offsets: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver) { + qp_dprintf("qp_set_viewport_offsets: fail (pointer to NULL)\n"); + return; + } driver->offset_x = offset_x; driver->offset_y = offset_y; @@ -187,8 +202,8 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { qp_dprintf("qp_viewport: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_viewport: fail (validation_ok == false)\n"); return false; } @@ -210,8 +225,8 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) { qp_dprintf("qp_pixdata: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_pixdata: fail (validation_ok == false)\n"); return false; } diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h index 00f5d7931af8..7222d3b41373 100644 --- a/quantum/painter/qp.h +++ b/quantum/painter/qp.h @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -11,6 +11,22 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter global configurables (add to your keyboard's config.h) +#ifndef QUANTUM_PAINTER_DISPLAY_TIMEOUT +/** + * @def This controls the amount of time (in milliseconds) that all displays will remain on after the last user input. + * If set to 0, the display will remain on indefinitely. + */ +# define QUANTUM_PAINTER_DISPLAY_TIMEOUT 30000 +#endif // QUANTUM_PAINTER_DISPLAY_TIMEOUT + +#ifndef QUANTUM_PAINTER_TASK_THROTTLE +/** + * @def This controls the amount of time (in milliseconds) that the Quantum Painter internal task will wait between + * each execution. + */ +# define QUANTUM_PAINTER_TASK_THROTTLE 1 +#endif // QUANTUM_PAINTER_TASK_THROTTLE + #ifndef QUANTUM_PAINTER_NUM_IMAGES /** * @def This controls the maximum number of images that Quantum Painter can load at any one time. Images can be loaded @@ -53,7 +69,7 @@ * @def This controls the maximum size of the pixel data buffer used for single blocks of transmission. Larger buffers * means more data is processed at one time, with less frequent transmissions, at the cost of RAM. */ -# define QUANTUM_PAINTER_PIXDATA_BUFFER_SIZE 32 +# define QUANTUM_PAINTER_PIXDATA_BUFFER_SIZE 1024 #endif #ifndef QUANTUM_PAINTER_SUPPORTS_256_PALETTE @@ -442,34 +458,50 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai #ifdef QUANTUM_PAINTER_RGB565_SURFACE_ENABLE # include "qp_rgb565_surface.h" +#else // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE +# define RGB565_SURFACE_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE #ifdef QUANTUM_PAINTER_ILI9163_ENABLE # include "qp_ili9163.h" +#else // QUANTUM_PAINTER_ILI9163_ENABLE +# define ILI9163_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_ILI9163_ENABLE #ifdef QUANTUM_PAINTER_ILI9341_ENABLE # include "qp_ili9341.h" +#else // QUANTUM_PAINTER_ILI9341_ENABLE +# define ILI9341_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_ILI9341_ENABLE #ifdef QUANTUM_PAINTER_ILI9488_ENABLE # include "qp_ili9488.h" +#else // QUANTUM_PAINTER_ILI9488_ENABLE +# define ILI9488_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_ILI9488_ENABLE #ifdef QUANTUM_PAINTER_ST7789_ENABLE # include "qp_st7789.h" +#else // QUANTUM_PAINTER_ST7789_ENABLE +# define ST7789_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_ST7789_ENABLE #ifdef QUANTUM_PAINTER_ST7735_ENABLE # include "qp_st7735.h" +#else // QUANTUM_PAINTER_ST7735_ENABLE +# define ST7735_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_ST7735_ENABLE #ifdef QUANTUM_PAINTER_GC9A01_ENABLE # include "qp_gc9a01.h" +#else // QUANTUM_PAINTER_GC9A01_ENABLE +# define GC9A01_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_GC9A01_ENABLE #ifdef QUANTUM_PAINTER_SSD1351_ENABLE # include "qp_ssd1351.h" +#else // QUANTUM_PAINTER_SSD1351_ENABLE +# define SSD1351_NUM_DEVICES 0 #endif // QUANTUM_PAINTER_SSD1351_ENABLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/quantum/painter/qp_comms.c b/quantum/painter/qp_comms.c index dc17b4946003..63667783e10d 100644 --- a/quantum/painter/qp_comms.c +++ b/quantum/painter/qp_comms.c @@ -7,8 +7,8 @@ // Base comms APIs bool qp_comms_init(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_comms_init: fail (validation_ok == false)\n"); return false; } @@ -17,8 +17,8 @@ bool qp_comms_init(painter_device_t device) { } bool qp_comms_start(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_comms_start: fail (validation_ok == false)\n"); return false; } @@ -27,8 +27,8 @@ bool qp_comms_start(painter_device_t device) { } void qp_comms_stop(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_comms_stop: fail (validation_ok == false)\n"); return; } @@ -37,8 +37,8 @@ void qp_comms_stop(painter_device_t device) { } uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_count) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_comms_send: fail (validation_ok == false)\n"); return false; } @@ -50,8 +50,8 @@ uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_ // Comms APIs that use a D/C pin void qp_comms_command(painter_device_t device, uint8_t cmd) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct painter_comms_with_command_vtable_t *comms_vtable = (struct painter_comms_with_command_vtable_t *)driver->comms_vtable; + painter_driver_t * driver = (painter_driver_t *)device; + painter_comms_with_command_vtable_t *comms_vtable = (painter_comms_with_command_vtable_t *)driver->comms_vtable; comms_vtable->send_command(device, cmd); } @@ -66,7 +66,7 @@ uint32_t qp_comms_command_databuf(painter_device_t device, uint8_t cmd, const vo } void qp_comms_bulk_command_sequence(painter_device_t device, const uint8_t *sequence, size_t sequence_len) { - struct painter_driver_t * driver = (struct painter_driver_t *)device; - struct painter_comms_with_command_vtable_t *comms_vtable = (struct painter_comms_with_command_vtable_t *)driver->comms_vtable; + painter_driver_t * driver = (painter_driver_t *)device; + painter_comms_with_command_vtable_t *comms_vtable = (painter_comms_with_command_vtable_t *)driver->comms_vtable; comms_vtable->bulk_command_sequence(device, sequence, sequence_len); } diff --git a/quantum/painter/qp_draw.h b/quantum/painter/qp_draw.h index 84b1946ca7a3..3d073efe8caf 100644 --- a/quantum/painter/qp_draw.h +++ b/quantum/painter/qp_draw.h @@ -63,7 +63,7 @@ enum qp_internal_rle_mode_t { NON_REPEATING_RUN, }; -struct qp_internal_byte_input_state { +typedef struct qp_internal_byte_input_state_t { painter_device_t device; qp_stream_t* src_stream; int16_t curr; @@ -74,22 +74,22 @@ struct qp_internal_byte_input_state { uint8_t remain; // number of bytes remaining in the current mode } rle; }; -}; +} qp_internal_byte_input_state_t; -struct qp_internal_pixel_output_state { +typedef struct qp_internal_pixel_output_state_t { painter_device_t device; uint32_t pixel_write_pos; uint32_t max_pixels; -}; +} qp_internal_pixel_output_state_t; bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg); -struct qp_internal_byte_output_state { +typedef struct qp_internal_byte_output_state_t { painter_device_t device; uint32_t byte_write_pos; uint32_t max_bytes; -}; +} qp_internal_byte_output_state_t; bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg); -qp_internal_byte_input_callback qp_internal_prepare_input_state(struct qp_internal_byte_input_state* input_state, painter_compression_t compression); +qp_internal_byte_input_callback qp_internal_prepare_input_state(qp_internal_byte_input_state_t* input_state, painter_compression_t compression); diff --git a/quantum/painter/qp_draw_circle.c b/quantum/painter/qp_draw_circle.c index edaae358356b..7f5a7ddfcd71 100644 --- a/quantum/painter/qp_draw_circle.c +++ b/quantum/painter/qp_draw_circle.c @@ -127,8 +127,8 @@ static bool qp_circle_helper_impl(painter_device_t device, uint16_t centerx, uin bool qp_circle(painter_device_t device, uint16_t x, uint16_t y, uint16_t radius, uint8_t hue, uint8_t sat, uint8_t val, bool filled) { qp_dprintf("qp_circle: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_circle: fail (validation_ok == false)\n"); return false; } diff --git a/quantum/painter/qp_draw_codec.c b/quantum/painter/qp_draw_codec.c index 5d1cf7c52e99..cee2e32e2810 100644 --- a/quantum/painter/qp_draw_codec.c +++ b/quantum/painter/qp_draw_codec.c @@ -54,8 +54,8 @@ bool qp_internal_decode_grayscale(painter_device_t device, uint32_t pixel_count, } bool qp_internal_decode_recolor(painter_device_t device, uint32_t pixel_count, uint8_t bits_per_pixel, qp_internal_byte_input_callback input_callback, void* input_arg, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, qp_internal_pixel_output_callback output_callback, void* output_arg) { - struct painter_driver_t* driver = (struct painter_driver_t*)device; - int16_t steps = 1 << bits_per_pixel; // number of items we need to interpolate + painter_driver_t* driver = (painter_driver_t*)device; + int16_t steps = 1 << bits_per_pixel; // number of items we need to interpolate if (qp_internal_interpolate_palette(fg_hsv888, bg_hsv888, steps)) { if (!driver->driver_vtable->palette_convert(device, steps, qp_internal_global_pixel_lookup_table)) { return false; @@ -84,13 +84,13 @@ bool qp_internal_send_bytes(painter_device_t device, uint32_t byte_count, qp_int // Progressive pull of bytes, push of pixels static inline int16_t qp_drawimage_byte_uncompressed_decoder(void* cb_arg) { - struct qp_internal_byte_input_state* state = (struct qp_internal_byte_input_state*)cb_arg; - state->curr = qp_stream_get(state->src_stream); + qp_internal_byte_input_state_t* state = (qp_internal_byte_input_state_t*)cb_arg; + state->curr = qp_stream_get(state->src_stream); return state->curr; } static inline int16_t qp_drawimage_byte_rle_decoder(void* cb_arg) { - struct qp_internal_byte_input_state* state = (struct qp_internal_byte_input_state*)cb_arg; + qp_internal_byte_input_state_t* state = (qp_internal_byte_input_state_t*)cb_arg; // Work out if we're parsing the initial marker byte if (state->rle.mode == MARKER_BYTE) { @@ -126,8 +126,8 @@ static inline int16_t qp_drawimage_byte_rle_decoder(void* cb_arg) { } bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg) { - struct qp_internal_pixel_output_state* state = (struct qp_internal_pixel_output_state*)cb_arg; - struct painter_driver_t* driver = (struct painter_driver_t*)state->device; + qp_internal_pixel_output_state_t* state = (qp_internal_pixel_output_state_t*)cb_arg; + painter_driver_t* driver = (painter_driver_t*)state->device; if (!driver->driver_vtable->append_pixels(state->device, qp_internal_global_pixdata_buffer, palette, state->pixel_write_pos++, 1, &index)) { return false; @@ -145,8 +145,8 @@ bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg } bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) { - struct qp_internal_byte_output_state* state = (struct qp_internal_byte_output_state*)cb_arg; - struct painter_driver_t* driver = (struct painter_driver_t*)state->device; + qp_internal_byte_output_state_t* state = (qp_internal_byte_output_state_t*)cb_arg; + painter_driver_t* driver = (painter_driver_t*)state->device; if (!driver->driver_vtable->append_pixdata(state->device, qp_internal_global_pixdata_buffer, state->byte_write_pos++, byteval)) { return false; @@ -154,7 +154,7 @@ bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) { // If we've hit the transmit limit, send out the entire buffer and reset the write position if (state->byte_write_pos == state->max_bytes) { - struct painter_driver_t* driver = (struct painter_driver_t*)state->device; + painter_driver_t* driver = (painter_driver_t*)state->device; if (!driver->driver_vtable->pixdata(state->device, qp_internal_global_pixdata_buffer, state->byte_write_pos * 8 / driver->native_bits_per_pixel)) { return false; } @@ -164,7 +164,7 @@ bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) { return true; } -qp_internal_byte_input_callback qp_internal_prepare_input_state(struct qp_internal_byte_input_state* input_state, painter_compression_t compression) { +qp_internal_byte_input_callback qp_internal_prepare_input_state(qp_internal_byte_input_state_t* input_state, painter_compression_t compression) { switch (compression) { case IMAGE_UNCOMPRESSED: return qp_drawimage_byte_uncompressed_decoder; diff --git a/quantum/painter/qp_draw_core.c b/quantum/painter/qp_draw_core.c index 309ef93dd07a..aa5fa4aa761f 100644 --- a/quantum/painter/qp_draw_core.c +++ b/quantum/painter/qp_draw_core.c @@ -37,21 +37,21 @@ __attribute__((__aligned__(4))) qp_pixel_t qp_internal_global_pixel_lookup_table // Helpers uint32_t qp_internal_num_pixels_in_buffer(painter_device_t device) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; return ((QUANTUM_PAINTER_PIXDATA_BUFFER_SIZE * 8) / driver->native_bits_per_pixel); } // qp_setpixel internal implementation, but accepts a buffer with pre-converted native pixel. Only the first pixel is used. bool qp_internal_setpixel_impl(painter_device_t device, uint16_t x, uint16_t y) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; return driver->driver_vtable->viewport(device, x, y, x, y) && driver->driver_vtable->pixdata(device, qp_internal_global_pixdata_buffer, 1); } // Fills the global native pixel buffer with equivalent pixels matching the supplied HSV void qp_internal_fill_pixdata(painter_device_t device, uint32_t num_pixels, uint8_t hue, uint8_t sat, uint8_t val) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device); - num_pixels = QP_MIN(pixels_in_pixdata, num_pixels); + painter_driver_t *driver = (painter_driver_t *)device; + uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device); + num_pixels = QP_MIN(pixels_in_pixdata, num_pixels); // Convert the color to native pixel format qp_pixel_t color = {.hsv888 = {.h = hue, .s = sat, .v = val}}; @@ -144,8 +144,8 @@ bool qp_internal_load_qgf_palette(qp_stream_t *stream, uint8_t bpp) { // Quantum Painter External API: qp_setpixel bool qp_setpixel(painter_device_t device, uint16_t x, uint16_t y, uint8_t hue, uint8_t sat, uint8_t val) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_setpixel: fail (validation_ok == false)\n"); return false; } @@ -174,8 +174,8 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin } qp_dprintf("qp_line(%d, %d, %d, %d): entry\n", (int)x0, (int)y0, (int)x1, (int)y1); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_line: fail (validation_ok == false)\n"); return false; } @@ -228,8 +228,8 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin // Quantum Painter External API: qp_rect bool qp_internal_fillrect_helper_impl(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { - uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device); - struct painter_driver_t *driver = (struct painter_driver_t *)device; + uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device); + painter_driver_t *driver = (painter_driver_t *)device; uint16_t l = QP_MIN(left, right); uint16_t r = QP_MAX(left, right); @@ -252,8 +252,8 @@ bool qp_internal_fillrect_helper_impl(painter_device_t device, uint16_t left, ui bool qp_rect(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint8_t hue, uint8_t sat, uint8_t val, bool filled) { qp_dprintf("qp_rect(%d, %d, %d, %d): entry\n", (int)left, (int)top, (int)right, (int)bottom); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_rect: fail (validation_ok == false)\n"); return false; } diff --git a/quantum/painter/qp_draw_ellipse.c b/quantum/painter/qp_draw_ellipse.c index 7f2f4abcfdd5..e912a3e91fe8 100644 --- a/quantum/painter/qp_draw_ellipse.c +++ b/quantum/painter/qp_draw_ellipse.c @@ -61,8 +61,8 @@ static bool qp_ellipse_helper_impl(painter_device_t device, uint16_t centerx, ui bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, uint16_t sizey, uint8_t hue, uint8_t sat, uint8_t val, bool filled) { qp_dprintf("qp_ellipse: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_ellipse: fail (validation_ok == false)\n"); return false; } diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c index fa806172420b..fb17a05a1b61 100644 --- a/quantum/painter/qp_draw_image.c +++ b/quantum/painter/qp_draw_image.c @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #include "qp_internal.h" @@ -90,7 +90,7 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) { bool qp_close_image(painter_image_handle_t image) { qgf_image_handle_t *qgf_image = (qgf_image_handle_t *)image; - if (!qgf_image->validate_ok) { + if (!qgf_image || !qgf_image->validate_ok) { qp_dprintf("qp_close_image: fail (invalid image)\n"); return false; } @@ -124,7 +124,7 @@ typedef struct qgf_frame_info_t { } qgf_frame_info_t; static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device, qgf_image_handle_t *qgf_image, uint16_t frame_number, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, qgf_frame_info_t *info) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; // Drop out if we can't actually place the data we read out anywhere if (!info) { @@ -209,14 +209,14 @@ static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device, static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint16_t y, painter_image_handle_t image, int frame_number, qgf_frame_info_t *frame_info, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888) { qp_dprintf("qp_drawimage_recolor: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_drawimage_recolor: fail (validation_ok == false)\n"); return false; } qgf_image_handle_t *qgf_image = (qgf_image_handle_t *)image; - if (!qgf_image->validate_ok) { + if (!qgf_image || !qgf_image->validate_ok) { qp_dprintf("qp_drawimage_recolor: fail (invalid image)\n"); return false; } @@ -254,8 +254,8 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1 } // Set up the input state - struct qp_internal_byte_input_state input_state = {.device = device, .src_stream = &qgf_image->stream}; - qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, frame_info->compression_scheme); + qp_internal_byte_input_state_t input_state = {.device = device, .src_stream = &qgf_image->stream}; + qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, frame_info->compression_scheme); if (input_callback == NULL) { qp_dprintf("qp_drawimage_recolor: fail (invalid image compression scheme)\n"); qp_comms_stop(device); @@ -265,7 +265,7 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1 bool ret = false; if (frame_info->bpp <= 8) { // Set up the output state - struct qp_internal_pixel_output_state output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)}; + qp_internal_pixel_output_state_t output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)}; // Decode the pixel data and stream to the display ret = qp_internal_decode_palette(device, pixel_count, frame_info->bpp, input_callback, &input_state, qp_internal_global_pixel_lookup_table, qp_internal_pixel_appender, &output_state); @@ -273,9 +273,13 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1 if (ret && output_state.pixel_write_pos > 0) { ret &= driver->driver_vtable->pixdata(device, qp_internal_global_pixdata_buffer, output_state.pixel_write_pos); } + } else if (frame_info->bpp != driver->native_bits_per_pixel) { + // Prevent stuff like drawing 24bpp images on 16bpp displays + qp_dprintf("Image's bpp doesn't match the target display's native_bits_per_pixel\n"); + return false; } else { // Set up the output state - struct qp_internal_byte_output_state output_state = {.device = device, .byte_write_pos = 0, .max_bytes = qp_internal_num_pixels_in_buffer(device) * driver->native_bits_per_pixel / 8}; + qp_internal_byte_output_state_t output_state = {.device = device, .byte_write_pos = 0, .max_bytes = qp_internal_num_pixels_in_buffer(device) * driver->native_bits_per_pixel / 8}; // Stream the raw pixel data to the display uint32_t byte_count = pixel_count * frame_info->bpp / 8; @@ -414,15 +418,3 @@ void qp_internal_animation_tick(void) { static uint32_t last_anim_exec = 0; deferred_exec_advanced_task(animation_executors, QUANTUM_PAINTER_CONCURRENT_ANIMATIONS, &last_anim_exec); } - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Quantum Painter Core API: qp_internal_task - -void qp_internal_task(void) { - qp_internal_animation_tick(); -#ifdef QUANTUM_PAINTER_LVGL_INTEGRATION_ENABLE - // Run LVGL ticks - void qp_lvgl_internal_tick(void); - qp_lvgl_internal_tick(); -#endif -} diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c index f9fb2bf08f6a..ff6fc01d11ef 100644 --- a/quantum/painter/qp_draw_text.c +++ b/quantum/painter/qp_draw_text.c @@ -136,7 +136,7 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) { bool qp_close_font(painter_font_handle_t font) { qff_font_handle_t *qff_font = (qff_font_handle_t *)font; - if (!qff_font->validate_ok) { + if (!qff_font || !qff_font->validate_ok) { qp_dprintf("qp_close_font: fail (invalid font)\n"); return false; } @@ -164,7 +164,7 @@ typedef bool (*code_point_handler)(qff_font_handle_t *qff_font, uint32_t code_po // Helper that sets up the palette (if required) and returns the offset in the stream that the data starts static inline bool qp_drawtext_prepare_font_for_render(painter_device_t device, qff_font_handle_t *qff_font, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, uint32_t *data_offset) { - struct painter_driver_t *driver = (struct painter_driver_t *)device; + painter_driver_t *driver = (painter_driver_t *)device; // Drop out if we can't actually place the data we read out anywhere if (!data_offset) { @@ -233,7 +233,7 @@ static inline bool qp_drawtext_prepare_glyph_for_render(qff_font_handle_t *qff_f uint8_t glyph_width = (uint8_t)(glyph_info.value & QFF_GLYPH_WIDTH_MASK); uint32_t glyph_offset = ((glyph_info.value & QFF_GLYPH_OFFSET_MASK) >> QFF_GLYPH_WIDTH_BITS); uint32_t data_offset = sizeof(qff_font_descriptor_v1_t) // Skip the font descriptor - + sizeof(qff_ascii_glyph_table_v1_t) // Skip the ascii table + + (qff_font->has_ascii_table ? sizeof(qff_ascii_glyph_table_v1_t) : 0) // Skip the ascii table + (qff_font->num_unicode_glyphs > 0 ? (sizeof(qff_unicode_glyph_table_v1_t) + (qff_font->num_unicode_glyphs * sizeof(qff_unicode_glyph_v1_t))) : 0) // Skip the unicode table + (qff_font->has_palette ? (sizeof(qgf_palette_v1_t) + ((1 << qff_font->bpp) * sizeof(qgf_palette_entry_v1_t))) : 0) // Skip the palette + sizeof(qgf_block_header_v1_t) // Skip the data block header @@ -268,7 +268,7 @@ static inline bool qp_drawtext_prepare_glyph_for_render(qff_font_handle_t *qff_f uint8_t glyph_width = (uint8_t)(glyph_info.value & QFF_GLYPH_WIDTH_MASK); uint32_t glyph_offset = ((glyph_info.value & QFF_GLYPH_OFFSET_MASK) >> QFF_GLYPH_WIDTH_BITS); uint32_t data_offset = sizeof(qff_font_descriptor_v1_t) // Skip the font descriptor - + sizeof(qff_ascii_glyph_table_v1_t) // Skip the ascii table + + (qff_font->has_ascii_table ? sizeof(qff_ascii_glyph_table_v1_t) : 0) // Skip the ascii table + (qff_font->num_unicode_glyphs > 0 ? (sizeof(qff_unicode_glyph_table_v1_t) + (qff_font->num_unicode_glyphs * sizeof(qff_unicode_glyph_v1_t))) : 0) // Skip the unicode table + (qff_font->has_palette ? (sizeof(qgf_palette_v1_t) + ((1 << qff_font->bpp) * sizeof(qgf_palette_entry_v1_t))) : 0) // Skip the palette + sizeof(qgf_block_header_v1_t) // Skip the data block header @@ -319,13 +319,13 @@ static inline bool qp_iterate_code_points(qff_font_handle_t *qff_font, const cha // String width calculation // Callback state -struct code_point_iter_calcwidth_state { +typedef struct code_point_iter_calcwidth_state_t { int16_t width; -}; +} code_point_iter_calcwidth_state_t; // Codepoint handler callback: width calc static inline bool qp_font_code_point_handler_calcwidth(qff_font_handle_t *qff_font, uint32_t code_point, uint8_t width, uint8_t height, void *cb_arg) { - struct code_point_iter_calcwidth_state *state = (struct code_point_iter_calcwidth_state *)cb_arg; + code_point_iter_calcwidth_state_t *state = (code_point_iter_calcwidth_state_t *)cb_arg; // Increment the overall width by this glyph's width state->width += width; @@ -337,19 +337,19 @@ static inline bool qp_font_code_point_handler_calcwidth(qff_font_handle_t *qff_f // String drawing implementation // Callback state -struct code_point_iter_drawglyph_state { - painter_device_t device; - int16_t xpos; - int16_t ypos; - qp_internal_byte_input_callback input_callback; - struct qp_internal_byte_input_state * input_state; - struct qp_internal_pixel_output_state *output_state; -}; +typedef struct code_point_iter_drawglyph_state_t { + painter_device_t device; + int16_t xpos; + int16_t ypos; + qp_internal_byte_input_callback input_callback; + qp_internal_byte_input_state_t * input_state; + qp_internal_pixel_output_state_t *output_state; +} code_point_iter_drawglyph_state_t; // Codepoint handler callback: drawing static inline bool qp_font_code_point_handler_drawglyph(qff_font_handle_t *qff_font, uint32_t code_point, uint8_t width, uint8_t height, void *cb_arg) { - struct code_point_iter_drawglyph_state *state = (struct code_point_iter_drawglyph_state *)cb_arg; - struct painter_driver_t * driver = (struct painter_driver_t *)state->device; + code_point_iter_drawglyph_state_t *state = (code_point_iter_drawglyph_state_t *)cb_arg; + painter_driver_t * driver = (painter_driver_t *)state->device; // Reset the input state's RLE mode -- the stream should already be correctly positioned by qp_iterate_code_points() state->input_state->rle.mode = MARKER_BYTE; // ignored if not using RLE @@ -380,13 +380,13 @@ static inline bool qp_font_code_point_handler_drawglyph(qff_font_handle_t *qff_f int16_t qp_textwidth(painter_font_handle_t font, const char *str) { qff_font_handle_t *qff_font = (qff_font_handle_t *)font; - if (!qff_font->validate_ok) { + if (!qff_font || !qff_font->validate_ok) { qp_dprintf("qp_textwidth: fail (invalid font)\n"); return false; } // Create the codepoint iterator state - struct code_point_iter_calcwidth_state state = {.width = 0}; + code_point_iter_calcwidth_state_t state = {.width = 0}; // Iterate each codepoint, return the calculated width if successful. return qp_iterate_code_points(qff_font, str, qp_font_code_point_handler_calcwidth, &state) ? state.width : 0; } @@ -405,14 +405,14 @@ int16_t qp_drawtext(painter_device_t device, uint16_t x, uint16_t y, painter_fon int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, painter_font_handle_t font, const char *str, uint8_t hue_fg, uint8_t sat_fg, uint8_t val_fg, uint8_t hue_bg, uint8_t sat_bg, uint8_t val_bg) { qp_dprintf("qp_drawtext_recolor: entry\n"); - struct painter_driver_t *driver = (struct painter_driver_t *)device; - if (!driver->validate_ok) { + painter_driver_t *driver = (painter_driver_t *)device; + if (!driver || !driver->validate_ok) { qp_dprintf("qp_drawtext_recolor: fail (validation_ok == false)\n"); return 0; } qff_font_handle_t *qff_font = (qff_font_handle_t *)font; - if (!qff_font->validate_ok) { + if (!qff_font || !qff_font->validate_ok) { qp_dprintf("qp_drawtext_recolor: fail (invalid font)\n"); return false; } @@ -423,8 +423,8 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai } // Set up the byte input state and input callback - struct qp_internal_byte_input_state input_state = {.device = device, .src_stream = &qff_font->stream}; - qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, qff_font->compression_scheme); + qp_internal_byte_input_state_t input_state = {.device = device, .src_stream = &qff_font->stream}; + qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, qff_font->compression_scheme); if (input_callback == NULL) { qp_dprintf("qp_drawtext_recolor: fail (invalid font compression scheme)\n"); qp_comms_stop(device); @@ -432,18 +432,18 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai } // Set up the pixel output state - struct qp_internal_pixel_output_state output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)}; + qp_internal_pixel_output_state_t output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)}; // Set up the codepoint iteration state - struct code_point_iter_drawglyph_state state = {// Common - .device = device, - .xpos = x, - .ypos = y, - // Input - .input_callback = input_callback, - .input_state = &input_state, - // Output - .output_state = &output_state}; + code_point_iter_drawglyph_state_t state = {// Common + .device = device, + .xpos = x, + .ypos = y, + // Input + .input_callback = input_callback, + .input_state = &input_state, + // Output + .output_state = &output_state}; qp_pixel_t fg_hsv888 = {.hsv888 = {.h = hue_fg, .s = sat_fg, .v = val_fg}}; qp_pixel_t bg_hsv888 = {.hsv888 = {.h = hue_bg, .s = sat_bg, .v = val_bg}}; diff --git a/quantum/painter/qp_internal.c b/quantum/painter/qp_internal.c new file mode 100644 index 000000000000..87a30c3f9b72 --- /dev/null +++ b/quantum/painter/qp_internal.c @@ -0,0 +1,103 @@ +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "qp_internal.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Quantum Painter Core API: device registration + +enum { + // Work out how many devices we're actually going to be instantiating + // NOTE: We intentionally do not include surfaces here, despite them conforming to the same API. + QP_NUM_DEVICES = (ILI9163_NUM_DEVICES) // ILI9163 + + (ILI9341_NUM_DEVICES) // ILI9341 + + (ILI9488_NUM_DEVICES) // ILI9488 + + (ST7789_NUM_DEVICES) // ST7789 + + (ST7735_NUM_DEVICES) // ST7735 + + (GC9A01_NUM_DEVICES) // GC9A01 + + (SSD1351_NUM_DEVICES) // SSD1351 +}; + +static painter_device_t qp_devices[QP_NUM_DEVICES] = {NULL}; + +bool qp_internal_register_device(painter_device_t driver) { + for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) { + if (qp_devices[i] == NULL) { + qp_devices[i] = driver; + return true; + } + } + + // We should never get here -- someone has screwed up their device counts during config + qp_dprintf("qp_internal_register_device: no more space for devices!\n"); + return false; +} + +#if (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0 +static void qp_internal_display_timeout_task(void) { + // Handle power on/off state + static bool display_on = true; + bool should_change_display_state = false; + bool target_display_state = false; + if (last_input_activity_elapsed() < (QUANTUM_PAINTER_DISPLAY_TIMEOUT)) { + should_change_display_state = display_on == false; + target_display_state = true; + } else { + should_change_display_state = display_on == true; + target_display_state = false; + } + + if (should_change_display_state) { + for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) { + if (qp_devices[i] != NULL) { + qp_power(qp_devices[i], target_display_state); + } + } + + display_on = target_display_state; + } +} +#endif // (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0 + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Quantum Painter Core API: qp_internal_task + +_Static_assert((QUANTUM_PAINTER_TASK_THROTTLE) > 0 && (QUANTUM_PAINTER_TASK_THROTTLE) < 1000, "QUANTUM_PAINTER_TASK_THROTTLE must be between 1 and 999"); + +void qp_internal_task(void) { + // Perform throttling of the internal processing of Quantum Painter + static uint32_t last_tick = 0; + uint32_t now = timer_read32(); + if (TIMER_DIFF_32(now, last_tick) < (QUANTUM_PAINTER_TASK_THROTTLE)) { + return; + } + last_tick = now; + +#if (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0 + qp_internal_display_timeout_task(); +#endif // (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0 + + // Handle animations + void qp_internal_animation_tick(void); + qp_internal_animation_tick(); + +#ifdef QUANTUM_PAINTER_LVGL_INTEGRATION_ENABLE + // Run LVGL ticks + void qp_lvgl_internal_tick(void); + qp_lvgl_internal_tick(); +#endif + + // Flush (render) dirty regions to corresponding displays +#if !defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT) + bool old_debug_state = debug_enable; + debug_enable = false; +#endif // defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT) + for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) { + if (qp_devices[i] != NULL) { + qp_flush(qp_devices[i]); + } + } +#if !defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT) + debug_enable = old_debug_state; +#endif // defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT) +} diff --git a/quantum/painter/qp_internal_driver.h b/quantum/painter/qp_internal_driver.h index 82a0178a73b1..69da966f8c84 100644 --- a/quantum/painter/qp_internal_driver.h +++ b/quantum/painter/qp_internal_driver.h @@ -1,4 +1,4 @@ -// Copyright 2021 Nick Brassel (@tzarc) +// Copyright 2021-2023 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -19,7 +19,7 @@ typedef bool (*painter_driver_append_pixels)(painter_device_t device, uint8_t *t typedef bool (*painter_driver_append_pixdata)(painter_device_t device, uint8_t *target_buffer, uint32_t pixdata_offset, uint8_t pixdata_byte); // Driver vtable definition -struct painter_driver_vtable_t { +typedef struct painter_driver_vtable_t { painter_driver_init_func init; painter_driver_power_func power; painter_driver_clear_func clear; @@ -29,7 +29,7 @@ struct painter_driver_vtable_t { painter_driver_convert_palette_func palette_convert; painter_driver_append_pixels append_pixels; painter_driver_append_pixdata append_pixdata; -}; +} painter_driver_vtable_t; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Comms callbacks @@ -39,28 +39,28 @@ typedef bool (*painter_driver_comms_start_func)(painter_device_t device); typedef void (*painter_driver_comms_stop_func)(painter_device_t device); typedef uint32_t (*painter_driver_comms_send_func)(painter_device_t device, const void *data, uint32_t byte_count); -struct painter_comms_vtable_t { +typedef struct painter_comms_vtable_t { painter_driver_comms_init_func comms_init; painter_driver_comms_start_func comms_start; painter_driver_comms_stop_func comms_stop; painter_driver_comms_send_func comms_send; -}; +} painter_comms_vtable_t; typedef void (*painter_driver_comms_send_command_func)(painter_device_t device, uint8_t cmd); typedef void (*painter_driver_comms_bulk_command_sequence)(painter_device_t device, const uint8_t *sequence, size_t sequence_len); -struct painter_comms_with_command_vtable_t { - struct painter_comms_vtable_t base; // must be first, so this object can be cast from the painter_comms_vtable_t* type +typedef struct painter_comms_with_command_vtable_t { + painter_comms_vtable_t base; // must be first, so this object can be cast from the painter_comms_vtable_t* type painter_driver_comms_send_command_func send_command; painter_driver_comms_bulk_command_sequence bulk_command_sequence; -}; +} painter_comms_with_command_vtable_t; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver base definition -struct painter_driver_t { - const struct painter_driver_vtable_t *driver_vtable; - const struct painter_comms_vtable_t * comms_vtable; +typedef struct painter_driver_t { + const painter_driver_vtable_t *driver_vtable; + const painter_comms_vtable_t * comms_vtable; // Flag signifying if validation was successful bool validate_ok; @@ -81,4 +81,9 @@ struct painter_driver_t { // Comms config pointer -- needs to point to an appropriate comms config if the comms driver requires it. void *comms_config; -}; +} painter_driver_t; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Device internals + +bool qp_internal_register_device(painter_device_t driver); diff --git a/quantum/painter/qp_stream.h b/quantum/painter/qp_stream.h index c0e745adc1d5..4f2b612e43f6 100644 --- a/quantum/painter/qp_stream.h +++ b/quantum/painter/qp_stream.h @@ -48,14 +48,14 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Stream definition -struct qp_stream_t { +typedef struct qp_stream_t { int16_t (*get)(qp_stream_t *stream); bool (*put)(qp_stream_t *stream, uint8_t c); int (*seek)(qp_stream_t *stream, int32_t offset, int origin); int32_t (*tell)(qp_stream_t *stream); bool (*is_eof)(qp_stream_t *stream); void (*close)(qp_stream_t *stream); -}; +} qp_stream_t; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Memory streams diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk index 199e406dd6f4..7752936cbdc3 100644 --- a/quantum/painter/rules.mk +++ b/quantum/painter/rules.mk @@ -24,6 +24,7 @@ SRC += \ $(QUANTUM_DIR)/unicode/utf8.c \ $(QUANTUM_DIR)/color.c \ $(QUANTUM_DIR)/painter/qp.c \ + $(QUANTUM_DIR)/painter/qp_internal.c \ $(QUANTUM_DIR)/painter/qp_stream.c \ $(QUANTUM_DIR)/painter/qgf.c \ $(QUANTUM_DIR)/painter/qff.c \ diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c index 75bb5f81fc3d..abb3817b5f65 100644 --- a/quantum/pointing_device/pointing_device.c +++ b/quantum/pointing_device/pointing_device.c @@ -74,7 +74,8 @@ uint16_t pointing_device_get_shared_cpi(void) { #endif // defined(SPLIT_POINTING_ENABLE) -static report_mouse_t local_mouse_report = {}; +static report_mouse_t local_mouse_report = {}; +static bool pointing_device_force_send = false; extern const pointing_device_driver_t pointing_device_driver; @@ -163,11 +164,11 @@ __attribute__((weak)) void pointing_device_init(void) { * This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons. * */ -__attribute__((weak)) void pointing_device_send(void) { - static report_mouse_t old_report = {}; +__attribute__((weak)) bool pointing_device_send(void) { + static report_mouse_t old_report = {}; + bool should_send_report = has_mouse_report_changed(&local_mouse_report, &old_report); - // If you need to do other things, like debugging, this is the place to do it. - if (has_mouse_report_changed(&local_mouse_report, &old_report)) { + if (should_send_report) { host_mouse_send(&local_mouse_report); } // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device @@ -175,6 +176,8 @@ __attribute__((weak)) void pointing_device_send(void) { memset(&local_mouse_report, 0, sizeof(local_mouse_report)); local_mouse_report.buttons = buttons; memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report)); + + return should_send_report || buttons; } /** @@ -220,18 +223,18 @@ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) { * It applies any optional configuration e.g. rotation or axis inversion and then initiates a send. * */ -__attribute__((weak)) void pointing_device_task(void) { +__attribute__((weak)) bool pointing_device_task(void) { #if defined(SPLIT_POINTING_ENABLE) // Don't poll the target side pointing device. if (!is_keyboard_master()) { - return; + return false; }; #endif #if (POINTING_DEVICE_TASK_THROTTLE_MS > 0) static uint32_t last_exec = 0; if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { - return; + return false; } last_exec = timer_read32(); #endif @@ -286,7 +289,11 @@ __attribute__((weak)) void pointing_device_task(void) { report_mouse_t mousekey_report = mousekey_get_report(); local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons; #endif - pointing_device_send(); + + const bool send_report = pointing_device_send() || pointing_device_force_send; + pointing_device_force_send = false; + + return send_report; } /** @@ -304,7 +311,8 @@ report_mouse_t pointing_device_get_report(void) { * @param[in] mouse_report */ void pointing_device_set_report(report_mouse_t mouse_report) { - local_mouse_report = mouse_report; + pointing_device_force_send = has_mouse_report_changed(&local_mouse_report, &mouse_report); + memcpy(&local_mouse_report, &mouse_report, sizeof(local_mouse_report)); } /** diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h index d430e6cfa4b0..afd653eaeeee 100644 --- a/quantum/pointing_device/pointing_device.h +++ b/quantum/pointing_device/pointing_device.h @@ -28,6 +28,9 @@ along with this program. If not, see . #if defined(POINTING_DEVICE_DRIVER_adns5050) # include "drivers/sensors/adns5050.h" # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW +#elif defined(POINTING_DEVICE_DRIVER_pmw3320) +# include "drivers/sensors/pmw3320.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_adns9800) # include "spi_master.h" # include "drivers/sensors/adns9800.h" @@ -97,8 +100,8 @@ typedef int16_t clamp_range_t; #endif void pointing_device_init(void); -void pointing_device_task(void); -void pointing_device_send(void); +bool pointing_device_task(void); +bool pointing_device_send(void); report_mouse_t pointing_device_get_report(void); void pointing_device_set_report(report_mouse_t mouse_report); uint16_t pointing_device_get_cpi(void); diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c index 5e78817c7c5f..fc3106e37e9a 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.c +++ b/quantum/pointing_device/pointing_device_auto_mouse.c @@ -18,9 +18,16 @@ #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE # include "pointing_device_auto_mouse.h" +# include "debug.h" +# include "action_util.h" +# include "quantum_keycodes.h" /* local data structure for tracking auto mouse */ -static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER}; +static auto_mouse_context_t auto_mouse_context = { + .config.layer = (uint8_t)(AUTO_MOUSE_DEFAULT_LAYER), + .config.timeout = (uint16_t)(AUTO_MOUSE_TIME), + .config.debounce = (uint8_t)(AUTO_MOUSE_DEBOUNCE), +}; /* local functions */ static bool is_mouse_record(uint16_t keycode, keyrecord_t* record); @@ -62,6 +69,24 @@ uint8_t get_auto_mouse_layer(void) { return auto_mouse_context.config.layer; } +/** + * @brief Get the current timeout to turn off mouse layer + * + * @return uint16_t timeout in ms + */ +uint16_t get_auto_mouse_timeout(void) { + return auto_mouse_context.config.timeout; +} + +/** + * @brief Get the auto mouse debouncing timeout + * + * @return uint8_t + */ +uint8_t get_auto_mouse_debounce(void) { + return auto_mouse_context.config.debounce; +} + /** * @brief get layer_toggled value * @@ -114,6 +139,28 @@ void set_auto_mouse_layer(uint8_t layer) { auto_mouse_reset(); } +/** + * @brief Changes the timeout for the mouse auto layer to be disabled + * + * @param timeout + */ +void set_auto_mouse_timeout(uint16_t timeout) { + if (auto_mouse_context.config.timeout == timeout) return; + auto_mouse_context.config.timeout = timeout; + auto_mouse_reset(); +} + +/** + * @brief Set the auto mouse key debounce + * + * @param debounce + */ +void set_auto_mouse_debounce(uint8_t debounce) { + if (auto_mouse_context.config.debounce == debounce) return; + auto_mouse_context.config.debounce = debounce; + auto_mouse_reset(); +} + /** * @brief toggle mouse layer setting * @@ -181,7 +228,7 @@ __attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) { */ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { // skip if disabled, delay timer running, or debounce - if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { + if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= auto_mouse_context.config.debounce || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { return; } // update activation and reset debounce @@ -192,7 +239,7 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { layer_on((AUTO_MOUSE_TARGET_LAYER)); } - } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) { + } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) { layer_off((AUTO_MOUSE_TARGET_LAYER)); auto_mouse_context.timer.active = 0; } diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h index 0f26af79e670..1343855e0017 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.h +++ b/quantum/pointing_device/pointing_device_auto_mouse.h @@ -16,11 +16,14 @@ #pragma once -#include - -#include "quantum.h" +#include +#include #include "pointing_device.h" -#include "print.h" +#include "keycodes.h" +#include "action.h" +#include "report.h" +#include "action_layer.h" +#include "action_tapping.h" /* check settings and set defaults */ #ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE @@ -43,8 +46,10 @@ /* data structure */ typedef struct { struct { - bool is_enabled; - uint8_t layer; + bool is_enabled; + uint8_t layer; + uint16_t timeout; + uint8_t debounce; } config; struct { uint16_t active; @@ -62,6 +67,10 @@ void set_auto_mouse_enable(bool enable); // enabl bool get_auto_mouse_enable(void); // get auto_mouse_enable void set_auto_mouse_layer(uint8_t layer); // set target layer by index uint8_t get_auto_mouse_layer(void); // get target layer index +void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout +uint16_t get_auto_mouse_timeout(void); // get layer timeout +void set_auto_mouse_debounce(uint8_t debounce); // set debounce +uint8_t get_auto_mouse_debounce(void); // get debounce void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!) layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced) diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c index d6f29c062e2b..9a4315f76fdf 100644 --- a/quantum/pointing_device/pointing_device_drivers.c +++ b/quantum/pointing_device/pointing_device_drivers.c @@ -50,6 +50,28 @@ const pointing_device_driver_t pointing_device_driver = { }; // clang-format on +#elif defined(POINTING_DEVICE_DRIVER_pmw3320) +report_mouse_t pmw3320_get_report(report_mouse_t mouse_report) { + report_pmw3320_t data = pmw3320_read_burst(); + + if (data.dx != 0 || data.dy != 0) { + pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); + mouse_report.x = (mouse_xy_report_t)data.dx; + mouse_report.y = (mouse_xy_report_t)data.dy; + } + + return mouse_report; +} + +// clang-format off +const pointing_device_driver_t pointing_device_driver = { + .init = pmw3320_init, + .get_report = pmw3320_get_report, + .set_cpi = pmw3320_set_cpi, + .get_cpi = pmw3320_get_cpi, +}; +// clang-format on + #elif defined(POINTING_DEVICE_DRIVER_adns9800) report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) { diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index c189dd02b713..a8464e1b830c 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -1,5 +1,6 @@ #include "audio.h" #include "process_audio.h" +#include #ifndef VOICE_CHANGE_SONG # define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND) @@ -12,7 +13,7 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG; float compute_freq_for_midi_note(uint8_t note) { // https://en.wikipedia.org/wiki/MIDI_tuning_standard - return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A; + return powf(2.0f, (note - 69) / 12.0f) * PITCH_STANDARD_A; } bool process_audio(uint16_t keycode, keyrecord_t *record) { @@ -61,6 +62,3 @@ void process_audio_noteoff(uint8_t note) { void process_audio_all_notes_off(void) { stop_all_notes(); } - -__attribute__((weak)) void audio_on_user(void) {} -__attribute__((weak)) void audio_off_user(void) {} diff --git a/quantum/process_keycode/process_audio.h b/quantum/process_keycode/process_audio.h index 42cfab4af27d..69e201e447f0 100644 --- a/quantum/process_keycode/process_audio.h +++ b/quantum/process_keycode/process_audio.h @@ -1,11 +1,12 @@ #pragma once +#include +#include +#include "action.h" + float compute_freq_for_midi_note(uint8_t note); bool process_audio(uint16_t keycode, keyrecord_t *record); void process_audio_noteon(uint8_t note); void process_audio_noteoff(uint8_t note); void process_audio_all_notes_off(void); - -void audio_on_user(void); -void audio_off_user(void); diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index c744f5e76c40..c53026548d7b 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -14,27 +14,28 @@ * along with this program. If not, see . */ -#ifdef AUTO_SHIFT_ENABLE - -# include -# include "process_auto_shift.h" - -# ifndef AUTO_SHIFT_DISABLED_AT_STARTUP -# define AUTO_SHIFT_STARTUP_STATE true /* enabled */ -# else -# define AUTO_SHIFT_STARTUP_STATE false /* disabled */ -# endif +#include "process_auto_shift.h" +#include "quantum.h" +#include "action_util.h" +#include "timer.h" +#include "keycodes.h" + +#ifndef AUTO_SHIFT_DISABLED_AT_STARTUP +# define AUTO_SHIFT_STARTUP_STATE true /* enabled */ +#else +# define AUTO_SHIFT_STARTUP_STATE false /* disabled */ +#endif // Stores the last Auto Shift key's up or down time, for evaluation or keyrepeat. static uint16_t autoshift_time = 0; -# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) +#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) // Stores the last key's up or down time, to replace autoshift_time so that Tap Hold times are accurate. static uint16_t retroshift_time = 0; // Stores a possibly Retro Shift key's up or down time, as retroshift_time needs // to be set before the Retro Shift key is evaluated if it is interrupted by an // Auto Shifted key. static uint16_t last_retroshift_time; -# endif +#endif static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; static uint16_t autoshift_lastkey = KC_NO; static keyrecord_t autoshift_lastrecord; @@ -68,15 +69,23 @@ __attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyreco /** \brief Called on physical press, returns whether is Auto Shift key */ __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { switch (keycode) { -# ifndef NO_AUTO_SHIFT_ALPHA +#ifndef NO_AUTO_SHIFT_ALPHA case AUTO_SHIFT_ALPHA: -# endif -# ifndef NO_AUTO_SHIFT_NUMERIC +#endif +#ifndef NO_AUTO_SHIFT_NUMERIC case AUTO_SHIFT_NUMERIC: +#endif +#ifndef NO_AUTO_SHIFT_SPECIAL +# ifndef NO_AUTO_SHIFT_TAB + case KC_TAB: # endif -# ifndef NO_AUTO_SHIFT_SPECIAL - case AUTO_SHIFT_SPECIAL: +# ifndef NO_AUTO_SHIFT_SYMBOLS + case AUTO_SHIFT_SYMBOLS: # endif +#endif +#ifdef AUTO_SHIFT_ENTER + case KC_ENT: +#endif return true; } return get_custom_auto_shifted_key(keycode, record); @@ -123,9 +132,9 @@ bool get_autoshift_shift_state(uint16_t keycode) { /** \brief Restores the shift key if it was cancelled by Auto Shift */ static void autoshift_flush_shift(void) { autoshift_flags.holding_shift = false; -# ifdef CAPS_WORD_ENABLE +#ifdef CAPS_WORD_ENABLE if (!is_caps_word_on()) -# endif // CAPS_WORD_ENABLE +#endif // CAPS_WORD_ENABLE { del_weak_mods(MOD_BIT(KC_LSFT)); } @@ -147,26 +156,26 @@ static void autoshift_flush_shift(void) { static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) { // clang-format off if ((get_mods() -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) +#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) | get_oneshot_mods() -# endif +#endif ) & (~MOD_BIT(KC_LSFT)) ) { // clang-format on // Prevents keyrepeating unshifted value of key after using it in a key combo. autoshift_lastkey = KC_NO; -# ifndef AUTO_SHIFT_MODIFIERS +#ifndef AUTO_SHIFT_MODIFIERS // We can't return true here anymore because custom unshifted values are // possible and there's no good way to tell whether the press returned // true upon release. set_autoshift_shift_state(keycode, false); autoshift_press_user(keycode, false, record); -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) +# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) set_oneshot_mods(get_oneshot_mods() & (~MOD_BIT(KC_LSFT))); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); -# endif - return false; # endif + return false; +#endif } // Store record to be sent to user functions if there's no release record then. @@ -174,19 +183,19 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) autoshift_lastrecord.event.pressed = false; autoshift_lastrecord.event.time = 0; // clang-format off -# if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY) +#if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY) if (keycode == autoshift_lastkey && -# ifdef AUTO_SHIFT_REPEAT_PER_KEY +# ifdef AUTO_SHIFT_REPEAT_PER_KEY get_auto_shift_repeat(autoshift_lastkey, record) && -# endif -# if !defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY) +# endif +# if !defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY) ( !autoshift_flags.lastshifted -# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY +# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY || get_auto_shift_no_auto_repeat(autoshift_lastkey, record) -# endif - ) && # endif + ) && +# endif TIMER_DIFF_16(now, autoshift_time) < GET_TAPPING_TERM(autoshift_lastkey, record) ) { // clang-format on @@ -203,23 +212,23 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) autoshift_press_user(autoshift_lastkey, autoshift_flags.lastshifted, record); return false; } -# endif +#endif // Use physical shift state of press event to be more like normal typing. -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) +#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) autoshift_flags.lastshifted = (get_mods() | get_oneshot_mods()) & MOD_BIT(KC_LSFT); set_oneshot_mods(get_oneshot_mods() & (~MOD_BIT(KC_LSFT))); -# else +#else autoshift_flags.lastshifted = get_mods() & MOD_BIT(KC_LSFT); -# endif +#endif // Record the keycode so we can simulate it later. autoshift_lastkey = keycode; autoshift_time = now; autoshift_flags.in_progress = true; -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) +#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); -# endif +#endif return false; } @@ -240,11 +249,11 @@ static void autoshift_end(uint16_t keycode, uint16_t now, bool matrix_trigger, k autoshift_flags.lastshifted = autoshift_flags.lastshifted || TIMER_DIFF_16(now, autoshift_time) >= -# ifdef AUTO_SHIFT_TIMEOUT_PER_KEY +#ifdef AUTO_SHIFT_TIMEOUT_PER_KEY get_autoshift_timeout(autoshift_lastkey, record) -# else +#else autoshift_timeout -# endif +#endif ; // clang-format on set_autoshift_shift_state(autoshift_lastkey, autoshift_flags.lastshifted); @@ -259,23 +268,23 @@ static void autoshift_end(uint16_t keycode, uint16_t now, bool matrix_trigger, k autoshift_press_user(autoshift_lastkey, autoshift_flags.lastshifted, record); // clang-format off -# if (defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)) && (!defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY)) +#if (defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)) && (!defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY)) if (matrix_trigger -# ifdef AUTO_SHIFT_REPEAT_PER_KEY +# ifdef AUTO_SHIFT_REPEAT_PER_KEY && get_auto_shift_repeat(autoshift_lastkey, record) -# endif -# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY +# endif +# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY && !get_auto_shift_no_auto_repeat(autoshift_lastkey, record) -# endif +# endif ) { // Prevents release. return; } -# endif +#endif // clang-format on -# if TAP_CODE_DELAY > 0 +#if TAP_CODE_DELAY > 0 wait_ms(TAP_CODE_DELAY); -# endif +#endif autoshift_release_user(autoshift_lastkey, autoshift_flags.lastshifted, record); autoshift_flush_shift(); @@ -303,11 +312,11 @@ void autoshift_matrix_scan(void) { if (autoshift_flags.in_progress) { const uint16_t now = timer_read(); if (TIMER_DIFF_16(now, autoshift_time) >= -# ifdef AUTO_SHIFT_TIMEOUT_PER_KEY +#ifdef AUTO_SHIFT_TIMEOUT_PER_KEY get_autoshift_timeout(autoshift_lastkey, &autoshift_lastrecord) -# else +#else autoshift_timeout -# endif +#endif ) { autoshift_end(autoshift_lastkey, now, true, &autoshift_lastrecord); } @@ -328,18 +337,18 @@ void autoshift_disable(void) { autoshift_flush_shift(); } -# ifndef AUTO_SHIFT_NO_SETUP +#ifndef AUTO_SHIFT_NO_SETUP void autoshift_timer_report(void) { -# ifdef SEND_STRING_ENABLE +# ifdef SEND_STRING_ENABLE const char *autoshift_timeout_str = get_u16_str(autoshift_timeout, ' '); // Skip padding spaces while (*autoshift_timeout_str == ' ') { autoshift_timeout_str++; } send_string(autoshift_timeout_str); -# endif -} # endif +} +#endif bool get_autoshift_state(void) { return autoshift_flags.enabled; @@ -361,11 +370,11 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { // https://github.com/qmk/qmk_firmware/pull/9826#issuecomment-733559550 // clang-format off const uint16_t now = -# if !defined(RETRO_SHIFT) || defined(NO_ACTION_TAPPING) +#if !defined(RETRO_SHIFT) || defined(NO_ACTION_TAPPING) timer_read() -# else +#else (record->event.pressed) ? retroshift_time : timer_read() -# endif +#endif ; // clang-format on @@ -386,7 +395,7 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { autoshift_disable(); break; -# ifndef AUTO_SHIFT_NO_SETUP +#ifndef AUTO_SHIFT_NO_SETUP case AS_UP: autoshift_timeout += 5; break; @@ -396,29 +405,27 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { case AS_RPT: autoshift_timer_report(); break; -# endif +#endif } // If Retro Shift is disabled, possible custom actions shouldn't happen. // clang-format off -# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) -# if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) +#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) +# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY const bool is_hold_on_interrupt = get_hold_on_other_key_press(keycode, record); -# elif defined(IGNORE_MOD_TAP_INTERRUPT) +# else const bool is_hold_on_interrupt = false; -# else - const bool is_hold_on_interrupt = IS_QK_MOD_TAP(keycode); -# endif -# endif +# endif +#endif if (IS_RETRO(keycode) -# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) +#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) // Not tapped or #defines mean that rolls should use hold action. && ( record->tap.count == 0 -# ifdef RETRO_TAPPING_PER_KEY +# ifdef RETRO_TAPPING_PER_KEY || !get_retro_tapping(keycode, record) -# endif - || (record->tap.interrupted && is_hold_on_interrupt)) # endif + || (record->tap.interrupted && is_hold_on_interrupt)) +#endif ) { // clang-format on autoshift_lastkey = KC_NO; @@ -434,25 +441,21 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { // tap.count gets set to 0 in process_action // clang-format off else if (IS_RETRO(keycode) -# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) +#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) && ( record->tap.count == 0 -# ifdef RETRO_TAPPING_PER_KEY +# ifdef RETRO_TAPPING_PER_KEY || !get_retro_tapping(keycode, record) -# endif - ) # endif + ) +#endif ) { // Fixes modifiers not being applied to rolls with AUTO_SHIFT_MODIFIERS set. -# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) - if (autoshift_flags.in_progress -# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY - && get_hold_on_other_key_press(keycode, record) -# endif - ) { +#ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY + if (autoshift_flags.in_progress && get_hold_on_other_key_press(keycode, record)) { autoshift_end(KC_NO, now, false, &autoshift_lastrecord); } -# endif +#endif // clang-format on return true; } @@ -478,7 +481,7 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { return true; } -# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) +#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) // Called to record time before possible delays by action_tapping_process. void retroshift_poll_time(keyevent_t *event) { last_retroshift_time = retroshift_time; @@ -492,6 +495,4 @@ void retroshift_swap_times(void) { last_retroshift_time = temp; } } -# endif - #endif diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index a9e9904c0a7f..e41597e80bf4 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -16,7 +16,11 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" +#include "keyboard.h" +#include "keycodes.h" #ifndef AUTO_SHIFT_TIMEOUT # define AUTO_SHIFT_TIMEOUT 175 @@ -28,6 +32,10 @@ // clang-format off #define AUTO_SHIFT_ALPHA KC_A ... KC_Z #define AUTO_SHIFT_NUMERIC KC_1 ... KC_0 +#define AUTO_SHIFT_SYMBOLS \ + KC_MINUS ... KC_SLASH: \ + case KC_NONUS_BACKSLASH + #ifdef NO_AUTO_SHIFT_TAB #define AUTO_SHIFT_SPECIAL \ KC_MINUS ... KC_SLASH: \ diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c index 137678826646..edc47718f324 100644 --- a/quantum/process_keycode/process_autocorrect.c +++ b/quantum/process_keycode/process_autocorrect.c @@ -1,11 +1,16 @@ // Copyright 2021 Google LLC // Copyright 2021 @filterpaper +// Copyright 2023 Pablo Martinez (@elpekenin) // SPDX-License-Identifier: Apache-2.0 // Original source: https://getreuer.info/posts/keyboards/autocorrection #include "process_autocorrect.h" #include +#include "keycodes.h" +#include "quantum_keycodes.h" #include "keycode_config.h" +#include "send_string.h" +#include "action_util.h" #if __has_include("autocorrect_data.h") # include "autocorrect_data.h" @@ -57,7 +62,7 @@ void autocorrect_toggle(void) { } /** - * @brief handler for determining if autocorrect should process keypress + * @brief handler for user to override whether autocorrect should process this keypress * * @param keycode Keycode registered by matrix press, per keymap * @param record keyrecord_t structure @@ -67,6 +72,23 @@ void autocorrect_toggle(void) { * @return false Stop processing and escape from autocorrect. */ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) { + return process_autocorrect_default_handler(keycode, record, typo_buffer_size, mods); +} + +/** + * @brief fallback handler for determining if autocorrect should process this keypress + * can be used by user callback to get the basic keycode being "wrapped" + * + * NOTE: These values may have been edited by user callback before getting here + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @param typo_buffer_size passed along to allow resetting of autocorrect buffer + * @param mods allow processing of mod status + * @return true Allow autocorection + * @return false Stop processing and escape from autocorrect. + */ +bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) { // See quantum_keycodes.h for reference on these matched ranges. switch (*keycode) { // Exclude these keycodes from processing. @@ -157,10 +179,12 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord * * @param backspaces number of characters to remove * @param str pointer to PROGMEM string to replace mistyped seletion with + * @param typo the wrong string that triggered a correction + * @param correct what it would become after the changes * @return true apply correction * @return false user handled replacement */ -__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str) { +__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) { return true; } @@ -284,11 +308,57 @@ bool process_autocorrect(uint16_t keycode, keyrecord_t *record) { if (code & 128) { // A typo was found! Apply autocorrect. const uint8_t backspaces = (code & 63) + !record->event.pressed; - if (apply_autocorrect(backspaces, (char const *)(autocorrect_data + state + 1))) { + const char * changes = (const char *)(autocorrect_data + state + 1); + + /* Gather info about the typo'd word + * + * Since buffer may contain several words, delimited by spaces, we + * iterate from the end to find the start and length of the typo + */ + char typo[AUTOCORRECT_MAX_LENGTH + 1] = {0}; // extra char for null terminator + + uint8_t typo_len = 0; + uint8_t typo_start = 0; + bool space_last = typo_buffer[typo_buffer_size - 1] == KC_SPC; + for (uint8_t i = typo_buffer_size; i > 0; --i) { + // stop counting after finding space (unless it is the last thing) + if (typo_buffer[i - 1] == KC_SPC && i != typo_buffer_size) { + typo_start = i; + break; + } + + ++typo_len; + } + + // when detecting 'typo:', reduce the length of the string by one + if (space_last) { + --typo_len; + } + + // convert buffer of keycodes into a string + for (uint8_t i = 0; i < typo_len; ++i) { + typo[i] = typo_buffer[typo_start + i] - KC_A + 'a'; + } + + /* Gather the corrected word + * + * A) Correction of 'typo:' -- Code takes into account + * an extra backspace to delete the space (which we dont copy) + * for this reason the offset is correct to "skip" the null terminator + * + * B) When correcting 'typo' -- Need extra offset for terminator + */ + char correct[AUTOCORRECT_MAX_LENGTH + 10] = {0}; // let's hope this is big enough + + uint8_t offset = space_last ? backspaces : backspaces + 1; + strcpy(correct, typo); + strcpy_P(correct + typo_len - offset, changes); + + if (apply_autocorrect(backspaces, changes, typo, correct)) { for (uint8_t i = 0; i < backspaces; ++i) { tap_code(KC_BSPC); } - send_string_P((char const *)(autocorrect_data + state + 1)); + send_string_P(changes); } if (keycode == KC_SPC) { diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h index c7596107e505..ea77d6f56f8e 100644 --- a/quantum/process_keycode/process_autocorrect.h +++ b/quantum/process_keycode/process_autocorrect.h @@ -1,15 +1,19 @@ // Copyright 2021 Google LLC // Copyright 2021 @filterpaper +// Copyright 2023 Pablo Martinez (@elpekenin) // SPDX-License-Identifier: Apache-2.0 // Original source: https://getreuer.info/posts/keyboards/autocorrection #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_autocorrect(uint16_t keycode, keyrecord_t *record); bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); -bool apply_autocorrect(uint8_t backspaces, const char *str); +bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); +bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct); bool autocorrect_is_enabled(void); void autocorrect_enable(void); diff --git a/quantum/process_keycode/process_backlight.h b/quantum/process_keycode/process_backlight.h index 7fe887ae6752..e926833e79cf 100644 --- a/quantum/process_keycode/process_backlight.h +++ b/quantum/process_keycode/process_backlight.h @@ -16,6 +16,8 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_backlight(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_caps_word.c b/quantum/process_keycode/process_caps_word.c index 3850930f13f5..bd861b621ef8 100644 --- a/quantum/process_keycode/process_caps_word.c +++ b/quantum/process_keycode/process_caps_word.c @@ -13,6 +13,62 @@ // limitations under the License. #include "process_caps_word.h" +#include "process_auto_shift.h" +#include "caps_word.h" +#include "keycodes.h" +#include "quantum_keycodes.h" +#include "modifiers.h" +#include "timer.h" +#include "action_tapping.h" +#include "action_util.h" + +#ifdef CAPS_WORD_INVERT_ON_SHIFT +static uint8_t held_mods = 0; + +static bool handle_shift(uint16_t keycode, keyrecord_t* record) { + switch (keycode) { + case OSM(MOD_LSFT): + keycode = KC_LSFT; + break; + case OSM(MOD_RSFT): + keycode = KC_RSFT; + break; + +# ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + if (record->tap.count == 0) { // Mod-tap key is held. + switch (QK_MOD_TAP_GET_MODS(keycode)) { + case MOD_LSFT: + keycode = KC_LSFT; + break; + case MOD_RSFT: + keycode = KC_RSFT; + break; + } + } +# endif // NO_ACTION_TAPPING + } + + if (keycode == KC_LSFT || keycode == KC_RSFT) { + const uint8_t mod = MOD_BIT(keycode); + + if (is_caps_word_on()) { + if (record->event.pressed) { + held_mods |= mod; + } else { + held_mods &= ~mod; + } + return false; + } else if ((held_mods & mod) != 0) { + held_mods &= ~mod; + del_mods(mod); + return record->event.pressed; + } + } + + return true; +} +#endif // CAPS_WORD_INVERT_ON_SHIFT bool process_caps_word(uint16_t keycode, keyrecord_t* record) { if (keycode == QK_CAPS_WORD_TOGGLE) { @@ -21,6 +77,11 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { } return false; } +#ifdef CAPS_WORD_INVERT_ON_SHIFT + if (!handle_shift(keycode, record)) { + return false; + } +#endif // CAPS_WORD_INVERT_ON_SHIFT #ifndef NO_ACTION_ONESHOT const uint8_t mods = get_mods() | get_oneshot_mods(); @@ -95,6 +156,7 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: + case QK_TRI_LAYER_LOWER ... QK_TRI_LAYER_UPPER: // Ignore AltGr. case KC_RALT: case OSM(MOD_RALT): @@ -111,12 +173,14 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { if (record->tap.count == 0) { // Mod-tap key is held. const uint8_t mods = QK_MOD_TAP_GET_MODS(keycode); switch (mods) { +# ifndef CAPS_WORD_INVERT_ON_SHIFT case MOD_LSFT: keycode = KC_LSFT; break; case MOD_RSFT: keycode = KC_RSFT; break; +# endif // CAPS_WORD_INVERT_ON_SHIFT case MOD_RSFT | MOD_RALT: keycode = RSFT(KC_RALT); break; @@ -124,6 +188,9 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { return true; default: caps_word_off(); +# ifdef CAPS_WORD_INVERT_ON_SHIFT + add_mods(held_mods); +# endif // CAPS_WORD_INVERT_ON_SHIFT return true; } } else { @@ -163,12 +230,20 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { clear_weak_mods(); #endif // AUTO_SHIFT_ENABLE if (caps_word_press_user(keycode)) { +#ifdef CAPS_WORD_INVERT_ON_SHIFT + if (held_mods) { + set_weak_mods(get_weak_mods() ^ MOD_BIT(KC_LSFT)); + } +#endif // CAPS_WORD_INVERT_ON_SHIFT send_keyboard_report(); return true; } } caps_word_off(); +#ifdef CAPS_WORD_INVERT_ON_SHIFT + add_mods(held_mods); +#endif // CAPS_WORD_INVERT_ON_SHIFT return true; } diff --git a/quantum/process_keycode/process_caps_word.h b/quantum/process_keycode/process_caps_word.h index f215bbc3a3df..f5eb140d3219 100644 --- a/quantum/process_keycode/process_caps_word.h +++ b/quantum/process_keycode/process_caps_word.h @@ -14,8 +14,9 @@ #pragma once -#include "quantum.h" -#include "caps_word.h" +#include +#include +#include "action.h" /** * @brief Process handler for Caps Word feature. diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index b662a3f2f4d1..0ee58282e603 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c @@ -1,5 +1,7 @@ -#include "audio.h" #include "process_clicky.h" +#include "audio.h" +#include "eeconfig.h" +#include #ifdef AUDIO_CLICKY diff --git a/quantum/process_keycode/process_clicky.h b/quantum/process_keycode/process_clicky.h index 67b6463c5d4d..dfdba1413157 100644 --- a/quantum/process_keycode/process_clicky.h +++ b/quantum/process_keycode/process_clicky.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include "action.h" + void clicky_play(void); bool process_clicky(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 8597649c9296..64d30fc140d9 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -14,18 +14,18 @@ * along with this program. If not, see . */ -#include "print.h" #include "process_combo.h" +#include +#include "process_auto_shift.h" +#include "caps_word.h" +#include "timer.h" +#include "wait.h" +#include "keyboard.h" +#include "keymap_common.h" +#include "action_layer.h" #include "action_tapping.h" -#include "action.h" - -#ifdef COMBO_COUNT -__attribute__((weak)) combo_t key_combos[COMBO_COUNT]; -uint16_t COMBO_LEN = COMBO_COUNT; -#else -extern combo_t key_combos[]; -extern uint16_t COMBO_LEN; -#endif +#include "action_util.h" +#include "keymap_introspection.h" __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} @@ -144,7 +144,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; static inline void release_combo(uint16_t combo_index, combo_t *combo) { if (combo->keycode) { keyrecord_t record = { - .event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false), + .event = MAKE_COMBOEVENT(false), .keycode = combo->keycode, }; #ifndef NO_ACTION_TAPPING @@ -194,8 +194,8 @@ static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) { void clear_combos(void) { uint16_t index = 0; longest_term = 0; - for (index = 0; index < COMBO_LEN; ++index) { - combo_t *combo = &key_combos[index]; + for (index = 0; index < combo_count(); ++index) { + combo_t *combo = combo_get(index); if (!COMBO_ACTIVE(combo)) { RESET_COMBO_STATE(combo); } @@ -232,7 +232,7 @@ static inline void dump_key_buffer(void) { process_record(record); #endif } - record->event.time = 0; + record->event.type = TICK_EVENT; #if defined(CAPS_WORD_ENABLE) && defined(AUTO_SHIFT_ENABLE) // Edge case: preserve the weak Left Shift mod if both Caps Word and @@ -286,7 +286,7 @@ void drop_combo_from_buffer(uint16_t combo_index) { queued_combo_t *qcombo = &combo_buffer[i]; if (qcombo->combo_index == combo_index) { - combo_t *combo = &key_combos[combo_index]; + combo_t *combo = combo_get(combo_index); DISABLE_COMBO(combo); if (i == combo_buffer_read) { @@ -332,8 +332,9 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { KEY_STATE_DOWN(state, key_index); if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) { // this in the end executes the combo when the key_buffer is dumped. - record->keycode = combo->keycode; - record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO); + record->keycode = combo->keycode; + record->event.type = COMBO_EVENT; + record->event.key = MAKE_KEYPOS(0, 0); qrecord->combo_index = combo_index; ACTIVATE_COMBO(combo); @@ -342,7 +343,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { } else { // key was part of the combo but not the last one, "disable" it // by making it a TICK event. - record->event.time = 0; + record->event.type = TICK_EVENT; } } drop_combo_from_buffer(combo_index); @@ -352,7 +353,7 @@ static inline void apply_combos(void) { // Apply all buffered normal combos. for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) { queued_combo_t *buffered_combo = &combo_buffer[i]; - combo_t * combo = &key_combos[buffered_combo->combo_index]; + combo_t * combo = combo_get(buffered_combo->combo_index); #ifdef COMBO_MUST_TAP_PER_COMBO if (get_combo_must_tap(buffered_combo->combo_index, combo)) { @@ -457,7 +458,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * combo_t *drop = NULL; for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) { queued_combo_t *qcombo = &combo_buffer[combo_buffer_i]; - combo_t * buffered_combo = &key_combos[qcombo->combo_index]; + combo_t * buffered_combo = combo_get(qcombo->combo_index); if ((drop = overlaps(buffered_combo, combo))) { DISABLE_COMBO(drop); @@ -563,8 +564,8 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { } #endif - for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) { - combo_t *combo = &key_combos[idx]; + for (uint16_t idx = 0; idx < combo_count(); ++idx) { + combo_t *combo = combo_get(idx); is_combo_key |= process_single_combo(combo, keycode, record, idx); no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo)); } diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index e430c4a5f726..f1d534236e24 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -16,9 +16,11 @@ #pragma once -#include "progmem.h" -#include "quantum.h" #include +#include +#include "action.h" +#include "keycodes.h" +#include "quantum_keycodes.h" #ifdef EXTRA_SHORT_COMBOS # define MAX_COMBO_LENGTH 6 @@ -37,7 +39,7 @@ # define COMBO_BUFFER_LENGTH 4 #endif -typedef struct { +typedef struct combo_t { const uint16_t *keys; uint16_t keycode; #ifdef EXTRA_SHORT_COMBOS diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index c2e7e7716f5f..30a51503dbb7 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -17,6 +17,15 @@ /* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ #include "process_dynamic_macro.h" +#include +#include "action_layer.h" +#include "keycodes.h" +#include "debug.h" +#include "wait.h" + +#ifdef BACKLIGHT_ENABLE +# include "backlight.h" +#endif // default feedback method void dynamic_macro_led_blink(void) { @@ -29,7 +38,7 @@ void dynamic_macro_led_blink(void) { /* User hooks for Dynamic Macros */ -__attribute__((weak)) void dynamic_macro_record_start_user(void) { +__attribute__((weak)) void dynamic_macro_record_start_user(int8_t direction) { dynamic_macro_led_blink(); } @@ -62,10 +71,10 @@ __attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrec * @param[out] macro_pointer The new macro buffer iterator. * @param[in] macro_buffer The macro buffer used to initialize macro_pointer. */ -void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) { +void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) { dprintln("dynamic macro recording: started"); - dynamic_macro_record_start_user(); + dynamic_macro_record_start_user(direction); clear_keyboard(); layer_clear(); @@ -151,6 +160,67 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin *macro_end = macro_pointer; } +/* Both macros use the same buffer but read/write on different + * ends of it. + * + * Macro1 is written left-to-right starting from the beginning of + * the buffer. + * + * Macro2 is written right-to-left starting from the end of the + * buffer. + * + * ¯o_buffer macro_end + * v v + * +------------------------------------------------------------+ + * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| + * +------------------------------------------------------------+ + * ^ ^ + * r_macro_end r_macro_buffer + * + * During the recording when one macro encounters the end of the + * other macro, the recording is stopped. Apart from this, there + * are no arbitrary limits for the macros' length in relation to + * each other: for example one can either have two medium sized + * macros or one long macro and one short macro. Or even one empty + * and one using the whole buffer. + */ +static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; + +/* Pointer to the first buffer element after the first macro. + * Initially points to the very beginning of the buffer since the + * macro is empty. */ +static keyrecord_t *macro_end = macro_buffer; + +/* The other end of the macro buffer. Serves as the beginning of + * the second macro. */ +static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; + +/* Like macro_end but for the second macro. */ +static keyrecord_t *r_macro_end = macro_buffer + DYNAMIC_MACRO_SIZE - 1; + +/* A persistent pointer to the current macro position (iterator) + * used during the recording. */ +static keyrecord_t *macro_pointer = NULL; + +/* 0 - no macro is being recorded right now + * 1,2 - either macro 1 or 2 is being recorded */ +static uint8_t macro_id = 0; + +/** + * If a dynamic macro is currently being recorded, stop recording. + */ +void dynamic_macro_stop_recording(void) { + switch (macro_id) { + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; + } + macro_id = 0; +} + /* Handle the key events related to the dynamic macros. Should be * called from process_record_user() like this: * @@ -162,62 +232,16 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin * } */ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { - /* Both macros use the same buffer but read/write on different - * ends of it. - * - * Macro1 is written left-to-right starting from the beginning of - * the buffer. - * - * Macro2 is written right-to-left starting from the end of the - * buffer. - * - * ¯o_buffer macro_end - * v v - * +------------------------------------------------------------+ - * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| - * +------------------------------------------------------------+ - * ^ ^ - * r_macro_end r_macro_buffer - * - * During the recording when one macro encounters the end of the - * other macro, the recording is stopped. Apart from this, there - * are no arbitrary limits for the macros' length in relation to - * each other: for example one can either have two medium sized - * macros or one long macro and one short macro. Or even one empty - * and one using the whole buffer. - */ - static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; - - /* Pointer to the first buffer element after the first macro. - * Initially points to the very beginning of the buffer since the - * macro is empty. */ - static keyrecord_t *macro_end = macro_buffer; - - /* The other end of the macro buffer. Serves as the beginning of - * the second macro. */ - static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; - - /* Like macro_end but for the second macro. */ - static keyrecord_t *r_macro_end = r_macro_buffer; - - /* A persistent pointer to the current macro position (iterator) - * used during the recording. */ - static keyrecord_t *macro_pointer = NULL; - - /* 0 - no macro is being recorded right now - * 1,2 - either macro 1 or 2 is being recorded */ - static uint8_t macro_id = 0; - if (macro_id == 0) { /* No macro recording in progress. */ if (!record->event.pressed) { switch (keycode) { case QK_DYNAMIC_MACRO_RECORD_START_1: - dynamic_macro_record_start(¯o_pointer, macro_buffer); + dynamic_macro_record_start(¯o_pointer, macro_buffer, +1); macro_id = 1; return false; case QK_DYNAMIC_MACRO_RECORD_START_2: - dynamic_macro_record_start(¯o_pointer, r_macro_buffer); + dynamic_macro_record_start(¯o_pointer, r_macro_buffer, -1); macro_id = 2; return false; case QK_DYNAMIC_MACRO_PLAY_1: @@ -238,15 +262,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release * just after the recording * starts for DM_RSTP. */ - switch (macro_id) { - case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; - case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; - } - macro_id = 0; + dynamic_macro_stop_recording(); } return false; #ifdef DYNAMIC_MACRO_NO_NESTING diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h index 39036541b8d9..2f10733cae31 100644 --- a/quantum/process_keycode/process_dynamic_macro.h +++ b/quantum/process_keycode/process_dynamic_macro.h @@ -18,7 +18,9 @@ /* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" /* May be overridden with a custom value. Be aware that the effective * macro length is half of this value: each keypress is recorded twice @@ -35,7 +37,8 @@ void dynamic_macro_led_blink(void); bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record); -void dynamic_macro_record_start_user(void); +void dynamic_macro_record_start_user(int8_t direction); void dynamic_macro_play_user(int8_t direction); void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); void dynamic_macro_record_end_user(int8_t direction); +void dynamic_macro_stop_recording(void); diff --git a/quantum/process_keycode/process_dynamic_tapping_term.c b/quantum/process_keycode/process_dynamic_tapping_term.c index 146b9fccd726..cf52626e428c 100644 --- a/quantum/process_keycode/process_dynamic_tapping_term.c +++ b/quantum/process_keycode/process_dynamic_tapping_term.c @@ -14,8 +14,10 @@ * along with this program. If not, see . */ -#include "quantum.h" #include "process_dynamic_tapping_term.h" +#include "quantum.h" +#include "keycodes.h" +#include "send_string.h" #ifndef DYNAMIC_TAPPING_TERM_INCREMENT # define DYNAMIC_TAPPING_TERM_INCREMENT 5 diff --git a/quantum/process_keycode/process_dynamic_tapping_term.h b/quantum/process_keycode/process_dynamic_tapping_term.h index 85e83ee73b0a..fee29e18dfdb 100644 --- a/quantum/process_keycode/process_dynamic_tapping_term.h +++ b/quantum/process_keycode/process_dynamic_tapping_term.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include "action.h" diff --git a/quantum/process_keycode/process_grave_esc.c b/quantum/process_keycode/process_grave_esc.c index ddf027391d5a..d786f57a8034 100644 --- a/quantum/process_keycode/process_grave_esc.c +++ b/quantum/process_keycode/process_grave_esc.c @@ -14,6 +14,9 @@ * along with this program. If not, see . */ #include "process_grave_esc.h" +#include "keycodes.h" +#include "modifiers.h" +#include "action_util.h" /* true if the last press of QK_GRAVE_ESCAPE was shifted (i.e. GUI or SHIFT were pressed), false otherwise. * Used to ensure that the correct keycode is released if the key is released. diff --git a/quantum/process_keycode/process_grave_esc.h b/quantum/process_keycode/process_grave_esc.h index bbf448376314..358ff3c4e78f 100755 --- a/quantum/process_keycode/process_grave_esc.h +++ b/quantum/process_keycode/process_grave_esc.h @@ -15,6 +15,8 @@ */ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_grave_esc(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_haptic.h b/quantum/process_keycode/process_haptic.h index 6dbb0f014d06..7e61f6c0d6a4 100644 --- a/quantum/process_keycode/process_haptic.h +++ b/quantum/process_keycode/process_haptic.h @@ -15,6 +15,7 @@ */ #pragma once +#include #include #include "action.h" diff --git a/quantum/process_keycode/process_joystick.h b/quantum/process_keycode/process_joystick.h index 1fb8757708d7..aa1a4432716f 100644 --- a/quantum/process_keycode/process_joystick.h +++ b/quantum/process_keycode/process_joystick.h @@ -17,6 +17,7 @@ #pragma once #include -#include "quantum.h" +#include +#include "action.h" bool process_joystick(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_key_lock.h b/quantum/process_keycode/process_key_lock.h index 5159b0ba023c..858945a8e448 100644 --- a/quantum/process_keycode/process_key_lock.h +++ b/quantum/process_keycode/process_key_lock.h @@ -16,7 +16,9 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" void cancel_key_lock(void); bool process_key_lock(uint16_t *keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_key_override.c b/quantum/process_keycode/process_key_override.c index 17e490e67ae3..264e2562b8cf 100644 --- a/quantum/process_keycode/process_key_override.c +++ b/quantum/process_keycode/process_key_override.c @@ -15,12 +15,14 @@ * along with this program. If not, see . */ -#include "quantum.h" +#include "process_key_override.h" #include "report.h" #include "timer.h" -#include "process_key_override.h" - -#include +#include "debug.h" +#include "wait.h" +#include "action_util.h" +#include "quantum.h" +#include "quantum_keycodes.h" #ifndef KEY_OVERRIDE_REPEAT_DELAY # define KEY_OVERRIDE_REPEAT_DELAY 500 @@ -322,6 +324,15 @@ static bool try_activating_override(const uint16_t keycode, const uint8_t layer, clear_active_override(false); +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE + // Send a dummy keycode before unregistering the modifier(s) + // so that suppressing the modifier(s) doesn't falsely get interpreted + // by the host OS as a tap of a modifier key. + // For example, unintended activations of the start menu on Windows when + // using a GUI+ key override with suppressed mods. + neutralize_flashing_modifiers(active_mods); +#endif + active_override = override; active_override_trigger_is_down = true; diff --git a/quantum/process_keycode/process_key_override.h b/quantum/process_keycode/process_key_override.h index fd76f297a807..3e37c7e63a60 100644 --- a/quantum/process_keycode/process_key_override.h +++ b/quantum/process_keycode/process_key_override.h @@ -18,9 +18,8 @@ #pragma once #include -#include #include - +#include "action.h" #include "action_layer.h" /** diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index a9823b628503..ca017a577deb 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -16,6 +16,7 @@ #include "process_leader.h" #include "leader.h" +#include "quantum_keycodes.h" bool process_leader(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h index eb0f721f6008..b78fbb94dff6 100644 --- a/quantum/process_keycode/process_leader.h +++ b/quantum/process_keycode/process_leader.h @@ -16,6 +16,8 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_leader(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c index 5fafe8550fc4..3b35884d68a7 100644 --- a/quantum/process_keycode/process_magic.c +++ b/quantum/process_keycode/process_magic.c @@ -14,8 +14,13 @@ * along with this program. If not, see . */ #include "process_magic.h" +#include "keycode_config.h" +#include "keycodes.h" +#include "eeconfig.h" #ifdef AUDIO_ENABLE +# include "audio.h" + # ifndef AG_NORM_SONG # define AG_NORM_SONG SONG(AG_NORM_SOUND) # endif diff --git a/quantum/process_keycode/process_magic.h b/quantum/process_keycode/process_magic.h index 1eb39f14557c..aa65a43baede 100644 --- a/quantum/process_keycode/process_magic.h +++ b/quantum/process_keycode/process_magic.h @@ -15,6 +15,8 @@ */ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_magic(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index ce62559849a6..377fcb69e25b 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -15,12 +15,13 @@ */ #include "process_midi.h" -#ifdef MIDI_ENABLE -# include -# include "midi.h" -# include "qmk_midi.h" +#include +#include "midi.h" +#include "qmk_midi.h" +#include "timer.h" +#include "debug.h" -# ifdef MIDI_BASIC +#ifdef MIDI_BASIC void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); @@ -34,12 +35,9 @@ void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); } -# endif // MIDI_BASIC - -# ifdef MIDI_ADVANCED - -# include "timer.h" +#endif // MIDI_BASIC +#ifdef MIDI_ADVANCED static uint8_t tone_status[2][MIDI_TONE_COUNT]; static uint8_t midi_modulation; @@ -248,11 +246,11 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { return true; } -# endif // MIDI_ADVANCED +#endif // MIDI_ADVANCED void midi_task(void) { midi_device_process(&midi_device); -# ifdef MIDI_ADVANCED +#ifdef MIDI_ADVANCED if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return; midi_modulation_timer = timer_read(); @@ -270,7 +268,5 @@ void midi_task(void) { if (midi_modulation > 127) midi_modulation = 127; } -# endif +#endif } - -#endif // MIDI_ENABLE diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index e528c6ec0cab..64ccc610f90a 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -16,7 +16,10 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" +#include "quantum_keycodes.h" #ifdef MIDI_ENABLE diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 7c572079a719..f047668504c3 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -14,8 +14,10 @@ * along with this program. If not, see . */ #include "process_music.h" +#include "timer.h" #ifdef AUDIO_ENABLE +# include "audio.h" # include "process_audio.h" #endif #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 83726a05ba9f..ed39d3cda523 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -16,7 +16,9 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) diff --git a/quantum/process_keycode/process_programmable_button.h b/quantum/process_keycode/process_programmable_button.h index 47c6ce561440..ef818af4ca6c 100644 --- a/quantum/process_keycode/process_programmable_button.h +++ b/quantum/process_keycode/process_programmable_button.h @@ -18,6 +18,7 @@ along with this program. If not, see . #pragma once #include -#include "quantum.h" +#include +#include "action.h" bool process_programmable_button(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_repeat_key.c b/quantum/process_keycode/process_repeat_key.c new file mode 100644 index 000000000000..73f4ddedcf11 --- /dev/null +++ b/quantum/process_keycode/process_repeat_key.c @@ -0,0 +1,113 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "process_repeat_key.h" +#include "repeat_key.h" +#include "keycodes.h" +#include "quantum_keycodes.h" +#include "action_util.h" + +// Default implementation of remember_last_key_user(). +__attribute__((weak)) bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return true; +} + +static bool remember_last_key(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + switch (keycode) { + // Ignore MO, TO, TG, TT, and TL layer switch keys. + case QK_MOMENTARY ... QK_MOMENTARY_MAX: + case QK_TO ... QK_TO_MAX: + case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: + case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: + // Ignore mod keys. + case KC_LCTL ... KC_RGUI: + case KC_HYPR: + case KC_MEH: +#ifndef NO_ACTION_ONESHOT // Ignore one-shot keys. + case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: + case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: +#endif // NO_ACTION_ONESHOT +#ifdef TRI_LAYER_ENABLE // Ignore Tri Layer keys. + case QK_TRI_LAYER_LOWER: + case QK_TRI_LAYER_UPPER: +#endif // TRI_LAYER_ENABLE + return false; + + // Ignore hold events on tap-hold keys. +#ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: +# ifndef NO_ACTION_LAYER + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: +# endif // NO_ACTION_LAYER + if (record->tap.count == 0) { + return false; + } + break; +#endif // NO_ACTION_TAPPING + +#ifdef SWAP_HANDS_ENABLE + case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: + if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) { + return false; + } + break; +#endif // SWAP_HANDS_ENABLE + + case QK_REPEAT_KEY: +#ifndef NO_ALT_REPEAT_KEY + case QK_ALT_REPEAT_KEY: +#endif // NO_ALT_REPEAT_KEY + return false; + } + + return remember_last_key_user(keycode, record, remembered_mods); +} + +bool process_last_key(uint16_t keycode, keyrecord_t* record) { + if (get_repeat_key_count()) { + return true; + } + + if (record->event.pressed) { + uint8_t remembered_mods = get_mods() | get_weak_mods(); +#ifndef NO_ACTION_ONESHOT + remembered_mods |= get_oneshot_mods(); +#endif // NO_ACTION_ONESHOT + + if (remember_last_key(keycode, record, &remembered_mods)) { + set_last_record(keycode, record); + set_last_mods(remembered_mods); + } + } + + return true; +} + +bool process_repeat_key(uint16_t keycode, keyrecord_t* record) { + if (get_repeat_key_count()) { + return true; + } + + if (keycode == QK_REPEAT_KEY) { + repeat_key_invoke(&record->event); + return false; +#ifndef NO_ALT_REPEAT_KEY + } else if (keycode == QK_ALT_REPEAT_KEY) { + alt_repeat_key_invoke(&record->event); + return false; +#endif // NO_ALT_REPEAT_KEY + } + + return true; +} diff --git a/quantum/process_keycode/process_repeat_key.h b/quantum/process_keycode/process_repeat_key.h new file mode 100644 index 000000000000..c3b200c63220 --- /dev/null +++ b/quantum/process_keycode/process_repeat_key.h @@ -0,0 +1,64 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include +#include "action.h" + +/** + * @brief Process handler for remembering the last key. + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @return true Continue processing keycodes, and send to host + * @return false Stop processing keycodes, and don't send to host + */ +bool process_last_key(uint16_t keycode, keyrecord_t* record); + +/** + * @brief Optional callback defining which keys are remembered. + * + * @param keycode Keycode that was just pressed + * @param record keyrecord_t structure + * @param remembered_mods Mods that will be remembered with this key + * @return true Key is remembered + * @return false Key is ignored + * + * Modifier and layer switch keys are always ignored. For all other keys, this + * callback is called on every key press. Returning true means that the key is + * remembered, false means it is ignored. By default, all non-modifier, + * non-layer switch keys are remembered. + * + * The `remembered_mods` arg represents the mods that will be remembered with + * this key. It can be modified to forget certain mods, for instance to forget + * capitalization when repeating shifted letters: + * + * // Forget Shift on letter keys. + * if (KC_A <= keycode && keycode <= KC_Z && (*remembered_mods & ~MOD_MASK_SHIFT) == 0) { + * *remembered_mods = 0; + * } + */ +bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods); + +/** + * @brief Process handler for Repeat Key feature. + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @return true Continue processing keycodes, and send to host + * @return false Stop processing keycodes, and don't send to host + */ +bool process_repeat_key(uint16_t keycode, keyrecord_t* record); diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index dae129786e22..4e63bf3ca84c 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -14,6 +14,14 @@ * along with this program. If not, see . */ #include "process_rgb.h" +#include "action_util.h" + +#ifdef RGB_MATRIX_ENABLE +# include "rgb_matrix.h" +#endif +#ifdef RGBLIGHT_ENABLE +# include "rgblight.h" +#endif typedef void (*rgb_func_pointer)(void); diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h index 26aca46896bc..b1069d4bb6f7 100644 --- a/quantum/process_keycode/process_rgb.h +++ b/quantum/process_keycode/process_rgb.h @@ -15,6 +15,8 @@ */ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_rgb(const uint16_t keycode, const keyrecord_t *record); diff --git a/quantum/process_keycode/process_secure.h b/quantum/process_keycode/process_secure.h index 2814264b92f5..78d793f0f66f 100644 --- a/quantum/process_keycode/process_secure.h +++ b/quantum/process_keycode/process_secure.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include "action.h" diff --git a/quantum/process_keycode/process_sequencer.h b/quantum/process_keycode/process_sequencer.h index 2b85f24299ed..3a9bdc2b2409 100644 --- a/quantum/process_keycode/process_sequencer.h +++ b/quantum/process_keycode/process_sequencer.h @@ -16,6 +16,8 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" bool process_sequencer(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index 3109ea17114a..f948ad6238b9 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -13,8 +13,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "process_space_cadet.h" +#include "keycodes.h" +#include "timer.h" +#include "action.h" #include "action_tapping.h" +#include "action_util.h" // ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** // Shift / paren setup diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h index fcb70f3b4369..6d10051532c3 100644 --- a/quantum/process_keycode/process_space_cadet.h +++ b/quantum/process_keycode/process_space_cadet.h @@ -15,7 +15,9 @@ */ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); bool process_space_cadet(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index 8ba98bd4bbe6..af26d4ca86c3 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -15,6 +15,7 @@ */ #include "process_steno.h" #include "quantum_keycodes.h" +#include "eeconfig.h" #include "keymap_steno.h" #include #ifdef VIRTSER_ENABLE @@ -173,13 +174,13 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { switch (keycode) { #ifdef STENO_ENABLE_ALL case QK_STENO_BOLT: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { steno_set_mode(STENO_MODE_BOLT); } return false; case QK_STENO_GEMINI: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { steno_set_mode(STENO_MODE_GEMINI); } return false; @@ -193,7 +194,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { } #endif // STENO_COMBINEDMAP case STN__MIN ... STN__MAX: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { n_pressed_keys++; switch (mode) { #ifdef STENO_ENABLE_BOLT diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h index 68d6097b9b78..0dd2103218e5 100644 --- a/quantum/process_keycode/process_steno.h +++ b/quantum/process_keycode/process_steno.h @@ -16,7 +16,9 @@ #pragma once -#include "quantum.h" +#include +#include +#include "action.h" #define BOLT_STROKE_SIZE 4 #define GEMINI_STROKE_SIZE 6 diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 706f5cddbb1b..b8a8d32f350c 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -13,7 +13,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include "process_tap_dance.h" #include "quantum.h" +#include "action_layer.h" +#include "action_tapping.h" +#include "action_util.h" +#include "timer.h" +#include "wait.h" static uint16_t active_td; static uint16_t last_tap_time; @@ -88,6 +95,10 @@ static inline void process_tap_dance_action_on_each_tap(tap_dance_action_t *acti _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); } +static inline void process_tap_dance_action_on_each_release(tap_dance_action_t *action) { + _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_release); +} + static inline void process_tap_dance_action_on_reset(tap_dance_action_t *action) { _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset); del_weak_mods(action->state.weak_mods); @@ -151,8 +162,12 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { process_tap_dance_action_on_each_tap(action); active_td = action->state.finished ? 0 : keycode; } else { + process_tap_dance_action_on_each_release(action); if (action->state.finished) { process_tap_dance_action_on_reset(action); + if (active_td == keycode) { + active_td = 0; + } } } diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 5cb6d9202c6b..2b114dabd36d 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -16,18 +16,17 @@ #pragma once -#ifdef TAP_DANCE_ENABLE - -# include -# include +#include +#include +#include "action.h" typedef struct { uint16_t interrupting_keycode; uint8_t count; uint8_t weak_mods; -# ifndef NO_ACTION_ONESHOT +#ifndef NO_ACTION_ONESHOT uint8_t oneshot_mods; -# endif +#endif bool pressed : 1; bool finished : 1; bool interrupted : 1; @@ -41,6 +40,7 @@ typedef struct { tap_dance_user_fn_t on_each_tap; tap_dance_user_fn_t on_dance_finished; tap_dance_user_fn_t on_reset; + tap_dance_user_fn_t on_each_release; } fn; void *user_data; } tap_dance_action_t; @@ -56,24 +56,27 @@ typedef struct { void (*layer_function)(uint8_t); } tap_dance_dual_role_t; -# define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ - { .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), } +#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \ + { .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset, NULL}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), } -# define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) \ - { .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), } +#define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) \ + { .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), } -# define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \ - { .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), } +#define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \ + { .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), } -# define ACTION_TAP_DANCE_FN(user_fn) \ - { .fn = {NULL, user_fn, NULL}, .user_data = NULL, } +#define ACTION_TAP_DANCE_FN(user_fn) \ + { .fn = {NULL, user_fn, NULL, NULL}, .user_data = NULL, } -# define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \ - { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, } +#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \ + { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, NULL}, .user_data = NULL, } -# define TD(n) (QK_TAP_DANCE | TD_INDEX(n)) -# define TD_INDEX(code) ((code)&0xFF) -# define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions) +#define ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(user_fn_on_each_tap, user_fn_on_each_release, user_fn_on_dance_finished, user_fn_on_dance_reset) \ + { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, user_fn_on_each_release}, .user_data = NULL, } + +#define TD(n) (QK_TAP_DANCE | TD_INDEX(n)) +#define TD_INDEX(code) ((code)&0xFF) +#define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions) extern tap_dance_action_t tap_dance_actions[]; @@ -92,9 +95,3 @@ void tap_dance_pair_reset(tap_dance_state_t *state, void *user_data); void tap_dance_dual_role_on_each_tap(tap_dance_state_t *state, void *user_data); void tap_dance_dual_role_finished(tap_dance_state_t *state, void *user_data); void tap_dance_dual_role_reset(tap_dance_state_t *state, void *user_data); - -#else - -# define TD(n) KC_NO - -#endif diff --git a/quantum/process_keycode/process_tri_layer.h b/quantum/process_keycode/process_tri_layer.h index 9c4e3df1c2f4..5e6e4ff94db2 100644 --- a/quantum/process_keycode/process_tri_layer.h +++ b/quantum/process_keycode/process_tri_layer.h @@ -3,6 +3,8 @@ #pragma once +#include +#include #include "action.h" /** diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 3aa09d5948f2..91a038bab1cd 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -15,110 +15,30 @@ */ #include "process_ucis.h" -#include "unicode.h" -#include "keycode.h" -#include "wait.h" +#include "ucis.h" +#include "keycodes.h" -ucis_state_t ucis_state; - -void ucis_start(void) { - ucis_state.count = 0; - ucis_state.in_progress = true; - - ucis_start_user(); -} - -__attribute__((weak)) void ucis_start_user(void) { - register_unicode(0x2328); // ⌨ -} - -__attribute__((weak)) void ucis_success(uint8_t symbol_index) {} - -static bool is_uni_seq(char *seq) { - uint8_t i; - for (i = 0; seq[i]; i++) { - uint16_t keycode; - if ('1' <= seq[i] && seq[i] <= '0') { - keycode = seq[i] - '1' + KC_1; - } else { - keycode = seq[i] - 'a' + KC_A; - } - if (i > ucis_state.count || ucis_state.codes[i] != keycode) { +bool process_ucis(uint16_t keycode, keyrecord_t *record) { + if (ucis_active() && record->event.pressed) { + bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE; + if (ucis_count() >= UCIS_MAX_INPUT_LENGTH && !special) { return false; } - } - return ucis_state.codes[i] == KC_ENTER || ucis_state.codes[i] == KC_SPACE; -} - -__attribute__((weak)) void ucis_symbol_fallback(void) { - for (uint8_t i = 0; i < ucis_state.count - 1; i++) { - tap_code(ucis_state.codes[i]); - } -} - -__attribute__((weak)) void ucis_cancel(void) {} - -void register_ucis(const uint32_t *code_points) { - for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) { - register_unicode(code_points[i]); - } -} -bool process_ucis(uint16_t keycode, keyrecord_t *record) { - if (!ucis_state.in_progress || !record->event.pressed) { - return true; - } - - bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE; - if (ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) { - return false; - } - - ucis_state.codes[ucis_state.count] = keycode; - ucis_state.count++; - - switch (keycode) { - case KC_BACKSPACE: - if (ucis_state.count >= 2) { - ucis_state.count -= 2; - return true; - } else { - ucis_state.count--; - return false; - } - - case KC_SPACE: - case KC_ENTER: - case KC_ESCAPE: - for (uint8_t i = 0; i < ucis_state.count; i++) { - tap_code(KC_BACKSPACE); - } - - if (keycode == KC_ESCAPE) { - ucis_state.in_progress = false; - ucis_cancel(); - return false; - } - - uint8_t i; - bool symbol_found = false; - for (i = 0; ucis_symbol_table[i].symbol; i++) { - if (is_uni_seq(ucis_symbol_table[i].symbol)) { - symbol_found = true; - register_ucis(ucis_symbol_table[i].code_points); - break; - } + if (!ucis_add(keycode)) { + switch (keycode) { + case KC_BACKSPACE: + return ucis_remove_last(); + case KC_ESCAPE: + ucis_cancel(); + return false; + case KC_SPACE: + case KC_ENTER: + ucis_finish(); + return false; } - if (symbol_found) { - ucis_success(i); - } else { - ucis_symbol_fallback(); - } - - ucis_state.in_progress = false; - return false; - - default: - return true; + } } + + return true; } diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h index 54eb9413d41b..6282df78932d 100644 --- a/quantum/process_keycode/process_ucis.h +++ b/quantum/process_keycode/process_ucis.h @@ -18,48 +18,6 @@ #include #include - #include "action.h" -#ifndef UCIS_MAX_SYMBOL_LENGTH -# define UCIS_MAX_SYMBOL_LENGTH 32 -#endif -#ifndef UCIS_MAX_CODE_POINTS -# define UCIS_MAX_CODE_POINTS 3 -#endif - -typedef struct { - char * symbol; - uint32_t code_points[UCIS_MAX_CODE_POINTS]; -} ucis_symbol_t; - -typedef struct { - uint8_t count; - uint16_t codes[UCIS_MAX_SYMBOL_LENGTH]; - bool in_progress : 1; -} ucis_state_t; - -extern ucis_state_t ucis_state; - -// clang-format off - -#define UCIS_TABLE(...) \ - { \ - __VA_ARGS__, \ - { NULL, {} } \ - } -#define UCIS_SYM(name, ...) \ - { name, {__VA_ARGS__} } - -// clang-format on - -extern const ucis_symbol_t ucis_symbol_table[]; - -void ucis_start(void); -void ucis_start_user(void); -void ucis_symbol_fallback(void); -void ucis_success(uint8_t symbol_index); - -void register_ucis(const uint32_t *code_points); - bool process_ucis(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 1ec76245a342..8ee6fcd7fca7 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -16,6 +16,7 @@ #include "process_unicode.h" #include "unicode.h" +#include "keycodes.h" #include "quantum_keycodes.h" bool process_unicode(uint16_t keycode, keyrecord_t *record) { diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index 341bc8d861dc..9a51ffaf7c9c 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -18,7 +18,6 @@ #include #include - #include "action.h" bool process_unicode(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index a0b901002763..f43770977aa2 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -17,7 +17,8 @@ #include "process_unicode_common.h" #include "unicode.h" #include "action_util.h" -#include "keycode.h" +#include "keycodes.h" +#include "modifiers.h" #if defined(UNICODE_ENABLE) # include "process_unicode.h" @@ -32,10 +33,18 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { bool shifted = get_mods() & MOD_MASK_SHIFT; switch (keycode) { case QK_UNICODE_MODE_NEXT: - cycle_unicode_input_mode(shifted ? -1 : +1); + if (shifted) { + unicode_input_mode_step_reverse(); + } else { + unicode_input_mode_step(); + } break; case QK_UNICODE_MODE_PREVIOUS: - cycle_unicode_input_mode(shifted ? +1 : -1); + if (shifted) { + unicode_input_mode_step(); + } else { + unicode_input_mode_step_reverse(); + } break; case QK_UNICODE_MODE_MACOS: set_unicode_input_mode(UNICODE_MODE_MACOS); diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index fd09a41818f9..046583007930 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -18,7 +18,6 @@ #include #include - #include "action.h" bool process_unicode_common(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 195c093e6e5d..a85568521c5d 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -15,41 +15,12 @@ */ #include "process_unicodemap.h" -#include "unicode.h" -#include "quantum_keycodes.h" -#include "keycode.h" -#include "action_util.h" -#include "host.h" - -__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { - if (keycode >= QK_UNICODEMAP_PAIR) { - // Keycode is a pair: extract index based on Shift / Caps Lock state - uint16_t index; - - uint8_t mods = get_mods() | get_weak_mods(); -#ifndef NO_ACTION_ONESHOT - mods |= get_oneshot_mods(); -#endif - - bool shift = mods & MOD_MASK_SHIFT; - bool caps = host_keyboard_led_state().caps_lock; - if (shift ^ caps) { - index = QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(keycode); - } else { - index = QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(keycode); - } - - return index; - } else { - // Keycode is a regular index - return QK_UNICODEMAP_GET_INDEX(keycode); - } -} +#include "unicodemap.h" +#include "keycodes.h" bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { - uint32_t code_point = pgm_read_dword(unicode_map + unicodemap_index(keycode)); - register_unicode(code_point); + register_unicodemap(unicodemap_index(keycode)); } return true; } diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index 5a3aeb000062..f07082e9efa9 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -18,11 +18,6 @@ #include #include - #include "action.h" -#include "progmem.h" - -extern const uint32_t unicode_map[] PROGMEM; -uint16_t unicodemap_index(uint16_t keycode); -bool process_unicodemap(uint16_t keycode, keyrecord_t *record); +bool process_unicodemap(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/programmable_button.h b/quantum/programmable_button.h index e8c916d75c90..4c2cd534fe80 100644 --- a/quantum/programmable_button.h +++ b/quantum/programmable_button.h @@ -21,9 +21,9 @@ along with this program. If not, see . #include /** - * \defgroup programmable_button + * \file * - * HID Programmable Buttons + * \defgroup programmable_button HID Programmable Buttons * \{ */ diff --git a/quantum/quantum.c b/quantum/quantum.c index 8a6cb962974c..f74cf9fa0c2e 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -17,24 +17,60 @@ #include #include "quantum.h" +#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) +# include "process_backlight.h" +#endif + #ifdef BLUETOOTH_ENABLE # include "outputselect.h" #endif -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" +#ifdef GRAVE_ESC_ENABLE +# include "process_grave_esc.h" +#endif + +#ifdef HAPTIC_ENABLE +# include "process_haptic.h" +#endif + +#ifdef JOYSTICK_ENABLE +# include "process_joystick.h" +#endif + +#ifdef LEADER_ENABLE +# include "process_leader.h" +#endif + +#ifdef MAGIC_KEYCODE_ENABLE +# include "process_magic.h" #endif #ifdef MIDI_ENABLE # include "process_midi.h" #endif -#ifdef VELOCIKEY_ENABLE -# include "velocikey.h" +#ifdef PROGRAMMABLE_BUTTON_ENABLE +# include "process_programmable_button.h" #endif -#ifdef HAPTIC_ENABLE -# include "haptic.h" +#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) +# include "process_rgb.h" +#endif + +#ifdef SECURE_ENABLE +# include "process_secure.h" +#endif + +#ifdef TRI_LAYER_ENABLE +# include "process_tri_layer.h" +#endif + +#ifdef UNICODE_COMMON_ENABLE +# include "process_unicode_common.h" +#endif + +#ifdef VELOCIKEY_ENABLE +# include "velocikey.h" #endif #ifdef AUDIO_ENABLE @@ -115,6 +151,14 @@ __attribute__((weak)) void tap_code16(uint16_t code) { tap_code16_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); } +__attribute__((weak)) bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record) { + return pre_process_record_user(keycode, record); +} + +__attribute__((weak)) bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) { + return true; +} + __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } @@ -169,7 +213,7 @@ void soft_reset_keyboard(void) { /* Convert record into usable keycode via the contained event. */ uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { -#ifdef COMBO_ENABLE +#if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE) if (record->keycode) { return record->keycode; } @@ -203,14 +247,12 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { /* Get keycode, and then process pre tapping functionality */ bool pre_process_record_quantum(keyrecord_t *record) { - if (!( + uint16_t keycode = get_record_keycode(record, true); + return pre_process_record_kb(keycode, record) && #ifdef COMBO_ENABLE - process_combo(get_record_keycode(record, true), record) && + process_combo(keycode, record) && #endif - true)) { - return false; - } - return true; // continue processing + true; } /* Get keycode, and then call keyboard function */ @@ -268,6 +310,9 @@ bool process_record_quantum(keyrecord_t *record) { // Must run asap to ensure all keypresses are recorded. process_dynamic_macro(keycode, record) && #endif +#ifdef REPEAT_KEY_ENABLE + process_last_key(keycode, record) && process_repeat_key(keycode, record) && +#endif #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) process_clicky(keycode, record) && #endif @@ -305,15 +350,15 @@ bool process_record_quantum(keyrecord_t *record) { #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) process_music(keycode, record) && #endif +#ifdef CAPS_WORD_ENABLE + process_caps_word(keycode, record) && +#endif #ifdef KEY_OVERRIDE_ENABLE process_key_override(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif -#ifdef CAPS_WORD_ENABLE - process_caps_word(keycode, record) && -#endif #if defined(UNICODE_COMMON_ENABLE) process_unicode_common(keycode, record) && #endif @@ -463,7 +508,7 @@ void suspend_power_down_quantum(void) { #ifndef NO_SUSPEND_POWER_DOWN // Turn off backlight # ifdef BACKLIGHT_ENABLE - backlight_set(0); + backlight_level_noeeprom(0); # endif # ifdef LED_MATRIX_ENABLE diff --git a/quantum/quantum.h b/quantum/quantum.h index 9c7175a4eefd..258217db96c1 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -18,7 +18,7 @@ #include "platform_deps.h" #include "wait.h" #include "matrix.h" -#include "keymap.h" +#include "keyboard.h" #ifdef BACKLIGHT_ENABLE # include "backlight.h" @@ -36,6 +36,9 @@ # include "rgb_matrix.h" #endif +#include "keymap_common.h" +#include "quantum_keycodes.h" +#include "keycode_config.h" #include "action_layer.h" #include "eeconfig.h" #include "bootloader.h" @@ -44,10 +47,12 @@ #include "sync_timer.h" #include "gpio.h" #include "atomic_util.h" +#include "host.h" #include "led.h" #include "action_util.h" #include "action_tapping.h" #include "print.h" +#include "debug.h" #include "suspend.h" #include #include @@ -88,30 +93,20 @@ extern layer_state_t layer_state; # include "process_music.h" #endif -#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) -# include "process_backlight.h" -#endif - #ifdef LEADER_ENABLE # include "leader.h" -# include "process_leader.h" #endif -#ifdef UNICODE_ENABLE -# include "process_unicode.h" +#ifdef UNICODE_COMMON_ENABLE +# include "unicode.h" #endif #ifdef UCIS_ENABLE -# include "process_ucis.h" +# include "ucis.h" #endif #ifdef UNICODEMAP_ENABLE -# include "process_unicodemap.h" -#endif - -#ifdef UNICODE_COMMON_ENABLE -# include "unicode.h" -# include "process_unicode_common.h" +# include "unicodemap.h" #endif #ifdef KEY_OVERRIDE_ENABLE @@ -142,24 +137,8 @@ extern layer_state_t layer_state; # include "process_space_cadet.h" #endif -#ifdef MAGIC_KEYCODE_ENABLE -# include "process_magic.h" -#endif - -#ifdef JOYSTICK_ENABLE -# include "process_joystick.h" -#endif - #ifdef PROGRAMMABLE_BUTTON_ENABLE -# include "process_programmable_button.h" -#endif - -#ifdef GRAVE_ESC_ENABLE -# include "process_grave_esc.h" -#endif - -#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) -# include "process_rgb.h" +# include "programmable_button.h" #endif #ifdef HD44780_ENABLE @@ -172,7 +151,6 @@ extern layer_state_t layer_state; #ifdef HAPTIC_ENABLE # include "haptic.h" -# include "process_haptic.h" #endif #ifdef OLED_ENABLE @@ -201,7 +179,6 @@ extern layer_state_t layer_state; #ifdef SECURE_ENABLE # include "secure.h" -# include "process_secure.h" #endif #ifdef DYNAMIC_KEYMAP_ENABLE @@ -248,7 +225,11 @@ extern layer_state_t layer_state; #ifdef TRI_LAYER_ENABLE # include "tri_layer.h" -# include "process_tri_layer.h" +#endif + +#ifdef REPEAT_KEY_ENABLE +# include "repeat_key.h" +# include "process_repeat_key.h" #endif void set_single_persistent_default_layer(uint8_t default_layer); @@ -261,6 +242,9 @@ void set_single_persistent_default_layer(uint8_t default_layer); uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache); uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); +bool pre_process_record_quantum(keyrecord_t *record); +bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record); +bool pre_process_record_user(uint16_t keycode, keyrecord_t *record); bool process_action_kb(keyrecord_t *record); bool process_record_kb(uint16_t keycode, keyrecord_t *record); bool process_record_user(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f931b7e4c70a..d3249bd45559 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -179,10 +179,10 @@ #define QK_UNICODE_GET_CODE_POINT(kc) ((kc)&0x7FFF) // UNICODEMAP_ENABLE - Allows Unicode input up to 0x10FFFF, requires unicode_map -#define X(i) (QK_UNICODEMAP | ((i)&0x3FFF)) +#define UM(i) (QK_UNICODEMAP | ((i)&0x3FFF)) #define QK_UNICODEMAP_GET_INDEX(kc) ((kc)&0x3FFF) -#define XP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j +#define UP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j #define QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(kc) ((kc)&0x7F) #define QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(kc) (((kc) >> 7) & 0x7F) diff --git a/quantum/quantum_keycodes_legacy.h b/quantum/quantum_keycodes_legacy.h index 120c98bc6283..260ac1c8a443 100644 --- a/quantum/quantum_keycodes_legacy.h +++ b/quantum/quantum_keycodes_legacy.h @@ -53,3 +53,6 @@ #define GUI_ON QK_MAGIC_GUI_ON #define GUI_OFF QK_MAGIC_GUI_OFF #define GUI_TOG QK_MAGIC_TOGGLE_GUI + +#define X(i) UM(i) +#define XP(i, j) UP(i, j) diff --git a/quantum/raw_hid.h b/quantum/raw_hid.h index 6d60ab2bffc1..16830833ccf4 100644 --- a/quantum/raw_hid.h +++ b/quantum/raw_hid.h @@ -1,5 +1,31 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once +#include + +/** + * \file + * + * \defgroup raw_hid Raw HID API + * \{ + */ + +/** + * \brief Callback, invoked when a raw HID report has been received from the host. + * + * \param data A pointer to the received data. Always 32 bytes in length. + * \param length The length of the buffer. Always 32. + */ void raw_hid_receive(uint8_t *data, uint8_t length); +/** + * \brief Send an HID report. + * + * \param data A pointer to the data to send. Must always be 32 bytes in length. + * \param length The length of the buffer. Must always be 32. + */ void raw_hid_send(uint8_t *data, uint8_t length); + +/** \} */ diff --git a/quantum/repeat_key.c b/quantum/repeat_key.c new file mode 100644 index 000000000000..4567428723ac --- /dev/null +++ b/quantum/repeat_key.c @@ -0,0 +1,283 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "repeat_key.h" +#include "quantum_keycodes.h" + +// Variables saving the state of the last key press. +static keyrecord_t last_record = {0}; +static uint8_t last_mods = 0; +// Signed count of the number of times the last key has been repeated or +// alternate repeated: it is 0 when a key is pressed normally, positive when +// repeated, and negative when alternate repeated. +static int8_t last_repeat_count = 0; +// The repeat_count, but set to 0 outside of repeat_key_invoke() so that it is +// nonzero only while a repeated key is being processed. +static int8_t processing_repeat_count = 0; + +uint16_t get_last_keycode(void) { + return last_record.keycode; +} + +uint8_t get_last_mods(void) { + return last_mods; +} + +void set_last_keycode(uint16_t keycode) { + set_last_record(keycode, &(keyrecord_t){ +#ifndef NO_ACTION_TAPPING + .tap.interrupted = false, + .tap.count = 1, +#endif + }); +} + +void set_last_mods(uint8_t mods) { + last_mods = mods; +} + +void set_last_record(uint16_t keycode, keyrecord_t* record) { + last_record = *record; + last_record.keycode = keycode; + last_repeat_count = 0; +} + +/** @brief Updates `last_repeat_count` in direction `dir`. */ +static void update_last_repeat_count(int8_t dir) { + if (dir * last_repeat_count < 0) { + last_repeat_count = dir; + } else if (dir * last_repeat_count < 127) { + last_repeat_count += dir; + } +} + +int8_t get_repeat_key_count(void) { + return processing_repeat_count; +} + +void repeat_key_invoke(const keyevent_t* event) { + // It is possible (e.g. in rolled presses) that the last key changes while + // the Repeat Key is pressed. To prevent stuck keys, it is important to + // remember separately what key record was processed on press so that the + // the corresponding record is generated on release. + static keyrecord_t registered_record = {0}; + static int8_t registered_repeat_count = 0; + // Since this function calls process_record(), it may recursively call + // itself. We return early if `processing_repeat_count` is nonzero to + // prevent infinite recursion. + if (processing_repeat_count || !last_record.keycode) { + return; + } + + if (event->pressed) { + update_last_repeat_count(1); + // On press, apply the last mods state, stacking on top of current mods. + register_weak_mods(last_mods); + registered_record = last_record; + registered_repeat_count = last_repeat_count; + } + + // Generate a keyrecord and plumb it into the event pipeline. + registered_record.event = *event; + processing_repeat_count = registered_repeat_count; + process_record(®istered_record); + processing_repeat_count = 0; + + // On release, restore the mods state. + if (!event->pressed) { + unregister_weak_mods(last_mods); + } +} + +#ifndef NO_ALT_REPEAT_KEY +/** + * @brief Find alternate keycode from a table of opposing keycode pairs. + * @param table Array of pairs of basic keycodes, declared as PROGMEM. + * @param table_size_bytes The size of the table in bytes. + * @param target The basic keycode to find. + * @return The alternate basic keycode, or KC_NO if none was found. + * + * @note The table keycodes and target must be basic keycodes. + * + * This helper is used several times below to define alternate keys. Given a + * table of pairs of basic keycodes, the function finds the pair containing + * `target` and returns the other keycode in the pair. + */ +static uint8_t find_alt_keycode(const uint8_t (*table)[2], uint8_t table_size_bytes, uint8_t target) { + const uint8_t* keycodes = (const uint8_t*)table; + for (uint8_t i = 0; i < table_size_bytes; ++i) { + if (target == pgm_read_byte(keycodes + i)) { + // Xor (i ^ 1) the index to get the other element in the pair. + return pgm_read_byte(keycodes + (i ^ 1)); + } + } + return KC_NO; +} + +uint16_t get_alt_repeat_key_keycode(void) { + uint16_t keycode = last_record.keycode; + uint8_t mods = last_mods; + + // Call the user callback first to give it a chance to override the default + // alternate key definitions that follow. + uint16_t alt_keycode = get_alt_repeat_key_keycode_user(keycode, mods); + + if (alt_keycode != KC_TRANSPARENT) { + return alt_keycode; + } + + // Convert 8-bit mods to the 5-bit format used in keycodes. This is lossy: + // if left and right handed mods were mixed, they all become right handed. + mods = ((mods & 0xf0) ? /* set right hand bit */ 0x10 : 0) + // Combine right and left hand mods. + | (((mods >> 4) | mods) & 0xf); + + switch (keycode) { + case QK_MODS ... QK_MODS_MAX: // Unpack modifier + basic key. + mods |= QK_MODS_GET_MODS(keycode); + keycode = QK_MODS_GET_BASIC_KEYCODE(keycode); + break; + +# ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode); + break; +# ifndef NO_ACTION_LAYER + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode); + break; +# endif // NO_ACTION_LAYER +# endif // NO_ACTION_TAPPING + +# ifdef SWAP_HANDS_ENABLE + case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: + if (IS_SWAP_HANDS_KEYCODE(keycode)) { + return KC_NO; + } + keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode); + break; +# endif // SWAP_HANDS_ENABLE + } + + if (IS_QK_BASIC(keycode)) { + if ((mods & (MOD_LCTL | MOD_LALT | MOD_LGUI))) { + // The last key was pressed with a modifier other than Shift. + // The following maps + // mod + F <-> mod + B + // and a few others, supporting several core hotkeys used in + // Emacs, Vim, less, and other programs. + // clang-format off + static const uint8_t pairs[][2] PROGMEM = { + {KC_F , KC_B }, // Forward / Backward. + {KC_D , KC_U }, // Down / Up. + {KC_N , KC_P }, // Next / Previous. + {KC_A , KC_E }, // Home / End. + {KC_O , KC_I }, // Older / Newer in Vim jump list. + }; + // clang-format on + alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode); + } else { + // The last key was pressed with no mods or only Shift. The + // following map a few more Vim hotkeys. + // clang-format off + static const uint8_t pairs[][2] PROGMEM = { + {KC_J , KC_K }, // Down / Up. + {KC_H , KC_L }, // Left / Right. + // These two lines map W and E to B, and B to W. + {KC_W , KC_B }, // Forward / Backward by word. + {KC_E , KC_B }, // Forward / Backward by word. + }; + // clang-format on + alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode); + } + + if (!alt_keycode) { + // The following key pairs are considered with any mods. + // clang-format off + static const uint8_t pairs[][2] PROGMEM = { + {KC_LEFT, KC_RGHT}, // Left / Right Arrow. + {KC_UP , KC_DOWN}, // Up / Down Arrow. + {KC_HOME, KC_END }, // Home / End. + {KC_PGUP, KC_PGDN}, // Page Up / Page Down. + {KC_BSPC, KC_DEL }, // Backspace / Delete. + {KC_LBRC, KC_RBRC}, // Brackets [ ] and { }. +#ifdef EXTRAKEY_ENABLE + {KC_WBAK, KC_WFWD}, // Browser Back / Forward. + {KC_MNXT, KC_MPRV}, // Next / Previous Media Track. + {KC_MFFD, KC_MRWD}, // Fast Forward / Rewind Media. + {KC_VOLU, KC_VOLD}, // Volume Up / Down. + {KC_BRIU, KC_BRID}, // Brightness Up / Down. +#endif // EXTRAKEY_ENABLE +#ifdef MOUSEKEY_ENABLE + {KC_MS_L, KC_MS_R}, // Mouse Cursor Left / Right. + {KC_MS_U, KC_MS_D}, // Mouse Cursor Up / Down. + {KC_WH_L, KC_WH_R}, // Mouse Wheel Left / Right. + {KC_WH_U, KC_WH_D}, // Mouse Wheel Up / Down. +#endif // MOUSEKEY_ENABLE + }; + // clang-format on + alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode); + } + + if (alt_keycode) { + // Combine basic keycode with mods. + return (mods << 8) | alt_keycode; + } + } + + return KC_NO; // No alternate key found. +} + +void alt_repeat_key_invoke(const keyevent_t* event) { + static keyrecord_t registered_record = {0}; + static int8_t registered_repeat_count = 0; + // Since this function calls process_record(), it may recursively call + // itself. We return early if `processing_repeat_count` is nonzero to + // prevent infinite recursion. + if (processing_repeat_count) { + return; + } + + if (event->pressed) { + registered_record = (keyrecord_t){ +# ifndef NO_ACTION_TAPPING + .tap.interrupted = false, + .tap.count = 0, +# endif + .keycode = get_alt_repeat_key_keycode(), + }; + } + + // Early return if there is no alternate key defined. + if (!registered_record.keycode) { + return; + } + + if (event->pressed) { + update_last_repeat_count(-1); + registered_repeat_count = last_repeat_count; + } + + // Generate a keyrecord and plumb it into the event pipeline. + registered_record.event = *event; + processing_repeat_count = registered_repeat_count; + process_record(®istered_record); + processing_repeat_count = 0; +} + +// Default implementation of get_alt_repeat_key_keycode_user(). +__attribute__((weak)) uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods) { + return KC_TRANSPARENT; +} +#endif // NO_ALT_REPEAT_KEY diff --git a/quantum/repeat_key.h b/quantum/repeat_key.h new file mode 100644 index 000000000000..8084be24ad4c --- /dev/null +++ b/quantum/repeat_key.h @@ -0,0 +1,83 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include +#include "action.h" +#include "keyboard.h" + +uint16_t get_last_keycode(void); /**< Keycode of the last key. */ +uint8_t get_last_mods(void); /**< Mods active with the last key. */ +void set_last_keycode(uint16_t keycode); /**< Sets the last key. */ +void set_last_mods(uint8_t mods); /**< Sets the last mods. */ + +/** @brief Gets the record for the last key. */ +keyrecord_t* get_last_record(void); + +/** @brief Sets keycode and record info for the last key. */ +void set_last_record(uint16_t keycode, keyrecord_t* record); + +/** + * @brief Signed count of times the key has been repeated or alternate repeated. + * + * @note The count is nonzero only while a repeated or alternate-repeated key is + * being processed. + * + * When a key is pressed normally, the count is 0. When the Repeat Key is used + * to repeat a key, the count is 1 on the first repeat, 2 on the second repeat, + * and continuing up to 127. + * + * Negative counts are used similarly for alternate repeating. When the + * Alternate Repeat Key is used, the count is -1 on the first alternate repeat, + * -2 on the second, continuing down to -127. + */ +int8_t get_repeat_key_count(void); + +/** + * @brief Calls `process_record()` on a generated record repeating the last key. + * @param event Event information in the generated record. + */ +void repeat_key_invoke(const keyevent_t* event); + +#ifndef NO_ALT_REPEAT_KEY + +/** + * @brief Keycode to be used for alternate repeating. + * + * Alternate Repeat performs this keycode based on the last eligible pressed key + * and mods, get_last_keycode() and get_last_mods(). For example, when the last + * key was KC_UP, this function returns KC_DOWN. The function returns KC_NO if + * the last key doesn't have a defined alternate. + */ +uint16_t get_alt_repeat_key_keycode(void); + +/** + * @brief Calls `process_record()` to alternate repeat the last key. + * @param event Event information in the generated record. + */ +void alt_repeat_key_invoke(const keyevent_t* event); + +/** + * @brief Optional user callback to define additional alternate keys. + * + * When `get_alt_repeat_key_keycode()` is called, it first calls this callback. + * It should return a keycode representing the "alternate" of the given keycode + * and mods. Returning KC_NO defers to the default definitions in + * `get_alt_repeat_key_keycode()`. + */ +uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods); + +#endif // NO_ALT_REPEAT_KEY diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h index 6bde60053bf5..5d3df1059e5c 100644 --- a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -10,17 +10,16 @@ static void jellybean_raindrops_set_color(int i, effect_params_t* params) { } bool JELLYBEAN_RAINDROPS(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); if (!params->init) { // Change one LED every tick, make sure speed is not 0 if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { jellybean_raindrops_set_color(random8_max(RGB_MATRIX_LED_COUNT), params); } - return false; - } - - RGB_MATRIX_USE_LIMITS(led_min, led_max); - for (int i = led_min; i < led_max; i++) { - jellybean_raindrops_set_color(i, params); + } else { + for (int i = led_min; i < led_max; i++) { + jellybean_raindrops_set_color(i, params); + } } return rgb_matrix_check_finished_leds(led_max); } diff --git a/quantum/rgb_matrix/animations/pixel_fractal_anim.h b/quantum/rgb_matrix/animations/pixel_fractal_anim.h index 875b4ceb3dc0..4cd1d9b86149 100644 --- a/quantum/rgb_matrix/animations/pixel_fractal_anim.h +++ b/quantum/rgb_matrix/animations/pixel_fractal_anim.h @@ -7,7 +7,11 @@ RGB_MATRIX_EFFECT(PIXEL_FRACTAL) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS static bool PIXEL_FRACTAL(effect_params_t* params) { -# define MID_COL MATRIX_COLS / 2 +# if MATRIX_COLS < 2 +# define MID_COL 1 +# else +# define MID_COL MATRIX_COLS / 2 +# endif static bool led[MATRIX_ROWS][MID_COL]; static uint32_t wait_timer = 0; diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h index 9d63f451e278..26cd73b57804 100644 --- a/quantum/rgb_matrix/animations/pixel_rain_anim.h +++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h @@ -16,13 +16,9 @@ static bool PIXEL_RAIN(effect_params_t* params) { if (!HAS_ANY_FLAGS(g_led_config.flags[led_index], params->flags)) { return; } - if (random8() & 2) { - rgb_matrix_set_color(led_index, 0, 0, 0); - } else { - HSV hsv = {random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v}; - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(led_index, rgb.r, rgb.g, rgb.b); - } + HSV hsv = (random8() & 2) ? (HSV){0, 0, 0} : (HSV){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(led_index, rgb.r, rgb.g, rgb.b); wait_timer = g_rgb_timer + interval(); } diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h index 00d137f1a6ce..d09bdc463171 100644 --- a/quantum/rgb_matrix/animations/typing_heatmap_anim.h +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -1,6 +1,9 @@ #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) RGB_MATRIX_EFFECT(TYPING_HEATMAP) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# ifndef RGB_MATRIX_TYPING_HEATMAP_INCREASE_STEP +# define RGB_MATRIX_TYPING_HEATMAP_INCREASE_STEP 32 +# endif # ifndef RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS # define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25 @@ -16,7 +19,7 @@ RGB_MATRIX_EFFECT(TYPING_HEATMAP) void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { # ifdef RGB_MATRIX_TYPING_HEATMAP_SLIM // Limit effect to pressed keys - g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); + g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], RGB_MATRIX_TYPING_HEATMAP_INCREASE_STEP); # else if (g_led_config.matrix_co[row][col] == NO_LED) { // skip as pressed key doesn't have an led position return; @@ -27,7 +30,7 @@ void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { continue; } if (i_row == row && i_col == col) { - g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); + g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], RGB_MATRIX_TYPING_HEATMAP_INCREASE_STEP); } else { # define LED_DISTANCE(led_a, led_b) sqrt16(((int16_t)(led_a.x - led_b.x) * (int16_t)(led_a.x - led_b.x)) + ((int16_t)(led_a.y - led_b.y) * (int16_t)(led_a.y - led_b.y))) uint8_t distance = LED_DISTANCE(g_led_config.point[g_led_config.matrix_co[row][col]], g_led_config.point[g_led_config.matrix_co[i_row][i_col]]); diff --git a/quantum/rgb_matrix/post_config.h b/quantum/rgb_matrix/post_config.h new file mode 100644 index 000000000000..7162c8679ba3 --- /dev/null +++ b/quantum/rgb_matrix/post_config.h @@ -0,0 +1,29 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +// clang-format off + +// framebuffer +#if defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) || \ + defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) +# define RGB_MATRIX_FRAMEBUFFER_EFFECTS +#endif + +// reactive +#if defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) || \ + defined(ENABLE_RGB_MATRIX_SPLASH) || \ + defined(ENABLE_RGB_MATRIX_MULTISPLASH) || \ + defined(ENABLE_RGB_MATRIX_SOLID_SPLASH) || \ + defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || \ + defined(ENABLE_RGB_MATRIX_SOLID_MULTISPLASH) +# define RGB_MATRIX_KEYPRESSES +#endif diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 86f9a2dd4efb..11b3110f42cb 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -19,8 +19,13 @@ #include "rgb_matrix.h" #include "progmem.h" #include "eeprom.h" +#include "eeconfig.h" +#include "keyboard.h" +#include "sync_timer.h" +#include "debug.h" #include #include +#include #include @@ -428,7 +433,10 @@ void rgb_matrix_task(void) { case RENDERING: rgb_task_render(effect); if (effect) { - rgb_matrix_indicators(); + // Only run the basic indicators in the last render iteration (default there are 5 iterations) + if (rgb_effect_params.iter == RGB_MATRIX_LED_PROCESS_MAX_ITERATIONS) { + rgb_matrix_indicators(); + } rgb_matrix_indicators_advanced(&rgb_effect_params); } break; @@ -459,14 +467,7 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) { * and not sure which would be better. Otherwise, this should be called from * rgb_task_render, right before the iter++ line. */ -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; - if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; -#else - uint8_t min = 0; - uint8_t max = RGB_MATRIX_LED_COUNT; -#endif + RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1); rgb_matrix_indicators_advanced_kb(min, max); } diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 62078f6e60c4..38040fb0ccc4 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -22,12 +22,14 @@ #include #include "rgb_matrix_types.h" #include "color.h" -#include "quantum.h" +#include "keyboard.h" #ifdef IS31FL3731 # include "is31fl3731.h" #elif defined(IS31FL3733) # include "is31fl3733.h" +#elif defined(IS31FL3736) +# include "is31fl3736.h" #elif defined(IS31FL3737) # include "is31fl3737.h" #elif defined(IS31FL3741) @@ -47,39 +49,42 @@ #endif #ifndef RGB_MATRIX_LED_PROCESS_LIMIT -# define RGB_MATRIX_LED_PROCESS_LIMIT (RGB_MATRIX_LED_COUNT + 4) / 5 +# define RGB_MATRIX_LED_PROCESS_LIMIT ((RGB_MATRIX_LED_COUNT + 4) / 5) #endif +#define RGB_MATRIX_LED_PROCESS_MAX_ITERATIONS ((RGB_MATRIX_LED_COUNT + RGB_MATRIX_LED_PROCESS_LIMIT - 1) / RGB_MATRIX_LED_PROCESS_LIMIT) #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT # if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; \ uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ + uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; # endif #else # if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS(min, max) \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ uint8_t min = 0; \ uint8_t max = RGB_MATRIX_LED_COUNT; \ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = 0; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = 0; \ uint8_t max = RGB_MATRIX_LED_COUNT; # endif #endif +#define RGB_MATRIX_USE_LIMITS(min, max) RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter) + #define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \ if (i >= led_min && i < led_max) { \ rgb_matrix_set_color(i, r, g, b); \ diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 5b81915845fb..695ecc78a47a 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -15,6 +15,7 @@ */ #include "rgb_matrix.h" +#include "util.h" /* Each driver needs to define the struct * const rgb_matrix_driver_t rgb_matrix_driver; @@ -23,7 +24,7 @@ * be here if shared between boards. */ -#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741) || defined(IS31FLCOMMON) || defined(CKLED2001) +#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3736) || defined(IS31FL3737) || defined(IS31FL3741) || defined(IS31FLCOMMON) || defined(CKLED2001) # include "i2c_master.h" // TODO: Remove this at some later date @@ -37,13 +38,13 @@ static void init(void) { i2c_init(); # if defined(IS31FL3731) - IS31FL3731_init(DRIVER_ADDR_1); + is31fl3731_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) - IS31FL3731_init(DRIVER_ADDR_2); + is31fl3731_init(DRIVER_ADDR_2); # if defined(DRIVER_ADDR_3) - IS31FL3731_init(DRIVER_ADDR_3); + is31fl3731_init(DRIVER_ADDR_3); # if defined(DRIVER_ADDR_4) - IS31FL3731_init(DRIVER_ADDR_4); + is31fl3731_init(DRIVER_ADDR_4); # endif # endif # endif @@ -52,40 +53,61 @@ static void init(void) { # if !defined(DRIVER_SYNC_1) # define DRIVER_SYNC_1 0 # endif - IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1); + is31fl3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1); # if defined(DRIVER_ADDR_2) # if !defined(DRIVER_SYNC_2) # define DRIVER_SYNC_2 0 # endif - IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2); + is31fl3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2); # if defined(DRIVER_ADDR_3) # if !defined(DRIVER_SYNC_3) # define DRIVER_SYNC_3 0 # endif - IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3); + is31fl3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3); # if defined(DRIVER_ADDR_4) # if !defined(DRIVER_SYNC_4) # define DRIVER_SYNC_4 0 # endif - IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4); + is31fl3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4); +# endif +# endif +# endif + +# elif defined(IS31FL3736) + is31fl3736_init(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + is31fl3736_init(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + is31fl3736_init(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + is31fl3736_init(DRIVER_ADDR_4); # endif # endif # endif # elif defined(IS31FL3737) - IS31FL3737_init(DRIVER_ADDR_1); + is31fl3737_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) - IS31FL3737_init(DRIVER_ADDR_2); + is31fl3737_init(DRIVER_ADDR_2); # if defined(DRIVER_ADDR_3) - IS31FL3737_init(DRIVER_ADDR_3); + is31fl3737_init(DRIVER_ADDR_3); # if defined(DRIVER_ADDR_4) - IS31FL3737_init(DRIVER_ADDR_4); + is31fl3737_init(DRIVER_ADDR_4); # endif # endif # endif # elif defined(IS31FL3741) - IS31FL3741_init(DRIVER_ADDR_1); + is31fl3741_init(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + is31fl3741_init(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + is31fl3741_init(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + is31fl3741_init(DRIVER_ADDR_4); +# endif +# endif +# endif # elif defined(IS31FLCOMMON) IS31FL_common_init(DRIVER_ADDR_1, ISSI_SSR_1); @@ -100,13 +122,13 @@ static void init(void) { # endif # elif defined(CKLED2001) - CKLED2001_init(DRIVER_ADDR_1); + ckled2001_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) - CKLED2001_init(DRIVER_ADDR_2); + ckled2001_init(DRIVER_ADDR_2); # if defined(DRIVER_ADDR_3) - CKLED2001_init(DRIVER_ADDR_3); + ckled2001_init(DRIVER_ADDR_3); # if defined(DRIVER_ADDR_4) - CKLED2001_init(DRIVER_ADDR_4); + ckled2001_init(DRIVER_ADDR_4); # endif # endif # endif @@ -117,59 +139,82 @@ static void init(void) { // This only caches it for later # if defined(IS31FL3731) - IS31FL3731_set_led_control_register(index, enabled, enabled, enabled); + is31fl3731_set_led_control_register(index, enabled, enabled, enabled); # elif defined(IS31FL3733) - IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); + is31fl3733_set_led_control_register(index, enabled, enabled, enabled); +# elif defined(IS31FL3736) + is31fl3736_set_led_control_register(index, enabled, enabled, enabled); # elif defined(IS31FL3737) - IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); + is31fl3737_set_led_control_register(index, enabled, enabled, enabled); # elif defined(IS31FL3741) - IS31FL3741_set_led_control_register(index, enabled, enabled, enabled); + is31fl3741_set_led_control_register(index, enabled, enabled, enabled); # elif defined(IS31FLCOMMON) IS31FL_RGB_set_scaling_buffer(index, enabled, enabled, enabled); # elif defined(CKLED2001) - CKLED2001_set_led_control_register(index, enabled, enabled, enabled); + ckled2001_set_led_control_register(index, enabled, enabled, enabled); # endif } // This actually updates the LED drivers # if defined(IS31FL3731) - IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0); + is31fl3731_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1); + is31fl3731_update_led_control_registers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2); + is31fl3731_update_led_control_registers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3); + is31fl3731_update_led_control_registers(DRIVER_ADDR_4, 3); # endif # endif # endif # elif defined(IS31FL3733) - IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); + is31fl3733_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); + is31fl3733_update_led_control_registers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2); + is31fl3733_update_led_control_registers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3); + is31fl3733_update_led_control_registers(DRIVER_ADDR_4, 3); +# endif +# endif +# endif + +# elif defined(IS31FL3736) + is31fl3736_update_led_control_registers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + is31fl3736_update_led_control_registers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + is31fl3736_update_led_control_registers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + is31fl3736_update_led_control_registers(DRIVER_ADDR_4, 3); # endif # endif # endif # elif defined(IS31FL3737) - IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0); + is31fl3737_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1); + is31fl3737_update_led_control_registers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3737_update_led_control_registers(DRIVER_ADDR_3, 2); + is31fl3737_update_led_control_registers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3737_update_led_control_registers(DRIVER_ADDR_4, 3); + is31fl3737_update_led_control_registers(DRIVER_ADDR_4, 3); # endif # endif # endif # elif defined(IS31FL3741) - IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0); + is31fl3741_update_led_control_registers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + is31fl3741_update_led_control_registers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + is31fl3741_update_led_control_registers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + is31fl3741_update_led_control_registers(DRIVER_ADDR_4, 3); +# endif +# endif +# endif # elif defined(IS31FLCOMMON) # ifdef ISSI_MANUAL_SCALING @@ -187,13 +232,13 @@ static void init(void) { # endif # elif defined(CKLED2001) - CKLED2001_update_led_control_registers(DRIVER_ADDR_1, 0); + ckled2001_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - CKLED2001_update_led_control_registers(DRIVER_ADDR_2, 1); + ckled2001_update_led_control_registers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - CKLED2001_update_led_control_registers(DRIVER_ADDR_3, 2); + ckled2001_update_led_control_registers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - CKLED2001_update_led_control_registers(DRIVER_ADDR_4, 3); + ckled2001_update_led_control_registers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -202,13 +247,13 @@ static void init(void) { # if defined(IS31FL3731) static void flush(void) { - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0); + is31fl3731_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1); + is31fl3731_update_pwm_buffers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2); + is31fl3731_update_pwm_buffers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3); + is31fl3731_update_pwm_buffers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -217,19 +262,19 @@ static void flush(void) { const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = IS31FL3731_set_color, - .set_color_all = IS31FL3731_set_color_all, + .set_color = is31fl3731_set_color, + .set_color_all = is31fl3731_set_color_all, }; # elif defined(IS31FL3733) static void flush(void) { - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); + is31fl3733_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); + is31fl3733_update_pwm_buffers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2); + is31fl3733_update_pwm_buffers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3); + is31fl3733_update_pwm_buffers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -238,19 +283,40 @@ static void flush(void) { const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = IS31FL3733_set_color, - .set_color_all = IS31FL3733_set_color_all, + .set_color = is31fl3733_set_color, + .set_color_all = is31fl3733_set_color_all, +}; + +# elif defined(IS31FL3736) +static void flush(void) { + is31fl3736_update_pwm_buffers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + is31fl3736_update_pwm_buffers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + is31fl3736_update_pwm_buffers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + is31fl3736_update_pwm_buffers(DRIVER_ADDR_4, 3); +# endif +# endif +# endif +} + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = is31fl3736_set_color, + .set_color_all = is31fl3736_set_color_all, }; # elif defined(IS31FL3737) static void flush(void) { - IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0); + is31fl3737_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1); + is31fl3737_update_pwm_buffers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - IS31FL3737_update_pwm_buffers(DRIVER_ADDR_3, 2); + is31fl3737_update_pwm_buffers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - IS31FL3737_update_pwm_buffers(DRIVER_ADDR_4, 3); + is31fl3737_update_pwm_buffers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -259,23 +325,29 @@ static void flush(void) { const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = IS31FL3737_set_color, - .set_color_all = IS31FL3737_set_color_all, + .set_color = is31fl3737_set_color, + .set_color_all = is31fl3737_set_color_all, }; # elif defined(IS31FL3741) static void flush(void) { - IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, 0); + is31fl3741_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - IS31FL3741_update_pwm_buffers(DRIVER_ADDR_2, 1); + is31fl3741_update_pwm_buffers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + is31fl3741_update_pwm_buffers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + is31fl3741_update_pwm_buffers(DRIVER_ADDR_4, 3); +# endif +# endif # endif } const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = IS31FL3741_set_color, - .set_color_all = IS31FL3741_set_color_all, + .set_color = is31fl3741_set_color, + .set_color_all = is31fl3741_set_color_all, }; # elif defined(IS31FLCOMMON) @@ -301,13 +373,13 @@ const rgb_matrix_driver_t rgb_matrix_driver = { # elif defined(CKLED2001) static void flush(void) { - CKLED2001_update_pwm_buffers(DRIVER_ADDR_1, 0); + ckled2001_update_pwm_buffers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_2, 1); + ckled2001_update_pwm_buffers(DRIVER_ADDR_2, 1); # if defined(DRIVER_ADDR_3) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_3, 2); + ckled2001_update_pwm_buffers(DRIVER_ADDR_3, 2); # if defined(DRIVER_ADDR_4) - CKLED2001_update_pwm_buffers(DRIVER_ADDR_4, 3); + ckled2001_update_pwm_buffers(DRIVER_ADDR_4, 3); # endif # endif # endif @@ -316,8 +388,8 @@ static void flush(void) { const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = CKLED2001_set_color, - .set_color_all = CKLED2001_set_color_all, + .set_color = ckled2001_set_color, + .set_color_all = ckled2001_set_color_all, }; # endif @@ -327,24 +399,24 @@ const rgb_matrix_driver_t rgb_matrix_driver = { static void init(void) { spi_init(); - AW20216_init(DRIVER_1_CS, DRIVER_1_EN); + aw20216_init(DRIVER_1_CS, DRIVER_1_EN); # if defined(DRIVER_2_CS) - AW20216_init(DRIVER_2_CS, DRIVER_2_EN); + aw20216_init(DRIVER_2_CS, DRIVER_2_EN); # endif } static void flush(void) { - AW20216_update_pwm_buffers(DRIVER_1_CS, 0); + aw20216_update_pwm_buffers(DRIVER_1_CS, 0); # if defined(DRIVER_2_CS) - AW20216_update_pwm_buffers(DRIVER_2_CS, 1); + aw20216_update_pwm_buffers(DRIVER_2_CS, 1); # endif } const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = AW20216_set_color, - .set_color_all = AW20216_set_color_all, + .set_color = aw20216_set_color, + .set_color_all = aw20216_set_color_all, }; #elif defined(WS2812) @@ -355,12 +427,17 @@ const rgb_matrix_driver_t rgb_matrix_driver = { // LED color buffer LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT]; +bool ws2812_dirty = false; -static void init(void) {} +static void init(void) { + ws2812_dirty = false; +} static void flush(void) { - // Assumes use of RGB_DI_PIN - ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT); + if (ws2812_dirty) { + ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT); + ws2812_dirty = false; + } } // Set an led in the buffer to a color @@ -378,6 +455,11 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { } # endif + if (rgb_matrix_ws2812_array[i].r == r && rgb_matrix_ws2812_array[i].g == g && rgb_matrix_ws2812_array[i].b == b) { + return; + } + + ws2812_dirty = true; rgb_matrix_ws2812_array[i].r = r; rgb_matrix_ws2812_array[i].g = g; rgb_matrix_ws2812_array[i].b = b; diff --git a/quantum/rgb_matrix/rgb_matrix_types.h b/quantum/rgb_matrix/rgb_matrix_types.h index eea603c41c9c..53ff7321b8df 100644 --- a/quantum/rgb_matrix/rgb_matrix_types.h +++ b/quantum/rgb_matrix/rgb_matrix_types.h @@ -83,16 +83,18 @@ typedef struct PACKED { } led_config_t; typedef union { - uint32_t raw; + uint64_t raw; struct PACKED { uint8_t enable : 2; uint8_t mode : 6; HSV hsv; - uint8_t speed; // EECONFIG needs to be increased to support this + uint8_t speed; led_flags_t flags; }; } rgb_config_t; +_Static_assert(sizeof(rgb_config_t) == sizeof(uint64_t), "RGB Matrix EECONFIG out of spec."); + #if defined(_MSC_VER) # pragma pack(pop) #endif diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 19d80e0097dc..158112f31dad 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -21,6 +21,7 @@ #include "rgblight.h" #include "color.h" #include "debug.h" +#include "util.h" #include "led_tables.h" #include #ifdef EEPROM_ENABLE @@ -30,13 +31,6 @@ # include "velocikey.h" #endif -#ifndef MIN -# define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef MAX -# define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif - #ifdef RGBLIGHT_SPLIT /* for split keyboard */ # define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE @@ -183,18 +177,19 @@ void rgblight_check_config(void) { } } -uint32_t eeconfig_read_rgblight(void) { +uint64_t eeconfig_read_rgblight(void) { #ifdef EEPROM_ENABLE - return eeprom_read_dword(EECONFIG_RGBLIGHT); + return (uint64_t)((eeprom_read_dword(EECONFIG_RGBLIGHT)) | ((uint64_t)eeprom_read_byte(EECONFIG_RGBLIGHT_EXTENDED) << 32)); #else return 0; #endif } -void eeconfig_update_rgblight(uint32_t val) { +void eeconfig_update_rgblight(uint64_t val) { #ifdef EEPROM_ENABLE rgblight_check_config(); - eeprom_update_dword(EECONFIG_RGBLIGHT, val); + eeprom_update_dword(EECONFIG_RGBLIGHT, val & 0xFFFFFFFF); + eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, (val >> 32) & 0xFF); #endif } @@ -269,13 +264,13 @@ void rgblight_reload_from_eeprom(void) { } } -uint32_t rgblight_read_dword(void) { +uint64_t rgblight_read_qword(void) { return rgblight_config.raw; } -void rgblight_update_dword(uint32_t dword) { +void rgblight_update_qword(uint64_t qword) { RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; - rgblight_config.raw = dword; + rgblight_config.raw = qword; if (rgblight_config.enable) rgblight_mode_noeeprom(rgblight_config.mode); else { @@ -422,6 +417,10 @@ void rgblight_disable_noeeprom(void) { rgblight_set(); } +void rgblight_enabled_noeeprom(bool state) { + state ? rgblight_enable_noeeprom() : rgblight_disable_noeeprom(); +} + bool rgblight_is_enabled(void) { return rgblight_config.enable; } @@ -491,7 +490,7 @@ void rgblight_increase_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed < 3) rgblight_config.speed++; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); } } void rgblight_increase_speed(void) { @@ -505,7 +504,7 @@ void rgblight_decrease_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed > 0) rgblight_config.speed--; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); } } void rgblight_decrease_speed(void) { @@ -614,7 +613,7 @@ uint8_t rgblight_get_speed(void) { void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { rgblight_config.speed = speed; if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed); } else { dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed); @@ -1278,7 +1277,7 @@ void rgblight_effect_snake(animation_status_t *anim) { for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; if (k > RGBLED_NUM) { - k = k % RGBLED_NUM; + k = k % (RGBLED_NUM); } if (k < 0) { k = k + rgblight_ranges.effect_num_leds; diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h index 769388846241..001058f96230 100644 --- a/quantum/rgblight/rgblight.h +++ b/quantum/rgblight/rgblight.h @@ -174,6 +174,10 @@ typedef struct { uint8_t val; } rgblight_segment_t; +// rgblight_set_layer_state doesn't take effect until the next time +// rgblight_task runs, so timers must be enabled for layers to work. +# define RGBLIGHT_USE_TIMER + # define RGBLIGHT_END_SEGMENT_INDEX (255) # define RGBLIGHT_END_SEGMENTS \ { RGBLIGHT_END_SEGMENT_INDEX, 0, 0, 0 } @@ -240,19 +244,20 @@ extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM; extern const uint8_t RGBLED_TWINKLE_INTERVALS[3] PROGMEM; extern bool is_rgblight_initialized; -// Should stay in sycn with rgb matrix config as we reuse eeprom storage for both (for now) typedef union { - uint32_t raw; + uint64_t raw; struct { bool enable : 1; uint8_t mode : 7; uint8_t hue : 8; uint8_t sat : 8; uint8_t val : 8; - uint8_t speed : 8; // EECONFIG needs to be increased to support this + uint8_t speed : 8; }; } rgblight_config_t; +_Static_assert(sizeof(rgblight_config_t) == sizeof(uint64_t), "RGB Light EECONFIG out of spec."); + typedef struct _rgblight_status_t { uint8_t base_mode; bool timer_enabled; @@ -321,6 +326,7 @@ void rgblight_enable(void); void rgblight_enable_noeeprom(void); void rgblight_disable(void); void rgblight_disable_noeeprom(void); +void rgblight_enabled_noeeprom(bool state); /* hue, sat, val change */ void rgblight_increase_hue(void); @@ -362,10 +368,10 @@ HSV rgblight_get_hsv(void); void rgblight_init(void); void rgblight_suspend(void); void rgblight_wakeup(void); -uint32_t rgblight_read_dword(void); -void rgblight_update_dword(uint32_t dword); -uint32_t eeconfig_read_rgblight(void); -void eeconfig_update_rgblight(uint32_t val); +uint64_t rgblight_read_qword(void); +void rgblight_update_qword(uint64_t qword); +uint64_t eeconfig_read_rgblight(void); +void eeconfig_update_rgblight(uint64_t val); void eeconfig_update_rgblight_current(void); void eeconfig_update_rgblight_default(void); void eeconfig_debug_rgblight(void); diff --git a/quantum/secure.h b/quantum/secure.h index bb2ba50f3166..ae9b5b904521 100644 --- a/quantum/secure.h +++ b/quantum/secure.h @@ -3,10 +3,15 @@ #pragma once -/** \file +/** + * \file * - * Exposes a set of functionality to act as a virtual padlock for your device - * ... As long as that padlock is made of paper and its currently raining. + * \defgroup secure Secure API + * + * \brief Exposes a set of functionality to act as a virtual padlock for your device + * ...as long as that padlock is made of paper and it's currently raining. + * + * \{ */ #include @@ -77,3 +82,5 @@ bool secure_hook_user(secure_status_t secure_status); /** \brief keyboard hook called when changing secure status device */ bool secure_hook_kb(secure_status_t secure_status); + +/** \} */ diff --git a/quantum/send_string/send_string.h b/quantum/send_string/send_string.h index 4eb55b88dccc..dbaed43ebccb 100644 --- a/quantum/send_string/send_string.h +++ b/quantum/send_string/send_string.h @@ -15,9 +15,11 @@ */ /** - * \defgroup send_string + * \file * - * Send String API. These functions allow you to create macros by typing out sequences of keystrokes. + * \defgroup send_string Send String API + * + * \brief These functions allow you to create macros by typing out sequences of keystrokes. * \{ */ diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index a43138345402..5d044c4ea0bd 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -18,9 +18,10 @@ #include "keyboard.h" #include "timer.h" #include "transport.h" -#include "quantum.h" #include "wait.h" +#include "debug.h" #include "usb_util.h" +#include "bootloader.h" #ifdef EE_HANDS # include "eeconfig.h" @@ -205,9 +206,6 @@ void split_pre_init(void) { #endif if (is_keyboard_master()) { -#if defined(USE_I2C) && defined(SSD1306OLED) - matrix_master_OLED_init(); -#endif transport_master_init(); } } diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h index 5c9a260a14ab..f83b05b6a636 100644 --- a/quantum/split_common/split_util.h +++ b/quantum/split_common/split_util.h @@ -2,13 +2,11 @@ #include #include -#include #include "matrix.h" extern volatile bool isLeftHand; -void matrix_master_OLED_init(void); void split_pre_init(void); void split_post_init(void); diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 18d3826b838c..4d4d2b957084 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -92,6 +92,10 @@ enum serial_transaction_id { PUT_HAPTIC, #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) +#if defined(SPLIT_ACTIVITY_ENABLE) + PUT_ACTIVITY, +#endif // SPLIT_ACTIVITY_ENABLE + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) PUT_RPC_INFO, PUT_RPC_REQ_DATA, @@ -109,6 +113,10 @@ enum serial_transaction_id { SPLIT_TRANSACTION_IDS_USER, #endif // SPLIT_TRANSACTION_IDS_USER +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + PUT_DETECTED_OS, +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + NUM_TOTAL_TRANSACTIONS }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 8e1961b58623..2b9423cd6369 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -20,13 +20,50 @@ #include "crc.h" #include "debug.h" #include "matrix.h" -#include "quantum.h" +#include "host.h" +#include "action_util.h" +#include "sync_timer.h" +#include "wait.h" #include "transactions.h" #include "transport.h" #include "transaction_id_define.h" #include "split_util.h" #include "synchronization_util.h" +#ifdef BACKLIGHT_ENABLE +# include "backlight.h" +#endif +#ifdef RGBLIGHT_ENABLE +# include "rgblight.h" +#endif +#ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" +#endif +#ifdef RGB_MATRIX_ENABLE +# include "rgb_matrix.h" +#endif +#ifdef OLED_ENABLE +# include "oled_driver.h" +#endif +#ifdef ST7565_ENABLE +# include "st7565.h" +#endif +#ifdef ENCODER_ENABLE +# include "encoder.h" +#endif +#ifdef HAPTIC_ENABLE +# include "haptic.h" +#endif +#ifdef POINTING_DEVICE_ENABLE +# include "pointing_device.h" +#endif +#ifdef OS_DETECTION_ENABLE +# include "os_detection.h" +#endif +#ifdef WPM_ENABLE +# include "wpm.h" +#endif + #define SYNC_TIMER_OFFSET 2 #ifndef FORCED_SYNC_THROTTLE_MS @@ -412,7 +449,7 @@ static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t uint8_t backlight_level = split_shmem->backlight_level; split_shared_memory_unlock(); - backlight_set(backlight_level); + backlight_level_noeeprom(backlight_level); } # define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight) @@ -790,6 +827,63 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) +#if defined(SPLIT_ACTIVITY_ENABLE) + +static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + static uint32_t last_update = 0; + split_slave_activity_sync_t activity_sync; + activity_sync.matrix_timestamp = last_matrix_activity_time(); + activity_sync.encoder_timestamp = last_encoder_activity_time(); + activity_sync.pointing_device_timestamp = last_pointing_device_activity_time(); + return send_if_data_mismatch(PUT_ACTIVITY, &last_update, &activity_sync, &split_shmem->activity_sync, sizeof(activity_sync)); +} + +static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + set_activity_timestamps(split_shmem->activity_sync.matrix_timestamp, split_shmem->activity_sync.encoder_timestamp, split_shmem->activity_sync.pointing_device_timestamp); +} + +// clang-format off +# define TRANSACTIONS_ACTIVITY_MASTER() TRANSACTION_HANDLER_MASTER(activity) +# define TRANSACTIONS_ACTIVITY_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(activity) +# define TRANSACTIONS_ACTIVITY_REGISTRATIONS [PUT_ACTIVITY] = trans_initiator2target_initializer(activity_sync), +// clang-format on + +#else // defined(SPLIT_ACTIVITY_ENABLE) + +# define TRANSACTIONS_ACTIVITY_MASTER() +# define TRANSACTIONS_ACTIVITY_SLAVE() +# define TRANSACTIONS_ACTIVITY_REGISTRATIONS + +#endif // defined(SPLIT_ACTIVITY_ENABLE) + +//////////////////////////////////////////////////// +// Detected OS + +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + +static bool detected_os_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + static uint32_t last_detected_os_update = 0; + os_variant_t detected_os = detected_host_os(); + bool okay = send_if_condition(PUT_DETECTED_OS, &last_detected_os_update, (detected_os != split_shmem->detected_os), &detected_os, sizeof(os_variant_t)); + return okay; +} + +static void detected_os_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + slave_update_detected_host_os(split_shmem->detected_os); +} + +# define TRANSACTIONS_DETECTED_OS_MASTER() TRANSACTION_HANDLER_MASTER(detected_os) +# define TRANSACTIONS_DETECTED_OS_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(detected_os) +# define TRANSACTIONS_DETECTED_OS_REGISTRATIONS [PUT_DETECTED_OS] = trans_initiator2target_initializer(detected_os), + +#else // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + +# define TRANSACTIONS_DETECTED_OS_MASTER() +# define TRANSACTIONS_DETECTED_OS_SLAVE() +# define TRANSACTIONS_DETECTED_OS_REGISTRATIONS + +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + //////////////////////////////////////////////////// split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { @@ -818,6 +912,8 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { TRANSACTIONS_POINTING_REGISTRATIONS TRANSACTIONS_WATCHDOG_REGISTRATIONS TRANSACTIONS_HAPTIC_REGISTRATIONS + TRANSACTIONS_ACTIVITY_REGISTRATIONS + TRANSACTIONS_DETECTED_OS_REGISTRATIONS // clang-format on #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -846,6 +942,8 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix TRANSACTIONS_POINTING_MASTER(); TRANSACTIONS_WATCHDOG_MASTER(); TRANSACTIONS_HAPTIC_MASTER(); + TRANSACTIONS_ACTIVITY_MASTER(); + TRANSACTIONS_DETECTED_OS_MASTER(); return true; } @@ -867,6 +965,8 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ TRANSACTIONS_POINTING_SLAVE(); TRANSACTIONS_WATCHDOG_SLAVE(); TRANSACTIONS_HAPTIC_SLAVE(); + TRANSACTIONS_ACTIVITY_SLAVE(); + TRANSACTIONS_DETECTED_OS_SLAVE(); } #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h index e38ec79ce910..af3e68a15fbb 100644 --- a/quantum/split_common/transactions.h +++ b/quantum/split_common/transactions.h @@ -16,8 +16,8 @@ #pragma once -#include "stdint.h" -#include "stdbool.h" +#include +#include #include "matrix.h" #include "transaction_id_define.h" diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index adee4470d22b..2e2b918d4518 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -16,8 +16,8 @@ #pragma once -#include "stdint.h" -#include "stdbool.h" +#include +#include #include "progmem.h" #include "action_layer.h" @@ -122,6 +122,15 @@ typedef struct _split_slave_haptic_sync_t { } split_slave_haptic_sync_t; #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) +#if defined(SPLIT_ACTIVITY_ENABLE) +# include "keyboard.h" +typedef struct _split_slave_activity_sync_t { + uint32_t matrix_timestamp; + uint32_t encoder_timestamp; + uint32_t pointing_device_timestamp; +} split_slave_activity_sync_t; +#endif // defined(SPLIT_ACTIVITY_ENABLE) + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _rpc_sync_info_t { uint8_t checksum; @@ -133,6 +142,10 @@ typedef struct _rpc_sync_info_t { } rpc_sync_info_t; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) +# include "os_detection.h" +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + typedef struct _split_shared_memory_t { #ifdef USE_I2C int8_t transaction_id; @@ -200,15 +213,23 @@ typedef struct _split_shared_memory_t { bool watchdog_pinged; #endif // defined(SPLIT_WATCHDOG_ENABLE) -#if defined(HAPTIC_ENABLE) +#if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) split_slave_haptic_sync_t haptic_sync; #endif // defined(HAPTIC_ENABLE) +#if defined(SPLIT_ACTIVITY_ENABLE) + split_slave_activity_sync_t activity_sync; +#endif // defined(SPLIT_ACTIVITY_ENABLE) + #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) rpc_sync_info_t rpc_info; uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) + +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) + os_variant_t detected_os; +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) } split_shared_memory_t; extern split_shared_memory_t *const split_shmem; diff --git a/quantum/unicode/ucis.c b/quantum/unicode/ucis.c new file mode 100644 index 000000000000..32be78520654 --- /dev/null +++ b/quantum/unicode/ucis.c @@ -0,0 +1,96 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ucis.h" +#include "unicode.h" +#include "action.h" + +uint8_t count = 0; +bool active = false; +char input[UCIS_MAX_INPUT_LENGTH] = {0}; + +void ucis_start(void) { + count = 0; + active = true; + + register_unicode(0x2328); // ⌨ +} + +bool ucis_active(void) { + return active; +} + +uint8_t ucis_count(void) { + return count; +} + +static char keycode_to_char(uint16_t keycode) { + if (keycode >= KC_A && keycode <= KC_Z) { + return 'a' + (keycode - KC_A); + } else if (keycode >= KC_1 && keycode <= KC_9) { + return '1' + (keycode - KC_1); + } else if (keycode == KC_0) { + return '0'; + } + return 0; +} + +bool ucis_add(uint16_t keycode) { + char c = keycode_to_char(keycode); + if (c) { + input[count++] = c; + return true; + } + return false; +} + +bool ucis_remove_last(void) { + if (count) { + count--; + return true; + } + + return false; +} + +static bool match_mnemonic(char *mnemonic) { + for (uint8_t i = 0; input[i]; i++) { + if (i > count || input[i] != mnemonic[i]) { + return false; + } + } + return true; +} + +void ucis_finish(void) { + uint8_t i = 0; + bool found = false; + for (; ucis_symbol_table[i].mnemonic; i++) { + if (match_mnemonic(ucis_symbol_table[i].mnemonic)) { + found = true; + break; + } + } + + if (found) { + for (uint8_t j = 0; j <= count; j++) { + tap_code(KC_BACKSPACE); + } + register_ucis(i); + } + + active = false; +} + +void ucis_cancel(void) { + count = 0; + active = false; +} + +void register_ucis(uint8_t index) { + const uint32_t *code_points = ucis_symbol_table[index].code_points; + + for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) { + register_unicode(code_points[i]); + } +} diff --git a/quantum/unicode/ucis.h b/quantum/unicode/ucis.h new file mode 100644 index 000000000000..5a4fa267841c --- /dev/null +++ b/quantum/unicode/ucis.h @@ -0,0 +1,97 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +/** + * \file + * + * \defgroup ucis UCIS + * \{ + */ + +#ifndef UCIS_MAX_INPUT_LENGTH +# define UCIS_MAX_INPUT_LENGTH 32 +#endif + +#ifndef UCIS_MAX_CODE_POINTS +# define UCIS_MAX_CODE_POINTS 3 +#endif + +typedef struct { + char* mnemonic; + uint32_t code_points[UCIS_MAX_CODE_POINTS]; +} ucis_symbol_t; + +// clang-format off + +#define UCIS_TABLE(...) { \ + __VA_ARGS__, \ + { NULL, {} } \ +} + +#define UCIS_SYM(name, ...) { \ + .mnemonic = name, \ + .code_points = {__VA_ARGS__} \ +} + +// clang-format on + +extern const ucis_symbol_t ucis_symbol_table[]; + +/** + * \brief Begin the input sequence. + */ +void ucis_start(void); + +/** + * \brief Whether UCIS is currently active. + * + * \return `true` if UCIS is active. + */ +bool ucis_active(void); + +/** + * \brief Get the number of characters in the input sequence buffer. + * + * \return The current input sequence buffer length. + */ +uint8_t ucis_count(void); + +/** + * \brief Add the given keycode to the input sequence buffer. + * + * \param keycode The keycode to add. Must be between `KC_A` and `KC_Z`, or `KC_1` and `KC_0`. + * + * \return `true` if the keycode was added. + */ +bool ucis_add(uint16_t keycode); + +/** + * \brief Remove the last character from the input sequence. + * + * \return `true` if the sequence was not empty. + */ +bool ucis_remove_last(void); + +/** + * Mark the input sequence as complete, and attempt to match. + */ +void ucis_finish(void); + +/** + * \brief Cancel the input sequence. + */ +void ucis_cancel(void); + +/** + * Send the code point(s) for the given UCIS index. + * + * \param index The index into the UCIS symbol table. + */ +void register_ucis(uint8_t index); + +/** \} */ diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c index 35cb62e70045..78a4cad58594 100644 --- a/quantum/unicode/unicode.c +++ b/quantum/unicode/unicode.c @@ -25,6 +25,8 @@ #include "wait.h" #include "send_string.h" #include "utf8.h" +#include "debug.h" +#include "quantum.h" #if defined(AUDIO_ENABLE) # include "audio.h" @@ -71,16 +73,8 @@ static int8_t selected_count = ARRAY_SIZE(selected); static int8_t selected_index; #endif -/** \brief unicode input mode set at user level - * - * Run user code on unicode input mode change - */ __attribute__((weak)) void unicode_input_mode_set_user(uint8_t input_mode) {} -/** \brief unicode input mode set at keyboard level - * - * Run keyboard code on unicode input mode change - */ __attribute__((weak)) void unicode_input_mode_set_kb(uint8_t input_mode) { unicode_input_mode_set_user(input_mode); } @@ -170,6 +164,10 @@ uint8_t get_unicode_input_mode(void) { return unicode_config.input_mode; } +static void persist_unicode_input_mode(void) { + eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); +} + void set_unicode_input_mode(uint8_t mode) { unicode_config.input_mode = mode; persist_unicode_input_mode(); @@ -180,26 +178,34 @@ void set_unicode_input_mode(uint8_t mode) { dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); } -void cycle_unicode_input_mode(int8_t offset) { +static void cycle_unicode_input_mode(int8_t offset) { #if UNICODE_SELECTED_MODES != -1 selected_index = (selected_index + offset) % selected_count; if (selected_index < 0) { selected_index += selected_count; } + unicode_config.input_mode = selected[selected_index]; + # if UNICODE_CYCLE_PERSIST persist_unicode_input_mode(); # endif + # ifdef AUDIO_ENABLE unicode_play_song(unicode_config.input_mode); # endif + unicode_input_mode_set_kb(unicode_config.input_mode); dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); #endif } -void persist_unicode_input_mode(void) { - eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); +void unicode_input_mode_step(void) { + cycle_unicode_input_mode(1); +} + +void unicode_input_mode_step_reverse(void) { + cycle_unicode_input_mode(-1); } __attribute__((weak)) void unicode_input_start(void) { diff --git a/quantum/unicode/unicode.h b/quantum/unicode/unicode.h index 6f1e35d55405..90a54c8b18b5 100644 --- a/quantum/unicode/unicode.h +++ b/quantum/unicode/unicode.h @@ -17,16 +17,24 @@ #pragma once #include +#include "unicode_keycodes.h" -#include "quantum.h" +/** + * \file + * + * \defgroup unicode Unicode + * \{ + */ typedef union { - uint32_t raw; + uint8_t raw; struct { uint8_t input_mode : 8; }; } unicode_config_t; +_Static_assert(sizeof(unicode_config_t) == sizeof(uint8_t), "Unicode EECONFIG out of spec."); + extern unicode_config_t unicode_config; enum unicode_input_modes { @@ -40,127 +48,87 @@ enum unicode_input_modes { UNICODE_MODE_COUNT // Number of available input modes (always leave at the end) }; -void unicode_input_mode_init(void); +void unicode_input_mode_init(void); + +/** + * \brief Get the current Unicode input mode. + * + * \return The currently active Unicode input mode. + */ uint8_t get_unicode_input_mode(void); -void set_unicode_input_mode(uint8_t mode); -void cycle_unicode_input_mode(int8_t offset); -void persist_unicode_input_mode(void); +/** + * \brief Set the Unicode input mode. + * + * \param mode The input mode to set. + */ +void set_unicode_input_mode(uint8_t mode); + +/** + * \brief Change to the next Unicode input mode. + */ +void unicode_input_mode_step(void); + +/** + * \brief Change to the previous Unicode input mode. + */ +void unicode_input_mode_step_reverse(void); + +/** + * \brief User-level callback, invoked when the input mode is changed. + * + * \param input_mode The new input mode. + */ void unicode_input_mode_set_user(uint8_t input_mode); + +/** + * \brief Keyboard-level callback, invoked when the input mode is changed. + * + * \param input_mode The new input mode. + */ void unicode_input_mode_set_kb(uint8_t input_mode); +/** + * \brief Begin the Unicode input sequence. The exact behavior depends on the currently selected input mode. + */ void unicode_input_start(void); + +/** + * \brief Complete the Unicode input sequence. The exact behavior depends on the currently selected input mode. + */ void unicode_input_finish(void); + +/** + * \brief Cancel the Unicode input sequence. The exact behavior depends on the currently selected input mode. + */ void unicode_input_cancel(void); +/** + * \brief Send a 16-bit hex number. + * + * \param hex The number to send. + */ void register_hex(uint16_t hex); + +/** + * \brief Send a 32-bit hex number. + * + * \param hex The number to send. + */ void register_hex32(uint32_t hex); + +/** + * \brief Input a single Unicode character. A surrogate pair will be sent if required by the input mode. + * + * \param code_point The code point of the character to send. + */ void register_unicode(uint32_t code_point); +/** + * \brief Send a string containing Unicode characters. + * + * \param str The string to send. + */ void send_unicode_string(const char *str); -// clang-format off - -#define UC_BSPC UC(0x0008) // (backspace) - -#define UC_SPC UC(0x0020) // (space) -#define UC_EXLM UC(0x0021) // ! -#define UC_DQUT UC(0x0022) // " -#define UC_HASH UC(0x0023) // # -#define UC_DLR UC(0x0024) // $ -#define UC_PERC UC(0x0025) // % -#define UC_AMPR UC(0x0026) // & -#define UC_QUOT UC(0x0027) // ' -#define UC_LPRN UC(0x0028) // ( -#define UC_RPRN UC(0x0029) // ) -#define UC_ASTR UC(0x002A) // * -#define UC_PLUS UC(0x002B) // + -#define UC_COMM UC(0x002C) // , -#define UC_DASH UC(0x002D) // - -#define UC_DOT UC(0x002E) // . -#define UC_SLSH UC(0x002F) // / - -#define UC_0 UC(0x0030) // 0 -#define UC_1 UC(0x0031) // 1 -#define UC_2 UC(0x0032) // 2 -#define UC_3 UC(0x0033) // 3 -#define UC_4 UC(0x0034) // 4 -#define UC_5 UC(0x0035) // 5 -#define UC_6 UC(0x0036) // 6 -#define UC_7 UC(0x0037) // 7 -#define UC_8 UC(0x0038) // 8 -#define UC_9 UC(0x0039) // 9 -#define UC_COLN UC(0x003A) // : -#define UC_SCLN UC(0x003B) // ; -#define UC_LT UC(0x003C) // < -#define UC_EQL UC(0x003D) // = -#define UC_GT UC(0x003E) // > -#define UC_QUES UC(0x003F) // ? - -#define UC_AT UC(0x0040) // @ -#define UC_A UC(0x0041) // A -#define UC_B UC(0x0042) // B -#define UC_C UC(0x0043) // C -#define UC_D UC(0x0044) // D -#define UC_E UC(0x0045) // E -#define UC_F UC(0x0046) // F -#define UC_G UC(0x0047) // G -#define UC_H UC(0x0048) // H -#define UC_I UC(0x0049) // I -#define UC_J UC(0x004A) // J -#define UC_K UC(0x004B) // K -#define UC_L UC(0x004C) // L -#define UC_M UC(0x004D) // M -#define UC_N UC(0x004E) // N -#define UC_O UC(0x004F) // O - -#define UC_P UC(0x0050) // P -#define UC_Q UC(0x0051) // Q -#define UC_R UC(0x0052) // R -#define UC_S UC(0x0053) // S -#define UC_T UC(0x0054) // T -#define UC_U UC(0x0055) // U -#define UC_V UC(0x0056) // V -#define UC_W UC(0x0057) // W -#define UC_X UC(0x0058) // X -#define UC_Y UC(0x0059) // Y -#define UC_Z UC(0x005A) // Z -#define UC_LBRC UC(0x005B) // [ -#define UC_BSLS UC(0x005C) // (backslash) -#define UC_RBRC UC(0x005D) // ] -#define UC_CIRM UC(0x005E) // ^ -#define UC_UNDR UC(0x005F) // _ - -#define UC_GRV UC(0x0060) // ` -#define UC_a UC(0x0061) // a -#define UC_b UC(0x0062) // b -#define UC_c UC(0x0063) // c -#define UC_d UC(0x0064) // d -#define UC_e UC(0x0065) // e -#define UC_f UC(0x0066) // f -#define UC_g UC(0x0067) // g -#define UC_h UC(0x0068) // h -#define UC_i UC(0x0069) // i -#define UC_j UC(0x006A) // j -#define UC_k UC(0x006B) // k -#define UC_l UC(0x006C) // l -#define UC_m UC(0x006D) // m -#define UC_n UC(0x006E) // n -#define UC_o UC(0x006F) // o - -#define UC_p UC(0x0070) // p -#define UC_q UC(0x0071) // q -#define UC_r UC(0x0072) // r -#define UC_s UC(0x0073) // s -#define UC_t UC(0x0074) // t -#define UC_u UC(0x0075) // u -#define UC_v UC(0x0076) // v -#define UC_w UC(0x0077) // w -#define UC_x UC(0x0078) // x -#define UC_y UC(0x0079) // y -#define UC_z UC(0x007A) // z -#define UC_LCBR UC(0x007B) // { -#define UC_PIPE UC(0x007C) // | -#define UC_RCBR UC(0x007D) // } -#define UC_TILD UC(0x007E) // ~ -#define UC_DEL UC(0x007F) // (delete) +/** \} */ diff --git a/quantum/unicode/unicode_keycodes.h b/quantum/unicode/unicode_keycodes.h new file mode 100644 index 000000000000..acc176cb6f2e --- /dev/null +++ b/quantum/unicode/unicode_keycodes.h @@ -0,0 +1,125 @@ +/* Copyright 2023 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "quantum_keycodes.h" + +// clang-format off + +#define UC_BSPC UC(0x0008) // (backspace) + +#define UC_SPC UC(0x0020) // (space) +#define UC_EXLM UC(0x0021) // ! +#define UC_DQUT UC(0x0022) // " +#define UC_HASH UC(0x0023) // # +#define UC_DLR UC(0x0024) // $ +#define UC_PERC UC(0x0025) // % +#define UC_AMPR UC(0x0026) // & +#define UC_QUOT UC(0x0027) // ' +#define UC_LPRN UC(0x0028) // ( +#define UC_RPRN UC(0x0029) // ) +#define UC_ASTR UC(0x002A) // * +#define UC_PLUS UC(0x002B) // + +#define UC_COMM UC(0x002C) // , +#define UC_DASH UC(0x002D) // - +#define UC_DOT UC(0x002E) // . +#define UC_SLSH UC(0x002F) // / + +#define UC_0 UC(0x0030) // 0 +#define UC_1 UC(0x0031) // 1 +#define UC_2 UC(0x0032) // 2 +#define UC_3 UC(0x0033) // 3 +#define UC_4 UC(0x0034) // 4 +#define UC_5 UC(0x0035) // 5 +#define UC_6 UC(0x0036) // 6 +#define UC_7 UC(0x0037) // 7 +#define UC_8 UC(0x0038) // 8 +#define UC_9 UC(0x0039) // 9 +#define UC_COLN UC(0x003A) // : +#define UC_SCLN UC(0x003B) // ; +#define UC_LT UC(0x003C) // < +#define UC_EQL UC(0x003D) // = +#define UC_GT UC(0x003E) // > +#define UC_QUES UC(0x003F) // ? + +#define UC_AT UC(0x0040) // @ +#define UC_A UC(0x0041) // A +#define UC_B UC(0x0042) // B +#define UC_C UC(0x0043) // C +#define UC_D UC(0x0044) // D +#define UC_E UC(0x0045) // E +#define UC_F UC(0x0046) // F +#define UC_G UC(0x0047) // G +#define UC_H UC(0x0048) // H +#define UC_I UC(0x0049) // I +#define UC_J UC(0x004A) // J +#define UC_K UC(0x004B) // K +#define UC_L UC(0x004C) // L +#define UC_M UC(0x004D) // M +#define UC_N UC(0x004E) // N +#define UC_O UC(0x004F) // O + +#define UC_P UC(0x0050) // P +#define UC_Q UC(0x0051) // Q +#define UC_R UC(0x0052) // R +#define UC_S UC(0x0053) // S +#define UC_T UC(0x0054) // T +#define UC_U UC(0x0055) // U +#define UC_V UC(0x0056) // V +#define UC_W UC(0x0057) // W +#define UC_X UC(0x0058) // X +#define UC_Y UC(0x0059) // Y +#define UC_Z UC(0x005A) // Z +#define UC_LBRC UC(0x005B) // [ +#define UC_BSLS UC(0x005C) // (backslash) +#define UC_RBRC UC(0x005D) // ] +#define UC_CIRM UC(0x005E) // ^ +#define UC_UNDR UC(0x005F) // _ + +#define UC_GRV UC(0x0060) // ` +#define UC_a UC(0x0061) // a +#define UC_b UC(0x0062) // b +#define UC_c UC(0x0063) // c +#define UC_d UC(0x0064) // d +#define UC_e UC(0x0065) // e +#define UC_f UC(0x0066) // f +#define UC_g UC(0x0067) // g +#define UC_h UC(0x0068) // h +#define UC_i UC(0x0069) // i +#define UC_j UC(0x006A) // j +#define UC_k UC(0x006B) // k +#define UC_l UC(0x006C) // l +#define UC_m UC(0x006D) // m +#define UC_n UC(0x006E) // n +#define UC_o UC(0x006F) // o + +#define UC_p UC(0x0070) // p +#define UC_q UC(0x0071) // q +#define UC_r UC(0x0072) // r +#define UC_s UC(0x0073) // s +#define UC_t UC(0x0074) // t +#define UC_u UC(0x0075) // u +#define UC_v UC(0x0076) // v +#define UC_w UC(0x0077) // w +#define UC_x UC(0x0078) // x +#define UC_y UC(0x0079) // y +#define UC_z UC(0x007A) // z +#define UC_LCBR UC(0x007B) // { +#define UC_PIPE UC(0x007C) // | +#define UC_RCBR UC(0x007D) // } +#define UC_TILD UC(0x007E) // ~ +#define UC_DEL UC(0x007F) // (delete) diff --git a/quantum/unicode/unicodemap.c b/quantum/unicode/unicodemap.c new file mode 100644 index 000000000000..2f618056a2e7 --- /dev/null +++ b/quantum/unicode/unicodemap.c @@ -0,0 +1,43 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "unicodemap.h" +#include "unicode.h" +#include "keycodes.h" +#include "quantum_keycodes.h" +#include "modifiers.h" +#include "host.h" +#include "action_util.h" + +uint8_t unicodemap_index(uint16_t keycode) { + if (keycode >= QK_UNICODEMAP_PAIR) { + // Keycode is a pair: extract index based on Shift / Caps Lock state + uint16_t index; + + uint8_t mods = get_mods() | get_weak_mods(); +#ifndef NO_ACTION_ONESHOT + mods |= get_oneshot_mods(); +#endif + + bool shift = mods & MOD_MASK_SHIFT; + bool caps = host_keyboard_led_state().caps_lock; + if (shift ^ caps) { + index = QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(keycode); + } else { + index = QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(keycode); + } + + return index; + } else { + // Keycode is a regular index + return QK_UNICODEMAP_GET_INDEX(keycode); + } +} + +uint32_t unicodemap_get_code_point(uint8_t index) { + return pgm_read_dword(unicode_map + index); +} + +void register_unicodemap(uint8_t index) { + register_unicode(unicodemap_get_code_point(index)); +} diff --git a/quantum/unicode/unicodemap.h b/quantum/unicode/unicodemap.h new file mode 100644 index 000000000000..00d2aec8fad7 --- /dev/null +++ b/quantum/unicode/unicodemap.h @@ -0,0 +1,43 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include "progmem.h" + +/** + * \file + * + * \defgroup unicodemap Unicode Map + * \{ + */ + +extern const uint32_t unicode_map[] PROGMEM; + +/** + * \brief Get the index into the `unicode_map` array for the given keycode, respecting shift state for pair keycodes. + * + * \param keycode The Unicode Map keycode to get the index of. + * + * \return An index into the `unicode_map` array. + */ +uint8_t unicodemap_index(uint16_t keycode); + +/** + * \brief Get the code point for the given index in the `unicode_map` array. + * + * \param index The index into the `unicode_map` array. + * + * \return A Unicode code point value. + */ +uint32_t unicodemap_get_code_point(uint8_t index); + +/** + * \brief Send the code point for the given index in the `unicode_map` array. + * + * \param index The index into the `unicode_map` array. + */ +void register_unicodemap(uint8_t index); + +/** \} */ diff --git a/quantum/velocikey.c b/quantum/velocikey.c index 58e14215bb36..03e91911f6c6 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -2,13 +2,7 @@ #include "timer.h" #include "eeconfig.h" #include "eeprom.h" - -#ifndef MIN -# define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef MAX -# define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif +#include "util.h" #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; diff --git a/quantum/via.c b/quantum/via.c index c54e37a17516..2acd7aa90c31 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -22,19 +22,41 @@ # error "DYNAMIC_KEYMAP_ENABLE is not enabled" #endif -#include "quantum.h" - #include "via.h" #include "raw_hid.h" #include "dynamic_keymap.h" #include "eeprom.h" +#include "eeconfig.h" +#include "matrix.h" +#include "timer.h" +#include "wait.h" #include "version.h" // for QMK_BUILDDATE used in EEPROM magic -#if defined(RGB_MATRIX_ENABLE) +#if defined(AUDIO_ENABLE) +# include "audio.h" +#endif + +#if defined(BACKLIGHT_ENABLE) +# include "backlight.h" +#endif + +#if defined(RGBLIGHT_ENABLE) +# include "rgblight.h" +#endif + +#if (defined(RGB_MATRIX_ENABLE) || defined(LED_MATRIX_ENABLE)) # include #endif +#if defined(RGB_MATRIX_ENABLE) +# include "rgb_matrix.h" +#endif + +#if defined(LED_MATRIX_ENABLE) +# include "led_matrix.h" +#endif + // Can be called in an overriding via_init_kb() to test if keyboard level code usage of // EEPROM is invalid and use/save defaults. bool via_eeprom_is_valid(void) { @@ -141,6 +163,9 @@ __attribute__((weak)) void via_set_device_indication(uint8_t value) { #if defined(RGB_MATRIX_ENABLE) rgb_matrix_toggle_noeeprom(); #endif // RGB_MATRIX_ENABLE +#if defined(LED_MATRIX_ENABLE) + led_matrix_toggle_noeeprom(); +#endif // LED_MATRIX_ENABLE #if defined(AUDIO_ENABLE) if (value == 0) { wait_ms(10); @@ -194,6 +219,7 @@ __attribute__((weak)) void via_custom_value_command_kb(uint8_t *data, uint8_t le // id_qmk_backlight_channel -> via_qmk_backlight_command() // id_qmk_rgblight_channel -> via_qmk_rgblight_command() // id_qmk_rgb_matrix_channel -> via_qmk_rgb_matrix_command() +// id_qmk_led_matrix_channel -> via_qmk_led_matrix_command() // id_qmk_audio_channel -> via_qmk_audio_command() // __attribute__((weak)) void via_custom_value_command(uint8_t *data, uint8_t length) { @@ -219,7 +245,14 @@ __attribute__((weak)) void via_custom_value_command(uint8_t *data, uint8_t lengt via_qmk_rgb_matrix_command(data, length); return; } -#endif // RGBLIGHT_ENABLE +#endif // RGB_MATRIX_ENABLE + +#if defined(LED_MATRIX_ENABLE) + if (*channel_id == id_qmk_led_matrix_channel) { + via_qmk_led_matrix_command(data, length); + return; + } +#endif // LED_MATRIX_ENABLE #if defined(AUDIO_ENABLE) if (*channel_id == id_qmk_audio_channel) { @@ -692,6 +725,90 @@ void via_qmk_rgb_matrix_save(void) { #endif // RGB_MATRIX_ENABLE +#if defined(LED_MATRIX_ENABLE) + +# if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX +# undef LED_MATRIX_MAXIMUM_BRIGHTNESS +# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX +# endif + +void via_qmk_led_matrix_command(uint8_t *data, uint8_t length) { + // data = [ command_id, channel_id, value_id, value_data ] + uint8_t *command_id = &(data[0]); + uint8_t *value_id_and_data = &(data[2]); + + switch (*command_id) { + case id_custom_set_value: { + via_qmk_led_matrix_set_value(value_id_and_data); + break; + } + case id_custom_get_value: { + via_qmk_led_matrix_get_value(value_id_and_data); + break; + } + case id_custom_save: { + via_qmk_led_matrix_save(); + break; + } + default: { + *command_id = id_unhandled; + break; + } + } +} + +void via_qmk_led_matrix_get_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_qmk_led_matrix_brightness: { + value_data[0] = ((uint16_t)led_matrix_get_val() * UINT8_MAX) / LED_MATRIX_MAXIMUM_BRIGHTNESS; + break; + } + case id_qmk_led_matrix_effect: { + value_data[0] = led_matrix_is_enabled() ? led_matrix_get_mode() : 0; + break; + } + case id_qmk_led_matrix_effect_speed: { + value_data[0] = led_matrix_get_speed(); + break; + } + } +} + +void via_qmk_led_matrix_set_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + switch (*value_id) { + case id_qmk_led_matrix_brightness: { + led_matrix_set_val_noeeprom(scale8(value_data[0], LED_MATRIX_MAXIMUM_BRIGHTNESS)); + break; + } + case id_qmk_led_matrix_effect: { + if (value_data[0] == 0) { + led_matrix_disable_noeeprom(); + } else { + led_matrix_enable_noeeprom(); + led_matrix_mode_noeeprom(value_data[0]); + } + break; + } + case id_qmk_led_matrix_effect_speed: { + led_matrix_set_speed_noeeprom(value_data[0]); + break; + } + } +} + +void via_qmk_led_matrix_save(void) { + eeconfig_update_led_matrix(); +} + +#endif // LED_MATRIX_ENABLE + #if defined(AUDIO_ENABLE) extern audio_config_t audio_config; diff --git a/quantum/via.h b/quantum/via.h index ab4eb0502818..01d4c48b374f 100644 --- a/quantum/via.h +++ b/quantum/via.h @@ -17,6 +17,7 @@ #pragma once #include "eeconfig.h" // for EECONFIG_SIZE +#include "action.h" // Keyboard level code can change where VIA stores the magic. // The magic is the build date YYMMDD encoded as BCD in 3 bytes, @@ -109,6 +110,7 @@ enum via_channel_id { id_qmk_rgblight_channel = 2, id_qmk_rgb_matrix_channel = 3, id_qmk_audio_channel = 4, + id_qmk_led_matrix_channel = 5, }; enum via_qmk_backlight_value { @@ -130,6 +132,12 @@ enum via_qmk_rgb_matrix_value { id_qmk_rgb_matrix_color = 4, }; +enum via_qmk_led_matrix_value { + id_qmk_led_matrix_brightness = 1, + id_qmk_led_matrix_effect = 2, + id_qmk_led_matrix_effect_speed = 3, +}; + enum via_qmk_audio_value { id_qmk_audio_enable = 1, id_qmk_audio_clicky_enable = 2, @@ -182,6 +190,13 @@ void via_qmk_rgb_matrix_get_value(uint8_t *data); void via_qmk_rgb_matrix_save(void); #endif +#if defined(LED_MATRIX_ENABLE) +void via_qmk_led_matrix_command(uint8_t *data, uint8_t length); +void via_qmk_led_matrix_set_value(uint8_t *data); +void via_qmk_led_matrix_get_value(uint8_t *data); +void via_qmk_led_matrix_save(void); +#endif + #if defined(AUDIO_ENABLE) void via_qmk_audio_command(uint8_t *data, uint8_t length); void via_qmk_audio_set_value(uint8_t *data); diff --git a/tests/audio/config.h b/tests/audio/config.h new file mode 100644 index 000000000000..d0c4ddadbd3b --- /dev/null +++ b/tests/audio/config.h @@ -0,0 +1,18 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "test_common.h" diff --git a/tests/audio/test.mk b/tests/audio/test.mk new file mode 100644 index 000000000000..a2c71d958781 --- /dev/null +++ b/tests/audio/test.mk @@ -0,0 +1,16 @@ +# Copyright 2023 Google LLC +# +# 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 . + +AUDIO_ENABLE = yes diff --git a/tests/audio/test_audio.cpp b/tests/audio/test_audio.cpp new file mode 100644 index 000000000000..ef34748b0606 --- /dev/null +++ b/tests/audio/test_audio.cpp @@ -0,0 +1,118 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include +#include + +#include "gtest/gtest.h" +#include "keyboard_report_util.hpp" +#include "test_common.hpp" + +namespace { + +class AudioTest : public TestFixture { + public: + uint16_t infer_tempo() { + return audio_ms_to_duration(1875) / 2; + } +}; + +TEST_F(AudioTest, OnOffToggle) { + audio_on(); + EXPECT_TRUE(audio_is_on()); + + audio_off(); + EXPECT_FALSE(audio_is_on()); + + audio_toggle(); + EXPECT_TRUE(audio_is_on()); + + audio_toggle(); + EXPECT_FALSE(audio_is_on()); +} + +TEST_F(AudioTest, ChangeTempo) { + for (int tempo = 50; tempo <= 250; tempo += 50) { + audio_set_tempo(tempo); + EXPECT_EQ(infer_tempo(), tempo); + } + + audio_set_tempo(10); + audio_increase_tempo(25); + EXPECT_EQ(infer_tempo(), 35); + + audio_decrease_tempo(4); + EXPECT_EQ(infer_tempo(), 31); + + audio_increase_tempo(250); + EXPECT_EQ(infer_tempo(), 255); + + audio_set_tempo(9); + EXPECT_EQ(infer_tempo(), 10); + + audio_decrease_tempo(100); + EXPECT_EQ(infer_tempo(), 10); +} + +TEST_F(AudioTest, BpmConversion) { + const int tol = 1; + + audio_set_tempo(120); + // At 120 bpm, there are 2 beats per second, and a whole note is 500 ms. + EXPECT_NEAR(audio_duration_to_ms(64 /* whole note */), 500, tol); + EXPECT_NEAR(audio_ms_to_duration(500), 64, tol); + EXPECT_EQ(audio_duration_to_ms(0), 0); + EXPECT_EQ(audio_ms_to_duration(0), 0); + + audio_set_tempo(10); + // At 10 bpm, UINT16_MAX ms corresponds to 699/64 beats and is the longest + // duration that can be converted without overflow. + EXPECT_NEAR(audio_ms_to_duration(UINT16_MAX), 699, tol); + EXPECT_NEAR(audio_duration_to_ms(699), 65531, tol); + + audio_set_tempo(255); + // At 255 bpm, UINT16_MAX ms corresponds to 17825/64 beats and is the longest + // duration that can be converted without overflow. + EXPECT_NEAR(audio_ms_to_duration(UINT16_MAX), 17825, tol); + EXPECT_NEAR(audio_duration_to_ms(17825), 65533, tol); + + std::mt19937 rng(0 /*seed*/); + std::uniform_int_distribution dist_tempo(10, 255); + std::uniform_int_distribution dist_ms(0, UINT16_MAX); + + // Test bpm <-> ms conversions for random tempos and durations. + for (int trial = 0; trial < 50; ++trial) { + const int tempo = dist_tempo(rng); + const int duration_ms = dist_ms(rng); + SCOPED_TRACE("tempo " + testing::PrintToString(tempo) + ", duration " + testing::PrintToString(duration_ms) + " ms"); + + audio_set_tempo(tempo); + int duration_bpm = std::round((64.0f / (60.0f * 1000.0f)) * duration_ms * tempo); + ASSERT_NEAR(audio_ms_to_duration(duration_ms), duration_bpm, tol); + + int roundtrip_ms = std::round((60.0f * 1000.0f / 64.0f) * duration_bpm / tempo); + // Because of round-off error, duration_ms and roundtrip_ms may differ by + // about (60 * 1000 / 64) / tempo. + int roundtrip_tol = tol * (60.0f * 1000.0f / 64.0f) / tempo; + ASSERT_NEAR(roundtrip_ms, duration_ms, roundtrip_tol); + + // Only test converting back to ms if the result would be in uint16_t range. + if (roundtrip_ms <= UINT16_MAX) { + ASSERT_NEAR(audio_duration_to_ms(duration_bpm), roundtrip_ms, tol); + } + } +} + +} // namespace diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index b7ecfa52ef8e..0aa4b780078f 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp @@ -365,9 +365,10 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { InSequence s; KeymapKey layer_0_key_0 = KeymapKey{0, 0, 0, LT(1, KC_T)}; + KeymapKey layer_0_key_1 = KeymapKey{0, 1, 0, KC_X}; KeymapKey layer_1_key_1 = KeymapKey{1, 1, 0, RALT(KC_9)}; - set_keymap({layer_0_key_0, layer_1_key_1}); + set_keymap({layer_0_key_0, layer_0_key_1, layer_1_key_1}); /* Press layer tap and wait for tapping term to switch to layer 1 */ EXPECT_NO_REPORT(driver); diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp index 2401c2c837a5..2a3434bf1616 100644 --- a/tests/basic/test_one_shot_keys.cpp +++ b/tests/basic/test_one_shot_keys.cpp @@ -160,6 +160,150 @@ INSTANTIATE_TEST_CASE_P( )); // clang-format on +TEST_F(OneShot, OSMChainingTwoOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and relesea OSM2 */ + EXPECT_NO_REPORT(driver); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key */ + EXPECT_EMPTY_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(OneShot, OSMDoubleTapNotLockingOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and release OSM2 twice */ + EXPECT_NO_REPORT(driver); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key */ + EXPECT_EMPTY_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key */ + EXPECT_EMPTY_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(OneShot, OSMHoldNotLockingOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and hold OSM2 */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code)).Times(1); + osm_key2.press(); + run_one_scan_loop(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + /* Press and release regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + EXPECT_REPORT(driver, (osm_key2.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release OSM2 */ + EXPECT_EMPTY_REPORT(driver); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key */ + EXPECT_EMPTY_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + TEST_F(OneShot, OSLWithAdditionalKeypress) { TestDriver driver; InSequence s; diff --git a/tests/caps_word/caps_word_combo/test.mk b/tests/caps_word/caps_word_combo/test.mk index 9f2e157189fe..c2948641130c 100644 --- a/tests/caps_word/caps_word_combo/test.mk +++ b/tests/caps_word/caps_word_combo/test.mk @@ -17,3 +17,4 @@ CAPS_WORD_ENABLE = yes COMBO_ENABLE = yes AUTO_SHIFT_ENABLE = yes +INTROSPECTION_KEYMAP_C = test_combos.c diff --git a/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp b/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp index 0876cc91a307..2cee203dfdd6 100644 --- a/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp +++ b/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp @@ -38,29 +38,6 @@ using ::testing::AnyOf; using ::testing::InSequence; using ::testing::TestParamInfo; -extern "C" { -// Define some combos to use for the test, including overlapping combos and -// combos that chord tap-hold keys. -enum combo_events { AB_COMBO, BC_COMBO, AD_COMBO, DE_COMBO, FGHI_COMBO, COMBO_LENGTH }; -uint16_t COMBO_LEN = COMBO_LENGTH; - -const uint16_t ab_combo[] PROGMEM = {KC_A, KC_B, COMBO_END}; -const uint16_t bc_combo[] PROGMEM = {KC_B, KC_C, COMBO_END}; -const uint16_t ad_combo[] PROGMEM = {KC_A, LCTL_T(KC_D), COMBO_END}; -const uint16_t de_combo[] PROGMEM = {LCTL_T(KC_D), LT(1, KC_E), COMBO_END}; -const uint16_t fghi_combo[] PROGMEM = {KC_F, KC_G, KC_H, KC_I, COMBO_END}; - -// clang-format off -combo_t key_combos[] = { - [AB_COMBO] = COMBO(ab_combo, KC_SPC), // KC_A + KC_B = KC_SPC - [BC_COMBO] = COMBO(bc_combo, KC_X), // KC_B + KC_C = KC_X - [AD_COMBO] = COMBO(ad_combo, KC_Y), // KC_A + LCTL_T(KC_D) = KC_Y - [DE_COMBO] = COMBO(de_combo, KC_Z), // LCTL_T(KC_D) + LT(1, KC_E) = KC_Z - [FGHI_COMBO] = COMBO(fghi_combo, KC_W) // KC_F + KC_G + KC_H + KC_I = KC_W -}; -// clang-format on -} // extern "C" - namespace { // To test combos thorougly, we test them with pressing the chord keys with diff --git a/tests/caps_word/caps_word_combo/test_combos.c b/tests/caps_word/caps_word_combo/test_combos.c new file mode 100644 index 000000000000..1d07118d509c --- /dev/null +++ b/tests/caps_word/caps_word_combo/test_combos.c @@ -0,0 +1,20 @@ +#include + +// Define some combos to use for the test, including overlapping combos and +// combos that chord tap-hold keys. +enum combo_events { AB_COMBO, BC_COMBO, AD_COMBO, DE_COMBO, FGHI_COMBO }; + +const uint16_t ab_combo[] PROGMEM = {KC_A, KC_B, COMBO_END}; +const uint16_t bc_combo[] PROGMEM = {KC_B, KC_C, COMBO_END}; +const uint16_t ad_combo[] PROGMEM = {KC_A, LCTL_T(KC_D), COMBO_END}; +const uint16_t de_combo[] PROGMEM = {LCTL_T(KC_D), LT(1, KC_E), COMBO_END}; +const uint16_t fghi_combo[] PROGMEM = {KC_F, KC_G, KC_H, KC_I, COMBO_END}; + +// clang-format off +combo_t key_combos[] = { + [AB_COMBO] = COMBO(ab_combo, KC_SPC), // KC_A + KC_B = KC_SPC + [BC_COMBO] = COMBO(bc_combo, KC_X), // KC_B + KC_C = KC_X + [AD_COMBO] = COMBO(ad_combo, KC_Y), // KC_A + LCTL_T(KC_D) = KC_Y + [DE_COMBO] = COMBO(de_combo, KC_Z), // LCTL_T(KC_D) + LT(1, KC_E) = KC_Z + [FGHI_COMBO] = COMBO(fghi_combo, KC_W) // KC_F + KC_G + KC_H + KC_I = KC_W +}; diff --git a/tests/caps_word/caps_word_invert_on_shift/config.h b/tests/caps_word/caps_word_invert_on_shift/config.h new file mode 100644 index 000000000000..7a3ec846f992 --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/config.h @@ -0,0 +1,21 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "test_common.h" + +#define CAPS_WORD_INVERT_ON_SHIFT +#define PERMISSIVE_HOLD diff --git a/tests/caps_word/caps_word_invert_on_shift/test.mk b/tests/caps_word/caps_word_invert_on_shift/test.mk new file mode 100644 index 000000000000..319c04d67a91 --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/test.mk @@ -0,0 +1,17 @@ +# Copyright 2023 Google LLC +# +# 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 . + +CAPS_WORD_ENABLE = yes + diff --git a/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp b/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp new file mode 100644 index 000000000000..d3224481818c --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp @@ -0,0 +1,215 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_fixture.hpp" +#include "test_keymap_key.hpp" + +using ::testing::_; +using ::testing::AnyNumber; +using ::testing::AnyOf; +using ::testing::InSequence; +using ::testing::TestParamInfo; + +namespace { + +struct ShiftKeyParams { + std::string name; + uint16_t keycode; + uint16_t report_shift_code; + + static const std::string& GetName(const TestParamInfo& info) { + return info.param.name; + } +}; + +class CapsWordInvertOnShift : public ::testing::WithParamInterface, public TestFixture { + void SetUp() override { + caps_word_off(); + } +}; + +// With Caps Word on, type "A, 4, Shift(A, 4, A), A, Shift(A), 4". +TEST_P(CapsWordInvertOnShift, ShiftWithinWord) { + TestDriver driver; + KeymapKey key_shift(0, 0, 0, GetParam().keycode); + KeymapKey key_a(0, 1, 0, KC_A); + KeymapKey key_4(0, 2, 0, KC_4); + set_keymap({key_shift, key_a, key_4}); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "A4a$aAa4" + InSequence s; + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + EXPECT_REPORT(driver, (KC_4)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (KC_LSFT, KC_4)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (KC_4)); + } + + caps_word_on(); + tap_keys(key_a, key_4); // Type "A, 4". + + key_shift.press(); // Type "Shift(A, 4, A)". + run_one_scan_loop(); + tap_keys(key_a, key_4, key_a); + key_shift.release(); + run_one_scan_loop(); + + tap_key(key_a); // Type "A". + + key_shift.press(); // Type "Shift(A)". + run_one_scan_loop(); + tap_key(key_a); + key_shift.release(); + run_one_scan_loop(); + + tap_key(key_4); // Type "4". + + VERIFY_AND_CLEAR(driver); +} + +TEST_P(CapsWordInvertOnShift, ShiftHeldAtWordEnd) { + TestDriver driver; + KeymapKey key_shift(0, 0, 0, GetParam().keycode); + KeymapKey key_a(0, 1, 0, KC_A); + KeymapKey key_slsh(0, 2, 0, KC_SLSH); + set_keymap({key_shift, key_a, key_slsh}); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT), + KeyboardReport(KC_RSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "Aa?A" + InSequence s; + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_SLSH)); + EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_A)); + } + + caps_word_on(); + tap_key(key_a); + + key_shift.press(); // Press Shift. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), 0); + + tap_key(key_a); + tap_key(key_slsh); // Tap '/' key, which is word breaking, ending Caps Word. + + EXPECT_FALSE(is_caps_word_on()); + EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); + + tap_key(key_a); + key_shift.release(); // Release Shift. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), 0); + VERIFY_AND_CLEAR(driver); +} + +TEST_P(CapsWordInvertOnShift, TwoShiftsHeld) { + TestDriver driver; + KeymapKey key_shift1(0, 0, 0, GetParam().keycode); + KeymapKey key_shift2(0, 1, 0, GetParam().report_shift_code); + KeymapKey key_a(0, 2, 0, KC_A); + KeymapKey key_slsh(0, 3, 0, KC_SLSH); + set_keymap({key_shift1, key_shift2, key_a, key_slsh}); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT), + KeyboardReport(KC_RSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "Aa?a" + InSequence s; + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_SLSH)); + EXPECT_REPORT(driver, (KC_A)); + } + + caps_word_on(); + tap_key(key_a); + + key_shift1.press(); // Press shift1. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), 0); + + tap_key(key_a); + tap_key(key_slsh); // Tap '/' key, which is word breaking, ending Caps Word. + + EXPECT_FALSE(is_caps_word_on()); + EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); + + key_shift2.press(); // Press shift2. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); + + key_shift1.release(); // Release shift1. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), 0); + tap_key(key_a); + + key_shift2.release(); // Release shift2. + run_one_scan_loop(); + + EXPECT_EQ(get_mods(), 0); + VERIFY_AND_CLEAR(driver); +} + +// clang-format off +INSTANTIATE_TEST_CASE_P( + Shifts, + CapsWordInvertOnShift, + ::testing::Values( + ShiftKeyParams{"KC_LSFT", KC_LSFT, KC_LSFT}, + ShiftKeyParams{"KC_RSFT", KC_RSFT, KC_RSFT}, + ShiftKeyParams{"LSFT_T", LSFT_T(KC_A), KC_LSFT}, + ShiftKeyParams{"RSFT_T", RSFT_T(KC_A), KC_RSFT}, + ShiftKeyParams{"OSM_LSFT", OSM(MOD_LSFT), KC_LSFT}, + ShiftKeyParams{"OSM_RSFT", OSM(MOD_RSFT), KC_RSFT} + ), + ShiftKeyParams::GetName + ); +// clang-format on + +} // namespace diff --git a/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp b/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp index 01cdfd6408d2..21e5493526e0 100644 --- a/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp +++ b/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp @@ -39,8 +39,8 @@ const uint32_t unicode_map[] PROGMEM = { [DELTA_UPPERCASE] = 0x0394, }; -#define U_DASH XP(ENDASH, EMDASH) -#define U_DELTA XP(DELTA_LOWERCASE, DELTA_UPPERCASE) +#define U_DASH UP(ENDASH, EMDASH) +#define U_DELTA UP(DELTA_LOWERCASE, DELTA_UPPERCASE) bool caps_word_press_user(uint16_t keycode) { switch (keycode) { diff --git a/tests/caps_word/test_caps_word.cpp b/tests/caps_word/test_caps_word.cpp index 6d38b383f31d..802f1e960e5c 100644 --- a/tests/caps_word/test_caps_word.cpp +++ b/tests/caps_word/test_caps_word.cpp @@ -371,6 +371,11 @@ INSTANTIATE_TEST_CASE_P( "OSL", OSL(1), 1, KC_NO, true}, CapsWordPressUserParams{ "LT_held", LT_1_KC_A, TAPPING_TERM + 1, KC_NO, true}, + // Tri-Layer keys are ignored and continue Caps Word. + CapsWordPressUserParams{ + "TL_LOWR", TL_LOWR, 1, KC_NO, true}, + CapsWordPressUserParams{ + "TL_UPPR", TL_UPPR, 1, KC_NO, true}, // AltGr keys are ignored and continue Caps Word. CapsWordPressUserParams{ "KC_RALT", KC_RALT, 1, KC_NO, true}, diff --git a/tests/combo/config.h b/tests/combo/config.h new file mode 100644 index 000000000000..805293263433 --- /dev/null +++ b/tests/combo/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 Stefan Kerkmann (@KarlK90) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define TAPPING_TERM 200 diff --git a/tests/combo/test.mk b/tests/combo/test.mk new file mode 100644 index 000000000000..4776b9d0c4aa --- /dev/null +++ b/tests/combo/test.mk @@ -0,0 +1,6 @@ +# Copyright 2023 Stefan Kerkmann (@KarlK90) +# SPDX-License-Identifier: GPL-2.0-or-later + +COMBO_ENABLE = yes + +INTROSPECTION_KEYMAP_C = test_combos.c diff --git a/tests/combo/test_combo.cpp b/tests/combo/test_combo.cpp new file mode 100644 index 000000000000..ac852f9d1669 --- /dev/null +++ b/tests/combo/test_combo.cpp @@ -0,0 +1,57 @@ +// Copyright 2023 Stefan Kerkmann (@KarlK90) +// Copyright 2023 @filterpaper +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "quantum.h" +#include "keycode.h" +#include "test_common.h" +#include "test_driver.hpp" +#include "test_fixture.hpp" +#include "test_keymap_key.hpp" + +using testing::_; +using testing::InSequence; + +class Combo : public TestFixture {}; + +TEST_F(Combo, combo_modtest_tapped) { + TestDriver driver; + KeymapKey key_y(0, 0, 1, KC_Y); + KeymapKey key_u(0, 0, 2, KC_U); + set_keymap({key_y, key_u}); + + EXPECT_REPORT(driver, (KC_SPACE)); + EXPECT_EMPTY_REPORT(driver); + tap_combo({key_y, key_u}); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(Combo, combo_modtest_held_longer_than_tapping_term) { + TestDriver driver; + KeymapKey key_y(0, 0, 1, KC_Y); + KeymapKey key_u(0, 0, 2, KC_U); + set_keymap({key_y, key_u}); + + EXPECT_REPORT(driver, (KC_RIGHT_SHIFT)); + EXPECT_EMPTY_REPORT(driver); + tap_combo({key_y, key_u}, TAPPING_TERM + 1); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(Combo, combo_osmshift_tapped) { + TestDriver driver; + KeymapKey key_z(0, 0, 1, KC_Z); + KeymapKey key_x(0, 0, 2, KC_X); + KeymapKey key_i(0, 0, 3, KC_I); + set_keymap({key_z, key_x, key_i}); + + EXPECT_NO_REPORT(driver); + tap_combo({key_z, key_x}); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (KC_I, KC_LEFT_SHIFT)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_i); + VERIFY_AND_CLEAR(driver); +} diff --git a/tests/combo/test_combos.c b/tests/combo/test_combos.c new file mode 100644 index 000000000000..8dcb364c6e50 --- /dev/null +++ b/tests/combo/test_combos.c @@ -0,0 +1,17 @@ +// Copyright 2023 Stefan Kerkmann (@KarlK90) +// Copyright 2023 @filterpaper +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "quantum.h" + +enum combos { modtest, osmshift }; + +uint16_t const modtest_combo[] = {KC_Y, KC_U, COMBO_END}; +uint16_t const osmshift_combo[] = {KC_Z, KC_X, COMBO_END}; + +// clang-format off +combo_t key_combos[] = { + [modtest] = COMBO(modtest_combo, RSFT_T(KC_SPACE)), + [osmshift] = COMBO(osmshift_combo, OSM(MOD_LSFT)) +}; +// clang-format on diff --git a/tests/repeat_key/alt_repeat_key/config.h b/tests/repeat_key/alt_repeat_key/config.h new file mode 100644 index 000000000000..d0c4ddadbd3b --- /dev/null +++ b/tests/repeat_key/alt_repeat_key/config.h @@ -0,0 +1,18 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "test_common.h" diff --git a/tests/repeat_key/alt_repeat_key/test.mk b/tests/repeat_key/alt_repeat_key/test.mk new file mode 100644 index 000000000000..080871c81645 --- /dev/null +++ b/tests/repeat_key/alt_repeat_key/test.mk @@ -0,0 +1,18 @@ +# Copyright 2023 Google LLC +# +# 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 . + +REPEAT_KEY_ENABLE = yes + +EXTRAKEY_ENABLE = yes diff --git a/tests/repeat_key/alt_repeat_key/test_alt_repeat_key.cpp b/tests/repeat_key/alt_repeat_key/test_alt_repeat_key.cpp new file mode 100644 index 000000000000..ae525acb4554 --- /dev/null +++ b/tests/repeat_key/alt_repeat_key/test_alt_repeat_key.cpp @@ -0,0 +1,523 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_fixture.hpp" +#include "test_keymap_key.hpp" + +using ::testing::AnyNumber; +using ::testing::InSequence; + +namespace { + +bool process_record_user_default(uint16_t keycode, keyrecord_t* record) { + return true; +} + +bool remember_last_key_user_default(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return true; +} + +uint16_t get_alt_repeat_key_keycode_user_default(uint16_t keycode, uint8_t mods) { + return KC_TRNS; +} + +// Indirections so that process_record_user() can be replaced with other +// functions in the test cases below. +std::function process_record_user_fun = process_record_user_default; +std::function remember_last_key_user_fun = remember_last_key_user_default; +std::function get_alt_repeat_key_keycode_user_fun = get_alt_repeat_key_keycode_user_default; + +extern "C" bool process_record_user(uint16_t keycode, keyrecord_t* record) { + return process_record_user_fun(keycode, record); +} + +extern "C" bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return remember_last_key_user_fun(keycode, record, remembered_mods); +} + +extern "C" uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods) { + return get_alt_repeat_key_keycode_user_fun(keycode, mods); +} + +class AltRepeatKey : public TestFixture { + public: + bool process_record_user_was_called_; + + void SetUp() override { + process_record_user_fun = process_record_user_default; + remember_last_key_user_fun = remember_last_key_user_default; + get_alt_repeat_key_keycode_user_fun = get_alt_repeat_key_keycode_user_default; + } + + void ExpectProcessRecordUserCalledWith(bool expected_press, uint16_t expected_keycode, int8_t expected_repeat_key_count) { + process_record_user_was_called_ = false; + process_record_user_fun = [=](uint16_t keycode, keyrecord_t* record) { + EXPECT_EQ(record->event.pressed, expected_press); + EXPECT_KEYCODE_EQ(keycode, expected_keycode); + EXPECT_EQ(get_repeat_key_count(), expected_repeat_key_count); + // Tests below use this to verify process_record_user() was called. + process_record_user_was_called_ = true; + return true; + }; + } + + // Expects that the characters of `s` are sent. + // NOTE: This implementation is limited to chars a-z, A-Z. + void ExpectString(TestDriver& driver, const std::string& s) { + InSequence seq; + for (int c : s) { + switch (c) { + case 'a' ... 'z': { // Lowercase letter. + uint16_t keycode = c - ('a' - KC_A); + EXPECT_REPORT(driver, (keycode)); + } break; + + case 'A' ... 'Z': { // Capital letter = KC_LSFT + letter key. + uint16_t keycode = c - ('A' - KC_A); + EXPECT_REPORT(driver, (KC_LSFT, keycode)); + } break; + } + } + } +}; + +TEST_F(AltRepeatKey, AlternateBasic) { + TestDriver driver; + KeymapKey key_bspc(0, 0, 0, KC_BSPC); + KeymapKey key_pgdn(0, 1, 0, KC_PGDN); + KeymapKey key_pgup(0, 2, 0, KC_PGUP); + KeymapKey key_repeat(0, 4, 0, QK_REP); + KeymapKey key_alt_repeat(0, 5, 0, QK_AREP); + set_keymap({key_bspc, key_pgdn, key_pgup, key_repeat, key_alt_repeat}); + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + { + InSequence seq; + EXPECT_REPORT(driver, (KC_BSPC)); + EXPECT_REPORT(driver, (KC_DEL)); + EXPECT_REPORT(driver, (KC_DEL)); + EXPECT_REPORT(driver, (KC_BSPC)); + EXPECT_REPORT(driver, (KC_DEL)); + EXPECT_REPORT(driver, (KC_PGDN)); + EXPECT_REPORT(driver, (KC_PGUP)); + EXPECT_REPORT(driver, (KC_PGUP)); + EXPECT_REPORT(driver, (KC_PGDN)); + } + + tap_key(key_bspc); + + for (int n = 1; n <= 2; ++n) { // Tap the Alternate Repeat Key twice. + ExpectProcessRecordUserCalledWith(true, KC_DEL, -n); + key_alt_repeat.press(); // Press the Alternate Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + // Expect the corresponding release event. + ExpectProcessRecordUserCalledWith(false, KC_DEL, -n); + key_alt_repeat.release(); // Release the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + } + + process_record_user_fun = process_record_user_default; + tap_keys(key_repeat, key_alt_repeat); + tap_keys(key_pgdn, key_alt_repeat); + tap_keys(key_pgup, key_alt_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +struct TestParamsAlternateKeyCodes { + uint16_t keycode; + uint8_t mods; + uint16_t expected_alt_keycode; +}; + +// Tests `get_alt_repeat_key_keycode()` for various keycodes. +TEST_F(AltRepeatKey, GetAltRepeatKeyKeycode) { + for (const auto& params : std::vector({ + // clang-format off + // Each line tests one call to `get_alt_repeat_key_keycode()`: + // {keycode, mods, expected_alt_keycode}. + // Arrows. + {KC_LEFT, 0, KC_RGHT}, + {KC_RGHT, 0, KC_LEFT}, + {KC_LEFT, MOD_BIT(KC_LSFT), LSFT(KC_RGHT)}, + {KC_LEFT, MOD_BIT(KC_RSFT), RSFT(KC_RGHT)}, + {KC_LEFT, MOD_BIT(KC_LCTL) | MOD_BIT(KC_LSFT), C(S(KC_RGHT))}, + {KC_LEFT, MOD_BIT(KC_LGUI), LGUI(KC_RGHT)}, + {C(KC_LEFT), MOD_BIT(KC_LSFT), C(S(KC_RGHT))}, + {KC_UP, 0, KC_DOWN}, + // Navigation keys. + {KC_PGUP, 0, KC_PGDN}, + {KC_HOME, 0, KC_END }, + // Media keys. + {KC_WBAK, 0, KC_WFWD}, + {KC_MNXT, 0, KC_MPRV}, + {KC_MRWD, 0, KC_MFFD}, + {KC_VOLU, 0, KC_VOLD}, + {KC_BRIU, 0, KC_BRID}, + // Emacs navigation. + {KC_N, MOD_BIT(KC_LCTL), C(KC_P)}, + {KC_B, MOD_BIT(KC_LCTL), LCTL(KC_F)}, + {KC_B, MOD_BIT(KC_RCTL), RCTL(KC_F)}, + {KC_B, MOD_BIT(KC_LALT), LALT(KC_F)}, + {KC_F, MOD_BIT(KC_LCTL), C(KC_B)}, + {KC_A, MOD_BIT(KC_LCTL), C(KC_E)}, + {KC_D, MOD_BIT(KC_LCTL), C(KC_U)}, + // Vim navigation. + {KC_J, 0, KC_K}, + {KC_K, 0, KC_J}, + {KC_H, 0, KC_L}, + {KC_B, 0, KC_W}, + {KC_W, 0, KC_B}, + {KC_E, 0, KC_B}, + {KC_B, MOD_BIT(KC_LSFT), S(KC_W)}, + {KC_W, MOD_BIT(KC_LSFT), S(KC_B)}, + {KC_E, MOD_BIT(KC_LSFT), S(KC_B)}, + {KC_O, MOD_BIT(KC_LCTL), C(KC_I)}, + {KC_I, MOD_BIT(KC_LCTL), C(KC_O)}, + // Other. + {KC_DEL, 0, KC_BSPC}, + {KC_LBRC, 0, KC_RBRC}, + {KC_LCBR, 0, KC_RCBR}, + // Some keys where the last key is a tap-hold key. + {LSFT_T(KC_F), MOD_BIT(KC_RCTL), RCTL(KC_B)}, + {LT(1, KC_A), MOD_BIT(KC_RGUI), RGUI(KC_E)}, + {RALT_T(KC_J), 0, KC_K}, + // Some keys where no alternate is defined. + {KC_A, 0, KC_NO}, + {KC_F1, 0, KC_NO}, + {QK_LEAD, 0, KC_NO}, + {MO(1), 0, KC_NO}, + // clang-format on + })) { + SCOPED_TRACE(std::string("Input keycode: ") + get_keycode_identifier_or_default(params.keycode)); + set_last_keycode(params.keycode); + set_last_mods(params.mods); + + const uint16_t actual = get_alt_repeat_key_keycode(); + + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), params.expected_alt_keycode); + } +} + +// Test adding to and overriding the above through the +// `get_alt_repeat_key_keycode_user()` callback. +TEST_F(AltRepeatKey, GetAltRepeatKeyKeycodeUser) { + get_alt_repeat_key_keycode_user_fun = [](uint16_t keycode, uint8_t mods) -> uint16_t { + bool shifted = (mods & MOD_MASK_SHIFT); + switch (keycode) { + case KC_LEFT: + return KC_ENT; + case MO(1): + return TG(1); + case KC_TAB: // Tab <-> Shift + Tab example. + if (shifted) { + return KC_TAB; + } else { + return S(KC_TAB); + } + } + + // Ctrl + Y <-> Ctrl + Z example. + if ((mods & MOD_MASK_CTRL)) { + switch (keycode) { + case KC_Y: + return C(KC_Z); + case KC_Z: + return C(KC_Y); + } + } + + return KC_NO; + }; + + set_last_keycode(KC_LEFT); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), KC_ENT); + + set_last_keycode(MO(1)); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), TG(1)); + + set_last_keycode(KC_TAB); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), S(KC_TAB)); + + set_last_keycode(KC_TAB); + set_last_mods(MOD_BIT(KC_LSFT)); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), KC_TAB); + + set_last_keycode(KC_Z); + set_last_mods(MOD_BIT(KC_LCTL)); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), C(KC_Y)); + + set_last_keycode(KC_Y); + set_last_mods(MOD_BIT(KC_LCTL)); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), C(KC_Z)); +} + +// Tests rolling from a key to Alternate Repeat. +TEST_F(AltRepeatKey, RollingToAltRepeat) { + TestDriver driver; + KeymapKey key_left(0, 0, 0, KC_LEFT); + KeymapKey key_alt_repeat(0, 1, 0, QK_AREP); + set_keymap({key_left, key_alt_repeat}); + + { + InSequence seq; + EXPECT_REPORT(driver, (KC_LEFT)); + EXPECT_REPORT(driver, (KC_LEFT, KC_RGHT)); + EXPECT_REPORT(driver, (KC_RGHT)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_RGHT)); + EXPECT_EMPTY_REPORT(driver); + } + + // Perform a rolled press from Left to Alternate Repeat. + + ExpectProcessRecordUserCalledWith(true, KC_LEFT, 0); + key_left.press(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(true, KC_RGHT, -1); + key_alt_repeat.press(); // Press the Alternate Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_LEFT, 0); + key_left.release(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_RGHT, -1); + key_alt_repeat.release(); // Release the Alternate Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + process_record_user_fun = process_record_user_default; + tap_key(key_alt_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests rolling from Alternate Repeat to another key. +TEST_F(AltRepeatKey, RollingFromAltRepeat) { + TestDriver driver; + KeymapKey key_left(0, 0, 0, KC_LEFT); + KeymapKey key_up(0, 1, 0, KC_UP); + KeymapKey key_alt_repeat(0, 2, 0, QK_AREP); + set_keymap({key_left, key_up, key_alt_repeat}); + + { + InSequence seq; + EXPECT_REPORT(driver, (KC_LEFT)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_RGHT)); + EXPECT_REPORT(driver, (KC_RGHT, KC_UP)); + EXPECT_REPORT(driver, (KC_UP)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_DOWN)); + EXPECT_EMPTY_REPORT(driver); + } + + tap_key(key_left); + + // Perform a rolled press from Alternate Repeat to Up. + + ExpectProcessRecordUserCalledWith(true, KC_RGHT, -1); + key_alt_repeat.press(); // Press the Alternate Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(true, KC_UP, 0); + key_up.press(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_UP); + + ExpectProcessRecordUserCalledWith(false, KC_RGHT, -1); + key_alt_repeat.release(); // Release the Alternate Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_UP, 0); + key_up.release(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + process_record_user_fun = process_record_user_default; + tap_key(key_alt_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests using the Alternate Repeat Key on a macro that doesn't have an +// alternate keycode defined. +TEST_F(AltRepeatKey, AlternateUnsupportedMacro) { + TestDriver driver; + KeymapKey key_foo(0, 0, 0, QK_USER_0); + KeymapKey key_alt_repeat(0, 1, 0, QK_AREP); + set_keymap({key_foo, key_alt_repeat}); + + process_record_user_fun = [=](uint16_t keycode, keyrecord_t* record) { + process_record_user_was_called_ = true; + switch (keycode) { + case QK_USER_0: + if (record->event.pressed) { + SEND_STRING("foo"); + } + break; + } + return true; + }; + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "foofoo"); + + process_record_user_was_called_ = false; + tap_key(key_foo); + + EXPECT_TRUE(process_record_user_was_called_); + EXPECT_KEYCODE_EQ(get_last_keycode(), QK_USER_0); + EXPECT_KEYCODE_EQ(get_alt_repeat_key_keycode(), KC_NO); + + process_record_user_was_called_ = false; + key_alt_repeat.press(); // Press Alternate Repeat. + run_one_scan_loop(); + + EXPECT_FALSE(process_record_user_was_called_); + + process_record_user_was_called_ = false; + key_alt_repeat.release(); // Release Alternate Repeat. + run_one_scan_loop(); + + EXPECT_FALSE(process_record_user_was_called_); + + process_record_user_was_called_ = false; + tap_key(key_foo); + + EXPECT_TRUE(process_record_user_was_called_); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests a macro with custom alternate behavior. +TEST_F(AltRepeatKey, MacroCustomAlternate) { + TestDriver driver; + KeymapKey key_foo(0, 0, 0, QK_USER_0); + KeymapKey key_alt_repeat(0, 1, 0, QK_AREP); + set_keymap({key_foo, key_alt_repeat}); + + get_alt_repeat_key_keycode_user_fun = [](uint16_t keycode, uint8_t mods) -> uint16_t { + switch (keycode) { + case QK_USER_0: + return QK_USER_0; // QK_USER_0 handles its own alternate. + default: + return KC_NO; // No key by default. + } + }; + process_record_user_fun = [=](uint16_t keycode, keyrecord_t* record) { + process_record_user_was_called_ = true; + switch (keycode) { + case QK_USER_0: + if (record->event.pressed) { + if (get_repeat_key_count() >= 0) { + SEND_STRING("foo"); + } else { // Key is being alternate repeated. + SEND_STRING("bar"); + } + } + break; + } + return true; + }; + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "foobarbar"); + + tap_keys(key_foo, key_alt_repeat, key_alt_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests the Additional "Alternate" keys example from the documentation page. +TEST_F(AltRepeatKey, AdditionalAlternateKeysExample) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_w(0, 1, 0, KC_W); + KeymapKey key_altrep2(0, 2, 0, QK_USER_0); + KeymapKey key_altrep3(0, 3, 0, QK_USER_1); + set_keymap({key_a, key_w, key_altrep2, key_altrep3}); + + remember_last_key_user_fun = [](uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + switch (keycode) { + case QK_USER_0: + case QK_USER_1: + return false; // Ignore ALTREP keys. + } + return true; // Other keys can be repeated. + }; + process_record_user_fun = [=](uint16_t keycode, keyrecord_t* record) { + switch (keycode) { + case QK_USER_0: + if (record->event.pressed) { + const uint16_t last_key = get_last_keycode(); + switch (last_key) { + case KC_A: + SEND_STRING(/*a*/ "tion"); + break; + case KC_W: + SEND_STRING(/*w*/ "hich"); + break; + } + } + return false; + case QK_USER_1: + if (record->event.pressed) { + const uint16_t last_key = get_last_keycode(); + switch (last_key) { + case KC_A: + SEND_STRING(/*a*/ "bout"); + break; + case KC_W: + SEND_STRING(/*w*/ "ould"); + break; + } + } + return false; + } + return true; + }; + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "ationwhichaboutwould"); + + tap_keys(key_a, key_altrep2, key_w, key_altrep2); + tap_keys(key_a, key_altrep3, key_w, key_altrep3); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +} // namespace diff --git a/tests/repeat_key/config.h b/tests/repeat_key/config.h new file mode 100644 index 000000000000..003d980c824b --- /dev/null +++ b/tests/repeat_key/config.h @@ -0,0 +1,20 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "test_common.h" + +#define NO_ALT_REPEAT_KEY diff --git a/tests/repeat_key/repeat_key_combo/config.h b/tests/repeat_key/repeat_key_combo/config.h new file mode 100644 index 000000000000..d0c4ddadbd3b --- /dev/null +++ b/tests/repeat_key/repeat_key_combo/config.h @@ -0,0 +1,18 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "test_common.h" diff --git a/tests/repeat_key/repeat_key_combo/test.mk b/tests/repeat_key/repeat_key_combo/test.mk new file mode 100644 index 000000000000..aac41acaebf9 --- /dev/null +++ b/tests/repeat_key/repeat_key_combo/test.mk @@ -0,0 +1,19 @@ +# Copyright 2023 Google LLC +# +# 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 . + +REPEAT_KEY_ENABLE = yes + +COMBO_ENABLE = yes +INTROSPECTION_KEYMAP_C = test_combos.c diff --git a/tests/repeat_key/repeat_key_combo/test_combos.c b/tests/repeat_key/repeat_key_combo/test_combos.c new file mode 100644 index 000000000000..86de89e19334 --- /dev/null +++ b/tests/repeat_key/repeat_key_combo/test_combos.c @@ -0,0 +1,8 @@ +// Copyright 2023 Stefan Kerkmann (@KarlK90) +// Copyright 2023 @filterpaper +// Copyright 2023 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "quantum.h" + +const uint16_t xy_combo[] PROGMEM = {KC_X, KC_Y, COMBO_END}; +combo_t key_combos[] = {COMBO(xy_combo, KC_Q)}; diff --git a/tests/repeat_key/repeat_key_combo/test_repeat_key_combo.cpp b/tests/repeat_key/repeat_key_combo/test_repeat_key_combo.cpp new file mode 100644 index 000000000000..c2d96a0dfe6d --- /dev/null +++ b/tests/repeat_key/repeat_key_combo/test_repeat_key_combo.cpp @@ -0,0 +1,60 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_fixture.hpp" +#include "test_keymap_key.hpp" + +using ::testing::AnyNumber; +using ::testing::InSequence; + +namespace { + +class RepeatKey : public TestFixture {}; + +// Tests repeating a combo, KC_X + KC_Y = KC_Q, by typing +// "X, Repeat, Repeat, {X Y}, Repeat, Repeat". This produces "xxxqqq". +TEST_F(RepeatKey, Combo) { + TestDriver driver; + KeymapKey key_x(0, 0, 0, KC_X); + KeymapKey key_y(0, 1, 0, KC_Y); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_x, key_y, key_repeat}); + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + { + InSequence seq; + EXPECT_REPORT(driver, (KC_X)); + EXPECT_REPORT(driver, (KC_X)); + EXPECT_REPORT(driver, (KC_X)); + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_REPORT(driver, (KC_Q)); + } + + tap_keys(key_x, key_repeat, key_repeat); + tap_combo({key_x, key_y}); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_Q); + + tap_keys(key_repeat, key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +} // namespace diff --git a/tests/repeat_key/test.mk b/tests/repeat_key/test.mk new file mode 100644 index 000000000000..aec8ff3bfb89 --- /dev/null +++ b/tests/repeat_key/test.mk @@ -0,0 +1,18 @@ +# Copyright 2023 Google LLC +# +# 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 . + +REPEAT_KEY_ENABLE = yes + +AUTO_SHIFT_ENABLE = yes diff --git a/tests/repeat_key/test_repeat_key.cpp b/tests/repeat_key/test_repeat_key.cpp new file mode 100644 index 000000000000..eee44fc10448 --- /dev/null +++ b/tests/repeat_key/test_repeat_key.cpp @@ -0,0 +1,754 @@ +// Copyright 2023 Google LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_fixture.hpp" +#include "test_keymap_key.hpp" + +using ::testing::AnyNumber; +using ::testing::AnyOf; +using ::testing::InSequence; + +#define FOO_MACRO SAFE_RANGE + +namespace { + +bool process_record_user_default(uint16_t keycode, keyrecord_t* record) { + return true; +} + +bool remember_last_key_user_default(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return true; +} + +// Indirection so that process_record_user() and remember_last_key_user() +// can be replaced with other functions in the test cases below. +std::function process_record_user_fun = process_record_user_default; +std::function remember_last_key_user_fun = remember_last_key_user_default; + +extern "C" bool process_record_user(uint16_t keycode, keyrecord_t* record) { + return process_record_user_fun(keycode, record); +} +extern "C" bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return remember_last_key_user_fun(keycode, record, remembered_mods); +} + +class RepeatKey : public TestFixture { + public: + bool process_record_user_was_called_; + + void SetUp() override { + autoshift_disable(); + process_record_user_fun = process_record_user_default; + remember_last_key_user_fun = remember_last_key_user_default; + } + + void ExpectProcessRecordUserCalledWith(bool expected_press, uint16_t expected_keycode, int8_t expected_repeat_key_count) { + process_record_user_was_called_ = false; + process_record_user_fun = [=](uint16_t keycode, keyrecord_t* record) { + EXPECT_EQ(record->event.pressed, expected_press); + EXPECT_KEYCODE_EQ(keycode, expected_keycode); + EXPECT_EQ(get_repeat_key_count(), expected_repeat_key_count); + // Tests below use this to verify process_record_user() was called. + process_record_user_was_called_ = true; + return true; + }; + } + + // Expects that the characters of `s` are sent. + // NOTE: This implementation is limited to chars a-z, A-Z. + void ExpectString(TestDriver& driver, const std::string& s) { + InSequence seq; + for (int c : s) { + switch (c) { + case 'a' ... 'z': { // Lowercase letter. + uint16_t keycode = c - ('a' - KC_A); + EXPECT_REPORT(driver, (keycode)); + } break; + + case 'A' ... 'Z': { // Capital letter = KC_LSFT + letter key. + uint16_t keycode = c - ('A' - KC_A); + EXPECT_REPORT(driver, (KC_LSFT, keycode)); + } break; + } + } + } +}; + +// Tests that "A, Repeat, Repeat, B, Repeat" produces "aaabb". +TEST_F(RepeatKey, Basic) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_b(0, 1, 0, KC_B); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_a, key_b, key_repeat}); + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "aaabb"); + + // When KC_A is pressed, process_record_user() should be called + // with a press event with keycode == KC_A and repeat_key_count() == 0. + ExpectProcessRecordUserCalledWith(true, KC_A, 0); + key_a.press(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + // After pressing A, the keycode of the key to be repeated is KC_A. + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_A); + EXPECT_EQ(get_last_mods(), 0); + + // Expect the corresponding release event when A is released. + ExpectProcessRecordUserCalledWith(false, KC_A, 0); + key_a.release(); + run_one_scan_loop(); + + for (int n = 1; n <= 2; ++n) { // Tap the Repeat Key twice. + // When Repeat is pressed, process_record_user() should be called with a + // press event with keycode == KC_A and repeat_key_count() == n. + ExpectProcessRecordUserCalledWith(true, KC_A, n); + key_repeat.press(); // Press the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + // Expect the corresponding release event. + ExpectProcessRecordUserCalledWith(false, KC_A, n); + key_repeat.release(); // Release the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + } + + process_record_user_fun = process_record_user_default; + tap_key(key_b); + // Then after tapping key_b, the keycode to be repeated becomes KC_B. + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_B); + + tap_key(key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests repeating a macro. The keycode FOO_MACRO sends "foo" when pressed. The +// test taps "FOO_MACRO, Repeat, Repeat", producing "foofoofoo". +TEST_F(RepeatKey, Macro) { + TestDriver driver; + KeymapKey key_foo(0, 0, 0, FOO_MACRO); + KeymapKey key_repeat(0, 1, 0, QK_REP); + set_keymap({key_foo, key_repeat}); + + // Define process_record_user() to handle FOO_MACRO. + process_record_user_fun = [](uint16_t keycode, keyrecord_t* record) { + switch (keycode) { + case FOO_MACRO: + if (record->event.pressed) { + SEND_STRING("foo"); + } + break; + } + return true; + }; + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "foofoofoo"); + + tap_key(key_foo); + + EXPECT_KEYCODE_EQ(get_last_keycode(), FOO_MACRO); + + tap_keys(key_repeat, key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests a macro with customized repeat behavior: "foo" is sent normally, "bar" +// on the first repeat, and "baz" on subsequent repeats. The test taps +// "FOO_MACRO, Repeat, Repeat, FOO_MACRO, Repeat", producing "foobarbazfoobar". +TEST_F(RepeatKey, MacroCustomRepeat) { + TestDriver driver; + KeymapKey key_foo(0, 0, 0, FOO_MACRO); + KeymapKey key_repeat(0, 1, 0, QK_REP); + set_keymap({key_foo, key_repeat}); + + process_record_user_fun = [](uint16_t keycode, keyrecord_t* record) { + switch (keycode) { + case FOO_MACRO: + if (record->event.pressed) { + switch (get_repeat_key_count()) { + case 0: // When pressed normally. + SEND_STRING("foo"); + break; + case 1: // On first repeat. + SEND_STRING("bar"); + break; + default: // On subsequent repeats. + SEND_STRING("baz"); + break; + } + } + break; + } + return true; + }; + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "foobarbazfoobar"); + + tap_key(key_foo); + + EXPECT_KEYCODE_EQ(get_last_keycode(), FOO_MACRO); + + tap_keys(key_repeat, key_repeat, key_foo, key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests repeating keys on different layers. A 2-layer keymap is defined: +// Layer 0: QK_REP , MO(1) , KC_A +// Layer 1: KC_TRNS, KC_TRNS, KC_B +// The test does the following, which should produce "bbbaaa": +// 1. Hold MO(1), switching to layer 1. +// 2. Tap KC_B on layer 1. +// 3. Release MO(1), switching back to layer 0. +// 4. Tap Repeat twice. +// 5. Tap KC_A on layer 0. +// 6. Hold MO(1), switching to layer 1. +// 7. Tap Repeat twice. +TEST_F(RepeatKey, AcrossLayers) { + TestDriver driver; + KeymapKey key_repeat(0, 0, 0, QK_REP); + KeymapKey key_mo_1(0, 1, 0, MO(1)); + KeymapKey regular_key(0, 2, 0, KC_A); + set_keymap({// Layer 0. + key_repeat, key_mo_1, regular_key, + // Layer 1. + KeymapKey{1, 0, 0, KC_TRNS}, KeymapKey{1, 1, 0, KC_TRNS}, KeymapKey{1, 2, 0, KC_B}}); + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "bbbaaa"); + + key_mo_1.press(); // Hold the MO(1) layer key. + run_one_scan_loop(); + tap_key(regular_key); // Taps the KC_B key on layer 1. + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_B); + + key_mo_1.release(); // Release the layer key. + run_one_scan_loop(); + tap_keys(key_repeat, key_repeat); + tap_key(regular_key); // Taps the KC_A key on layer 0. + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_A); + + key_mo_1.press(); // Hold the layer key. + run_one_scan_loop(); + tap_keys(key_repeat, key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests "A(down), Repeat(down), A(up), Repeat(up), Repeat" produces "aaa". +TEST_F(RepeatKey, RollingToRepeat) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_repeat(0, 1, 0, QK_REP); + set_keymap({key_a, key_repeat}); + + { + InSequence seq; + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + } + + // Perform a rolled press from A to Repeat. + + ExpectProcessRecordUserCalledWith(true, KC_A, 0); + key_a.press(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(true, KC_A, 1); + key_repeat.press(); // Press the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_A, 0); + key_a.release(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_A, 1); + key_repeat.release(); // Release the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + process_record_user_fun = process_record_user_default; + tap_key(key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests "A, Repeat(down), B(down), Repeat(up), B(up), Repeat" produces "aabb". +TEST_F(RepeatKey, RollingFromRepeat) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_b(0, 1, 0, KC_B); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_a, key_b, key_repeat}); + + { + InSequence seq; + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (KC_A, KC_B)); + EXPECT_REPORT(driver, (KC_B)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_B)); + EXPECT_EMPTY_REPORT(driver); + } + + tap_key(key_a); + + // Perform a rolled press from Repeat to B. + + ExpectProcessRecordUserCalledWith(true, KC_A, 1); + key_repeat.press(); // Press the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(true, KC_B, 0); + key_b.press(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_B); + + ExpectProcessRecordUserCalledWith(false, KC_A, 1); + key_repeat.release(); // Release the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + ExpectProcessRecordUserCalledWith(false, KC_B, 0); + key_b.release(); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + process_record_user_fun = process_record_user_default; + tap_key(key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests Repeat Key with a modifier, types "AltGr+C, Repeat, Repeat, C". +TEST_F(RepeatKey, RecallMods) { + TestDriver driver; + KeymapKey key_c(0, 0, 0, KC_C); + KeymapKey key_altgr(0, 1, 0, KC_RALT); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_c, key_altgr, key_repeat}); + + // Allow any number of reports with no keys or only KC_RALT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_RALT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "AltGr+C, AltGr+C, AltGr+C, C". + InSequence seq; + EXPECT_REPORT(driver, (KC_RALT, KC_C)); + EXPECT_REPORT(driver, (KC_RALT, KC_C)); + EXPECT_REPORT(driver, (KC_RALT, KC_C)); + EXPECT_REPORT(driver, (KC_C)); + } + + key_altgr.press(); + run_one_scan_loop(); + tap_key(key_c); + key_altgr.release(); + run_one_scan_loop(); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_C); + EXPECT_EQ(get_last_mods(), MOD_BIT(KC_RALT)); + + tap_keys(key_repeat, key_repeat, key_c); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests that Repeat Key stacks mods, types +// "Ctrl+Left, Repeat, Shift+Repeat, Shift+Repeat, Repeat, Left". +TEST_F(RepeatKey, StackMods) { + TestDriver driver; + KeymapKey key_left(0, 0, 0, KC_LEFT); + KeymapKey key_shift(0, 1, 0, KC_LSFT); + KeymapKey key_ctrl(0, 2, 0, KC_LCTL); + KeymapKey key_repeat(0, 3, 0, QK_REP); + set_keymap({key_left, key_shift, key_ctrl, key_repeat}); + + // Allow any number of reports with no keys or only mods. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LCTL), + KeyboardReport(KC_LSFT), + KeyboardReport(KC_LCTL, KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "Ctrl+Left, Ctrl+Shift+Left". + InSequence seq; + EXPECT_REPORT(driver, (KC_LCTL, KC_LEFT)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LEFT)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LSFT, KC_LEFT)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LSFT, KC_LEFT)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LEFT)); + EXPECT_REPORT(driver, (KC_LEFT)); + } + + key_ctrl.press(); + run_one_scan_loop(); + tap_key(key_left); + run_one_scan_loop(); + key_ctrl.release(); + run_one_scan_loop(); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_LEFT); + EXPECT_EQ(get_last_mods(), MOD_BIT(KC_LCTL)); + + tap_key(key_repeat); + + key_shift.press(); + run_one_scan_loop(); + tap_keys(key_repeat, key_repeat); + key_shift.release(); + run_one_scan_loop(); + + EXPECT_EQ(get_last_mods(), MOD_BIT(KC_LCTL)); + + tap_keys(key_repeat, key_left); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Types: "S(KC_1), Repeat, Ctrl+Repeat, Ctrl+Repeat, Repeat, KC_2". +TEST_F(RepeatKey, ShiftedKeycode) { + TestDriver driver; + KeymapKey key_exlm(0, 0, 0, S(KC_1)); + KeymapKey key_2(0, 1, 0, KC_2); + KeymapKey key_ctrl(0, 2, 0, KC_LCTL); + KeymapKey key_repeat(0, 3, 0, QK_REP); + set_keymap({key_exlm, key_2, key_ctrl, key_repeat}); + + // Allow any number of reports with no keys or only mods. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LCTL), + KeyboardReport(KC_LSFT), + KeyboardReport(KC_LCTL, KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "Shift+1, Shift+1, Ctrl+Shift+1, Ctrl+Shift+1, Shift+1, 2". + InSequence seq; + EXPECT_REPORT(driver, (KC_LSFT, KC_1)); + EXPECT_REPORT(driver, (KC_LSFT, KC_1)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LSFT, KC_1)); + EXPECT_REPORT(driver, (KC_LCTL, KC_LSFT, KC_1)); + EXPECT_REPORT(driver, (KC_LSFT, KC_1)); + EXPECT_REPORT(driver, (KC_2)); + } + + tap_key(key_exlm); + + EXPECT_KEYCODE_EQ(get_last_keycode(), S(KC_1)); + + tap_key(key_repeat); + + key_ctrl.press(); + run_one_scan_loop(); + tap_keys(key_repeat, key_repeat); + key_ctrl.release(); + run_one_scan_loop(); + + tap_keys(key_repeat, key_2); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests Repeat Key with a one-shot Shift, types +// "A, OSM(MOD_LSFT), Repeat, Repeat". +TEST_F(RepeatKey, WithOneShotShift) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_oneshot_shift(0, 1, 0, OSM(MOD_LSFT)); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_a, key_oneshot_shift, key_repeat}); + + // Allow any number of reports with no keys or only KC_RALT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + ExpectString(driver, "aAa"); + + tap_keys(key_a, key_oneshot_shift, key_repeat, key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests Repeat Key with a mod-tap key, types +// "A, Repeat, Repeat, A(down), Repeat, Repeat, A(up), Repeat". +TEST_F(RepeatKey, ModTap) { + TestDriver driver; + KeymapKey key_mt_a(0, 0, 0, LSFT_T(KC_A)); + KeymapKey key_repeat(0, 1, 0, QK_REP); + set_keymap({key_mt_a, key_repeat}); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + ExpectString(driver, "aaaAAa"); + + tap_key(key_mt_a); + + EXPECT_KEYCODE_EQ(get_last_keycode(), LSFT_T(KC_A)); + + tap_keys(key_repeat, key_repeat); + key_mt_a.press(); + run_one_scan_loop(); + tap_key(key_repeat, TAPPING_TERM + 1); + tap_key(key_repeat); + key_mt_a.release(); + run_one_scan_loop(); + tap_key(key_repeat); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests with Auto Shift. When repeating an autoshiftable key, it does not +// matter how long the original key was held, rather, quickly tapping vs. +// long-pressing the Repeat Key determines whether the shifted key is repeated. +// +// The test does the following, which should produce "aaABbB": +// 1. Tap KC_A quickly. +// 2. Tap Repeat Key quickly. +// 3. Long-press Repeat Key. +// 4. Long-press KC_B. +// 5. Tap Repeat Key quickly. +// 6. Long-press Repeat Key. +TEST_F(RepeatKey, AutoShift) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_b(0, 1, 0, KC_B); + KeymapKey key_repeat(0, 2, 0, QK_REP); + set_keymap({key_a, key_b, key_repeat}); + + autoshift_enable(); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + ExpectString(driver, "aaABbB"); + + tap_key(key_a); // Tap A quickly. + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_A); + EXPECT_EQ(get_last_mods(), 0); + + tap_key(key_repeat); + tap_key(key_repeat, AUTO_SHIFT_TIMEOUT + 1); + + tap_key(key_b, AUTO_SHIFT_TIMEOUT + 1); // Long press B. + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_B); + EXPECT_EQ(get_last_mods(), 0); + + tap_key(key_repeat); + tap_key(key_repeat, AUTO_SHIFT_TIMEOUT + 1); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Defines `remember_last_key_user()` to forget the Shift mod and types: +// "Ctrl+A, Repeat, Shift+A, Repeat, Shift+Repeat". +TEST_F(RepeatKey, FilterRememberedMods) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_ctrl(0, 1, 0, KC_LCTL); + KeymapKey key_shift(0, 2, 0, KC_LSFT); + KeymapKey key_repeat(0, 3, 0, QK_REP); + set_keymap({key_a, key_ctrl, key_shift, key_repeat}); + + remember_last_key_user_fun = [](uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + *remembered_mods &= ~MOD_MASK_SHIFT; + return true; + }; + + // Allow any number of reports with no keys or only mods. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LCTL), + KeyboardReport(KC_LSFT), + KeyboardReport(KC_LCTL, KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + + { // Expect: "Ctrl+A, Ctrl+A, Shift+A, A, Shift+A". + InSequence seq; + EXPECT_REPORT(driver, (KC_LCTL, KC_A)); + EXPECT_REPORT(driver, (KC_LCTL, KC_A)); + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + EXPECT_REPORT(driver, (KC_A)); + EXPECT_REPORT(driver, (KC_LSFT, KC_A)); + } + + key_ctrl.press(); + run_one_scan_loop(); + tap_key(key_a); + + EXPECT_EQ(get_last_mods(), MOD_BIT(KC_LCTL)); + + key_ctrl.release(); + run_one_scan_loop(); + + tap_key(key_repeat); + key_shift.press(); + run_one_scan_loop(); + tap_key(key_a); + + EXPECT_EQ(get_last_mods(), 0); // Shift should be forgotten. + + key_shift.release(); + run_one_scan_loop(); + + tap_key(key_repeat); + + key_shift.press(); + run_one_scan_loop(); + tap_key(key_repeat); + key_shift.release(); + run_one_scan_loop(); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests set_last_keycode() and set_last_mods(). +TEST_F(RepeatKey, SetRepeatKeyKeycode) { + TestDriver driver; + KeymapKey key_repeat(0, 0, 0, QK_REP); + set_keymap({key_repeat}); + + // Allow any number of reports with no keys or only KC_LSFT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + // clang-format on + ExpectString(driver, "aaBB"); + + set_last_keycode(KC_A); + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_A); + + for (int n = 1; n <= 2; ++n) { // Tap the Repeat Key twice. + // When Repeat is pressed, process_record_user() should be called with a + // press event with keycode == KC_A and repeat_key_count() == n. + ExpectProcessRecordUserCalledWith(true, KC_A, n); + key_repeat.press(); // Press the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + // Expect the corresponding release event. + ExpectProcessRecordUserCalledWith(false, KC_A, n); + key_repeat.release(); // Release the Repeat Key. + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + } + + process_record_user_fun = process_record_user_default; + set_last_keycode(KC_B); + set_last_mods(MOD_BIT(KC_LSFT)); + + tap_keys(key_repeat, key_repeat); + + set_last_keycode(KC_NO); + tap_keys(key_repeat, key_repeat); // Has no effect. + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +// Tests the `repeat_key_invoke()` function. +TEST_F(RepeatKey, RepeatKeyInvoke) { + TestDriver driver; + KeymapKey key_s(0, 0, 0, KC_S); + set_keymap({key_s}); + + // Allow any number of empty reports. + EXPECT_EMPTY_REPORT(driver).Times(AnyNumber()); + ExpectString(driver, "ss"); + + tap_key(key_s); + + EXPECT_KEYCODE_EQ(get_last_keycode(), KC_S); + + // Calling repeat_key_invoke() should result in process_record_user() + // getting a press event with keycode KC_S. + ExpectProcessRecordUserCalledWith(true, KC_S, 1); + keyevent_t event; + event.key = {0, 0}; + event.pressed = true; + event.time = timer_read(); + event.type = KEY_EVENT; + repeat_key_invoke(&event); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + // Make the release event. + ExpectProcessRecordUserCalledWith(false, KC_S, 1); + event.pressed = false; + event.time = timer_read(); + repeat_key_invoke(&event); + run_one_scan_loop(); + EXPECT_TRUE(process_record_user_was_called_); + + testing::Mock::VerifyAndClearExpectations(&driver); +} + +} // namespace diff --git a/tests/tap_dance/examples.c b/tests/tap_dance/examples.c index af7438820954..13086bbb4bba 100644 --- a/tests/tap_dance/examples.c +++ b/tests/tap_dance/examples.c @@ -187,13 +187,35 @@ void x_reset(tap_dance_state_t *state, void *user_data) { xtap_state.state = TD_NONE; } +static void release_press(tap_dance_state_t *state, void *user_data) { + tap_code16(KC_P); +} + +static void release_unpress(tap_dance_state_t *state, void *user_data) { + tap_code16(KC_U); +} + +static void release_unpress_mark_finished(tap_dance_state_t *state, void *user_data) { + tap_code16(KC_U); + state->finished = true; +} + +static void release_finished(tap_dance_state_t *state, void *user_data) { + tap_code16(KC_F); +} + +static void release_reset(tap_dance_state_t *state, void *user_data) { + tap_code16(KC_R); +} tap_dance_action_t tap_dance_actions[] = { [TD_ESC_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_CAPS), [CT_EGG] = ACTION_TAP_DANCE_FN(dance_egg), [CT_FLSH] = ACTION_TAP_DANCE_FN_ADVANCED(dance_flsh_each, dance_flsh_finished, dance_flsh_reset), [CT_CLN] = ACTION_TAP_DANCE_TAP_HOLD(KC_COLN, KC_SCLN), - [X_CTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, x_finished, x_reset) + [X_CTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, x_finished, x_reset), + [TD_RELEASE] = ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(release_press, release_unpress, release_finished, release_reset), + [TD_RELEASE_AND_FINISH] = ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(release_press, release_unpress_mark_finished, release_finished, release_reset), }; // clang-format on diff --git a/tests/tap_dance/examples.h b/tests/tap_dance/examples.h index 2622af6b2f4a..6118188dd185 100644 --- a/tests/tap_dance/examples.h +++ b/tests/tap_dance/examples.h @@ -26,6 +26,8 @@ enum { CT_FLSH, CT_CLN, X_CTL, + TD_RELEASE, + TD_RELEASE_AND_FINISH, }; #ifdef __cplusplus diff --git a/tests/tap_dance/test_examples.cpp b/tests/tap_dance/test_examples.cpp index 6dabc45513af..7858dab92b9d 100644 --- a/tests/tap_dance/test_examples.cpp +++ b/tests/tap_dance/test_examples.cpp @@ -316,3 +316,119 @@ TEST_F(TapDance, QuadFunction) { EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); } + +TEST_F(TapDance, DanceFnAdvancedWithRelease) { + TestDriver driver; + InSequence s; + auto key_rls = KeymapKey(0, 1, 0, TD(TD_RELEASE)); + + set_keymap({key_rls}); + + /* Single press and unpress */ + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + EXPECT_REPORT(driver, (KC_F)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_R)); + EXPECT_EMPTY_REPORT(driver); + idle_for(TAPPING_TERM); + run_one_scan_loop(); + + /* Double press and unpress */ + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + EXPECT_REPORT(driver, (KC_F)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_R)); + EXPECT_EMPTY_REPORT(driver); + idle_for(TAPPING_TERM); + run_one_scan_loop(); + + /* Unpress after tapping term has elapsed (key is registered as held) */ + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + EXPECT_REPORT(driver, (KC_F)); + EXPECT_EMPTY_REPORT(driver); + idle_for(TAPPING_TERM); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_R)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); +} + +TEST_F(TapDance, DanceFnAdvancedWithReleaseAndFinish) { + TestDriver driver; + InSequence s; + auto key_rls = KeymapKey(0, 1, 0, TD(TD_RELEASE_AND_FINISH)); + + set_keymap({key_rls}); + + /* Single press and unpress */ + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_R)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + // Verify the finished and/or reset functions aren't called + // after the tapping term elapses + idle_for(TAPPING_TERM); + run_one_scan_loop(); + + /* Unpress after tapping term has elapsed (key is registered as held) */ + key_rls.press(); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); + + EXPECT_REPORT(driver, (KC_F)); + EXPECT_EMPTY_REPORT(driver); + idle_for(TAPPING_TERM); + run_one_scan_loop(); + + key_rls.release(); + EXPECT_REPORT(driver, (KC_U)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_R)); + EXPECT_EMPTY_REPORT(driver); + run_one_scan_loop(); +} diff --git a/tests/tap_hold_configurations/default_mod_tap/config.h b/tests/tap_hold_configurations/default_mod_tap/config.h index f22448845e62..6d872dd57b5e 100644 --- a/tests/tap_hold_configurations/default_mod_tap/config.h +++ b/tests/tap_hold_configurations/default_mod_tap/config.h @@ -17,5 +17,3 @@ #pragma once #include "test_common.h" - -#define IGNORE_MOD_TAP_INTERRUPT diff --git a/tests/tap_hold_configurations/quick_tap/test_quick_tap.cpp b/tests/tap_hold_configurations/quick_tap/test_quick_tap.cpp index 8ec6ea62a3ea..dda58463fb9e 100644 --- a/tests/tap_hold_configurations/quick_tap/test_quick_tap.cpp +++ b/tests/tap_hold_configurations/quick_tap/test_quick_tap.cpp @@ -27,86 +27,6 @@ using testing::InSequence; class QuickTap : public TestFixture {}; -TEST_F(QuickTap, tap_regular_key_while_mod_tap_key_is_held) { - TestDriver driver; - InSequence s; - auto mod_tap_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); - auto regular_key = KeymapKey(0, 2, 0, KC_A); - - set_keymap({mod_tap_key, regular_key}); - - /* Press mod-tap key. */ - EXPECT_NO_REPORT(driver); - mod_tap_key.press(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Press regular key. */ - EXPECT_NO_REPORT(driver); - regular_key.press(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Release regular key. */ - EXPECT_NO_REPORT(driver); - regular_key.release(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Release mod-tap key. */ - EXPECT_REPORT(driver, (KC_LSFT)); - mod_tap_key.release(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Idle for tapping term of mod tap hold key. */ - EXPECT_REPORT(driver, (KC_LSFT, KC_A)); - EXPECT_REPORT(driver, (KC_LSFT)); - EXPECT_EMPTY_REPORT(driver); - idle_for(TAPPING_TERM - 3); - VERIFY_AND_CLEAR(driver); -} - -TEST_F(QuickTap, tap_mod_tap_key_while_mod_tap_key_is_held) { - TestDriver driver; - InSequence s; - auto first_mod_tap_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); - auto second_mod_tap_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); - - set_keymap({first_mod_tap_key, second_mod_tap_key}); - - /* Press first mod-tap key */ - EXPECT_NO_REPORT(driver); - first_mod_tap_key.press(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Press second mod-tap key */ - EXPECT_NO_REPORT(driver); - second_mod_tap_key.press(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Release second tap-hold key */ - EXPECT_NO_REPORT(driver); - second_mod_tap_key.release(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Release first mod-tap key */ - EXPECT_REPORT(driver, (KC_LSFT)); - first_mod_tap_key.release(); - run_one_scan_loop(); - VERIFY_AND_CLEAR(driver); - - /* Idle for tapping term of first mod-tap key. */ - EXPECT_REPORT(driver, (KC_LSFT, KC_A)); - EXPECT_REPORT(driver, (KC_LSFT)); - EXPECT_EMPTY_REPORT(driver); - idle_for(TAPPING_TERM - 3); - VERIFY_AND_CLEAR(driver); -} - TEST_F(QuickTap, tap_regular_key_while_layer_tap_key_is_held) { TestDriver driver; InSequence s; diff --git a/tests/tap_hold_configurations/retro_tapping/config.h b/tests/tap_hold_configurations/retro_tapping/config.h index 4b38f2644b83..cc9f1624770e 100644 --- a/tests/tap_hold_configurations/retro_tapping/config.h +++ b/tests/tap_hold_configurations/retro_tapping/config.h @@ -18,4 +18,7 @@ #include "test_common.h" -#define RETRO_TAPPING \ No newline at end of file +#define RETRO_TAPPING +#define DUMMY_MOD_NEUTRALIZER_KEYCODE KC_RIGHT_CTRL +#define MODS_TO_NEUTRALIZE \ + { MOD_BIT(KC_LEFT_GUI) } diff --git a/tests/tap_hold_configurations/retro_tapping/test_neutralization.cpp b/tests/tap_hold_configurations/retro_tapping/test_neutralization.cpp new file mode 100644 index 000000000000..10d675a3b188 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test_neutralization.cpp @@ -0,0 +1,201 @@ +/* Copyright 2023 Vladislav Kucheriavykh + * + * 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 . + */ + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "action_tapping.h" +#include "test_keymap_key.hpp" + +using testing::_; +using testing::InSequence; + +class RetroTapNeutralization : public TestFixture {}; + +TEST_F(RetroTapNeutralization, neutralize_retro_tapped_left_gui_mod_tap) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 7, 0, LGUI_T(KC_P)); + + set_keymap({mod_tap_hold_key}); + + EXPECT_NO_REPORT(driver); + mod_tap_hold_key.press(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (KC_LGUI)); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (DUMMY_MOD_NEUTRALIZER_KEYCODE, KC_LGUI)); + EXPECT_REPORT(driver, (KC_LGUI)); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(RetroTapNeutralization, do_not_neutralize_retro_tapped_left_shift_mod_tap) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 7, 0, LSFT_T(KC_P)); + + set_keymap({mod_tap_hold_key}); + + EXPECT_NO_REPORT(driver); + mod_tap_hold_key.press(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(RetroTapNeutralization, do_not_neutralize_retro_tapped_right_gui_mod_tap) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 7, 0, RGUI_T(KC_P)); + + set_keymap({mod_tap_hold_key}); + + EXPECT_NO_REPORT(driver); + mod_tap_hold_key.press(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (KC_RGUI)); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(RetroTapNeutralization, do_not_neutralize_retro_tapped_left_gui_shift_mod_tap) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 7, 0, MT(MOD_LGUI | MOD_LSFT, KC_P)); + + set_keymap({mod_tap_hold_key}); + + EXPECT_NO_REPORT(driver); + mod_tap_hold_key.press(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + EXPECT_REPORT(driver, (KC_LSFT, KC_LGUI)); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(RetroTapNeutralization, do_not_neutralize_roll_of_regular_and_mod_tap_keys) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 1, 0, LGUI_T(KC_P)); + auto regular_key = KeymapKey(0, 2, 0, KC_A); + + set_keymap({mod_tap_hold_key, regular_key}); + + /* Press mod-tap-hold key. */ + EXPECT_NO_REPORT(driver); + mod_tap_hold_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key. */ + EXPECT_NO_REPORT(driver); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key. */ + EXPECT_NO_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release mod-tap-hold key. */ + EXPECT_REPORT(driver, (KC_P)); + EXPECT_REPORT(driver, (KC_P, KC_A)); + EXPECT_REPORT(driver, (KC_P)); + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Idle for tapping term of mod tap hold key. */ + idle_for(TAPPING_TERM - 3); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(RetroTapNeutralization, do_not_neutralize_tap_regular_key_while_mod_tap_is_held) { + TestDriver driver; + InSequence s; + auto mod_tap_hold_key = KeymapKey(0, 1, 0, LGUI_T(KC_P)); + auto regular_key = KeymapKey(0, 2, 0, KC_A); + + set_keymap({mod_tap_hold_key, regular_key}); + + /* Press and hold mod-tap key. */ + EXPECT_REPORT(driver, (KC_LEFT_GUI)); + mod_tap_hold_key.press(); + idle_for(TAPPING_TERM + 1); + VERIFY_AND_CLEAR(driver); + + /* Press regular key. */ + EXPECT_REPORT(driver, (KC_A, KC_LEFT_GUI)); + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key. */ + EXPECT_REPORT(driver, (KC_LEFT_GUI)); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release mod-tap-hold key. */ + EXPECT_EMPTY_REPORT(driver); + mod_tap_hold_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Idle for tapping term of mod tap hold key. */ + idle_for(TAPPING_TERM - 3); + VERIFY_AND_CLEAR(driver); +} diff --git a/tests/test_common/keycode_table.cpp b/tests/test_common/keycode_table.cpp index d21630c01be1..9ed80cdbcf66 100644 --- a/tests/test_common/keycode_table.cpp +++ b/tests/test_common/keycode_table.cpp @@ -663,6 +663,8 @@ std::map KEYCODE_ID_TABLE = { {QK_AUTOCORRECT_TOGGLE, "QK_AUTOCORRECT_TOGGLE"}, {QK_TRI_LAYER_LOWER, "QK_TRI_LAYER_LOWER"}, {QK_TRI_LAYER_UPPER, "QK_TRI_LAYER_UPPER"}, + {QK_REPEAT_KEY, "QK_REPEAT_KEY"}, + {QK_ALT_REPEAT_KEY, "QK_ALT_REPEAT_KEY"}, {QK_KB_0, "QK_KB_0"}, {QK_KB_1, "QK_KB_1"}, {QK_KB_2, "QK_KB_2"}, diff --git a/tests/test_common/keycode_util.hpp b/tests/test_common/keycode_util.hpp index d5a520d4b2d5..3143ab364edc 100644 --- a/tests/test_common/keycode_util.hpp +++ b/tests/test_common/keycode_util.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include std::string get_keycode_identifier_or_default(uint16_t keycode); diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index f1c52cb7b62b..0495da8205ac 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -60,7 +60,10 @@ void TestDriver::send_extra(report_extra_t* report) { namespace internal { void expect_unicode_code_point(TestDriver& driver, uint32_t code_point) { testing::InSequence seq; - EXPECT_REPORT(driver, (KC_LCTL, KC_LSFT, KC_U)); + EXPECT_REPORT(driver, (KC_LEFT_CTRL, KC_LEFT_SHIFT)); + EXPECT_REPORT(driver, (KC_LEFT_CTRL, KC_LEFT_SHIFT, KC_U)); + EXPECT_REPORT(driver, (KC_LEFT_CTRL, KC_LEFT_SHIFT)); + EXPECT_EMPTY_REPORT(driver); bool print_zero = false; for (int i = 7; i >= 0; --i) { @@ -71,10 +74,12 @@ void expect_unicode_code_point(TestDriver& driver, uint32_t code_point) { const uint8_t digit = (code_point >> (i * 4)) & 0xf; if (digit || print_zero) { EXPECT_REPORT(driver, (hex_digit_to_keycode(digit))); + EXPECT_EMPTY_REPORT(driver); print_zero = true; } } - EXPECT_REPORT(driver, (KC_SPC)); + EXPECT_REPORT(driver, (KC_SPACE)); + EXPECT_EMPTY_REPORT(driver); } } // namespace internal diff --git a/tests/test_common/test_driver.hpp b/tests/test_common/test_driver.hpp index 8d09e448405a..d8a6885d0ff8 100644 --- a/tests/test_common/test_driver.hpp +++ b/tests/test_common/test_driver.hpp @@ -20,6 +20,7 @@ #include #include "host.h" #include "keyboard_report_util.hpp" +#include "keycode_util.hpp" #include "test_logger.hpp" class TestDriver { @@ -98,6 +99,17 @@ class TestDriver { */ #define EXPECT_NO_REPORT(driver) EXPECT_ANY_REPORT(driver).Times(0) +/** @brief Tests whether keycode `actual` is equal to `expected`. */ +#define EXPECT_KEYCODE_EQ(actual, expected) EXPECT_THAT((actual), KeycodeEq((expected))) + +MATCHER_P(KeycodeEq, expected_keycode, "is equal to " + testing::PrintToString(expected_keycode) + ", keycode " + get_keycode_identifier_or_default(expected_keycode)) { + if (arg == expected_keycode) { + return true; + } + *result_listener << "keycode " << get_keycode_identifier_or_default(arg); + return false; +} + /** * @brief Verify and clear all gmock expectations that have been setup until * this point. diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 76daa625ad8e..72763d0bc08c 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -22,7 +22,6 @@ extern "C" { #include "debug.h" #include "eeconfig.h" #include "keyboard.h" -#include "keymap.h" void set_time(uint32_t t); void advance_time(uint32_t ms); diff --git a/tests/unicode/config.h b/tests/unicode/config.h new file mode 100644 index 000000000000..16f95f7f8db7 --- /dev/null +++ b/tests/unicode/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define UNICODE_SELECTED_MODES UNICODE_MODE_LINUX, UNICODE_MODE_MACOS diff --git a/tests/unicode/test.mk b/tests/unicode/test.mk new file mode 100644 index 000000000000..1afc79be559c --- /dev/null +++ b/tests/unicode/test.mk @@ -0,0 +1,5 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +UNICODE_COMMON = yes diff --git a/tests/unicode/test_unicode.cpp b/tests/unicode/test_unicode.cpp new file mode 100644 index 000000000000..a8500e3ba1dc --- /dev/null +++ b/tests/unicode/test_unicode.cpp @@ -0,0 +1,86 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class Unicode : public TestFixture {}; + +TEST_F(Unicode, sends_bmp_unicode_sequence) { + TestDriver driver; + + set_unicode_input_mode(UNICODE_MODE_LINUX); + + EXPECT_UNICODE(driver, 0x03A8); // Ψ + register_unicode(0x03A8); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(Unicode, sends_smp_unicode_sequence) { + TestDriver driver; + + set_unicode_input_mode(UNICODE_MODE_LINUX); + + EXPECT_UNICODE(driver, 0x1F9D9); // 🧙 + register_unicode(0x1F9D9); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(Unicode, sends_surrogate_pair_for_macos) { + TestDriver driver; + + set_unicode_input_mode(UNICODE_MODE_MACOS); + + // EXPECT_UNICODE() assumes Linux input mode + { + testing::InSequence s; + + // Alt+D83EDDD9 🧙 + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_D, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_8, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_3, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_E, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_D, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_D, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_D, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_9, KC_LEFT_ALT)); + EXPECT_REPORT(driver, (KC_LEFT_ALT)); + EXPECT_EMPTY_REPORT(driver); + } + + register_unicode(0x1F9D9); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(Unicode, sends_unicode_string) { + TestDriver driver; + + set_unicode_input_mode(UNICODE_MODE_LINUX); + + { + testing::InSequence s; + + EXPECT_UNICODE(driver, 0xFF31); + EXPECT_UNICODE(driver, 0xFF2D); + EXPECT_UNICODE(driver, 0xFF2B); + EXPECT_UNICODE(driver, 0xFF01); + } + send_unicode_string("QMK!"); + + VERIFY_AND_CLEAR(driver); +} diff --git a/tests/unicode/unicode_basic/config.h b/tests/unicode/unicode_basic/config.h new file mode 100644 index 000000000000..16f95f7f8db7 --- /dev/null +++ b/tests/unicode/unicode_basic/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define UNICODE_SELECTED_MODES UNICODE_MODE_LINUX, UNICODE_MODE_MACOS diff --git a/tests/unicode/unicode_basic/test.mk b/tests/unicode/unicode_basic/test.mk new file mode 100644 index 000000000000..f53051dce679 --- /dev/null +++ b/tests/unicode/unicode_basic/test.mk @@ -0,0 +1,5 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +UNICODE_ENABLE = yes diff --git a/tests/unicode/unicode_basic/test_unicode_basic.cpp b/tests/unicode/unicode_basic/test_unicode_basic.cpp new file mode 100644 index 000000000000..598b57277f3d --- /dev/null +++ b/tests/unicode/unicode_basic/test_unicode_basic.cpp @@ -0,0 +1,26 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class UnicodeBasic : public TestFixture {}; + +TEST_F(UnicodeBasic, sends_unicode_sequence) { + TestDriver driver; + + set_unicode_input_mode(UNICODE_MODE_LINUX); + + auto key_uc = KeymapKey(0, 0, 0, UC(0x03A8)); // Ψ + + set_keymap({key_uc}); + + EXPECT_UNICODE(driver, 0x03A8); + tap_key(key_uc); + + VERIFY_AND_CLEAR(driver); +} diff --git a/tests/unicode/unicode_map/config.h b/tests/unicode/unicode_map/config.h new file mode 100644 index 000000000000..0d86922f0da7 --- /dev/null +++ b/tests/unicode/unicode_map/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define UNICODE_SELECTED_MODES UNICODE_MODE_LINUX diff --git a/tests/unicode/unicode_map/test.mk b/tests/unicode/unicode_map/test.mk new file mode 100644 index 000000000000..e6d003479988 --- /dev/null +++ b/tests/unicode/unicode_map/test.mk @@ -0,0 +1,5 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +UNICODEMAP_ENABLE = yes diff --git a/tests/unicode/unicode_map/test_unicode_map.cpp b/tests/unicode/unicode_map/test_unicode_map.cpp new file mode 100644 index 000000000000..cacd8f3c757c --- /dev/null +++ b/tests/unicode/unicode_map/test_unicode_map.cpp @@ -0,0 +1,54 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +const uint32_t PROGMEM unicode_map[] = { + 0x03A8, // Ψ + 0x2318 // ⌘ +}; + +class UnicodeMap : public TestFixture {}; + +TEST_F(UnicodeMap, sends_unicodemap_code_point_from_keycode) { + TestDriver driver; + + auto key_um = KeymapKey(0, 0, 0, UM(0)); + + set_keymap({key_um}); + + EXPECT_UNICODE(driver, 0x03A8); + tap_key(key_um); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(UnicodeMap, sends_unicodemap_pair_from_keycode) { + TestDriver driver; + + auto key_shift = KeymapKey(0, 0, 0, KC_LEFT_SHIFT); + auto key_up = KeymapKey(0, 1, 0, UP(0, 1)); + + set_keymap({key_shift, key_up}); + + EXPECT_UNICODE(driver, 0x03A8); + tap_key(key_up); + + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + key_shift.press(); + run_one_scan_loop(); + + EXPECT_UNICODE(driver, 0x2318); + tap_key(key_up); + + EXPECT_NO_REPORT(driver); + key_shift.release(); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} diff --git a/tests/unicode/unicode_ucis/config.h b/tests/unicode/unicode_ucis/config.h new file mode 100644 index 000000000000..0d86922f0da7 --- /dev/null +++ b/tests/unicode/unicode_ucis/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define UNICODE_SELECTED_MODES UNICODE_MODE_LINUX diff --git a/tests/unicode/unicode_ucis/test.mk b/tests/unicode/unicode_ucis/test.mk new file mode 100644 index 000000000000..d7ac6517583a --- /dev/null +++ b/tests/unicode/unicode_ucis/test.mk @@ -0,0 +1,5 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +UCIS_ENABLE = yes diff --git a/tests/unicode/unicode_ucis/test_unicode_ucis.cpp b/tests/unicode/unicode_ucis/test_unicode_ucis.cpp new file mode 100644 index 000000000000..acc6329f857b --- /dev/null +++ b/tests/unicode/unicode_ucis/test_unicode_ucis.cpp @@ -0,0 +1,221 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +// clang-format off +const ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE( + UCIS_SYM("qmk", 0x03A8) // Ψ +); +// clang-format on + +class UnicodeUCIS : public TestFixture {}; + +TEST_F(UnicodeUCIS, matches_sequence) { + TestDriver driver; + + auto key_q = KeymapKey(0, 0, 0, KC_Q); + auto key_m = KeymapKey(0, 1, 0, KC_M); + auto key_k = KeymapKey(0, 2, 0, KC_K); + auto key_enter = KeymapKey(0, 3, 0, KC_ENTER); + + set_keymap({key_q, key_m, key_k, key_enter}); + + EXPECT_UNICODE(driver, 0x2328); // ⌨ + ucis_start(); + + EXPECT_EQ(ucis_active(), true); + EXPECT_EQ(ucis_count(), 0); + + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_q); + EXPECT_EQ(ucis_count(), 1); + + EXPECT_REPORT(driver, (KC_M)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_m); + EXPECT_EQ(ucis_count(), 2); + + EXPECT_REPORT(driver, (KC_K)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_k); + EXPECT_EQ(ucis_count(), 3); + + EXPECT_REPORT(driver, (KC_BACKSPACE)).Times(4); + EXPECT_EMPTY_REPORT(driver).Times(4); + EXPECT_UNICODE(driver, 0x03A8); + tap_key(key_enter); + + EXPECT_EQ(ucis_active(), false); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(UnicodeUCIS, cancels_sequence) { + TestDriver driver; + + auto key_q = KeymapKey(0, 0, 0, KC_Q); + auto key_m = KeymapKey(0, 1, 0, KC_M); + auto key_k = KeymapKey(0, 2, 0, KC_K); + auto key_escape = KeymapKey(0, 3, 0, KC_ESCAPE); + + set_keymap({key_q, key_m, key_k, key_escape}); + + EXPECT_UNICODE(driver, 0x2328); // ⌨ + ucis_start(); + + EXPECT_EQ(ucis_active(), true); + EXPECT_EQ(ucis_count(), 0); + + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_q); + EXPECT_EQ(ucis_count(), 1); + + EXPECT_REPORT(driver, (KC_M)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_m); + EXPECT_EQ(ucis_count(), 2); + + EXPECT_REPORT(driver, (KC_K)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_k); + EXPECT_EQ(ucis_count(), 3); + + EXPECT_NO_REPORT(driver); + tap_key(key_escape); + + EXPECT_EQ(ucis_active(), false); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(UnicodeUCIS, matches_sequence_with_corrected_typo) { + TestDriver driver; + + auto key_q = KeymapKey(0, 0, 0, KC_Q); + auto key_m = KeymapKey(0, 1, 0, KC_M); + auto key_j = KeymapKey(0, 2, 0, KC_J); + auto key_k = KeymapKey(0, 3, 0, KC_K); + auto key_backspace = KeymapKey(0, 4, 0, KC_BACKSPACE); + auto key_enter = KeymapKey(0, 5, 0, KC_ENTER); + + set_keymap({key_q, key_m, key_j, key_k, key_backspace, key_enter}); + + EXPECT_UNICODE(driver, 0x2328); // ⌨ + ucis_start(); + + EXPECT_EQ(ucis_active(), true); + EXPECT_EQ(ucis_count(), 0); + + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_q); + EXPECT_EQ(ucis_count(), 1); + + EXPECT_REPORT(driver, (KC_M)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_m); + EXPECT_EQ(ucis_count(), 2); + + EXPECT_REPORT(driver, (KC_J)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_j); + EXPECT_EQ(ucis_count(), 3); + + EXPECT_REPORT(driver, (KC_BACKSPACE)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_backspace); + EXPECT_EQ(ucis_count(), 2); + + EXPECT_REPORT(driver, (KC_K)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_k); + EXPECT_EQ(ucis_count(), 3); + + EXPECT_REPORT(driver, (KC_BACKSPACE)).Times(4); + EXPECT_EMPTY_REPORT(driver).Times(4); + EXPECT_UNICODE(driver, 0x03A8); + tap_key(key_enter); + + EXPECT_EQ(ucis_active(), false); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(UnicodeUCIS, does_not_match_longer_sequence) { + TestDriver driver; + + auto key_q = KeymapKey(0, 0, 0, KC_Q); + auto key_m = KeymapKey(0, 1, 0, KC_M); + auto key_k = KeymapKey(0, 2, 0, KC_K); + auto key_enter = KeymapKey(0, 3, 0, KC_ENTER); + + set_keymap({key_q, key_m, key_k, key_enter}); + + EXPECT_UNICODE(driver, 0x2328); // ⌨ + ucis_start(); + + EXPECT_EQ(ucis_active(), true); + EXPECT_EQ(ucis_count(), 0); + + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_q); + EXPECT_EQ(ucis_count(), 1); + + EXPECT_REPORT(driver, (KC_M)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_m); + EXPECT_EQ(ucis_count(), 2); + + EXPECT_REPORT(driver, (KC_K)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_k); + EXPECT_EQ(ucis_count(), 3); + + EXPECT_REPORT(driver, (KC_K)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_k); + EXPECT_EQ(ucis_count(), 4); + + EXPECT_NO_REPORT(driver); + tap_key(key_enter); + + EXPECT_EQ(ucis_active(), false); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(UnicodeUCIS, does_not_match_shorter_sequence) { + TestDriver driver; + + auto key_q = KeymapKey(0, 0, 0, KC_Q); + auto key_enter = KeymapKey(0, 1, 0, KC_ENTER); + + set_keymap({key_q, key_enter}); + + EXPECT_UNICODE(driver, 0x2328); // ⌨ + ucis_start(); + + EXPECT_EQ(ucis_active(), true); + EXPECT_EQ(ucis_count(), 0); + + EXPECT_REPORT(driver, (KC_Q)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_q); + EXPECT_EQ(ucis_count(), 1); + + EXPECT_NO_REPORT(driver); + tap_key(key_enter); + + EXPECT_EQ(ucis_active(), false); + + VERIFY_AND_CLEAR(driver); +} diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index d3f15c458876..d159dacc55bf 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -1,4 +1,4 @@ -TMK_COMMON_SRC += \ +SRC += \ $(PROTOCOL_DIR)/host.c \ $(PROTOCOL_DIR)/report.c \ $(PROTOCOL_DIR)/usb_device_state.c \ @@ -7,7 +7,7 @@ TMK_COMMON_SRC += \ SHARED_EP_ENABLE = no MOUSE_SHARED_EP ?= yes ifeq ($(strip $(KEYBOARD_SHARED_EP)), yes) - TMK_COMMON_DEFS += -DKEYBOARD_SHARED_EP + OPT_DEFS += -DKEYBOARD_SHARED_EP SHARED_EP_ENABLE = yes # With the current usb_descriptor.c code, # you can't share kbd without sharing mouse; @@ -18,31 +18,31 @@ endif ifeq ($(strip $(MOUSE_ENABLE)), yes) OPT_DEFS += -DMOUSE_ENABLE ifeq ($(strip $(MOUSE_SHARED_EP)), yes) - TMK_COMMON_DEFS += -DMOUSE_SHARED_EP + OPT_DEFS += -DMOUSE_SHARED_EP SHARED_EP_ENABLE = yes endif endif ifeq ($(strip $(EXTRAKEY_ENABLE)), yes) - TMK_COMMON_DEFS += -DEXTRAKEY_ENABLE + OPT_DEFS += -DEXTRAKEY_ENABLE SHARED_EP_ENABLE = yes endif ifeq ($(strip $(PROGRAMMABLE_BUTTON_ENABLE)), yes) - TMK_COMMON_DEFS += -DPROGRAMMABLE_BUTTON_ENABLE + OPT_DEFS += -DPROGRAMMABLE_BUTTON_ENABLE SHARED_EP_ENABLE = yes endif ifeq ($(strip $(RAW_ENABLE)), yes) - TMK_COMMON_DEFS += -DRAW_ENABLE + OPT_DEFS += -DRAW_ENABLE endif ifeq ($(strip $(CONSOLE_ENABLE)), yes) - TMK_COMMON_DEFS += -DCONSOLE_ENABLE + OPT_DEFS += -DCONSOLE_ENABLE else # TODO: decouple this so other print backends can exist - TMK_COMMON_DEFS += -DNO_PRINT - TMK_COMMON_DEFS += -DNO_DEBUG + OPT_DEFS += -DNO_PRINT + OPT_DEFS += -DNO_DEBUG endif ifeq ($(strip $(NKRO_ENABLE)), yes) @@ -51,55 +51,55 @@ ifeq ($(strip $(NKRO_ENABLE)), yes) else ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) $(info NKRO is not currently supported with Bluetooth, and has been disabled.) else - TMK_COMMON_DEFS += -DNKRO_ENABLE + OPT_DEFS += -DNKRO_ENABLE SHARED_EP_ENABLE = yes endif endif ifeq ($(strip $(RING_BUFFERED_6KRO_REPORT_ENABLE)), yes) - TMK_COMMON_DEFS += -DRING_BUFFERED_6KRO_REPORT_ENABLE + OPT_DEFS += -DRING_BUFFERED_6KRO_REPORT_ENABLE endif ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes) - TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN + OPT_DEFS += -DNO_SUSPEND_POWER_DOWN endif ifeq ($(strip $(NO_USB_STARTUP_CHECK)), yes) - TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK + OPT_DEFS += -DNO_USB_STARTUP_CHECK endif ifeq ($(strip $(JOYSTICK_SHARED_EP)), yes) - TMK_COMMON_DEFS += -DJOYSTICK_SHARED_EP + OPT_DEFS += -DJOYSTICK_SHARED_EP SHARED_EP_ENABLE = yes endif ifeq ($(strip $(JOYSTICK_ENABLE)), yes) - TMK_COMMON_DEFS += -DJOYSTICK_ENABLE + OPT_DEFS += -DJOYSTICK_ENABLE ifeq ($(strip $(SHARED_EP_ENABLE)), yes) - TMK_COMMON_DEFS += -DJOYSTICK_SHARED_EP + OPT_DEFS += -DJOYSTICK_SHARED_EP SHARED_EP_ENABLE = yes endif endif ifeq ($(strip $(DIGITIZER_SHARED_EP)), yes) - TMK_COMMON_DEFS += -DDIGITIZER_SHARED_EP + OPT_DEFS += -DDIGITIZER_SHARED_EP SHARED_EP_ENABLE = yes endif ifeq ($(strip $(DIGITIZER_ENABLE)), yes) - TMK_COMMON_DEFS += -DDIGITIZER_ENABLE + OPT_DEFS += -DDIGITIZER_ENABLE ifeq ($(strip $(SHARED_EP_ENABLE)), yes) - TMK_COMMON_DEFS += -DDIGITIZER_SHARED_EP + OPT_DEFS += -DDIGITIZER_SHARED_EP SHARED_EP_ENABLE = yes endif endif ifeq ($(strip $(SHARED_EP_ENABLE)), yes) - TMK_COMMON_DEFS += -DSHARED_EP_ENABLE + OPT_DEFS += -DSHARED_EP_ENABLE endif ifeq ($(strip $(USB_HID_ENABLE)), yes) - include $(TMK_DIR)/protocol/usb_hid.mk + include $(TMK_DIR)/protocol/usb_hid/usb_hid.mk endif # Search Path diff --git a/tmk_core/protocol/arm_atsam.mk b/tmk_core/protocol/arm_atsam/arm_atsam.mk similarity index 100% rename from tmk_core/protocol/arm_atsam.mk rename to tmk_core/protocol/arm_atsam/arm_atsam.mk diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 1ccfbfb54a92..30817c17b643 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -21,9 +21,9 @@ along with this program. If not, see . #include "report.h" #include "host.h" #include "host_driver.h" +#include "suspend.h" #include "keycode_config.h" #include -#include "quantum.h" // From protocol directory #include "arm_atsam_protocol.h" diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix.c b/tmk_core/protocol/arm_atsam/md_rgb_matrix.c index 52fe86d297b4..0f316b256cfc 100644 --- a/tmk_core/protocol/arm_atsam/md_rgb_matrix.c +++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix.c @@ -23,6 +23,8 @@ along with this program. If not, see . # include "arm_atsam_protocol.h" # include "led.h" # include "rgb_matrix.h" +# include "eeprom.h" +# include "host.h" # include # include @@ -347,24 +349,24 @@ static void flush(void) { } void md_rgb_matrix_indicators_advanced(uint8_t led_min, uint8_t led_max) { - uint8_t kbled = keyboard_leds(); - if (kbled && rgb_matrix_config.enable) { + led_t led_state = host_keyboard_led_state(); + if (led_state.raw && rgb_matrix_config.enable) { for (uint8_t i = led_min; i < led_max; i++) { if ( # if USB_LED_NUM_LOCK_SCANCODE != 255 - (led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1 << USB_LED_NUM_LOCK))) || + (led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && led_state.num_lock) || # endif // NUM LOCK # if USB_LED_CAPS_LOCK_SCANCODE != 255 - (led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1 << USB_LED_CAPS_LOCK))) || + (led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && led_state.caps_lock) || # endif // CAPS LOCK # if USB_LED_SCROLL_LOCK_SCANCODE != 255 - (led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1 << USB_LED_SCROLL_LOCK))) || + (led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && led_state.scroll_lock) || # endif // SCROLL LOCK # if USB_LED_COMPOSE_SCANCODE != 255 - (led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1 << USB_LED_COMPOSE))) || + (led_map[i].scan == USB_LED_COMPOSE_SCANCODE && led_state.compose) || # endif // COMPOSE # if USB_LED_KANA_SCANCODE != 255 - (led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1 << USB_LED_KANA))) || + (led_map[i].scan == USB_LED_KANA_SCANCODE && led_state.kana) || # endif // KANA (0)) { if (rgb_matrix_get_flags() & LED_FLAG_INDICATOR) { diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix.h b/tmk_core/protocol/arm_atsam/md_rgb_matrix.h index f27da028a0c3..bb3312e8e749 100644 --- a/tmk_core/protocol/arm_atsam/md_rgb_matrix.h +++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix.h @@ -15,11 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _LED_MATRIX_H_ -#define _LED_MATRIX_H_ +#pragma once -#include "quantum.h" -#include "eeprom.h" +#include // From keyboard #include "config_led.h" @@ -200,5 +198,3 @@ void md_led_changed(void); #else extern uint8_t gcr_desired; #endif // USE_MASSDROP_CONFIGURATOR - -#endif //_LED_MATRIX_H_ diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c index dda8cb0c77c5..6b80c4e3792d 100644 --- a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c +++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c @@ -19,6 +19,7 @@ along with this program. If not, see . # ifdef USE_MASSDROP_CONFIGURATOR # include "md_rgb_matrix.h" +# include "util.h" // Teal <-> Salmon led_setup_t leds_teal_salmon[] = { diff --git a/tmk_core/protocol/arm_atsam/spi_master.h b/tmk_core/protocol/arm_atsam/spi_master.h index 26c55128be12..80678a57077e 100644 --- a/tmk_core/protocol/arm_atsam/spi_master.h +++ b/tmk_core/protocol/arm_atsam/spi_master.h @@ -16,7 +16,9 @@ #pragma once +#include #include +#include "gpio.h" typedef int16_t spi_status_t; diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index 619ce7b4b7b8..c5000e59f71d 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c @@ -49,6 +49,8 @@ #include "suspend.h" #include "wait.h" +#define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED (2U) + /* ------------------------- * TMK host driver defs * ------------------------- @@ -182,12 +184,12 @@ void protocol_pre_task(void) { #if !defined(NO_USB_STARTUP_CHECK) if (USB_DRIVER.state == USB_SUSPENDED) { - print("[s]"); + dprintln("suspending keyboard"); while (USB_DRIVER.state == USB_SUSPENDED) { /* Do this in the suspended state */ suspend_power_down(); // on AVR this deep sleeps for 15ms /* Remote wakeup */ - if (suspend_wakeup_condition()) { + if ((USB_DRIVER.status & USB_GETSTATUS_REMOTE_WAKEUP_ENABLED) && suspend_wakeup_condition()) { usbWakeupHost(&USB_DRIVER); restart_usb_driver(&USB_DRIVER); } diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios/chibios.mk similarity index 100% rename from tmk_core/protocol/chibios.mk rename to tmk_core/protocol/chibios/chibios.mk diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8996da84d4be..4d47b451a1d3 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -48,10 +48,10 @@ # include "sleep_led.h" #endif #include "suspend.h" +#include "wait.h" #include "usb_descriptor.h" #include "lufa.h" -#include "quantum.h" #include "usb_device_state.h" #include @@ -882,7 +882,7 @@ void protocol_post_init(void) { void protocol_pre_task(void) { #if !defined(NO_USB_STARTUP_CHECK) if (USB_DeviceState == DEVICE_STATE_Suspended) { - print("[s]"); + dprintln("suspending keyboard"); while (USB_DeviceState == DEVICE_STATE_Suspended) { suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa/lufa.mk similarity index 100% rename from tmk_core/protocol/lufa.mk rename to tmk_core/protocol/lufa/lufa.mk diff --git a/tmk_core/protocol/report.c b/tmk_core/protocol/report.c index 5755098c60f1..1ba3be4604e0 100644 --- a/tmk_core/protocol/report.c +++ b/tmk_core/protocol/report.c @@ -281,13 +281,21 @@ void clear_keys_from_report(report_keyboard_t* keyboard_report) { #ifdef MOUSE_ENABLE /** - * @brief Compares 2 mouse reports for difference and returns result + * @brief Compares 2 mouse reports for difference and returns result. Empty + * reports always evaluate as unchanged. * * @param[in] new_report report_mouse_t * @param[in] old_report report_mouse_t * @return bool result */ __attribute__((weak)) bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report) { - return memcmp(new_report, old_report, sizeof(report_mouse_t)); + // memcmp doesn't work here because of the `report_id` field when using + // shared mouse endpoint + bool changed = ((new_report->buttons != old_report->buttons) || +# ifdef MOUSE_EXTENDED_REPORT + (new_report->boot_x != 0 && new_report->boot_x != old_report->boot_x) || (new_report->boot_y != 0 && new_report->boot_y != old_report->boot_y) || +# endif + (new_report->x != 0 && new_report->x != old_report->x) || (new_report->y != 0 && new_report->y != old_report->y) || (new_report->h != 0 && new_report->h != old_report->h) || (new_report->v != 0 && new_report->v != old_report->v)); + return changed; } #endif diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 5ab9e3ff4f56..e215c9090043 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -93,6 +93,8 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = { HID_RI_USAGE_PAGE(8, 0x08), // LED HID_RI_USAGE_MINIMUM(8, 0x01), // Num Lock HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), HID_RI_REPORT_COUNT(8, 0x05), HID_RI_REPORT_SIZE(8, 0x01), HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), diff --git a/tmk_core/protocol/usb_hid/override_wiring.c b/tmk_core/protocol/usb_hid/override_wiring.c index adc6645f8eb4..40bb574d7d6c 100644 --- a/tmk_core/protocol/usb_hid/override_wiring.c +++ b/tmk_core/protocol/usb_hid/override_wiring.c @@ -2,7 +2,7 @@ * To keep Timer0 for common/timer.c override arduino/wiring.c. */ #define __DELAY_BACKWARD_COMPATIBLE__ -#include +#include "wait.h" #include "platforms/timer.h" @@ -16,11 +16,11 @@ unsigned long micros(void) } void delay(unsigned long ms) { - _delay_ms(ms); + wait_ms(ms); } void delayMicroseconds(unsigned int us) { - _delay_us(us); + wait_us(us); } void init(void) { diff --git a/tmk_core/protocol/usb_hid.mk b/tmk_core/protocol/usb_hid/usb_hid.mk similarity index 100% rename from tmk_core/protocol/usb_hid.mk rename to tmk_core/protocol/usb_hid/usb_hid.mk diff --git a/tmk_core/protocol/usb_util.c b/tmk_core/protocol/usb_util.c index 49aadedc2af9..3b3be4a76757 100644 --- a/tmk_core/protocol/usb_util.c +++ b/tmk_core/protocol/usb_util.c @@ -13,13 +13,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "quantum.h" + #include "usb_util.h" +#include "gpio.h" +#include "wait.h" __attribute__((weak)) void usb_disconnect(void) {} + __attribute__((weak)) bool usb_connected_state(void) { return true; } + __attribute__((weak)) bool usb_vbus_state(void) { #ifdef USB_VBUS_PIN setPinInput(USB_VBUS_PIN); diff --git a/tmk_core/protocol/usb_util.h b/tmk_core/protocol/usb_util.h index 13db9fbfbdfb..6f0e406378fd 100644 --- a/tmk_core/protocol/usb_util.h +++ b/tmk_core/protocol/usb_util.h @@ -13,10 +13,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #pragma once #include void usb_disconnect(void); + bool usb_connected_state(void); + bool usb_vbus_state(void); diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index b3eeff9e0169..d74f375f66af 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -435,6 +435,8 @@ const PROGMEM uchar keyboard_hid_report[] = { 0x05, 0x08, // Usage Page (LED) 0x19, 0x01, // Usage Minimum (Num Lock) 0x29, 0x05, // Usage Maximum (Kana) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) 0x95, 0x05, // Report Count (5) 0x75, 0x01, // Report Size (1) 0x91, 0x02, // Output (Data, Variable, Absolute) diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb/vusb.mk similarity index 100% rename from tmk_core/protocol/vusb.mk rename to tmk_core/protocol/vusb/vusb.mk diff --git a/util/ci/discord-results.py b/util/ci/discord-results.py new file mode 100755 index 000000000000..0c09a4213a1a --- /dev/null +++ b/util/ci/discord-results.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import argparse +import os +import re +import sys +from pathlib import Path +from discord_webhook import DiscordWebhook, DiscordEmbed + +parser = argparse.ArgumentParser(prog='discord-results.py', description='Sends a Discord webhook notification at the end of a CI run.') +parser.add_argument('-b', '--branch') +parser.add_argument('-k', '--keymap') +parser.add_argument('-u', '--url') +args = parser.parse_args() + +qmk_dir = Path(__file__).resolve().parents[2].resolve() + +keyboard_re = re.compile(r'CI Metadata: KEYBOARD=(.*)$', re.MULTILINE) +keymap_re = re.compile(r'CI Metadata: KEYMAP=(.*)$', re.MULTILINE) + +successful_builds = sum([len(list(qmk_dir.glob(f'*.{extension}'))) for extension in ['uf2', 'bin', 'hex']]) +failures = list(sorted([f.resolve() for f in (qmk_dir / '.build/').glob('failed.log.*')])) +failed_builds = [] +for f in failures: + with open(f) as fh: + data = fh.read() + kb = keyboard_re.search(data).group(1) + km = keymap_re.search(data).group(1) + failed_builds.append(f'{kb}:{km}') + +webhook = DiscordWebhook(url=os.getenv('DISCORD_WEBHOOK'), username="QMK GitHub CI") +if len(failed_builds) > 0: + failstr = '' + for f in failed_builds: + if len(failstr) >= 1800: + failstr += '<>' + break + failstr += f'{f}\n' + + embed = DiscordEmbed(title=f':infinity: CI Build Failure ({args.branch}, {args.keymap})', description=f'**{successful_builds}** builds succeeded, **{len(failed_builds)}** builds failed:```{failstr}```', color='ff9999') +else: + embed = DiscordEmbed(title=f':infinity: CI Build Success ({args.branch}, {args.keymap})', description=f'**{successful_builds}** builds succeeded.', color='99ff99') + +embed.add_embed_field(name='Build Target', value=f'[**{args.branch}**](https://github.com/qmk/qmk_firmware/tree/{args.branch}) / **{args.keymap}** keymap') +embed.add_embed_field(name='Workflow Run', value=f'[**Link**]({args.url})') +embed.set_timestamp() + +webhook.add_embed(embed) +webhook.execute() diff --git a/util/ci/generate_failure_markdown.sh b/util/ci/generate_failure_markdown.sh new file mode 100755 index 000000000000..ccb3eacb3501 --- /dev/null +++ b/util/ci/generate_failure_markdown.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +this_script="$(realpath "${BASH_SOURCE[0]}")" +script_dir="$(realpath "$(dirname "$this_script")")" +qmk_firmware_dir="$(realpath "$script_dir/../../")" + +dump_failure_info() { + local failure_file="$1" + local keyboard=$(cat "$failure_file" | grep 'CI Metadata: KEYBOARD=' | cut -d= -f2) + local keymap=$(cat "$failure_file" | grep 'CI Metadata: KEYMAP=' | cut -d= -f2) + echo "## ${keyboard}:${keymap}" + echo "\`\`\`" + cat "$failure_file" | sed -e $'s/\x1b\[[0-9;]*m//g' | grep -v "CI Metadata:" | grep -vP "(Entering|Leaving) directory" + echo "\`\`\`" +} + +for failure_file in $(find "$qmk_firmware_dir/.build" -name 'failed.log.*' | sort); do + dump_failure_info "$failure_file" +done + +exit 0 diff --git a/util/ci/requirements.txt b/util/ci/requirements.txt new file mode 100644 index 000000000000..3196568e1a7c --- /dev/null +++ b/util/ci/requirements.txt @@ -0,0 +1 @@ +discord-webhook diff --git a/util/docker_build.sh b/util/docker_build.sh index 8dce38732064..828b5751af53 100755 --- a/util/docker_build.sh +++ b/util/docker_build.sh @@ -81,5 +81,5 @@ fi -e ALT_GET_KEYBOARDS=true \ -e SKIP_GIT="$SKIP_GIT" \ -e MAKEFLAGS="$MAKEFLAGS" \ - qmkfm/qmk_cli \ + ghcr.io/qmk/qmk_cli \ make "$keyboard${keymap:+:$keymap}${target:+:$target}" diff --git a/util/docker_cmd.sh b/util/docker_cmd.sh index a179cef732ce..4a82890603b8 100755 --- a/util/docker_cmd.sh +++ b/util/docker_cmd.sh @@ -55,5 +55,5 @@ fi $uid_arg \ -w /qmk_firmware \ -v "$dir":/qmk_firmware \ - qmkfm/qmk_cli \ + ghcr.io/qmk/qmk_cli \ "$@" diff --git a/util/install/macos.sh b/util/install/macos.sh index 870b4bec9451..8890c5a3f08c 100755 --- a/util/install/macos.sh +++ b/util/install/macos.sh @@ -19,8 +19,13 @@ _qmk_install() { # https://github.com/qmk/homebrew-qmk brew install qmk/qmk/qmk + # Conflicts with new toolchain formulae + brew uninstall --ignore-dependencies arm-gcc-bin@8 >/dev/null 2>&1 + + # Keg-only, so need to be manually linked brew link --force avr-gcc@8 - brew link --force arm-gcc-bin@8 + brew link --force arm-none-eabi-binutils + brew link --force arm-none-eabi-gcc@8 python3 -m pip install -r $QMK_FIRMWARE_DIR/requirements.txt } diff --git a/util/uf2conv.py b/util/uf2conv.py index 7f5645414a2d..84271cee4f6f 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py @@ -8,6 +8,7 @@ import os.path import argparse import json +from time import sleep UF2_MAGIC_START0 = 0x0A324655 # "UF2\n" @@ -73,7 +74,7 @@ def convert_from_uf2(buf): assert False, "Non-word padding size at " + ptr while padding > 0: padding -= 4 - outp += b"\x00\x00\x00\x00" + outp.append(b"\x00\x00\x00\x00") if familyid == 0x0 or ((hd[2] & 0x2000) and familyid == hd[7]): outp.append(block[32 : 32 + datalen]) curraddr = newaddr + datalen @@ -150,10 +151,15 @@ def encode(self, blockno, numblocks): flags = 0x0 if familyid: flags |= 0x2000 + if devicetype: + flags |= 0x8000 hd = struct.pack("= 3 and words[1] == "2" and words[2] == "FAT": drives.append(words[0]) else: - rootpath = "/media" + searchpaths = ["/media"] if sys.platform == "darwin": - rootpath = "/Volumes" + searchpaths = ["/Volumes"] elif sys.platform == "linux": - tmp = rootpath + "/" + os.environ["USER"] - if os.path.isdir(tmp): - rootpath = tmp - tmp = "/run" + rootpath + "/" + os.environ["USER"] - if os.path.isdir(tmp): - rootpath = tmp - for d in os.listdir(rootpath): - drives.append(os.path.join(rootpath, d)) + searchpaths += ["/media/" + os.environ["USER"], '/run/media/' + os.environ["USER"]] + + for rootpath in searchpaths: + if os.path.isdir(rootpath): + for d in os.listdir(rootpath): + if os.path.isdir(rootpath): + drives.append(os.path.join(rootpath, d)) def has_info(d): @@ -276,23 +281,27 @@ def error(msg): parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.') parser.add_argument('input', metavar='INPUT', type=str, nargs='?', help='input file (HEX, BIN or UF2)') - parser.add_argument('-b' , '--base', dest='base', type=str, + parser.add_argument('-b', '--base', dest='base', type=str, default="0x2000", help='set base address of application for BIN format (default: 0x2000)') - parser.add_argument('-o' , '--output', metavar="FILE", dest='output', type=str, + parser.add_argument('-f', '--family', dest='family', type=str, + default="0x0", + help='specify familyID - number or name (default: 0x0)') + parser.add_argument('-t' , '--device-type', dest='devicetype', type=str, + help='specify deviceTypeID extension tag - number') + parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str, help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible') - parser.add_argument('-d' , '--device', dest="device_path", + parser.add_argument('-d', '--device', dest="device_path", help='select a device path to flash') - parser.add_argument('-l' , '--list', action='store_true', + parser.add_argument('-l', '--list', action='store_true', help='list connected devices') - parser.add_argument('-c' , '--convert', action='store_true', + parser.add_argument('-c', '--convert', action='store_true', help='do not flash, just convert') - parser.add_argument('-D' , '--deploy', action='store_true', + parser.add_argument('-D', '--deploy', action='store_true', help='just flash, do not convert') - parser.add_argument('-f' , '--family', dest='family', type=str, - default="0x0", - help='specify familyID - number or name (default: 0x0)') - parser.add_argument('-C' , '--carray', action='store_true', + parser.add_argument('-w', '--wait', action='store_true', + help='wait for device to flash') + parser.add_argument('-C', '--carray', action='store_true', help='convert binary file to a C array, not UF2') parser.add_argument('-i', '--info', action='store_true', help='display header information from UF2, do not convert') @@ -309,6 +318,9 @@ def error(msg): except ValueError: error("Family ID needs to be a number or one of: " + ", ".join(families.keys())) + global devicetype + devicetype = int(args.devicetype, 0) if args.devicetype else None + if args.list: list_drives() else: @@ -337,20 +349,23 @@ def error(msg): print("Converted to %s, output size: %d, start address: 0x%x" % (ext, len(outbuf), appstartaddr)) if args.convert or ext != "uf2": - drives = [] if args.output == None: args.output = "flash." + ext - else: - drives = get_drives() - if args.output: write_file(args.output, outbuf) - else: + if ext == "uf2" and not args.convert and not args.info: + drives = get_drives() if len(drives) == 0: - error("No drive to deploy.") - for d in drives: - print("Flashing %s (%s)" % (d, board_id(d))) - write_file(d + "/NEW.UF2", outbuf) + if args.wait: + print("Waiting for drive to deploy...") + while len(drives) == 0: + sleep(0.1) + drives = get_drives() + elif not args.output: + error("No drive to deploy.") + for d in drives: + print("Flashing %s (%s)" % (d, board_id(d))) + write_file(d + "/NEW.UF2", outbuf) if __name__ == "__main__": diff --git a/util/uf2families.json b/util/uf2families.json index fafae82a60a4..778af4421fc6 100644 --- a/util/uf2families.json +++ b/util/uf2families.json @@ -77,7 +77,7 @@ { "id": "0x57755a57", "short_name": "STM32F4", - "description": "ST STM32F401" + "description": "ST STM32F4xx" }, { "id": "0x5a18069b", @@ -188,5 +188,30 @@ "id": "0x9af03e33", "short_name": "GD32VF103", "description": "GigaDevice GD32VF103" + }, + { + "id": "0x4f6ace52", + "short_name": "CSK4", + "description": "LISTENAI CSK300x/400x" + }, + { + "id": "0x6e7348a8", + "short_name": "CSK6", + "description": "LISTENAI CSK60xx" + }, + { + "id": "0x11de784a", + "short_name": "M0SENSE", + "description": "M0SENSE BL702" + }, + { + "id": "0x4b684d71", + "short_name": "MaixPlay-U4", + "description": "Sipeed MaixPlay-U4(BL618)" + }, + { + "id": "0x9517422f", + "short_name": "RZA1LU", + "description": "Renesas RZ/A1LU (R7S7210xx)" } ] diff --git a/util/vagrant/Dockerfile b/util/vagrant/Dockerfile deleted file mode 100644 index 951d4fc40d7b..000000000000 --- a/util/vagrant/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM qmkfm/qmk_cli - -# Basic upgrades; install sudo and SSH. -RUN apt-get update && apt-get install --no-install-recommends -y \ - sudo \ - openssh-server \ - && rm -rf /var/lib/apt/lists/* -RUN mkdir /var/run/sshd -RUN sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config -RUN echo 'UseDNS no' >> /etc/ssh/sshd_config - -# Remove the policy file once we're finished installing software. -# This allows invoke-rc.d and friends to work as expected. -RUN rm /usr/sbin/policy-rc.d - -# Add the Vagrant user and necessary passwords. -RUN groupadd vagrant -RUN useradd -c "Vagrant" -g vagrant -d /home/vagrant -m -s /bin/bash vagrant -RUN echo 'root:vagrant' | chpasswd -RUN echo 'vagrant:vagrant' | chpasswd - -# Allow the vagrant user to use sudo without a password. -RUN echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant - -# Install Vagrant's insecure public key so provisioning and 'vagrant ssh' work. -RUN mkdir /home/vagrant/.ssh -ADD https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub /home/vagrant/.ssh/authorized_keys -RUN chmod 0600 /home/vagrant/.ssh/authorized_keys -RUN chown -R vagrant:vagrant /home/vagrant/.ssh -RUN chmod 0700 /home/vagrant/.ssh - -EXPOSE 22 -CMD ["/usr/sbin/sshd", "-D"] diff --git a/util/vagrant/readme.md b/util/vagrant/readme.md deleted file mode 100644 index a8396007ee09..000000000000 --- a/util/vagrant/readme.md +++ /dev/null @@ -1,12 +0,0 @@ -# QMK Vagrant Utilities - -## Dockerfile -Vagrant-friendly `qmkfm/qmk_cli`. - -In order for the Docker provider and `vagrant ssh` to function the container has a few extra requirements. - -* vagrant user -* ssh server - * configured with expected public key -* sudo - * passwordless for vagrant user