diff options
158 files changed, 3236 insertions, 2871 deletions
diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index a19667f97e..f0c49baf60 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -35,4 +35,4 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_KEY }} AWS_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com - SOURCE_DIR: 'api_data' + SOURCE_DIR: '.build/api_data' diff --git a/.github/workflows/develop_api.yml b/.github/workflows/develop_api.yml index f0098142c7..3eb6e53c20 100644 --- a/.github/workflows/develop_api.yml +++ b/.github/workflows/develop_api.yml @@ -35,4 +35,4 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_KEY }} AWS_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com - SOURCE_DIR: 'api_data' + SOURCE_DIR: '.build/api_data' diff --git a/api_data/_config.yml b/api_data/_config.yml deleted file mode 100644 index 277f1f2c51..0000000000 --- a/api_data/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman diff --git a/builddefs/build_test.mk b/builddefs/build_test.mk index 7226004aab..5ad33b19c5 100644 --- a/builddefs/build_test.mk +++ b/builddefs/build_test.mk @@ -4,6 +4,8 @@ endif .DEFAULT_GOAL := all +OPT = g + include paths.mk include $(BUILDDEFS_PATH)/message.mk diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 08d186d656..a1793f91a5 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -646,8 +646,9 @@ ifeq ($(strip $(HAPTIC_ENABLE)),yes) endif ifeq ($(strip $(HD44780_ENABLE)), yes) - SRC += platforms/avr/drivers/hd44780.c OPT_DEFS += -DHD44780_ENABLE + COMMON_VPATH += $(DRIVER_PATH)/lcd + SRC += hd44780.c endif VALID_OLED_DRIVER_TYPES := SSD1306 custom diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index b303a87919..85dfe67f3f 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -316,7 +316,7 @@ gccversion : @$(BUILD_CMD) %.uf2: %.hex - $(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex -o $(BUILD_DIR)/$(TARGET).uf2 -c -f $(UF2_FAMILY) >/dev/null 2>&1) + $(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex --output $(BUILD_DIR)/$(TARGET).uf2 --convert --family $(UF2_FAMILY) >/dev/null 2>&1) #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" @$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD) @$(BUILD_CMD) diff --git a/builddefs/generic_features.mk b/builddefs/generic_features.mk index e4151eb217..53d4e16fd4 100644 --- a/builddefs/generic_features.mk +++ b/builddefs/generic_features.mk @@ -25,6 +25,7 @@ GENERIC_FEATURES = \ DYNAMIC_KEYMAP \ DYNAMIC_MACRO \ ENCODER \ + ENCODER_MAP \ GRAVE_ESC \ HAPTIC \ KEY_LOCK \ diff --git a/builddefs/mcu_selection.mk b/builddefs/mcu_selection.mk index 9fdd22c3b6..ec33ee4446 100644 --- a/builddefs/mcu_selection.mk +++ b/builddefs/mcu_selection.mk @@ -9,7 +9,9 @@ ifneq ($(findstring MKL26Z64, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = KINETIS MCU_SERIES = KL2x @@ -36,7 +38,9 @@ ifneq ($(findstring MK20DX128, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = KINETIS MCU_SERIES = K20x @@ -63,7 +67,9 @@ ifneq ($(findstring MK20DX256, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = KINETIS MCU_SERIES = K20x @@ -90,7 +96,9 @@ ifneq ($(findstring MK66FX1M0, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = KINETIS MCU_SERIES = MK66F18 @@ -117,7 +125,9 @@ ifneq ($(findstring STM32F042, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F0xx @@ -157,7 +167,9 @@ ifneq ($(findstring STM32F072, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F0xx @@ -192,7 +204,9 @@ ifneq ($(findstring STM32F103, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F1xx @@ -224,7 +238,9 @@ ifneq ($(findstring STM32F303, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F3xx @@ -259,7 +275,9 @@ ifneq ($(findstring STM32F401, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F4xx @@ -299,7 +317,9 @@ ifneq ($(findstring STM32F405, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F4xx @@ -334,7 +354,9 @@ ifneq ($(findstring STM32F407, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F4xx @@ -369,7 +391,9 @@ ifneq ($(findstring STM32F411, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F4xx @@ -409,7 +433,9 @@ ifneq ($(findstring STM32F446, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32F4xx @@ -441,7 +467,9 @@ ifneq ($(findstring STM32G431, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32G4xx @@ -476,7 +504,9 @@ ifneq ($(findstring STM32G474, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32G4xx @@ -511,7 +541,9 @@ ifneq (,$(filter $(MCU),STM32L432 STM32L442)) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32L4xx @@ -548,7 +580,9 @@ ifneq (,$(filter $(MCU),STM32L433 STM32L443)) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32L4xx @@ -585,7 +619,9 @@ ifneq (,$(filter $(MCU),STM32L412 STM32L422)) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = STM32 MCU_SERIES = STM32L4xx @@ -602,7 +638,7 @@ ifneq (,$(filter $(MCU),STM32L412 STM32L422)) # <keyboard_dir>/boards/, or drivers/boards/ BOARD ?= GENERIC_STM32_L412XB - PLATFORM_NAME ?= platform_l432 + PLATFORM_NAME ?= platform_l412_l422 USE_FPU ?= yes @@ -622,7 +658,9 @@ ifneq ($(findstring WB32F3G71, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) MCU_FAMILY = WB32 MCU_SERIES = WB32F3G71xx @@ -657,7 +695,10 @@ ifneq ($(findstring GD32VF103, $(MCU)),) ## chip/board settings # - the next two should match the directories in - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) + # OR + # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + MCU_PORT_NAME = GD MCU_FAMILY = GD32V MCU_SERIES = GD32VF103 diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk index 2820332d56..b30399a56c 100644 --- a/builddefs/show_options.mk +++ b/builddefs/show_options.mk @@ -57,6 +57,7 @@ OTHER_OPTION_NAMES = \ HELIX ZINC \ AUTOLOG_ENABLE \ DEBUG_ENABLE \ + ENCODER_MAP_ENABLE \ ENCODER_ENABLE_CUSTOM \ GERMAN_ENABLE \ HAPTIC_ENABLE \ diff --git a/builddefs/testlist.mk b/builddefs/testlist.mk index 86da5668ac..b8d22bce80 100644 --- a/builddefs/testlist.mk +++ b/builddefs/testlist.mk @@ -2,6 +2,7 @@ TEST_LIST = $(sort $(patsubst %/test.mk,%, $(shell find $(ROOT_DIR)tests -type f FULL_TESTS := $(notdir $(TEST_LIST)) include $(QUANTUM_PATH)/debounce/tests/testlist.mk +include $(QUANTUM_PATH)/encoder/tests/testlist.mk include $(QUANTUM_PATH)/sequencer/tests/testlist.mk include $(PLATFORM_PATH)/test/testlist.mk diff --git a/data/mappings/info_config.json b/data/mappings/info_config.json index cfe8807d43..2121741d19 100644 --- a/data/mappings/info_config.json +++ b/data/mappings/info_config.json @@ -3,7 +3,7 @@ { # Format: # <config.h key>: {"info_key": <info.json key>, ["value_type": <value_type>], ["to_json": <true/false>], ["to_c": <true/false>]} - # value_type: one of "array", "array.int", "bool", "int", "hex", "list", "mapping" + # value_type: one of "array", "array.int", "bool", "int", "hex", "list", "mapping", "str", "raw" # to_json: Default `true`. Set to `false` to exclude this mapping from info.json # to_c: Default `true`. Set to `false` to exclude this mapping from config.h # warn_duplicate: Default `true`. Set to `false` to turn off warning when a value exists in both places @@ -17,7 +17,7 @@ "DEVICE_VER": {"info_key": "usb.device_ver", "value_type": "hex"}, # TODO: Replace ^^^ with vvv #"DEVICE_VER": {"info_key": "usb.device_version", "value_type": "bcd_version"}, - "DESCRIPTION": {"info_key": "keyboard_folder", "to_json": false}, + "DESCRIPTION": {"info_key": "keyboard_folder", "value_type": "str", "to_json": false}, "DIODE_DIRECTION": {"info_key": "diode_direction"}, "FORCE_NKRO": {"info_key": "usb.force_nkro", "value_type": "bool"}, "DYNAMIC_KEYMAP_EEPROM_MAX_ADDR": {"info_key": "dynamic_keymap.eeprom_max_addr", "value_type": "int"}, diff --git a/data/mappings/info_rules.json b/data/mappings/info_rules.json index aea67e04c8..f03cadcd44 100644 --- a/data/mappings/info_rules.json +++ b/data/mappings/info_rules.json @@ -3,7 +3,7 @@ { # Format: # <rules.mk key>: {"info_key": <info.json key>, ["value_type": <value_type>], ["to_json": <true/false>], ["to_c": <true/false>]} - # value_type: one of "array", "array.int", "bool", "int", "list", "hex", "mapping" + # value_type: one of "array", "array.int", "bool", "int", "list", "hex", "mapping", "str", "raw" # to_json: Default `true`. Set to `false` to exclude this mapping from info.json # to_c: Default `true`. Set to `false` to exclude this mapping from rules.mk # warn_duplicate: Default `true`. Set to `false` to turn off warning when a value exists in both places @@ -20,6 +20,6 @@ "MOUSEKEY_ENABLE": {"info_key": "mouse_key.enabled", "value_type": "bool"}, "NO_USB_STARTUP_CHECK": {"info_key": "usb.no_startup_check", "value_type": "bool"}, "SPLIT_KEYBOARD": {"info_key": "split.enabled", "value_type": "bool"}, - "SPLIT_TRANSPORT": {"info_key": "split.transport.protocol", "value_type": "str", "to_c": false}, + "SPLIT_TRANSPORT": {"info_key": "split.transport.protocol", "to_c": false}, "WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"} } diff --git a/api_data/readme.md b/data/templates/api/readme.md index a4b2c6bce7..a4b2c6bce7 100644 --- a/api_data/readme.md +++ b/data/templates/api/readme.md diff --git a/docs/_summary.md b/docs/_summary.md index 74203aa0f8..249bfcd9ed 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -94,7 +94,7 @@ * Hardware Features * Displays - * [HD44780 LCD Controller](feature_hd44780.md) + * [HD44780 LCD Driver](feature_hd44780.md) * [ST7565 LCD Driver](feature_st7565.md) * [OLED Driver](feature_oled_driver.md) * Lighting @@ -147,7 +147,7 @@ * [EEPROM Driver](eeprom_driver.md) * ['serial' Driver](serial_driver.md) * [UART Driver](uart_driver.md) - * [GPIO Controls](internals_gpio_control.md) + * [GPIO Controls](gpio_control.md) * [Keyboard Guidelines](hardware_keyboard_guidelines.md) * Python Development @@ -183,10 +183,10 @@ * [Understanding QMK](understanding_qmk.md) * QMK Internals (In Progress) - * [Defines](internals_defines.md) - * [Input Callback Reg](internals_input_callback_reg.md) - * [Midi Device](internals_midi_device.md) - * [Midi Device Setup Process](internals_midi_device_setup_process.md) - * [Midi Util](internals_midi_util.md) - * [Send Functions](internals_send_functions.md) - * [Sysex Tools](internals_sysex_tools.md) + * [Defines](internals/defines.md) + * [Input Callback Reg](internals/input_callback_reg.md) + * [Midi Device](internals/midi_device.md) + * [Midi Device Setup Process](internals/midi_device_setup_process.md) + * [Midi Util](internals/midi_util.md) + * [Send Functions](internals/send_functions.md) + * [Sysex Tools](internals/sysex_tools.md) diff --git a/docs/config_options.md b/docs/config_options.md index 838c4d86fd..8227a0e074 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -131,6 +131,8 @@ If you define these options you will disable the associated feature, which can s If you define these options you will enable the associated feature, which may increase your code size. +* `#define ENABLE_COMPILE_KEYCODE` + * Enables the `QK_MAKE` keycode * `#define FORCE_NKRO` * NKRO by default requires to be turned on, this forces it on during keyboard startup regardless of EEPROM setting. NKRO can still be turned off but will be turned on again if the keyboard reboots. * `#define STRICT_LAYER_RELEASE` diff --git a/docs/data_driven_config.md b/docs/data_driven_config.md index 38fb5dbf14..cdcf21a19c 100644 --- a/docs/data_driven_config.md +++ b/docs/data_driven_config.md @@ -44,7 +44,7 @@ In other cases you should group like options together in an `object`. This is pa In most cases you can add a simple mapping. These are maintained as JSON files in `data/mappings/info_config.json` and `data/mappings/info_rules.json`, and control mapping for `config.h` and `rules.mk`, respectively. Each mapping is keyed by the `config.h` or `rules.mk` variable, and the value is a hash with the following keys: * `info_key`: (required) The location within `info.json` for this value. See below. -* `value_type`: (optional) Default `str`. The format for this variable's value. See below. +* `value_type`: (optional) Default `raw`. The format for this variable's value. See below. * `to_json`: (optional) Default `true`. Set to `false` to exclude this mapping from info.json * `to_c`: (optional) Default `true`. Set to `false` to exclude this mapping from config.h * `warn_duplicate`: (optional) Default `true`. Set to `false` to turn off warning when a value exists in both places @@ -57,7 +57,7 @@ Under the hood we use [Dotty Dict](https://dotty-dict.readthedocs.io/en/latest/) #### Value Types -By default we treat all values as simple strings. If your value is more complex you can use one of these types to intelligently parse the data: +By default we treat all values as unquoted "raw" data. If your value is more complex you can use one of these types to intelligently parse the data: * `array`: A comma separated array of strings * `array.int`: A comma separated array of integers @@ -65,6 +65,7 @@ By default we treat all values as simple strings. If your value is more complex * `hex`: A number formatted as hex * `list`: A space separate array of strings * `mapping`: A hash of key/value pairs +* `str`: A quoted string literal ### Add code to extract it diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 6a1a3750a6..a3d56fd5ef 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -54,9 +54,43 @@ If you are using different pinouts for the encoders on each half of a split keyb #define ENCODER_RESOLUTIONS_RIGHT { 2, 4 } ``` +If the `_RIGHT` definitions aren't specified in your `config.h`, then the non-`_RIGHT` versions will be applied to both sides of the split. + +Additionally, if one side does not have an encoder, you can specify `{}` for the pins/resolution -- for example, a split keyboard with only a right-side encoder: + +```c +#define ENCODERS_PAD_A { } +#define ENCODERS_PAD_B { } +#define ENCODER_RESOLUTIONS { } +#define ENCODERS_PAD_A_RIGHT { B12 } +#define ENCODERS_PAD_B_RIGHT { B13 } +#define ENCODER_RESOLUTIONS_RIGHT { 4 } +``` + +## Encoder map + +Encoder mapping may be added to your `keymap.c`, which replicates the normal keyswitch layer handling functionality, but with encoders. Add this to your `rules.mk`: + +```make +ENCODER_MAP_ENABLE = yes +``` + +Your `keymap.c` will then need an encoder mapping defined (for four layers and two encoders): + +```c +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { + [_BASE] = { ENCODER_CCW_CW(KC_MS_WH_UP, KC_MS_WH_DOWN), ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, + [_LOWER] = { ENCODER_CCW_CW(RGB_HUD, RGB_HUI), ENCODER_CCW_CW(RGB_SAD, RGB_SAI) }, + [_RAISE] = { ENCODER_CCW_CW(RGB_VAD, RGB_VAI), ENCODER_CCW_CW(RGB_SPD, RGB_SPI) }, + [_ADJUST] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD), ENCODER_CCW_CW(KC_RIGHT, KC_LEFT) }, +}; +#endif +``` + ## Callbacks -The callback functions can be inserted into your `<keyboard>.c`: +When not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`: ```c bool encoder_update_kb(uint8_t index, bool clockwise) { diff --git a/docs/feature_hd44780.md b/docs/feature_hd44780.md index dc476c734f..4ade640baa 100644 --- a/docs/feature_hd44780.md +++ b/docs/feature_hd44780.md @@ -1,57 +1,298 @@ -# HD44780 LCD Displays - -This is an integration of Peter Fleury's LCD library. This page will explain the basics. [For in depth documentation visit his page.](http://www.peterfleury.epizy.com/doxygen/avr-gcc-libraries/group__pfleury__lcd.html) - -You can enable support for HD44780 Displays by setting the `HD44780_ENABLE` flag in your keyboards `rules.mk` to yes. - -## Configuration - -You will need to configure the pins used by your display, and its number of lines and columns in your keyboard's `config.h`. - - -Uncomment the section labled HD44780 and change the parameters as needed. -```` -/* - * HD44780 LCD Display Configuration - */ - -#define LCD_LINES 2 //< number of visible lines of the display -#define LCD_DISP_LENGTH 16 //< visibles characters per line of the display -#define LCD_IO_MODE 1 //< 0: memory mapped mode, 1: IO port mode -#if LCD_IO_MODE -#define LCD_PORT PORTB //< port for the LCD lines -#define LCD_DATA0_PORT LCD_PORT //< port for 4bit data bit 0 -#define LCD_DATA1_PORT LCD_PORT //< port for 4bit data bit 1 -#define LCD_DATA2_PORT LCD_PORT //< port for 4bit data bit 2 -#define LCD_DATA3_PORT LCD_PORT //< port for 4bit data bit 3 -#define LCD_DATA0_PIN 4 //< pin for 4bit data bit 0 -#define LCD_DATA1_PIN 5 //< pin for 4bit data bit 1 -#define LCD_DATA2_PIN 6 //< pin for 4bit data bit 2 -#define LCD_DATA3_PIN 7 //< pin for 4bit data bit 3 -#define LCD_RS_PORT LCD_PORT //< port for RS line -#define LCD_RS_PIN 3 //< pin for RS line -#define LCD_RW_PORT LCD_PORT //< port for RW line -#define LCD_RW_PIN 2 //< pin for RW line -#define LCD_E_PORT LCD_PORT //< port for Enable line -#define LCD_E_PIN 1 //< pin for Enable line -#endif -```` - -Should you need to configure other properties you can copy them from `quantum/hd44780.h` and set them in your `config.h` +# HD44780 LCD Driver + +## Supported Hardware + +LCD modules using [HD44780U](https://www.sparkfun.com/datasheets/LCD/HD44780.pdf) IC or equivalent, communicating in 4-bit mode. + +|Module|Size |Notes | +|------|--------------|---------------------------------| +|1602A |16x2, 5x8 dots| | +|2004A |20x4, 5x8 dots|Untested, not currently supported| + +To run these modules at 3.3V, an additional MAX660 voltage converter IC must be soldered on, along with two 10µF capacitors. See [this page](https://www.codrey.com/electronic-circuits/hack-your-16x2-lcd/) for more details. ## Usage -To initialize your display, call `lcd_init()` with one of these parameters: -```` -LCD_DISP_OFF : display off -LCD_DISP_ON : display on, cursor off -LCD_DISP_ON_CURSOR : display on, cursor on -LCD_DISP_ON_CURSOR_BLINK : display on, cursor on flashing -```` -This is best done in your keyboards `matrix_init_kb` or your keymaps `matrix_init_user`. -It is advised to clear the display before use. -To do so call `lcd_clrscr()`. +Add the following to your `rules.mk`: + +```make +HD44780_ENABLE = yes +``` + +## Basic Configuration + +Add the following to your `config.h`: + +|Define |Default |Description | +|-----------------------|--------------|-----------------------------------------------------------------------------------------------------| +|`HD44780_DATA_PINS` |*Not defined* |(Required) An array of four GPIO pins connected to the display's D4-D7 pins, eg. `{ B1, B3, B2, B6 }`| +|`HD44780_RS_PIN` |*Not defined* |(Required) The GPIO connected to the display's RS pin | +|`HD44780_RW_PIN` |*Not defined* |(Required) The GPIO connected to the display's RW pin | +|`HD44780_E_PIN` |*Not defined* |(Required) The GPIO connected to the display's E pin | +|`HD44780_DISPLAY_COLS` |`16` |The number of visible characters on a single line of the display | +|`HD44780_DISPLAY_LINES`|`2` |The number of visible lines on the display | +|`HD44780_WRAP_LINES` |*Not defined* |If defined, input characters will wrap to the next line | + +## Examples + +### Hello World + +Add the following to your `keymap.c`: + +```c +void keyboard_post_init_user(void) { + hd44780_init(true, true); // Show blinking cursor + hd44780_puts_P(PSTR("Hello, world!\n")); +} +``` + +### Custom Character Definition + +Up to eight custom characters can be defined. This data is stored in the Character Generator RAM (CGRAM), and is not persistent across power cycles. + +This example defines the QMK Psi as the first custom character. The first 16 positions in the character set are reserved for the eight custom characters duplicated. + +``` +Byte | 16 8 4 2 1 + 1 | x x x ■ □ ■ □ ■ + 2 | x x x ■ □ ■ □ ■ + 3 | x x x ■ □ ■ □ ■ + 4 | x x x □ ■ ■ ■ □ + 5 | x x x □ □ ■ □ □ + 6 | x x x □ □ ■ □ □ + 7 | x x x □ □ ■ □ □ + 8 | x x x □ □ □ □ □ +``` + +```c +const uint8_t PROGMEM psi[8] = { 0x15, 0x15, 0x15, 0x0E, 0x04, 0x04, 0x04, 0x00 }; + +void keyboard_post_init_user(void) { + hd44780_init(false, false); + hd44780_define_char_P(0, psi); + // Cursor is incremented while defining characters so must be reset + hd44780_home(); + // 0x08 to avoid null terminator + hd44780_puts_P(PSTR("\x08 QMK Firmware")); +} +``` + +## API + +### `void hd44780_init(bool cursor, bool blink)` + +Initialize the display. + +This function should be called only once, before any of the other functions can be called. + +#### Arguments + + - `bool cursor` + Whether to show the cursor. + - `bool blink` + Whether to blink the cursor, if shown. + +--- + +### `void hd44780_clear(void)` + +Clear the display. + +This function is called on init. + +--- + +### `void hd44780_home(void)` + +Move the cursor to the home position. + +This function is called on init. + +--- + +### `void hd44780_on(bool cursor, bool blink)` + +Turn the display on, and/or set the cursor properties. + +This function is called on init. + +#### Arguments + + - `bool cursor` + Whether to show the cursor. + - `bool blink` + Whether to blink the cursor, if shown. + +--- + +### `void hd44780_off(void)` + +Turn the display off. + +--- + +### `void hd44780_set_cursor(uint8_t col, uint8_t line)` + +Move the cursor to the specified position on the display. + +#### Arguments + + - `uint8_t col` + The column number to move to, from 0 to 15 on 16x2 displays. + - `bool line` + The line number to move to, either 0 or 1 on 16x2 displays. + +--- + +### `void hd44780_putc(char c)` + +Print a character to the display. The newline character `\n` will move the cursor to the start of the next line. + +The exact character shown may depend on the ROM code of your particular display - refer to the datasheet for the full character set. + +#### Arguments + + - `char c` + The character to print. + +--- + +### `void hd44780_puts(const char *s)` + +Print a string of characters to the display. + +#### Arguments + + - `const char *s` + The string to print. + +--- + +### `void hd44780_puts_P(const char *s)` + +Print a string of characters from PROGMEM to the display. + +On ARM devices, this function is simply an alias of `hd44780_puts()`. + +#### Arguments + + - `const char *s` + The PROGMEM string to print (ie. `PSTR("Hello")`). + +--- + +### `void hd44780_define_char(uint8_t index, uint8_t *data)` + +Define a custom character. + +#### Arguments + + - `uint8_t index` + The index of the custom character to define, from 0 to 7. + - `uint8_t *data` + An array of 8 bytes containing the 5-bit row data of the character, where the first byte is the topmost row, and the least significant bit of each byte is the rightmost column. + +--- + +### `void hd44780_define_char_P(uint8_t index, const uint8_t *data)` + +Define a custom character from PROGMEM. + +On ARM devices, this function is simply an alias of `hd44780_define_char()`. + +#### Arguments + + - `uint8_t index` + The index of the custom character to define, from 0 to 7. + - `const uint8_t *data` + A PROGMEM array of 8 bytes containing the 5-bit row data of the character, where the first byte is the topmost row, and the least significant bit of each byte is the rightmost column. + +--- + +### `bool hd44780_busy(void)` + +Indicates whether the display is currently processing, and cannot accept instructions. + +#### Return Value + +`true` if the display is busy. + +--- + +### `void hd44780_write(uint8_t data, bool isData)` + +Write a byte to the display. + +#### Arguments + + - `uint8_t data` + The byte to send to the display. + - `bool isData` + Whether the byte is an instruction or character data. + +--- + +### `uint8_t hd44780_read(bool isData)` + +Read a byte from the display. + +#### Arguments + + - `bool isData` + Whether to read the current cursor position, or the character at the cursor. + +#### Return Value + +If `isData` is `true`, the returned byte will be the character at the current DDRAM address. Otherwise, it will be the current DDRAM address and the busy flag. + +--- + +### `void hd44780_command(uint8_t command)` + +Send a command to the display. Refer to the datasheet and `hd44780.h` for the valid commands and defines. + +This function waits for the display to clear the busy flag before sending the command. + +#### Arguments + + - `uint8_t command` + The command to send. + +--- + +### `void hd44780_data(uint8_t data)` + +Send a byte of data to the display. + +This function waits for the display to clear the busy flag before sending the data. + +#### Arguments + + - `uint8_t data` + The byte of data to send. + +--- + +### `void hd44780_set_cgram_address(uint8_t address)` + +Set the CGRAM address. + +This function is used when defining custom characters. + +#### Arguments + + - `uint8_t address` + The CGRAM address to move to, from `0x00` to `0x3F`. + +--- + +### `void hd44780_set_ddram_address(uint8_t address)` + +Set the DDRAM address. + +This function is used when printing characters to the display, and setting the cursor. -To now print something to your Display you first call `lcd_gotoxy(column, line)`. To go to the start of the first line you would call `lcd_gotoxy(0, 0)` and then print a string with `lcd_puts("example string")`. +#### Arguments -There are more methods available to control the display. [For in depth documentation please visit the linked page.](http://www.peterfleury.epizy.com/doxygen/avr-gcc-libraries/group__pfleury__lcd.html) + - `uint8_t address` + The DDRAM address to move to, from `0x00` to `0x7F`. diff --git a/docs/feature_midi.md b/docs/feature_midi.md index 3da5c4940a..490bf7cc7d 100644 --- a/docs/feature_midi.md +++ b/docs/feature_midi.md @@ -254,7 +254,7 @@ For the above, the `MI_C` keycode will produce a C3 (note number 48), and so on. <!-- #### QMK Internals (Autogenerated) - * [Internals/MIDI Device Setup Process](internals_midi_device_setup_process.md) - * [Internals/MIDI Device](internals_midi_device.md) - * [Internals/MIDI Util](internals_midi_util.md) + * [Internals/MIDI Device Setup Process](internals/midi_device_setup_process.md) + * [Internals/MIDI Device](internals/midi_device.md) + * [Internals/MIDI Util](internals/midi_util.md) --> diff --git a/docs/feature_swap_hands.md b/docs/feature_swap_hands.md index 654108ae70..6768020f12 100644 --- a/docs/feature_swap_hands.md +++ b/docs/feature_swap_hands.md @@ -31,3 +31,16 @@ Note that the array indices are reversed same as the matrix and the values are o |`SH_OS` |One shot swap hands: toggles while pressed or until next key press. | `SH_TT` swap-hands tap-toggle key is similar to [layer tap-toggle](feature_layers.md?id=switching-and-toggling-layers). Tapping repeatedly (5 taps by default) will toggle swap-hands on or off, like `SH_TG`. Tap-toggle count can be changed by defining a value for `TAPPING_TOGGLE`. + +## Encoder Mapping + +When using an encoder mapping, it's also able to handle swapping encoders between sides, too. + +Encoder indexes are defined as left-to-right, and the extent of the array needs to match the number of encoders on the keyboard. + +As an example, if a split keyboard has a single encoder per side, you can swap the order by using the following code in your keymap: +```c +#if defined(SWAP_HANDS_ENABLE) && defined(ENCODER_MAP_ENABLE) +const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS] = { 1, 0 }; +#endif +``` diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 6c3e2a1a2f..bced419a03 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -230,17 +230,6 @@ send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻"); Example uses include sending Unicode strings when a key is pressed, as described in [Macros](feature_macros.md). -### `send_unicode_hex_string()` (Deprecated) - -Similar to `send_unicode_string()`, but the characters are represented by their Unicode code points, written in hexadecimal and separated by spaces. For example, the table flip above would be achieved with: - -```c -send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B"); -``` - -An easy way to convert your Unicode string to this format is to use [this site](https://r12a.github.io/app-conversion/) and take the result in the "Hex/UTF-32" section. - - ## Additional Language Support In `quantum/keymap_extras`, you'll see various language files — these work the same way as the ones for alternative layouts such as Colemak or BÉPO. When you include one of these language headers, you gain access to keycodes specific to that language / national layout. Such keycodes are defined by a 2-letter country/language code, followed by an underscore and a 4-letter abbreviation of the character to which the key corresponds. For example, including `keymap_french.h` and using `FR_UGRV` in your keymap will output `ù` when typed on a system with a native French AZERTY layout. diff --git a/docs/flashing.md b/docs/flashing.md index 83f4bf82ae..ae31f9c621 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -347,3 +347,14 @@ Flashing sequence: 2. Wait for the OS to detect the device 3. Copy the .uf2 file to the new USB disk 4. Wait for the keyboard to become available + +or + +CLI Flashing sequence: + +1. Enter the bootloader using any of the following methods: + * Tap the `RESET` keycode + * Double-tap the `nRST` button on the PCB. +2. Wait for the OS to detect the device +3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/blackpill_f411_tinyuf2 --keymap default` +4. Wait for the keyboard to become available diff --git a/docs/internals_gpio_control.md b/docs/gpio_control.md index e1f1515b71..e1f1515b71 100644 --- a/docs/internals_gpio_control.md +++ b/docs/gpio_control.md diff --git a/docs/internals_defines.md b/docs/internals/defines.md index fdcb553589..fdcb553589 100644 --- a/docs/internals_defines.md +++ b/docs/internals/defines.md diff --git a/docs/internals_input_callback_reg.md b/docs/internals/input_callback_reg.md index 4ea132a83a..4ea132a83a 100644 --- a/docs/internals_input_callback_reg.md +++ b/docs/internals/input_callback_reg.md diff --git a/docs/internals_midi_device.md b/docs/internals/midi_device.md index 5b57abd454..5b57abd454 100644 --- a/docs/internals_midi_device.md +++ b/docs/internals/midi_device.md diff --git a/docs/internals_midi_device_setup_process.md b/docs/internals/midi_device_setup_process.md index ae82197c5c..ae82197c5c 100644 --- a/docs/internals_midi_device_setup_process.md +++ b/docs/internals/midi_device_setup_process.md diff --git a/docs/internals_midi_util.md b/docs/internals/midi_util.md index 97821bd180..97821bd180 100644 --- a/docs/internals_midi_util.md +++ b/docs/internals/midi_util.md diff --git a/docs/internals_send_functions.md b/docs/internals/send_functions.md index b331508008..b331508008 100644 --- a/docs/internals_send_functions.md +++ b/docs/internals/send_functions.md diff --git a/docs/internals_sysex_tools.md b/docs/internals/sysex_tools.md index 55dbe9e164..55dbe9e164 100644 --- a/docs/internals_sysex_tools.md +++ b/docs/internals/sysex_tools.md diff --git a/docs/ja/_summary.md b/docs/ja/_summary.md index b90480041c..81b5756c27 100644 --- a/docs/ja/_summary.md +++ b/docs/ja/_summary.md @@ -137,7 +137,7 @@ * [EEPROM ドライバ](ja/eeprom_driver.md) * [シリアル ドライバ](ja/serial_driver.md) * [UART ドライバ](ja/uart_driver.md) - * [GPIO 制御](ja/internals_gpio_control.md) + * [GPIO 制御](ja/gpio_control.md) * [キーボード ガイドライン](ja/hardware_keyboard_guidelines.md) * Python 開発 @@ -173,10 +173,10 @@ * [QMK を理解する](ja/understanding_qmk.md) * QMK の内部詳細(作成中) - * [定義](ja/internals_defines.md) - * [入力コールバック登録](ja/internals_input_callback_reg.md) - * [Midi デバイス](ja/internals_midi_device.md) - * [Midi デバイスのセットアップ手順](ja/internals_midi_device_setup_process.md) - * [Midi ユーティリティ](ja/internals_midi_util.md) - * [Midi 送信関数](ja/internals_send_functions.md) - * [Sysex Tools](ja/internals_sysex_tools.md) + * [定義](ja/internals/defines.md) + * [入力コールバック登録](ja/internals/input_callback_reg.md) + * [Midi デバイス](ja/internals/midi_device.md) + * [Midi デバイスのセットアップ手順](ja/internals/midi_device_setup_process.md) + * [Midi ユーティリティ](ja/internals/midi_util.md) + * [Midi 送信関数](ja/internals/send_functions.md) + * [Sysex Tools](ja/internals/sysex_tools.md) diff --git a/docs/ja/feature_unicode.md b/docs/ja/feature_unicode.md index bfcb866ce1..2158678f3c 100644 --- a/docs/ja/feature_unicode.md +++ b/docs/ja/feature_unicode.md @@ -233,17 +233,6 @@ send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻"); 使用例には、[Macros](ja/feature_macros.md) で説明されているように、キーが押された時に Unicode 文字列を送信することが含まれます。 -### `send_unicode_hex_string()` - -`send_unicode_string()` に似ていますが、文字は Unicode コードポイントで表され、16進数で記述され、空白で区切られています。例えば、上記のちゃぶ台返しは以下で表されます: - -```c -send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B"); -``` - -[このサイト](https://r12a.github.io/app-conversion/)で結果を "Hex/UTF-32" で受け取ることで、Unicode 文字列をこの形式に簡単に変換できます。 - - ## 追加の言語サポート `quantum/keymap_extras` には、様々な言語ファイルがあります — これらは Colemak または BÉPO のような代替レイアウトのファイルと同じように動作します。これらの言語ヘッダのいずれかを `#include` すると、その言語/国のレイアウトに固有のキーコードにアクセスできます。このようなキーコードは、2文字の国/言語コードの後に、アンダースコアとキーが対応する4文字の略語が続くことで定義されます。例えば、キーマップに `keymap_french.h` を含め、`FR_UGRV` を使うと、ネイティブのフランス語 AZERTY レイアウトを使うシステムで入力すると、`ù` が出力されます。 diff --git a/docs/ja/internals_gpio_control.md b/docs/ja/gpio_control.md index 60c5367870..7bece3e0c7 100644 --- a/docs/ja/internals_gpio_control.md +++ b/docs/ja/gpio_control.md @@ -1,8 +1,8 @@ # GPIO 制御 :id=gpio-control <!--- - original document: 0.13.15:docs/internals_gpio_control.md - git diff 0.13.15 HEAD -- docs/internals_gpio_control.md | cat + original document: 0.13.15:docs/gpio_control.md + git diff 0.13.15 HEAD -- docs/gpio_control.md | cat --> QMK には、マイクロコントローラに依存しない GPIO 制御抽象レイヤーがあります。これは異なるプラットフォーム間でピン制御に簡単にアクセスできるようにするためのものです。 diff --git a/docs/ja/internals_defines.md b/docs/ja/internals_defines.md deleted file mode 100644 index 512730df75..0000000000 --- a/docs/ja/internals_defines.md +++ /dev/null @@ -1,78 +0,0 @@ -# `defines` グループ {#group__defines} - -## 概要 - -メンバー | 説明 ---------------------------------|--------------------------------------------- -`define `[`SYSEX_BEGIN`](#group__defines_1ga1a3c39bb790dda8a368c4247caabcf79) | -`define `[`SYSEX_END`](#group__defines_1ga753706d1d28e6f96d7caf1973e80feed) | -`define `[`MIDI_STATUSMASK`](#group__defines_1gab78a1c818a5f5dab7a8946543f126c69) | -`define `[`MIDI_CHANMASK`](#group__defines_1ga239edc0a6f8405d3a8f2804f1590b909) | -`define `[`MIDI_CC`](#group__defines_1ga45f116a1daab76b3c930c2cecfaef215) | -`define `[`MIDI_NOTEON`](#group__defines_1gafd416f27bf3590868c0c1f55c30be4c7) | -`define `[`MIDI_NOTEOFF`](#group__defines_1gabed24bea2d989fd655e2ef2ad0765adc) | -`define `[`MIDI_AFTERTOUCH`](#group__defines_1ga3a322d8cfd53576a2e167c1840551b0f) | -`define `[`MIDI_PITCHBEND`](#group__defines_1gabcc799504e8064679bca03f232223af4) | -`define `[`MIDI_PROGCHANGE`](#group__defines_1gaefb3f1595ffbb9db66b46c2c919a3d42) | -`define `[`MIDI_CHANPRESSURE`](#group__defines_1gaeb3281cc7fcd0daade8ed3d2dfc33dbe) | -`define `[`MIDI_CLOCK`](#group__defines_1gafa5e4e295aafd15ab7893344599b3b89) | -`define `[`MIDI_TICK`](#group__defines_1ga3b99408ff864613765d4c3c2ceb52aa7) | -`define `[`MIDI_START`](#group__defines_1ga8233631c85823aa546f932ad8975caa4) | -`define `[`MIDI_CONTINUE`](#group__defines_1gab24430f0081e27215b0da84dd0ee745c) | -`define `[`MIDI_STOP`](#group__defines_1ga3af9271d4b1f0d22904a0b055f48cf62) | -`define `[`MIDI_ACTIVESENSE`](#group__defines_1gacd88ed42dba52bb4b2052c5656362677) | -`define `[`MIDI_RESET`](#group__defines_1ga02947f30ca62dc332fdeb10c5868323b) | -`define `[`MIDI_TC_QUARTERFRAME`](#group__defines_1gaaa072f33590e236d1bfd8f28e833ae31) | -`define `[`MIDI_SONGPOSITION`](#group__defines_1ga412f6ed33a2150051374bee334ee1705) | -`define `[`MIDI_SONGSELECT`](#group__defines_1gafcab254838b028365ae0259729e72c4e) | -`define `[`MIDI_TUNEREQUEST`](#group__defines_1ga8100b907b8c0a84e58b1c53dcd9bd795) | -`define `[`SYSEX_EDUMANUFID`](#group__defines_1ga5ef855ed955b00a2239ca16afbeb164f) | - -## メンバー - -#### `define `[`SYSEX_BEGIN`](#group__defines_1ga1a3c39bb790dda8a368c4247caabcf79) {#group__defines_1ga1a3c39bb790dda8a368c4247caabcf79} - -#### `define `[`SYSEX_END`](#group__defines_1ga753706d1d28e6f96d7caf1973e80feed) {#group__defines_1ga753706d1d28e6f96d7caf1973e80feed} - -#### `define `[`MIDI_STATUSMASK`](#group__defines_1gab78a1c818a5f5dab7a8946543f126c69) {#group__defines_1gab78a1c818a5f5dab7a8946543f126c69} - -#### `define `[`MIDI_CHANMASK`](#group__defines_1ga239edc0a6f8405d3a8f2804f1590b909) {#group__defines_1ga239edc0a6f8405d3a8f2804f1590b909} - -#### `define `[`MIDI_CC`](#group__defines_1ga45f116a1daab76b3c930c2cecfaef215) {#group__defines_1ga45f116a1daab76b3c930c2cecfaef215} - -#### `define `[`MIDI_NOTEON`](#group__defines_1gafd416f27bf3590868c0c1f55c30be4c7) {#group__defines_1gafd416f27bf3590868c0c1f55c30be4c7} - -#### `define `[`MIDI_NOTEOFF`](#group__defines_1gabed24bea2d989fd655e2ef2ad0765adc) {#group__defines_1gabed24bea2d989fd655e2ef2ad0765adc} - -#### `define `[`MIDI_AFTERTOUCH`](#group__defines_1ga3a322d8cfd53576a2e167c1840551b0f) {#group__defines_1ga3a322d8cfd53576a2e167c1840551b0f} - -#### `define `[`MIDI_PITCHBEND`](#group__defines_1gabcc799504e8064679bca03f232223af4) {#group__defines_1gabcc799504e8064679bca03f232223af4} - -#### `define `[`MIDI_PROGCHANGE`](#group__defines_1gaefb3f1595ffbb9db66b46c2c919a3d42) {#group__defines_1gaefb3f1595ffbb9db66b46c2c919a3d42} - -#### `define `[`MIDI_CHANPRESSURE`](#group__defines_1gaeb3281cc7fcd0daade8ed3d2dfc33dbe) {#group__defines_1gaeb3281cc7fcd0daade8ed3d2dfc33dbe} - -#### `define `[`MIDI_CLOCK`](#group__defines_1gafa5e4e295aafd15ab7893344599b3b89) {#group__defines_1gafa5e4e295aafd15ab7893344599b3b89} - -#### `define `[`MIDI_TICK`](#group__defines_1ga3b99408ff864613765d4c3c2ceb52aa7) {#group__defines_1ga3b99408ff864613765d4c3c2ceb52aa7} - -#### `define `[`MIDI_START`](#group__defines_1ga8233631c85823aa546f932ad8975caa4) {#group__defines_1ga8233631c85823aa546f932ad8975caa4} - -#### `define `[`MIDI_CONTINUE`](#group__defines_1gab24430f0081e27215b0da84dd0ee745c) {#group__defines_1gab24430f0081e27215b0da84dd0ee745c} - -#### `define `[`MIDI_STOP`](#group__defines_1ga3af9271d4b1f0d22904a0b055f48cf62) {#group__defines_1ga3af9271d4b1f0d22904a0b055f48cf62} - -#### `define `[`MIDI_ACTIVESENSE`](#group__defines_1gacd88ed42dba52bb4b2052c5656362677) {#group__defines_1gacd88ed42dba52bb4b2052c5656362677} - -#### `define `[`MIDI_RESET`](#group__defines_1ga02947f30ca62dc332fdeb10c5868323b) {#group__defines_1ga02947f30ca62dc332fdeb10c5868323b} - -#### `define `[`MIDI_TC_QUARTERFRAME`](#group__defines_1gaaa072f33590e236d1bfd8f28e833ae31) {#group__defines_1gaaa072f33590e236d1bfd8f28e833ae31} - -#### `define `[`MIDI_SONGPOSITION`](#group__defines_1ga412f6ed33a2150051374bee334ee1705) {#group__defines_1ga412f6ed33a2150051374bee334ee1705} - -#### `define `[`MIDI_SONGSELECT`](#group__defines_1gafcab254838b028365ae0259729e72c4e) {#group__defines_1gafcab254838b028365ae0259729e72c4e} - -#### `define `[`MIDI_TUNEREQUEST`](#group__defines_1ga8100b907b8c0a84e58b1c53dcd9bd795) {#group__defines_1ga8100b907b8c0a84e58b1c53dcd9bd795} - -#### `define `[`SYSEX_EDUMANUFID`](#group__defines_1ga5ef855ed955b00a2239ca16afbeb164f) {#group__defines_1ga5ef855ed955b00a2239ca16afbeb164f} - diff --git a/docs/ja/internals_input_callback_reg.md b/docs/ja/internals_input_callback_reg.md deleted file mode 100644 index 864b1d5750..0000000000 --- a/docs/ja/internals_input_callback_reg.md +++ /dev/null @@ -1,173 +0,0 @@ -# group `input_callback_reg` {#group__input__callback__reg} - -<!--- - original document: 0.9.34:docs/internals_input_callback_reg.md - git diff 0.9.34 HEAD -- docs/internals_input_callback_reg.md | cat ---> - -これらは受信コールバックを登録するために使用する関数です。 - -関数は、適切な midi メッセージが関連するデバイスの入力と一致した場合に呼び出されます。 - -## 概要 - -| メンバー | 説明 | ---------------------------------|--------------------------------------------- -| `public void `[`midi_register_cc_callback`](#group__input__callback__reg_1ga64ab672abbbe393c9c4a83110c8df718)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | コントロールチェンジメッセージ受信コールバックを登録する。 | -| `public void `[`midi_register_noteon_callback`](#group__input__callback__reg_1ga3962f276c17618923f1152779552103e)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | ノートオン受信コールバックを登録する。 | -| `public void `[`midi_register_noteoff_callback`](#group__input__callback__reg_1gac847b66051bd6d53b762958be0ec4c6d)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | ノートオフ受信コールバックを登録する。 | -| `public void `[`midi_register_aftertouch_callback`](#group__input__callback__reg_1gaa95bc901bd9edff956a667c9a69dd01f)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | アフタータッチ受信コールバックを登録する。 | -| `public void `[`midi_register_pitchbend_callback`](#group__input__callback__reg_1ga071a28f02ba14f53de219be70ebd9a48)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | ピッチベンド受信コールバックを登録する。 | -| `public void `[`midi_register_songposition_callback`](#group__input__callback__reg_1gaf2adfd79637f3553d8f26deb1ca22ed6)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` | ソングポジション受信コールバックを登録する。 | -| `public void `[`midi_register_progchange_callback`](#group__input__callback__reg_1gae6ba1a35a4cde9bd15dd42f87401d127)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` | プログラムチェンジ受信コールバックを登録する。 | -| `public void `[`midi_register_chanpressure_callback`](#group__input__callback__reg_1ga39b31f1f4fb93917ce039b958f21b4f5)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` | チャンネルプレッシャー受信コールバックを登録する。 | -| `public void `[`midi_register_songselect_callback`](#group__input__callback__reg_1gaf9aafc76a2dc4b9fdbb4106cbda6ce72)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` | ソングセレクト受信コールバックを登録する。 | -| `public void `[`midi_register_tc_quarterframe_callback`](#group__input__callback__reg_1ga0a119fada2becc628cb15d753b257e6e)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` | タイムコードクォータフレーム受信コールバックを登録する。 | -| `public void `[`midi_register_realtime_callback`](#group__input__callback__reg_1ga764f440e857b89084b1a07f9da2ff93a)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_one_byte_func_t func)` | リアルタイム受信コールバックを登録する。 | -| `public void `[`midi_register_tunerequest_callback`](#group__input__callback__reg_1gae40ff3ce20bda79fef87da24b8321cb1)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_one_byte_func_t func)` | チューンリクエスト受信コールバックを登録する。 | -| `public void `[`midi_register_sysex_callback`](#group__input__callback__reg_1ga63ce9631b025785c1848d0122d4c4c48)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_sysex_func_t func)` | システムエクスクルーシブ受信コールバックを登録する。 | -| `public void `[`midi_register_fallthrough_callback`](#group__input__callback__reg_1ga7ed189164aa9682862b3181153afbd94)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t func)` | フォールスルー受信コールバックを登録する。 | -| `public void `[`midi_register_catchall_callback`](#group__input__callback__reg_1ga9dbfed568d047a6cd05708f11fe39e99)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t func)` | キャッチオール受信コールバックを登録する。 | - -## メンバー - -#### `public void `[`midi_register_cc_callback`](#group__input__callback__reg_1ga64ab672abbbe393c9c4a83110c8df718)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1ga64ab672abbbe393c9c4a83110c8df718} - -コントロールチェンジメッセージ受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_noteon_callback`](#group__input__callback__reg_1ga3962f276c17618923f1152779552103e)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1ga3962f276c17618923f1152779552103e} - -ノートオン受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_noteoff_callback`](#group__input__callback__reg_1gac847b66051bd6d53b762958be0ec4c6d)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1gac847b66051bd6d53b762958be0ec4c6d} - -ノートオフ受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_aftertouch_callback`](#group__input__callback__reg_1gaa95bc901bd9edff956a667c9a69dd01f)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1gaa95bc901bd9edff956a667c9a69dd01f} - -アフタータッチ受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_pitchbend_callback`](#group__input__callback__reg_1ga071a28f02ba14f53de219be70ebd9a48)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1ga071a28f02ba14f53de219be70ebd9a48} - -ピッチベンド受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_songposition_callback`](#group__input__callback__reg_1gaf2adfd79637f3553d8f26deb1ca22ed6)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_three_byte_func_t func)` {#group__input__callback__reg_1gaf2adfd79637f3553d8f26deb1ca22ed6} - -ソングポジション受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_progchange_callback`](#group__input__callback__reg_1gae6ba1a35a4cde9bd15dd42f87401d127)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` {#group__input__callback__reg_1gae6ba1a35a4cde9bd15dd42f87401d127} - -プログラムチェンジ受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_chanpressure_callback`](#group__input__callback__reg_1ga39b31f1f4fb93917ce039b958f21b4f5)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` {#group__input__callback__reg_1ga39b31f1f4fb93917ce039b958f21b4f5} - -チャンネルプレッシャー受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_songselect_callback`](#group__input__callback__reg_1gaf9aafc76a2dc4b9fdbb4106cbda6ce72)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` {#group__input__callback__reg_1gaf9aafc76a2dc4b9fdbb4106cbda6ce72} - -ソングセレクト受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_tc_quarterframe_callback`](#group__input__callback__reg_1ga0a119fada2becc628cb15d753b257e6e)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_two_byte_func_t func)` {#group__input__callback__reg_1ga0a119fada2becc628cb15d753b257e6e} - -タイムコードクォータフレーム受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_realtime_callback`](#group__input__callback__reg_1ga764f440e857b89084b1a07f9da2ff93a)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_one_byte_func_t func)` {#group__input__callback__reg_1ga764f440e857b89084b1a07f9da2ff93a} - -リアルタイム受信コールバックを登録する。 - -全てのリアルタイムメッセージ型に対してコールバックが呼ばれます。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_tunerequest_callback`](#group__input__callback__reg_1gae40ff3ce20bda79fef87da24b8321cb1)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_one_byte_func_t func)` {#group__input__callback__reg_1gae40ff3ce20bda79fef87da24b8321cb1} - -チューンリクエスト受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_sysex_callback`](#group__input__callback__reg_1ga63ce9631b025785c1848d0122d4c4c48)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_sysex_func_t func)` {#group__input__callback__reg_1ga63ce9631b025785c1848d0122d4c4c48} - -システムエクスクルーシブ受信コールバックを登録する。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_fallthrough_callback`](#group__input__callback__reg_1ga7ed189164aa9682862b3181153afbd94)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t func)` {#group__input__callback__reg_1ga7ed189164aa9682862b3181153afbd94} - -フォールスルー受信コールバックを登録する。 - -より具体的なコールバックが見つからない場合にのみ呼ばれます。例えば、ノートオン受信コールバックを登録していないがノートオンメッセージを受け取った場合、フォールスルー受信コールバックが登録されている場合はそれが呼ばれます。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 - -#### `public void `[`midi_register_catchall_callback`](#group__input__callback__reg_1ga9dbfed568d047a6cd05708f11fe39e99)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t func)` {#group__input__callback__reg_1ga9dbfed568d047a6cd05708f11fe39e99} - -キャッチオール受信コールバックを登録する。 - -登録されている場合は、より具体的なコールバックあるいはフォールスルー受信コールバックが登録されている場合でも、一致する全てのメッセージに対してキャッチオール受信コールバックが呼ばれます。 - -#### パラメータ -* `device` 関連するデバイス - -* `func` 登録するコールバック関数 diff --git a/docs/ja/internals_midi_device.md b/docs/ja/internals_midi_device.md deleted file mode 100644 index 6adc2d5ad9..0000000000 --- a/docs/ja/internals_midi_device.md +++ /dev/null @@ -1,148 +0,0 @@ -# `midi_device` グループ {#group__midi__device} - -<!--- - original document: 0.10.9:docs/internals_midi_device.md - git diff 0.10.9 HEAD -- docs/internals_midi_device.md | cat ---> - -独自の MIDI デバイスを実装する時に、関数を使います。 - -実際にデバイスを介してバイトを送信するために、送信関数を設定します。このメソッドは、このデバイスで例えば midi_send_cc のような送信関数を呼ぶ時に呼ばれます。 - -midi_device_input を使ってデバイスからの入力データを処理し、それをデバイスに関連付けられたコールバックで渡します。 - -デバイスのプロセス関数の最初に呼び出される関数が必要な場合、midi_device_set_pre_input_process_func を使います。通常、入力をポーリングして midi_device_input に渡します。 - -## 概要 - -メンバー | 説明 ---------------------------------|--------------------------------------------- -`define `[`MIDI_INPUT_QUEUE_LENGTH`](#group__midi__device_1ga4aaa419caebdca2bbdfc1331e79781a8) | -`enum `[`input_state_t`](#group__midi__device_1gac203e877d3df4275ceb8e7180a61f621) | -`public void `[`midi_device_input`](#group__midi__device_1gad8d3db8eb35d9cfa51ef036a0a9d70db)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t cnt,uint8_t * input)` | 入力バイトを処理します。この関数はバイトを解析し、指定されたデバイスに関連する適切なコールバックを呼びます。この関数は、カスタムデバイスを作成していて、MIDI 入力が必要な場合に使います。 -`public void `[`midi_device_set_send_func`](#group__midi__device_1ga59f5a46bdd4452f186cc73d9e96d4673)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t send_func)` | 出力データバイトの送信に使われるコールバック関数を設定します。これは、カスタムデバイスを作成している場合のみ使われます。ロックを気にすることなく様々な MIDI 送信関数を呼び出すことができるように、コールバック関数で割り込みを無効にすることができます。 -`public void `[`midi_device_set_pre_input_process_func`](#group__midi__device_1ga4de0841b87c04fc23cb56b6451f33b69)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_no_byte_func_t pre_process_func)` | midi_device_process 呼び出しの最初に呼ばれるコールバックを設定します。これは入力データをポーリングし、midi_device_input 関数を介してデータを送信できます。カスタムデバイスを作成している場合のみ、これを使う可能性があります。 -`struct `[`_midi_device`](docs/api_midi_device.md#struct__midi__device) | この構造体は、MIDI デバイスの入出力関数と処理データを表します。 - -## メンバー - -#### `define `[`MIDI_INPUT_QUEUE_LENGTH`](#group__midi__device_1ga4aaa419caebdca2bbdfc1331e79781a8) {#group__midi__device_1ga4aaa419caebdca2bbdfc1331e79781a8} - -#### `enum `[`input_state_t`](#group__midi__device_1gac203e877d3df4275ceb8e7180a61f621) {#group__midi__device_1gac203e877d3df4275ceb8e7180a61f621} - -値 | 説明 ---------------------------------|--------------------------------------------- -IDLE | -ONE_BYTE_MESSAGE | -TWO_BYTE_MESSAGE | -THREE_BYTE_MESSAGE | -SYSEX_MESSAGE | - -#### `public void `[`midi_device_input`](#group__midi__device_1gad8d3db8eb35d9cfa51ef036a0a9d70db)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t cnt,uint8_t * input)` {#group__midi__device_1gad8d3db8eb35d9cfa51ef036a0a9d70db} - -入力バイトを処理します。この関数はバイトを解析し、指定されたデバイスに関連する適切なコールバックを呼びます。この関数は、カスタムデバイスを作成していて、MIDI 入力が必要な場合に使います。 - -#### パラメータ -* `device` 入力を関連付ける MIDI デバイス - -* `cnt` 処理中のバイト数 - -* `input` 処理するバイトデータ - -#### `public void `[`midi_device_set_send_func`](#group__midi__device_1ga59f5a46bdd4452f186cc73d9e96d4673)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_var_byte_func_t send_func)` {#group__midi__device_1ga59f5a46bdd4452f186cc73d9e96d4673} - -出力データバイトの送信に使われるコールバック関数を設定します。これは、カスタムデバイスを作成している場合のみ使われます。ロックを気にすることなく様々な MIDI 送信関数を呼び出すことができるように、コールバック関数で割り込みを無効にすることができます。 - -#### パラメータ -* `device` このコールバックを関連付ける MIDI デバイス - -* `send_func` 送信を行うコールバック関数 - -#### `public void `[`midi_device_set_pre_input_process_func`](#group__midi__device_1ga4de0841b87c04fc23cb56b6451f33b69)`(`[`MidiDevice`](#struct__midi__device)` * device,midi_no_byte_func_t pre_process_func)` {#group__midi__device_1ga4de0841b87c04fc23cb56b6451f33b69} - -midi_device_process 呼び出しの最初に呼ばれるコールバックを設定します。これは入力データをポーリングし、midi_device_input 関数を介してデータを送信できます。カスタムデバイスを作成している場合のみ、これを使う可能性があります。 - -#### パラメータ -* `device` このコールバックを関連付ける MIDI デバイス - -* `midi_no_byte_func_t` 実際のコールバック関数 - -# `_midi_device` 構造体 {#struct__midi__device} - -この構造体は、MIDI デバイスの入出力関数と処理データを表します。 - -デバイスは、実際の物理デバイス [シリアルポート、USB ポート]、または仮想デバイスを表すことができます。この構造体を直接変更する必要はありません。 - -## 概要 - -| メンバー | 説明 ---------------------------------|--------------------------------------------- -`public midi_var_byte_func_t `[`send_func`](docs/api_midi_device.md#struct__midi__device_1a25d4c94b4bbccd5b98f1032b469f3ff9) | -`public midi_three_byte_func_t `[`input_cc_callback`](docs/api_midi_device.md#struct__midi__device_1a6da5236c1bc73877728df92d213a78d1) | -`public midi_three_byte_func_t `[`input_noteon_callback`](docs/api_midi_device.md#struct__midi__device_1aa10b15cf1a7fb825a5df0d2abbe34a1c) | -`public midi_three_byte_func_t `[`input_noteoff_callback`](docs/api_midi_device.md#struct__midi__device_1aaf290043078534d3a5a0ea4c840eba84) | -`public midi_three_byte_func_t `[`input_aftertouch_callback`](docs/api_midi_device.md#struct__midi__device_1acb0b4901c545cec4b28b126f2d8c315f) | -`public midi_three_byte_func_t `[`input_pitchbend_callback`](docs/api_midi_device.md#struct__midi__device_1a305fea672caeb996f2233bf8cd2bef18) | -`public midi_three_byte_func_t `[`input_songposition_callback`](docs/api_midi_device.md#struct__midi__device_1a5f3f13638b3fef3fc561ed1bf301d586) | -`public midi_two_byte_func_t `[`input_progchange_callback`](docs/api_midi_device.md#struct__midi__device_1adaf1da617c9a10a9dcad00ab1959d3da) | -`public midi_two_byte_func_t `[`input_chanpressure_callback`](docs/api_midi_device.md#struct__midi__device_1ab7ca2925c539915d43974eff604d85f7) | -`public midi_two_byte_func_t `[`input_songselect_callback`](docs/api_midi_device.md#struct__midi__device_1a89bed8a5a55376120cfc0a62b42f057f) | -`public midi_two_byte_func_t `[`input_tc_quarterframe_callback`](docs/api_midi_device.md#struct__midi__device_1ad9813e75d22e284f9f65a907d20600f0) | -`public midi_one_byte_func_t `[`input_realtime_callback`](docs/api_midi_device.md#struct__midi__device_1a9448eba4afb7e43650434748db3777be) | -`public midi_one_byte_func_t `[`input_tunerequest_callback`](docs/api_midi_device.md#struct__midi__device_1a0cb8fd53e00cf1d4202d4fa04d038e8d) | -`public midi_sysex_func_t `[`input_sysex_callback`](docs/api_midi_device.md#struct__midi__device_1afff9a0ce641762aaef24c1e6953ec9a2) | -`public midi_var_byte_func_t `[`input_fallthrough_callback`](docs/api_midi_device.md#struct__midi__device_1abb974ec6d734001b4a0e370f292be503) | -`public midi_var_byte_func_t `[`input_catchall_callback`](docs/api_midi_device.md#struct__midi__device_1aae0d535129d4fd650edc98eb3f7584f8) | -`public midi_no_byte_func_t `[`pre_input_process_callback`](docs/api_midi_device.md#struct__midi__device_1aeb0bb8923d66c23d874e177dc4265754) | -`public uint8_t `[`input_buffer`](docs/api_midi_device.md#struct__midi__device_1a7c5684857d6af4ebc4dc12da27bd6b2a) | -`public input_state_t `[`input_state`](docs/api_midi_device.md#struct__midi__device_1a69a687d2d1c449ec15a11c07a5722e39) | -`public uint16_t `[`input_count`](docs/api_midi_device.md#struct__midi__device_1a68dea8e7b6151e89c85c95caa612ee5d) | -`public uint8_t `[`input_queue_data`](docs/api_midi_device.md#struct__midi__device_1ada41de021135dc423abedcbb30f366ff) | -`public `[`byteQueue_t`](#structbyte_queue__t)` `[`input_queue`](#struct__midi__device_1a49c8538a8a02193c58e28a56eb695d8f) | - -## メンバー - -#### `public midi_var_byte_func_t `[`send_func`](docs/api_midi_device.md#struct__midi__device_1a25d4c94b4bbccd5b98f1032b469f3ff9) {#struct__midi__device_1a25d4c94b4bbccd5b98f1032b469f3ff9} - -#### `public midi_three_byte_func_t `[`input_cc_callback`](docs/api_midi_device.md#struct__midi__device_1a6da5236c1bc73877728df92d213a78d1) {#struct__midi__device_1a6da5236c1bc73877728df92d213a78d1} - -#### `public midi_three_byte_func_t `[`input_noteon_callback`](docs/api_midi_device.md#struct__midi__device_1aa10b15cf1a7fb825a5df0d2abbe34a1c) {#struct__midi__device_1aa10b15cf1a7fb825a5df0d2abbe34a1c} - -#### `public midi_three_byte_func_t `[`input_noteoff_callback`](docs/api_midi_device.md#struct__midi__device_1aaf290043078534d3a5a0ea4c840eba84) {#struct__midi__device_1aaf290043078534d3a5a0ea4c840eba84} - -#### `public midi_three_byte_func_t `[`input_aftertouch_callback`](docs/api_midi_device.md#struct__midi__device_1acb0b4901c545cec4b28b126f2d8c315f) {#struct__midi__device_1acb0b4901c545cec4b28b126f2d8c315f} - -#### `public midi_three_byte_func_t `[`input_pitchbend_callback`](docs/api_midi_device.md#struct__midi__device_1a305fea672caeb996f2233bf8cd2bef18) {#struct__midi__device_1a305fea672caeb996f2233bf8cd2bef18} - -#### `public midi_three_byte_func_t `[`input_songposition_callback`](docs/api_midi_device.md#struct__midi__device_1a5f3f13638b3fef3fc561ed1bf301d586) {#struct__midi__device_1a5f3f13638b3fef3fc561ed1bf301d586} - -#### `public midi_two_byte_func_t `[`input_progchange_callback`](docs/api_midi_device.md#struct__midi__device_1adaf1da617c9a10a9dcad00ab1959d3da) {#struct__midi__device_1adaf1da617c9a10a9dcad00ab1959d3da} - -#### `public midi_two_byte_func_t `[`input_chanpressure_callback`](docs/api_midi_device.md#struct__midi__device_1ab7ca2925c539915d43974eff604d85f7) {#struct__midi__device_1ab7ca2925c539915d43974eff604d85f7} - -#### `public midi_two_byte_func_t `[`input_songselect_callback`](docs/api_midi_device.md#struct__midi__device_1a89bed8a5a55376120cfc0a62b42f057f) {#struct__midi__device_1a89bed8a5a55376120cfc0a62b42f057f} - -#### `public midi_two_byte_func_t `[`input_tc_quarterframe_callback`](docs/api_midi_device.md#struct__midi__device_1ad9813e75d22e284f9f65a907d20600f0) {#struct__midi__device_1ad9813e75d22e284f9f65a907d20600f0} - -#### `public midi_one_byte_func_t `[`input_realtime_callback`](docs/api_midi_device.md#struct__midi__device_1a9448eba4afb7e43650434748db3777be) {#struct__midi__device_1a9448eba4afb7e43650434748db3777be} - -#### `public midi_one_byte_func_t `[`input_tunerequest_callback`](docs/api_midi_device.md#struct__midi__device_1a0cb8fd53e00cf1d4202d4fa04d038e8d) {#struct__midi__device_1a0cb8fd53e00cf1d4202d4fa04d038e8d} - -#### `public midi_sysex_func_t `[`input_sysex_callback`](docs/api_midi_device.md#struct__midi__device_1afff9a0ce641762aaef24c1e6953ec9a2) {#struct__midi__device_1afff9a0ce641762aaef24c1e6953ec9a2} - -#### `public midi_var_byte_func_t `[`input_fallthrough_callback`](docs/api_midi_device.md#struct__midi__device_1abb974ec6d734001b4a0e370f292be503) {#struct__midi__device_1abb974ec6d734001b4a0e370f292be503} - -#### `public midi_var_byte_func_t `[`input_catchall_callback`](docs/api_midi_device.md#struct__midi__device_1aae0d535129d4fd650edc98eb3f7584f8) {#struct__midi__device_1aae0d535129d4fd650edc98eb3f7584f8} - -#### `public midi_no_byte_func_t `[`pre_input_process_callback`](docs/api_midi_device.md#struct__midi__device_1aeb0bb8923d66c23d874e177dc4265754) {#struct__midi__device_1aeb0bb8923d66c23d874e177dc4265754} - -#### `public uint8_t `[`input_buffer`](docs/api_midi_device.md#struct__midi__device_1a7c5684857d6af4ebc4dc12da27bd6b2a) {#struct__midi__device_1a7c5684857d6af4ebc4dc12da27bd6b2a} - -#### `public input_state_t `[`input_state`](docs/api_midi_device.md#struct__midi__device_1a69a687d2d1c449ec15a11c07a5722e39) {#struct__midi__device_1a69a687d2d1c449ec15a11c07a5722e39} - -#### `public uint16_t `[`input_count`](docs/api_midi_device.md#struct__midi__device_1a68dea8e7b6151e89c85c95caa612ee5d) {#struct__midi__device_1a68dea8e7b6151e89c85c95caa612ee5d} - -#### `public uint8_t `[`input_queue_data`](docs/api_midi_device.md#struct__midi__device_1ada41de021135dc423abedcbb30f366ff) {#struct__midi__device_1ada41de021135dc423abedcbb30f366ff} - -#### `public `[`byteQueue_t`](#structbyte_queue__t)` `[`input_queue`](#struct__midi__device_1a49c8538a8a02193c58e28a56eb695d8f) {#struct__midi__device_1a49c8538a8a02193c58e28a56eb695d8f} - diff --git a/docs/ja/internals_midi_device_setup_process.md b/docs/ja/internals_midi_device_setup_process.md deleted file mode 100644 index 9806156452..0000000000 --- a/docs/ja/internals_midi_device_setup_process.md +++ /dev/null @@ -1,36 +0,0 @@ -# `midi_device_setup_process` グループ {#group__midi__device__setup__process} - -<!--- - original document: 0.10.9:docs/internals_midi_device_setup_process.md - git diff 0.10.9 HEAD -- docs/internals_midi_device_setup_process.md | cat ---> - -これらは、デバイスを初期化して実行するために使う必要があるメソッドです。 - -## 概要 - -メンバー | 説明 ---------------------------------|--------------------------------------------- -`public void `[`midi_device_init`](#group__midi__device__setup__process_1gaf29deddc94ea98a59daa0bde1aefd9d9)`(`[`MidiDevice`](#struct__midi__device)` * device)` | デバイスを初期化します。 -`public void `[`midi_device_process`](#group__midi__device__setup__process_1gaa3d5993d0e998a1b59bbf5ab9c7b492b)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 入力データを処理します。 - -## メンバー - -#### `public void `[`midi_device_init`](#group__midi__device__setup__process_1gaf29deddc94ea98a59daa0bde1aefd9d9)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__midi__device__setup__process_1gaf29deddc94ea98a59daa0bde1aefd9d9} - -デバイスを初期化します。 - -問題のデバイスを使う前にこれを呼び出す必要があります。 - -#### パラメータ -* `device` 初期化するデバイス - -#### `public void `[`midi_device_process`](#group__midi__device__setup__process_1gaa3d5993d0e998a1b59bbf5ab9c7b492b)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__midi__device__setup__process_1gaa3d5993d0e998a1b59bbf5ab9c7b492b} - -入力データを処理します。 - -このメソッドは入力処理を駆動します。入力コールバックが呼び出されることが予想される場合は、このメソッドを頻繁に呼び出す必要があります。 - -#### パラメータ -* `device` 処理するデバイス - diff --git a/docs/ja/internals_midi_util.md b/docs/ja/internals_midi_util.md deleted file mode 100644 index 5ff9870df9..0000000000 --- a/docs/ja/internals_midi_util.md +++ /dev/null @@ -1,59 +0,0 @@ -# `midi_util` グループ {#group__midi__util} - -<!--- - original document: 0.10.9:docs/internals_midi_util.md - git diff 0.10.9 HEAD -- docs/internals_midi_util.md | cat ---> - -## 概要 - -| メンバー | 説明 ---------------------------------|--------------------------------------------- -| `enum `[`midi_packet_length_t`](#group__midi__util_1gae29ff56aee2b430ffe53933b97e5e79e) | 可能なパケット長の値の列挙型。 -| `public bool `[`midi_is_statusbyte`](#group__midi__util_1ga12e3b42ff9cbb4b4f2bc455fc8743ee5)`(uint8_t theByte)` | 指定されたバイトがステータスバイトであるかどうかを検査します。 -| `public bool `[`midi_is_realtime`](#group__midi__util_1gad2f52c363e34a8000d80c983c324e2d7)`(uint8_t theByte)` | 指定されたバイトがリアルタイムメッセージであるかどうかを検査します。 -| `public `[`midi_packet_length_t`](#group__midi__util_1gae29ff56aee2b430ffe53933b97e5e79e)` `[`midi_packet_length`](#group__midi__util_1gaa168b43af6ae9de0debce1625e4b8175)`(uint8_t status)` | 指定されたステータスバイトに関連付けられたパケットの長さを調べます。 - -## メンバー - -#### `enum `[`midi_packet_length_t`](#group__midi__util_1gae29ff56aee2b430ffe53933b97e5e79e) {#group__midi__util_1gae29ff56aee2b430ffe53933b97e5e79e} - -| 値 | 説明 ---------------------------------|--------------------------------------------- -UNDEFINED | -ONE | -TWO | -THREE | - -可能なパケット長の値の列挙型。 - -#### `public bool `[`midi_is_statusbyte`](#group__midi__util_1ga12e3b42ff9cbb4b4f2bc455fc8743ee5)`(uint8_t theByte)` {#group__midi__util_1ga12e3b42ff9cbb4b4f2bc455fc8743ee5} - -指定されたバイトがステータスバイトであるかどうかを検査します。 - -#### パラメータ -* `theByte` 検査するバイト - -#### 返り値 -指定されたバイトが MIDI ステータスバイトの場合は true - -#### `public bool `[`midi_is_realtime`](#group__midi__util_1gad2f52c363e34a8000d80c983c324e2d7)`(uint8_t theByte)` {#group__midi__util_1gad2f52c363e34a8000d80c983c324e2d7} - -指定されたバイトがリアルタイムメッセージであるかどうかを検査します。 - -#### パラメータ -* `theByte` 検査するバイト - -#### 返り値 -リアルタイムメッセージの場合は true、それ以外の場合は false - -#### `public `[`midi_packet_length_t`](#group__midi__util_1gae29ff56aee2b430ffe53933b97e5e79e)` `[`midi_packet_length`](#group__midi__util_1gaa168b43af6ae9de0debce1625e4b8175)`(uint8_t status)` {#group__midi__util_1gaa168b43af6ae9de0debce1625e4b8175} - -指定されたステータスバイトに関連付けられたパケットの長さを調べます。 - -#### パラメータ -* `status` ステータスバイト - -#### 返り値 -パケットの長さ。バイトがステータスバイトではない場合、あるいは sysex ステータスバイトの場合は、UNDEFINED を返します。 - diff --git a/docs/ja/internals_send_functions.md b/docs/ja/internals_send_functions.md deleted file mode 100644 index 2747d3997f..0000000000 --- a/docs/ja/internals_send_functions.md +++ /dev/null @@ -1,246 +0,0 @@ -# `send_functions` グループ {#group__send__functions} - -<!--- - original document: 0.10.9:docs/internals_send_functions.md - git diff 0.10.9 HEAD -- docs/internals_send_functions.md | cat ---> - -これらは、デバイスを介して MIDI データを送信するために使う関数です。 - -## 概要 - -メンバー | 説明 ---------------------------------|--------------------------------------------- -`public void `[`midi_send_cc`](#group__send__functions_1gaaf884811c92df405ca8fe1a00082f960)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t val)` | 指定されたデバイスを介して、コントロールチェンジメッセージを送信します。 -`public void `[`midi_send_noteon`](#group__send__functions_1ga467bcf46dbf03ec269ce565b46bc2775)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t vel)` | 指定されたデバイスを介してノートオンメッセージを送信します。 -`public void `[`midi_send_noteoff`](#group__send__functions_1gaedb7d8805425eef5d47d57ddcb4c7a49)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t vel)` | 指定されたデバイスを介してノートオフメッセージを送信します。 -`public void `[`midi_send_aftertouch`](#group__send__functions_1ga0014847571317a0e34b2ef46a6bc584f)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t note_num,uint8_t amt)` | 指定されたデバイスを介してアフタータッチメッセージを送信します。 -`public void `[`midi_send_pitchbend`](#group__send__functions_1gae5a4a1e71611e7534be80af9ce3d3491)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,int16_t amt)` | 指定されたデバイスを介してピッチベンドメッセージを送信します。 -`public void `[`midi_send_programchange`](#group__send__functions_1ga7b15588ef25e5e1ff09c2afc3151ce86)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num)` | 指定されたデバイスを介してプログラムチェンジメッセージを送信します。 -`public void `[`midi_send_channelpressure`](#group__send__functions_1gaf23e69fdf812e89c0036f51f88ab2e1b)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t amt)` | 指定されたデバイスを介してチャンネルプレッシャーメッセージを送信します。 -`public void `[`midi_send_clock`](#group__send__functions_1ga4e1b11a7cdb0875f6e03ce7c79c581aa)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してクロックメッセージを送信します。 -`public void `[`midi_send_tick`](#group__send__functions_1ga2b43c7d433d940c5b907595aac947972)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してティックメッセージを送信します。 -`public void `[`midi_send_start`](#group__send__functions_1ga1569749a8d58ccc56789289d7c7245cc)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してスタートメッセージを送信します。 -`public void `[`midi_send_continue`](#group__send__functions_1gaed5dc29d754a27372e89ab8bc20ee120)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してコンティニューメッセージを送信します。 -`public void `[`midi_send_stop`](#group__send__functions_1ga026e1a620276cb653ac501aa0d12a988)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してストップメッセージを送信します。 -`public void `[`midi_send_activesense`](#group__send__functions_1ga9b6e4c6ce4719d2604187b325620db37)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してアクティブセンスメッセージを送信します。 -`public void `[`midi_send_reset`](#group__send__functions_1ga3671e39a6d93ca9568fc493001af1b1b)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してリセットメッセージを送信します。 -`public void `[`midi_send_tcquarterframe`](#group__send__functions_1ga5b85639910eec280bb744c934d0fd45a)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t time)` | 指定されたデバイスを介してタイムコードクォータフレームメッセージを送信します。 -`public void `[`midi_send_songposition`](#group__send__functions_1gab1c9eeef3b57a8cd2e6128d18e85eb7f)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t pos)` | 指定されたデバイスを介してソングポジションメッセージを送信します。 -`public void `[`midi_send_songselect`](#group__send__functions_1ga42de7838ba70d949af9a50f9facc3c50)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t song)` | 指定されたデバイスを介してソングセレクトメッセージを送信します。 -`public void `[`midi_send_tunerequest`](#group__send__functions_1ga8db6c7e04d48e4d2266dd59118ca0656)`(`[`MidiDevice`](#struct__midi__device)` * device)` | 指定されたデバイスを介してチューンリクエストメッセージを送信します。 -`public void `[`midi_send_byte`](#group__send__functions_1ga857e85eb90b288385642d4d991e09881)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t b)` | 指定されたデバイスを介してバイトを送信します。 -`public void `[`midi_send_data`](#group__send__functions_1ga36e2f2e45369d911b76969361679054b)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t count,uint8_t byte0,uint8_t byte1,uint8_t byte2)` | 最大3バイトのデータを送信します。 -`public void `[`midi_send_array`](#group__send__functions_1ga245243cb1da18d2cea18d4b18d846ead)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t count,uint8_t * array)` | フォーマットされた MIDI データの配列を送信します。 - -## メンバー - -#### `public void `[`midi_send_cc`](#group__send__functions_1gaaf884811c92df405ca8fe1a00082f960)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t val)` {#group__send__functions_1gaaf884811c92df405ca8fe1a00082f960} - -指定されたデバイスを介して、コントロールチェンジメッセージ(cc)を送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `num` コントロールチェンジナンバー - -* `val` コントロールチェンジナンバーの値 - -#### `public void `[`midi_send_noteon`](#group__send__functions_1ga467bcf46dbf03ec269ce565b46bc2775)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t vel)` {#group__send__functions_1ga467bcf46dbf03ec269ce565b46bc2775} - -指定されたデバイスを介してノートオンメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `num` ノート番号 - -* `vel` ノートベロシティ - -#### `public void `[`midi_send_noteoff`](#group__send__functions_1gaedb7d8805425eef5d47d57ddcb4c7a49)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num,uint8_t vel)` {#group__send__functions_1gaedb7d8805425eef5d47d57ddcb4c7a49} - -指定されたデバイスを介してノートオフメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `num` ノート番号 - -* `vel` ノートベロシティ - -#### `public void `[`midi_send_aftertouch`](#group__send__functions_1ga0014847571317a0e34b2ef46a6bc584f)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t note_num,uint8_t amt)` {#group__send__functions_1ga0014847571317a0e34b2ef46a6bc584f} - -指定されたデバイスを介してアフタータッチメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `note_num` ノート番号 - -* `amt` アフタータッチ量 - -#### `public void `[`midi_send_pitchbend`](#group__send__functions_1gae5a4a1e71611e7534be80af9ce3d3491)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,int16_t amt)` {#group__send__functions_1gae5a4a1e71611e7534be80af9ce3d3491} - -指定されたデバイスを介してピッチベンドメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `amt` ベンド量の範囲: -8192..8191、0 はベンドしないことを意味します - -#### `public void `[`midi_send_programchange`](#group__send__functions_1ga7b15588ef25e5e1ff09c2afc3151ce86)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t num)` {#group__send__functions_1ga7b15588ef25e5e1ff09c2afc3151ce86} - -指定されたデバイスを介してプログラムチェンジメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `num` 変更先のプログラム - -#### `public void `[`midi_send_channelpressure`](#group__send__functions_1gaf23e69fdf812e89c0036f51f88ab2e1b)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t chan,uint8_t amt)` {#group__send__functions_1gaf23e69fdf812e89c0036f51f88ab2e1b} - -指定されたデバイスを介してチャンネルプレッシャーメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `chan` 送信するチャンネル、0-15 - -* `amt` チャンネルプレッシャーの量 - -#### `public void `[`midi_send_clock`](#group__send__functions_1ga4e1b11a7cdb0875f6e03ce7c79c581aa)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga4e1b11a7cdb0875f6e03ce7c79c581aa} - -指定されたデバイスを介してクロックメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_tick`](#group__send__functions_1ga2b43c7d433d940c5b907595aac947972)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga2b43c7d433d940c5b907595aac947972} - -指定されたデバイスを介してティックメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_start`](#group__send__functions_1ga1569749a8d58ccc56789289d7c7245cc)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga1569749a8d58ccc56789289d7c7245cc} - -指定されたデバイスを介してスタートメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_continue`](#group__send__functions_1gaed5dc29d754a27372e89ab8bc20ee120)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1gaed5dc29d754a27372e89ab8bc20ee120} - -指定されたデバイスを介してコンティニューメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_stop`](#group__send__functions_1ga026e1a620276cb653ac501aa0d12a988)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga026e1a620276cb653ac501aa0d12a988} - -指定されたデバイスを介してストップメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_activesense`](#group__send__functions_1ga9b6e4c6ce4719d2604187b325620db37)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga9b6e4c6ce4719d2604187b325620db37} - -指定されたデバイスを介してアクティブセンスメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_reset`](#group__send__functions_1ga3671e39a6d93ca9568fc493001af1b1b)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga3671e39a6d93ca9568fc493001af1b1b} - -指定されたデバイスを介してリセットメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_tcquarterframe`](#group__send__functions_1ga5b85639910eec280bb744c934d0fd45a)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t time)` {#group__send__functions_1ga5b85639910eec280bb744c934d0fd45a} - -指定されたデバイスを介してタイムコードクォータフレームメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `time` このクォータフレームの時間。範囲は、0..16383 - -#### `public void `[`midi_send_songposition`](#group__send__functions_1gab1c9eeef3b57a8cd2e6128d18e85eb7f)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t pos)` {#group__send__functions_1gab1c9eeef3b57a8cd2e6128d18e85eb7f} - -指定されたデバイスを介してソングポジションメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `pos` ソングポジション - -#### `public void `[`midi_send_songselect`](#group__send__functions_1ga42de7838ba70d949af9a50f9facc3c50)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t song)` {#group__send__functions_1ga42de7838ba70d949af9a50f9facc3c50} - -指定されたデバイスを介してソングセレクトメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `song` 選択するソング - -#### `public void `[`midi_send_tunerequest`](#group__send__functions_1ga8db6c7e04d48e4d2266dd59118ca0656)`(`[`MidiDevice`](#struct__midi__device)` * device)` {#group__send__functions_1ga8db6c7e04d48e4d2266dd59118ca0656} - -指定されたデバイスを介してチューンリクエストメッセージを送信します。 - -#### パラメータ -* `device` 送信に使うデバイス - -#### `public void `[`midi_send_byte`](#group__send__functions_1ga857e85eb90b288385642d4d991e09881)`(`[`MidiDevice`](#struct__midi__device)` * device,uint8_t b)` {#group__send__functions_1ga857e85eb90b288385642d4d991e09881} - -指定されたデバイスを介してバイトを送信します。 - -これは、指定された MIDI デバイスを介してデータを送信する一般的なメソッドです。これは、この API に実装されていない sysex データまたはメッセージがある場合、それらを送信するのに役立ちます。そのようなものを見つけた場合は、私たちがそれらを追加できるように、作者に連絡してください。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `b` 送信するバイト - -#### `public void `[`midi_send_data`](#group__send__functions_1ga36e2f2e45369d911b76969361679054b)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t count,uint8_t byte0,uint8_t byte1,uint8_t byte2)` {#group__send__functions_1ga36e2f2e45369d911b76969361679054b} - -最大3バイトのデータを送信します。 - -これを使って sysex を通過できるように count に4の剰余が適用されます。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `count` 送信するバイト数、4の剰余が適用されます - -* `byte0` 最初のバイト - -* `byte1` 2番目のバイト。cnt % 4 != 2 の場合は無視されます - -* `byte2` 3番目のバイト。cnt % 4 != 3 の場合は無視されます - -#### `public void `[`midi_send_array`](#group__send__functions_1ga245243cb1da18d2cea18d4b18d846ead)`(`[`MidiDevice`](#struct__midi__device)` * device,uint16_t count,uint8_t * array)` {#group__send__functions_1ga245243cb1da18d2cea18d4b18d846ead} - -フォーマットされた MIDI データの配列を送信します。 - -sysex に使うことができます。 - -#### パラメータ -* `device` 送信に使うデバイス - -* `count` 送信するバイト数 - -* `array` バイトの配列 - diff --git a/docs/ja/internals_sysex_tools.md b/docs/ja/internals_sysex_tools.md deleted file mode 100644 index 629b4f2445..0000000000 --- a/docs/ja/internals_sysex_tools.md +++ /dev/null @@ -1,66 +0,0 @@ -# `sysex_tools` グループ {#group__sysex__tools} - -<!--- - original document: 0.10.9:docs/internals_sysex_tools.md - git diff 0.10.9 HEAD -- docs/internals_sysex_tools.md | cat ---> - -## 概要 - -| メンバー | 説明 ---------------------------------|--------------------------------------------- -| `public uint16_t `[`sysex_encoded_length`](#group__sysex__tools_1ga061e5607030412d6e62e2390d8013f0a)`(uint16_t decoded_length)` | エンコード後のメッセージの長さを計算します。 -| `public uint16_t `[`sysex_decoded_length`](#group__sysex__tools_1ga121fc227d3acc1c0ea08c9a5c26fa3b0)`(uint16_t encoded_length)` | デコード後のメッセージの長さを計算します。 -| `public uint16_t `[`sysex_encode`](#group__sysex__tools_1ga54d77f8d32f92a6f329daefa2b314742)`(uint8_t * encoded,const uint8_t * source,uint16_t length)` | sysex メッセージで安全に送信できるようにデータをエンコードします。 -| `public uint16_t `[`sysex_decode`](#group__sysex__tools_1gaaad1d9ba2d5eca709a0ab4ba40662229)`(uint8_t * decoded,const uint8_t * source,uint16_t length)` | エンコードされたデータをデコードします。 - -## メンバー - -#### `public uint16_t `[`sysex_encoded_length`](#group__sysex__tools_1ga061e5607030412d6e62e2390d8013f0a)`(uint16_t decoded_length)` {#group__sysex__tools_1ga061e5607030412d6e62e2390d8013f0a} - -エンコード後のメッセージの長さを計算します。 - -#### パラメータ -* `decoded_length` エンコードするメッセージの長さのバイト数。 - -#### 返り値 -エンコード後のメッセージの長さのバイト数。 - -#### `public uint16_t `[`sysex_decoded_length`](#group__sysex__tools_1ga121fc227d3acc1c0ea08c9a5c26fa3b0)`(uint16_t encoded_length)` {#group__sysex__tools_1ga121fc227d3acc1c0ea08c9a5c26fa3b0} - -デコード後のメッセージの長さを計算します。 - -#### パラメータ -* `encoded_length` エンコードされたメッセージの長さのバイト数。 - -#### 返り値 -デコードされた後のメッセージの長さのバイト数。 - -#### `public uint16_t `[`sysex_encode`](#group__sysex__tools_1ga54d77f8d32f92a6f329daefa2b314742)`(uint8_t * encoded,const uint8_t * source,uint16_t length)` {#group__sysex__tools_1ga54d77f8d32f92a6f329daefa2b314742} - -sysex メッセージで安全に送信できるようにデータをエンコードします。 - -#### パラメータ -* `encoded` 出力データバッファは、少なくとも sysex_encoded_length(length) バイトの長さが必要です。 - -* `source` エンコードされるデータの入力バッファ。 - -* `length` 入力バッファからエンコードするバイト数。 - -#### 返り値 -エンコードされたバイト数。 - -#### `public uint16_t `[`sysex_decode`](#group__sysex__tools_1gaaad1d9ba2d5eca709a0ab4ba40662229)`(uint8_t * decoded,const uint8_t * source,uint16_t length)` {#group__sysex__tools_1gaaad1d9ba2d5eca709a0ab4ba40662229} - -エンコードされたデータをデコードします。 - -#### パラメータ -* `decoded` 出力データバッファは、少なくとも sysex_decoded_length(length) バイトの長さが必要です。 - -* `source` デコードされるデータの入力バッファ。 - -* `length` 入力バッファからデコードするバイト数。 - -#### 返り値 -デコードされたバイト数。 - diff --git a/docs/ja/proton_c_conversion.md b/docs/ja/proton_c_conversion.md index 983aed4ee5..8f0c857cba 100644 --- a/docs/ja/proton_c_conversion.md +++ b/docs/ja/proton_c_conversion.md @@ -27,7 +27,7 @@ QMK で現在サポートされているキーボードが Pro Micro(または #endif ``` -`PORTB/DDRB` などが定義されていないというエラーが発生した場合は、ARM と AVR の両方で機能する [GPIO 制御](ja/internals_gpio_control.md) を使用するようにキーボードのコードを変換する必要があります。これは AVR ビルドにまったく影響を与えません。 +`PORTB/DDRB` などが定義されていないというエラーが発生した場合は、ARM と AVR の両方で機能する [GPIO 制御](ja/gpio_control.md) を使用するようにキーボードのコードを変換する必要があります。これは AVR ビルドにまったく影響を与えません。 Proton C には1つのオンボード LED(C13)しかなく、デフォルトでは TXLED(D5) がそれにマップされています。代わりに RXLED(B0) をそれにマッピングしたい場合は、`config.h` に次のように追加してください。 diff --git a/docs/keycodes.md b/docs/keycodes.md index 58ce43d309..942e0a6616 100644 --- a/docs/keycodes.md +++ b/docs/keycodes.md @@ -219,11 +219,12 @@ See also: [Basic Keycodes](keycodes_basic.md) See also: [Quantum Keycodes](quantum_keycodes.md#qmk-keycodes) -|Key |Aliases |Description | -|-----------------|---------|-------------------------------------------------------| -|`QK_BOOTLOADER` |`QK_BOOT`|Put the keyboard into bootloader mode for flashing | -|`QK_DEBUG_TOGGLE`|`DB_TOGG`|Toggle debug mode | -|`QK_CLEAR_EEPROM`|`EE_CLR` |Reinitializes the keyboard's EEPROM (persistent memory)| +|Key |Aliases |Description | +|-----------------|---------|---------------------------------------------------------------------------------| +|`QK_BOOTLOADER` |`QK_BOOT`|Put the keyboard into bootloader mode for flashing | +|`QK_DEBUG_TOGGLE`|`DB_TOGG`|Toggle debug mode | +|`QK_CLEAR_EEPROM`|`EE_CLR` |Reinitializes the keyboard's EEPROM (persistent memory) | +|`QK_MAKE` | |Sends `qmk compile -kb (keyboard) -km (keymap)`, or `qmk flash` if shift is held | ## Audio Keys :id=audio-keys diff --git a/docs/proton_c_conversion.md b/docs/proton_c_conversion.md index 47511e1b1e..1e1b1e806d 100644 --- a/docs/proton_c_conversion.md +++ b/docs/proton_c_conversion.md @@ -20,7 +20,7 @@ This exposes the `CONVERT_TO_PROTON_C` flag that you can use in your code with ` #endif ``` -If you get errors about `PORTB/DDRB`, etc not being defined, so you'll need to convert the keyboard's code to use the [GPIO Controls](internals_gpio_control.md) that will work for both ARM and AVR. This shouldn't affect the AVR builds at all. +If you get errors about `PORTB/DDRB`, etc not being defined, so you'll need to convert the keyboard's code to use the [GPIO Controls](gpio_control.md) that will work for both ARM and AVR. This shouldn't affect the AVR builds at all. The Proton C only has one on-board LED (C13), and by default, the TXLED (D5) is mapped to it. If you want the RXLED (B0) mapped to it instead, add this like to your `config.h`: diff --git a/docs/quantum_keycodes.md b/docs/quantum_keycodes.md index 8e29e05886..46a8b7de19 100644 --- a/docs/quantum_keycodes.md +++ b/docs/quantum_keycodes.md @@ -8,8 +8,9 @@ On this page we have documented keycodes between `0x00FF` and `0xFFFF` which are ## QMK Keycodes :id=qmk-keycodes -|Key |Aliases |Description | -|-----------------|---------|-------------------------------------------------------| -|`QK_BOOTLOADER` |`QK_BOOT`|Put the keyboard into bootloader mode for flashing | -|`QK_DEBUG_TOGGLE`|`DB_TOGG`|Toggle debug mode | -|`QK_CLEAR_EEPROM`|`EE_CLR` |Reinitializes the keyboard's EEPROM (persistent memory)| +|Key |Aliases |Description | +|-----------------|---------|---------------------------------------------------------------------------------| +|`QK_BOOTLOADER` |`QK_BOOT`|Put the keyboard into bootloader mode for flashing | +|`QK_DEBUG_TOGGLE`|`DB_TOGG`|Toggle debug mode | +|`QK_CLEAR_EEPROM`|`EE_CLR` |Reinitializes the keyboard's EEPROM (persistent memory) | +|`QK_MAKE` | |Sends `qmk compile -kb (keyboard) -km (keymap)`, or `qmk flash` if shift is held | diff --git a/docs/zh-cn/_summary.md b/docs/zh-cn/_summary.md index 8a710a9ec1..dbad1021fa 100644 --- a/docs/zh-cn/_summary.md +++ b/docs/zh-cn/_summary.md @@ -146,7 +146,7 @@ * [EEPROM驱动](zh-cn/eeprom_driver.md) * [串口驱动](zh-cn/serial_driver.md) * [UART驱动](zh-cn/uart_driver.md) - * [操控GPIO](zh-cn/internals_gpio_control.md) + * [操控GPIO](zh-cn/gpio_control.md) * [键盘开发指引](zh-cn/hardware_keyboard_guidelines.md) * Python开发 @@ -182,12 +182,12 @@ * [了解QMK](zh-cn/understanding_qmk.md) * QMK内部细节 (编辑中) - * [定义](zh-cn/internals_defines.md) - * [输入回调的注册](zh-cn/internals_input_callback_reg.md) - * [Midi设备](zh-cn/internals_midi_device.md) - * [Midi设备驱动流程](zh-cn/internals_midi_device_setup_process.md) - * [Midi辅助功能](zh-cn/internals_midi_util.md) - * [发送函数](zh-cn/internals_send_functions.md) - * [Sysex工具](zh-cn/internals_sysex_tools.md) + * [定义](zh-cn/internals/defines.md) + * [输入回调的注册](zh-cn/internals/input_callback_reg.md) + * [Midi设备](zh-cn/internals/midi_device.md) + * [Midi设备驱动流程](zh-cn/internals/midi_device_setup_process.md) + * [Midi辅助功能](zh-cn/internals/midi_util.md) + * [发送函数](zh-cn/internals/send_functions.md) + * [Sysex工具](zh-cn/internals/sysex_tools.md) <!--fromen:20211014-12:00(GMT+8) commit 04cf161aa01fd433b5dae69d9fd31569ed5dca59--> diff --git a/drivers/gpio/sn74x154.c b/drivers/gpio/sn74x154.c new file mode 100644 index 0000000000..5f21f12b55 --- /dev/null +++ b/drivers/gpio/sn74x154.c @@ -0,0 +1,58 @@ +/* Copyright 2022 + * + * 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/>. + */ + +#include "sn74x154.h" +#include "gpio.h" + +#define ADDRESS_PIN_COUNT 4 + +#ifndef SN74X154_ADDRESS_PINS +# error sn74x154: no address pins defined! +#endif + +static const pin_t address_pins[ADDRESS_PIN_COUNT] = SN74X154_ADDRESS_PINS; + +void sn74x154_init(void) { + for (int i = 0; i < ADDRESS_PIN_COUNT; i++) { + setPinOutput(address_pins[i]); + writePinLow(address_pins[i]); + } + +#if defined(SN74X154_E0_PIN) + setPinOutput(SN74X154_E0_PIN); + writePinHigh(SN74X154_E0_PIN); +#endif + +#if defined(SN74X154_E1_PIN) + setPinOutput(SN74X154_E1_PIN); + writePinHigh(SN74X154_E1_PIN); +#endif +} + +void sn74x154_set_enabled(bool enabled) { +#if defined(SN74X154_E0_PIN) + writePin(SN74X154_E0_PIN, !enabled); +#endif +#if defined(SN74X154_E1_PIN) + writePin(SN74X154_E1_PIN, !enabled); +#endif +} + +void sn74x154_set_addr(uint8_t address) { + for (int i = 0; i < ADDRESS_PIN_COUNT; i++) { + writePin(address_pins[i], address & (1 << i)); + } +} diff --git a/drivers/gpio/sn74x154.h b/drivers/gpio/sn74x154.h new file mode 100644 index 0000000000..ce6a9ddb0e --- /dev/null +++ b/drivers/gpio/sn74x154.h @@ -0,0 +1,48 @@ +/* Copyright 2022 + * + * 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/>. + */ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +/** + * Driver for 74x154 4-to-16 decoder/demultiplexer with inverting outputs + * https://assets.nexperia.com/documents/data-sheet/74HC_HCT154.pdf + */ + +/** + * Initialize the address and output enable pins. + */ +void sn74x154_init(void); + +/** + * Set the enabled state. + * + * When enabled is true, pulls the E0 and E1 pins low. + * + * \param enabled The enable state to set. + */ +void sn74x154_set_enabled(bool enabled); + +/** + * Set the output pin address. + * + * The selected output pin will be pulled low, while the remaining output pins will be high. + * + * \param address The address to set, from 0 to 15. + */ +void sn74x154_set_addr(uint8_t address); diff --git a/drivers/lcd/hd44780.c b/drivers/lcd/hd44780.c new file mode 100644 index 0000000000..c988ebe56c --- /dev/null +++ b/drivers/lcd/hd44780.c @@ -0,0 +1,284 @@ +/* +Copyright 2022 + +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/>. +*/ + +#include "hd44780.h" +#include "gpio.h" +#include "progmem.h" +#include "wait.h" + +#ifndef HD44780_DATA_PINS +# error hd44780: no data pins defined! +#endif + +#ifndef HD44780_RS_PIN +# error hd44780: no RS pin defined! +#endif + +#ifndef HD44780_RW_PIN +# error hd44780: no R/W pin defined! +#endif + +#ifndef HD44780_E_PIN +# error hd44780: no E pin defined! +#endif + +static const pin_t data_pins[4] = HD44780_DATA_PINS; + +#ifndef HD44780_DISPLAY_COLS +# define HD44780_DISPLAY_COLS 16 +#endif + +#ifndef HD44780_DISPLAY_LINES +# define HD44780_DISPLAY_LINES 2 +#endif + +#ifndef HD44780_DDRAM_LINE0_ADDR +# define HD44780_DDRAM_LINE0_ADDR 0x00 +#endif +#ifndef HD44780_DDRAM_LINE1_ADDR +# define HD44780_DDRAM_LINE1_ADDR 0x40 +#endif + +#define HD44780_INIT_DELAY_MS 16 +#define HD44780_ENABLE_DELAY_US 1 + +static void hd44780_latch(void) { + writePinHigh(HD44780_E_PIN); + wait_us(HD44780_ENABLE_DELAY_US); + writePinLow(HD44780_E_PIN); +} + +void hd44780_write(uint8_t data, bool isData) { + writePin(HD44780_RS_PIN, isData); + writePinLow(HD44780_RW_PIN); + + for (int i = 0; i < 4; i++) { + setPinOutput(data_pins[i]); + } + + // Write high nibble + for (int i = 0; i < 4; i++) { + writePin(data_pins[i], (data >> 4) & (1 << i)); + } + hd44780_latch(); + + // Write low nibble + for (int i = 0; i < 4; i++) { + writePin(data_pins[i], data & (1 << i)); + } + hd44780_latch(); + + for (int i = 0; i < 4; i++) { + writePinHigh(data_pins[i]); + } +} + +uint8_t hd44780_read(bool isData) { + uint8_t data = 0; + + writePin(HD44780_RS_PIN, isData); + writePinHigh(HD44780_RW_PIN); + + for (int i = 0; i < 4; i++) { + setPinInput(data_pins[i]); + } + + writePinHigh(HD44780_E_PIN); + wait_us(HD44780_ENABLE_DELAY_US); + + // Read high nibble + for (int i = 0; i < 4; i++) { + data |= (readPin(data_pins[i]) << i); + } + + data <<= 4; + + writePinLow(HD44780_E_PIN); + wait_us(HD44780_ENABLE_DELAY_US); + writePinHigh(HD44780_E_PIN); + wait_us(HD44780_ENABLE_DELAY_US); + + // Read low nibble + for (int i = 0; i < 4; i++) { + data |= (readPin(data_pins[i]) << i); + } + + writePinLow(HD44780_E_PIN); + + return data; +} + +bool hd44780_busy(void) { + return hd44780_read(false) & HD44780_BUSY_FLAG; +} + +void hd44780_command(uint8_t command) { + while (hd44780_busy()) + ; + hd44780_write(command, false); +} + +void hd44780_data(uint8_t data) { + while (hd44780_busy()) + ; + hd44780_write(data, true); +} + +void hd44780_clear(void) { + hd44780_command(HD44780_CMD_CLEAR_DISPLAY); +} + +void hd44780_home(void) { + hd44780_command(HD44780_CMD_RETURN_HOME); +} + +void hd44780_on(bool cursor, bool blink) { + if (cursor) { + if (blink) { + hd44780_command(HD44780_CMD_DISPLAY | HD44780_DISPLAY_ON | HD44780_DISPLAY_CURSOR | HD44780_DISPLAY_BLINK); + } else { + hd44780_command(HD44780_CMD_DISPLAY | HD44780_DISPLAY_ON | HD44780_DISPLAY_CURSOR); + } + } else { + hd44780_command(HD44780_CMD_DISPLAY | HD44780_DISPLAY_ON); + } +} + +void hd44780_off() { + hd44780_command(HD44780_CMD_DISPLAY); +} + +void hd44780_set_cgram_address(uint8_t address) { + hd44780_command(HD44780_CMD_SET_CGRAM_ADDRESS + (address & 0x3F)); +} + +void hd44780_set_ddram_address(uint8_t address) { + hd44780_command(HD44780_CMD_SET_DDRAM_ADDRESS + (address & 0x7F)); +} + +void hd44780_init(bool cursor, bool blink) { + setPinOutput(HD44780_RS_PIN); + setPinOutput(HD44780_RW_PIN); + setPinOutput(HD44780_E_PIN); + + for (int i = 0; i < 4; i++) { + setPinOutput(data_pins[i]); + } + + wait_ms(HD44780_INIT_DELAY_MS); + + // Manually configure for 4-bit mode - can't use hd44780_command() yet + // HD44780U datasheet, Fig. 24 (p46) + writePinHigh(data_pins[0]); // Function set + writePinHigh(data_pins[1]); // DL = 1 + hd44780_latch(); + wait_ms(5); + // Send again + hd44780_latch(); + wait_us(64); + // And again (?) + hd44780_latch(); + wait_us(64); + + writePinLow(data_pins[0]); // DL = 0 + hd44780_latch(); + wait_us(64); + +#if HD44780_DISPLAY_LINES == 1 + hd44780_command(HD44780_CMD_FUNCTION); // 4 bit, 1 line, 5x8 dots +#else + hd44780_command(HD44780_CMD_FUNCTION | HD44780_FUNCTION_2_LINES); // 4 bit, 2 lines, 5x8 dots +#endif + hd44780_on(cursor, blink); + hd44780_clear(); + hd44780_home(); + hd44780_command(HD44780_CMD_ENTRY_MODE | HD44780_ENTRY_MODE_INC); +} + +void hd44780_set_cursor(uint8_t col, uint8_t line) { + register uint8_t address = col; + +#if HD44780_DISPLAY_LINES == 1 + address += HD44780_DDRAM_LINE0_ADDR; +#elif HD44780_DISPLAY_LINES == 2 + if (line == 0) { + address += HD44780_DDRAM_LINE0_ADDR; + } else { + address += HD44780_DDRAM_LINE1_ADDR; + } +#endif + + hd44780_set_ddram_address(address); +} + +void hd44780_define_char(uint8_t index, uint8_t *data) { + hd44780_set_cgram_address((index & 0x7) << 3); + for (uint8_t i = 0; i < 8; i++) { + hd44780_data(data[i]); + } +} + +void hd44780_putc(char c) { + while (hd44780_busy()) + ; + uint8_t current_position = hd44780_read(false); + + if (c == '\n') { + hd44780_set_cursor(0, current_position < HD44780_DDRAM_LINE1_ADDR ? 1 : 0); + } else { +#if defined(HD44780_WRAP_LINES) +# if HD44780_DISPLAY_LINES == 1 + if (current_position == HD44780_DDRAM_LINE0_ADDR + HD44780_DISPLAY_COLS) { + // Go to start of line + hd44780_set_cursor(0, 0); + } +# elif HD44780_DISPLAY_LINES == 2 + if (current_position == HD44780_DDRAM_LINE0_ADDR + HD44780_DISPLAY_COLS) { + // Go to start of second line + hd44780_set_cursor(0, 1); + } else if (current_position == HD44780_DDRAM_LINE1_ADDR + HD44780_DISPLAY_COLS) { + // Go to start of first line + hd44780_set_cursor(0, 0); + } +# endif +#endif + hd44780_data(c); + } +} + +void hd44780_puts(const char *s) { + register char c; + while ((c = *s++)) { + hd44780_putc(c); + } +} + +#if defined(__AVR__) +void hd44780_define_char_P(uint8_t index, const uint8_t *data) { + hd44780_set_cgram_address(index << 3); + for (uint8_t i = 0; i < 8; i++) { + hd44780_data(pgm_read_byte(data++)); + } +} + +void hd44780_puts_P(const char *s) { + register char c; + while ((c = pgm_read_byte(s++))) { + hd44780_putc(c); + } +} +#endif diff --git a/drivers/lcd/hd44780.h b/drivers/lcd/hd44780.h new file mode 100644 index 0000000000..9e43339344 --- /dev/null +++ b/drivers/lcd/hd44780.h @@ -0,0 +1,220 @@ +/* +Copyright 2022 + +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/>. +*/ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +/** + * \defgroup hd44780 + * + * HD44780 Character LCD Driver + * \{ + */ + +/* + * HD44780 instructions + * https://www.sparkfun.com/datasheets/LCD/HD44780.pdf + * Table 6 (p24) + */ +// Clear display +#define HD44780_CMD_CLEAR_DISPLAY 0x01 +// Return home +#define HD44780_CMD_RETURN_HOME 0x02 +// Entry mode set +#define HD44780_CMD_ENTRY_MODE 0x04 +#define HD44780_ENTRY_MODE_INC 0x02 // I/D +#define HD44780_ENTRY_MODE_SHIFT 0x01 // S +// Display on/off control +#define HD44780_CMD_DISPLAY 0x08 +#define HD44780_DISPLAY_ON 0x04 // D +#define HD44780_DISPLAY_CURSOR 0x02 // C +#define HD44780_DISPLAY_BLINK 0x01 // B +// Cursor or display shift +#define HD44780_CMD_MOVE 0x10 +#define HD44780_MOVE_DISPLAY 0x08 // S/C +#define HD44780_MOVE_RIGHT 0x04 // R/L +// Function set +#define HD44780_CMD_FUNCTION 0x20 +#define HD44780_FUNCTION_8_BIT 0x10 // DL +#define HD44780_FUNCTION_2_LINES 0x08 // N +#define HD44780_FUNCTION_5X10_DOTS 0x04 // F +// Set CGRAM address +#define HD44780_CMD_SET_CGRAM_ADDRESS 0x40 +// Set DDRAM address +#define HD44780_CMD_SET_DDRAM_ADDRESS 0x80 + +// Bitmask for busy flag when reading +#define HD44780_BUSY_FLAG 0x80 + +/** + * \brief Write a byte to the display. + * + * \param data The byte to send to the display. + * \param isData Whether the byte is an instruction or character data. + */ +void hd44780_write(uint8_t data, bool isData); + +/** + * \brief Read a byte from the display. + * + * \param isData Whether to read the current cursor position, or the character at the cursor. + * + * \return If `isData` is `true`, the returned byte will be the character at the current DDRAM address. Otherwise, it will be the current DDRAM address and the busy flag. + */ +uint8_t hd44780_read(bool isData); + +/** + * \brief Indicates whether the display is currently processing, and cannot accept instructions. + * + * \return `true` if the display is busy. + */ +bool hd44780_busy(void); + +/** + * \brief Send a command to the display. Refer to the datasheet for the valid commands. + * + * This function waits for the display to clear the busy flag before sending the command. + * + * \param command The command to send. + */ +void hd44780_command(uint8_t command); + +/** + * \brief Send a byte of data to the display. + * + * This function waits for the display to clear the busy flag before sending the data. + * + * \param data The byte of data to send. + */ +void hd44780_data(uint8_t data); + +/** + * \brief Clear the display. + * + * This function is called on init. + */ +void hd44780_clear(void); + +/** + * \brief Move the cursor to the home position. + * + * This function is called on init. + */ +void hd44780_home(void); + +/** + * \brief Turn the display on, and/or set the cursor position. + * + * This function is called on init. + * + * \param cursor Whether to show the cursor. + * \param blink Whether to blink the cursor, if shown. + */ +void hd44780_on(bool cursor, bool blink); + +/** + * \brief Turn the display off. + */ +void hd44780_off(void); + +/** + * \brief Set the CGRAM address. + * + * This function is used when defining custom characters. + * + * \param address The CGRAM address to move to, from `0x00` to `0x3F`. + */ +void hd44780_set_cgram_address(uint8_t address); + +/** + * \brief Set the DDRAM address. + * + * This function is used when printing characters to the display, and setting the cursor. + * + * \param address The DDRAM address to move to, from `0x00` to `0x7F`. + */ +void hd44780_set_ddram_address(uint8_t address); + +/** + * \brief Initialize the display. + * + * This function should be called only once, before any of the other functions can be called. + * + * \param cursor Whether to show the cursor. + * \param blink Whether to blink the cursor, if shown. + */ +void hd44780_init(bool cursor, bool blink); + +/** + * \brief Move the cursor to the specified position on the display. + * + * \param col The column number to move to, from 0 to 15 on 16x2 displays. + * \param line The line number to move to, either 0 or 1 on 16x2 displays. + */ +void hd44780_set_cursor(uint8_t col, uint8_t line); + +/** + * \brief Define a custom character. + * + * \param index The index of the custom character to define, from 0 to 7. + * \param data An array of 8 bytes containing the 5-bit row data of the character, where the first byte is the topmost row, and the least significant bit of each byte is the rightmost column. + */ +void hd44780_define_char(uint8_t index, uint8_t *data); + +/** + * \brief Print a character to the display. The newline character will move the cursor to the start of the next line. + * + * The exact character shown may depend on the ROM code of your particular display - refer to the datasheet for the full character set. + * + * \param c The character to print. + */ +void hd44780_putc(char c); + +/** + * \brief Print a string of characters to the display. + * + * \param s The string to print. + */ +void hd44780_puts(const char *s); + +#if defined(__AVR__) || defined(__DOXYGEN__) +/** + * \brief Define a custom character from PROGMEM. + * + * On ARM devices, this function is simply an alias of hd44780_define_char(). + * + * \param index The index of the custom character to define, from 0 to 7. + * \param data A PROGMEM array of 8 bytes containing the 5-bit row data of the character, where the first byte is the topmost row, and the least significant bit of each byte is the rightmost column. + */ +void hd44780_define_char_P(uint8_t index, const uint8_t *data); + +/** + * \brief Print a string of characters from PROGMEM to the display. + * + * On ARM devices, this function is simply an alias of hd44780_puts(). + * + * \param s The PROGMEM string to print. + */ +void hd44780_puts_P(const char *s); +#else +# define hd44780_define_char_P(index, data) hd44780_define_char(index, data) +# define hd44780_puts_P(s) hd44780_puts(s) +#endif + +/** \} */ diff --git a/keyboards/al1/config.h b/keyboards/al1/config.h index ea6474dc18..07cc94a279 100644 --- a/keyboards/al1/config.h +++ b/keyboards/al1/config.h @@ -30,6 +30,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MATRIX_ROWS 6 #define MATRIX_COLS 16 +#define MATRIX_ROW_PINS { C7, B1, B2, C6, B4, B5 } + +#define SN74X154_ADDRESS_PINS { D4, D5, D6, D7 } +#define SN74X154_E1_PIN D3 + #define LED_NUM_LOCK_PIN D0 #define LED_CAPS_LOCK_PIN B7 #define LED_SCROLL_LOCK_PIN D1 diff --git a/keyboards/al1/matrix.c b/keyboards/al1/matrix.c index 1407cbc089..e3d7971f1c 100644 --- a/keyboards/al1/matrix.c +++ b/keyboards/al1/matrix.c @@ -1,91 +1,101 @@ -#include "matrix.h" +/* Copyright 2022 + * + * 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/>. + */ +#include "matrix.h" #include "gpio.h" +#include "sn74x154.h" -static uint8_t read_rows(void) { - return (readPin(C7) ? 0 : 1) | - (readPin(B1) ? 0 : 2) | - (readPin(B2) ? 0 : 4) | - (readPin(C6) ? 0 : 8) | - (readPin(B4) ? 0 : 16) | - (readPin(B5) ? 0 : 32); -} +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +/* All columns use a 74HC154 4-to-16 demultiplexer. + * D3 is the enable pin, must be set high to use it. + * + * A3 A2 A1 A0 + * D7 D6 D5 D4 + * 0: 0 0 0 0 + * 1: 0 0 0 1 + * 2: 0 0 1 0 + * 3: 0 0 1 1 + * 4: 0 1 0 0 + * 5: 0 1 0 1 + * 6: 0 1 1 0 + * 7: 0 1 1 1 + * 8: 1 0 0 0 + * 9: 1 0 0 1 + * 10: 1 0 1 0 + * 11: 1 0 1 1 + * 12: 1 1 0 0 + * 13: 1 1 0 1 + * 14: 1 1 1 0 + * 15: 1 1 1 1 + */ static void select_col(uint8_t col) { - writePinLow(D3); - - writePin(D4, (col & 1)); - writePin(D5, (col & 2)); - writePin(D6, (col & 4)); - writePin(D7, (col & 8)); + sn74x154_set_addr(col); } -static void unselect_cols(void) { - writePinHigh(D3); +static void init_pins(void) { + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + setPinInputHigh(row_pins[x]); + } } -void matrix_init_custom(void) { - /* 74HC154 col pin configuration - * pin: D3 D7 D6 D5 D4 - * row: off 0 x x x x - * 0 1 0 0 0 0 - * 1 1 0 0 0 1 - * 2 1 0 0 1 0 - * 3 1 0 0 1 1 - * 4 1 0 1 0 0 - * 5 1 0 1 0 1 - * 6 1 0 1 1 0 - * 7 1 0 1 1 1 - * 8 1 1 0 0 0 - * 9 1 1 0 0 1 - * 10 1 1 0 1 0 - * 11 1 1 0 1 1 - * 12 1 1 1 0 0 - * 13 1 1 1 0 1 - * 14 1 1 1 1 0 - * 15 1 1 1 1 1 - */ - setPinOutput(D3); - writePinHigh(D3); +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { + bool matrix_changed = false; + + // Select col and wait for col seleciton to stabilize + select_col(current_col); + matrix_io_delay(); - setPinOutput(D4); - setPinOutput(D5); - setPinOutput(D6); - setPinOutput(D7); + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[row_index]; + // Check row pin state + if (readPin(row_pins[row_index]) == 0) { + // Pin LO, set col bit + current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); + } else { + // Pin HI, clear col bit + current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); + } - /* Row pin configuration - * - * row: 0 1 2 3 4 5 - * pin: C7 B1 B2 C6 B4 B5 - * - */ - setPinInputHigh(C7); - setPinInputHigh(B1); - setPinInputHigh(B2); - setPinInputHigh(C6); - setPinInputHigh(B4); - setPinInputHigh(B5); + // Determine if the matrix changed state + if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) { + matrix_changed = true; + } + } + + return matrix_changed; +} + +void matrix_init_custom(void) { + // initialize demultiplexer + sn74x154_init(); + sn74x154_set_enabled(true); + // initialize key pins + init_pins(); } bool matrix_scan_custom(matrix_row_t current_matrix[]) { bool changed = false; - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - select_col(col); - matrix_io_delay(); - uint8_t rows = read_rows(); - - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - bool prev_bit = current_matrix[row] & ((matrix_row_t)1 << col); - bool curr_bit = rows & (1 << row); - - if (prev_bit != curr_bit) { - current_matrix[row] ^= ((matrix_row_t)1 << col); - changed = true; - } - } - unselect_cols(); + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(current_matrix, current_col); } return changed; diff --git a/keyboards/al1/rules.mk b/keyboards/al1/rules.mk index 670712f661..1f8e81de20 100644 --- a/keyboards/al1/rules.mk +++ b/keyboards/al1/rules.mk @@ -18,4 +18,5 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output CUSTOM_MATRIX = lite -SRC += matrix.c +VPATH += drivers/gpio +SRC += matrix.c sn74x154.c diff --git a/keyboards/draculad/config.h b/keyboards/draculad/config.h index abcdc76b4b..3060f801c6 100644 --- a/keyboards/draculad/config.h +++ b/keyboards/draculad/config.h @@ -61,7 +61,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define ENCODERS_PAD_A {B2 , B4} #define ENCODERS_PAD_B {B6 , B5} -#define ENCODER_RESOLUTIONS { 4, 4, 4, 1} +#define ENCODER_RESOLUTIONS { 4, 4 } +#define ENCODER_RESOLUTIONS_RIGHT { 4, 1 } #define UNUSED_PINS #define EE_HANDS diff --git a/keyboards/evyd13/wasdat/matrix.c b/keyboards/evyd13/wasdat/matrix.c index c97dd84694..60a1ea235a 100644 --- a/keyboards/evyd13/wasdat/matrix.c +++ b/keyboards/evyd13/wasdat/matrix.c @@ -24,27 +24,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -/* col 0: C7 - * col 1: B6 - * col 2: C6 - * col 3: B4 - * col 4: B5 - * col 5: D7 +/* Columns 6-12 use a 74HC138 3-to-8 demultiplexer. * - * These columns use a 74HC138 3 to 8 bit demultiplexer. - * A2 A1 A0 - * col / pin: PD0 PD1 PD2 - * 6: 1 1 1 - * 7: 1 1 0 - * 8: 1 0 1 - * 9: 1 0 0 - * 10: 0 1 1 - * 11: 0 1 0 - * 12: 0 0 1 + * 0: C7 + * 1: B6 + * 2: C6 + * 3: B4 + * 4: B5 + * 5: D7 * - * col 13: D3 - * col 14: B7 - * col 15: B3 + * A2 A1 A0 + * D0 D1 D2 + * 6: 1 1 1 + * 7: 1 1 0 + * 8: 1 0 1 + * 9: 1 0 0 + * 10: 0 1 1 + * 11: 0 1 0 + * 12: 0 0 1 + * + * 13: D3 + * 14: B7 + * 15: B3 */ static void select_col(uint8_t col) { if (col_pins[col] != NO_PIN) { @@ -117,10 +118,10 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) } void matrix_init_custom(void) { - // initialize key pins - init_pins(); // initialize demultiplexer sn74x138_init(); + // initialize key pins + init_pins(); } bool matrix_scan_custom(matrix_row_t current_matrix[]) { diff --git a/keyboards/evyd13/wasdat_code/config.h b/keyboards/evyd13/wasdat_code/config.h index ae009c1c29..a8b5c032ca 100644 --- a/keyboards/evyd13/wasdat_code/config.h +++ b/keyboards/evyd13/wasdat_code/config.h @@ -41,22 +41,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. * */ #define MATRIX_ROW_PINS { E6, C7, C6, B6, B5, B4, D7, D6 } -#define MATRIX_COL_PINS { } +#define MATRIX_COL_PINS { F7, F5, F6, F1, F4, F0, NO_PIN, D5, D3, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN } // Columns 6 and 9-15 controlled by demux #define UNUSED_PINS -/* COL2ROW, ROW2COL*/ -#define DIODE_DIRECTION ROW2COL +#define SN74X138_ADDRESS_PINS { D2, D1, D0 } +#define SN74X138_E3_PIN D4 // For QMK DFU #define QMK_ESC_OUTPUT E6 #define QMK_ESC_INPUT F0 #define QMK_LED B1 -/* - * Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN. - */ -//#define SOFT_SERIAL_PIN D0 // or D1, D2, D3, E6 - #define LED_NUM_LOCK_PIN B3 #define LED_CAPS_LOCK_PIN B1 #define LED_SCROLL_LOCK_PIN B2 diff --git a/keyboards/evyd13/wasdat_code/matrix.c b/keyboards/evyd13/wasdat_code/matrix.c index 7844db7ab7..f30ea3355a 100644 --- a/keyboards/evyd13/wasdat_code/matrix.c +++ b/keyboards/evyd13/wasdat_code/matrix.c @@ -14,280 +14,70 @@ 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 "util.h" #include "matrix.h" -#include "debounce.h" #include "quantum.h" +#include "sn74x138.h" -#ifdef DIRECT_PINS -static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -//static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -#endif - -// matrix code - -#ifdef DIRECT_PINS - -static void init_pins(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = direct_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - matrix_row_t last_row_value = current_matrix[current_row]; - current_matrix[current_row] = 0; - - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - pin_t pin = direct_pins[current_row][col_index]; - if (pin != NO_PIN) { - current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - } - - return (last_row_value != current_matrix[current_row]); -} - -#elif (DIODE_DIRECTION == COL2ROW) - -static void select_row(uint8_t row) { - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); -} - -static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } - -static void unselect_rows(void) { - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); - } -} - -static void init_pins(void) { - unselect_rows(); - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[current_row]; - - // Clear data in matrix row - current_matrix[current_row] = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - wait_us(30); - - // For each col... - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - - // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); - - // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - return (last_row_value != current_matrix[current_row]); -} - -#elif (DIODE_DIRECTION == ROW2COL) - -/* Cols 0 - 15 - * col 0: F7 - * col 1: F5 - * col 2: F6 - * col 3: F1 - * col 4: F4 - * col 5: F0 - * These columns use a 74HC237D 3 to 8 bit demultiplexer. D4 is the enable pin, must be set high to use it. - * A0 A1 A2 - * col / pin: PD2 PD1 PD0 - * 6: 1 1 1 - * col 7: D3 - * col 8: B7 - * 9: 0 1 1 - * 10: 1 0 1 - * 11: 0 0 1 - * 12: 1 1 0 - * 13: 0 1 0 - * 14: 1 0 0 - * 15: 0 0 0 +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +/* Columns 6 and 9-15 use a 74HC138 3-to-8 demultiplexer. + * D4 is the enable pin, must be set high to use it. + * + * 0: F7 + * 1: F5 + * 2: F6 + * 3: F1 + * 4: F4 + * 5: F0 + * + * A2 A1 A0 + * D0 D1 D2 + * 6: 1 1 1 + * + * 7: D5 + * 8: D3 + * + * 9: 1 1 0 + * 10: 1 0 1 + * 11: 1 0 0 + * 12: 0 1 1 + * 13: 0 1 0 + * 14: 0 0 1 + * 15: 0 0 0 */ static void select_col(uint8_t col) { - switch (col) { - case 0: - writePinLow(F7); - break; - case 1: - writePinLow(F5); - break; - case 2: - writePinLow(F6); - break; - case 3: - writePinLow(F1); - break; - case 4: - writePinLow(F4); - break; - case 5: - writePinLow(F0); - break; - case 6: - writePinHigh(D4); - writePinHigh(D2); - writePinHigh(D1); - writePinHigh(D0); - break; - case 7: - writePinLow(D5); - break; - case 8: - writePinLow(D3); - break; - case 9: - writePinHigh(D4); - writePinHigh(D1); - writePinHigh(D0); - break; - case 10: - writePinHigh(D4); - writePinHigh(D2); - writePinHigh(D0); - break; - case 11: - writePinHigh(D4); - writePinHigh(D0); - break; - case 12: - writePinHigh(D4); - writePinHigh(D2); - writePinHigh(D1); - break; - case 13: - writePinHigh(D4); - writePinHigh(D1); - break; - case 14: - writePinHigh(D4); - writePinHigh(D2); - break; - case 15: - writePinHigh(D4); - break; + if (col_pins[col] != NO_PIN) { + writePinLow(col_pins[col]); + } else { + sn74x138_set_addr((col == 6) ? 7 : 15 - col); + sn74x138_set_enabled(true); } } static void unselect_col(uint8_t col) { - switch (col) { - case 0: - writePinHigh(F7); - break; - case 1: - writePinHigh(F5); - break; - case 2: - writePinHigh(F6); - break; - case 3: - writePinHigh(F1); - break; - case 4: - writePinHigh(F4); - break; - case 5: - writePinHigh(F0); - break; - case 6: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 7: - writePinHigh(D5); - break; - case 8: - writePinHigh(D3); - break; - case 9: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 10: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 11: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 12: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 13: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 14: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; - case 15: - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); - break; + if (col_pins[col] != NO_PIN) { + setPinOutput(col_pins[col]); + writePinHigh(col_pins[col]); + } else { + sn74x138_set_enabled(false); } } static void unselect_cols(void) { - //Native - writePinHigh(F7); - writePinHigh(F5); - writePinHigh(F6); - writePinHigh(F1); - writePinHigh(F4); - writePinHigh(F0); - writePinHigh(D3); - writePinHigh(D5); + // Native + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + if (col_pins[x] != NO_PIN) { + setPinOutput(col_pins[x]); + writePinHigh(col_pins[x]); + } + } - //Demultiplexer - writePinLow(D4); - writePinLow(D2); - writePinLow(D1); - writePinLow(D0); + // Demultiplexer + sn74x138_set_enabled(false); } static void init_pins(void) { @@ -295,27 +85,14 @@ static void init_pins(void) { for (uint8_t x = 0; x < MATRIX_ROWS; x++) { setPinInputHigh(row_pins[x]); } - setPinOutput(D0); - setPinOutput(D1); - setPinOutput(D2); - setPinOutput(D3); - setPinOutput(F7); - setPinOutput(F5); - setPinOutput(F6); - setPinOutput(F1); - setPinOutput(F4); - setPinOutput(F0); - setPinOutput(D3); - setPinOutput(D5); - setPinOutput(D4); } static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { bool matrix_changed = false; - // Select col and wait for col selecton to stabilize + // Select col and wait for col selection to stabilize select_col(current_col); - wait_us(30); + matrix_io_delay(); // For each row... for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { @@ -343,9 +120,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) return matrix_changed; } -#endif - void matrix_init_custom(void) { + // initialize demultiplexer + sn74x138_init(); // initialize key pins init_pins(); } @@ -353,17 +130,10 @@ void matrix_init_custom(void) { bool matrix_scan_custom(matrix_row_t current_matrix[]) { bool changed = false; -#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) - // Set row, read cols - for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - changed |= read_cols_on_row(current_matrix, current_row); - } -#elif (DIODE_DIRECTION == ROW2COL) // Set col, read rows for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { changed |= read_rows_on_col(current_matrix, current_col); } -#endif return changed; } diff --git a/keyboards/evyd13/wasdat_code/rules.mk b/keyboards/evyd13/wasdat_code/rules.mk index 6fd1fce10e..b37dfa459c 100644 --- a/keyboards/evyd13/wasdat_code/rules.mk +++ b/keyboards/evyd13/wasdat_code/rules.mk @@ -18,6 +18,7 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output CUSTOM_MATRIX = lite -SRC += matrix.c +VPATH += drivers/gpio +SRC += matrix.c sn74x138.c LAYOUTS = fullsize_ansi fullsize_iso tkl_ansi tkl_iso diff --git a/keyboards/handwired/wakizashi40/config.h b/keyboards/handwired/wakizashi40/config.h index 78f85f2197..e9976616ec 100644 --- a/keyboards/handwired/wakizashi40/config.h +++ b/keyboards/handwired/wakizashi40/config.h @@ -17,4 +17,3 @@ #pragma once #include "config_common.h" -#define DYNAMIC_KEYMAP_LAYER_COUNT 12 diff --git a/keyboards/handwired/wakizashi40/info.json b/keyboards/handwired/wakizashi40/info.json index 58eadb29e6..b97d61171b 100644 --- a/keyboards/handwired/wakizashi40/info.json +++ b/keyboards/handwired/wakizashi40/info.json @@ -1,9 +1,9 @@ { - "manufacturer": "fumbucker", + "manufacturer": "xia0", "keyboard_name": "Wakizashi 40", - "maintainer": "fumbucker", + "maintainer": "xia0", "debounce": 5, - "processor": "at90usb1286", + "processor": "atmega32u4", "diode_direction": "COL2ROW", "features": { "audio": false, @@ -20,8 +20,8 @@ "unicode": false }, "matrix_pins": { - "cols": ["C5", "C4", "D2", "D3", "D4", "D5", "C6", "D7", "B0", "B1", "B2", "B3", "B4"], - "rows": ["C0", "C1", "C2", "C3"] + "cols": ["F4", "F6", "F7", "B1", "B3", "B2", "B6", "B5", "B4", "E6", "D7", "C6", "D4"], + "rows": ["D3", "D2", "D1", "D0"] }, "usb": { "vid": "0x6662", diff --git a/keyboards/handwired/wakizashi40/keymaps/via/keymap.c b/keyboards/handwired/wakizashi40/keymaps/via/keymap.c index d456b8b40a..fb9d37ac20 100644 --- a/keyboards/handwired/wakizashi40/keymaps/via/keymap.c +++ b/keyboards/handwired/wakizashi40/keymaps/via/keymap.c @@ -16,77 +16,27 @@ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - - [0] = LAYOUT_all( - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, - MO(3), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT, - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_ESC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, - KC_LCTL, KC_LGUI, KC_LALT, LT(1, KC_SPC), LT(2, KC_SPC), KC_LALT, KC_MENU, KC_LCTL), - - [1] = LAYOUT_all( - KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F5, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, - MO(11), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_TRNS, KC_EQL, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_SPC, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS), - - [2] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS, - MO(11), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, KC_TRNS, KC_QUOT, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_SPC, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS), - - [3] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_QUOT, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [4] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [5] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [6] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [7] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [8] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [9] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [10] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), - - [11] = LAYOUT_all( - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) - + [0] = LAYOUT_all( + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + MO(3), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_ESC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, + KC_LCTL, KC_LGUI, KC_LALT, LT(1, KC_SPC), LT(2, KC_SPC), KC_LALT, KC_MENU, KC_LCTL), + + [1] = LAYOUT_all( + KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F5, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, + MO(3), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_TRNS, KC_EQL, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_SPC, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS), + + [2] = LAYOUT_all( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS, + MO(3), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, KC_TRNS, KC_QUOT, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_SPC, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS), + + [3] = LAYOUT_all( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_QUOT, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), }; diff --git a/keyboards/handwired/wakizashi40/readme.md b/keyboards/handwired/wakizashi40/readme.md index d94a75651c..8bb6c2aebc 100644 --- a/keyboards/handwired/wakizashi40/readme.md +++ b/keyboards/handwired/wakizashi40/readme.md @@ -1,12 +1,12 @@ # Wakizashi 40 -![Wakizashi40](https://cdn.thingiverse.com/renders/51/50/81/13/a9/7078248666f70b422127c6662cf79563_preview_featured.jpg) +![Wakizashi40](https://i.imgur.com/TVTfa0X.jpg) Reverse stagger 40% keyboard based on the Katana 60. -* Keyboard Maintainer: [fumbucker](https://github.com/xia0) -* Hardware Supported: Teensy2++ -* Hardware Availability: [thingiverse](https://www.thingiverse.com/thing:3467930) +* Keyboard Maintainer: [xia0](https://github.com/xia0) +* Hardware Supported: ATmega32u4 +* Hardware Availability: [prusaprinters.org](https://www.prusaprinters.org/prints/128575-wakizashi-40-keyboard) Make example for this keyboard (after setting up your build environment): @@ -16,4 +16,6 @@ See [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) ## Bootloader -* **Keycode in layout**: Press the key mapped to `RESET` if it is available (Capslock + R). +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard +* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead +* **Keycode in layout**: Press the key mapped to `RESET` if it is available diff --git a/keyboards/hnahkb/vn66/rules.mk b/keyboards/hnahkb/vn66/rules.mk index f1c1ec985e..542b79b4d8 100644 --- a/keyboards/hnahkb/vn66/rules.mk +++ b/keyboards/hnahkb/vn66/rules.mk @@ -17,5 +17,6 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output ENCODER_ENABLE = yes +LTO_ENABLE = yes LAYOUTS = 66_ansi 66_iso diff --git a/keyboards/horrortroll/handwired_k552/rules.mk b/keyboards/horrortroll/handwired_k552/rules.mk index 5df510cd44..f29c92f64c 100644 --- a/keyboards/horrortroll/handwired_k552/rules.mk +++ b/keyboards/horrortroll/handwired_k552/rules.mk @@ -20,6 +20,7 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output NO_USB_STARTUP_CHECK = yes +LTO_ENABLE = yes # RGB Matrix enabled RGB_MATRIX_ENABLE = yes diff --git a/keyboards/input_club/ergodox_infinity/mcuconf.h b/keyboards/input_club/ergodox_infinity/mcuconf.h index f6730b99ca..e4dfa75186 100644 --- a/keyboards/input_club/ergodox_infinity/mcuconf.h +++ b/keyboards/input_club/ergodox_infinity/mcuconf.h @@ -62,7 +62,7 @@ /* Need to redefine this, since the default is for K20x */ /* This is for Teensy LC; you should comment it out (or change to 5) * for Teensy 3.x */ -#define KINETIS_USB_USB0_IRQ_PRIORITY 2 +#define KINETIS_USB_USB0_IRQ_PRIORITY 5 /* * SPI driver system settings. diff --git a/keyboards/matrix/abelx/mcuconf.h b/keyboards/matrix/abelx/mcuconf.h index a22ce51c4c..a2fd42b8c4 100644 --- a/keyboards/matrix/abelx/mcuconf.h +++ b/keyboards/matrix/abelx/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -169,7 +169,6 @@ /* * 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 diff --git a/keyboards/sofle/keyhive/config.h b/keyboards/sofle/keyhive/config.h index c934754e65..93048f3cd1 100755 --- a/keyboards/sofle/keyhive/config.h +++ b/keyboards/sofle/keyhive/config.h @@ -42,11 +42,12 @@ #define DEBOUNCE 5 // Encoder support -#define ENCODERS_PAD_A { F5 } -#define ENCODERS_PAD_B { F4 } -#define ENCODERS_PAD_A_RIGHT { F4 } -#define ENCODERS_PAD_B_RIGHT { F5 } -#define ENCODER_RESOLUTIONS { 4, 2 } // Left encoder seems to have double-output issue but right does not. +#define ENCODERS_PAD_A { F5 } +#define ENCODERS_PAD_B { F4 } +#define ENCODERS_PAD_A_RIGHT { F4 } +#define ENCODERS_PAD_B_RIGHT { F5 } +#define ENCODER_RESOLUTIONS { 4 } +#define ENCODER_RESOLUTIONS_RIGHT { 2 } // Left encoder seems to have double-output issue but right does not. #define TAP_CODE_DELAY 10 diff --git a/keyboards/sowbug/68keys/config.h b/keyboards/sowbug/68keys/config.h index 0aad9a4574..0721302dbe 100644 --- a/keyboards/sowbug/68keys/config.h +++ b/keyboards/sowbug/68keys/config.h @@ -26,7 +26,6 @@ #define DEVICE_VER 0x0001 #define MANUFACTURER github.com/sowbug #define PRODUCT 68-key keyboard -#define DESCRIPTION A 68-key keyboard based on 68keys.io // key matrix size #define MATRIX_ROWS 5 diff --git a/keyboards/sowbug/ansi_tkl/config.h b/keyboards/sowbug/ansi_tkl/config.h index 505453b72b..44e82bbac7 100644 --- a/keyboards/sowbug/ansi_tkl/config.h +++ b/keyboards/sowbug/ansi_tkl/config.h @@ -26,7 +26,6 @@ #define DEVICE_VER 0x0001 #define MANUFACTURER github.com/sowbug #define PRODUCT ANSI TKL -#define DESCRIPTION A tenkeyless ANSI-layout keyboard // key matrix size #define MATRIX_ROWS 6 diff --git a/keyboards/tkc/portico68v2/config.h b/keyboards/tkc/portico68v2/config.h index 486863d702..dea6180958 100644 --- a/keyboards/tkc/portico68v2/config.h +++ b/keyboards/tkc/portico68v2/config.h @@ -79,8 +79,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # define ENABLE_RGB_MATRIX_HUE_PENDULUM # define ENABLE_RGB_MATRIX_HUE_WAVE # define ENABLE_RGB_MATRIX_PIXEL_RAIN -# define ENABLE_RGB_MATRIX_PIXEL_FLOW -# define ENABLE_RGB_MATRIX_PIXEL_FRACTAL +//# define ENABLE_RGB_MATRIX_PIXEL_FLOW +//# define ENABLE_RGB_MATRIX_PIXEL_FRACTAL // enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined # define ENABLE_RGB_MATRIX_TYPING_HEATMAP # define ENABLE_RGB_MATRIX_DIGITAL_RAIN diff --git a/keyboards/unicomp/spacesaver_m_pre_2013/overnumpad_1xb/config.h b/keyboards/unicomp/spacesaver_m_pre_2013/overnumpad_1xb/config.h index 7bd5b224df..597d287b07 100644 --- a/keyboards/unicomp/spacesaver_m_pre_2013/overnumpad_1xb/config.h +++ b/keyboards/unicomp/spacesaver_m_pre_2013/overnumpad_1xb/config.h @@ -23,7 +23,6 @@ #define DEVICE_VER 0x0001 #define MANUFACTURER Unicomp/Purdea Andrei #define PRODUCT Unicomp Spacesaver M -#define DESCRIPTION QMK firmware for the Unicomp Spacesaver M keyboard with a replacement Overnumpad controller #define SERIAL_NUMBER "purdea.ro:overnumpad_controller" /* key matrix size */ diff --git a/keyboards/viktus/sp_mini/config.h b/keyboards/viktus/sp_mini/config.h index a0671c97f3..bce8a4cc4c 100644 --- a/keyboards/viktus/sp_mini/config.h +++ b/keyboards/viktus/sp_mini/config.h @@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // wiring of each half #define MATRIX_ROW_PINS { F0, B5, B4, D7, D6 } -#define MATRIX_COL_PINS { B6, C6, C7, D4, D2, D3, D5 } // no B7 on left hand +#define MATRIX_COL_PINS { B6, C6, C7, D4, D2, D3, D5, NO_PIN } // no B7 on left hand #define MATRIX_ROW_PINS_RIGHT { F0, B5, B4, D7, D6 } #define MATRIX_COL_PINS_RIGHT { B6, C6, C7, D4, D2, D3, D5, B7 } @@ -78,7 +78,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. //#define ENCODERS_PAD_A_RIGHT {F4} //#define ENCODERS_PAD_B_RIGHT {F1} -#define ENCODER_RESOLUTIONS { 8, 8 } +#define ENCODER_RESOLUTIONS { 8 } /* * Feature disable options diff --git a/keyboards/xelus/ninjin/config.h b/keyboards/xelus/ninjin/config.h index cbaca37b5e..4dd40210a6 100644 --- a/keyboards/xelus/ninjin/config.h +++ b/keyboards/xelus/ninjin/config.h @@ -22,7 +22,6 @@ #define DEVICE_VER 0x0001 #define MANUFACTURER Xelus #define PRODUCT Ninjin -#define DESCRIPTION Ninjin /* key matrix size */ #define MATRIX_ROWS 6 diff --git a/lib/chibios b/lib/chibios -Subproject d7b9d1c87f724bd7c8cd1486d6d0dc3ba52e0d5 +Subproject 257302333c31f1f710800c2b97acf3550de043e diff --git a/lib/chibios-contrib b/lib/chibios-contrib -Subproject d1c2126d1cd867c50127da84425805e225df855 +Subproject ff1c6ec90cfc250d81e6f29a0d60a4faf2afb46 diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 285bd90eb5..0596b3f22b 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -1,7 +1,7 @@ """This script automates the generation of the QMK API data. """ from pathlib import Path -from shutil import copyfile +import shutil import json from milc import cli @@ -12,28 +12,42 @@ from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load from qmk.keyboard import find_readme, list_keyboards +TEMPLATE_PATH = Path('data/templates/api/') +BUILD_API_PATH = Path('.build/api_data/') + @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") +@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on partial name matches the supplied value. May be passed multiple times.") @cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) def generate_api(cli): """Generates the QMK API data. """ - api_data_dir = Path('api_data') - v1_dir = api_data_dir / 'v1' + if BUILD_API_PATH.exists(): + shutil.rmtree(BUILD_API_PATH) + + shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) + + v1_dir = BUILD_API_PATH / 'v1' keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target - if not api_data_dir.exists(): - api_data_dir.mkdir() + # Filter down when required + keyboard_list = list_keyboards() + if cli.args.filter: + kb_list = [] + for keyboard_name in keyboard_list: + if any(i in keyboard_name for i in cli.args.filter): + kb_list.append(keyboard_name) + keyboard_list = kb_list kb_all = {} usb_list = {} # Generate and write keyboard specific JSON files - for keyboard_name in list_keyboards(): + for keyboard_name in keyboard_list: kb_all[keyboard_name] = info_json(keyboard_name) keyboard_dir = v1_dir / 'keyboards' / keyboard_name keyboard_info = keyboard_dir / 'info.json' @@ -47,7 +61,7 @@ def generate_api(cli): cli.log.debug('Wrote file %s', keyboard_info) if keyboard_readme_src: - copyfile(keyboard_readme_src, keyboard_readme) + shutil.copyfile(keyboard_readme_src, keyboard_readme) cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) if 'usb' in kb_all[keyboard_name]: diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index fdc76b23d4..adefdb5732 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -84,7 +84,7 @@ def generate_config_items(kb_info_json, config_h_lines): for config_key, info_dict in info_config_map.items(): info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') to_config = info_dict.get('to_config', True) if not to_config: @@ -112,6 +112,11 @@ def generate_config_items(kb_info_json, config_h_lines): config_h_lines.append(f'#ifndef {key}') config_h_lines.append(f'# define {key} {value}') config_h_lines.append(f'#endif // {key}') + elif key_type == 'str': + config_h_lines.append('') + config_h_lines.append(f'#ifndef {config_key}') + config_h_lines.append(f'# define {config_key} "{config_value}"') + config_h_lines.append(f'#endif // {config_key}') elif key_type == 'bcd_version': (major, minor, revision) = config_value.split('.') config_h_lines.append('') diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py index 74112d834d..eb3099e138 100644 --- a/lib/python/qmk/cli/generate/docs.py +++ b/lib/python/qmk/cli/generate/docs.py @@ -10,6 +10,7 @@ DOCS_PATH = Path('docs/') BUILD_PATH = Path('.build/') BUILD_DOCS_PATH = BUILD_PATH / 'docs' DOXYGEN_PATH = BUILD_PATH / 'doxygen' +MOXYGEN_PATH = BUILD_DOCS_PATH / 'internals' @cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True) @@ -34,10 +35,10 @@ def generate_docs(cli): 'stdin': DEVNULL, } - cli.log.info('Generating internal docs...') + cli.log.info('Generating docs...') # Generate internal docs cli.run(['doxygen', 'Doxyfile'], **args) - cli.run(['moxygen', '-q', '-g', '-o', BUILD_DOCS_PATH / 'internals_%s.md', DOXYGEN_PATH / 'xml'], **args) + cli.run(['moxygen', '-q', '-g', '-o', MOXYGEN_PATH / '%s.md', DOXYGEN_PATH / 'xml'], **args) - cli.log.info('Successfully generated internal docs to %s.', BUILD_DOCS_PATH) + cli.log.info('Successfully generated docs to %s.', BUILD_DOCS_PATH) diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 29a1130f99..6f342c6567 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -21,7 +21,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): return None info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') try: rules_value = kb_info_json[info_key] @@ -34,6 +34,8 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): return f'{rules_key} ?= {"yes" if rules_value else "no"}' elif key_type == 'mapping': return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()]) + elif key_type == 'str': + return f'{rules_key} ?= "{rules_value}"' return f'{rules_key} ?= {rules_value}' diff --git a/lib/python/qmk/cli/pytest.py b/lib/python/qmk/cli/pytest.py index b7b17f0e9d..5c9c173caa 100644 --- a/lib/python/qmk/cli/pytest.py +++ b/lib/python/qmk/cli/pytest.py @@ -12,8 +12,7 @@ from milc import cli def pytest(cli): """Run several linting/testing commands. """ - nose2 = cli.run(['nose2', '-v', '-t' - 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) + nose2 = cli.run(['nose2', '-v', '-t', 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) flake8 = cli.run(['flake8', 'lib/python'], capture_output=False, stdin=DEVNULL) return flake8.returncode | nose2.returncode diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index d0bd00beb7..9c0a5dce56 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -228,7 +228,7 @@ def dump_lines(output_file, lines, quiet=True): output_file.parent.mkdir(parents=True, exist_ok=True) if output_file.exists(): output_file.replace(output_file.parent / (output_file.name + '.bak')) - output_file.write_text(generated) + output_file.write_text(generated, encoding='utf-8') if not quiet: cli.log.info(f'Wrote {output_file.name} to {output_file}.') diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index b86eaa059f..c399a9f321 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -411,7 +411,7 @@ def _extract_config_h(info_data): for config_key, info_dict in info_config_map.items(): info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') try: if config_key in config_c and info_dict.get('to_json', True): @@ -443,6 +443,9 @@ def _extract_config_h(info_data): elif key_type == 'int': dotty_info[info_key] = int(config_c[config_key]) + elif key_type == 'str': + dotty_info[info_key] = config_c[config_key].strip('"') + elif key_type == 'bcd_version': major = int(config_c[config_key][2:4]) minor = int(config_c[config_key][4]) @@ -491,7 +494,7 @@ def _extract_rules_mk(info_data): for rules_key, info_dict in info_rules_map.items(): info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') try: if rules_key in rules and info_dict.get('to_json', True): @@ -523,6 +526,9 @@ def _extract_rules_mk(info_data): elif key_type == 'int': dotty_info[info_key] = int(rules[rules_key]) + elif key_type == 'str': + dotty_info[info_key] = rules[rules_key].strip('"') + else: dotty_info[info_key] = rules[rules_key] diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 55e69175e6..d40d4bf573 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -244,7 +244,7 @@ def test_clean(): def test_generate_api(): - result = check_subcommand('generate-api', '--dry-run') + result = check_subcommand('generate-api', '--dry-run', '--filter', 'handwired/pytest') check_returncode(result) @@ -259,7 +259,7 @@ def test_generate_config_h(): result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic') check_returncode(result) assert '# define DEVICE_VER 0x0001' in result.stdout - assert '# define DESCRIPTION handwired/pytest/basic' in result.stdout + assert '# define DESCRIPTION "handwired/pytest/basic"' in result.stdout assert '# define DIODE_DIRECTION COL2ROW' in result.stdout assert '# define MANUFACTURER none' in result.stdout assert '# define PRODUCT pytest' in result.stdout diff --git a/platforms/arm_atsam/pin_defs.h b/platforms/arm_atsam/_pin_defs.h index 5b50b23910..5b50b23910 100644 --- a/platforms/arm_atsam/pin_defs.h +++ b/platforms/arm_atsam/_pin_defs.h diff --git a/platforms/avr/pin_defs.h b/platforms/avr/_pin_defs.h index 3889704a87..3889704a87 100644 --- a/platforms/avr/pin_defs.h +++ b/platforms/avr/_pin_defs.h diff --git a/platforms/avr/drivers/hd44780.c b/platforms/avr/drivers/hd44780.c deleted file mode 100644 index f15d7d0da8..0000000000 --- a/platforms/avr/drivers/hd44780.c +++ /dev/null @@ -1,542 +0,0 @@ -/**************************************************************************** - Title: HD44780U LCD library - Author: Peter Fleury <pfleury@gmx.ch> http://tinyurl.com/peterfleury - License: GNU General Public License Version 3 - File: $Id: lcd.c,v 1.15.2.2 2015/01/17 12:16:05 peter Exp $ - Software: AVR-GCC 3.3 - Target: any AVR device, memory mapped mode only for AT90S4414/8515/Mega - - DESCRIPTION - Basic routines for interfacing a HD44780U-based text lcd display - - Originally based on Volker Oth's lcd library, - changed lcd_init(), added additional constants for lcd_command(), - added 4-bit I/O mode, improved and optimized code. - - Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in - 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported. - - Memory mapped mode compatible with Kanda STK200, but supports also - generation of R/W signal through A8 address line. - - USAGE - See the C include lcd.h file for a description of each function - -*****************************************************************************/ -#include <inttypes.h> -#include <avr/io.h> -#include <avr/pgmspace.h> -#include <util/delay.h> -#include "hd44780.h" - -/* -** constants/macros -*/ -#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */ -#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) -/* on ATmega64/128 PINF is on port 0x00 and not 0x60 */ -# define PIN(x) (&PORTF == &(x) ? _SFR_IO8(0x00) : (*(&x - 2))) -#else -# define PIN(x) (*(&x - 2)) /* address of input register of port x */ -#endif - -#if LCD_IO_MODE -# define lcd_e_delay() _delay_us(LCD_DELAY_ENABLE_PULSE) -# define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN); -# define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN); -# define lcd_e_toggle() toggle_e() -# define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN) -# define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN) -# define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN) -# define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN) -#endif - -#if LCD_IO_MODE -# if LCD_LINES == 1 -# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE -# else -# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES -# endif -#else -# if LCD_LINES == 1 -# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE -# else -# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES -# endif -#endif - -#if LCD_CONTROLLER_KS0073 -# if LCD_LINES == 4 - -# define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x2C /* |0|010|1100 4-bit mode, extension-bit RE = 1 */ -# define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28 /* |0|010|1000 4-bit mode, extension-bit RE = 0 */ -# define KS0073_4LINES_MODE 0x09 /* |0|000|1001 4 lines mode */ - -# endif -#endif - -/* -** function prototypes -*/ -#if LCD_IO_MODE -static void toggle_e(void); -#endif - -/* -** local functions -*/ - -/************************************************************************* -delay for a minimum of <us> microseconds -the number of loops is calculated at compile-time from MCU clock frequency -*************************************************************************/ -#define delay(us) _delay_us(us) - -#if LCD_IO_MODE -/* toggle Enable Pin to initiate write */ -static void toggle_e(void) { - lcd_e_high(); - lcd_e_delay(); - lcd_e_low(); -} -#endif - -/************************************************************************* -Low-level function to write byte to LCD controller -Input: data byte to write to LCD - rs 1: write data - 0: write instruction -Returns: none -*************************************************************************/ -#if LCD_IO_MODE -static void lcd_write(uint8_t data, uint8_t rs) { - unsigned char dataBits; - - if (rs) { /* write data (RS=1, RW=0) */ - lcd_rs_high(); - } else { /* write instruction (RS=0, RW=0) */ - lcd_rs_low(); - } - lcd_rw_low(); /* RW=0 write mode */ - - if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) { - /* configure data pins as output */ - DDR(LCD_DATA0_PORT) |= 0x0F; - - /* output high nibble first */ - dataBits = LCD_DATA0_PORT & 0xF0; - LCD_DATA0_PORT = dataBits | ((data >> 4) & 0x0F); - lcd_e_toggle(); - - /* output low nibble */ - LCD_DATA0_PORT = dataBits | (data & 0x0F); - lcd_e_toggle(); - - /* all data pins high (inactive) */ - LCD_DATA0_PORT = dataBits | 0x0F; - } else { - /* configure data pins as output */ - DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN); - DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN); - DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN); - DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN); - - /* output high nibble first */ - LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN); - LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN); - LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN); - LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); - if (data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); - if (data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); - if (data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); - if (data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); - lcd_e_toggle(); - - /* output low nibble */ - LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN); - LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN); - LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN); - LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); - if (data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); - if (data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); - if (data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); - if (data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); - lcd_e_toggle(); - - /* all data pins high (inactive) */ - LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); - LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); - LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); - LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); - } -} -#else -# define lcd_write(d, rs) \ - if (rs) \ - *(volatile uint8_t *)(LCD_IO_DATA) = d; \ - else \ - *(volatile uint8_t *)(LCD_IO_FUNCTION) = d; -/* rs==0 -> write instruction to LCD_IO_FUNCTION */ -/* rs==1 -> write data to LCD_IO_DATA */ -#endif - -/************************************************************************* -Low-level function to read byte from LCD controller -Input: rs 1: read data - 0: read busy flag / address counter -Returns: byte read from LCD controller -*************************************************************************/ -#if LCD_IO_MODE -static uint8_t lcd_read(uint8_t rs) { - uint8_t data; - - if (rs) - lcd_rs_high(); /* RS=1: read data */ - else - lcd_rs_low(); /* RS=0: read busy flag */ - lcd_rw_high(); /* RW=1 read mode */ - - if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) { - DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */ - - lcd_e_high(); - lcd_e_delay(); - data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */ - lcd_e_low(); - - lcd_e_delay(); /* Enable 500ns low */ - - lcd_e_high(); - lcd_e_delay(); - data |= PIN(LCD_DATA0_PORT) & 0x0F; /* read low nibble */ - lcd_e_low(); - } else { - /* configure data pins as input */ - DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN); - DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN); - DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN); - DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN); - - /* read high nibble first */ - lcd_e_high(); - lcd_e_delay(); - data = 0; - if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x10; - if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x20; - if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x40; - if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x80; - lcd_e_low(); - - lcd_e_delay(); /* Enable 500ns low */ - - /* read low nibble */ - lcd_e_high(); - lcd_e_delay(); - if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x01; - if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x02; - if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x04; - if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x08; - lcd_e_low(); - } - return data; -} -#else -# define lcd_read(rs) (rs) ? *(volatile uint8_t *)(LCD_IO_DATA + LCD_IO_READ) : *(volatile uint8_t *)(LCD_IO_FUNCTION + LCD_IO_READ) -/* rs==0 -> read instruction from LCD_IO_FUNCTION */ -/* rs==1 -> read data from LCD_IO_DATA */ -#endif - -/************************************************************************* -loops while lcd is busy, returns address counter -*************************************************************************/ -static uint8_t lcd_waitbusy(void) - -{ - register uint8_t c; - - /* wait until busy flag is cleared */ - while ((c = lcd_read(0)) & (1 << LCD_BUSY)) { - } - - /* the address counter is updated 4us after the busy flag is cleared */ - delay(LCD_DELAY_BUSY_FLAG); - - /* now read the address counter */ - return (lcd_read(0)); // return address counter - -} /* lcd_waitbusy */ - -/************************************************************************* -Move cursor to the start of next line or to the first line if the cursor -is already on the last line. -*************************************************************************/ -static inline void lcd_newline(uint8_t pos) { - register uint8_t addressCounter; - -#if LCD_LINES == 1 - addressCounter = 0; -#endif -#if LCD_LINES == 2 - if (pos < (LCD_START_LINE2)) - addressCounter = LCD_START_LINE2; - else - addressCounter = LCD_START_LINE1; -#endif -#if LCD_LINES == 4 -# if KS0073_4LINES_MODE - if (pos < LCD_START_LINE2) - addressCounter = LCD_START_LINE2; - else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3)) - addressCounter = LCD_START_LINE3; - else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4)) - addressCounter = LCD_START_LINE4; - else - addressCounter = LCD_START_LINE1; -# else - if (pos < LCD_START_LINE3) - addressCounter = LCD_START_LINE2; - else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4)) - addressCounter = LCD_START_LINE3; - else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2)) - addressCounter = LCD_START_LINE4; - else - addressCounter = LCD_START_LINE1; -# endif -#endif - lcd_command((1 << LCD_DDRAM) + addressCounter); - -} /* lcd_newline */ - -/* -** PUBLIC FUNCTIONS -*/ - -/************************************************************************* -Send LCD controller instruction command -Input: instruction to send to LCD controller, see HD44780 data sheet -Returns: none -*************************************************************************/ -void lcd_command(uint8_t cmd) { - lcd_waitbusy(); - lcd_write(cmd, 0); -} - -/************************************************************************* -Send data byte to LCD controller -Input: data to send to LCD controller, see HD44780 data sheet -Returns: none -*************************************************************************/ -void lcd_data(uint8_t data) { - lcd_waitbusy(); - lcd_write(data, 1); -} - -/************************************************************************* -Set cursor to specified position -Input: x horizontal position (0: left most position) - y vertical position (0: first line) -Returns: none -*************************************************************************/ -void lcd_gotoxy(uint8_t x, uint8_t y) { -#if LCD_LINES == 1 - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x); -#endif -#if LCD_LINES == 2 - if (y == 0) - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x); - else - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x); -#endif -#if LCD_LINES == 4 - if (y == 0) - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x); - else if (y == 1) - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x); - else if (y == 2) - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE3 + x); - else /* y==3 */ - lcd_command((1 << LCD_DDRAM) + LCD_START_LINE4 + x); -#endif - -} /* lcd_gotoxy */ - -/************************************************************************* -*************************************************************************/ -int lcd_getxy(void) { - return lcd_waitbusy(); -} - -/************************************************************************* -Clear display and set cursor to home position -*************************************************************************/ -void lcd_clrscr(void) { - lcd_command(1 << LCD_CLR); -} - -/************************************************************************* -Set cursor to home position -*************************************************************************/ -void lcd_home(void) { - lcd_command(1 << LCD_HOME); -} - -/************************************************************************* -Display character at current cursor position -Input: character to be displayed -Returns: none -*************************************************************************/ -void lcd_putc(char c) { - uint8_t pos; - - pos = lcd_waitbusy(); // read busy-flag and address counter - if (c == '\n') { - lcd_newline(pos); - } else { -#if LCD_WRAP_LINES == 1 -# if LCD_LINES == 1 - if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0); - } -# elif LCD_LINES == 2 - if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0); - } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0); - } -# elif LCD_LINES == 4 - if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0); - } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE3, 0); - } else if (pos == LCD_START_LINE3 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE4, 0); - } else if (pos == LCD_START_LINE4 + LCD_DISP_LENGTH) { - lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0); - } -# endif - lcd_waitbusy(); -#endif - lcd_write(c, 1); - } - -} /* lcd_putc */ - -/************************************************************************* -Display string without auto linefeed -Input: string to be displayed -Returns: none -*************************************************************************/ -void lcd_puts(const char *s) -/* print string on lcd (no auto linefeed) */ -{ - register char c; - - while ((c = *s++)) { - lcd_putc(c); - } - -} /* lcd_puts */ - -/************************************************************************* -Display string from program memory without auto linefeed -Input: string from program memory be be displayed -Returns: none -*************************************************************************/ -void lcd_puts_p(const char *progmem_s) -/* print string from program memory on lcd (no auto linefeed) */ -{ - register char c; - - while ((c = pgm_read_byte(progmem_s++))) { - lcd_putc(c); - } - -} /* lcd_puts_p */ - -/************************************************************************* -Initialize display and select type of cursor -Input: dispAttr LCD_DISP_OFF display off - LCD_DISP_ON display on, cursor off - LCD_DISP_ON_CURSOR display on, cursor on - LCD_DISP_CURSOR_BLINK display on, cursor on flashing -Returns: none -*************************************************************************/ -void lcd_init(uint8_t dispAttr) { -#if LCD_IO_MODE - /* - * Initialize LCD to 4 bit I/O mode - */ - - if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (&LCD_RS_PORT == &LCD_DATA0_PORT) && (&LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) && (LCD_RS_PIN == 4) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6)) { - /* configure all port bits as output (all LCD lines on same port) */ - DDR(LCD_DATA0_PORT) |= 0x7F; - } else if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) { - /* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */ - DDR(LCD_DATA0_PORT) |= 0x0F; - DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN); - DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN); - DDR(LCD_E_PORT) |= _BV(LCD_E_PIN); - } else { - /* configure all port bits as output (LCD data and control lines on different ports */ - DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN); - DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN); - DDR(LCD_E_PORT) |= _BV(LCD_E_PIN); - DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN); - DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN); - DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN); - DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN); - } - delay(LCD_DELAY_BOOTUP); /* wait 16ms or more after power-on */ - - /* initial write to lcd is 8bit */ - LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // LCD_FUNCTION>>4; - LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // LCD_FUNCTION_8BIT>>4; - lcd_e_toggle(); - delay(LCD_DELAY_INIT); /* delay, busy flag can't be checked here */ - - /* repeat last command */ - lcd_e_toggle(); - delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */ - - /* repeat last command a third time */ - lcd_e_toggle(); - delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */ - - /* now configure for 4bit mode */ - LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4 - lcd_e_toggle(); - delay(LCD_DELAY_INIT_4BIT); /* some displays need this additional delay */ - - /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */ -#else - /* - * Initialize LCD to 8 bit memory mapped mode - */ - - /* enable external SRAM (memory mapped lcd) and one wait state */ - MCUCR = _BV(SRE) | _BV(SRW); - - /* reset LCD */ - delay(LCD_DELAY_BOOTUP); /* wait 16ms after power-on */ - lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */ - delay(LCD_DELAY_INIT); /* wait 5ms */ - lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */ - delay(LCD_DELAY_INIT_REP); /* wait 64us */ - lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */ - delay(LCD_DELAY_INIT_REP); /* wait 64us */ -#endif - -#if KS0073_4LINES_MODE - /* Display with KS0073 controller requires special commands for enabling 4 line mode */ - lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON); - lcd_command(KS0073_4LINES_MODE); - lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF); -#else - lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */ -#endif - lcd_command(LCD_DISP_OFF); /* display off */ - lcd_clrscr(); /* display clear */ - lcd_command(LCD_MODE_DEFAULT); /* set entry mode */ - lcd_command(dispAttr); /* display/cursor control */ - -} /* lcd_init */ diff --git a/platforms/avr/drivers/hd44780.h b/platforms/avr/drivers/hd44780.h deleted file mode 100644 index 08e60f8a44..0000000000 --- a/platforms/avr/drivers/hd44780.h +++ /dev/null @@ -1,348 +0,0 @@ -/************************************************************************* - Title : C include file for the HD44780U LCD library (lcd.c) - Author: Peter Fleury <pfleury@gmx.ch> http://tinyurl.com/peterfleury - License: GNU General Public License Version 3 - File: $Id: lcd.h,v 1.14.2.4 2015/01/20 17:16:07 peter Exp $ - Software: AVR-GCC 4.x - Hardware: any AVR device, memory mapped mode only for AVR with - memory mapped interface (AT90S8515/ATmega8515/ATmega128) -***************************************************************************/ - -/** - @mainpage - Collection of libraries for AVR-GCC - @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury - @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3 - - @file - @defgroup pfleury_lcd LCD library <lcd.h> - @code #include <lcd.h> @endcode - - @brief Basic routines for interfacing a HD44780U-based character LCD display - - LCD character displays can be found in many devices, like espresso machines, laser printers. - The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays. - - This library allows easy interfacing with a HD44780 compatible display and can be - operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in - 4-bit IO port mode (LCD_IO_MODE defined as 1). 8-bit IO port mode is not supported. - - Memory mapped mode is compatible with old Kanda STK200 starter kit, but also supports - generation of R/W signal through A8 address line. - - @see The chapter <a href=" http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html" target="_blank">Interfacing a HD44780 Based LCD to an AVR</a> - on my home page, which shows example circuits how to connect an LCD to an AVR controller. - - @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury - - @version 2.0 - - @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3 - -*/ - -#pragma once - -#include <inttypes.h> -#include <avr/pgmspace.h> - -#if (__GNUC__ * 100 + __GNUC_MINOR__) < 405 -# error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !" -#endif - -/**@{*/ - -/* - * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file - * by adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile - * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h - */ -#ifdef _LCD_DEFINITIONS_FILE -# include "lcd_definitions.h" -#endif - -/** - * @name Definition for LCD controller type - * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller. - */ -#ifndef LCD_CONTROLLER_KS0073 -# define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */ -#endif - -/** - * @name Definitions for Display Size - * Change these definitions to adapt setting to your display - * - * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by - * adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile. - * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h - * - */ -#ifndef LCD_LINES -# define LCD_LINES 2 /**< number of visible lines of the display */ -#endif -#ifndef LCD_DISP_LENGTH -# define LCD_DISP_LENGTH 16 /**< visibles characters per line of the display */ -#endif -#ifndef LCD_LINE_LENGTH -# define LCD_LINE_LENGTH 0x40 /**< internal line length of the display */ -#endif -#ifndef LCD_START_LINE1 -# define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */ -#endif -#ifndef LCD_START_LINE2 -# define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */ -#endif -#ifndef LCD_START_LINE3 -# define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */ -#endif -#ifndef LCD_START_LINE4 -# define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */ -#endif -#ifndef LCD_WRAP_LINES -# define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */ -#endif - -/** - * @name Definitions for 4-bit IO mode - * - * The four LCD data lines and the three control lines RS, RW, E can be on the - * same port or on different ports. - * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on - * different ports. - * - * Normally the four data lines should be mapped to bit 0..3 on one port, but it - * is possible to connect these data lines in different order or even on different - * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions. - * - * Adjust these definitions to your target.\n - * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by - * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile. - * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h - * - */ -#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */ - -#if LCD_IO_MODE - -# ifndef LCD_PORT -# define LCD_PORT PORTA /**< port for the LCD lines */ -# endif -# ifndef LCD_DATA0_PORT -# define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */ -# endif -# ifndef LCD_DATA1_PORT -# define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */ -# endif -# ifndef LCD_DATA2_PORT -# define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */ -# endif -# ifndef LCD_DATA3_PORT -# define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */ -# endif -# ifndef LCD_DATA0_PIN -# define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0 */ -# endif -# ifndef LCD_DATA1_PIN -# define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1 */ -# endif -# ifndef LCD_DATA2_PIN -# define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2 */ -# endif -# ifndef LCD_DATA3_PIN -# define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3 */ -# endif -# ifndef LCD_RS_PORT -# define LCD_RS_PORT LCD_PORT /**< port for RS line */ -# endif -# ifndef LCD_RS_PIN -# define LCD_RS_PIN 3 /**< pin for RS line */ -# endif -# ifndef LCD_RW_PORT -# define LCD_RW_PORT LCD_PORT /**< port for RW line */ -# endif -# ifndef LCD_RW_PIN -# define LCD_RW_PIN 2 /**< pin for RW line */ -# endif -# ifndef LCD_E_PORT -# define LCD_E_PORT LCD_PORT /**< port for Enable line */ -# endif -# ifndef LCD_E_PIN -# define LCD_E_PIN 1 /**< pin for Enable line */ -# endif - -#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__) -/* - * memory mapped mode is only supported when the device has an external data memory interface - */ -# define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */ -# define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */ -# define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */ - -#else -# error "external data memory interface not available for this device, use 4-bit IO port mode" - -#endif - -/** - * @name Definitions of delays - * Used to calculate delay timers. - * Adapt the F_CPU define in the Makefile to the clock frequency in Hz of your target - * - * These delay times can be adjusted, if some displays require different delays.\n - * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by - * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile. - * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h - */ -#ifndef LCD_DELAY_BOOTUP -# define LCD_DELAY_BOOTUP 16000 /**< delay in micro seconds after power-on */ -#endif -#ifndef LCD_DELAY_INIT -# define LCD_DELAY_INIT 5000 /**< delay in micro seconds after initialization command sent */ -#endif -#ifndef LCD_DELAY_INIT_REP -# define LCD_DELAY_INIT_REP 64 /**< delay in micro seconds after initialization command repeated */ -#endif -#ifndef LCD_DELAY_INIT_4BIT -# define LCD_DELAY_INIT_4BIT 64 /**< delay in micro seconds after setting 4-bit mode */ -#endif -#ifndef LCD_DELAY_BUSY_FLAG -# define LCD_DELAY_BUSY_FLAG 4 /**< time in micro seconds the address counter is updated after busy flag is cleared */ -#endif -#ifndef LCD_DELAY_ENABLE_PULSE -# define LCD_DELAY_ENABLE_PULSE 1 /**< enable signal pulse width in micro seconds */ -#endif - -/** - * @name Definitions for LCD command instructions - * The constants define the various LCD controller instructions which can be passed to the - * function lcd_command(), see HD44780 data sheet for a complete description. - */ - -/* instruction register bit positions, see HD44780U data sheet */ -#define LCD_CLR 0 /* DB0: clear display */ -#define LCD_HOME 1 /* DB1: return to home position */ -#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */ -#define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */ -#define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */ -#define LCD_ON 3 /* DB3: turn lcd/cursor on */ -#define LCD_ON_DISPLAY 2 /* DB2: turn display on */ -#define LCD_ON_CURSOR 1 /* DB1: turn cursor on */ -#define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */ -#define LCD_MOVE 4 /* DB4: move cursor/display */ -#define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */ -#define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */ -#define LCD_FUNCTION 5 /* DB5: function set */ -#define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */ -#define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */ -#define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */ -#define LCD_CGRAM 6 /* DB6: set CG RAM address */ -#define LCD_DDRAM 7 /* DB7: set DD RAM address */ -#define LCD_BUSY 7 /* DB7: LCD is busy */ - -/* set entry mode: display shift on/off, dec/inc cursor move direction */ -#define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */ -#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */ -#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */ -#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */ - -/* display on/off, cursor on/off, blinking char at cursor position */ -#define LCD_DISP_OFF 0x08 /* display off */ -#define LCD_DISP_ON 0x0C /* display on, cursor off */ -#define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */ -#define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */ -#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */ - -/* move cursor/shift display */ -#define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */ -#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */ -#define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */ -#define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */ - -/* function set: set interface data length and number of display lines */ -#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */ -#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */ -#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */ -#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */ - -#define LCD_MODE_DEFAULT ((1 << LCD_ENTRY_MODE) | (1 << LCD_ENTRY_INC)) - -/** - * @name Functions - */ - -/** - @brief Initialize display and select type of cursor - @param dispAttr \b LCD_DISP_OFF display off\n - \b LCD_DISP_ON display on, cursor off\n - \b LCD_DISP_ON_CURSOR display on, cursor on\n - \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing - @return none -*/ -extern void lcd_init(uint8_t dispAttr); - -/** - @brief Clear display and set cursor to home position - @return none -*/ -extern void lcd_clrscr(void); - -/** - @brief Set cursor to home position - @return none -*/ -extern void lcd_home(void); - -/** - @brief Set cursor to specified position - - @param x horizontal position\n (0: left most position) - @param y vertical position\n (0: first line) - @return none -*/ -extern void lcd_gotoxy(uint8_t x, uint8_t y); - -/** - @brief Display character at current cursor position - @param c character to be displayed - @return none -*/ -extern void lcd_putc(char c); - -/** - @brief Display string without auto linefeed - @param s string to be displayed - @return none -*/ -extern void lcd_puts(const char *s); - -/** - @brief Display string from program memory without auto linefeed - @param progmem_s string from program memory be be displayed - @return none - @see lcd_puts_P -*/ -extern void lcd_puts_p(const char *progmem_s); - -/** - @brief Send LCD controller instruction command - @param cmd instruction to send to LCD controller, see HD44780 data sheet - @return none -*/ -extern void lcd_command(uint8_t cmd); - -/** - @brief Send data byte to LCD controller - - Similar to lcd_putc(), but without interpreting LF - @param data byte to send to LCD controller, see HD44780 data sheet - @return none -*/ -extern void lcd_data(uint8_t data); - -/** - @brief macros for automatically storing string constant in program memory -*/ -#define lcd_puts_P(__s) lcd_puts_p(PSTR(__s)) - -/**@}*/ diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 4d9cafaeef..9f304d2e20 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -18,6 +18,13 @@ COMPILEFLAGS += -ffunction-sections COMPILEFLAGS += -fdata-sections COMPILEFLAGS += -fpack-struct COMPILEFLAGS += -fshort-enums +COMPILEFLAGS += -mcall-prologues + +# Linker relaxation is only possible if +# link time optimizations are not enabled. +ifeq ($(strip $(LTO_ENABLE)), no) + COMPILEFLAGS += -mrelax +endif ASFLAGS += $(AVR_ASFLAGS) @@ -28,7 +35,7 @@ CFLAGS += -fno-strict-aliasing CXXFLAGS += $(COMPILEFLAGS) CXXFLAGS += -fno-exceptions -std=c++11 -LDFLAGS +=-Wl,--gc-sections +LDFLAGS += -Wl,--gc-sections OPT_DEFS += -DF_CPU=$(F_CPU)UL diff --git a/platforms/chibios/pin_defs.h b/platforms/chibios/_pin_defs.h index c03f8de0c2..a84d931cc2 100644 --- a/platforms/chibios/pin_defs.h +++ b/platforms/chibios/_pin_defs.h @@ -15,6 +15,12 @@ */ #pragma once +#if defined(MCU_KINETIS) +// TODO: including this avoids "error: expected identifier before '(' token" errors +// here just to please KINETIS builds... +# include <hal.h> +#endif + // Defines mapping for Proton C replacement #ifdef CONVERT_TO_PROTON_C // Left side (front) diff --git a/platforms/chibios/boards/GENERIC_STM32_F303XC/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_F303XC/configs/mcuconf.h index c6f5a8ac52..e0af4a276b 100644 --- a/platforms/chibios/boards/GENERIC_STM32_F303XC/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_F303XC/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -186,7 +186,6 @@ /* * 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 diff --git a/platforms/chibios/boards/GENERIC_STM32_F405XG/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_F405XG/configs/mcuconf.h index 908a580a91..394e750256 100644 --- a/platforms/chibios/boards/GENERIC_STM32_F405XG/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_F405XG/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -86,6 +86,28 @@ #define STM32_IRQ_EXTI21_PRIORITY 15 #define STM32_IRQ_EXTI22_PRIORITY 15 +#define STM32_IRQ_TIM1_BRK_TIM9_PRIORITY 7 +#define STM32_IRQ_TIM1_UP_TIM10_PRIORITY 7 +#define STM32_IRQ_TIM1_TRGCO_TIM11_PRIORITY 7 +#define STM32_IRQ_TIM1_CC_PRIORITY 7 +#define STM32_IRQ_TIM2_PRIORITY 7 +#define STM32_IRQ_TIM3_PRIORITY 7 +#define STM32_IRQ_TIM4_PRIORITY 7 +#define STM32_IRQ_TIM5_PRIORITY 7 +#define STM32_IRQ_TIM6_PRIORITY 7 +#define STM32_IRQ_TIM7_PRIORITY 7 +#define STM32_IRQ_TIM8_BRK_TIM12_PRIORITY 7 +#define STM32_IRQ_TIM8_UP_TIM13_PRIORITY 7 +#define STM32_IRQ_TIM8_TRGCO_TIM14_PRIORITY 7 +#define STM32_IRQ_TIM8_CC_PRIORITY 7 + +#define STM32_IRQ_USART1_PRIORITY 12 +#define STM32_IRQ_USART2_PRIORITY 12 +#define STM32_IRQ_USART3_PRIORITY 12 +#define STM32_IRQ_UART4_PRIORITY 12 +#define STM32_IRQ_UART5_PRIORITY 12 +#define STM32_IRQ_USART6_PRIORITY 12 + /* * ADC driver system settings. */ @@ -137,21 +159,11 @@ #define STM32_GPT_USE_TIM7 FALSE #define STM32_GPT_USE_TIM8 FALSE #define STM32_GPT_USE_TIM9 FALSE +#define STM32_GPT_USE_TIM10 FALSE #define STM32_GPT_USE_TIM11 FALSE #define STM32_GPT_USE_TIM12 FALSE +#define STM32_GPT_USE_TIM13 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. @@ -199,13 +211,11 @@ #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 +#define STM32_ICU_USE_TIM10 FALSE +#define STM32_ICU_USE_TIM11 FALSE +#define STM32_ICU_USE_TIM12 FALSE +#define STM32_ICU_USE_TIM13 FALSE +#define STM32_ICU_USE_TIM14 FALSE /* * MAC driver system settings. @@ -221,7 +231,6 @@ /* * 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 @@ -229,13 +238,11 @@ #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 +#define STM32_PWM_USE_TIM10 FALSE +#define STM32_PWM_USE_TIM11 FALSE +#define STM32_PWM_USE_TIM12 FALSE +#define STM32_PWM_USE_TIM13 FALSE +#define STM32_PWM_USE_TIM14 FALSE /* * RTC driver system settings. @@ -265,12 +272,6 @@ #define STM32_SERIAL_USE_UART4 FALSE #define STM32_SERIAL_USE_UART5 FALSE #define STM32_SERIAL_USE_USART6 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 /* * SPI driver system settings. @@ -319,12 +320,6 @@ #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 diff --git a/platforms/chibios/boards/GENERIC_STM32_F407XE/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_F407XE/configs/mcuconf.h index 928ee56c71..07399ad2f7 100644 --- a/platforms/chibios/boards/GENERIC_STM32_F407XE/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_F407XE/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -86,6 +86,28 @@ #define STM32_IRQ_EXTI21_PRIORITY 15 #define STM32_IRQ_EXTI22_PRIORITY 15 +#define STM32_IRQ_TIM1_BRK_TIM9_PRIORITY 7 +#define STM32_IRQ_TIM1_UP_TIM10_PRIORITY 7 +#define STM32_IRQ_TIM1_TRGCO_TIM11_PRIORITY 7 +#define STM32_IRQ_TIM1_CC_PRIORITY 7 +#define STM32_IRQ_TIM2_PRIORITY 7 +#define STM32_IRQ_TIM3_PRIORITY 7 +#define STM32_IRQ_TIM4_PRIORITY 7 +#define STM32_IRQ_TIM5_PRIORITY 7 +#define STM32_IRQ_TIM6_PRIORITY 7 +#define STM32_IRQ_TIM7_PRIORITY 7 +#define STM32_IRQ_TIM8_BRK_TIM12_PRIORITY 7 +#define STM32_IRQ_TIM8_UP_TIM13_PRIORITY 7 +#define STM32_IRQ_TIM8_TRGCO_TIM14_PRIORITY 7 +#define STM32_IRQ_TIM8_CC_PRIORITY 7 + +#define STM32_IRQ_USART1_PRIORITY 12 +#define STM32_IRQ_USART2_PRIORITY 12 +#define STM32_IRQ_USART3_PRIORITY 12 +#define STM32_IRQ_UART4_PRIORITY 12 +#define STM32_IRQ_UART5_PRIORITY 12 +#define STM32_IRQ_USART6_PRIORITY 12 + /* * ADC driver system settings. */ @@ -137,21 +159,11 @@ #define STM32_GPT_USE_TIM7 FALSE #define STM32_GPT_USE_TIM8 FALSE #define STM32_GPT_USE_TIM9 FALSE +#define STM32_GPT_USE_TIM10 FALSE #define STM32_GPT_USE_TIM11 FALSE #define STM32_GPT_USE_TIM12 FALSE +#define STM32_GPT_USE_TIM13 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. @@ -199,13 +211,11 @@ #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 +#define STM32_ICU_USE_TIM10 FALSE +#define STM32_ICU_USE_TIM11 FALSE +#define STM32_ICU_USE_TIM12 FALSE +#define STM32_ICU_USE_TIM13 FALSE +#define STM32_ICU_USE_TIM14 FALSE /* * MAC driver system settings. @@ -221,7 +231,6 @@ /* * 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 @@ -229,13 +238,11 @@ #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 +#define STM32_PWM_USE_TIM10 FALSE +#define STM32_PWM_USE_TIM11 FALSE +#define STM32_PWM_USE_TIM12 FALSE +#define STM32_PWM_USE_TIM13 FALSE +#define STM32_PWM_USE_TIM14 FALSE /* * RTC driver system settings. @@ -265,12 +272,6 @@ #define STM32_SERIAL_USE_UART4 FALSE #define STM32_SERIAL_USE_UART5 FALSE #define STM32_SERIAL_USE_USART6 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 /* * SPI driver system settings. @@ -319,12 +320,6 @@ #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 diff --git a/platforms/chibios/boards/GENERIC_STM32_G431XB/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_G431XB/configs/mcuconf.h index d115028300..fd00280115 100644 --- a/platforms/chibios/boards/GENERIC_STM32_G431XB/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_G431XB/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ * HAL driver system settings. */ #define STM32_NO_INIT FALSE +#define STM32_CLOCK_DYNAMIC FALSE #define STM32_VOS STM32_VOS_RANGE1 #define STM32_PWR_BOOST TRUE #define STM32_PWR_CR2 (PWR_CR2_PLS_LEV0) @@ -227,7 +228,6 @@ /* * 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 @@ -240,6 +240,13 @@ /* * RTC driver system settings. */ +#define STM32_RTC_PRESA_VALUE 32 +#define STM32_RTC_PRESS_VALUE 1024 +#define STM32_RTC_CR_INIT 0 +#define STM32_TAMP_CR1_INIT 0 +#define STM32_TAMP_CR2_INIT 0 +#define STM32_TAMP_FLTCR_INIT 0 +#define STM32_TAMP_IER_INIT 0 /* * SDC driver system settings. @@ -255,6 +262,15 @@ #define STM32_SERIAL_USE_LPUART1 FALSE /* + * SIO driver system settings. + */ +#define STM32_SIO_USE_USART1 FALSE +#define STM32_SIO_USE_USART2 FALSE +#define STM32_SIO_USE_USART3 FALSE +#define STM32_SIO_USE_UART4 FALSE +#define STM32_SIO_USE_LPUART1 FALSE + +/* * SPI driver system settings. */ #define STM32_SPI_USE_SPI1 FALSE diff --git a/platforms/chibios/boards/GENERIC_STM32_G474XE/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_G474XE/configs/mcuconf.h index 5710e2cb45..d6385da624 100644 --- a/platforms/chibios/boards/GENERIC_STM32_G474XE/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_G474XE/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ * HAL driver system settings. */ #define STM32_NO_INIT FALSE +#define STM32_CLOCK_DYNAMIC FALSE #define STM32_VOS STM32_VOS_RANGE1 #define STM32_PWR_BOOST TRUE #define STM32_PWR_CR2 (PWR_CR2_PLS_LEV0) @@ -274,7 +275,6 @@ /* * 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 @@ -289,6 +289,13 @@ /* * RTC driver system settings. */ +#define STM32_RTC_PRESA_VALUE 32 +#define STM32_RTC_PRESS_VALUE 1024 +#define STM32_RTC_CR_INIT 0 +#define STM32_TAMP_CR1_INIT 0 +#define STM32_TAMP_CR2_INIT 0 +#define STM32_TAMP_FLTCR_INIT 0 +#define STM32_TAMP_IER_INIT 0 /* * SDC driver system settings. @@ -305,6 +312,16 @@ #define STM32_SERIAL_USE_LPUART1 FALSE /* + * SIO driver system settings. + */ +#define STM32_SIO_USE_USART1 FALSE +#define STM32_SIO_USE_USART2 FALSE +#define STM32_SIO_USE_USART3 FALSE +#define STM32_SIO_USE_UART4 FALSE +#define STM32_SIO_USE_UART5 FALSE +#define STM32_SIO_USE_LPUART1 FALSE + +/* * SPI driver system settings. */ #define STM32_SPI_USE_SPI1 FALSE @@ -383,5 +400,6 @@ */ #define STM32_WSPI_USE_QUADSPI1 FALSE #define STM32_WSPI_QUADSPI1_DMA_STREAM STM32_DMA_STREAM_ID(2, 7) +#define STM32_WSPI_QUADSPI1_PRESCALER_VALUE 1 #endif /* MCUCONF_H */ diff --git a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/board.h b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/board.h index 2e37d95fe3..de5f85acdd 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/board.h +++ b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/board.h @@ -18,7 +18,4 @@ #include_next "board.h" #undef STM32L432xx - -// Pretend that we're an L443xx as the ChibiOS definitions for L4x2/L4x3 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 +#define STM32L422xx diff --git a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/config.h index fc9055ccfb..d67de4cfe2 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/config.h +++ b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/config.h @@ -18,8 +18,6 @@ /* It is chip dependent, the correct number can be looked up by checking against ST's application note AN2606. */ -#define PAL_STM32_OSPEED_HIGHEST PAL_STM32_OSPEED_HIGH - #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif diff --git a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/mcuconf.h index 8ad5a8da21..47f1598b74 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_L412XB/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -32,12 +32,7 @@ #define MCUCONF_H #define STM32L4xx_MCUCONF -#define STM32L412_MCUCONF #define STM32L422_MCUCONF -#define STM32L432_MCUCONF -#define STM32L433_MCUCONF -#define STM32L442_MCUCONF -#define STM32L443_MCUCONF /* * HAL driver system settings. @@ -52,16 +47,13 @@ #define STM32_HSE_ENABLED FALSE #define STM32_LSE_ENABLED FALSE #define STM32_MSIPLL_ENABLED FALSE -#define STM32_ADC_CLOCK_ENABLED TRUE -#define STM32_USB_CLOCK_ENABLED TRUE -#define STM32_SAI1_CLOCK_ENABLED TRUE -#define STM32_SAI2_CLOCK_ENABLED TRUE #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 4 #define STM32_PLLN_VALUE 80 +#define STM32_PLLPDIV_VALUE 0 #define STM32_PLLP_VALUE 7 #define STM32_PLLQ_VALUE 4 #define STM32_PLLR_VALUE 4 @@ -73,29 +65,22 @@ #define STM32_MCOPRE STM32_MCOPRE_DIV1 #define STM32_LSCOSEL STM32_LSCOSEL_NOCLOCK #define STM32_PLLSAI1N_VALUE 72 +#define STM32_PLLSAI1PDIV_VALUE 6 #define STM32_PLLSAI1P_VALUE 7 #define STM32_PLLSAI1Q_VALUE 6 #define STM32_PLLSAI1R_VALUE 6 -#define STM32_PLLSAI2N_VALUE 72 -#define STM32_PLLSAI2P_VALUE 7 -#define STM32_PLLSAI2R_VALUE 6 /* * Peripherals clock sources. */ #define STM32_USART1SEL STM32_USART1SEL_SYSCLK #define STM32_USART2SEL STM32_USART2SEL_SYSCLK -#define STM32_USART3SEL STM32_USART3SEL_SYSCLK -#define STM32_UART4SEL STM32_UART4SEL_SYSCLK -#define STM32_UART5SEL STM32_UART5SEL_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_SAI2SEL STM32_SAI2SEL_OFF #define STM32_CLK48SEL STM32_CLK48SEL_HSI48 #define STM32_ADCSEL STM32_ADCSEL_SYSCLK #define STM32_SWPMI1SEL STM32_SWPMI1SEL_PCLK1 @@ -127,7 +112,6 @@ #define STM32_IRQ_USART1_PRIORITY 12 #define STM32_IRQ_USART2_PRIORITY 12 -#define STM32_IRQ_USART3_PRIORITY 12 #define STM32_IRQ_LPUART1_PRIORITY 12 /* @@ -137,29 +121,15 @@ #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_USE_ADC2 FALSE +#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) +#define STM32_ADC_ADC2_DMA_PRIORITY 2 #define STM32_ADC_ADC12_IRQ_PRIORITY 5 #define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 5 +#define STM32_ADC_ADC2_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. @@ -198,7 +168,6 @@ /* * 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 @@ -218,23 +187,22 @@ #define STM32_SERIAL_USE_USART1 FALSE #define STM32_SERIAL_USE_USART2 FALSE #define STM32_SERIAL_USE_LPUART1 FALSE -#define STM32_SERIAL_USART1_PRIORITY 12 -#define STM32_SERIAL_USART2_PRIORITY 12 -#define STM32_SERIAL_LPUART1_PRIORITY 12 + +/* + * SIO driver system settings. + */ +#define STM32_SIO_USE_USART1 FALSE +#define STM32_SIO_USE_USART2 FALSE +#define STM32_SIO_USE_LPUART1 FALSE /* * SPI driver system settings. */ #define STM32_SPI_USE_SPI1 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_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_SPI3_DMA_PRIORITY 1 #define STM32_SPI_SPI1_IRQ_PRIORITY 10 -#define STM32_SPI_SPI3_IRQ_PRIORITY 10 #define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure") /* diff --git a/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/config.h index b1838b30a8..839d031ca4 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/config.h +++ b/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/config.h @@ -2,9 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once -// Fixup equivalent usages within QMK as the base board definitions only go up to high -#define PAL_STM32_OSPEED_HIGHEST PAL_STM32_OSPEED_HIGH - #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif diff --git a/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/mcuconf.h index 707134d49e..be64b04812 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_STM32_L432XC/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ #define STM32L4xx_MCUCONF #define STM32L432_MCUCONF -#define STM32L433_MCUCONF /* * HAL driver system settings. @@ -183,7 +182,6 @@ /* * 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 @@ -203,9 +201,13 @@ #define STM32_SERIAL_USE_USART1 FALSE #define STM32_SERIAL_USE_USART2 FALSE #define STM32_SERIAL_USE_LPUART1 FALSE -#define STM32_SERIAL_USART1_PRIORITY 12 -#define STM32_SERIAL_USART2_PRIORITY 12 -#define STM32_SERIAL_LPUART1_PRIORITY 12 + +/* + * SIO driver system settings. + */ +#define STM32_SIO_USE_USART1 FALSE +#define STM32_SIO_USE_USART2 FALSE +#define STM32_SIO_USE_LPUART1 FALSE /* * SPI driver system settings. diff --git a/platforms/chibios/boards/GENERIC_STM32_L433XC/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_L433XC/configs/config.h index fc9055ccfb..d67de4cfe2 100644 --- a/platforms/chibios/boards/GENERIC_STM32_L433XC/configs/config.h +++ b/platforms/chibios/boards/GENERIC_STM32_L433XC/configs/config.h @@ -18,8 +18,6 @@ /* It is chip dependent, the correct number can be looked up by checking against ST's application note AN2606. */ -#define PAL_STM32_OSPEED_HIGHEST PAL_STM32_OSPEED_HIGH - #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif diff --git a/platforms/chibios/boards/QMK_PROTON_C/configs/chconf.h b/platforms/chibios/boards/QMK_PROTON_C/configs/chconf.h index f812332960..cc10304a3f 100644 --- a/platforms/chibios/boards/QMK_PROTON_C/configs/chconf.h +++ b/platforms/chibios/boards/QMK_PROTON_C/configs/chconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,7 +29,27 @@ #define CHCONF_H #define _CHIBIOS_RT_CONF_ -#define _CHIBIOS_RT_CONF_VER_6_1_ +#define _CHIBIOS_RT_CONF_VER_7_0_ + +/*===========================================================================*/ +/** + * @name System settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Handling of instances. + * @note If enabled then threads assigned to various instances can + * interact each other using the same synchronization objects. + * If disabled then each OS instance is a separate world, no + * direct interactions are handled by the OS. + */ +#if !defined(CH_CFG_SMP_MODE) +#define CH_CFG_SMP_MODE FALSE +#endif + +/** @} */ /*===========================================================================*/ /** @@ -161,6 +181,16 @@ #endif /** + * @brief Time Stamps APIs. + * @details If enabled then the time stamps APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_TIMESTAMP) +#define CH_CFG_USE_TIMESTAMP TRUE +#endif + +/** * @brief Threads registry APIs. * @details If enabled then the registry APIs are included in the kernel. * @@ -631,7 +661,7 @@ * @details User fields added to the end of the @p ch_system_t structure. */ #define CH_CFG_SYSTEM_EXTRA_FIELDS \ - /* Add threads custom fields here.*/ + /* Add system custom fields here.*/ /** * @brief System initialization hook. @@ -639,7 +669,23 @@ * just before interrupts are enabled globally. */ #define CH_CFG_SYSTEM_INIT_HOOK() { \ - /* Add threads initialization code here.*/ \ + /* Add system initialization code here.*/ \ +} + +/** + * @brief OS instance structure extension. + * @details User fields added to the end of the @p os_instance_t structure. + */ +#define CH_CFG_OS_INSTANCE_EXTRA_FIELDS \ + /* Add OS instance custom fields here.*/ + +/** + * @brief OS instance initialization hook. + * + * @param[in] oip pointer to the @p os_instance_t structure + */ +#define CH_CFG_OS_INSTANCE_INIT_HOOK(oip) { \ + /* Add OS instance initialization code here.*/ \ } /** @@ -655,6 +701,8 @@ * * @note It is invoked from within @p _thread_init() and implicitly from all * the threads creation APIs. + * + * @param[in] tp pointer to the @p thread_t structure */ #define CH_CFG_THREAD_INIT_HOOK(tp) { \ /* Add threads initialization code here.*/ \ @@ -663,6 +711,8 @@ /** * @brief Threads finalization hook. * @details User finalization code added to the @p chThdExit() API. + * + * @param[in] tp pointer to the @p thread_t structure */ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \ /* Add threads finalization code here.*/ \ @@ -671,6 +721,9 @@ /** * @brief Context switch hook. * @details This hook is invoked just before switching between threads. + * + * @param[in] ntp thread being switched in + * @param[in] otp thread being switched out */ #define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ /* Context switch code here.*/ \ @@ -745,6 +798,14 @@ /* Trace code here.*/ \ } +/** + * @brief Runtime Faults Collection Unit hook. + * @details This hook is invoked each time new faults are collected and stored. + */ +#define CH_CFG_RUNTIME_FAULTS_HOOK(mask) { \ + /* Faults handling code here.*/ \ +} + /** @} */ /*===========================================================================*/ diff --git a/platforms/chibios/boards/QMK_PROTON_C/configs/halconf.h b/platforms/chibios/boards/QMK_PROTON_C/configs/halconf.h index d7a639a6d0..8367328a04 100644 --- a/platforms/chibios/boards/QMK_PROTON_C/configs/halconf.h +++ b/platforms/chibios/boards/QMK_PROTON_C/configs/halconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ #define HALCONF_H #define _CHIBIOS_HAL_CONF_ -#define _CHIBIOS_HAL_CONF_VER_7_1_ +#define _CHIBIOS_HAL_CONF_VER_8_0_ #include <mcuconf.h> @@ -416,6 +416,26 @@ #endif /*===========================================================================*/ +/* SIO driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SIO_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SIO_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Support for thread synchronization API. + */ +#if !defined(SIO_USE_SYNCHRONIZATION) || defined(__DOXYGEN__) +#define SIO_USE_SYNCHRONIZATION TRUE +#endif + +/*===========================================================================*/ /* SERIAL_USB driver related setting. */ /*===========================================================================*/ @@ -451,11 +471,10 @@ #endif /** - * @brief Enables circular transfers APIs. - * @note Disabling this option saves both code and data space. + * @brief Inserts an assertion on function errors before returning. */ -#if !defined(SPI_USE_CIRCULAR) || defined(__DOXYGEN__) -#define SPI_USE_CIRCULAR FALSE +#if !defined(SPI_USE_ASSERT_ON_ERROR) || defined(__DOXYGEN__) +#define SPI_USE_ASSERT_ON_ERROR TRUE #endif /** diff --git a/platforms/chibios/boards/QMK_PROTON_C/configs/mcuconf.h b/platforms/chibios/boards/QMK_PROTON_C/configs/mcuconf.h index 4d7b586c08..cab4c29cf6 100644 --- a/platforms/chibios/boards/QMK_PROTON_C/configs/mcuconf.h +++ b/platforms/chibios/boards/QMK_PROTON_C/configs/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -186,7 +186,6 @@ /* * 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 TRUE diff --git a/platforms/chibios/boards/common/configs/chconf.h b/platforms/chibios/boards/common/configs/chconf.h index 18ad609ca1..5db836e37c 100644 --- a/platforms/chibios/boards/common/configs/chconf.h +++ b/platforms/chibios/boards/common/configs/chconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,7 +29,27 @@ #define CHCONF_H #define _CHIBIOS_RT_CONF_ -#define _CHIBIOS_RT_CONF_VER_6_1_ +#define _CHIBIOS_RT_CONF_VER_7_0_ + +/*===========================================================================*/ +/** + * @name System settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Handling of instances. + * @note If enabled then threads assigned to various instances can + * interact each other using the same synchronization objects. + * If disabled then each OS instance is a separate world, no + * direct interactions are handled by the OS. + */ +#if !defined(CH_CFG_SMP_MODE) +#define CH_CFG_SMP_MODE FALSE +#endif + +/** @} */ /*===========================================================================*/ /** @@ -161,6 +181,16 @@ #endif /** + * @brief Time Stamps APIs. + * @details If enabled then the time stamps APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_TIMESTAMP) +#define CH_CFG_USE_TIMESTAMP TRUE +#endif + +/** * @brief Threads registry APIs. * @details If enabled then the registry APIs are included in the kernel. * @@ -631,7 +661,7 @@ * @details User fields added to the end of the @p ch_system_t structure. */ #define CH_CFG_SYSTEM_EXTRA_FIELDS \ - /* Add threads custom fields here.*/ + /* Add system custom fields here.*/ /** * @brief System initialization hook. @@ -639,7 +669,23 @@ * just before interrupts are enabled globally. */ #define CH_CFG_SYSTEM_INIT_HOOK() { \ - /* Add threads initialization code here.*/ \ + /* Add system initialization code here.*/ \ +} + +/** + * @brief OS instance structure extension. + * @details User fields added to the end of the @p os_instance_t structure. + */ +#define CH_CFG_OS_INSTANCE_EXTRA_FIELDS \ + /* Add OS instance custom fields here.*/ + +/** + * @brief OS instance initialization hook. + * + * @param[in] oip pointer to the @p os_instance_t structure + */ +#define CH_CFG_OS_INSTANCE_INIT_HOOK(oip) { \ + /* Add OS instance initialization code here.*/ \ } /** @@ -655,6 +701,8 @@ * * @note It is invoked from within @p _thread_init() and implicitly from all * the threads creation APIs. + * + * @param[in] tp pointer to the @p thread_t structure */ #define CH_CFG_THREAD_INIT_HOOK(tp) { \ /* Add threads initialization code here.*/ \ @@ -663,6 +711,8 @@ /** * @brief Threads finalization hook. * @details User finalization code added to the @p chThdExit() API. + * + * @param[in] tp pointer to the @p thread_t structure */ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \ /* Add threads finalization code here.*/ \ @@ -671,6 +721,9 @@ /** * @brief Context switch hook. * @details This hook is invoked just before switching between threads. + * + * @param[in] ntp thread being switched in + * @param[in] otp thread being switched out */ #define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ /* Context switch code here.*/ \ @@ -745,6 +798,14 @@ /* Trace code here.*/ \ } +/** + * @brief Runtime Faults Collection Unit hook. + * @details This hook is invoked each time new faults are collected and stored. + */ +#define CH_CFG_RUNTIME_FAULTS_HOOK(mask) { \ + /* Faults handling code here.*/ \ +} + /** @} */ /*===========================================================================*/ diff --git a/platforms/chibios/boards/common/configs/halconf.h b/platforms/chibios/boards/common/configs/halconf.h index c80f67ee27..1805a77438 100644 --- a/platforms/chibios/boards/common/configs/halconf.h +++ b/platforms/chibios/boards/common/configs/halconf.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ #define HALCONF_H #define _CHIBIOS_HAL_CONF_ -#define _CHIBIOS_HAL_CONF_VER_7_1_ +#define _CHIBIOS_HAL_CONF_VER_8_0_ #include <mcuconf.h> @@ -416,6 +416,26 @@ #endif /*===========================================================================*/ +/* SIO driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SIO_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SIO_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Support for thread synchronization API. + */ +#if !defined(SIO_USE_SYNCHRONIZATION) || defined(__DOXYGEN__) +#define SIO_USE_SYNCHRONIZATION TRUE +#endif + +/*===========================================================================*/ /* SERIAL_USB driver related setting. */ /*===========================================================================*/ @@ -451,11 +471,10 @@ #endif /** - * @brief Enables circular transfers APIs. - * @note Disabling this option saves both code and data space. + * @brief Inserts an assertion on function errors before returning. */ -#if !defined(SPI_USE_CIRCULAR) || defined(__DOXYGEN__) -#define SPI_USE_CIRCULAR FALSE +#if !defined(SPI_USE_ASSERT_ON_ERROR) || defined(__DOXYGEN__) +#define SPI_USE_ASSERT_ON_ERROR TRUE #endif /** diff --git a/platforms/chibios/drivers/ws2812_spi.c b/platforms/chibios/drivers/ws2812_spi.c index 76191db165..01d8148875 100644 --- a/platforms/chibios/drivers/ws2812_spi.c +++ b/platforms/chibios/drivers/ws2812_spi.c @@ -139,7 +139,33 @@ void ws2812_init(void) { #endif // WS2812_SPI_SCK_PIN // TODO: more dynamic baudrate - static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR_CR1_BR_X}; + static const SPIConfig spicfg = { +#ifndef HAL_LLD_SELECT_SPI_V2 +// HAL_SPI_V1 +# if SPI_SUPPORTS_CIRCULAR == TRUE + WS2812_SPI_BUFFER_MODE, +# endif + NULL, // end_cb + PAL_PORT(RGB_DI_PIN), + PAL_PAD(RGB_DI_PIN), + WS2812_SPI_DIVISOR_CR1_BR_X, + 0 +#else + // HAL_SPI_V2 +# if SPI_SUPPORTS_CIRCULAR == TRUE + WS2812_SPI_BUFFER_MODE, +# endif +# if SPI_SUPPORTS_SLAVE_MODE == TRUE + false, +# endif + NULL, // data_cb + NULL, // error_cb + PAL_PORT(RGB_DI_PIN), + PAL_PAD(RGB_DI_PIN), + WS2812_SPI_DIVISOR_CR1_BR_X, + 0 +#endif + }; spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk index 6ee53172d2..a91ef2cf35 100644 --- a/platforms/chibios/flash.mk +++ b/platforms/chibios/flash.mk @@ -40,6 +40,18 @@ endef dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter $(call EXEC_DFU_UTIL) +define EXEC_UF2_UTIL_DEPLOY + if ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; then \ + printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\ + sleep $(BOOTLOADER_RETRY_TIME) ;\ + while ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; do \ + printf "." ;\ + sleep $(BOOTLOADER_RETRY_TIME) ;\ + done ;\ + printf "\n" ;\ + fi +endef + # TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS # within the emulated eeprom via dfu-util or another tool ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-left)) @@ -90,6 +102,8 @@ ifneq ($(strip $(PROGRAM_CMD)),) $(UNSYNC_OUTPUT_CMD) && $(PROGRAM_CMD) else ifeq ($(strip $(BOOTLOADER)),kiibohd) $(UNSYNC_OUTPUT_CMD) && $(call EXEC_DFU_UTIL) +else ifeq ($(strip $(BOOTLOADER)),tinyuf2) + $(UNSYNC_OUTPUT_CMD) && $(call EXEC_UF2_UTIL_DEPLOY) else ifeq ($(strip $(MCU_FAMILY)),KINETIS) $(UNSYNC_OUTPUT_CMD) && $(call EXEC_TEENSY) else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062) diff --git a/platforms/chibios/platform.mk b/platforms/chibios/platform.mk index 6fd1fd83f5..91dd0479bc 100644 --- a/platforms/chibios/platform.mk +++ b/platforms/chibios/platform.mk @@ -39,7 +39,6 @@ ifeq ($(strip $(MCU)), risc-v) STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/RISCV-ECLIC/compilers/GCC/mk/startup_$(MCU_STARTUP).mk PORT_V = $(CHIBIOS_CONTRIB)/os/common/ports/RISCV-ECLIC/compilers/GCC/mk/port.mk RULESPATH = $(CHIBIOS_CONTRIB)/os/common/startup/RISCV-ECLIC/compilers/GCC - PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/GD/GD32VF103/platform.mk else # ARM Support CHIBIOS_PORT ?= @@ -82,10 +81,15 @@ ifeq ("$(PLATFORM_NAME)","") PLATFORM_NAME = platform endif +# If no MCU port name was specified, use the family instead +ifeq ("$(MCU_PORT_NAME)","") + MCU_PORT_NAME = $(MCU_FAMILY) +endif + ifeq ("$(wildcard $(PLATFORM_MK))","") - PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk + PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES)/$(PLATFORM_NAME).mk ifeq ("$(wildcard $(PLATFORM_MK))","") - PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk + PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES)/$(PLATFORM_NAME).mk endif endif diff --git a/platforms/chibios/timer.c b/platforms/chibios/timer.c index e3bdfdcc37..5e01ea6372 100644 --- a/platforms/chibios/timer.c +++ b/platforms/chibios/timer.c @@ -40,7 +40,7 @@ static virtual_timer_t update_timer; # define UPDATE_INTERVAL (((sysinterval_t)1) << (CH_CFG_ST_RESOLUTION - 1)) // VT callback function to keep the overflow bits of the system tick counter updated. -static void update_fn(void *arg) { +static void update_fn(struct ch_virtual_timer *timer, void *arg) { (void)arg; chSysLockFromISR(); get_system_time_ticks(); diff --git a/platforms/chibios/wait.c b/platforms/chibios/wait.c index 56fd6ffcec..88cb5e6d54 100644 --- a/platforms/chibios/wait.c +++ b/platforms/chibios/wait.c @@ -31,7 +31,7 @@ void wait_us(uint16_t duration) { * Only use this timer on the main thread; * other threads need to use their own timer. */ - if (chThdGetSelfX() == &ch.mainthread && duration < (1ULL << (sizeof(gptcnt_t) * 8))) { + if (chThdGetSelfX() == &(currcore->mainthread) && duration < (1ULL << (sizeof(gptcnt_t) * 8))) { gptStart(&WAIT_US_TIMER, &gpt_cfg); gptPolledDelay(&WAIT_US_TIMER, duration); } else { diff --git a/platforms/pin_defs.h b/platforms/pin_defs.h index ea730138f2..341fe89b6e 100644 --- a/platforms/pin_defs.h +++ b/platforms/pin_defs.h @@ -18,6 +18,6 @@ // useful for direct pin mapping #define NO_PIN (pin_t)(~0) -#if __has_include_next("pin_defs.h") -# include_next "pin_defs.h" /* Include the platforms pin_defs.h */ +#if __has_include("_pin_defs.h") +# include "_pin_defs.h" /* Include the platforms pin defs */ #endif diff --git a/quantum/action.c b/quantum/action.c index 3efed443a3..ef059f0e2a 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -14,9 +14,18 @@ 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 <limits.h> + +#ifdef DEBUG_ACTION +# include "debug.h" +#else +# include "nodebug.h" +#endif + #include "host.h" #include "keycode.h" #include "keyboard.h" +#include "keymap.h" #include "mousekey.h" #include "programmable_button.h" #include "command.h" @@ -32,12 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include "backlight.h" #endif -#ifdef DEBUG_ACTION -# include "debug.h" -#else -# include "nodebug.h" -#endif - #ifdef POINTING_DEVICE_ENABLE # include "pointing_device.h" #endif @@ -89,6 +92,7 @@ void action_exec(keyevent_t event) { } #ifdef SWAP_HANDS_ENABLE + // Swap hands handles both keys and encoders, if ENCODER_MAP_ENABLE is defined. if (!IS_NOEVENT(event)) { process_hand_swap(&event); } @@ -97,7 +101,7 @@ void action_exec(keyevent_t event) { keyrecord_t record = {.event = event}; #ifndef NO_ACTION_ONESHOT - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) if (has_oneshot_layer_timed_out()) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); @@ -136,27 +140,65 @@ void action_exec(keyevent_t event) { } #ifdef SWAP_HANDS_ENABLE +extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS]; +# ifdef ENCODER_MAP_ENABLE +extern const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS]; +# endif // ENCODER_MAP_ENABLE + bool swap_hands = false; bool swap_held = false; +bool should_swap_hands(size_t index, uint8_t *swap_state, bool pressed) { + size_t array_index = index / (CHAR_BIT); + size_t bit_index = index % (CHAR_BIT); + uint8_t bit_val = 1 << bit_index; + bool do_swap = pressed ? swap_hands : swap_state[array_index] & bit_val; + return do_swap; +} + +void set_swap_hands_state(size_t index, uint8_t *swap_state, bool on) { + size_t array_index = index / (CHAR_BIT); + size_t bit_index = index % (CHAR_BIT); + uint8_t bit_val = 1 << bit_index; + if (on) { + swap_state[array_index] |= bit_val; + } else { + swap_state[array_index] &= ~bit_val; + } +} + /** \brief Process Hand Swap * * FIXME: Needs documentation. */ void process_hand_swap(keyevent_t *event) { - static swap_state_row_t swap_state[MATRIX_ROWS]; - - keypos_t pos = event->key; - swap_state_row_t col_bit = (swap_state_row_t)1 << pos.col; - bool do_swap = event->pressed ? swap_hands : swap_state[pos.row] & (col_bit); - - if (do_swap) { - event->key.row = pgm_read_byte(&hand_swap_config[pos.row][pos.col].row); - event->key.col = pgm_read_byte(&hand_swap_config[pos.row][pos.col].col); - swap_state[pos.row] |= col_bit; - } else { - swap_state[pos.row] &= ~(col_bit); + keypos_t pos = event->key; + if (pos.row < MATRIX_ROWS && pos.col < MATRIX_COLS) { + static uint8_t matrix_swap_state[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)]; + size_t index = (size_t)(pos.row * MATRIX_COLS) + pos.col; + bool do_swap = should_swap_hands(index, matrix_swap_state, event->pressed); + if (do_swap) { + event->key.row = pgm_read_byte(&hand_swap_config[pos.row][pos.col].row); + event->key.col = pgm_read_byte(&hand_swap_config[pos.row][pos.col].col); + set_swap_hands_state(index, matrix_swap_state, true); + } else { + set_swap_hands_state(index, matrix_swap_state, false); + } + } +# ifdef ENCODER_MAP_ENABLE + else if (pos.row == KEYLOC_ENCODER_CW || pos.row == KEYLOC_ENCODER_CCW) { + static uint8_t encoder_swap_state[((NUM_ENCODERS) + (CHAR_BIT)-1) / (CHAR_BIT)]; + size_t index = pos.col; + bool do_swap = should_swap_hands(index, encoder_swap_state, event->pressed); + if (do_swap) { + event->key.row = pos.row; + event->key.col = pgm_read_byte(&encoder_hand_swap_config[pos.col]); + set_swap_hands_state(index, encoder_swap_state, true); + } else { + set_swap_hands_state(index, encoder_swap_state, false); + } } +# endif // ENCODER_MAP_ENABLE } #endif @@ -216,7 +258,7 @@ void process_record(keyrecord_t *record) { if (!process_record_quantum(record)) { #ifndef NO_ACTION_ONESHOT - if (is_oneshot_layer_active() && record->event.pressed && !keymap_config.oneshot_disable) { + if (is_oneshot_layer_active() && record->event.pressed && keymap_config.oneshot_enable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); } #endif @@ -281,7 +323,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifdef SWAP_HANDS_ENABLE && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) # endif - && !keymap_config.oneshot_disable) { + && keymap_config.oneshot_enable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); } @@ -325,7 +367,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case MODS_ONESHOT: // Oneshot modifier - if (keymap_config.oneshot_disable) { + if (!keymap_config.oneshot_enable) { if (event.pressed) { if (mods) { if (IS_MOD(action.key.code) || action.key.code == KC_NO) { @@ -571,7 +613,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case OP_ONESHOT: // Oneshot modifier - if (keymap_config.oneshot_disable) { + if (!keymap_config.oneshot_enable) { if (event.pressed) { layer_on(action.layer_tap.val); } else { diff --git a/quantum/action_layer.c b/quantum/action_layer.c index e20eedee40..473e0e948d 100644 --- a/quantum/action_layer.c +++ b/quantum/action_layer.c @@ -1,8 +1,5 @@ +#include <limits.h> #include <stdint.h> -#include "keyboard.h" -#include "action.h" -#include "util.h" -#include "action_layer.h" #ifdef DEBUG_ACTION # include "debug.h" @@ -10,6 +7,12 @@ # include "nodebug.h" #endif +#include "keyboard.h" +#include "keymap.h" +#include "action.h" +#include "util.h" +#include "action_layer.h" + /** \brief Default Layer State */ layer_state_t default_layer_state = 0; @@ -223,19 +226,20 @@ void layer_debug(void) { /** \brief source layer cache */ -uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS + 7) / 8][MAX_LAYER_BITS] = {{0}}; +uint8_t source_layers_cache[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)][MAX_LAYER_BITS] = {{0}}; +# ifdef ENCODER_MAP_ENABLE +uint8_t encoder_source_layers_cache[(NUM_ENCODERS + (CHAR_BIT)-1) / (CHAR_BIT)][MAX_LAYER_BITS] = {{0}}; +# endif // ENCODER_MAP_ENABLE -/** \brief update source layers cache +/** \brief update source layers cache impl * - * Updates the cached keys when changing layers + * Updates the supplied cache when changing layers */ -void update_source_layers_cache(keypos_t key, uint8_t layer) { - const uint8_t key_number = key.col + (key.row * MATRIX_COLS); - const uint8_t storage_row = key_number / 8; - const uint8_t storage_bit = key_number % 8; - +void update_source_layers_cache_impl(uint8_t layer, uint16_t entry_number, uint8_t cache[][MAX_LAYER_BITS]) { + const uint16_t storage_idx = entry_number / (CHAR_BIT); + const uint8_t storage_bit = entry_number % (CHAR_BIT); for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { - source_layers_cache[storage_row][bit_number] ^= (-((layer & (1U << bit_number)) != 0) ^ source_layers_cache[storage_row][bit_number]) & (1U << storage_bit); + cache[storage_idx][bit_number] ^= (-((layer & (1U << bit_number)) != 0) ^ cache[storage_idx][bit_number]) & (1U << storage_bit); } } @@ -243,18 +247,52 @@ void update_source_layers_cache(keypos_t key, uint8_t layer) { * * reads the cached keys stored when the layer was changed */ -uint8_t read_source_layers_cache(keypos_t key) { - const uint8_t key_number = key.col + (key.row * MATRIX_COLS); - const uint8_t storage_row = key_number / 8; - const uint8_t storage_bit = key_number % 8; - uint8_t layer = 0; +uint8_t read_source_layers_cache_impl(uint16_t entry_number, uint8_t cache[][MAX_LAYER_BITS]) { + const uint16_t storage_idx = entry_number / (CHAR_BIT); + const uint8_t storage_bit = entry_number % (CHAR_BIT); + uint8_t layer = 0; for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { - layer |= ((source_layers_cache[storage_row][bit_number] & (1U << storage_bit)) != 0) << bit_number; + layer |= ((cache[storage_idx][bit_number] & (1U << storage_bit)) != 0) << bit_number; } return layer; } + +/** \brief update encoder source layers cache + * + * Updates the cached encoders when changing layers + */ +void update_source_layers_cache(keypos_t key, uint8_t layer) { + if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { + const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col; + update_source_layers_cache_impl(layer, entry_number, source_layers_cache); + } +# ifdef ENCODER_MAP_ENABLE + else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) { + const uint16_t entry_number = key.col; + update_source_layers_cache_impl(layer, entry_number, encoder_source_layers_cache); + } +# endif // ENCODER_MAP_ENABLE +} + +/** \brief read source layers cache + * + * reads the cached keys stored when the layer was changed + */ +uint8_t read_source_layers_cache(keypos_t key) { + if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { + const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col; + return read_source_layers_cache_impl(entry_number, source_layers_cache); + } +# ifdef ENCODER_MAP_ENABLE + else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) { + const uint16_t entry_number = key.col; + return read_source_layers_cache_impl(entry_number, encoder_source_layers_cache); + } +# endif // ENCODER_MAP_ENABLE + return 0; +} #endif /** \brief Store or get action (FIXME: Needs better summary) diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index 6f8b4f8c56..e436619428 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c @@ -1,10 +1,5 @@ #include <stdint.h> #include <stdbool.h> -#include "action.h" -#include "action_layer.h" -#include "action_tapping.h" -#include "keycode.h" -#include "timer.h" #ifdef DEBUG_ACTION # include "debug.h" @@ -12,6 +7,12 @@ # include "nodebug.h" #endif +#include "action.h" +#include "action_layer.h" +#include "action_tapping.h" +#include "keycode.h" +#include "timer.h" + #ifndef NO_ACTION_TAPPING # define IS_TAPPING() !IS_NOEVENT(tapping_key.event) diff --git a/quantum/action_util.c b/quantum/action_util.c index 4ea0bf61fb..738410a4ac 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -155,7 +155,7 @@ void clear_oneshot_swaphands(void) { * FIXME: needs doc */ void set_oneshot_layer(uint8_t layer, uint8_t state) { - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { oneshot_layer_data = layer << 3 | state; layer_on(layer); # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) @@ -184,7 +184,7 @@ void reset_oneshot_layer(void) { void clear_oneshot_layer_state(oneshot_fullfillment_t state) { uint8_t start_state = oneshot_layer_data; oneshot_layer_data &= ~state; - if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) && !keymap_config.oneshot_disable) { + if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) && keymap_config.oneshot_enable) { layer_off(get_oneshot_layer()); reset_oneshot_layer(); } @@ -202,8 +202,8 @@ bool is_oneshot_layer_active(void) { * FIXME: needs doc */ void oneshot_set(bool active) { - if (keymap_config.oneshot_disable != active) { - keymap_config.oneshot_disable = active; + if (keymap_config.oneshot_enable != active) { + keymap_config.oneshot_enable = active; eeconfig_update_keymap(keymap_config.raw); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); dprintf("Oneshot: active: %d\n", active); @@ -215,7 +215,7 @@ void oneshot_set(bool active) { * FIXME: needs doc */ void oneshot_toggle(void) { - oneshot_set(!keymap_config.oneshot_disable); + oneshot_set(!keymap_config.oneshot_enable); } /** \brief enable oneshot @@ -235,7 +235,7 @@ void oneshot_disable(void) { } bool is_oneshot_enabled(void) { - return keymap_config.oneshot_disable; + return keymap_config.oneshot_enable; } #endif @@ -413,7 +413,7 @@ void del_oneshot_mods(uint8_t mods) { * FIXME: needs doc */ void set_oneshot_mods(uint8_t mods) { - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { if (oneshot_mods != mods) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_time = timer_read(); diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index f070375ff3..fc1c55784d 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -21,6 +21,12 @@ #include "dynamic_keymap.h" #include "via.h" // for default VIA_EEPROM_ADDR_END +#ifdef ENCODER_ENABLE +# include "encoder.h" +#else +# define NUM_ENCODERS 0 +#endif + #ifndef DYNAMIC_KEYMAP_LAYER_COUNT # define DYNAMIC_KEYMAP_LAYER_COUNT 4 #endif @@ -58,20 +64,28 @@ # endif #endif -// Dynamic macro starts after dynamic keymaps -#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR -# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2)) +// Dynamic encoders starts after dynamic keymaps +#ifndef DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR +# define DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2)) #endif +// Dynamic macro starts after dynamic encoders, but only when using ENCODER_MAP +#ifdef ENCODER_MAP_ENABLE +# ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR +# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * NUM_ENCODERS * 2 * 2)) +# endif // DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR +#else // ENCODER_MAP_ENABLE +# ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR +# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR) +# endif // DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR +#endif // ENCODER_MAP_ENABLE + // Sanity check that dynamic keymaps fit in available EEPROM // If there's not 100 bytes available for macros, then something is wrong. // The keyboard should override DYNAMIC_KEYMAP_LAYER_COUNT to reduce it, // or DYNAMIC_KEYMAP_EEPROM_MAX_ADDR to increase it, *only if* the microcontroller has // more than the default. -#if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR < 100 -# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) " < 100" -# error Dynamic keymaps are configured to use more EEPROM than is available. -#endif +_Static_assert((DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) - (DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) >= 100, "Dynamic keymaps are configured to use more EEPROM than is available."); // Dynamic macros are stored after the keymaps and use what is available // up to and including DYNAMIC_KEYMAP_EEPROM_MAX_ADDR. @@ -89,6 +103,7 @@ void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t c } uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column) { + if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || row >= MATRIX_ROWS || column >= MATRIX_COLS) return KC_NO; void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column); // Big endian, so we can read/write EEPROM directly from host if we want uint16_t keycode = eeprom_read_byte(address) << 8; @@ -97,12 +112,36 @@ uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column) } void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode) { + if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || row >= MATRIX_ROWS || column >= MATRIX_COLS) return; void *address = dynamic_keymap_key_to_eeprom_address(layer, row, column); // Big endian, so we can read/write EEPROM directly from host if we want eeprom_update_byte(address, (uint8_t)(keycode >> 8)); eeprom_update_byte(address + 1, (uint8_t)(keycode & 0xFF)); } +#ifdef ENCODER_MAP_ENABLE +void *dynamic_keymap_encoder_to_eeprom_address(uint8_t layer, uint8_t encoder_id) { + return ((void *)DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR) + (layer * NUM_ENCODERS * 2 * 2) + (encoder_id * 2 * 2); +} + +uint16_t dynamic_keymap_get_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise) { + if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || encoder_id >= NUM_ENCODERS) return KC_NO; + void *address = dynamic_keymap_encoder_to_eeprom_address(layer, encoder_id); + // Big endian, so we can read/write EEPROM directly from host if we want + uint16_t keycode = ((uint16_t)eeprom_read_byte(address + (clockwise ? 0 : 2))) << 8; + keycode |= eeprom_read_byte(address + (clockwise ? 0 : 2) + 1); + return keycode; +} + +void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise, uint16_t keycode) { + if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || encoder_id >= NUM_ENCODERS) return; + void *address = dynamic_keymap_encoder_to_eeprom_address(layer, encoder_id); + // Big endian, so we can read/write EEPROM directly from host if we want + eeprom_update_byte(address + (clockwise ? 0 : 2), (uint8_t)(keycode >> 8)); + eeprom_update_byte(address + (clockwise ? 0 : 2) + 1, (uint8_t)(keycode & 0xFF)); +} +#endif // ENCODER_MAP_ENABLE + void dynamic_keymap_reset(void) { // Reset the keymaps in EEPROM to what is in flash. // All keyboards using dynamic keymaps should define a layout @@ -113,6 +152,12 @@ void dynamic_keymap_reset(void) { dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column])); } } +#ifdef ENCODER_MAP_ENABLE + for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) { + dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0])); + dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1])); + } +#endif // ENCODER_MAP_ENABLE } } @@ -148,9 +193,15 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) { uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { return dynamic_keymap_get_keycode(layer, key.row, key.col); - } else { - return KC_NO; } +#ifdef ENCODER_MAP_ENABLE + else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) { + return dynamic_keymap_get_encoder(layer, key.col, true); + } else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) { + return dynamic_keymap_get_encoder(layer, key.col, false); + } +#endif // ENCODER_MAP_ENABLE + return KC_NO; } uint8_t dynamic_keymap_macro_get_count(void) { diff --git a/quantum/dynamic_keymap.h b/quantum/dynamic_keymap.h index 55676172b6..459b48d07a 100644 --- a/quantum/dynamic_keymap.h +++ b/quantum/dynamic_keymap.h @@ -22,7 +22,11 @@ uint8_t dynamic_keymap_get_layer_count(void); void * dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column); uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column); void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode); -void dynamic_keymap_reset(void); +#ifdef ENCODER_MAP_ENABLE +uint16_t dynamic_keymap_get_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise); +void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwise, uint16_t keycode); +#endif // ENCODER_MAP_ENABLE +void dynamic_keymap_reset(void); // These get/set the keycodes as stored in the EEPROM buffer // Data is big-endian 16-bit values (the keycodes) // Order is by layer/row/column diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 14cd5887f4..0ff9996ca4 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -46,7 +46,7 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); default_layer_state = 0; eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); - eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); + eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4); eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index f3cd1867ab..565a0dbe5b 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h @@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdbool.h> #ifndef EECONFIG_MAGIC_NUMBER -# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE9 // When changing, decrement this value to avoid future re-init issues +# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE8 // When changing, decrement this value to avoid future re-init issues #endif #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF diff --git a/quantum/encoder.c b/quantum/encoder.c index 438c7d8564..105bed0147 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -23,6 +23,10 @@ // for memcpy #include <string.h> +#ifndef ENCODER_MAP_KEY_DELAY +# define ENCODER_MAP_KEY_DELAY 2 +#endif + #if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) # define ENCODER_RESOLUTION 4 #endif @@ -31,11 +35,13 @@ # error "No encoder pads defined by ENCODERS_PAD_A and ENCODERS_PAD_B" #endif -#define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a) / sizeof(pin_t)) -static pin_t encoders_pad_a[] = ENCODERS_PAD_A; -static pin_t encoders_pad_b[] = ENCODERS_PAD_B; +extern volatile bool isLeftHand; + +static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_A; +static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_B; + #ifdef ENCODER_RESOLUTIONS -static uint8_t encoder_resolutions[] = ENCODER_RESOLUTIONS; +static uint8_t encoder_resolutions[NUM_ENCODERS] = ENCODER_RESOLUTIONS; #endif #ifndef ENCODER_DIRECTION_FLIP @@ -47,18 +53,20 @@ static uint8_t encoder_resolutions[] = ENCODER_RESOLUTIONS; #endif static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; -static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; -static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0}; +static uint8_t encoder_state[NUM_ENCODERS] = {0}; +static int8_t encoder_pulses[NUM_ENCODERS] = {0}; +// encoder counts +static uint8_t thisCount; #ifdef SPLIT_KEYBOARD -// right half encoders come over as second set of encoders -static uint8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; -// row offsets for each hand +// encoder offsets for each hand static uint8_t thisHand, thatHand; -#else -static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; +// encoder counts for each hand +static uint8_t thatCount; #endif +static uint8_t encoder_value[NUM_ENCODERS] = {0}; + __attribute__((weak)) void encoder_wait_pullup_charge(void) { wait_us(100); } @@ -72,46 +80,83 @@ __attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { } void encoder_init(void) { +#ifdef SPLIT_KEYBOARD + thisHand = isLeftHand ? 0 : NUM_ENCODERS_LEFT; + thatHand = NUM_ENCODERS_LEFT - thisHand; + thisCount = isLeftHand ? NUM_ENCODERS_LEFT : NUM_ENCODERS_RIGHT; + thatCount = isLeftHand ? NUM_ENCODERS_RIGHT : NUM_ENCODERS_LEFT; +#else // SPLIT_KEYBOARD + thisCount = NUM_ENCODERS; +#endif + +#ifdef ENCODER_TESTS + // Annoying that we have to clear out values during initialisation here, but + // because all the arrays are static locals, rerunning tests in the same + // executable doesn't reset any of these. Kinda crappy having test-only code + // here, but it's the simplest solution. + memset(encoder_value, 0, sizeof(encoder_value)); + memset(encoder_state, 0, sizeof(encoder_state)); + memset(encoder_pulses, 0, sizeof(encoder_pulses)); + static const pin_t encoders_pad_a_left[] = ENCODERS_PAD_A; + static const pin_t encoders_pad_b_left[] = ENCODERS_PAD_B; + for (uint8_t i = 0; i < thisCount; i++) { + encoders_pad_a[i] = encoders_pad_a_left[i]; + encoders_pad_b[i] = encoders_pad_b_left[i]; + } +#endif + #if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT) + // Re-initialise the pads if it's the right-hand side if (!isLeftHand) { - const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT; - const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT; -# if defined(ENCODER_RESOLUTIONS_RIGHT) - const uint8_t encoder_resolutions_right[] = ENCODER_RESOLUTIONS_RIGHT; -# endif - for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { + static const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT; + static const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT; + for (uint8_t i = 0; i < thisCount; i++) { encoders_pad_a[i] = encoders_pad_a_right[i]; encoders_pad_b[i] = encoders_pad_b_right[i]; -# if defined(ENCODER_RESOLUTIONS_RIGHT) - encoder_resolutions[i] = encoder_resolutions_right[i]; -# endif } } -#endif +#endif // defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT) - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + // Encoder resolutions is handled purely master-side, so concatenate the two arrays +#if defined(SPLIT_KEYBOARD) && defined(ENCODER_RESOLUTIONS) +# if defined(ENCODER_RESOLUTIONS_RIGHT) + static const uint8_t encoder_resolutions_right[NUM_ENCODERS_RIGHT] = ENCODER_RESOLUTIONS_RIGHT; +# else // defined(ENCODER_RESOLUTIONS_RIGHT) + static const uint8_t encoder_resolutions_right[NUM_ENCODERS_RIGHT] = ENCODER_RESOLUTIONS; +# endif // defined(ENCODER_RESOLUTIONS_RIGHT) + for (uint8_t i = 0; i < NUM_ENCODERS_RIGHT; i++) { + encoder_resolutions[NUM_ENCODERS_LEFT + i] = encoder_resolutions_right[i]; + } +#endif // defined(SPLIT_KEYBOARD) && defined(ENCODER_RESOLUTIONS) + + for (uint8_t i = 0; i < thisCount; i++) { setPinInputHigh(encoders_pad_a[i]); setPinInputHigh(encoders_pad_b[i]); } encoder_wait_pullup_charge(); - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + for (uint8_t i = 0; i < thisCount; i++) { encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); } +} -#ifdef SPLIT_KEYBOARD - thisHand = isLeftHand ? 0 : NUMBER_OF_ENCODERS; - thatHand = NUMBER_OF_ENCODERS - thisHand; -#endif +#ifdef ENCODER_MAP_ENABLE +static void encoder_exec_mapping(uint8_t index, bool clockwise) { + // The delays below cater for Windows and its wonderful requirements. + action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true)); + wait_ms(ENCODER_MAP_KEY_DELAY); + action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false)); + wait_ms(ENCODER_MAP_KEY_DELAY); } +#endif // ENCODER_MAP_ENABLE static bool encoder_update(uint8_t index, uint8_t state) { bool changed = false; uint8_t i = index; #ifdef ENCODER_RESOLUTIONS - uint8_t resolution = encoder_resolutions[i]; + const uint8_t resolution = encoder_resolutions[i]; #else - uint8_t resolution = ENCODER_RESOLUTION; + const uint8_t resolution = ENCODER_RESOLUTION; #endif #ifdef SPLIT_KEYBOARD @@ -121,12 +166,20 @@ static bool encoder_update(uint8_t index, uint8_t state) { if (encoder_pulses[i] >= resolution) { encoder_value[index]++; changed = true; +#ifdef ENCODER_MAP_ENABLE + encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE); +#else // ENCODER_MAP_ENABLE encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); +#endif // ENCODER_MAP_ENABLE } if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise encoder_value[index]--; changed = true; +#ifdef ENCODER_MAP_ENABLE + encoder_exec_mapping(index, ENCODER_CLOCKWISE); +#else // ENCODER_MAP_ENABLE encoder_update_kb(index, ENCODER_CLOCKWISE); +#endif // ENCODER_MAP_ENABLE } encoder_pulses[i] %= resolution; #ifdef ENCODER_DEFAULT_POS @@ -139,10 +192,13 @@ static bool encoder_update(uint8_t index, uint8_t state) { bool encoder_read(void) { bool changed = false; - for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { - encoder_state[i] <<= 2; - encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); - changed |= encoder_update(i, encoder_state[i]); + for (uint8_t i = 0; i < thisCount; i++) { + uint8_t new_status = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); + if ((encoder_state[i] & 0x3) != new_status) { + encoder_state[i] <<= 2; + encoder_state[i] |= new_status; + changed |= encoder_update(i, encoder_state[i]); + } } return changed; } @@ -150,26 +206,34 @@ bool encoder_read(void) { #ifdef SPLIT_KEYBOARD void last_encoder_activity_trigger(void); -void encoder_state_raw(uint8_t* slave_state) { - memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); +void encoder_state_raw(uint8_t *slave_state) { + memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * thisCount); } -void encoder_update_raw(uint8_t* slave_state) { +void encoder_update_raw(uint8_t *slave_state) { bool changed = false; - for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { - uint8_t index = i + thatHand; - int8_t delta = slave_state[i] - encoder_value[index]; + for (uint8_t i = 0; i < thatCount; i++) { // Note inverted logic -- we want the opposite side + const uint8_t index = i + thatHand; + int8_t delta = slave_state[i] - encoder_value[index]; while (delta > 0) { delta--; encoder_value[index]++; changed = true; +# ifdef ENCODER_MAP_ENABLE + encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE); +# else // ENCODER_MAP_ENABLE encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); +# endif // ENCODER_MAP_ENABLE } while (delta < 0) { delta++; encoder_value[index]--; changed = true; +# ifdef ENCODER_MAP_ENABLE + encoder_exec_mapping(index, ENCODER_CLOCKWISE); +# else // ENCODER_MAP_ENABLE encoder_update_kb(index, ENCODER_CLOCKWISE); +# endif // ENCODER_MAP_ENABLE } } diff --git a/quantum/encoder.h b/quantum/encoder.h index 25dc77721d..82f95b4931 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -18,6 +18,7 @@ #pragma once #include "quantum.h" +#include "util.h" void encoder_init(void); bool encoder_read(void); @@ -26,6 +27,37 @@ bool encoder_update_kb(uint8_t index, bool clockwise); bool encoder_update_user(uint8_t index, bool clockwise); #ifdef SPLIT_KEYBOARD + void encoder_state_raw(uint8_t* slave_state); void encoder_update_raw(uint8_t* slave_state); -#endif + +# if defined(ENCODERS_PAD_A_RIGHT) +# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) +# define NUM_ENCODERS_RIGHT (sizeof(((pin_t[])ENCODERS_PAD_A_RIGHT)) / sizeof(pin_t)) +# else +# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) +# define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT +# endif +# define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT) + +#else // SPLIT_KEYBOARD + +# define NUM_ENCODERS (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) +# define NUM_ENCODERS_LEFT NUM_ENCODERS +# define NUM_ENCODERS_RIGHT 0 + +#endif // SPLIT_KEYBOARD + +#ifndef NUM_ENCODERS +# define NUM_ENCODERS 0 +# define NUM_ENCODERS_LEFT 0 +# define NUM_ENCODERS_RIGHT 0 +#endif // NUM_ENCODERS + +#define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT) + +#ifdef ENCODER_MAP_ENABLE +# define ENCODER_CCW_CW(ccw, cw) \ + { (cw), (ccw) } +extern const uint16_t encoder_map[][NUM_ENCODERS][2]; +#endif // ENCODER_MAP_ENABLE diff --git a/quantum/encoder/tests/config_mock.h b/quantum/encoder/tests/config_mock.h new file mode 100644 index 0000000000..703dcaf103 --- /dev/null +++ b/quantum/encoder/tests/config_mock.h @@ -0,0 +1,22 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + { 0 } +#define ENCODERS_PAD_B \ + { 1 } + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/config_mock_split_left_eq_right.h b/quantum/encoder/tests/config_mock_split_left_eq_right.h new file mode 100644 index 0000000000..c80ac4d519 --- /dev/null +++ b/quantum/encoder/tests/config_mock_split_left_eq_right.h @@ -0,0 +1,26 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + { 0, 2 } +#define ENCODERS_PAD_B \ + { 1, 3 } +#define ENCODERS_PAD_A_RIGHT \ + { 4, 6 } +#define ENCODERS_PAD_B_RIGHT \ + { 5, 7 } + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock_split.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/config_mock_split_left_gt_right.h b/quantum/encoder/tests/config_mock_split_left_gt_right.h new file mode 100644 index 0000000000..91d5f3d605 --- /dev/null +++ b/quantum/encoder/tests/config_mock_split_left_gt_right.h @@ -0,0 +1,26 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + { 0, 2, 4 } +#define ENCODERS_PAD_B \ + { 1, 3, 5 } +#define ENCODERS_PAD_A_RIGHT \ + { 6, 8 } +#define ENCODERS_PAD_B_RIGHT \ + { 7, 9 } + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock_split.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/config_mock_split_left_lt_right.h b/quantum/encoder/tests/config_mock_split_left_lt_right.h new file mode 100644 index 0000000000..4108a184a6 --- /dev/null +++ b/quantum/encoder/tests/config_mock_split_left_lt_right.h @@ -0,0 +1,26 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + { 0, 2 } +#define ENCODERS_PAD_B \ + { 1, 3 } +#define ENCODERS_PAD_A_RIGHT \ + { 4, 6, 8 } +#define ENCODERS_PAD_B_RIGHT \ + { 5, 7, 9 } + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock_split.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/config_mock_split_no_left.h b/quantum/encoder/tests/config_mock_split_no_left.h new file mode 100644 index 0000000000..9db7fa7e41 --- /dev/null +++ b/quantum/encoder/tests/config_mock_split_no_left.h @@ -0,0 +1,26 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + {} +#define ENCODERS_PAD_B \ + {} +#define ENCODERS_PAD_A_RIGHT \ + { 0, 2 } +#define ENCODERS_PAD_B_RIGHT \ + { 1, 3 } + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock_split.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/config_mock_split_no_right.h b/quantum/encoder/tests/config_mock_split_no_right.h new file mode 100644 index 0000000000..14f18015e6 --- /dev/null +++ b/quantum/encoder/tests/config_mock_split_no_right.h @@ -0,0 +1,26 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +/* Here, "pins" from 0 to 31 are allowed. */ +#define ENCODERS_PAD_A \ + { 0, 2 } +#define ENCODERS_PAD_B \ + { 1, 3 } +#define ENCODERS_PAD_A_RIGHT \ + {} +#define ENCODERS_PAD_B_RIGHT \ + {} + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mock_split.h" + +#ifdef __cplusplus +}; +#endif diff --git a/quantum/encoder/tests/encoder_tests.cpp b/quantum/encoder/tests/encoder_tests.cpp index 1888fdab8d..b7c18aeec0 100644 --- a/quantum/encoder/tests/encoder_tests.cpp +++ b/quantum/encoder/tests/encoder_tests.cpp @@ -30,12 +30,12 @@ struct update { bool clockwise; }; -uint8_t uidx = 0; +uint8_t updates_array_idx = 0; update updates[32]; bool encoder_update_kb(uint8_t index, bool clockwise) { - updates[uidx % 32] = {index, clockwise}; - uidx++; + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; return true; } @@ -47,15 +47,15 @@ bool setAndRead(pin_t pin, bool val) { class EncoderTest : public ::testing::Test {}; TEST_F(EncoderTest, TestInit) { - uidx = 0; + updates_array_idx = 0; encoder_init(); EXPECT_EQ(pinIsInputHigh[0], true); EXPECT_EQ(pinIsInputHigh[1], true); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); } TEST_F(EncoderTest, TestOneClockwise) { - uidx = 0; + updates_array_idx = 0; encoder_init(); // send 4 pulses. with resolution 4, that's one step and we should get 1 update. setAndRead(0, false); @@ -63,26 +63,26 @@ TEST_F(EncoderTest, TestOneClockwise) { setAndRead(0, true); setAndRead(1, true); - EXPECT_EQ(uidx, 1); + EXPECT_EQ(updates_array_idx, 1); EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, true); } TEST_F(EncoderTest, TestOneCounterClockwise) { - uidx = 0; + updates_array_idx = 0; encoder_init(); setAndRead(1, false); setAndRead(0, false); setAndRead(1, true); setAndRead(0, true); - EXPECT_EQ(uidx, 1); + EXPECT_EQ(updates_array_idx, 1); EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, false); } TEST_F(EncoderTest, TestTwoClockwiseOneCC) { - uidx = 0; + updates_array_idx = 0; encoder_init(); setAndRead(0, false); setAndRead(1, false); @@ -97,7 +97,7 @@ TEST_F(EncoderTest, TestTwoClockwiseOneCC) { setAndRead(1, true); setAndRead(0, true); - EXPECT_EQ(uidx, 3); + EXPECT_EQ(updates_array_idx, 3); EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, true); EXPECT_EQ(updates[1].index, 0); @@ -107,38 +107,38 @@ TEST_F(EncoderTest, TestTwoClockwiseOneCC) { } TEST_F(EncoderTest, TestNoEarly) { - uidx = 0; + updates_array_idx = 0; encoder_init(); // send 3 pulses. with resolution 4, that's not enough for a step. setAndRead(0, false); setAndRead(1, false); setAndRead(0, true); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); // now send last pulse setAndRead(1, true); - EXPECT_EQ(uidx, 1); + EXPECT_EQ(updates_array_idx, 1); EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, true); } TEST_F(EncoderTest, TestHalfway) { - uidx = 0; + updates_array_idx = 0; encoder_init(); // go halfway setAndRead(0, false); setAndRead(1, false); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); // back off setAndRead(1, true); setAndRead(0, true); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); // go all the way setAndRead(0, false); setAndRead(1, false); setAndRead(0, true); setAndRead(1, true); // should result in 1 update - EXPECT_EQ(uidx, 1); + EXPECT_EQ(updates_array_idx, 1); EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, true); } diff --git a/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp new file mode 100644 index 0000000000..916e47b185 --- /dev/null +++ b/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp @@ -0,0 +1,135 @@ +/* Copyright 2021 Balz Guenat + * + * 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/>. + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <vector> +#include <algorithm> +#include <stdio.h> + +extern "C" { +#include "encoder.h" +#include "encoder/tests/mock_split.h" +} + +struct update { + int8_t index; + bool clockwise; +}; + +uint8_t updates_array_idx = 0; +update updates[32]; + +bool isLeftHand; + +bool encoder_update_kb(uint8_t index, bool clockwise) { + if (!isLeftHand) { + // this method has no effect on slave half + printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC"); + return true; + } + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; + return true; +} + +bool setAndRead(pin_t pin, bool val) { + setPin(pin, val); + return encoder_read(); +} + +class EncoderSplitTestLeftEqRight : public ::testing::Test { + protected: + void SetUp() override { + updates_array_idx = 0; + for (int i = 0; i < 32; i++) { + pinIsInputHigh[i] = 0; + pins[i] = 0; + } + } +}; + +TEST_F(EncoderSplitTestLeftEqRight, TestInitLeft) { + isLeftHand = true; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], true); + EXPECT_EQ(pinIsInputHigh[1], true); + EXPECT_EQ(pinIsInputHigh[2], true); + EXPECT_EQ(pinIsInputHigh[3], true); + EXPECT_EQ(pinIsInputHigh[4], false); + EXPECT_EQ(pinIsInputHigh[5], false); + EXPECT_EQ(pinIsInputHigh[6], false); + EXPECT_EQ(pinIsInputHigh[7], false); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftEqRight, TestInitRight) { + isLeftHand = false; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], false); + EXPECT_EQ(pinIsInputHigh[1], false); + EXPECT_EQ(pinIsInputHigh[2], false); + EXPECT_EQ(pinIsInputHigh[3], false); + EXPECT_EQ(pinIsInputHigh[4], true); + EXPECT_EQ(pinIsInputHigh[5], true); + EXPECT_EQ(pinIsInputHigh[6], true); + EXPECT_EQ(pinIsInputHigh[7], true); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseLeft) { + isLeftHand = true; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(0, false); + setAndRead(1, false); + setAndRead(0, true); + setAndRead(1, true); + + EXPECT_EQ(updates_array_idx, 1); // one update received + EXPECT_EQ(updates[0].index, 0); + EXPECT_EQ(updates[0].clockwise, true); +} + +TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseRightSent) { + isLeftHand = false; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(6, false); + setAndRead(7, false); + setAndRead(6, true); + setAndRead(7, true); + + uint8_t slave_state[32] = {0}; + encoder_state_raw(slave_state); + + EXPECT_EQ(slave_state[0], 0); + EXPECT_EQ(slave_state[1], 0xFF); +} + +TEST_F(EncoderSplitTestLeftEqRight, TestMultipleEncodersRightReceived) { + isLeftHand = true; + encoder_init(); + + uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder CW + encoder_update_raw(slave_state); + + EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side + EXPECT_EQ(updates[0].index, 2); + EXPECT_EQ(updates[0].clockwise, false); + EXPECT_EQ(updates[1].index, 3); + EXPECT_EQ(updates[1].clockwise, true); +} diff --git a/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp new file mode 100644 index 0000000000..7b64bb2981 --- /dev/null +++ b/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp @@ -0,0 +1,139 @@ +/* Copyright 2021 Balz Guenat + * + * 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/>. + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <vector> +#include <algorithm> +#include <stdio.h> + +extern "C" { +#include "encoder.h" +#include "encoder/tests/mock_split.h" +} + +struct update { + int8_t index; + bool clockwise; +}; + +uint8_t updates_array_idx = 0; +update updates[32]; + +bool isLeftHand; + +bool encoder_update_kb(uint8_t index, bool clockwise) { + if (!isLeftHand) { + // this method has no effect on slave half + printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC"); + return true; + } + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; + return true; +} + +bool setAndRead(pin_t pin, bool val) { + setPin(pin, val); + return encoder_read(); +} + +class EncoderSplitTestLeftGreaterThanRight : public ::testing::Test { + protected: + void SetUp() override { + updates_array_idx = 0; + for (int i = 0; i < 32; i++) { + pinIsInputHigh[i] = 0; + pins[i] = 0; + } + } +}; + +TEST_F(EncoderSplitTestLeftGreaterThanRight, TestInitLeft) { + isLeftHand = true; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], true); + EXPECT_EQ(pinIsInputHigh[1], true); + EXPECT_EQ(pinIsInputHigh[2], true); + EXPECT_EQ(pinIsInputHigh[3], true); + EXPECT_EQ(pinIsInputHigh[4], true); + EXPECT_EQ(pinIsInputHigh[5], true); + EXPECT_EQ(pinIsInputHigh[6], false); + EXPECT_EQ(pinIsInputHigh[7], false); + EXPECT_EQ(pinIsInputHigh[8], false); + EXPECT_EQ(pinIsInputHigh[9], false); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftGreaterThanRight, TestInitRight) { + isLeftHand = false; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], false); + EXPECT_EQ(pinIsInputHigh[1], false); + EXPECT_EQ(pinIsInputHigh[2], false); + EXPECT_EQ(pinIsInputHigh[3], false); + EXPECT_EQ(pinIsInputHigh[4], false); + EXPECT_EQ(pinIsInputHigh[5], false); + EXPECT_EQ(pinIsInputHigh[6], true); + EXPECT_EQ(pinIsInputHigh[7], true); + EXPECT_EQ(pinIsInputHigh[8], true); + EXPECT_EQ(pinIsInputHigh[9], true); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseLeft) { + isLeftHand = true; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(0, false); + setAndRead(1, false); + setAndRead(0, true); + setAndRead(1, true); + + EXPECT_EQ(updates_array_idx, 1); // one update received + EXPECT_EQ(updates[0].index, 0); + EXPECT_EQ(updates[0].clockwise, true); +} + +TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseRightSent) { + isLeftHand = false; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(6, false); + setAndRead(7, false); + setAndRead(6, true); + setAndRead(7, true); + + uint8_t slave_state[32] = {0}; + encoder_state_raw(slave_state); + + EXPECT_EQ(slave_state[0], 0xFF); + EXPECT_EQ(slave_state[1], 0); +} + +TEST_F(EncoderSplitTestLeftGreaterThanRight, TestMultipleEncodersRightReceived) { + isLeftHand = true; + encoder_init(); + + uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW + encoder_update_raw(slave_state); + + EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side + EXPECT_EQ(updates[0].index, 3); + EXPECT_EQ(updates[0].clockwise, false); + EXPECT_EQ(updates[1].index, 4); + EXPECT_EQ(updates[1].clockwise, true); +} diff --git a/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp new file mode 100644 index 0000000000..a6519c5762 --- /dev/null +++ b/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp @@ -0,0 +1,139 @@ +/* Copyright 2021 Balz Guenat + * + * 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/>. + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <vector> +#include <algorithm> +#include <stdio.h> + +extern "C" { +#include "encoder.h" +#include "encoder/tests/mock_split.h" +} + +struct update { + int8_t index; + bool clockwise; +}; + +uint8_t updates_array_idx = 0; +update updates[32]; + +bool isLeftHand; + +bool encoder_update_kb(uint8_t index, bool clockwise) { + if (!isLeftHand) { + // this method has no effect on slave half + printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC"); + return true; + } + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; + return true; +} + +bool setAndRead(pin_t pin, bool val) { + setPin(pin, val); + return encoder_read(); +} + +class EncoderSplitTestLeftLessThanRight : public ::testing::Test { + protected: + void SetUp() override { + updates_array_idx = 0; + for (int i = 0; i < 32; i++) { + pinIsInputHigh[i] = 0; + pins[i] = 0; + } + } +}; + +TEST_F(EncoderSplitTestLeftLessThanRight, TestInitLeft) { + isLeftHand = true; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], true); + EXPECT_EQ(pinIsInputHigh[1], true); + EXPECT_EQ(pinIsInputHigh[2], true); + EXPECT_EQ(pinIsInputHigh[3], true); + EXPECT_EQ(pinIsInputHigh[4], false); + EXPECT_EQ(pinIsInputHigh[5], false); + EXPECT_EQ(pinIsInputHigh[6], false); + EXPECT_EQ(pinIsInputHigh[7], false); + EXPECT_EQ(pinIsInputHigh[8], false); + EXPECT_EQ(pinIsInputHigh[9], false); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftLessThanRight, TestInitRight) { + isLeftHand = false; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], false); + EXPECT_EQ(pinIsInputHigh[1], false); + EXPECT_EQ(pinIsInputHigh[2], false); + EXPECT_EQ(pinIsInputHigh[3], false); + EXPECT_EQ(pinIsInputHigh[4], true); + EXPECT_EQ(pinIsInputHigh[5], true); + EXPECT_EQ(pinIsInputHigh[6], true); + EXPECT_EQ(pinIsInputHigh[7], true); + EXPECT_EQ(pinIsInputHigh[8], true); + EXPECT_EQ(pinIsInputHigh[9], true); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseLeft) { + isLeftHand = true; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(0, false); + setAndRead(1, false); + setAndRead(0, true); + setAndRead(1, true); + + EXPECT_EQ(updates_array_idx, 1); // one update received + EXPECT_EQ(updates[0].index, 0); + EXPECT_EQ(updates[0].clockwise, true); +} + +TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseRightSent) { + isLeftHand = false; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(6, false); + setAndRead(7, false); + setAndRead(6, true); + setAndRead(7, true); + + uint8_t slave_state[32] = {0}; + encoder_state_raw(slave_state); + + EXPECT_EQ(slave_state[0], 0); + EXPECT_EQ(slave_state[1], 0xFF); +} + +TEST_F(EncoderSplitTestLeftLessThanRight, TestMultipleEncodersRightReceived) { + isLeftHand = true; + encoder_init(); + + uint8_t slave_state[32] = {1, 0, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW + encoder_update_raw(slave_state); + + EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side + EXPECT_EQ(updates[0].index, 2); + EXPECT_EQ(updates[0].clockwise, false); + EXPECT_EQ(updates[1].index, 4); + EXPECT_EQ(updates[1].clockwise, true); +} diff --git a/quantum/encoder/tests/encoder_tests_split.cpp b/quantum/encoder/tests/encoder_tests_split_no_left.cpp index 25e52c83f9..b6b2d7e2d1 100644 --- a/quantum/encoder/tests/encoder_tests_split.cpp +++ b/quantum/encoder/tests/encoder_tests_split_no_left.cpp @@ -30,7 +30,7 @@ struct update { bool clockwise; }; -uint8_t uidx = 0; +uint8_t updates_array_idx = 0; update updates[32]; bool isLeftHand; @@ -41,8 +41,8 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC"); return true; } - updates[uidx % 32] = {index, clockwise}; - uidx++; + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; return true; } @@ -51,10 +51,10 @@ bool setAndRead(pin_t pin, bool val) { return encoder_read(); } -class EncoderTest : public ::testing::Test { +class EncoderSplitTestNoLeft : public ::testing::Test { protected: void SetUp() override { - uidx = 0; + updates_array_idx = 0; for (int i = 0; i < 32; i++) { pinIsInputHigh[i] = 0; pins[i] = 0; @@ -62,27 +62,27 @@ class EncoderTest : public ::testing::Test { } }; -TEST_F(EncoderTest, TestInitLeft) { +TEST_F(EncoderSplitTestNoLeft, TestInitLeft) { isLeftHand = true; encoder_init(); - EXPECT_EQ(pinIsInputHigh[0], true); - EXPECT_EQ(pinIsInputHigh[1], true); + EXPECT_EQ(pinIsInputHigh[0], false); + EXPECT_EQ(pinIsInputHigh[1], false); EXPECT_EQ(pinIsInputHigh[2], false); EXPECT_EQ(pinIsInputHigh[3], false); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); // no updates received } -TEST_F(EncoderTest, TestInitRight) { +TEST_F(EncoderSplitTestNoLeft, TestInitRight) { isLeftHand = false; encoder_init(); - EXPECT_EQ(pinIsInputHigh[0], false); - EXPECT_EQ(pinIsInputHigh[1], false); + EXPECT_EQ(pinIsInputHigh[0], true); + EXPECT_EQ(pinIsInputHigh[1], true); EXPECT_EQ(pinIsInputHigh[2], true); EXPECT_EQ(pinIsInputHigh[3], true); - EXPECT_EQ(uidx, 0); + EXPECT_EQ(updates_array_idx, 0); // no updates received } -TEST_F(EncoderTest, TestOneClockwiseLeft) { +TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseLeft) { isLeftHand = true; encoder_init(); // send 4 pulses. with resolution 4, that's one step and we should get 1 update. @@ -91,12 +91,10 @@ TEST_F(EncoderTest, TestOneClockwiseLeft) { setAndRead(0, true); setAndRead(1, true); - EXPECT_EQ(uidx, 1); - EXPECT_EQ(updates[0].index, 0); - EXPECT_EQ(updates[0].clockwise, true); + EXPECT_EQ(updates_array_idx, 0); // no updates received } -TEST_F(EncoderTest, TestOneClockwiseRightSent) { +TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseRightSent) { isLeftHand = false; encoder_init(); // send 4 pulses. with resolution 4, that's one step and we should get 1 update. @@ -105,39 +103,23 @@ TEST_F(EncoderTest, TestOneClockwiseRightSent) { setAndRead(2, true); setAndRead(3, true); - uint8_t slave_state[2] = {0}; + uint8_t slave_state[32] = {0}; encoder_state_raw(slave_state); - EXPECT_EQ((int8_t)slave_state[0], -1); + EXPECT_EQ(slave_state[0], 0); + EXPECT_EQ(slave_state[1], 0xFF); } -/* this test will not work after the previous test. - * this is due to encoder_value[1] already being set to -1 when simulating the right half. - * When we now receive this update acting as the left half, there is no change. - * This is hard to mock, as the static values inside encoder.c normally exist twice, once on each half, - * but here, they only exist once. - */ - -// TEST_F(EncoderTest, TestOneClockwiseRightReceived) { -// isLeftHand = true; -// encoder_init(); - -// uint8_t slave_state[2] = {255, 0}; -// encoder_update_raw(slave_state); - -// EXPECT_EQ(uidx, 1); -// EXPECT_EQ(updates[0].index, 1); -// EXPECT_EQ(updates[0].clockwise, true); -// } - -TEST_F(EncoderTest, TestOneCounterClockwiseRightReceived) { +TEST_F(EncoderSplitTestNoLeft, TestMultipleEncodersRightReceived) { isLeftHand = true; encoder_init(); - uint8_t slave_state[2] = {0, 0}; + uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW encoder_update_raw(slave_state); - EXPECT_EQ(uidx, 1); - EXPECT_EQ(updates[0].index, 1); + EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side + EXPECT_EQ(updates[0].index, 0); EXPECT_EQ(updates[0].clockwise, false); + EXPECT_EQ(updates[1].index, 1); + EXPECT_EQ(updates[1].clockwise, true); } diff --git a/quantum/encoder/tests/encoder_tests_split_no_right.cpp b/quantum/encoder/tests/encoder_tests_split_no_right.cpp new file mode 100644 index 0000000000..fa0a7c18a8 --- /dev/null +++ b/quantum/encoder/tests/encoder_tests_split_no_right.cpp @@ -0,0 +1,118 @@ +/* Copyright 2021 Balz Guenat + * + * 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/>. + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <vector> +#include <algorithm> +#include <stdio.h> + +extern "C" { +#include "encoder.h" +#include "encoder/tests/mock_split.h" +} + +struct update { + int8_t index; + bool clockwise; +}; + +uint8_t updates_array_idx = 0; +update updates[32]; + +bool isLeftHand; + +bool encoder_update_kb(uint8_t index, bool clockwise) { + if (!isLeftHand) { + // this method has no effect on slave half + printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC"); + return true; + } + updates[updates_array_idx % 32] = {index, clockwise}; + updates_array_idx++; + return true; +} + +bool setAndRead(pin_t pin, bool val) { + setPin(pin, val); + return encoder_read(); +} + +class EncoderSplitTestNoRight : public ::testing::Test { + protected: + void SetUp() override { + updates_array_idx = 0; + for (int i = 0; i < 32; i++) { + pinIsInputHigh[i] = 0; + pins[i] = 0; + } + } +}; + +TEST_F(EncoderSplitTestNoRight, TestInitLeft) { + isLeftHand = true; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], true); + EXPECT_EQ(pinIsInputHigh[1], true); + EXPECT_EQ(pinIsInputHigh[2], true); + EXPECT_EQ(pinIsInputHigh[3], true); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestNoRight, TestInitRight) { + isLeftHand = false; + encoder_init(); + EXPECT_EQ(pinIsInputHigh[0], false); + EXPECT_EQ(pinIsInputHigh[1], false); + EXPECT_EQ(pinIsInputHigh[2], false); + EXPECT_EQ(pinIsInputHigh[3], false); + EXPECT_EQ(updates_array_idx, 0); // no updates received +} + +TEST_F(EncoderSplitTestNoRight, TestOneClockwiseLeft) { + isLeftHand = true; + encoder_init(); + // send 4 pulses. with resolution 4, that's one step and we should get 1 update. + setAndRead(0, false); + setAndRead(1, false); + setAndRead(0, true); + setAndRead(1, true); + + EXPECT_EQ(updates_array_idx, 1); // one updates received + EXPECT_EQ(updates[0].index, 0); + EXPECT_EQ(updates[0].clockwise, true); +} + +TEST_F(EncoderSplitTestNoRight, TestOneClockwiseRightSent) { + isLeftHand = false; + encoder_init(); + + uint8_t slave_state[32] = {0xAA, 0xAA}; + encoder_state_raw(slave_state); + + EXPECT_EQ(slave_state[0], 0xAA); + EXPECT_EQ(slave_state[1], 0xAA); +} + +TEST_F(EncoderSplitTestNoRight, TestMultipleEncodersRightReceived) { + isLeftHand = true; + encoder_init(); + + uint8_t slave_state[32] = {1, 0xFF}; // These values would trigger updates if there were encoders on the other side + encoder_update_raw(slave_state); + + EXPECT_EQ(updates_array_idx, 0); // no updates received -- no right-hand encoders +} diff --git a/quantum/encoder/tests/mock.h b/quantum/encoder/tests/mock.h index dbc25a0846..80c336b5ef 100644 --- a/quantum/encoder/tests/mock.h +++ b/quantum/encoder/tests/mock.h @@ -19,12 +19,6 @@ #include <stdint.h> #include <stdbool.h> -/* Here, "pins" from 0 to 31 are allowed. */ -#define ENCODERS_PAD_A \ - { 0 } -#define ENCODERS_PAD_B \ - { 1 } - typedef uint8_t pin_t; extern bool pins[]; diff --git a/quantum/encoder/tests/mock_split.h b/quantum/encoder/tests/mock_split.h index 0ae62652f9..2fc12f1830 100644 --- a/quantum/encoder/tests/mock_split.h +++ b/quantum/encoder/tests/mock_split.h @@ -20,20 +20,10 @@ #include <stdbool.h> #define SPLIT_KEYBOARD -/* Here, "pins" from 0 to 31 are allowed. */ -#define ENCODERS_PAD_A \ - { 0 } -#define ENCODERS_PAD_B \ - { 1 } -#define ENCODERS_PAD_A_RIGHT \ - { 2 } -#define ENCODERS_PAD_B_RIGHT \ - { 3 } - typedef uint8_t pin_t; -extern bool isLeftHand; -void encoder_state_raw(uint8_t* slave_state); -void encoder_update_raw(uint8_t* slave_state); + +void encoder_state_raw(uint8_t* slave_state); +void encoder_update_raw(uint8_t* slave_state); extern bool pins[]; extern bool pinIsInputHigh[]; diff --git a/quantum/encoder/tests/rules.mk b/quantum/encoder/tests/rules.mk index b826ce3aed..6a2611952c 100644 --- a/quantum/encoder/tests/rules.mk +++ b/quantum/encoder/tests/rules.mk @@ -1,13 +1,58 @@ -encoder_DEFS := -DENCODER_MOCK_SINGLE +encoder_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SINGLE +encoder_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock.h encoder_SRC := \ + platforms/test/timer.c \ $(QUANTUM_PATH)/encoder/tests/mock.c \ $(QUANTUM_PATH)/encoder/tests/encoder_tests.cpp \ $(QUANTUM_PATH)/encoder.c -encoder_split_DEFS := -DENCODER_MOCK_SPLIT +encoder_split_left_eq_right_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SPLIT +encoder_split_left_eq_right_INC := $(QUANTUM_PATH)/split_common +encoder_split_left_eq_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_left_eq_right.h -encoder_split_SRC := \ +encoder_split_left_eq_right_SRC := \ + platforms/test/timer.c \ $(QUANTUM_PATH)/encoder/tests/mock_split.c \ - $(QUANTUM_PATH)/encoder/tests/encoder_tests_split.cpp \ + $(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_eq_right.cpp \ + $(QUANTUM_PATH)/encoder.c + +encoder_split_left_gt_right_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SPLIT +encoder_split_left_gt_right_INC := $(QUANTUM_PATH)/split_common +encoder_split_left_gt_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_left_gt_right.h + +encoder_split_left_gt_right_SRC := \ + platforms/test/timer.c \ + $(QUANTUM_PATH)/encoder/tests/mock_split.c \ + $(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_gt_right.cpp \ + $(QUANTUM_PATH)/encoder.c + +encoder_split_left_lt_right_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SPLIT +encoder_split_left_lt_right_INC := $(QUANTUM_PATH)/split_common +encoder_split_left_lt_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_left_lt_right.h + +encoder_split_left_lt_right_SRC := \ + platforms/test/timer.c \ + $(QUANTUM_PATH)/encoder/tests/mock_split.c \ + $(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_lt_right.cpp \ + $(QUANTUM_PATH)/encoder.c + +encoder_split_no_left_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SPLIT +encoder_split_no_left_INC := $(QUANTUM_PATH)/split_common +encoder_split_no_left_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_no_left.h + +encoder_split_no_left_SRC := \ + platforms/test/timer.c \ + $(QUANTUM_PATH)/encoder/tests/mock_split.c \ + $(QUANTUM_PATH)/encoder/tests/encoder_tests_split_no_left.cpp \ + $(QUANTUM_PATH)/encoder.c + +encoder_split_no_right_DEFS := -DENCODER_TESTS -DENCODER_ENABLE -DENCODER_MOCK_SPLIT +encoder_split_no_right_INC := $(QUANTUM_PATH)/split_common +encoder_split_no_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_no_right.h + +encoder_split_no_right_SRC := \ + platforms/test/timer.c \ + $(QUANTUM_PATH)/encoder/tests/mock_split.c \ + $(QUANTUM_PATH)/encoder/tests/encoder_tests_split_no_right.cpp \ $(QUANTUM_PATH)/encoder.c diff --git a/quantum/encoder/tests/testlist.mk b/quantum/encoder/tests/testlist.mk index 1be9f4a054..6b2fd84d96 100644 --- a/quantum/encoder/tests/testlist.mk +++ b/quantum/encoder/tests/testlist.mk @@ -1,3 +1,7 @@ TEST_LIST += \ encoder \ - encoder_split + encoder_split_left_eq_right \ + encoder_split_left_gt_right \ + encoder_split_left_lt_right \ + encoder_split_no_left \ + encoder_split_no_right diff --git a/quantum/keyboard.c b/quantum/keyboard.c index ba5609f0aa..bb6463bf19 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -489,7 +489,7 @@ bool matrix_scan_task(void) { // we can get here with some keys processed now. if (!keys_processed) #endif - action_exec(TICK); + action_exec(TICK_EVENT); MATRIX_LOOP_END: diff --git a/quantum/keyboard.h b/quantum/keyboard.h index e122b38264..fe0736a515 100644 --- a/quantum/keyboard.h +++ b/quantum/keyboard.h @@ -40,25 +40,47 @@ typedef struct { /* equivalent test of keypos_t */ #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) +/* special keypos_t entries */ +#define KEYLOC_TICK 255 +#define KEYLOC_COMBO 254 +#define KEYLOC_ENCODER_CW 253 +#define KEYLOC_ENCODER_CCW 252 + /* Rules for No Event: * 1) (time == 0) to handle (keyevent_t){} as empty event * 2) Matrix(255, 255) to make TICK event available */ static inline bool IS_NOEVENT(keyevent_t event) { - return event.time == 0 || (event.key.row == 255 && event.key.col == 255); + return event.time == 0 || (event.key.row == KEYLOC_TICK && event.key.col == KEYLOC_TICK); +} +static inline bool IS_KEYEVENT(keyevent_t event) { + return event.key.row < MATRIX_ROWS && event.key.col < MATRIX_COLS; +} +static inline bool IS_COMBOEVENT(keyevent_t event) { + return event.key.row == KEYLOC_COMBO; +} +static inline bool IS_ENCODEREVENT(keyevent_t event) { + return event.key.row == KEYLOC_ENCODER_CW || event.key.row == KEYLOC_ENCODER_CCW; } static inline bool IS_PRESSED(keyevent_t event) { - return (!IS_NOEVENT(event) && event.pressed); + return !IS_NOEVENT(event) && event.pressed; } static inline bool IS_RELEASED(keyevent_t event) { - return (!IS_NOEVENT(event) && !event.pressed); + return !IS_NOEVENT(event) && !event.pressed; } +/* Common keyevent object factory */ +#define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)}) +#define MAKE_KEYEVENT(row_num, col_num, press) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = (timer_read() | 1)}) + /* Tick event */ -#define TICK \ - (keyevent_t) { \ - .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) \ - } +#define TICK_EVENT MAKE_KEYEVENT(KEYLOC_TICK, KEYLOC_TICK, false) + +#ifdef ENCODER_MAP_ENABLE +/* Encoder events */ +# define ENCODER_CW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CW, (enc_id), (press)) +# define ENCODER_CCW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CCW, (enc_id), (press)) +#endif // ENCODER_MAP_ENABLE /* it runs once at early stage of startup before keyboard_init. */ void keyboard_setup(void); diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index d7e334fdc8..a2cb025ed2 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -37,7 +37,7 @@ typedef union { bool nkro : 1; bool swap_lctl_lgui : 1; bool swap_rctl_rgui : 1; - bool oneshot_disable : 1; + bool oneshot_enable : 1; }; } keymap_config_t; diff --git a/quantum/keymap.h b/quantum/keymap.h index 2ee2e1b576..d64b271efb 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // #include "print.h" #include "debug.h" #include "keycode_config.h" +#include "gpio.h" // for pin_t // ChibiOS uses RESET in its FlagStatus enumeration // Therefore define it as QK_BOOTLOADER here, to avoid name collision @@ -49,3 +50,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; + +#ifdef ENCODER_MAP_ENABLE +// Ensure we have a forward declaration for the encoder map +# include "encoder.h" +#endif diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index a91b2a0b36..c1940f0fd3 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -148,6 +148,15 @@ action_t action_for_keycode(uint16_t keycode) { // translates key to keycode __attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { - // Read entire word (16bits) - return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); + if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { + return pgm_read_word(&keymaps[layer][key.row][key.col]); + } +#ifdef ENCODER_MAP_ENABLE + else if (key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) { + return pgm_read_word(&encoder_map[layer][key.col][0]); + } else if (key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) { + return pgm_read_word(&encoder_map[layer][key.col][1]); + } +#endif // ENCODER_MAP_ENABLE + return KC_NO; } diff --git a/quantum/mousekey.c b/quantum/mousekey.c index 8bafbf977a..64d0e66682 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -16,6 +16,7 @@ */ #include <stdint.h> +#include <string.h> #include "keycode.h" #include "host.h" #include "timer.h" @@ -209,7 +210,7 @@ static uint8_t wheel_unit(void) { void mousekey_task(void) { // report cursor and scroll movement independently - report_mouse_t const tmpmr = mouse_report; + report_mouse_t tmpmr = mouse_report; mouse_report.x = 0; mouse_report.y = 0; @@ -251,8 +252,10 @@ void mousekey_task(void) { } } - if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send(); - mouse_report = tmpmr; + if (has_mouse_report_changed(&mouse_report, &tmpmr)) { + mousekey_send(); + } + memcpy(&mouse_report, &tmpmr, sizeof(tmpmr)); } void mousekey_on(uint8_t code) { @@ -340,11 +343,11 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0 void mousekey_task(void) { // report cursor and scroll movement independently - report_mouse_t const tmpmr = mouse_report; - mouse_report.x = 0; - mouse_report.y = 0; - mouse_report.v = 0; - mouse_report.h = 0; + report_mouse_t tmpmr = mouse_report; + mouse_report.x = 0; + mouse_report.y = 0; + mouse_report.v = 0; + mouse_report.h = 0; if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { mouse_report.x = tmpmr.x; @@ -355,8 +358,10 @@ void mousekey_task(void) { mouse_report.h = tmpmr.h; } - if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send(); - mouse_report = tmpmr; + if (has_mouse_report_changed(&mouse_report, &tmpmr)) { + mousekey_send(); + } + memcpy(&mouse_report, &tmpmr, sizeof(tmpmr)); } void adjust_speed(void) { diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 47a0af45d2..a160647890 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -71,17 +71,6 @@ static report_mouse_t local_mouse_report = {}; extern const pointing_device_driver_t pointing_device_driver; /** - * @brief Compares 2 mouse reports for difference and returns result - * - * @param[in] new_report report_mouse_t - * @param[in] old_report report_mouse_t - * @return bool result - */ -__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new_report, report_mouse_t old_report) { - return memcmp(&new_report, &old_report, sizeof(new_report)); -} - -/** * @brief Keyboard level code pointing device initialisation * */ @@ -165,7 +154,7 @@ __attribute__((weak)) void pointing_device_send(void) { static report_mouse_t old_report = {}; // If you need to do other things, like debugging, this is the place to do it. - if (has_mouse_report_changed(local_mouse_report, old_report)) { + if (has_mouse_report_changed(&local_mouse_report, &old_report)) { host_mouse_send(&local_mouse_report); } // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index a6bdbf120c..5c0eaeaf34 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -80,7 +80,6 @@ void pointing_device_task(void); void pointing_device_send(void); report_mouse_t pointing_device_get_report(void); void pointing_device_set_report(report_mouse_t mouse_report); -bool has_mouse_report_changed(report_mouse_t new_report, report_mouse_t old_report); uint16_t pointing_device_get_cpi(void); void pointing_device_set_cpi(uint16_t cpi); diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index efaf8fe0e9..d5a649adb3 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -88,8 +88,6 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; #define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH -#define COMBO_KEY_POS ((keypos_t){.col = 254, .row = 254}) - #ifndef EXTRA_SHORT_COMBOS /* flags are their own elements in combo_t struct. */ # define COMBO_ACTIVE(combo) (combo->active) @@ -140,12 +138,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; static inline void release_combo(uint16_t combo_index, combo_t *combo) { if (combo->keycode) { keyrecord_t record = { - .event = - { - .key = COMBO_KEY_POS, - .time = timer_read() | 1, - .pressed = false, - }, + .event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false), .keycode = combo->keycode, }; #ifndef NO_ACTION_TAPPING @@ -325,7 +318,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) { // this in the end executes the combo when the key_buffer is dumped. record->keycode = combo->keycode; - record->event.key = COMBO_KEY_POS; + record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO); qrecord->combo_index = combo_index; ACTIVATE_COMBO(combo); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 46b77e14ba..2606ea1f37 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -16,8 +16,6 @@ #include "process_unicode_common.h" #include "eeprom.h" -#include <ctype.h> -#include <string.h> unicode_config_t unicode_config; uint8_t unicode_saved_mods; @@ -231,37 +229,6 @@ void register_unicode(uint32_t code_point) { unicode_input_finish(); } -// clang-format off - -void send_unicode_hex_string(const char *str) { - if (!str) { - return; - } - - while (*str) { - // Find the next code point (token) in the string - for (; *str == ' '; str++); // Skip leading spaces - size_t n = strcspn(str, " "); // Length of the current token - char code_point[n+1]; - strncpy(code_point, str, n); // Copy token into buffer - code_point[n] = '\0'; // Make sure it's null-terminated - - // Normalize the code point: make all hex digits lowercase - for (char *p = code_point; *p; p++) { - *p = tolower((unsigned char)*p); - } - - // Send the code point as a Unicode input string - unicode_input_start(); - send_string(code_point); - unicode_input_finish(); - - str += n; // Move to the first ' ' (or '\0') after the current token - } -} - -// clang-format on - // Borrowed from https://nullprogram.com/blog/2017/10/06/ static const char *decode_utf8(const char *str, int32_t *code_point) { const char *next; diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 1a6607c757..8a4494c939 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -90,7 +90,6 @@ void register_hex(uint16_t hex); void register_hex32(uint32_t hex); void register_unicode(uint32_t code_point); -void send_unicode_hex_string(const char *str); void send_unicode_string(const char *str); bool process_unicode_common(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index ef6e5ac1df..d4e91ddd37 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -358,6 +358,26 @@ bool process_record_quantum(keyrecord_t *record) { oneshot_disable(); break; #endif +#ifdef ENABLE_COMPILE_KEYCODE + case QK_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader + { +# ifdef NO_ACTION_ONESHOT + const uint8_t temp_mod = mod_config(get_mods()); +# else + const uint8_t temp_mod = mod_config(get_mods() | get_oneshot_mods()); + clear_oneshot_mods(); +# endif + clear_mods(); + + SEND_STRING_DELAY("qmk", TAP_CODE_DELAY); + if (temp_mod & MOD_MASK_SHIFT) { // if shift is held, flash rather than compile + SEND_STRING_DELAY(" flash ", TAP_CODE_DELAY); + } else { + SEND_STRING_DELAY(" compile ", TAP_CODE_DELAY); + } + SEND_STRING_DELAY("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP SS_TAP(X_ENTER), TAP_CODE_DELAY); + } +#endif } } diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 2552c48165..dacfe5bdcd 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -595,6 +595,8 @@ enum quantum_keycodes { MAGIC_TOGGLE_CONTROL_CAPSLOCK, + QK_MAKE, + // Start of custom keycode range for keyboards and keymaps - always leave at the end SAFE_RANGE }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index cffbccaeee..105bf918cb 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -180,7 +180,7 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_update = 0; - uint8_t temp_state[NUMBER_OF_ENCODERS]; + uint8_t temp_state[NUM_ENCODERS_MAX_PER_SIDE]; bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, temp_state, split_shmem->encoders.state, sizeof(temp_state)); if (okay) encoder_update_raw(temp_state); @@ -188,7 +188,7 @@ static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t s } static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { - uint8_t encoder_state[NUMBER_OF_ENCODERS]; + uint8_t encoder_state[NUM_ENCODERS_MAX_PER_SIDE]; encoder_state_raw(encoder_state); // Always prepare the encoder state for read. memcpy(split_shmem->encoders.state, encoder_state, sizeof(encoder_state)); diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 26bd136728..e62679990a 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -42,7 +42,6 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, #ifdef ENCODER_ENABLE # include "encoder.h" -# define NUMBER_OF_ENCODERS (sizeof((pin_t[])ENCODERS_PAD_A) / sizeof(pin_t)) #endif // ENCODER_ENABLE #ifdef BACKLIGHT_ENABLE @@ -67,7 +66,7 @@ typedef struct _split_master_matrix_sync_t { #ifdef ENCODER_ENABLE typedef struct _split_slave_encoder_sync_t { uint8_t checksum; - uint8_t state[NUMBER_OF_ENCODERS]; + uint8_t state[NUM_ENCODERS_MAX_PER_SIDE]; } split_slave_encoder_sync_t; #endif // ENCODER_ENABLE diff --git a/quantum/util.h b/quantum/util.h index bef3b9abe3..ab96ce4bde 100644 --- a/quantum/util.h +++ b/quantum/util.h @@ -24,3 +24,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // convert to string #define STR(s) XSTR(s) #define XSTR(s) #s + +#if !defined(MIN) +# define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + +#if !defined(MAX) +# define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#endif @@ -1,3 +1,7 @@ +# This is the `develop` branch! + +See the [Breaking Changes](https://docs.qmk.fm/#/breaking_changes) document for more information. + # Quantum Mechanical Keyboard Firmware [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) diff --git a/tmk_core/protocol/report.c b/tmk_core/protocol/report.c index 854b59ae48..5755098c60 100644 --- a/tmk_core/protocol/report.c +++ b/tmk_core/protocol/report.c @@ -278,3 +278,16 @@ void clear_keys_from_report(report_keyboard_t* keyboard_report) { #endif memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys)); } + +#ifdef MOUSE_ENABLE +/** + * @brief Compares 2 mouse reports for difference and returns result + * + * @param[in] new_report report_mouse_t + * @param[in] old_report report_mouse_t + * @return bool result + */ +__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report) { + return memcmp(new_report, old_report, sizeof(report_mouse_t)); +} +#endif diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 1adc892f3b..7bbeb78af7 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h @@ -320,6 +320,10 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key); void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key); void clear_keys_from_report(report_keyboard_t* keyboard_report); +#ifdef MOUSE_ENABLE +bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report); +#endif + #ifdef __cplusplus } #endif diff --git a/util/generate_internal_docs.sh b/util/generate_internal_docs.sh deleted file mode 100755 index b107a37ad6..0000000000 --- a/util/generate_internal_docs.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -x - -if ! doxygen -v 2>&1 > /dev/null; then - echo "doxygen not found! Please install it!" - exit 1 -elif ! moxygen -V 2>&1 > /dev/null; then - echo -n "moxygen not found! Would you like to install it? [y/n] " - read ANSWER - case $ANSWER in - y|Y|yes|YES|Yes) - npm install -g moxygen - ;; - *) - exit 1 - ;; - esac -fi - -if [ ! -e Doxyfile ]; then - echo "Error: You must run this from the top-level qmk_firmware directory!" - exit 1 -fi - -# Generate the doxygen XML files -rm -rf doxygen -doxygen Doxyfile - -# Generate the moxygen Markdown files -moxygen -a -g -o docs/internals_%s.md doxygen/xml diff --git a/util/uf2conv.py b/util/uf2conv.py index 8677a828c9..fb82fd03ca 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py @@ -6,40 +6,13 @@ import re import os import os.path import argparse +import json UF2_MAGIC_START0 = 0x0A324655 # "UF2\n" UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected UF2_MAGIC_END = 0x0AB16F30 # Ditto -families = { - 'SAMD21': 0x68ed2b88, - 'SAML21': 0x1851780a, - 'SAMD51': 0x55114460, - 'NRF52': 0x1b57745f, - 'STM32F0': 0x647824b6, - 'STM32F1': 0x5ee21072, - 'STM32F2': 0x5d1a0a2e, - 'STM32F3': 0x6b846188, - 'STM32F4': 0x57755a57, - 'STM32F7': 0x53b80f00, - 'STM32G0': 0x300f5633, - 'STM32G4': 0x4c71240a, - 'STM32H7': 0x6db66082, - 'STM32L0': 0x202e3a91, - 'STM32L1': 0x1e1f432d, - 'STM32L4': 0x00ff6919, - 'STM32L5': 0x04240bdf, - 'STM32WB': 0x70d16653, - 'STM32WL': 0x21460ff0, - 'ATMEGA32': 0x16573617, - 'MIMXRT10XX': 0x4FB2D5BD, - 'LPC55': 0x2abc77ec, - 'GD32F350': 0x31D228C6, - 'ESP32S2': 0xbfdd4eee, - 'RP2040': 0xe48bff56 -} - INFO_FILE = "/INFO_UF2.TXT" appstartaddr = 0x2000 @@ -61,8 +34,13 @@ def is_hex(buf): def convert_from_uf2(buf): global appstartaddr + global familyid numblocks = len(buf) // 512 curraddr = None + currfamilyid = None + families_found = {} + prev_flag = None + all_flags_same = True outp = [] for blockno in range(numblocks): ptr = blockno * 512 @@ -78,9 +56,13 @@ def convert_from_uf2(buf): if datalen > 476: assert False, "Invalid UF2 data size at " + ptr newaddr = hd[3] - if curraddr is None: - appstartaddr = newaddr + if (hd[2] & 0x2000) and (currfamilyid == None): + currfamilyid = hd[7] + if curraddr == None or ((hd[2] & 0x2000) and hd[7] != currfamilyid): + currfamilyid = hd[7] curraddr = newaddr + if familyid == 0x0 or familyid == hd[7]: + appstartaddr = newaddr padding = newaddr - curraddr if padding < 0: assert False, "Block out of order at " + ptr @@ -91,8 +73,37 @@ def convert_from_uf2(buf): while padding > 0: padding -= 4 outp += b"\x00\x00\x00\x00" - outp.append(block[32 : 32 + datalen]) + if familyid == 0x0 or ((hd[2] & 0x2000) and familyid == hd[7]): + outp.append(block[32 : 32 + datalen]) curraddr = newaddr + datalen + if hd[2] & 0x2000: + if hd[7] in families_found.keys(): + if families_found[hd[7]] > newaddr: + families_found[hd[7]] = newaddr + else: + families_found[hd[7]] = newaddr + if prev_flag == None: + prev_flag = hd[2] + if prev_flag != hd[2]: + all_flags_same = False + if blockno == (numblocks - 1): + print("--- UF2 File Header Info ---") + families = load_families() + for family_hex in families_found.keys(): + family_short_name = "" + for name, value in families.items(): + if value == family_hex: + family_short_name = name + print("Family ID is {:s}, hex value is 0x{:08x}".format(family_short_name,family_hex)) + print("Target Address is 0x{:08x}".format(families_found[family_hex])) + if all_flags_same: + print("All block flag values consistent, 0x{:04x}".format(hd[2])) + else: + print("Flags were not all the same") + print("----------------------------") + if len(families_found) > 1 and familyid == 0x0: + outp = [] + appstartaddr = 0x0 return b"".join(outp) def convert_to_carray(file_content): @@ -166,12 +177,11 @@ def convert_from_hex_to_uf2(buf): upper = ((rec[4] << 8) | rec[5]) << 16 elif tp == 2: upper = ((rec[4] << 8) | rec[5]) << 4 - assert (upper & 0xffff) == 0 elif tp == 1: break elif tp == 0: - addr = upper | (rec[1] << 8) | rec[2] - if appstartaddr is None: + addr = upper + ((rec[1] << 8) | rec[2]) + if appstartaddr == None: appstartaddr = addr i = 4 while i < len(rec) - 1: @@ -215,7 +225,7 @@ def get_drives(): def has_info(d): try: return os.path.isfile(d + INFO_FILE) - except Exception: + except: return False return list(filter(has_info, drives)) @@ -238,10 +248,26 @@ def write_file(name, buf): print("Wrote %d bytes to %s" % (len(buf), name)) +def load_families(): + # The expectation is that the `uf2families.json` file is in the same + # directory as this script. Make a path that works using `__file__` + # which contains the full path to this script. + filename = "uf2families.json" + pathname = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename) + with open(pathname) as f: + raw_families = json.load(f) + + families = {} + for family in raw_families: + families[family["short_name"]] = int(family["id"], 0) + + return families + + def main(): global appstartaddr, familyid def error(msg): - print(msg) + print(msg, file=sys.stderr) sys.exit(1) parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.') parser.add_argument('input', metavar='INPUT', type=str, nargs='?', @@ -264,9 +290,13 @@ def main(): help='specify familyID - number or name (default: 0x0)') parser.add_argument('-C' , '--carray', action='store_true', help='convert binary file to a C array, not UF2') + parser.add_argument('-i', '--info', action='store_true', + help='display header information from UF2, do not convert') args = parser.parse_args() appstartaddr = int(args.base, 0) + families = load_families() + if args.family.upper() in families: familyid = families[args.family.upper()] else: @@ -286,9 +316,12 @@ def main(): ext = "uf2" if args.deploy: outbuf = inpbuf - elif from_uf2: + elif from_uf2 and not args.info: outbuf = convert_from_uf2(inpbuf) ext = "bin" + elif from_uf2 and args.info: + outbuf = "" + convert_from_uf2(inpbuf) elif is_hex(inpbuf): outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8")) elif args.carray: @@ -296,11 +329,12 @@ def main(): ext = "h" else: outbuf = convert_to_uf2(inpbuf) - print("Converting to %s, output size: %d, start address: 0x%x" % - (ext, len(outbuf), appstartaddr)) + if not args.deploy and not args.info: + print("Converted to %s, output size: %d, start address: 0x%x" % + (ext, len(outbuf), appstartaddr)) if args.convert or ext != "uf2": drives = [] - if args.output is None: + if args.output == None: args.output = "flash." + ext else: drives = get_drives() diff --git a/util/uf2families.json b/util/uf2families.json new file mode 100644 index 0000000000..fafae82a60 --- /dev/null +++ b/util/uf2families.json @@ -0,0 +1,192 @@ +[ + { + "id": "0x16573617", + "short_name": "ATMEGA32", + "description": "Microchip (Atmel) ATmega32" + }, + { + "id": "0x1851780a", + "short_name": "SAML21", + "description": "Microchip (Atmel) SAML21" + }, + { + "id": "0x1b57745f", + "short_name": "NRF52", + "description": "Nordic NRF52" + }, + { + "id": "0x1c5f21b0", + "short_name": "ESP32", + "description": "ESP32" + }, + { + "id": "0x1e1f432d", + "short_name": "STM32L1", + "description": "ST STM32L1xx" + }, + { + "id": "0x202e3a91", + "short_name": "STM32L0", + "description": "ST STM32L0xx" + }, + { + "id": "0x21460ff0", + "short_name": "STM32WL", + "description": "ST STM32WLxx" + }, + { + "id": "0x2abc77ec", + "short_name": "LPC55", + "description": "NXP LPC55xx" + }, + { + "id": "0x300f5633", + "short_name": "STM32G0", + "description": "ST STM32G0xx" + }, + { + "id": "0x31d228c6", + "short_name": "GD32F350", + "description": "GD32F350" + }, + { + "id": "0x04240bdf", + "short_name": "STM32L5", + "description": "ST STM32L5xx" + }, + { + "id": "0x4c71240a", + "short_name": "STM32G4", + "description": "ST STM32G4xx" + }, + { + "id": "0x4fb2d5bd", + "short_name": "MIMXRT10XX", + "description": "NXP i.MX RT10XX" + }, + { + "id": "0x53b80f00", + "short_name": "STM32F7", + "description": "ST STM32F7xx" + }, + { + "id": "0x55114460", + "short_name": "SAMD51", + "description": "Microchip (Atmel) SAMD51" + }, + { + "id": "0x57755a57", + "short_name": "STM32F4", + "description": "ST STM32F401" + }, + { + "id": "0x5a18069b", + "short_name": "FX2", + "description": "Cypress FX2" + }, + { + "id": "0x5d1a0a2e", + "short_name": "STM32F2", + "description": "ST STM32F2xx" + }, + { + "id": "0x5ee21072", + "short_name": "STM32F1", + "description": "ST STM32F103" + }, + { + "id": "0x621e937a", + "short_name": "NRF52833", + "description": "Nordic NRF52833" + }, + { + "id": "0x647824b6", + "short_name": "STM32F0", + "description": "ST STM32F0xx" + }, + { + "id": "0x68ed2b88", + "short_name": "SAMD21", + "description": "Microchip (Atmel) SAMD21" + }, + { + "id": "0x6b846188", + "short_name": "STM32F3", + "description": "ST STM32F3xx" + }, + { + "id": "0x6d0922fa", + "short_name": "STM32F407", + "description": "ST STM32F407" + }, + { + "id": "0x6db66082", + "short_name": "STM32H7", + "description": "ST STM32H7xx" + }, + { + "id": "0x70d16653", + "short_name": "STM32WB", + "description": "ST STM32WBxx" + }, + { + "id": "0x7eab61ed", + "short_name": "ESP8266", + "description": "ESP8266" + }, + { + "id": "0x7f83e793", + "short_name": "KL32L2", + "description": "NXP KL32L2x" + }, + { + "id": "0x8fb060fe", + "short_name": "STM32F407VG", + "description": "ST STM32F407VG" + }, + { + "id": "0xada52840", + "short_name": "NRF52840", + "description": "Nordic NRF52840" + }, + { + "id": "0xbfdd4eee", + "short_name": "ESP32S2", + "description": "ESP32-S2" + }, + { + "id": "0xc47e5767", + "short_name": "ESP32S3", + "description": "ESP32-S3" + }, + { + "id": "0xd42ba06c", + "short_name": "ESP32C3", + "description": "ESP32-C3" + }, + { + "id": "0x2b88d29c", + "short_name": "ESP32C2", + "description": "ESP32-C2" + }, + { + "id": "0x332726f6", + "short_name": "ESP32H2", + "description": "ESP32-H2" + }, + { + "id": "0xe48bff56", + "short_name": "RP2040", + "description": "Raspberry Pi RP2040" + }, + { + "id": "0x00ff6919", + "short_name": "STM32L4", + "description": "ST STM32L4xx" + }, + { + "id": "0x9af03e33", + "short_name": "GD32VF103", + "description": "GigaDevice GD32VF103" + } +] |