Merge tag '0.13.13' into firmware_21

This commit is contained in:
Drashna Jael're
2021-07-08 21:16:31 -07:00
177 changed files with 5485 additions and 1649 deletions

View File

@@ -23,6 +23,6 @@ jobs:
with: with:
submodules: recursive submodules: recursive
- name: Install dependencies - name: Install dependencies
run: pip3 install -r requirements.txt run: pip3 install -r requirements-dev.txt
- name: Run tests - name: Run tests
run: bin/qmk pytest run: bin/qmk pytest

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@
*.eep *.eep
*.elf *.elf
*.hex *.hex
*.uf2
*.qmk *.qmk
!util/bootloader.hex !util/bootloader.hex
!quantum/tools/eeprom_reset.hex !quantum/tools/eeprom_reset.hex

View File

@@ -29,6 +29,13 @@ $(info QMK Firmware $(QMK_VERSION))
endif endif
endif endif
# Determine which qmk cli to use
ifeq (,$(shell which qmk))
QMK_BIN = bin/qmk
else
QMK_BIN = qmk
endif
# avoid 'Entering|Leaving directory' messages # avoid 'Entering|Leaving directory' messages
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
@@ -86,8 +93,8 @@ clean:
.PHONY: distclean .PHONY: distclean
distclean: clean distclean: clean
echo -n 'Deleting *.bin and *.hex ... ' echo -n 'Deleting *.bin, *.hex, and *.uf2 ... '
rm -f *.bin *.hex rm -f *.bin *.hex *.uf2
echo 'done.' echo 'done.'
#Compatibility with the old make variables, anything you specify directly on the command line #Compatibility with the old make variables, anything you specify directly on the command line
@@ -396,7 +403,7 @@ define PARSE_KEYMAP
# Format it in bold # Format it in bold
KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR)
# Specify the variables that we are passing forward to submake # Specify the variables that we are passing forward to submake
MAKE_VARS := KEYBOARD=$$(CURRENT_KB) KEYMAP=$$(CURRENT_KM) REQUIRE_PLATFORM_KEY=$$(REQUIRE_PLATFORM_KEY) MAKE_VARS := KEYBOARD=$$(CURRENT_KB) KEYMAP=$$(CURRENT_KM) REQUIRE_PLATFORM_KEY=$$(REQUIRE_PLATFORM_KEY) QMK_BIN=$$(QMK_BIN)
# And the first part of the make command # And the first part of the make command
MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET) MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET)
# The message to display # The message to display
@@ -513,8 +520,8 @@ endef
%: %:
# Check if we have the CMP tool installed # Check if we have the CMP tool installed
cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi;
# Ensure that bin/qmk works. # Ensure that $(QMK_BIN) works.
if ! bin/qmk hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi if ! $(QMK_BIN) hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi
# Check if the submodules are dirty, and display a warning if they are # Check if the submodules are dirty, and display a warning if they are
ifndef SKIP_GIT ifndef SKIP_GIT
if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi

View File

@@ -29,9 +29,13 @@ def main():
""" """
# Change to the root of our checkout # Change to the root of our checkout
os.environ['ORIG_CWD'] = os.getcwd() os.environ['ORIG_CWD'] = os.getcwd()
os.environ['DEPRECATED_BIN_QMK'] = '1'
os.chdir(qmk_dir) os.chdir(qmk_dir)
print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr)
# Import the subcommands # Import the subcommands
import milc.subcommand.config # noqa
import qmk.cli # noqa import qmk.cli # noqa
# Execute # Execute

View File

@@ -89,11 +89,17 @@ ifeq ($(strip $(BOOTLOADER)), USBasp)
BOOTLOADER_SIZE = 4096 BOOTLOADER_SIZE = 4096
endif endif
ifeq ($(strip $(BOOTLOADER)), lufa-ms) ifeq ($(strip $(BOOTLOADER)), lufa-ms)
# DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!
# It is extremely prone to bricking, and is only included to support existing boards.
OPT_DEFS += -DBOOTLOADER_MS OPT_DEFS += -DBOOTLOADER_MS
BOOTLOADER_SIZE = 6144 BOOTLOADER_SIZE ?= 8192
FIRMWARE_FORMAT = bin FIRMWARE_FORMAT = bin
cpfirmware: lufa_warning
.INTERMEDIATE: lufa_warning
lufa_warning: $(FIRMWARE_FORMAT)
$(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
$(info LUFA MASS STORAGE Bootloader selected)
$(info DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!)
$(info It is extremely prone to bricking, and is only included to support existing boards.)
$(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
endif endif
ifdef BOOTLOADER_SIZE ifdef BOOTLOADER_SIZE
OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE)) OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
@@ -137,3 +143,6 @@ ifeq ($(strip $(BOOTLOADER)), stm32duino)
DFU_ARGS = -d 1EAF:0003 -a 2 -R DFU_ARGS = -d 1EAF:0003 -a 2 -R
DFU_SUFFIX_ARGS = -v 1EAF -p 0003 DFU_SUFFIX_ARGS = -v 1EAF -p 0003
endif endif
ifeq ($(strip $(BOOTLOADER)), tinyuf2)
OPT_DEFS += -DBOOTLOADER_TINYUF2
endif

View File

@@ -28,4 +28,4 @@ endif
# Generate the keymap.c # Generate the keymap.c
$(KEYBOARD_OUTPUT)/src/keymap.c: $(KEYMAP_JSON) $(KEYBOARD_OUTPUT)/src/keymap.c: $(KEYMAP_JSON)
bin/qmk json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON) $(QMK_BIN) json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON)

View File

@@ -12,6 +12,9 @@ endif
include common.mk include common.mk
# Set the qmk cli to use
QMK_BIN ?= qmk
# Set the filename for the final firmware binary # Set the filename for the final firmware binary
KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD)) KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD))
TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP) TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP)
@@ -97,7 +100,7 @@ MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP) MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
# Pull in rules from info.json # Pull in rules from info.json
INFO_RULES_MK = $(shell bin/qmk generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk) INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk)
include $(INFO_RULES_MK) include $(INFO_RULES_MK)
# Check for keymap.json first, so we can regenerate keymap.c # Check for keymap.json first, so we can regenerate keymap.c
@@ -295,13 +298,13 @@ endif
CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h
$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) $(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h $(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h
$(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES) $(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)
bin/qmk generate-keyboard-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(QMK_BIN) generate-keyboard-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h
$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES) $(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h $(QMK_BIN) generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h
generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h

View File

@@ -203,14 +203,17 @@ VALID_LED_MATRIX_TYPES := IS31FL3731 custom
ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) ifeq ($(strip $(LED_MATRIX_ENABLE)), yes)
ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),) ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),)
$(error LED_MATRIX_DRIVER="$(LED_MATRIX_DRIVER)" is not a valid matrix type) $(error "$(LED_MATRIX_DRIVER)" is not a valid matrix type)
else endif
BACKLIGHT_ENABLE = yes
BACKLIGHT_DRIVER = custom
OPT_DEFS += -DLED_MATRIX_ENABLE OPT_DEFS += -DLED_MATRIX_ENABLE
ifneq (,$(filter $(MCU), atmega16u2 atmega32u2 at90usb162))
# ATmegaxxU2 does not have hardware MUL instruction - lib8tion must be told to use software multiplication routines
OPT_DEFS += -DLIB8_ATTINY
endif
SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
SRC += $(QUANTUM_DIR)/led_matrix.c SRC += $(QUANTUM_DIR)/led_matrix.c
SRC += $(QUANTUM_DIR)/led_matrix_drivers.c SRC += $(QUANTUM_DIR)/led_matrix_drivers.c
endif CIE1931_CURVE := yes
ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731) ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731)
OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
@@ -327,7 +330,11 @@ endif
VALID_BACKLIGHT_TYPES := pwm timer software custom VALID_BACKLIGHT_TYPES := pwm timer software custom
BACKLIGHT_ENABLE ?= no BACKLIGHT_ENABLE ?= no
ifeq ($(strip $(CONVERT_TO_PROTON_C)), yes)
BACKLIGHT_DRIVER ?= software
else
BACKLIGHT_DRIVER ?= pwm BACKLIGHT_DRIVER ?= pwm
endif
ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),) ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),)
$(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type) $(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type)
@@ -402,10 +409,6 @@ ifeq ($(strip $(TERMINAL_ENABLE)), yes)
OPT_DEFS += -DUSER_PRINT OPT_DEFS += -DUSER_PRINT
endif endif
ifeq ($(strip $(USB_HID_ENABLE)), yes)
include $(TMK_DIR)/protocol/usb_hid.mk
endif
ifeq ($(strip $(WPM_ENABLE)), yes) ifeq ($(strip $(WPM_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/wpm.c SRC += $(QUANTUM_DIR)/wpm.c
OPT_DEFS += -DWPM_ENABLE OPT_DEFS += -DWPM_ENABLE
@@ -445,6 +448,23 @@ ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/dip_switch.c SRC += $(QUANTUM_DIR)/dip_switch.c
endif endif
VALID_MAGIC_TYPES := yes full lite
BOOTMAGIC_ENABLE ?= no
ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
$(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
endif
ifneq ($(strip $(BOOTMAGIC_ENABLE)), full)
OPT_DEFS += -DBOOTMAGIC_LITE
QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/bootmagic_lite.c
else
OPT_DEFS += -DBOOTMAGIC_ENABLE
QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/bootmagic_full.c
endif
endif
COMMON_VPATH += $(QUANTUM_DIR)/bootmagic
QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/magic.c
VALID_CUSTOM_MATRIX_TYPES:= yes lite no VALID_CUSTOM_MATRIX_TYPES:= yes lite no
CUSTOM_MATRIX ?= no CUSTOM_MATRIX ?= no

View File

@@ -59,8 +59,11 @@
'cmm_studio/saka68': { 'cmm_studio/saka68': {
target: 'cmm_studio/saka68/solder' target: 'cmm_studio/saka68/solder'
}, },
'crkbd/rev1': { 'crkbd/rev1/legacy': {
target: 'crkbd/rev1/legacy' target: 'crkbd/rev1'
},
'crkbd/rev1/common': {
target: 'crkbd/rev1'
}, },
'doro67/multi': { 'doro67/multi': {
layouts: { layouts: {

View File

@@ -25,7 +25,7 @@
}, },
"processor": { "processor": {
"type": "string", "type": "string",
"enum": ["cortex-m0", "cortex-m0plus", "cortex-m3", "cortex-m4", "MKL26Z64", "MK20DX128", "MK20DX256", "STM32F042", "STM32F072", "STM32F103", "STM32F303", "STM32F401", "STM32F411", "STM32G431", "STM32G474", "atmega16u2", "atmega32u2", "atmega16u4", "atmega32u4", "at90usb162", "at90usb646", "at90usb647", "at90usb1286", "at90usb1287", "atmega32a", "atmega328p", "atmega328", "attiny85", "unknown"] "enum": ["cortex-m0", "cortex-m0plus", "cortex-m3", "cortex-m4", "MKL26Z64", "MK20DX128", "MK20DX256", "MK66F18", "STM32F042", "STM32F072", "STM32F103", "STM32F303", "STM32F401", "STM32F411", "STM32F446", "STM32G431", "STM32G474", "STM32L433", "STM32L443", "atmega16u2", "atmega32u2", "atmega16u4", "atmega32u4", "at90usb162", "at90usb646", "at90usb647", "at90usb1286", "at90usb1287", "atmega32a", "atmega328p", "atmega328", "attiny85", "unknown"]
}, },
"board": { "board": {
"type": "string", "type": "string",
@@ -34,7 +34,7 @@
}, },
"bootloader": { "bootloader": {
"type": "string", "type": "string",
"enum": ["atmel-dfu", "bootloadHID", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "micronucleus", "qmk-dfu", "stm32-dfu", "stm32duino", "unknown", "USBasp"] "enum": ["atmel-dfu", "bootloadHID", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "micronucleus", "qmk-dfu", "stm32-dfu", "stm32duino", "unknown", "USBasp", "tinyuf2"]
}, },
"diode_direction": { "diode_direction": {
"type": "string", "type": "string",

View File

@@ -14,10 +14,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <avr/io.h>
#include "spi_master.h" #include "spi_master.h"
#include "quantum.h"
#include "timer.h" #include "timer.h"
#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) #if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)

View File

@@ -16,7 +16,9 @@
#pragma once #pragma once
#include "quantum.h" #include <stdbool.h>
#include "gpio.h"
typedef int16_t spi_status_t; typedef int16_t spi_status_t;

View File

@@ -101,8 +101,12 @@
// Options are 12, 10, 8, and 6 bit. // Options are 12, 10, 8, and 6 bit.
#ifndef ADC_RESOLUTION #ifndef ADC_RESOLUTION
# ifdef ADC_CFGR_RES_10BITS // ADCv3, ADCv4
# define ADC_RESOLUTION ADC_CFGR_RES_10BITS
# else // ADCv1, ADCv5, or the bodge for ADCv2 above
# define ADC_RESOLUTION ADC_CFGR1_RES_10BIT # define ADC_RESOLUTION ADC_CFGR1_RES_10BIT
# endif # endif
#endif
static ADCConfig adcCfg = {}; static ADCConfig adcCfg = {};
static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH]; static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH];
@@ -161,8 +165,8 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 ); case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 );
case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 ); case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 );
case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 ); case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 );
case B12: return TO_MUX( ADC_CHANNEL_IN2, 3 ); case B12: return TO_MUX( ADC_CHANNEL_IN3, 3 );
case B13: return TO_MUX( ADC_CHANNEL_IN3, 3 ); case B13: return TO_MUX( ADC_CHANNEL_IN5, 2 );
case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 ); case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 );
case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 ); case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 );
case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2 case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2
@@ -189,11 +193,52 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 ); case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 );
case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2 case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2
case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 ); case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 );
#elif defined(STM32F4XX) // TODO: add all pins #elif defined(STM32F4XX)
case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
//case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 ); case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
#elif defined(STM32F1XX) // TODO: add all pins case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
# if STM32_ADC_USE_ADC3
case F3: return TO_MUX( ADC_CHANNEL_IN9, 2 );
case F4: return TO_MUX( ADC_CHANNEL_IN14, 2 );
case F5: return TO_MUX( ADC_CHANNEL_IN15, 2 );
case F6: return TO_MUX( ADC_CHANNEL_IN4, 2 );
case F7: return TO_MUX( ADC_CHANNEL_IN5, 2 );
case F8: return TO_MUX( ADC_CHANNEL_IN6, 2 );
case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 );
case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 );
# endif
#elif defined(STM32F1XX)
case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
// STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the
// ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable.
#endif #endif
} }

View File

@@ -1,13 +1,20 @@
#include "quantum.h" /* Copyright 2021 QMK
#include "serial.h" *
#include "print.h" * 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 <http://www.gnu.org/licenses/>.
*/
#include <ch.h> #include "serial_usart.h"
#include <hal.h>
#ifndef USART_CR1_M0
# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
#endif
#ifndef USE_GPIOV1 #ifndef USE_GPIOV1
// The default PAL alternate modes are used to signal that the pins are used for USART // The default PAL alternate modes are used to signal that the pins are used for USART
@@ -20,50 +27,10 @@
# define SERIAL_USART_DRIVER SD1 # define SERIAL_USART_DRIVER SD1
#endif #endif
#ifndef SERIAL_USART_CR1
# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
#endif
#ifndef SERIAL_USART_CR2
# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
#endif
#ifndef SERIAL_USART_CR3
# define SERIAL_USART_CR3 0
#endif
#ifdef SOFT_SERIAL_PIN #ifdef SOFT_SERIAL_PIN
# define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN # define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN
#endif #endif
#ifndef SELECT_SOFT_SERIAL_SPEED
# define SELECT_SOFT_SERIAL_SPEED 1
#endif
#ifdef SERIAL_USART_SPEED
// Allow advanced users to directly set SERIAL_USART_SPEED
#elif SELECT_SOFT_SERIAL_SPEED == 0
# define SERIAL_USART_SPEED 460800
#elif SELECT_SOFT_SERIAL_SPEED == 1
# define SERIAL_USART_SPEED 230400
#elif SELECT_SOFT_SERIAL_SPEED == 2
# define SERIAL_USART_SPEED 115200
#elif SELECT_SOFT_SERIAL_SPEED == 3
# define SERIAL_USART_SPEED 57600
#elif SELECT_SOFT_SERIAL_SPEED == 4
# define SERIAL_USART_SPEED 38400
#elif SELECT_SOFT_SERIAL_SPEED == 5
# define SERIAL_USART_SPEED 19200
#else
# error invalid SELECT_SOFT_SERIAL_SPEED value
#endif
#ifndef SERIAL_USART_TIMEOUT
# define SERIAL_USART_TIMEOUT 100
#endif
#define HANDSHAKE_MAGIC 7
static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) { static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) {
msg_t ret = sdWrite(driver, data, size); msg_t ret = sdWrite(driver, data, size);
@@ -123,6 +90,10 @@ __attribute__((weak)) void usart_init(void) {
#else #else
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
#endif #endif
#if defined(USART_REMAP)
USART_REMAP;
#endif
} }
void usart_master_init(void) { void usart_master_init(void) {

View File

@@ -0,0 +1,90 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "quantum.h"
#include "serial.h"
#include "printf.h"
#include <ch.h>
#include <hal.h>
#ifndef USART_CR1_M0
# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
#endif
#ifndef SERIAL_USART_CR1
# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
#endif
#ifndef SERIAL_USART_CR2
# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
#endif
#ifndef SERIAL_USART_CR3
# define SERIAL_USART_CR3 0
#endif
#if defined(USART1_REMAP)
# define USART_REMAP \
do { \
(AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); \
} while (0)
#elif defined(USART2_REMAP)
# define USART_REMAP \
do { \
(AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); \
} while (0)
#elif defined(USART3_PARTIALREMAP)
# define USART_REMAP \
do { \
(AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); \
} while (0)
#elif defined(USART3_FULLREMAP)
# define USART_REMAP \
do { \
(AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \
} while (0)
#endif
#ifndef SELECT_SOFT_SERIAL_SPEED
# define SELECT_SOFT_SERIAL_SPEED 1
#endif
#ifdef SERIAL_USART_SPEED
// Allow advanced users to directly set SERIAL_USART_SPEED
#elif SELECT_SOFT_SERIAL_SPEED == 0
# define SERIAL_USART_SPEED 460800
#elif SELECT_SOFT_SERIAL_SPEED == 1
# define SERIAL_USART_SPEED 230400
#elif SELECT_SOFT_SERIAL_SPEED == 2
# define SERIAL_USART_SPEED 115200
#elif SELECT_SOFT_SERIAL_SPEED == 3
# define SERIAL_USART_SPEED 57600
#elif SELECT_SOFT_SERIAL_SPEED == 4
# define SERIAL_USART_SPEED 38400
#elif SELECT_SOFT_SERIAL_SPEED == 5
# define SERIAL_USART_SPEED 19200
#else
# error invalid SELECT_SOFT_SERIAL_SPEED value
#endif
#ifndef SERIAL_USART_TIMEOUT
# define SERIAL_USART_TIMEOUT 100
#endif
#define HANDSHAKE_MAGIC 7

View File

@@ -0,0 +1,261 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#include "serial_usart.h"
#include <stdatomic.h>
#if !defined(USE_GPIOV1)
// The default PAL alternate modes are used to signal that the pins are used for USART
# if !defined(SERIAL_USART_TX_PAL_MODE)
# define SERIAL_USART_TX_PAL_MODE 7
# endif
# if !defined(SERIAL_USART_RX_PAL_MODE)
# define SERIAL_USART_RX_PAL_MODE 7
# endif
#endif
#if !defined(SERIAL_USART_DRIVER)
# define SERIAL_USART_DRIVER UARTD1
#endif
#if !defined(SERIAL_USART_TX_PIN)
# define SERIAL_USART_TX_PIN A9
#endif
#if !defined(SERIAL_USART_RX_PIN)
# define SERIAL_USART_RX_PIN A10
#endif
#define SIGNAL_HANDSHAKE_RECEIVED 0x1
void handle_transactions_slave(uint8_t sstd_index);
static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake);
/*
* UART driver configuration structure. We use the blocking DMA enabled API and
* the rxchar callback to receive handshake tokens but only on the slave halve.
*/
// clang-format off
static UARTConfig uart_config = {
.txend1_cb = NULL,
.txend2_cb = NULL,
.rxend_cb = NULL,
.rxchar_cb = NULL,
.rxerr_cb = NULL,
.timeout_cb = NULL,
.speed = (SERIAL_USART_SPEED),
.cr1 = (SERIAL_USART_CR1),
.cr2 = (SERIAL_USART_CR2),
.cr3 = (SERIAL_USART_CR3)
};
// clang-format on
static SSTD_t* Transaction_table = NULL;
static uint8_t Transaction_table_size = 0;
static atomic_uint_least8_t handshake = 0xFF;
static thread_reference_t tp_target = NULL;
/*
* This callback is invoked when a character is received but the application
* was not ready to receive it, the character is passed as parameter.
* Receive transaction table index from initiator, which doubles as basic handshake token. */
static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake) {
/* Check if received handshake is not a valid transaction id.
* Please note that we can still catch a seemingly valid handshake
* i.e. a byte from a ongoing transfer which is in the allowed range.
* So this check mainly prevents any obviously wrong handshakes and
* subsequent wakeups of the receiving thread, which is a costly operation. */
if (received_handshake > Transaction_table_size) {
return;
}
handshake = (uint8_t)received_handshake;
chSysLockFromISR();
/* Wakeup receiving thread to start a transaction. */
chEvtSignalI(tp_target, (eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
chSysUnlockFromISR();
}
__attribute__((weak)) void usart_init(void) {
#if defined(USE_GPIOV1)
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
#else
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
#endif
}
/*
* This thread runs on the slave half and reacts to transactions initiated from the master.
*/
static THD_WORKING_AREA(waSlaveThread, 1024);
static THD_FUNCTION(SlaveThread, arg) {
(void)arg;
chRegSetThreadName("slave_usart_tx_rx");
while (true) {
/* We sleep as long as there is no handshake waiting for us. */
chEvtWaitAny((eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
handle_transactions_slave(handshake);
}
}
void soft_serial_target_init(SSTD_t* const sstd_table, int sstd_table_size) {
Transaction_table = sstd_table;
Transaction_table_size = (uint8_t)sstd_table_size;
usart_init();
#if defined(USART_REMAP)
USART_REMAP;
#endif
tp_target = chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
// Start receiving handshake tokens on slave halve
uart_config.rxchar_cb = receive_transaction_handshake;
uartStart(&SERIAL_USART_DRIVER, &uart_config);
}
/**
* @brief React to transactions started by the master.
* This version uses duplex send and receive usart pheriphals and DMA backed transfers.
*/
void inline handle_transactions_slave(uint8_t sstd_index) {
size_t buffer_size = 0;
msg_t msg = 0;
SSTD_t* trans = &Transaction_table[sstd_index];
/* Send back the handshake which is XORed as a simple checksum,
to signal that the slave is ready to receive possible transaction buffers */
sstd_index ^= HANDSHAKE_MAGIC;
buffer_size = (size_t)sizeof(sstd_index);
msg = uartSendTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK) {
if (trans->status) {
*trans->status = TRANSACTION_NO_RESPONSE;
}
return;
}
/* Receive transaction buffer from the master. If this transaction requires it.*/
buffer_size = (size_t)trans->initiator2target_buffer_size;
if (buffer_size) {
msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK) {
if (trans->status) {
*trans->status = TRANSACTION_NO_RESPONSE;
}
return;
}
}
/* Send transaction buffer to the master. If this transaction requires it. */
buffer_size = (size_t)trans->target2initiator_buffer_size;
if (buffer_size) {
msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK) {
if (trans->status) {
*trans->status = TRANSACTION_NO_RESPONSE;
}
return;
}
}
if (trans->status) {
*trans->status = TRANSACTION_ACCEPTED;
}
}
void soft_serial_initiator_init(SSTD_t* const sstd_table, int sstd_table_size) {
Transaction_table = sstd_table;
Transaction_table_size = (uint8_t)sstd_table_size;
usart_init();
#if defined(SERIAL_USART_PIN_SWAP)
uart_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins
#endif
#if defined(USART_REMAP)
USART_REMAP;
#endif
uartStart(&SERIAL_USART_DRIVER, &uart_config);
}
/**
* @brief Start transaction from the master to the slave.
* This version uses duplex send and receive usart pheriphals and DMA backed transfers.
*
* @param index Transaction Table index of the transaction to start.
* @return int TRANSACTION_NO_RESPONSE in case of Timeout.
* TRANSACTION_TYPE_ERROR in case of invalid transaction index.
* TRANSACTION_END in case of success.
*/
#if !defined(SERIAL_USE_MULTI_TRANSACTION)
int soft_serial_transaction(void) {
uint8_t sstd_index = 0;
#else
int soft_serial_transaction(int index) {
uint8_t sstd_index = index;
#endif
if (sstd_index > Transaction_table_size) {
return TRANSACTION_TYPE_ERROR;
}
SSTD_t* const trans = &Transaction_table[sstd_index];
msg_t msg = 0;
size_t buffer_size = (size_t)sizeof(sstd_index);
/* Send transaction table index to the slave, which doubles as basic handshake token. */
uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
uint8_t sstd_index_shake = 0xFF;
buffer_size = (size_t)sizeof(sstd_index_shake);
/* Receive the handshake token from the slave. The token was XORed by the slave as a simple checksum.
If the tokens match, the master will start to send and receive possible transaction buffers. */
msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index_shake, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
dprintln("USART: Handshake Failed");
return TRANSACTION_NO_RESPONSE;
}
/* Send transaction buffer to the slave. If this transaction requires it. */
buffer_size = (size_t)trans->initiator2target_buffer_size;
if (buffer_size) {
msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK) {
dprintln("USART: Send Failed");
return TRANSACTION_NO_RESPONSE;
}
}
/* Receive transaction buffer from the slave. If this transaction requires it. */
buffer_size = (size_t)trans->target2initiator_buffer_size;
if (buffer_size) {
msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (msg != MSG_OK) {
dprintln("USART: Receive Failed");
return TRANSACTION_NO_RESPONSE;
}
}
return TRANSACTION_END;
}

View File

@@ -15,7 +15,7 @@
*/ */
#include "spi_master.h" #include "spi_master.h"
#include "quantum.h"
#include "timer.h" #include "timer.h"
static pin_t currentSlavePin = NO_PIN; static pin_t currentSlavePin = NO_PIN;

View File

@@ -18,7 +18,9 @@
#include <ch.h> #include <ch.h>
#include <hal.h> #include <hal.h>
#include "quantum.h" #include <stdbool.h>
#include "gpio.h"
#ifndef SPI_DRIVER #ifndef SPI_DRIVER
# define SPI_DRIVER SPID2 # define SPI_DRIVER SPID2

View File

@@ -27,6 +27,15 @@
# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
#endif #endif
#ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT
# define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
#else
# if !STM32_PWM_USE_ADVANCED
# error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE"
# endif
# define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
#endif
// Push Pull or Open Drain Configuration // Push Pull or Open Drain Configuration
// Default Push Pull // Default Push Pull
#ifndef WS2812_EXTERNAL_PULLUP #ifndef WS2812_EXTERNAL_PULLUP
@@ -247,7 +256,7 @@ void ws2812_init(void) {
.channels = .channels =
{ {
[0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled
[WS2812_PWM_CHANNEL - 1] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about
}, },
.cr2 = 0, .cr2 = 0,
.dier = TIM_DIER_UDE, // DMA on update event for next period .dier = TIM_DIER_UDE, // DMA on update event for next period

View File

@@ -16,22 +16,63 @@
# define WS2812_SPI_MOSI_PAL_MODE 5 # define WS2812_SPI_MOSI_PAL_MODE 5
#endif #endif
#ifndef WS2812_SPI_SCK_PAL_MODE
# define WS2812_SPI_SCK_PAL_MODE 5
#endif
// Push Pull or Open Drain Configuration // Push Pull or Open Drain Configuration
// Default Push Pull // Default Push Pull
#ifndef WS2812_EXTERNAL_PULLUP #ifndef WS2812_EXTERNAL_PULLUP
# if defined(USE_GPIOV1) # if defined(USE_GPIOV1)
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL # define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
# else # else
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL # define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
# endif # endif
#else #else
# if defined(USE_GPIOV1) # if defined(USE_GPIOV1)
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN # define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
# else # else
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN # define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
# endif # endif
#endif #endif
// Define SPI config speed
// baudrate should target 3.2MHz
// F072 fpclk = 48MHz
// 48/16 = 3Mhz
#if WS2812_SPI_DIVISOR == 2
# define WS2812_SPI_DIVISOR (0)
#elif WS2812_SPI_DIVISOR == 4
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_0)
#elif WS2812_SPI_DIVISOR == 8
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1)
#elif WS2812_SPI_DIVISOR == 16 // same as default
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0)
#elif WS2812_SPI_DIVISOR == 32
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2)
#elif WS2812_SPI_DIVISOR == 64
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_0)
#elif WS2812_SPI_DIVISOR == 128
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1)
#elif WS2812_SPI_DIVISOR == 256
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
#else
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) // default
#endif
// Use SPI circular buffer
#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
# define WS2812_SPI_BUFFER_MODE 1 // circular buffer
#else
# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
#endif
#if defined(USE_GPIOV1)
# define WS2812_SCK_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
#else
# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
#endif
#define BYTES_FOR_LED_BYTE 4 #define BYTES_FOR_LED_BYTE 4
#define NB_COLORS 3 #define NB_COLORS 3
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS) #define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
@@ -78,17 +119,21 @@ static void set_led_color_rgb(LED_TYPE color, int pos) {
} }
void ws2812_init(void) { void ws2812_init(void) {
palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); palSetLineMode(RGB_DI_PIN, WS2812_MOSI_OUTPUT_MODE);
#ifdef WS2812_SPI_SCK_PIN
palSetLineMode(WS2812_SPI_SCK_PIN, WS2812_SCK_OUTPUT_MODE);
#endif // WS2812_SPI_SCK_PIN
// TODO: more dynamic baudrate // TODO: more dynamic baudrate
static const SPIConfig spicfg = { static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR};
0, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN),
SPI_CR1_BR_1 | SPI_CR1_BR_0 // baudrate : fpclk / 8 => 1tick is 0.32us (2.25 MHz)
};
spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */
spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */
spiSelect(&WS2812_SPI); /* Slave Select assertion. */ spiSelect(&WS2812_SPI); /* Slave Select assertion. */
#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
#endif
} }
void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
@@ -104,9 +149,11 @@ void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
// Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues. // Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues.
// Instead spiSend can be used to send synchronously (or the thread logic can be added back). // Instead spiSend can be used to send synchronously (or the thread logic can be added back).
#ifndef WS2812_SPI_USE_CIRCULAR_BUFFER
# ifdef WS2812_SPI_SYNC # ifdef WS2812_SPI_SYNC
spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
# else # else
spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
# endif # endif
#endif
} }

View File

@@ -68,7 +68,7 @@ uint8_t g_twi_transfer_buffer[20];
uint8_t g_pwm_buffer[DRIVER_COUNT][192]; uint8_t g_pwm_buffer[DRIVER_COUNT][192];
bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; 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) {

View File

@@ -4,7 +4,7 @@
// Online editor: http://teripom.x0.com/ // Online editor: http://teripom.x0.com/
static const unsigned char font[] PROGMEM = { static const unsigned char font[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, 0x07, 0x08, 0x7F, 0x08, 0x07, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00,
0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46, 0x00, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00,
0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00,

View File

@@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "progmem.h" #include "progmem.h"
#include "keyboard.h"
// Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf // 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 SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf
@@ -71,6 +73,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRE_CHARGE_PERIOD 0xD9 #define PRE_CHARGE_PERIOD 0xD9
#define VCOM_DETECT 0xDB #define VCOM_DETECT 0xDB
// Advance Graphic Commands
#define FADE_BLINK 0x23
#define ENABLE_FADE 0x20
#define ENABLE_BLINK 0x30
// Charge Pump Commands // Charge Pump Commands
#define CHARGE_PUMP 0x8D #define CHARGE_PUMP 0x8D
@@ -108,7 +115,7 @@ bool oled_initialized = false;
bool oled_active = false; bool oled_active = false;
bool oled_scrolling = false; bool oled_scrolling = false;
uint8_t oled_brightness = OLED_BRIGHTNESS; uint8_t oled_brightness = OLED_BRIGHTNESS;
uint8_t oled_rotation = 0; oled_rotation_t oled_rotation = 0;
uint8_t oled_rotation_width = 0; uint8_t oled_rotation_width = 0;
uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
uint8_t oled_scroll_start = 0; uint8_t oled_scroll_start = 0;
@@ -151,7 +158,13 @@ static void InvertCharacter(uint8_t *cursor) {
} }
} }
bool oled_init(uint8_t rotation) { bool oled_init(oled_rotation_t rotation) {
#if defined(USE_I2C) && defined(SPLIT_KEYBOARD)
if (!is_keyboard_master()) {
return true;
}
#endif
oled_rotation = oled_init_user(rotation); oled_rotation = oled_init_user(rotation);
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
oled_rotation_width = OLED_DISPLAY_WIDTH; oled_rotation_width = OLED_DISPLAY_WIDTH;
@@ -478,8 +491,9 @@ void oled_write_raw(const char *data, uint16_t size) {
uint16_t cursor_start_index = oled_cursor - &oled_buffer[0]; uint16_t cursor_start_index = oled_cursor - &oled_buffer[0];
if ((size + cursor_start_index) > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE - cursor_start_index; if ((size + cursor_start_index) > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE - cursor_start_index;
for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) { for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
if (oled_buffer[i] == data[i]) continue; uint8_t c = *data++;
oled_buffer[i] = data[i]; if (oled_buffer[i] == c) continue;
oled_buffer[i] = c;
oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE)); oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
} }
} }
@@ -539,7 +553,13 @@ bool oled_on(void) {
oled_timeout = timer_read32() + OLED_TIMEOUT; oled_timeout = timer_read32() + OLED_TIMEOUT;
#endif #endif
static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON}; static const uint8_t PROGMEM display_on[] =
#ifdef OLED_FADE_OUT
{I2C_CMD, FADE_BLINK, 0x00};
#else
{I2C_CMD, DISPLAY_ON};
#endif
if (!oled_active) { if (!oled_active) {
if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) { if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
print("oled_on cmd failed\n"); print("oled_on cmd failed\n");
@@ -555,7 +575,13 @@ bool oled_off(void) {
return !oled_active; return !oled_active;
} }
static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF}; static const uint8_t PROGMEM display_off[] =
#ifdef OLED_FADE_OUT
{I2C_CMD, FADE_BLINK, ENABLE_FADE | OLED_FADE_OUT_INTERVAL};
#else
{I2C_CMD, DISPLAY_OFF};
#endif
if (oled_active) { if (oled_active) {
if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
print("oled_off cmd failed\n"); print("oled_off cmd failed\n");

View File

@@ -154,10 +154,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# endif # endif
#endif #endif
#if !defined(OLED_FADE_OUT_INTERVAL)
# define OLED_FADE_OUT_INTERVAL 0x00
#endif
#if OLED_FADE_OUT_INTERVAL > 0x0F || OLED_FADE_OUT_INTERVAL < 0x00
# error OLED_FADE_OUT_INTERVAL must be between 0x00 and 0x0F
#endif
#if !defined(OLED_I2C_TIMEOUT) #if !defined(OLED_I2C_TIMEOUT)
# define OLED_I2C_TIMEOUT 100 # define OLED_I2C_TIMEOUT 100
#endif #endif
#if !defined(OLED_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD)
# define OLED_UPDATE_INTERVAL 50
#endif
typedef struct __attribute__((__packed__)) { typedef struct __attribute__((__packed__)) {
uint8_t *current_element; uint8_t *current_element;
uint16_t remaining_element_count; uint16_t remaining_element_count;
@@ -214,13 +226,17 @@ void oled_write(const char *data, bool invert);
void oled_write_ln(const char *data, bool invert); void oled_write_ln(const char *data, bool invert);
// Pans the buffer to the right (or left by passing true) by moving contents of the buffer // Pans the buffer to the right (or left by passing true) by moving contents of the buffer
// Useful for moving the screen in preparation for new drawing
void oled_pan(bool left); void oled_pan(bool left);
// Returns a pointer to the requested start index in the buffer plus remaining // Returns a pointer to the requested start index in the buffer plus remaining
// buffer length as struct // buffer length as struct
oled_buffer_reader_t oled_read_raw(uint16_t start_index); oled_buffer_reader_t oled_read_raw(uint16_t start_index);
// Writes a string to the buffer at current cursor position
void oled_write_raw(const char *data, uint16_t size); void oled_write_raw(const char *data, uint16_t size);
// Writes a single byte into the buffer at the specified index
void oled_write_raw_byte(const char data, uint16_t index); void oled_write_raw_byte(const char data, uint16_t index);
// Sets a specific pixel on or off // Sets a specific pixel on or off
@@ -239,17 +255,11 @@ void oled_write_P(const char *data, bool invert);
// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM // Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
void oled_write_ln_P(const char *data, bool invert); void oled_write_ln_P(const char *data, bool invert);
// Writes a PROGMEM string to the buffer at current cursor position
void oled_write_raw_P(const char *data, uint16_t size); void oled_write_raw_P(const char *data, uint16_t size);
#else #else
// Writes a string to the buffer at current cursor position
// Advances the cursor while writing, inverts the pixels if true
# define oled_write_P(data, invert) oled_write(data, invert) # define oled_write_P(data, invert) oled_write(data, invert)
// Writes a string to the buffer at current cursor position
// Advances the cursor while writing, inverts the pixels if true
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
# define oled_write_ln_P(data, invert) oled_write(data, invert) # define oled_write_ln_P(data, invert) oled_write(data, invert)
# define oled_write_raw_P(data, size) oled_write_raw(data, size) # define oled_write_raw_P(data, size) oled_write_raw(data, size)
#endif // defined(__AVR__) #endif // defined(__AVR__)

View File

@@ -222,7 +222,7 @@ uint8_t ergodox_left_leds_update(void) {
#ifdef SWAP_HANDS_ENABLE #ifdef SWAP_HANDS_ENABLE
__attribute__ ((weak)) __attribute__ ((weak))
// swap-hands action needs a matrix to define the swap // swap-hands action needs a matrix to define the swap
const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
/* Left hand, matrix positions */ /* Left hand, matrix positions */
{{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}}, {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
{{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}}, {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},

View File

@@ -386,7 +386,7 @@ bool music_mask_kb(uint16_t keycode) {
#ifdef SWAP_HANDS_ENABLE #ifdef SWAP_HANDS_ENABLE
// swap-hands action needs a matrix to define the swap // swap-hands action needs a matrix to define the swap
// clang-format off // clang-format off
const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
/* Left hand, matrix positions */ /* Left hand, matrix positions */
{{6,6}, {5,6}, {4,6}, {3,6}, {2,6}, {1,6},{0,6}}, {{6,6}, {5,6}, {4,6}, {3,6}, {2,6}, {1,6},{0,6}},
{{6,7}, {5,7}, {4,7}, {3,7}, {2,7}, {1,7},{0,7}}, {{6,7}, {5,7}, {4,7}, {3,7}, {2,7}, {1,7},{0,7}},

View File

@@ -2,6 +2,9 @@
MCU = STM32F303 MCU = STM32F303
BOARD = QMK_PROTON_C BOARD = QMK_PROTON_C
# Bootloader selection
BOOTLOADER = stm32-dfu
# Build Options # Build Options
# change yes to no to disable # change yes to no to disable
# #
@@ -23,7 +26,6 @@ DEBOUNCE_TYPE = custom
SWAP_HANDS_ENABLE = yes SWAP_HANDS_ENABLE = yes
RGB_MATRIX_ENABLE = yes RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = IS31FL3731 RGB_MATRIX_DRIVER = IS31FL3731
#SERIAL_LINK_ENABLE = yes
EEPROM_DRIVER = i2c EEPROM_DRIVER = i2c
MOUSE_SHARED_EP = no MOUSE_SHARED_EP = no

View File

@@ -55,7 +55,6 @@
{ k37, k38, k39, k33, k34, k35 } \ { k37, k38, k39, k33, k34, k35 } \
} }
#define KEYMAP LAYOUT_ortho_4x12
#define LAYOUT_planck_mit LAYOUT_planck_1x2uC #define LAYOUT_planck_mit LAYOUT_planck_1x2uC
#define LAYOUT_planck_grid LAYOUT_ortho_4x12 #define LAYOUT_planck_grid LAYOUT_ortho_4x12

View File

@@ -256,7 +256,7 @@ uint16_t muse_counter = 0;
uint8_t muse_offset = 70; uint8_t muse_offset = 70;
uint16_t muse_tempo = 50; uint16_t muse_tempo = 50;
void encoder_update(bool clockwise) { bool encoder_update(bool clockwise) {
if (muse_mode) { if (muse_mode) {
if (IS_LAYER_ON(_RAISE)) { if (IS_LAYER_ON(_RAISE)) {
if (clockwise) { if (clockwise) {
@@ -290,6 +290,7 @@ void encoder_update(bool clockwise) {
#endif #endif
} }
} }
return true;
} }
void dip_update(uint8_t index, bool active) { void dip_update(uint8_t index, bool active) {

View File

@@ -2,12 +2,15 @@
MCU = STM32F303 MCU = STM32F303
BOARD = QMK_PROTON_C BOARD = QMK_PROTON_C
# Bootloader selection
BOOTLOADER = stm32-dfu
# Build Options # Build Options
# change to "no" to disable the options, or define them in the Makefile in # change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically # the appropriate keymap folder that will get included automatically
# #
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration BOOTMAGIC_ENABLE = full # Virtual DIP switch configuration
MOUSEKEY_ENABLE = yes # Mouse keys MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug CONSOLE_ENABLE = no # Console for debug
@@ -22,7 +25,6 @@ ENCODER_ENABLE = yes
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
# SERIAL_LINK_ENABLE = yes
ENCODER_ENABLE = yes ENCODER_ENABLE = yes
RGB_MATRIX_DRIVER = IS31FL3737 RGB_MATRIX_DRIVER = IS31FL3737

View File

@@ -256,7 +256,7 @@ uint16_t muse_counter = 0;
uint8_t muse_offset = 70; uint8_t muse_offset = 70;
uint16_t muse_tempo = 50; uint16_t muse_tempo = 50;
void encoder_update(bool clockwise) { bool encoder_update(bool clockwise) {
if (muse_mode) { if (muse_mode) {
if (IS_LAYER_ON(_RAISE)) { if (IS_LAYER_ON(_RAISE)) {
if (clockwise) { if (clockwise) {
@@ -286,6 +286,7 @@ void encoder_update(bool clockwise) {
#endif #endif
} }
} }
return true;
} }
void dip_switch_update_user(uint8_t index, bool active) { void dip_switch_update_user(uint8_t index, bool active) {

View File

@@ -322,7 +322,7 @@ uint16_t muse_counter = 0;
uint8_t muse_offset = 70; uint8_t muse_offset = 70;
uint16_t muse_tempo = 50; uint16_t muse_tempo = 50;
void encoder_update(bool clockwise) { bool encoder_update(bool clockwise) {
if (muse_mode) { if (muse_mode) {
if (IS_LAYER_ON(_RAISE)) { if (IS_LAYER_ON(_RAISE)) {
if (clockwise) { if (clockwise) {
@@ -356,6 +356,7 @@ void encoder_update(bool clockwise) {
#endif #endif
} }
} }
return true;
} }
void matrix_scan_user(void) { void matrix_scan_user(void) {

View File

@@ -8,7 +8,7 @@ from milc import cli
from qmk.comment_remover import comment_remover from qmk.comment_remover import comment_remover
default_key_entry = {'x': -1, 'y': 0, 'w': 1} default_key_entry = {'x': -1, 'y': 0, 'w': 1}
single_comment_regex = re.compile(r' */[/*].*$') single_comment_regex = re.compile(r'\s+/[/*].*$')
multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE) multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE)

View File

@@ -12,6 +12,56 @@ from subprocess import run
from milc import cli, __VERSION__ from milc import cli, __VERSION__
from milc.questions import yesno from milc.questions import yesno
import_names = {
# A mapping of package name to importable name
'pep8-naming': 'pep8ext_naming',
'pyusb': 'usb.core',
}
safe_commands = [
# A list of subcommands we always run, even when the module imports fail
'clone',
'config',
'env',
'setup',
]
subcommands = [
'qmk.cli.bux',
'qmk.cli.c2json',
'qmk.cli.cformat',
'qmk.cli.chibios.confmigrate',
'qmk.cli.clean',
'qmk.cli.compile',
'qmk.cli.console',
'qmk.cli.docs',
'qmk.cli.doctor',
'qmk.cli.fileformat',
'qmk.cli.flash',
'qmk.cli.format.json',
'qmk.cli.generate.api',
'qmk.cli.generate.config_h',
'qmk.cli.generate.dfu_header',
'qmk.cli.generate.docs',
'qmk.cli.generate.info_json',
'qmk.cli.generate.keyboard_h',
'qmk.cli.generate.layouts',
'qmk.cli.generate.rgb_breathe_table',
'qmk.cli.generate.rules_mk',
'qmk.cli.hello',
'qmk.cli.info',
'qmk.cli.json2c',
'qmk.cli.lint',
'qmk.cli.list.keyboards',
'qmk.cli.list.keymaps',
'qmk.cli.kle2json',
'qmk.cli.multibuild',
'qmk.cli.new.keyboard',
'qmk.cli.new.keymap',
'qmk.cli.pyformat',
'qmk.cli.pytest',
]
def _run_cmd(*command): def _run_cmd(*command):
"""Run a command in a subshell. """Run a command in a subshell.
@@ -50,8 +100,8 @@ def _find_broken_requirements(requirements):
module_import = module_name.replace('-', '_') module_import = module_name.replace('-', '_')
# Not every module is importable by its own name. # Not every module is importable by its own name.
if module_name == "pep8-naming": if module_name in import_names:
module_import = "pep8ext_naming" module_import = import_names[module_name]
if not find_spec(module_import): if not find_spec(module_import):
broken_modules.append(module_name) broken_modules.append(module_name)
@@ -99,7 +149,7 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 7:
milc_version = __VERSION__.split('.') milc_version = __VERSION__.split('.')
if int(milc_version[0]) < 2 and int(milc_version[1]) < 3: if int(milc_version[0]) < 2 and int(milc_version[1]) < 4:
requirements = Path('requirements.txt').resolve() requirements = Path('requirements.txt').resolve()
print(f'Your MILC library is too old! Please upgrade: python3 -m pip install -U -r {str(requirements)}') print(f'Your MILC library is too old! Please upgrade: python3 -m pip install -U -r {str(requirements)}')
@@ -107,7 +157,13 @@ if int(milc_version[0]) < 2 and int(milc_version[1]) < 3:
# Check to make sure we have all our dependencies # Check to make sure we have all our dependencies
msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.' msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'
args = sys.argv[1:]
while args and args[0][0] == '-':
del args[0]
safe_command = args and args[0] in safe_commands
if not safe_command:
if _broken_module_imports('requirements.txt'): if _broken_module_imports('requirements.txt'):
if yesno('Would you like to install the required Python modules?'): if yesno('Would you like to install the required Python modules?'):
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt') _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
@@ -117,12 +173,7 @@ if _broken_module_imports('requirements.txt'):
print() print()
exit(1) exit(1)
if cli.config.user.developer: if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'):
args = sys.argv[1:]
while args and args[0][0] == '-':
del args[0]
if not args or args[0] != 'config':
if _broken_module_imports('requirements-dev.txt'):
if yesno('Would you like to install the required developer Python modules?'): if yesno('Would you like to install the required developer Python modules?'):
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt') _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt')
elif yesno('Would you like to disable developer mode?'): elif yesno('Would you like to disable developer mode?'):
@@ -135,26 +186,12 @@ if cli.config.user.developer:
exit(1) exit(1)
# Import our subcommands # Import our subcommands
from . import bux # noqa for subcommand in subcommands:
from . import c2json # noqa try:
from . import cformat # noqa __import__(subcommand)
from . import chibios # noqa
from . import clean # noqa except ModuleNotFoundError as e:
from . import compile # noqa if safe_command:
from milc.subcommand import config # noqa print(f'Warning: Could not import {subcommand}: {e.__class__.__name__}, {e}')
from . import docs # noqa else:
from . import doctor # noqa raise
from . import fileformat # noqa
from . import flash # noqa
from . import format # noqa
from . import generate # noqa
from . import hello # noqa
from . import info # noqa
from . import json2c # noqa
from . import lint # noqa
from . import list # noqa
from . import kle2json # noqa
from . import multibuild # noqa
from . import new # noqa
from . import pyformat # noqa
from . import pytest # noqa

View File

@@ -1 +0,0 @@
from . import confmigrate

View File

@@ -0,0 +1,302 @@
"""Acquire debugging information from usb hid devices
cli implementation of https://www.pjrc.com/teensy/hid_listen.html
"""
from pathlib import Path
from threading import Thread
from time import sleep, strftime
import hid
import usb.core
from milc import cli
LOG_COLOR = {
'next': 0,
'colors': [
'{fg_blue}',
'{fg_cyan}',
'{fg_green}',
'{fg_magenta}',
'{fg_red}',
'{fg_yellow}',
],
}
KNOWN_BOOTLOADERS = {
# VID , PID
('03EB', '2FEF'): 'atmel-dfu: ATmega16U2',
('03EB', '2FF0'): 'atmel-dfu: ATmega32U2',
('03EB', '2FF3'): 'atmel-dfu: ATmega16U4',
('03EB', '2FF4'): 'atmel-dfu: ATmega32U4',
('03EB', '2FF9'): 'atmel-dfu: AT90USB64',
('03EB', '2FFA'): 'atmel-dfu: AT90USB162',
('03EB', '2FFB'): 'atmel-dfu: AT90USB128',
('03EB', '6124'): 'Microchip SAM-BA',
('0483', 'DF11'): 'stm32-dfu: STM32 BOOTLOADER',
('16C0', '05DC'): 'USBasp: USBaspLoader',
('16C0', '05DF'): 'bootloadHID: HIDBoot',
('16C0', '0478'): 'halfkay: Teensy Halfkay',
('1B4F', '9203'): 'caterina: Pro Micro 3.3V',
('1B4F', '9205'): 'caterina: Pro Micro 5V',
('1B4F', '9207'): 'caterina: LilyPadUSB',
('1C11', 'B007'): 'kiibohd: Kiibohd DFU Bootloader',
('1EAF', '0003'): 'stm32duino: Maple 003',
('1FFB', '0101'): 'caterina: Polou A-Star 32U4 Bootloader',
('2341', '0036'): 'caterina: Arduino Leonardo',
('2341', '0037'): 'caterina: Arduino Micro',
('239A', '000C'): 'caterina: Adafruit Feather 32U4',
('239A', '000D'): 'caterina: Adafruit ItsyBitsy 32U4 3v',
('239A', '000E'): 'caterina: Adafruit ItsyBitsy 32U4 5v',
('239A', '000E'): 'caterina: Adafruit ItsyBitsy 32U4 5v',
('2A03', '0036'): 'caterina: Arduino Leonardo',
('2A03', '0037'): 'caterina: Arduino Micro',
('314B', '0106'): 'apm32-dfu: APM32 DFU ISP Mode'
}
class MonitorDevice(object):
def __init__(self, hid_device, numeric):
self.hid_device = hid_device
self.numeric = numeric
self.device = hid.Device(path=hid_device['path'])
self.current_line = ''
cli.log.info('Console Connected: %(color)s%(manufacturer_string)s %(product_string)s{style_reset_all} (%(color)s%(vendor_id)04X:%(product_id)04X:%(index)d{style_reset_all})', hid_device)
def read(self, size, encoding='ascii', timeout=1):
"""Read size bytes from the device.
"""
return self.device.read(size, timeout).decode(encoding)
def read_line(self):
"""Read from the device's console until we get a \n.
"""
while '\n' not in self.current_line:
self.current_line += self.read(32).replace('\x00', '')
lines = self.current_line.split('\n', 1)
self.current_line = lines[1]
return lines[0]
def run_forever(self):
while True:
try:
message = {**self.hid_device, 'text': self.read_line()}
identifier = (int2hex(message['vendor_id']), int2hex(message['product_id'])) if self.numeric else (message['manufacturer_string'], message['product_string'])
message['identifier'] = ':'.join(identifier)
message['ts'] = '{style_dim}{fg_green}%s{style_reset_all} ' % (strftime(cli.config.general.datetime_fmt),) if cli.args.timestamp else ''
cli.echo('%(ts)s%(color)s%(identifier)s:%(index)d{style_reset_all}: %(text)s' % message)
except hid.HIDException:
break
class FindDevices(object):
def __init__(self, vid, pid, index, numeric):
self.vid = vid
self.pid = pid
self.index = index
self.numeric = numeric
def run_forever(self):
"""Process messages from our queue in a loop.
"""
live_devices = {}
live_bootloaders = {}
while True:
try:
for device in list(live_devices):
if not live_devices[device]['thread'].is_alive():
cli.log.info('Console Disconnected: %(color)s%(manufacturer_string)s %(product_string)s{style_reset_all} (%(color)s%(vendor_id)04X:%(product_id)04X:%(index)d{style_reset_all})', live_devices[device])
del live_devices[device]
for device in self.find_devices():
if device['path'] not in live_devices:
device['color'] = LOG_COLOR['colors'][LOG_COLOR['next']]
LOG_COLOR['next'] = (LOG_COLOR['next'] + 1) % len(LOG_COLOR['colors'])
live_devices[device['path']] = device
try:
monitor = MonitorDevice(device, self.numeric)
device['thread'] = Thread(target=monitor.run_forever, daemon=True)
device['thread'].start()
except Exception as e:
device['e'] = e
device['e_name'] = e.__class__.__name__
cli.log.error("Could not connect to %(color)s%(manufacturer_string)s %(product_string)s{style_reset_all} (%(color)s:%(vendor_id)04X:%(product_id)04X:%(index)d): %(e_name)s: %(e)s", device)
if cli.config.general.verbose:
cli.log.exception(e)
del live_devices[device['path']]
if cli.args.bootloaders:
for device in self.find_bootloaders():
if device.address in live_bootloaders:
live_bootloaders[device.address]._qmk_found = True
else:
name = KNOWN_BOOTLOADERS[(int2hex(device.idVendor), int2hex(device.idProduct))]
cli.log.info('Bootloader Connected: {style_bright}{fg_magenta}%s', name)
device._qmk_found = True
live_bootloaders[device.address] = device
for device in list(live_bootloaders):
if live_bootloaders[device]._qmk_found:
live_bootloaders[device]._qmk_found = False
else:
name = KNOWN_BOOTLOADERS[(int2hex(live_bootloaders[device].idVendor), int2hex(live_bootloaders[device].idProduct))]
cli.log.info('Bootloader Disconnected: {style_bright}{fg_magenta}%s', name)
del live_bootloaders[device]
sleep(.1)
except KeyboardInterrupt:
break
def is_bootloader(self, hid_device):
"""Returns true if the device in question matches a known bootloader vid/pid.
"""
return (int2hex(hid_device.idVendor), int2hex(hid_device.idProduct)) in KNOWN_BOOTLOADERS
def is_console_hid(self, hid_device):
"""Returns true when the usage page indicates it's a teensy-style console.
"""
return hid_device['usage_page'] == 0xFF31 and hid_device['usage'] == 0x0074
def is_filtered_device(self, hid_device):
"""Returns True if the device should be included in the list of available consoles.
"""
return int2hex(hid_device['vendor_id']) == self.vid and int2hex(hid_device['product_id']) == self.pid
def find_devices_by_report(self, hid_devices):
"""Returns a list of available teensy-style consoles by doing a brute-force search.
Some versions of linux don't report usage and usage_page. In that case we fallback to reading the report (possibly inaccurately) ourselves.
"""
devices = []
for device in hid_devices:
path = device['path'].decode('utf-8')
if path.startswith('/dev/hidraw'):
number = path[11:]
report = Path(f'/sys/class/hidraw/hidraw{number}/device/report_descriptor')
if report.exists():
rp = report.read_bytes()
if rp[1] == 0x31 and rp[3] == 0x09:
devices.append(device)
return devices
def find_bootloaders(self):
"""Returns a list of available bootloader devices.
"""
return list(filter(self.is_bootloader, usb.core.find(find_all=True)))
def find_devices(self):
"""Returns a list of available teensy-style consoles.
"""
hid_devices = hid.enumerate()
devices = list(filter(self.is_console_hid, hid_devices))
if not devices:
devices = self.find_devices_by_report(hid_devices)
if self.vid and self.pid:
devices = list(filter(self.is_filtered_device, devices))
# Add index numbers
device_index = {}
for device in devices:
id = ':'.join((int2hex(device['vendor_id']), int2hex(device['product_id'])))
if id not in device_index:
device_index[id] = 0
device_index[id] += 1
device['index'] = device_index[id]
return devices
def int2hex(number):
"""Returns a string representation of the number as hex.
"""
return "%04X" % number
def list_devices(device_finder):
"""Show the user a nicely formatted list of devices.
"""
devices = device_finder.find_devices()
if devices:
cli.log.info('Available devices:')
for dev in devices:
color = LOG_COLOR['colors'][LOG_COLOR['next']]
LOG_COLOR['next'] = (LOG_COLOR['next'] + 1) % len(LOG_COLOR['colors'])
cli.log.info("\t%s%s:%s:%d{style_reset_all}\t%s %s", color, int2hex(dev['vendor_id']), int2hex(dev['product_id']), dev['index'], dev['manufacturer_string'], dev['product_string'])
if cli.args.bootloaders:
bootloaders = device_finder.find_bootloaders()
if bootloaders:
cli.log.info('Available Bootloaders:')
for dev in bootloaders:
cli.log.info("\t%s:%s\t%s", int2hex(dev.idVendor), int2hex(dev.idProduct), KNOWN_BOOTLOADERS[(int2hex(dev.idVendor), int2hex(dev.idProduct))])
@cli.argument('--bootloaders', arg_only=True, default=True, action='store_boolean', help='displaying bootloaders.')
@cli.argument('-d', '--device', help='Device to select - uses format <pid>:<vid>[:<index>].')
@cli.argument('-l', '--list', arg_only=True, action='store_true', help='List available hid_listen devices.')
@cli.argument('-n', '--numeric', arg_only=True, action='store_true', help='Show VID/PID instead of names.')
@cli.argument('-t', '--timestamp', arg_only=True, action='store_true', help='Print the timestamp for received messages as well.')
@cli.argument('-w', '--wait', type=int, default=1, help="How many seconds to wait between checks (Default: 1)")
@cli.subcommand('Acquire debugging information from usb hid devices.', hidden=False if cli.config.user.developer else True)
def console(cli):
"""Acquire debugging information from usb hid devices
"""
vid = None
pid = None
index = 1
if cli.config.console.device:
device = cli.config.console.device.split(':')
if len(device) == 2:
vid, pid = device
elif len(device) == 3:
vid, pid, index = device
if not index.isdigit():
cli.log.error('Device index must be a number! Got "%s" instead.', index)
exit(1)
index = int(index)
if index < 1:
cli.log.error('Device index must be greater than 0! Got %s', index)
exit(1)
else:
cli.log.error('Invalid format for device, expected "<pid>:<vid>[:<index>]" but got "%s".', cli.config.console.device)
cli.print_help()
exit(1)
vid = vid.upper()
pid = pid.upper()
device_finder = FindDevices(vid, pid, index, cli.args.numeric)
if cli.args.list:
return list_devices(device_finder)
print('Looking for devices...', flush=True)
device_finder.run_forever()

View File

@@ -1 +0,0 @@
from . import json

View File

@@ -1,9 +0,0 @@
from . import api
from . import config_h
from . import dfu_header
from . import docs
from . import info_json
from . import keyboard_h
from . import layouts
from . import rgb_breathe_table
from . import rules_mk

View File

@@ -85,7 +85,9 @@ def generate_layouts(cli):
for alias, target in kb_info_json.get('layout_aliases', {}).items(): for alias, target in kb_info_json.get('layout_aliases', {}).items():
layouts_h_lines.append('') layouts_h_lines.append('')
layouts_h_lines.append('#define %s %s' % (alias, target)) layouts_h_lines.append(f'#ifndef {alias}')
layouts_h_lines.append(f'# define {alias} {target}')
layouts_h_lines.append('#endif')
# Show the results # Show the results
layouts_h = '\n'.join(layouts_h_lines) + '\n' layouts_h = '\n'.join(layouts_h_lines) + '\n'

View File

@@ -1,2 +0,0 @@
from . import keyboards
from . import keymaps

View File

@@ -2,6 +2,7 @@
This will compile everything in parallel, for testing purposes. This will compile everything in parallel, for testing purposes.
""" """
import os
import re import re
from pathlib import Path from pathlib import Path
from subprocess import DEVNULL from subprocess import DEVNULL
@@ -11,6 +12,7 @@ from milc import cli
from qmk.constants import QMK_FIRMWARE from qmk.constants import QMK_FIRMWARE
from qmk.commands import _find_make from qmk.commands import _find_make
import qmk.keyboard import qmk.keyboard
import qmk.keymap
def _make_rules_mk_filter(key, value): def _make_rules_mk_filter(key, value):
@@ -29,6 +31,7 @@ def _is_split(keyboard_name):
@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.")
@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.") @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on the supplied value in rules.mk. Supported format is 'SPLIT_KEYBOARD=yes'. May be passed multiple times.") @cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on the supplied value in rules.mk. Supported format is 'SPLIT_KEYBOARD=yes'. May be passed multiple times.")
@cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.")
@cli.subcommand('Compile QMK Firmware for all keyboards.', hidden=False if cli.config.user.developer else True) @cli.subcommand('Compile QMK Firmware for all keyboards.', hidden=False if cli.config.user.developer else True)
def multibuild(cli): def multibuild(cli):
"""Compile QMK Firmware against all keyboards. """Compile QMK Firmware against all keyboards.
@@ -57,6 +60,7 @@ def multibuild(cli):
builddir.mkdir(parents=True, exist_ok=True) builddir.mkdir(parents=True, exist_ok=True)
with open(makefile, "w") as f: with open(makefile, "w") as f:
for keyboard_name in keyboard_list: for keyboard_name in keyboard_list:
if qmk.keymap.locate_keymap(keyboard_name, cli.args.keymap) is not None:
keyboard_safe = keyboard_name.replace('/', '_') keyboard_safe = keyboard_name.replace('/', '_')
# yapf: disable # yapf: disable
f.write( f.write(
@@ -64,16 +68,21 @@ def multibuild(cli):
all: {keyboard_safe}_binary all: {keyboard_safe}_binary
{keyboard_safe}_binary: {keyboard_safe}_binary:
@rm -f "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}" || true @rm -f "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}" || true
+@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="default" REQUIRE_PLATFORM_KEY= COLOR=true SILENT=false \\ +@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="{cli.args.keymap}" REQUIRE_PLATFORM_KEY= COLOR=true SILENT=false \\
>>"{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" 2>&1 \\ >>"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" 2>&1 \\
|| cp "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}" || cp "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" "{QMK_FIRMWARE}/.build/failed.log.{os.getpid()}.{keyboard_safe}"
@{{ grep '\[ERRORS\]' "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:default" ; }} \\ @{{ grep '\[ERRORS\]' "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:{cli.args.keymap}" ; }} \\
|| {{ grep '\[WARNINGS\]' "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;33m[WARNINGS]\e[0m\\n" "{keyboard_name}:default" ; }} \\ || {{ grep '\[WARNINGS\]' "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" >/dev/null 2>&1 && printf "Build %-64s \e[1;33m[WARNINGS]\e[0m\\n" "{keyboard_name}:{cli.args.keymap}" ; }} \\
|| printf "Build %-64s \e[1;32m[OK]\e[0m\\n" "{keyboard_name}:default" || printf "Build %-64s \e[1;32m[OK]\e[0m\\n" "{keyboard_name}:{cli.args.keymap}"
@rm -f "{QMK_FIRMWARE}/.build/build.log.{keyboard_safe}" || true @rm -f "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}" || true
"""# noqa """# noqa
) )
# yapf: enable # yapf: enable
cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile, 'all'], capture_output=False, stdin=DEVNULL) cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile.as_posix(), 'all'], capture_output=False, stdin=DEVNULL)
# Check for failures
failures = [f for f in builddir.glob(f'failed.log.{os.getpid()}.*')]
if len(failures) > 0:
return False

View File

@@ -1,2 +0,0 @@
from . import keyboard
from . import keymap

View File

@@ -201,6 +201,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va
f'VERBOSE={verbose}', f'VERBOSE={verbose}',
f'COLOR={color}', f'COLOR={color}',
'SILENT=false', 'SILENT=false',
f'QMK_BIN={"bin/qmk" if "DEPRECATED_BIN_QMK" in os.environ else "qmk"}',
]) ])
return make_command return make_command

View File

@@ -10,7 +10,7 @@ QMK_FIRMWARE = Path.cwd()
MAX_KEYBOARD_SUBFOLDERS = 5 MAX_KEYBOARD_SUBFOLDERS = 5
# Supported processor types # Supported processor types
CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F411', 'STM32G431', 'STM32G474' CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK66F18', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L433', 'STM32L443'
LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None
VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85'

View File

@@ -17,12 +17,12 @@ def automagic_keyboard(func):
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
# Ensure that `--keyboard` was not passed and CWD is under `qmk_firmware/keyboards` # Ensure that `--keyboard` was not passed and CWD is under `qmk_firmware/keyboards`
if cli.config_source[cli._entrypoint.__name__]['keyboard'] != 'argument': if cli.config_source[cli._subcommand.__name__]['keyboard'] != 'argument':
keyboard = find_keyboard_from_dir() keyboard = find_keyboard_from_dir()
if keyboard: if keyboard:
cli.config[cli._entrypoint.__name__]['keyboard'] = keyboard cli.config[cli._subcommand.__name__]['keyboard'] = keyboard
cli.config_source[cli._entrypoint.__name__]['keyboard'] = 'keyboard_directory' cli.config_source[cli._subcommand.__name__]['keyboard'] = 'keyboard_directory'
return func(*args, **kwargs) return func(*args, **kwargs)
@@ -37,12 +37,12 @@ def automagic_keymap(func):
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
# Ensure that `--keymap` was not passed and that we're under `qmk_firmware` # Ensure that `--keymap` was not passed and that we're under `qmk_firmware`
if cli.config_source[cli._entrypoint.__name__]['keymap'] != 'argument': if cli.config_source[cli._subcommand.__name__]['keymap'] != 'argument':
keymap_name, keymap_type = find_keymap_from_dir() keymap_name, keymap_type = find_keymap_from_dir()
if keymap_name: if keymap_name:
cli.config[cli._entrypoint.__name__]['keymap'] = keymap_name cli.config[cli._subcommand.__name__]['keymap'] = keymap_name
cli.config_source[cli._entrypoint.__name__]['keymap'] = keymap_type cli.config_source[cli._subcommand.__name__]['keymap'] = keymap_type
return func(*args, **kwargs) return func(*args, **kwargs)

View File

@@ -7,7 +7,7 @@ is_windows = 'windows' in platform.platform().lower()
def check_subcommand(command, *args): def check_subcommand(command, *args):
cmd = ['bin/qmk', command, *args] cmd = ['qmk', command, *args]
result = cli.run(cmd, stdin=DEVNULL, combined_output=True) result = cli.run(cmd, stdin=DEVNULL, combined_output=True)
return result return result
@@ -16,7 +16,7 @@ def check_subcommand_stdin(file_to_read, command, *args):
"""Pipe content of a file to a command and return output. """Pipe content of a file to a command and return output.
""" """
with open(file_to_read, encoding='utf-8') as my_file: with open(file_to_read, encoding='utf-8') as my_file:
cmd = ['bin/qmk', command, *args] cmd = ['qmk', command, *args]
result = cli.run(cmd, stdin=my_file, combined_output=True) result = cli.run(cmd, stdin=my_file, combined_output=True)
return result return result

View File

@@ -47,10 +47,12 @@ MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF: MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for flashing: MSG_FLASH = Creating load file for flashing:
MSG_UF2 = Creating UF2 file for deployment:
MSG_EEPROM = Creating load file for EEPROM: MSG_EEPROM = Creating load file for EEPROM:
MSG_BIN = Creating binary load file for flashing: MSG_BIN = Creating binary load file for flashing:
MSG_EXTENDED_LISTING = Creating Extended Listing: MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table: MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_EXECUTING = Executing:
MSG_LINKING = Linking: MSG_LINKING = Linking:
MSG_COMPILING = Compiling: MSG_COMPILING = Compiling:
MSG_COMPILING_CXX = Compiling: MSG_COMPILING_CXX = Compiling:
@@ -86,8 +88,10 @@ MSG_FILE_TOO_BIG = $(ERROR_COLOR)The firmware is too large!$(NO_COLOR) $(CURRENT
MSG_FILE_TOO_SMALL = The firmware is too small! $(CURRENT_SIZE)/$(MAX_SIZE)\n MSG_FILE_TOO_SMALL = The firmware is too small! $(CURRENT_SIZE)/$(MAX_SIZE)\n
MSG_FILE_JUST_RIGHT = The firmware size is fine - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n MSG_FILE_JUST_RIGHT = The firmware size is fine - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n
MSG_FILE_NEAR_LIMIT = The firmware size is approaching the maximum - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n MSG_FILE_NEAR_LIMIT = The firmware size is approaching the maximum - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n
MSG_PYTHON_MISSING = $(ERROR_COLOR)ERROR:$(NO_COLOR) Can not run bin/qmk!\n\n\ MSG_PYTHON_MISSING = $(ERROR_COLOR)ERROR:$(NO_COLOR) Can not run \"qmk\" command!\n\n\
Please run $(BOLD)util/qmk_install.sh$(NO_COLOR) to install all the dependencies QMK requires.\n\n Please run $(BOLD)util/qmk_install.sh$(NO_COLOR) to install all the dependencies QMK requires.\n\n
MSG_FLASH_BOOTLOADER = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's bootloader is not specified or is not supported by the \":flash\" target at this time.\n\n MSG_FLASH_BOOTLOADER = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's bootloader is not specified or is not supported by the \":flash\" target at this time.\n\n
MSG_FLASH_ARCH = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's architecture is not supported by the \":flash\" target at this time.\n\n MSG_FLASH_ARCH = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's architecture is not supported by the \":flash\" target at this time.\n\n
MSG_BOOTLOADER_NOT_FOUND = $(ERROR_COLOR)ERROR:$(NO_COLOR) Bootloader not found. Trying again in 5s.\n MSG_BOOTLOADER_NOT_FOUND = $(ERROR_COLOR)ERROR:$(NO_COLOR) Bootloader not found. Trying again in 5s.\n
BOOTLOADER_RETRY_TIME ?= 0.5
MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY = Bootloader not found. Trying again every $(BOOTLOADER_RETRY_TIME)s

174
nix/poetry.lock generated
View File

@@ -8,7 +8,7 @@ python-versions = "*"
[[package]] [[package]]
name = "argcomplete" name = "argcomplete"
version = "1.12.2" version = "1.12.3"
description = "Bash tab completion for argparse" description = "Bash tab completion for argparse"
category = "main" category = "main"
optional = false optional = false
@@ -19,17 +19,17 @@ test = ["coverage", "flake8", "pexpect", "wheel"]
[[package]] [[package]]
name = "attrs" name = "attrs"
version = "20.3.0" version = "21.2.0"
description = "Classes Without Boilerplate" description = "Classes Without Boilerplate"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[package.extras] [package.extras]
dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "furo", "sphinx", "pre-commit"] dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"]
docs = ["furo", "sphinx", "zope.interface"] docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"]
tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"]
tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six"] tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"]
[[package]] [[package]]
name = "colorama" name = "colorama"
@@ -43,7 +43,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
name = "coverage" name = "coverage"
version = "5.5" version = "5.5"
description = "Code coverage measurement for Python" description = "Code coverage measurement for Python"
category = "dev" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
@@ -63,9 +63,9 @@ setuptools_scm = "*"
[[package]] [[package]]
name = "flake8" name = "flake8"
version = "3.9.0" version = "3.9.2"
description = "the modular source code checker: pep8 pyflakes and co" description = "the modular source code checker: pep8 pyflakes and co"
category = "dev" category = "main"
optional = false optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
@@ -85,6 +85,32 @@ python-versions = "*"
[package.dependencies] [package.dependencies]
flake8 = "*" flake8 = "*"
[[package]]
name = "halo"
version = "0.0.31"
description = "Beautiful terminal spinners in Python"
category = "main"
optional = false
python-versions = ">=3.4"
[package.dependencies]
colorama = ">=0.3.9"
log-symbols = ">=0.0.14"
six = ">=1.12.0"
spinners = ">=0.0.24"
termcolor = ">=1.1.0"
[package.extras]
ipython = ["IPython (==5.7.0)", "ipywidgets (==7.1.0)"]
[[package]]
name = "hid"
version = "1.0.4"
description = "ctypes bindings for hidapi"
category = "main"
optional = false
python-versions = "*"
[[package]] [[package]]
name = "hjson" name = "hjson"
version = "3.0.2" version = "3.0.2"
@@ -110,17 +136,28 @@ six = ">=1.11.0"
format = ["idna", "jsonpointer (>1.13)", "rfc3987", "strict-rfc3339", "webcolors"] format = ["idna", "jsonpointer (>1.13)", "rfc3987", "strict-rfc3339", "webcolors"]
format_nongpl = ["idna", "jsonpointer (>1.13)", "webcolors", "rfc3986-validator (>0.1.0)", "rfc3339-validator"] format_nongpl = ["idna", "jsonpointer (>1.13)", "webcolors", "rfc3986-validator (>0.1.0)", "rfc3339-validator"]
[[package]]
name = "log-symbols"
version = "0.0.14"
description = "Colored symbols for various log levels for Python"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
colorama = ">=0.3.9"
[[package]] [[package]]
name = "mccabe" name = "mccabe"
version = "0.6.1" version = "0.6.1"
description = "McCabe checker, plugin for flake8" description = "McCabe checker, plugin for flake8"
category = "dev" category = "main"
optional = false optional = false
python-versions = "*" python-versions = "*"
[[package]] [[package]]
name = "milc" name = "milc"
version = "1.3.0" version = "1.4.2"
description = "Opinionated Batteries-Included Python 3 CLI Framework." description = "Opinionated Batteries-Included Python 3 CLI Framework."
category = "main" category = "main"
optional = false optional = false
@@ -130,12 +167,14 @@ python-versions = "*"
appdirs = "*" appdirs = "*"
argcomplete = "*" argcomplete = "*"
colorama = "*" colorama = "*"
halo = "*"
spinners = "*"
[[package]] [[package]]
name = "nose2" name = "nose2"
version = "0.10.0" version = "0.10.0"
description = "unittest2 with plugins, the succesor to nose" description = "unittest2 with plugins, the succesor to nose"
category = "dev" category = "main"
optional = false optional = false
python-versions = "*" python-versions = "*"
@@ -162,7 +201,7 @@ flake8-polyfill = ">=1.0.2,<2"
name = "pycodestyle" name = "pycodestyle"
version = "2.7.0" version = "2.7.0"
description = "Python style guide checker" description = "Python style guide checker"
category = "dev" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
@@ -170,13 +209,13 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
name = "pyflakes" name = "pyflakes"
version = "2.3.1" version = "2.3.1"
description = "passive checker of Python programs" description = "passive checker of Python programs"
category = "dev" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]] [[package]]
name = "pygments" name = "pygments"
version = "2.8.1" version = "2.9.0"
description = "Pygments is a syntax highlighting package written in Python." description = "Pygments is a syntax highlighting package written in Python."
category = "main" category = "main"
optional = false optional = false
@@ -190,6 +229,34 @@ category = "main"
optional = false optional = false
python-versions = ">=3.5" python-versions = ">=3.5"
[[package]]
name = "pyusb"
version = "1.1.1"
description = "Python USB access module"
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "qmk"
version = "0.0.51"
description = "A program to help users work with QMK Firmware."
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
dotty-dict = "*"
flake8 = "*"
hid = "*"
hjson = "*"
jsonschema = ">=3"
milc = ">=1.4.0"
nose2 = "*"
pygments = "*"
pyusb = "*"
yapf = "*"
[[package]] [[package]]
name = "setuptools-scm" name = "setuptools-scm"
version = "6.0.1" version = "6.0.1"
@@ -203,17 +270,25 @@ toml = ["toml"]
[[package]] [[package]]
name = "six" name = "six"
version = "1.15.0" version = "1.16.0"
description = "Python 2 and 3 compatibility utilities" description = "Python 2 and 3 compatibility utilities"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]] [[package]]
name = "wave" name = "spinners"
version = "0.0.2" version = "0.0.24"
description = "Whole Architecture Verification" description = "Spinners for terminals"
category = "dev" category = "main"
optional = false
python-versions = "*"
[[package]]
name = "termcolor"
version = "1.1.0"
description = "ANSII Color formatting for output in terminal."
category = "main"
optional = false optional = false
python-versions = "*" python-versions = "*"
@@ -221,14 +296,14 @@ python-versions = "*"
name = "yapf" name = "yapf"
version = "0.30.0" version = "0.30.0"
description = "A formatter for Python code." description = "A formatter for Python code."
category = "dev" category = "main"
optional = false optional = false
python-versions = "*" python-versions = "*"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.8" python-versions = "^3.8"
content-hash = "6adb87c61d9eacf55e4e80bc6c73325e4e4854a792e3881ff448b6ee1cb75091" content-hash = "5e181d51536240d08c74ba6a46bd0988ee4ca72ac3d5b388965ca8023e9b9a99"
[metadata.files] [metadata.files]
appdirs = [ appdirs = [
@@ -236,12 +311,12 @@ appdirs = [
{file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
] ]
argcomplete = [ argcomplete = [
{file = "argcomplete-1.12.2-py2.py3-none-any.whl", hash = "sha256:17f01a9b9b9ece3e6b07058eae737ad6e10de8b4e149105f84614783913aba71"}, {file = "argcomplete-1.12.3-py2.py3-none-any.whl", hash = "sha256:291f0beca7fd49ce285d2f10e4c1c77e9460cf823eef2de54df0c0fec88b0d81"},
{file = "argcomplete-1.12.2.tar.gz", hash = "sha256:de0e1282330940d52ea92a80fea2e4b9e0da1932aaa570f84d268939d1897b04"}, {file = "argcomplete-1.12.3.tar.gz", hash = "sha256:2c7dbffd8c045ea534921e63b0be6fe65e88599990d8dc408ac8c542b72a5445"},
] ]
attrs = [ attrs = [
{file = "attrs-20.3.0-py2.py3-none-any.whl", hash = "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6"}, {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"},
{file = "attrs-20.3.0.tar.gz", hash = "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"}, {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"},
] ]
colorama = [ colorama = [
{file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
@@ -305,13 +380,21 @@ dotty-dict = [
{file = "dotty_dict-1.3.0.tar.gz", hash = "sha256:eb0035a3629ecd84397a68f1f42f1e94abd1c34577a19cd3eacad331ee7cbaf0"}, {file = "dotty_dict-1.3.0.tar.gz", hash = "sha256:eb0035a3629ecd84397a68f1f42f1e94abd1c34577a19cd3eacad331ee7cbaf0"},
] ]
flake8 = [ flake8 = [
{file = "flake8-3.9.0-py2.py3-none-any.whl", hash = "sha256:12d05ab02614b6aee8df7c36b97d1a3b2372761222b19b58621355e82acddcff"}, {file = "flake8-3.9.2-py2.py3-none-any.whl", hash = "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907"},
{file = "flake8-3.9.0.tar.gz", hash = "sha256:78873e372b12b093da7b5e5ed302e8ad9e988b38b063b61ad937f26ca58fc5f0"}, {file = "flake8-3.9.2.tar.gz", hash = "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b"},
] ]
flake8-polyfill = [ flake8-polyfill = [
{file = "flake8-polyfill-1.0.2.tar.gz", hash = "sha256:e44b087597f6da52ec6393a709e7108b2905317d0c0b744cdca6208e670d8eda"}, {file = "flake8-polyfill-1.0.2.tar.gz", hash = "sha256:e44b087597f6da52ec6393a709e7108b2905317d0c0b744cdca6208e670d8eda"},
{file = "flake8_polyfill-1.0.2-py2.py3-none-any.whl", hash = "sha256:12be6a34ee3ab795b19ca73505e7b55826d5f6ad7230d31b18e106400169b9e9"}, {file = "flake8_polyfill-1.0.2-py2.py3-none-any.whl", hash = "sha256:12be6a34ee3ab795b19ca73505e7b55826d5f6ad7230d31b18e106400169b9e9"},
] ]
halo = [
{file = "halo-0.0.31-py2-none-any.whl", hash = "sha256:5350488fb7d2aa7c31a1344120cee67a872901ce8858f60da7946cef96c208ab"},
{file = "halo-0.0.31.tar.gz", hash = "sha256:7b67a3521ee91d53b7152d4ee3452811e1d2a6321975137762eb3d70063cc9d6"},
]
hid = [
{file = "hid-1.0.4-py2-none-any.whl", hash = "sha256:fba9913f07030b01059b822b24c83b370ca3f444e9e6443bd662f9f1aa3f0780"},
{file = "hid-1.0.4.tar.gz", hash = "sha256:f61b0382f37a334bc8ba8604bc84b94875ee4f594fbbaf82b2c3b3e827883fc1"},
]
hjson = [ hjson = [
{file = "hjson-3.0.2-py3-none-any.whl", hash = "sha256:5546438bf4e1b52bc964c6a47c4ed10fa5fba8a1b264e22efa893e333baad2db"}, {file = "hjson-3.0.2-py3-none-any.whl", hash = "sha256:5546438bf4e1b52bc964c6a47c4ed10fa5fba8a1b264e22efa893e333baad2db"},
{file = "hjson-3.0.2.tar.gz", hash = "sha256:2838fd7200e5839ea4516ece953f3a19892c41089f0d933ba3f68e596aacfcd5"}, {file = "hjson-3.0.2.tar.gz", hash = "sha256:2838fd7200e5839ea4516ece953f3a19892c41089f0d933ba3f68e596aacfcd5"},
@@ -320,13 +403,17 @@ jsonschema = [
{file = "jsonschema-3.2.0-py2.py3-none-any.whl", hash = "sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163"}, {file = "jsonschema-3.2.0-py2.py3-none-any.whl", hash = "sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163"},
{file = "jsonschema-3.2.0.tar.gz", hash = "sha256:c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"}, {file = "jsonschema-3.2.0.tar.gz", hash = "sha256:c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"},
] ]
log-symbols = [
{file = "log_symbols-0.0.14-py3-none-any.whl", hash = "sha256:4952106ff8b605ab7d5081dd2c7e6ca7374584eff7086f499c06edd1ce56dcca"},
{file = "log_symbols-0.0.14.tar.gz", hash = "sha256:cf0bbc6fe1a8e53f0d174a716bc625c4f87043cc21eb55dd8a740cfe22680556"},
]
mccabe = [ mccabe = [
{file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"},
{file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"},
] ]
milc = [ milc = [
{file = "milc-1.3.0-py2.py3-none-any.whl", hash = "sha256:a4dd8ce77f1d4ac5e08311eecc6954c349d4032d7ed4e0335822e09740514f22"}, {file = "milc-1.4.2-py2.py3-none-any.whl", hash = "sha256:65ee004caa769b1ee144b15be7908d1f623920ab6f356e5c5c95be9457aa15d8"},
{file = "milc-1.3.0.tar.gz", hash = "sha256:a9d0299aaaef7a3f00010589c3c0d0669798467e397580620a68e9290b36cdda"}, {file = "milc-1.4.2.tar.gz", hash = "sha256:c6b2f19e3196b00a0060f8c883533e356f2054a9f81692b7b97ccee0d01626fd"},
] ]
nose2 = [ nose2 = [
{file = "nose2-0.10.0-py2.py3-none-any.whl", hash = "sha256:aa620e759f2c5018d9ba041340391913e282ecebd3c392027f1575847b093ec6"}, {file = "nose2-0.10.0-py2.py3-none-any.whl", hash = "sha256:aa620e759f2c5018d9ba041340391913e282ecebd3c392027f1575847b093ec6"},
@@ -345,23 +432,34 @@ pyflakes = [
{file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"}, {file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"},
] ]
pygments = [ pygments = [
{file = "Pygments-2.8.1-py3-none-any.whl", hash = "sha256:534ef71d539ae97d4c3a4cf7d6f110f214b0e687e92f9cb9d2a3b0d3101289c8"}, {file = "Pygments-2.9.0-py3-none-any.whl", hash = "sha256:d66e804411278594d764fc69ec36ec13d9ae9147193a1740cd34d272ca383b8e"},
{file = "Pygments-2.8.1.tar.gz", hash = "sha256:2656e1a6edcdabf4275f9a3640db59fd5de107d88e8663c5d4e9a0fa62f77f94"}, {file = "Pygments-2.9.0.tar.gz", hash = "sha256:a18f47b506a429f6f4b9df81bb02beab9ca21d0a5fee38ed15aef65f0545519f"},
] ]
pyrsistent = [ pyrsistent = [
{file = "pyrsistent-0.17.3.tar.gz", hash = "sha256:2e636185d9eb976a18a8a8e96efce62f2905fea90041958d8cc2a189756ebf3e"}, {file = "pyrsistent-0.17.3.tar.gz", hash = "sha256:2e636185d9eb976a18a8a8e96efce62f2905fea90041958d8cc2a189756ebf3e"},
] ]
pyusb = [
{file = "pyusb-1.1.1-py3-none-any.whl", hash = "sha256:f18eb813d3a1439918071234589162c2f209a19adbeffeb1377ce078a4aebc70"},
{file = "pyusb-1.1.1.tar.gz", hash = "sha256:7d449ad916ce58aff60b89aae0b65ac130f289c24d6a5b7b317742eccffafc38"},
]
qmk = [
{file = "qmk-0.0.51-py2.py3-none-any.whl", hash = "sha256:5f676f389b2450b0956d7eb8e7e378d2e6690d5859a887c91876da0a5faf75ed"},
{file = "qmk-0.0.51.tar.gz", hash = "sha256:efeef209cde1df92b9823db686d9684962cd00aae9f45ba5e3d494aa5b3c6b9a"},
]
setuptools-scm = [ setuptools-scm = [
{file = "setuptools_scm-6.0.1-py3-none-any.whl", hash = "sha256:c3bd5f701c8def44a5c0bfe8d407bef3f80342217ef3492b951f3777bd2d915c"}, {file = "setuptools_scm-6.0.1-py3-none-any.whl", hash = "sha256:c3bd5f701c8def44a5c0bfe8d407bef3f80342217ef3492b951f3777bd2d915c"},
{file = "setuptools_scm-6.0.1.tar.gz", hash = "sha256:d1925a69cb07e9b29416a275b9fadb009a23c148ace905b2fb220649a6c18e92"}, {file = "setuptools_scm-6.0.1.tar.gz", hash = "sha256:d1925a69cb07e9b29416a275b9fadb009a23c148ace905b2fb220649a6c18e92"},
] ]
six = [ six = [
{file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"}, {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
] ]
wave = [ spinners = [
{file = "Wave-0.0.2.tar.gz", hash = "sha256:5a895bb85e04e38c82dba90d66a5ae8f488b50c58f3fc4df868a5bcdcabb8632"}, {file = "spinners-0.0.24-py3-none-any.whl", hash = "sha256:2fa30d0b72c9650ad12bbe031c9943b8d441e41b4f5602b0ec977a19f3290e98"},
{file = "Wave-0.0.2.zip", hash = "sha256:5187f49497287d218cc83d4cd1e5299dc31485ab3ed32abbaa9e95d8f73c4095"}, {file = "spinners-0.0.24.tar.gz", hash = "sha256:1eb6aeb4781d72ab42ed8a01dcf20f3002bf50740d7154d12fb8c9769bf9e27f"},
]
termcolor = [
{file = "termcolor-1.1.0.tar.gz", hash = "sha256:1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b"},
] ]
yapf = [ yapf = [
{file = "yapf-0.30.0-py2.py3-none-any.whl", hash = "sha256:3abf61ba67cf603069710d30acbc88cfe565d907e16ad81429ae90ce9651e0c9"}, {file = "yapf-0.30.0-py2.py3-none-any.whl", hash = "sha256:3abf61ba67cf603069710d30acbc88cfe565d907e16ad81429ae90ce9651e0c9"},

View File

@@ -2,7 +2,7 @@
# It is particularly required by the Nix environment (see shell.nix). To update versions, # It is particularly required by the Nix environment (see shell.nix). To update versions,
# normally one would run "poetry update --lock" # normally one would run "poetry update --lock"
[tool.poetry] [tool.poetry]
name = "qmk" name = "qmk_firmware"
version = "0.1.0" version = "0.1.0"
description = "" description = ""
authors = [] authors = []
@@ -12,18 +12,20 @@ python = "^3.8"
appdirs = "^1.4.4" appdirs = "^1.4.4"
argcomplete = "^1.12.2" argcomplete = "^1.12.2"
colorama = "^0.4.4" colorama = "^0.4.4"
hjson = "^3.0.2"
milc = "^1.1.0"
Pygments = "^2.8.0"
dotty-dict = "^1.3.0" dotty-dict = "^1.3.0"
hjson = "^3.0.2"
jsonschema = "^3.2.0" jsonschema = "^3.2.0"
milc = "^1.3.0"
Pygments = "^2.8.0"
qmk = "*"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
nose2 = "^0.10.0" nose2 = "^0.10.0"
flake8 = "^3.8.4" flake8 = "^3.8.4"
hid = "^1.0.4"
pep8-naming = "^0.11.1" pep8-naming = "^0.11.1"
pyusb = "^1.1.1"
yapf = "^0.30.0" yapf = "^0.30.0"
Wave = "^0.0.2"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]

View File

@@ -22,5 +22,17 @@
"type": "tarball", "type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/c0e881852006b132236cbf0301bd1939bb50867e.tar.gz", "url": "https://github.com/NixOS/nixpkgs/archive/c0e881852006b132236cbf0301bd1939bb50867e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"poetry2nix": {
"branch": "master",
"description": "Convert poetry projects to nix automagically [maintainer=@adisbladis] ",
"homepage": "",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "2d27d44397242b28c3f0081e0432e4f6c951f3a1",
"sha256": "06syfg150r59m4kksj5547b5kwxjxjaif5hiljcq966kb9hxsvmv",
"type": "tarball",
"url": "https://github.com/nix-community/poetry2nix/archive/2d27d44397242b28c3f0081e0432e4f6c951f3a1.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
} }
} }

View File

@@ -0,0 +1,5 @@
/* Address for jumping to bootloader on STM32 chips. */
/* It is chip dependent, the correct number can be looked up here:
* http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
*/
#define STM32_BOOTLOADER_ADDRESS 0x1FFF0000

View File

@@ -0,0 +1,5 @@
/* Address for jumping to bootloader on STM32 chips. */
/* It is chip dependent, the correct number can be looked up here:
* http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
*/
#define STM32_BOOTLOADER_ADDRESS 0x1FFF0000

View File

@@ -0,0 +1,89 @@
/*
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.
*/
/*
* STM32F411xC memory setup.
*/
MEMORY
{
flash0 (rx) : org = 0x08000000 + 64k, len = 256k - 64k /* tinyuf2 bootloader requires app to be located at 64k offset for this MCU */
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 = 128k
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
/* TinyUF2 bootloader reset support */
_board_dfu_dbl_tap = ORIGIN(ram0) + 64k - 4; /* this is based off the linker file for tinyuf2 */

View File

@@ -0,0 +1,89 @@
/*
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.
*/
/*
* STM32F411xE memory setup.
*/
MEMORY
{
flash0 (rx) : org = 0x08000000 + 64k, len = 512k - 64k /* tinyuf2 bootloader requires app to be located at 64k offset for this MCU */
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 = 128k
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
/* TinyUF2 bootloader reset support */
_board_dfu_dbl_tap = ORIGIN(ram0) + 64k - 4; /* this is based off the linker file for tinyuf2 */

View File

@@ -0,0 +1,9 @@
# List of all the board related files.
BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_F446RE/board.c
# Required include directories
BOARDINC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_F446RE
# Shared variables
ALLCSRC += $(BOARDSRC)
ALLINC += $(BOARDINC)

View File

@@ -0,0 +1,24 @@
/* Copyright 2020 Nick Brassel (tzarc)
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#define STM32_HSECLK 16000000
// The following is required to disable the pull-down on PA9, when PA9 is used for the keyboard matrix:
#define BOARD_OTG_NOVBUSSENS
#include_next "board.h"
#undef STM32_HSE_BYPASS

View File

@@ -0,0 +1,23 @@
/* Copyright 2021 Andrei Purdea
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* Address for jumping to bootloader on STM32 chips. */
/* It is chip dependent, the correct number can be looked up by checking against ST's application note AN2606.
*/
#define STM32_BOOTLOADER_ADDRESS 0x1FFF0000
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE
#endif

View File

@@ -0,0 +1,361 @@
/*
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.
*/
#ifndef MCUCONF_H
#define MCUCONF_H
/*
* STM32F4xx 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 STM32F4xx_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 8
#define STM32_PLLN_VALUE 180
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 7
#define STM32_PLLI2SN_VALUE 192
#define STM32_PLLI2SM_VALUE 8
#define STM32_PLLI2SR_VALUE 4
#define STM32_PLLI2SP_VALUE 4
#define STM32_PLLI2SQ_VALUE 4
#define STM32_PLLSAIN_VALUE 192
#define STM32_PLLSAIM_VALUE 8
#define STM32_PLLSAIP_VALUE 8
#define STM32_PLLSAIQ_VALUE 4
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV4
#define STM32_PPRE2 STM32_PPRE2_DIV2
#define STM32_RTCSEL STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE 8
#define STM32_MCO1SEL STM32_MCO1SEL_HSE
#define STM32_MCO1PRE STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL STM32_MCO2SEL_PLLI2S
#define STM32_MCO2PRE STM32_MCO2PRE_DIV1
#define STM32_I2SSRC STM32_I2SSRC_PLLI2S
#define STM32_SAI1SEL STM32_SAI2SEL_PLLR
#define STM32_SAI2SEL STM32_SAI2SEL_PLLR
#define STM32_CK48MSEL STM32_CK48MSEL_PLLALT
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE FALSE
/*
* 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 15
#define STM32_IRQ_EXTI18_PRIORITY 6
#define STM32_IRQ_EXTI19_PRIORITY 6
#define STM32_IRQ_EXTI20_PRIORITY 6
#define STM32_IRQ_EXTI21_PRIORITY 15
#define STM32_IRQ_EXTI22_PRIORITY 15
/*
* ADC driver system settings.
*/
#define STM32_ADC_ADCPRE ADC_CCR_ADCPRE_DIV4
#define STM32_ADC_USE_ADC1 FALSE
#define STM32_ADC_USE_ADC2 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
#define STM32_ADC_ADC1_DMA_PRIORITY 2
#define STM32_ADC_ADC2_DMA_PRIORITY 2
#define STM32_ADC_ADC3_DMA_PRIORITY 2
#define STM32_ADC_IRQ_PRIORITY 6
#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 6
#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY 6
#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY 6
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_USE_CAN2 FALSE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
#define STM32_CAN_CAN2_IRQ_PRIORITY 11
/*
* 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(1, 5)
#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
/*
* 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_TIM9 FALSE
#define STM32_GPT_USE_TIM11 FALSE
#define STM32_GPT_USE_TIM12 FALSE
#define STM32_GPT_USE_TIM14 FALSE
#define STM32_GPT_TIM1_IRQ_PRIORITY 7
#define STM32_GPT_TIM2_IRQ_PRIORITY 7
#define STM32_GPT_TIM3_IRQ_PRIORITY 7
#define STM32_GPT_TIM4_IRQ_PRIORITY 7
#define STM32_GPT_TIM5_IRQ_PRIORITY 7
#define STM32_GPT_TIM6_IRQ_PRIORITY 7
#define STM32_GPT_TIM7_IRQ_PRIORITY 7
#define STM32_GPT_TIM8_IRQ_PRIORITY 7
#define STM32_GPT_TIM9_IRQ_PRIORITY 7
#define STM32_GPT_TIM11_IRQ_PRIORITY 7
#define STM32_GPT_TIM12_IRQ_PRIORITY 7
#define STM32_GPT_TIM14_IRQ_PRIORITY 7
/*
* 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_BUSY_TIMEOUT 50
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2C_I2C1_IRQ_PRIORITY 5
#define STM32_I2C_I2C2_IRQ_PRIORITY 5
#define STM32_I2C_I2C3_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_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
/*
* I2S driver system settings.
*/
#define STM32_I2S_USE_SPI2 FALSE
#define STM32_I2S_USE_SPI3 FALSE
#define STM32_I2S_SPI2_IRQ_PRIORITY 10
#define STM32_I2S_SPI3_IRQ_PRIORITY 10
#define STM32_I2S_SPI2_DMA_PRIORITY 1
#define STM32_I2S_SPI3_DMA_PRIORITY 1
#define STM32_I2S_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_I2S_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2S_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2S_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2S_DMA_ERROR_HOOK(i2sp) 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_TIM9 FALSE
#define STM32_ICU_TIM1_IRQ_PRIORITY 7
#define STM32_ICU_TIM2_IRQ_PRIORITY 7
#define STM32_ICU_TIM3_IRQ_PRIORITY 7
#define STM32_ICU_TIM4_IRQ_PRIORITY 7
#define STM32_ICU_TIM5_IRQ_PRIORITY 7
#define STM32_ICU_TIM8_IRQ_PRIORITY 7
#define STM32_ICU_TIM9_IRQ_PRIORITY 7
/*
* 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_ADVANCED FALSE
#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_TIM9 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
#define STM32_PWM_TIM2_IRQ_PRIORITY 7
#define STM32_PWM_TIM3_IRQ_PRIORITY 7
#define STM32_PWM_TIM4_IRQ_PRIORITY 7
#define STM32_PWM_TIM5_IRQ_PRIORITY 7
#define STM32_PWM_TIM8_IRQ_PRIORITY 7
#define STM32_PWM_TIM9_IRQ_PRIORITY 7
/*
* SDC driver system settings.
*/
#define STM32_SDC_SDIO_DMA_PRIORITY 3
#define STM32_SDC_SDIO_IRQ_PRIORITY 9
#define STM32_SDC_WRITE_TIMEOUT_MS 1000
#define STM32_SDC_READ_TIMEOUT_MS 1000
#define STM32_SDC_CLOCK_ACTIVATION_DELAY 10
#define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
#define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
/*
* 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_USART1_PRIORITY 12
#define STM32_SERIAL_USART2_PRIORITY 12
#define STM32_SERIAL_USART3_PRIORITY 12
#define STM32_SERIAL_UART4_PRIORITY 12
#define STM32_SERIAL_UART5_PRIORITY 12
#define STM32_SERIAL_USART6_PRIORITY 12
#define STM32_SERIAL_UART7_PRIORITY 12
#define STM32_SERIAL_UART8_PRIORITY 12
/*
* 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_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0)
#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_SPI_SPI4_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0)
#define STM32_SPI_SPI4_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
#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_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_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
/*
* ST driver system settings.
*/
#define STM32_ST_IRQ_PRIORITY 8
#define STM32_ST_USE_TIMER 2
/*
* 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_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART1_IRQ_PRIORITY 12
#define STM32_UART_USART2_IRQ_PRIORITY 12
#define STM32_UART_USART3_IRQ_PRIORITY 12
#define STM32_UART_UART4_IRQ_PRIORITY 12
#define STM32_UART_UART5_IRQ_PRIORITY 12
#define STM32_UART_USART6_IRQ_PRIORITY 12
#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_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
/*
* USB driver system settings.
*/
#define STM32_USB_USE_OTG1 TRUE
#define STM32_USB_USE_OTG2 FALSE
#define STM32_USB_OTG1_IRQ_PRIORITY 14
#define STM32_USB_OTG2_IRQ_PRIORITY 14
#define STM32_USB_OTG1_RX_FIFO_SIZE 512
#define STM32_USB_OTG2_RX_FIFO_SIZE 1024
#define STM32_USB_OTG_THREAD_PRIO LOWPRIO
#define STM32_USB_OTG_THREAD_STACK_SIZE 128
#define STM32_USB_OTGFIFO_FILL_BASEPRI 0
/*
* WDG driver system settings.
*/
#define STM32_WDG_USE_IWDG FALSE
#endif /* MCUCONF_H */

View File

@@ -0,0 +1,9 @@
# List of all the board related files.
BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L432KC/board.c
# Required include directories
BOARDINC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L432KC
# Shared variables
ALLCSRC += $(BOARDSRC)
ALLINC += $(BOARDINC)

View File

@@ -0,0 +1,24 @@
/* Copyright 2018-2021 Harrison Chan (@Xelus)
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include_next "board.h"
#undef STM32L432xx
// Pretend that we're an L443xx as the ChibiOS definitions for L432/L433 mistakenly don't enable GPIOH, I2C2, or SPI2.
// Until ChibiOS upstream is fixed, this should be kept at L443, as nothing in QMK currently utilises the crypto peripheral on the L443.
#define STM32L443xx

View File

@@ -0,0 +1,26 @@
/* Copyright 2018-2021 Harrison Chan (@Xelus)
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* Address for jumping to bootloader on STM32 chips. */
/* It is chip dependent, the correct number can be looked up by checking against ST's application note AN2606.
*/
#define STM32_BOOTLOADER_ADDRESS 0x1FFF0000
#define PAL_STM32_OSPEED_HIGHEST PAL_STM32_OSPEED_HIGH
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE
#endif

View File

@@ -0,0 +1,292 @@
/*
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.
*/
/*
* STM32L4xx 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.
*/
#ifndef MCUCONF_H
#define MCUCONF_H
#define STM32L4xx_MCUCONF
#define STM32L443_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_VOS STM32_VOS_RANGE1
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
#define STM32_HSI48_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
#define STM32_MSIPLL_ENABLED FALSE
#define STM32_MSIRANGE STM32_MSIRANGE_4M
#define STM32_MSISRANGE STM32_MSISRANGE_4M
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSI16
#define STM32_PLLM_VALUE 1
#define STM32_PLLN_VALUE 10
#define STM32_PLLPDIV_VALUE 0
#define STM32_PLLP_VALUE 7
#define STM32_PLLQ_VALUE 2
#define STM32_PLLR_VALUE 2
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV1
#define STM32_PPRE2 STM32_PPRE2_DIV1
#define STM32_STOPWUCK STM32_STOPWUCK_MSI
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_MCOPRE STM32_MCOPRE_DIV1
#define STM32_LSCOSEL STM32_LSCOSEL_NOCLOCK
#define STM32_PLLSAI1N_VALUE 24
#define STM32_PLLSAI1PDIV_VALUE 0
#define STM32_PLLSAI1P_VALUE 7
#define STM32_PLLSAI1Q_VALUE 2
#define STM32_PLLSAI1R_VALUE 2
/*
* Peripherals clock sources.
*/
#define STM32_USART1SEL STM32_USART1SEL_SYSCLK
#define STM32_USART2SEL STM32_USART2SEL_SYSCLK
#define STM32_USART3SEL STM32_USART3SEL_SYSCLK
#define STM32_LPUART1SEL STM32_LPUART1SEL_SYSCLK
#define STM32_I2C1SEL STM32_I2C1SEL_SYSCLK
#define STM32_I2C2SEL STM32_I2C2SEL_SYSCLK
#define STM32_I2C3SEL STM32_I2C3SEL_SYSCLK
#define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1
#define STM32_LPTIM2SEL STM32_LPTIM2SEL_PCLK1
#define STM32_SAI1SEL STM32_SAI1SEL_OFF
#define STM32_CLK48SEL STM32_CLK48SEL_HSI48
#define STM32_ADCSEL STM32_ADCSEL_SYSCLK
#define STM32_SWPMI1SEL STM32_SWPMI1SEL_PCLK1
#define STM32_RTCSEL STM32_RTCSEL_LSI
/*
* 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_EXTI1635_38_PRIORITY 6
#define STM32_IRQ_EXTI18_PRIORITY 6
#define STM32_IRQ_EXTI19_PRIORITY 6
#define STM32_IRQ_EXTI20_PRIORITY 6
#define STM32_IRQ_EXTI21_22_PRIORITY 15
#define STM32_IRQ_TIM1_BRK_TIM15_PRIORITY 7
#define STM32_IRQ_TIM1_UP_TIM16_PRIORITY 7
#define STM32_IRQ_TIM1_TRGCO_TIM17_PRIORITY 7
#define STM32_IRQ_TIM1_CC_PRIORITY 7
#define STM32_IRQ_TIM2_PRIORITY 7
#define STM32_IRQ_TIM6_PRIORITY 7
#define STM32_IRQ_TIM7_PRIORITY 7
#define STM32_IRQ_USART1_PRIORITY 12
#define STM32_IRQ_USART2_PRIORITY 12
#define STM32_IRQ_USART3_PRIORITY 12
#define STM32_IRQ_LPUART1_PRIORITY 12
/*
* ADC driver system settings.
*/
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_USE_ADC1 FALSE
#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
#define STM32_ADC_ADC1_DMA_PRIORITY 2
#define STM32_ADC_ADC12_IRQ_PRIORITY 5
#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 5
#define STM32_ADC_ADC123_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1
#define STM32_ADC_ADC123_PRESC ADC_CCR_PRESC_DIV2
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
/*
* 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(2, 4)
#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
/*
* GPT driver system settings.
*/
#define STM32_GPT_USE_TIM1 FALSE
#define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM6 FALSE
#define STM32_GPT_USE_TIM7 FALSE
#define STM32_GPT_USE_TIM15 FALSE
#define STM32_GPT_USE_TIM16 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_BUSY_TIMEOUT 50
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C1_IRQ_PRIORITY 5
#define STM32_I2C_I2C2_IRQ_PRIORITY 5
#define STM32_I2C_I2C3_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_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_TIM15 FALSE
#define STM32_ICU_USE_TIM16 FALSE
/*
* PWM driver system settings.
*/
#define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM15 FALSE
#define STM32_PWM_USE_TIM16 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
/*
* SDMMC drive system settings.
*/
#define STM32_SDC_USE_SDMMC1 FALSE
#define STM32_SDC_SDMMC_UNALIGNED_SUPPORT TRUE
#define STM32_SDC_SDMMC_WRITE_TIMEOUT 1000
#define STM32_SDC_SDMMC_READ_TIMEOUT 1000
#define STM32_SDC_SDMMC_CLOCK_DELAY 10
#define STM32_SDC_SDMMC1_DMA_PRIORITY 3
#define STM32_SDC_SDMMC1_IRQ_PRIORITY 9
#define STM32_SDC_SDMMC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
/*
* 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_LPUART1 FALSE
#define STM32_SERIAL_USART1_PRIORITY 12
#define STM32_SERIAL_USART2_PRIORITY 12
#define STM32_SERIAL_USART3_PRIORITY 12
#define STM32_SERIAL_LPUART1_PRIORITY 12
/*
* 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_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1
#define STM32_SPI_SPI3_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_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_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 6)
#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
/*
* USB driver system settings.
*/
#define STM32_USB_USE_USB1 TRUE
#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
/*
* WDG driver system settings.
*/
#define STM32_WDG_USE_IWDG FALSE
/*
* WSPI driver system settings.
*/
#define STM32_WSPI_USE_QUADSPI1 FALSE
#define STM32_WSPI_QUADSPI1_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#endif /* MCUCONF_H */

View File

@@ -2,11 +2,9 @@
TARGET := $(TARGET)_proton_c TARGET := $(TARGET)_proton_c
MCU := STM32F303 MCU := STM32F303
BOARD := QMK_PROTON_C BOARD := QMK_PROTON_C
BOOTLOADER := stm32-dfu
OPT_DEFS += -DCONVERT_TO_PROTON_C OPT_DEFS += -DCONVERT_TO_PROTON_C
# These are defaults based on what has been implemented for ARM boards # These are defaults based on what has been implemented for ARM boards
AUDIO_ENABLE = yes AUDIO_ENABLE ?= yes
WS2812_DRIVER = bitbang WS2812_DRIVER ?= bitbang
# Force task driven PWM until ARM can provide automatic configuration
BACKLIGHT_DRIVER = software

View File

@@ -17,11 +17,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "quantum.h" #include "quantum.h"
#include "backlight.h" #include "backlight.h"
#include "eeprom.h"
#include "eeconfig.h" #include "eeconfig.h"
#include "debug.h" #include "debug.h"
backlight_config_t backlight_config; backlight_config_t backlight_config;
#ifndef BACKLIGHT_DEFAULT_LEVEL
# define BACKLIGHT_DEFAULT_LEVEL BACKLIGHT_LEVELS
#endif
#ifdef BACKLIGHT_BREATHING #ifdef BACKLIGHT_BREATHING
// TODO: migrate to backlight_config_t // TODO: migrate to backlight_config_t
static uint8_t breathing_period = BREATHING_PERIOD; static uint8_t breathing_period = BREATHING_PERIOD;
@@ -35,6 +40,7 @@ void backlight_init(void) {
/* check signature */ /* check signature */
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
eeconfig_update_backlight_default();
} }
backlight_config.raw = eeconfig_read_backlight(); backlight_config.raw = eeconfig_read_backlight();
if (backlight_config.level > BACKLIGHT_LEVELS) { if (backlight_config.level > BACKLIGHT_LEVELS) {
@@ -152,11 +158,23 @@ void backlight_level(uint8_t level) {
eeconfig_update_backlight(backlight_config.raw); eeconfig_update_backlight(backlight_config.raw);
} }
/** \brief Update current backlight state to EEPROM uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
*
*/ void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
void eeconfig_update_backlight_current(void) { eeconfig_update_backlight(backlight_config.raw); } void eeconfig_update_backlight_current(void) { eeconfig_update_backlight(backlight_config.raw); }
void eeconfig_update_backlight_default(void) {
backlight_config.enable = 1;
#ifdef BACKLIGHT_DEFAULT_BREATHING
backlight_config.breathing = 1;
#else
backlight_config.breathing = 0;
#endif
backlight_config.level = BACKLIGHT_DEFAULT_LEVEL;
eeconfig_update_backlight(backlight_config.raw);
}
/** \brief Get backlight level /** \brief Get backlight level
* *
* FIXME: needs doc * FIXME: needs doc

View File

@@ -55,7 +55,11 @@ void backlight_decrease(void);
void backlight_level_noeeprom(uint8_t level); void backlight_level_noeeprom(uint8_t level);
void backlight_level(uint8_t level); void backlight_level(uint8_t level);
uint8_t get_backlight_level(void); uint8_t get_backlight_level(void);
uint8_t eeconfig_read_backlight(void);
void eeconfig_update_backlight(uint8_t val);
void eeconfig_update_backlight_current(void); void eeconfig_update_backlight_current(void);
void eeconfig_update_backlight_default(void);
// implementation specific // implementation specific
void backlight_init_ports(void); void backlight_init_ports(void);

View File

@@ -0,0 +1,24 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#if defined(BOOTMAGIC_ENABLE)
# include "bootmagic_full.h"
#elif defined(BOOTMAGIC_LITE)
# include "bootmagic_lite.h"
#endif
void bootmagic(void);

View File

@@ -1,3 +1,18 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "wait.h" #include "wait.h"
@@ -10,18 +25,35 @@
#include "eeconfig.h" #include "eeconfig.h"
#include "bootmagic.h" #include "bootmagic.h"
keymap_config_t keymap_config; /** \brief Scan Keycode
/** \brief Bootmagic
* *
* FIXME: needs doc * FIXME: needs doc
*/ */
void bootmagic(void) { static bool scan_keycode(uint8_t keycode) {
/* check signature */ for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
if (!eeconfig_is_enabled()) { matrix_row_t matrix_row = matrix_get_row(r);
eeconfig_init(); for (uint8_t c = 0; c < MATRIX_COLS; c++) {
if (matrix_row & ((matrix_row_t)1 << c)) {
if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
return true;
}
}
}
}
return false;
} }
/** \brief Bootmagic Scan Keycode
*
* FIXME: needs doc
*/
static bool bootmagic_scan_keycode(uint8_t keycode) {
if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
return scan_keycode(keycode);
}
void bootmagic(void) {
/* do scans in case of bounce */ /* do scans in case of bounce */
print("bootmagic scan: ... "); print("bootmagic scan: ... ");
uint8_t scan = 100; uint8_t scan = 100;
@@ -46,8 +78,6 @@ void bootmagic(void) {
bootloader_jump(); bootloader_jump();
} }
/* debug enable */
debug_config.raw = eeconfig_read_debug();
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) { if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) { if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
debug_config.matrix = !debug_config.matrix; debug_config.matrix = !debug_config.matrix;
@@ -61,8 +91,6 @@ void bootmagic(void) {
} }
eeconfig_update_debug(debug_config.raw); eeconfig_update_debug(debug_config.raw);
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) { if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock; keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
} }
@@ -93,71 +121,27 @@ void bootmagic(void) {
uint8_t default_layer = 0; uint8_t default_layer = 0;
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
default_layer |= (1 << 0); default_layer |= (1 << 0);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
default_layer |= (1 << 1); default_layer |= (1 << 1);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
default_layer |= (1 << 2); default_layer |= (1 << 2);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
default_layer |= (1 << 3); default_layer |= (1 << 3);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
default_layer |= (1 << 4); default_layer |= (1 << 4);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
default_layer |= (1 << 5); default_layer |= (1 << 5);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
default_layer |= (1 << 6); default_layer |= (1 << 6);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
default_layer |= (1 << 7); default_layer |= (1 << 7);
} }
if (default_layer) {
eeconfig_update_default_layer(default_layer); eeconfig_update_default_layer(default_layer);
default_layer_set((layer_state_t)default_layer);
} else {
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
}
/* Also initialize layer state to trigger callback functions for layer_state */
layer_state_set_kb((layer_state_t)layer_state);
/* EE_HANDS handedness */ /* EE_HANDS handedness */
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
eeconfig_update_handedness(true); eeconfig_update_handedness(true);
} } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
eeconfig_update_handedness(false); eeconfig_update_handedness(false);
} }
} }
/** \brief Scan Keycode
*
* FIXME: needs doc
*/
static bool scan_keycode(uint8_t keycode) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row_t matrix_row = matrix_get_row(r);
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
if (matrix_row & ((matrix_row_t)1 << c)) {
if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
return true;
}
}
}
}
return false;
}
/** \brief Bootmagic Scan Keycode
*
* FIXME: needs doc
*/
bool bootmagic_scan_keycode(uint8_t keycode) {
if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
return scan_keycode(keycode);
}

View File

@@ -1,3 +1,19 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#pragma once #pragma once
/* FIXME: Add special doxygen comments for defines here. */ /* FIXME: Add special doxygen comments for defines here. */
@@ -97,6 +113,3 @@
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7
# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 # define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7
#endif #endif
void bootmagic(void);
bool bootmagic_scan_keycode(uint8_t keycode);

View File

@@ -1,3 +1,18 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#include "quantum.h" #include "quantum.h"
/** \brief Reset eeprom /** \brief Reset eeprom
@@ -47,3 +62,5 @@ __attribute__((weak)) void bootmagic_lite(void) {
bootloader_jump(); bootloader_jump();
} }
} }
void bootmagic(void) { bootmagic_lite(); }

View File

@@ -0,0 +1,25 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef BOOTMAGIC_LITE_COLUMN
# define BOOTMAGIC_LITE_COLUMN 0
#endif
#ifndef BOOTMAGIC_LITE_ROW
# define BOOTMAGIC_LITE_ROW 0
#endif
void bootmagic_lite(void);

54
quantum/bootmagic/magic.c Normal file
View File

@@ -0,0 +1,54 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdbool.h>
#include "wait.h"
#include "matrix.h"
#include "bootloader.h"
#include "debug.h"
#include "keymap.h"
#include "host.h"
#include "action_layer.h"
#include "eeconfig.h"
#include "bootmagic.h"
keymap_config_t keymap_config;
__attribute__((weak)) void bootmagic(void) {}
/** \brief Magic
*
* FIXME: Needs doc
*/
void magic(void) {
/* check signature */
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
/* init globals */
debug_config.raw = eeconfig_read_debug();
keymap_config.raw = eeconfig_read_keymap();
bootmagic();
/* read here just incase bootmagic process changed its value */
layer_state_t default_layer = (layer_state_t)eeconfig_read_default_layer();
default_layer_set(default_layer);
/* Also initialize layer state to trigger callback functions for layer_state */
layer_state_set_kb((layer_state_t)layer_state);
}

18
quantum/bootmagic/magic.h Normal file
View File

@@ -0,0 +1,18 @@
/* Copyright 2021 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 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
void magic(void);

View File

@@ -24,4 +24,7 @@
#define COL2ROW 0 #define COL2ROW 0
#define ROW2COL 1 #define ROW2COL 1
// Deprecated alias - avoid using
#define KEYMAP LAYOUT
#include "song_list.h" #include "song_list.h"

View File

@@ -59,9 +59,9 @@ static uint8_t thisHand, thatHand;
static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
#endif #endif
__attribute__((weak)) void encoder_update_user(int8_t index, bool clockwise) {} __attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
__attribute__((weak)) void encoder_update_kb(int8_t index, bool clockwise) { encoder_update_user(index, clockwise); } __attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { return encoder_update_user(index, clockwise); }
void encoder_init(void) { void encoder_init(void) {
#if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT) #if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT)
@@ -94,14 +94,14 @@ void encoder_init(void) {
#endif #endif
} }
static bool encoder_update(int8_t index, uint8_t state) { static bool encoder_update(uint8_t index, uint8_t state) {
bool changed = false; bool changed = false;
uint8_t i = index; uint8_t i = index;
#ifdef ENCODER_RESOLUTIONS #ifdef ENCODER_RESOLUTIONS
int8_t resolution = encoder_resolutions[i]; uint8_t resolution = encoder_resolutions[i];
#else #else
int8_t resolution = ENCODER_RESOLUTION; uint8_t resolution = ENCODER_RESOLUTION;
#endif #endif
#ifdef SPLIT_KEYBOARD #ifdef SPLIT_KEYBOARD

View File

@@ -22,8 +22,8 @@
void encoder_init(void); void encoder_init(void);
bool encoder_read(void); bool encoder_read(void);
void encoder_update_kb(int8_t index, bool clockwise); bool encoder_update_kb(uint8_t index, bool clockwise);
void encoder_update_user(int8_t index, bool clockwise); bool encoder_update_user(uint8_t index, bool clockwise);
#ifdef SPLIT_KEYBOARD #ifdef SPLIT_KEYBOARD
void encoder_state_raw(uint8_t* slave_state); void encoder_state_raw(uint8_t* slave_state);

View File

@@ -37,6 +37,7 @@ typedef union {
bool nkro : 1; bool nkro : 1;
bool swap_lctl_lgui : 1; bool swap_lctl_lgui : 1;
bool swap_rctl_rgui : 1; bool swap_rctl_rgui : 1;
bool oneshot_disable : 1;
}; };
} keymap_config_t; } keymap_config_t;

View File

@@ -17,79 +17,143 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdint.h>
#include <stdbool.h>
#include "quantum.h"
#include "led_matrix.h" #include "led_matrix.h"
#include "progmem.h" #include "progmem.h"
#include "config.h" #include "config.h"
#include "eeprom.h" #include "eeprom.h"
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include "led_tables.h"
led_eeconfig_t led_matrix_eeconfig; #include <lib/lib8tion/lib8tion.h>
#ifndef MAX #ifndef LED_MATRIX_CENTER
# define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) const led_point_t k_led_matrix_center = {112, 32};
#else
const led_point_t k_led_matrix_center = LED_MATRIX_CENTER;
#endif #endif
#ifndef MIN // Generic effect runners
# define MIN(a, b) ((a) < (b) ? (a) : (b)) #include "led_matrix_runners/effect_runner_dx_dy_dist.h"
#include "led_matrix_runners/effect_runner_dx_dy.h"
#include "led_matrix_runners/effect_runner_i.h"
#include "led_matrix_runners/effect_runner_sin_cos_i.h"
#include "led_matrix_runners/effect_runner_reactive.h"
#include "led_matrix_runners/effect_runner_reactive_splash.h"
// ------------------------------------------
// -----Begin led effect includes macros-----
#define LED_MATRIX_EFFECT(name)
#define LED_MATRIX_CUSTOM_EFFECT_IMPLS
#include "led_matrix_animations/led_matrix_effects.inc"
#ifdef LED_MATRIX_CUSTOM_KB
# include "led_matrix_kb.inc"
#endif
#ifdef LED_MATRIX_CUSTOM_USER
# include "led_matrix_user.inc"
#endif #endif
#ifndef LED_DISABLE_AFTER_TIMEOUT #undef LED_MATRIX_CUSTOM_EFFECT_IMPLS
# define LED_DISABLE_AFTER_TIMEOUT 0 #undef LED_MATRIX_EFFECT
// -----End led effect includes macros-------
// ------------------------------------------
#if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT)
# define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL)
#endif #endif
#ifndef LED_DISABLE_WHEN_USB_SUSPENDED #ifndef LED_DISABLE_TIMEOUT
# define LED_DISABLE_WHEN_USB_SUSPENDED false # define LED_DISABLE_TIMEOUT 0
#endif #endif
#ifndef EECONFIG_LED_MATRIX #if LED_DISABLE_WHEN_USB_SUSPENDED != 1
# define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT # undef LED_DISABLE_WHEN_USB_SUSPENDED
#endif #endif
#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255 #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
# define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 # undef LED_MATRIX_MAXIMUM_BRIGHTNESS
# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
#endif #endif
bool g_suspend_state = false; #if !defined(LED_MATRIX_VAL_STEP)
# define LED_MATRIX_VAL_STEP 8
#endif
// Global tick at 20 Hz #if !defined(LED_MATRIX_SPD_STEP)
uint32_t g_tick = 0; # define LED_MATRIX_SPD_STEP 16
#endif
// Ticks since this key was last hit. #if !defined(LED_MATRIX_STARTUP_MODE)
uint8_t g_key_hit[DRIVER_LED_TOTAL]; # define LED_MATRIX_STARTUP_MODE LED_MATRIX_SOLID
#endif
// Ticks since any key was last hit. #if !defined(LED_MATRIX_STARTUP_VAL)
uint32_t g_any_key_hit = 0; # define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS
#endif
uint32_t eeconfig_read_led_matrix(void) { return eeprom_read_dword(EECONFIG_LED_MATRIX); } #if !defined(LED_MATRIX_STARTUP_SPD)
# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2
#endif
void eeconfig_update_led_matrix(uint32_t config_value) { eeprom_update_dword(EECONFIG_LED_MATRIX, config_value); } // globals
led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
uint32_t g_led_timer;
#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
last_hit_t g_last_hit_tracker;
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
// internals
static bool suspend_state = false;
static uint8_t led_last_enable = UINT8_MAX;
static uint8_t led_last_effect = UINT8_MAX;
static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
static led_task_states led_task_state = SYNCING;
#if LED_DISABLE_TIMEOUT > 0
static uint32_t led_anykey_timer;
#endif // LED_DISABLE_TIMEOUT > 0
// double buffers
static uint32_t led_timer_buffer;
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
static last_hit_t last_hit_buffer;
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
// split led matrix
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
#endif
void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
void eeconfig_update_led_matrix_default(void) { void eeconfig_update_led_matrix_default(void) {
dprintf("eeconfig_update_led_matrix_default\n"); dprintf("eeconfig_update_led_matrix_default\n");
led_matrix_eeconfig.enable = 1; led_matrix_eeconfig.enable = 1;
led_matrix_eeconfig.mode = LED_MATRIX_UNIFORM_BRIGHTNESS; led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE;
led_matrix_eeconfig.val = 128; led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL;
led_matrix_eeconfig.speed = 0; led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD;
eeconfig_update_led_matrix(led_matrix_eeconfig.raw); led_matrix_eeconfig.flags = LED_FLAG_ALL;
eeconfig_update_led_matrix();
} }
void eeconfig_debug_led_matrix(void) { void eeconfig_debug_led_matrix(void) {
dprintf("led_matrix_eeconfig eeprom\n"); dprintf("led_matrix_eeconfig EEPROM\n");
dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable); dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable);
dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode); dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode);
dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val); dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val);
dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed); dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed);
dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags);
} }
uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; __attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
uint8_t g_last_led_count = 0;
uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
uint8_t led_count = 0; uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i);
uint8_t led_index = g_led_config.matrix_co[row][column]; uint8_t led_index = g_led_config.matrix_co[row][column];
if (led_index != NO_LED) { if (led_index != NO_LED) {
led_i[led_count] = led_index; led_i[led_count] = led_index;
@@ -100,88 +164,235 @@ uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
void led_matrix_set_index_value(int index, uint8_t value) { led_matrix_driver.set_value(index, value); } void led_matrix_set_value(int index, uint8_t value) {
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
void led_matrix_set_index_value_all(uint8_t value) { led_matrix_driver.set_value_all(value); } if (!is_keyboard_left() && index >= k_led_matrix_split[0])
# ifdef USE_CIE1931_CURVE
bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value]));
if (record->event.pressed) { # else
uint8_t led[8]; led_matrix_driver.set_value(index - k_led_matrix_split[0], value);
uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led); # endif
if (led_count > 0) { else if (is_keyboard_left() && index < k_led_matrix_split[0])
for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { #endif
g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; #ifdef USE_CIE1931_CURVE
} led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
g_last_led_hit[0] = led[0]; #else
g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1); led_matrix_driver.set_value(index, value);
}
for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 0;
g_any_key_hit = 0;
} else {
#ifdef LED_MATRIX_KEYRELEASES
uint8_t led[8];
uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led);
for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255;
g_any_key_hit = 255;
#endif #endif
} }
return true;
void led_matrix_set_value_all(uint8_t value) {
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value);
#else
# ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
# else
led_matrix_driver.set_value_all(value);
# endif
#endif
} }
void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; } void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef LED_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
#if LED_DISABLE_TIMEOUT > 0
led_anykey_timer = 0;
#endif // LED_DISABLE_TIMEOUT > 0
// All LEDs off #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } uint8_t led[LED_HITS_TO_REMEMBER];
uint8_t led_count = 0;
// Uniform brightness # if defined(LED_MATRIX_KEYRELEASES)
void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); } if (!pressed)
# elif defined(LED_MATRIX_KEYPRESSES)
void led_matrix_custom(void) {} if (pressed)
# endif // defined(LED_MATRIX_KEYRELEASES)
void led_matrix_task(void) { {
if (!led_matrix_eeconfig.enable) { led_count = led_matrix_map_row_column_to_led(row, col, led);
led_matrix_all_off();
led_matrix_indicators();
return;
} }
g_tick++; if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
if (g_any_key_hit < 0xFFFFFFFF) { memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
g_any_key_hit++; memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
last_hit_buffer.count--;
} }
for (int led = 0; led < DRIVER_LED_TOTAL; led++) { for (uint8_t i = 0; i < led_count; i++) {
if (g_key_hit[led] < 255) { uint8_t index = last_hit_buffer.count;
if (g_key_hit[led] == 254) g_last_led_count = MAX(g_last_led_count - 1, 0); last_hit_buffer.x[index] = g_led_config.point[led[i]].x;
g_key_hit[led]++; last_hit_buffer.y[index] = g_led_config.point[led[i]].y;
last_hit_buffer.index[index] = led[i];
last_hit_buffer.tick[index] = 0;
last_hit_buffer.count++;
} }
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
#if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) {
process_led_matrix_typing_heatmap(row, col);
}
#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
} }
// Ideally we would also stop sending zeros to the LED driver PWM buffers static bool led_matrix_none(effect_params_t *params) {
// while suspended and just do a software shutdown. This is a cheap hack for now. if (!params->init) {
bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); return false;
uint8_t effect = suspend_backlight ? 0 : led_matrix_eeconfig.mode; }
led_matrix_set_value_all(0);
return false;
}
static void led_task_timers(void) {
#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer);
#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
led_timer_buffer = sync_timer_read32();
// Update double buffer timers
#if LED_DISABLE_TIMEOUT > 0
if (led_anykey_timer < UINT32_MAX) {
if (UINT32_MAX - deltaTime < led_anykey_timer) {
led_anykey_timer = UINT32_MAX;
} else {
led_anykey_timer += deltaTime;
}
}
#endif // LED_DISABLE_TIMEOUT > 0
// Update double buffer last hit timers
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
uint8_t count = last_hit_buffer.count;
for (uint8_t i = 0; i < count; ++i) {
if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
last_hit_buffer.count--;
continue;
}
last_hit_buffer.tick[i] += deltaTime;
}
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
}
static void led_task_sync(void) {
// next task
if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING;
}
static void led_task_start(void) {
// reset iter
led_effect_params.iter = 0;
// update double buffers
g_led_timer = led_timer_buffer;
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
g_last_hit_tracker = last_hit_buffer;
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
// next task
led_task_state = RENDERING;
}
static void led_task_render(uint8_t effect) {
bool rendering = false;
led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable);
if (led_effect_params.flags != led_matrix_eeconfig.flags) {
led_effect_params.flags = led_matrix_eeconfig.flags;
led_matrix_set_value_all(0);
}
// this gets ticked at 20 Hz.
// each effect can opt to do calculations // each effect can opt to do calculations
// and/or request PWM buffer updates. // and/or request PWM buffer updates.
switch (effect) { switch (effect) {
case LED_MATRIX_UNIFORM_BRIGHTNESS: case LED_MATRIX_NONE:
led_matrix_uniform_brightness(); rendering = led_matrix_none(&led_effect_params);
break; break;
default:
led_matrix_custom(); // ---------------------------------------------
// -----Begin led effect switch case macros-----
#define LED_MATRIX_EFFECT(name, ...) \
case LED_MATRIX_##name: \
rendering = name(&led_effect_params); \
break; break;
#include "led_matrix_animations/led_matrix_effects.inc"
#undef LED_MATRIX_EFFECT
#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
# define LED_MATRIX_EFFECT(name, ...) \
case LED_MATRIX_CUSTOM_##name: \
rendering = name(&led_effect_params); \
break;
# ifdef LED_MATRIX_CUSTOM_KB
# include "led_matrix_kb.inc"
# endif
# ifdef LED_MATRIX_CUSTOM_USER
# include "led_matrix_user.inc"
# endif
# undef LED_MATRIX_EFFECT
#endif
// -----End led effect switch case macros-------
// ---------------------------------------------
} }
if (!suspend_backlight) { led_effect_params.iter++;
// next task
if (!rendering) {
led_task_state = FLUSHING;
if (!led_effect_params.init && effect == LED_MATRIX_NONE) {
// We only need to flush once if we are LED_MATRIX_NONE
led_task_state = SYNCING;
}
}
}
static void led_task_flush(uint8_t effect) {
// update last trackers after the first full render so we can init over several frames
led_last_effect = effect;
led_last_enable = led_matrix_eeconfig.enable;
// update pwm buffers
led_matrix_update_pwm_buffers();
// next task
led_task_state = SYNCING;
}
void led_matrix_task(void) {
led_task_timers();
// Ideally we would also stop sending zeros to the LED driver PWM buffers
// while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = suspend_state ||
#if LED_DISABLE_TIMEOUT > 0
(led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
#endif // LED_DISABLE_TIMEOUT > 0
false;
uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode;
switch (led_task_state) {
case STARTING:
led_task_start();
break;
case RENDERING:
led_task_render(effect);
if (effect) {
led_matrix_indicators(); led_matrix_indicators();
led_matrix_indicators_advanced(&led_effect_params);
}
break;
case FLUSHING:
led_task_flush(effect);
break;
case SYNCING:
led_task_sync();
break;
} }
// Tell the LED driver to update its state
led_matrix_driver.flush();
} }
void led_matrix_indicators(void) { void led_matrix_indicators(void) {
@@ -193,156 +404,180 @@ __attribute__((weak)) void led_matrix_indicators_kb(void) {}
__attribute__((weak)) void led_matrix_indicators_user(void) {} __attribute__((weak)) void led_matrix_indicators_user(void) {}
// void led_matrix_set_indicator_index(uint8_t *index, uint8_t row, uint8_t column) void led_matrix_indicators_advanced(effect_params_t *params) {
// { /* special handling is needed for "params->iter", since it's already been incremented.
// if (row >= MATRIX_ROWS) * Could move the invocations to led_task_render, but then it's missing a few checks
// { * and not sure which would be better. Otherwise, this should be called from
// // Special value, 255=none, 254=all * led_task_render, right before the iter++ line.
// *index = row; */
// } #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
// else uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
// { uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT;
// // This needs updated to something like if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
// // uint8_t led[8]; #else
// // uint8_t led_count = map_row_column_to_led(row, column, led); uint8_t min = 0;
// // for(uint8_t i = 0; i < led_count; i++) uint8_t max = DRIVER_LED_TOTAL;
// map_row_column_to_led(row, column, index); #endif
// } led_matrix_indicators_advanced_kb(min, max);
// } led_matrix_indicators_advanced_user(min, max);
}
__attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
__attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
void led_matrix_init(void) { void led_matrix_init(void) {
led_matrix_driver.init(); led_matrix_driver.init();
// Wait half a second for the driver to finish initializing #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
wait_ms(500); g_last_hit_tracker.count = 0;
for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
// clear the key hits g_last_hit_tracker.tick[i] = UINT16_MAX;
for (int led = 0; led < DRIVER_LED_TOTAL; led++) {
g_key_hit[led] = 255;
} }
last_hit_buffer.count = 0;
for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
last_hit_buffer.tick[i] = UINT16_MAX;
}
#endif // LED_MATRIX_KEYREACTIVE_ENABLED
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); dprintf("led_matrix_init_drivers eeconfig is not enabled.\n");
eeconfig_init(); eeconfig_init();
eeconfig_update_led_matrix_default(); eeconfig_update_led_matrix_default();
} }
led_matrix_eeconfig.raw = eeconfig_read_led_matrix(); eeconfig_read_led_matrix();
if (!led_matrix_eeconfig.mode) { if (!led_matrix_eeconfig.mode) {
dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
eeconfig_update_led_matrix_default(); eeconfig_update_led_matrix_default();
led_matrix_eeconfig.raw = eeconfig_read_led_matrix();
} }
eeconfig_debug_led_matrix(); // display current eeprom values eeconfig_debug_led_matrix(); // display current eeprom values
} }
// Deals with the messy details of incrementing an integer void led_matrix_set_suspend_state(bool state) {
static uint8_t increment(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { #ifdef LED_DISABLE_WHEN_USB_SUSPENDED
int16_t new_value = value; if (state) {
new_value += step; led_matrix_set_value_all(0); // turn off all LEDs when suspending
return MIN(MAX(new_value, min), max); }
suspend_state = state;
#endif
} }
static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { bool led_matrix_get_suspend_state(void) { return suspend_state; }
int16_t new_value = value;
new_value -= step;
return MIN(MAX(new_value, min), max);
}
// void *backlight_get_custom_key_value_eeprom_address(uint8_t led) { void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
// // 3 bytes per value
// return EECONFIG_LED_MATRIX + (led * 3);
// }
// void backlight_get_key_value(uint8_t led, uint8_t *value) {
// void *address = backlight_get_custom_key_value_eeprom_address(led);
// value = eeprom_read_byte(address);
// }
// void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) {
// uint8_t led[8];
// uint8_t led_count = map_row_column_to_led(row, column, led);
// for(uint8_t i = 0; i < led_count; i++) {
// if (led[i] < DRIVER_LED_TOTAL) {
// void *address = backlight_get_custom_key_value_eeprom_address(led[i]);
// eeprom_update_byte(address, value);
// }
// }
// }
uint32_t led_matrix_get_tick(void) { return g_tick; }
void led_matrix_toggle(void) {
led_matrix_eeconfig.enable ^= 1; led_matrix_eeconfig.enable ^= 1;
eeconfig_update_led_matrix(led_matrix_eeconfig.raw); led_task_state = STARTING;
if (write_to_eeprom) {
eeconfig_update_led_matrix();
} }
dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
}
void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
void led_matrix_enable(void) { void led_matrix_enable(void) {
led_matrix_eeconfig.enable = 1; led_matrix_enable_noeeprom();
eeconfig_update_led_matrix(led_matrix_eeconfig.raw); eeconfig_update_led_matrix();
} }
void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; } void led_matrix_enable_noeeprom(void) {
if (!led_matrix_eeconfig.enable) led_task_state = STARTING;
led_matrix_eeconfig.enable = 1;
}
void led_matrix_disable(void) { void led_matrix_disable(void) {
led_matrix_disable_noeeprom();
eeconfig_update_led_matrix();
}
void led_matrix_disable_noeeprom(void) {
if (led_matrix_eeconfig.enable) led_task_state = STARTING;
led_matrix_eeconfig.enable = 0; led_matrix_eeconfig.enable = 0;
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
} }
void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; }
void led_matrix_step(void) { void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
led_matrix_eeconfig.mode++; if (!led_matrix_eeconfig.enable) {
if (led_matrix_eeconfig.mode >= LED_MATRIX_EFFECT_MAX) { return;
}
if (mode < 1) {
led_matrix_eeconfig.mode = 1; led_matrix_eeconfig.mode = 1;
} } else if (mode >= LED_MATRIX_EFFECT_MAX) {
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
}
void led_matrix_step_reverse(void) {
led_matrix_eeconfig.mode--;
if (led_matrix_eeconfig.mode < 1) {
led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1;
} } else {
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
}
void led_matrix_increase_val(void) {
led_matrix_eeconfig.val = increment(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
}
void led_matrix_decrease_val(void) {
led_matrix_eeconfig.val = decrement(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
}
void led_matrix_increase_speed(void) {
led_matrix_eeconfig.speed = increment(led_matrix_eeconfig.speed, 1, 0, 3);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this
}
void led_matrix_decrease_speed(void) {
led_matrix_eeconfig.speed = decrement(led_matrix_eeconfig.speed, 1, 0, 3);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this
}
void led_matrix_mode(uint8_t mode, bool eeprom_write) {
led_matrix_eeconfig.mode = mode; led_matrix_eeconfig.mode = mode;
if (eeprom_write) {
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
} }
led_task_state = STARTING;
if (write_to_eeprom) {
eeconfig_update_led_matrix();
} }
dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
}
void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); }
uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; }
void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_eeconfig.val = val; } void led_matrix_step_helper(bool write_to_eeprom) {
uint8_t mode = led_matrix_eeconfig.mode + 1;
void led_matrix_set_value(uint8_t val) { led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom);
led_matrix_set_value_noeeprom(val);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
} }
void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); }
void led_matrix_step(void) { led_matrix_step_helper(true); }
void backlight_set(uint8_t val) { led_matrix_set_value(val); } void led_matrix_step_reverse_helper(bool write_to_eeprom) {
uint8_t mode = led_matrix_eeconfig.mode - 1;
led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom);
}
void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); }
void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); }
void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
if (!led_matrix_eeconfig.enable) {
return;
}
led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
if (write_to_eeprom) {
eeconfig_update_led_matrix();
}
dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
}
void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); }
uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; }
void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); }
void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); }
void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); }
void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
led_matrix_eeconfig.speed = speed;
if (write_to_eeprom) {
eeconfig_update_led_matrix();
}
dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
}
void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); }
uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; }
void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); }
void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); }
void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); }
void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); }
led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; }
void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; }

View File

@@ -19,61 +19,120 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdbool.h>
#include "led_matrix_types.h" #include "led_matrix_types.h"
#include "quantum.h"
#ifndef BACKLIGHT_ENABLE #ifdef IS31FL3731
# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE # include "is31fl3731-simple.h"
#endif #endif
#ifndef LED_MATRIX_LED_FLUSH_LIMIT
# define LED_MATRIX_LED_FLUSH_LIMIT 16
#endif
#ifndef LED_MATRIX_LED_PROCESS_LIMIT
# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
#endif
#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
#else
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = 0; \
uint8_t max = DRIVER_LED_TOTAL;
#endif
#define LED_MATRIX_TEST_LED_FLAGS() \
if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
enum led_matrix_effects { enum led_matrix_effects {
LED_MATRIX_UNIFORM_BRIGHTNESS = 1, LED_MATRIX_NONE = 0,
// All new effects go above this line
// --------------------------------------
// -----Begin led effect enum macros-----
#define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name,
#include "led_matrix_animations/led_matrix_effects.inc"
#undef LED_MATRIX_EFFECT
#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
# define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name,
# ifdef LED_MATRIX_CUSTOM_KB
# include "led_matrix_kb.inc"
# endif
# ifdef LED_MATRIX_CUSTOM_USER
# include "led_matrix_user.inc"
# endif
# undef LED_MATRIX_EFFECT
#endif
// --------------------------------------
// -----End led effect enum macros-------
LED_MATRIX_EFFECT_MAX LED_MATRIX_EFFECT_MAX
}; };
void led_matrix_set_index_value(int index, uint8_t value); void eeconfig_update_led_matrix_default(void);
void led_matrix_set_index_value_all(uint8_t value); void eeconfig_update_led_matrix(void);
void eeconfig_debug_led_matrix(void);
uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
void led_matrix_set_value(int index, uint8_t value);
void led_matrix_set_value_all(uint8_t value);
void process_led_matrix(uint8_t row, uint8_t col, bool pressed);
void led_matrix_task(void);
// This runs after another backlight effect and replaces // This runs after another backlight effect and replaces
// colors already set // values already set
void led_matrix_indicators(void); void led_matrix_indicators(void);
void led_matrix_indicators_kb(void); void led_matrix_indicators_kb(void);
void led_matrix_indicators_user(void); void led_matrix_indicators_user(void);
void led_matrix_indicators_advanced(effect_params_t *params);
void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
void led_matrix_init(void); void led_matrix_init(void);
void led_matrix_setup_drivers(void);
void led_matrix_set_suspend_state(bool state); void led_matrix_set_suspend_state(bool state);
void led_matrix_set_indicator_state(uint8_t state); bool led_matrix_get_suspend_state(void);
void led_matrix_task(void);
// 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 led_matrix_update_pwm_buffers(void);
bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
uint32_t led_matrix_get_tick(void);
void led_matrix_toggle(void); void led_matrix_toggle(void);
void led_matrix_toggle_noeeprom(void);
void led_matrix_enable(void); void led_matrix_enable(void);
void led_matrix_enable_noeeprom(void); void led_matrix_enable_noeeprom(void);
void led_matrix_disable(void); void led_matrix_disable(void);
void led_matrix_disable_noeeprom(void); void led_matrix_disable_noeeprom(void);
void led_matrix_step(void); uint8_t led_matrix_is_enabled(void);
void led_matrix_step_reverse(void); void led_matrix_mode(uint8_t mode);
void led_matrix_increase_val(void);
void led_matrix_decrease_val(void);
void led_matrix_increase_speed(void);
void led_matrix_decrease_speed(void);
void led_matrix_mode(uint8_t mode, bool eeprom_write);
void led_matrix_mode_noeeprom(uint8_t mode); void led_matrix_mode_noeeprom(uint8_t mode);
uint8_t led_matrix_get_mode(void); uint8_t led_matrix_get_mode(void);
void led_matrix_set_value(uint8_t mode); void led_matrix_step(void);
void led_matrix_set_value_noeeprom(uint8_t mode); void led_matrix_step_noeeprom(void);
void led_matrix_step_reverse(void);
void led_matrix_step_reverse_noeeprom(void);
void led_matrix_set_val(uint8_t val);
void led_matrix_set_val_noeeprom(uint8_t val);
uint8_t led_matrix_get_val(void);
void led_matrix_increase_val(void);
void led_matrix_increase_val_noeeprom(void);
void led_matrix_decrease_val(void);
void led_matrix_decrease_val_noeeprom(void);
void led_matrix_set_speed(uint8_t speed);
void led_matrix_set_speed_noeeprom(uint8_t speed);
uint8_t led_matrix_get_speed(void);
void led_matrix_increase_speed(void);
void led_matrix_increase_speed_noeeprom(void);
void led_matrix_decrease_speed(void);
void led_matrix_decrease_speed_noeeprom(void);
led_flags_t led_matrix_get_flags(void);
void led_matrix_set_flags(led_flags_t flags);
typedef struct { typedef struct {
/* Perform any initialisation required for the other driver functions to work. */ /* Perform any initialisation required for the other driver functions to work. */
@@ -91,4 +150,11 @@ extern const led_matrix_driver_t led_matrix_driver;
extern led_eeconfig_t led_matrix_eeconfig; extern led_eeconfig_t led_matrix_eeconfig;
extern uint32_t g_led_timer;
extern led_config_t g_led_config; extern led_config_t g_led_config;
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
extern last_hit_t g_last_hit_tracker;
#endif
#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
#endif

View File

@@ -0,0 +1,24 @@
#ifndef DISABLE_LED_MATRIX_ALPHAS_MODS
LED_MATRIX_EFFECT(ALPHAS_MODS)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
// alphas = val1, mods = val2
bool ALPHAS_MODS(effect_params_t* params) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t val1 = led_matrix_eeconfig.val;
uint8_t val2 = val1 + led_matrix_eeconfig.speed;
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) {
led_matrix_set_value(i, val2);
} else {
led_matrix_set_value(i, val1);
}
}
return led_max < DRIVER_LED_TOTAL;
}
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_ALPHAS_MODS

View File

@@ -0,0 +1,13 @@
#ifndef DISABLE_LED_MATRIX_BAND
LED_MATRIX_EFFECT(BAND)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) {
int16_t v = val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8;
return scale8(v < 0 ? 0 : v, val);
}
bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_BAND

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_BAND_PINWHEEL
LED_MATRIX_EFFECT(BAND_PINWHEEL)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); }
bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_BAND_PINWHEEL

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_BAND_SPIRAL
LED_MATRIX_EFFECT(BAND_SPIRAL)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); }
bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_BAND_SPIRAL

View File

@@ -0,0 +1,19 @@
#ifndef DISABLE_LED_MATRIX_BREATHING
LED_MATRIX_EFFECT(BREATHING)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
bool BREATHING(effect_params_t* params) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t val = led_matrix_eeconfig.val;
uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 8);
val = scale8(abs8(sin8(time) - 128) * 2, val);
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
led_matrix_set_value(i, val);
}
return led_max < DRIVER_LED_TOTAL;
}
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_BREATHING

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT
LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); }
bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_CYCLE_OUT_IN
LED_MATRIX_EFFECT(CYCLE_OUT_IN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); }
bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_CYCLE_UP_DOWN
LED_MATRIX_EFFECT(CYCLE_UP_DOWN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); }
bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_DUAL_BEACON
LED_MATRIX_EFFECT(DUAL_BEACON)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); }
bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_DUAL_BEACON

View File

@@ -0,0 +1,18 @@
// Add your new core led matrix effect here, order determins enum order, requires "led_matrix_animations/ directory
#include "led_matrix_animations/solid_anim.h"
#include "led_matrix_animations/alpha_mods_anim.h"
#include "led_matrix_animations/breathing_anim.h"
#include "led_matrix_animations/band_anim.h"
#include "led_matrix_animations/band_pinwheel_anim.h"
#include "led_matrix_animations/band_spiral_anim.h"
#include "led_matrix_animations/cycle_left_right_anim.h"
#include "led_matrix_animations/cycle_up_down_anim.h"
#include "led_matrix_animations/cycle_out_in_anim.h"
#include "led_matrix_animations/dual_beacon_anim.h"
#include "led_matrix_animations/solid_reactive_simple_anim.h"
#include "led_matrix_animations/solid_reactive_wide.h"
#include "led_matrix_animations/solid_reactive_cross.h"
#include "led_matrix_animations/solid_reactive_nexus.h"
#include "led_matrix_animations/solid_splash_anim.h"
#include "led_matrix_animations/wave_left_right_anim.h"
#include "led_matrix_animations/wave_up_down_anim.h"

View File

@@ -0,0 +1,15 @@
LED_MATRIX_EFFECT(SOLID)
#ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
bool SOLID(effect_params_t* params) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t val = led_matrix_eeconfig.val;
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
led_matrix_set_value(i, val);
}
return led_max < DRIVER_LED_TOTAL;
}
#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS

View File

@@ -0,0 +1,35 @@
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS)
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS
LED_MATRIX_EFFECT(SOLID_REACTIVE_CROSS)
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS
LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS)
# endif
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick + dist;
dx = dx < 0 ? dx * -1 : dx;
dy = dy < 0 ? dy * -1 : dy;
dx = dx * 16 > 255 ? 255 : dx * 16;
dy = dy * 16 > 255 ? 255 : dy * 16;
effect += dx > dy ? dy : dx;
if (effect > 255) effect = 255;
return qadd8(val, 255 - effect);
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS
bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS
bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS)
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

View File

@@ -0,0 +1,32 @@
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS)
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS
LED_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS)
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS
LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS)
# endif
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick - dist;
if (effect > 255) effect = 255;
if (dist > 72) effect = 255;
if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255;
return qadd8(val, 255 - effect);
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS
bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS
bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS)
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

View File

@@ -0,0 +1,12 @@
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE
LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); }
bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
# endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

View File

@@ -0,0 +1,30 @@
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE)
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE
LED_MATRIX_EFFECT(SOLID_REACTIVE_WIDE)
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE
LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE)
# endif
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick + dist * 5;
if (effect > 255) effect = 255;
return qadd8(val, 255 - effect);
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE
bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE
bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE)
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

View File

@@ -0,0 +1,30 @@
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
# if !defined(DISABLE_LED_MATRIX_SOLID_SPLASH) || !defined(DISABLE_LED_MATRIX_SOLID_MULTISPLASH)
# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH
LED_MATRIX_EFFECT(SOLID_SPLASH)
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH
LED_MATRIX_EFFECT(SOLID_MULTISPLASH)
# endif
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick - dist;
if (effect > 255) effect = 255;
return qadd8(val, 255 - effect);
}
# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH
bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH
bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
# endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH)
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT
LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); }
bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT

View File

@@ -0,0 +1,10 @@
#ifndef DISABLE_LED_MATRIX_WAVE_UP_DOWN
LED_MATRIX_EFFECT(WAVE_UP_DOWN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); }
bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN

View File

@@ -15,9 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdint.h>
#include <stdbool.h>
#include "quantum.h"
#include "led_matrix.h" #include "led_matrix.h"
/* Each driver needs to define a struct: /* Each driver needs to define a struct:
@@ -30,10 +27,6 @@
#if defined(IS31FL3731) || defined(IS31FL3733) #if defined(IS31FL3731) || defined(IS31FL3733)
# if defined(IS31FL3731)
# include "is31fl3731-simple.h"
# endif
# include "i2c_master.h" # include "i2c_master.h"
static void init(void) { static void init(void) {
@@ -53,16 +46,28 @@ static void init(void) {
# endif # endif
# else # else
# ifdef LED_DRIVER_ADDR_1 # ifdef LED_DRIVER_ADDR_1
IS31FL3733_init(LED_DRIVER_ADDR_1, 0); # ifndef LED_DRIVER_SYNC_1
# define LED_DRIVER_SYNC_1 0
# endif
IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
# endif # endif
# ifdef LED_DRIVER_ADDR_2 # ifdef LED_DRIVER_ADDR_2
IS31FL3733_init(LED_DRIVER_ADDR_2, 0); # ifndef LED_DRIVER_SYNC_2
# define LED_DRIVER_SYNC_2 0
# endif
IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
# endif # endif
# ifdef LED_DRIVER_ADDR_3 # ifdef LED_DRIVER_ADDR_3
IS31FL3733_init(LED_DRIVER_ADDR_3, 0); # ifndef LED_DRIVER_SYNC_3
# define LED_DRIVER_SYNC_3 0
# endif
IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
# endif # endif
# ifdef LED_DRIVER_ADDR_4 # ifdef LED_DRIVER_ADDR_4
IS31FL3733_init(LED_DRIVER_ADDR_4, 0); # ifndef LED_DRIVER_SYNC_4
# define LED_DRIVER_SYNC_4 0
# endif
IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
# endif # endif
# endif # endif

View File

@@ -0,0 +1,16 @@
#pragma once
typedef uint8_t (*dx_dy_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t time);
bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x;
int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y;
led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time));
}
return led_max < DRIVER_LED_TOTAL;
}

View File

@@ -0,0 +1,17 @@
#pragma once
typedef uint8_t (*dx_dy_dist_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time);
bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x;
int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y;
uint8_t dist = sqrt16(dx * dx + dy * dy);
led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time));
}
return led_max < DRIVER_LED_TOTAL;
}

View File

@@ -0,0 +1,14 @@
#pragma once
typedef uint8_t (*i_f)(uint8_t val, uint8_t i, uint8_t time);
bool effect_runner_i(effect_params_t* params, i_f effect_func) {
LED_MATRIX_USE_LIMITS(led_min, led_max);
uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
LED_MATRIX_TEST_LED_FLAGS();
led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time));
}
return led_max < DRIVER_LED_TOTAL;
}

Some files were not shown because too many files have changed in this diff Show More