Compare commits

...

42 Commits

Author SHA1 Message Date
Nick Brassel
3cc250fe28
Merge fee56db8a1 into 36b5559b99 2024-11-21 17:32:05 +11:00
Drashna Jaelre
36b5559b99
[Core] Add Layer Lock feature (#23430)
Co-authored-by: Daniel <1767914+iamdanielv@users.noreply.github.com>
Co-authored-by: Pascal Getreuer <getreuer@google.com>
Co-authored-by: Pascal Getreuer <50221757+getreuer@users.noreply.github.com>
2024-11-21 17:31:54 +11:00
HorrorTroll
39161b9ee7
Added MCU support for ArteryTek AT32F415 (#23445) 2024-11-21 17:28:28 +11:00
QMK Bot
074bbbfb21 Merge remote-tracking branch 'origin/master' into develop 2024-11-21 06:22:51 +00:00
Ryan
638b22d057
qmk new-keyboard: separate dev board and MCU selection (#24548) 2024-11-21 17:22:14 +11:00
Ryan
9bea332a21
qmk via2json: Improve macro parsing (#24345) 2024-11-21 17:20:05 +11:00
Ryan
8cbcdcac62
qmk new-keymap: validate keymap name (#23420) 2024-11-21 17:18:51 +11:00
Pablo Martínez
88afd53b1f
[CLI] Refactor painter arguments to table instead of commandline (#24456)
Co-authored-by: Nick Brassel <nick@tzarc.org>
2024-11-21 17:16:46 +11:00
Ryan
9c86583981
Backward compatibility for new RGB keycode handling (#24490)
Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
2024-11-20 09:53:33 +11:00
QMK Bot
e66fce38b2 Merge remote-tracking branch 'origin/master' into develop 2024-11-19 21:59:43 +00:00
Nick Brassel
c843ad1268
Add Sagittarius encoder support. (#24617) 2024-11-20 08:59:07 +11:00
QMK Bot
0853a8ea35 Merge remote-tracking branch 'origin/master' into develop 2024-11-19 20:38:13 +00:00
russell-myers1
0988523851
Fix typo in docs/api_development_overview.md (#24620) 2024-11-19 13:37:39 -07:00
Nick Brassel
fee56db8a1
Merge remote-tracking branch 'upstream/develop' into data-repository 2024-11-02 22:31:51 +11:00
Nick Brassel
078ecc9079
Merge remote-tracking branch 'upstream/develop' into data-repository 2024-09-20 15:22:09 +10:00
Nick Brassel
22bd29e683
Fixup build. 2024-09-19 20:59:31 +10:00
Nick Brassel
aa2092a06b
Merge remote-tracking branch 'upstream/develop' into data-repository 2024-09-19 11:48:16 +10:00
Nick Brassel
57bcc8cbaf
Updated location of eeconfig magic numbers so non-EEPROM nvm drivers can use them too. 2024-09-19 00:32:07 +10:00
Nick Brassel
7847adcdf3
nvm_xxxxx_erase 2024-09-05 22:37:55 +10:00
Nick Brassel
3456f0b6a6
rollback 2024-09-03 21:51:50 +10:00
Nick Brassel
ea2d6c6bb1
code size fix 2024-09-03 20:58:09 +10:00
Nick Brassel
dc95e78fac
code-side docs 2024-09-03 20:04:50 +10:00
Nick Brassel
cbcbfbb6a0
fixups 2024-09-03 19:49:55 +10:00
Nick Brassel
bba99473c3
convert api to structs/unions 2024-09-03 19:26:27 +10:00
Nick Brassel
d9ae8048d9
convert api to structs/unions 2024-09-03 19:16:12 +10:00
Nick Brassel
2c3af2bfa8
convert api to structs/unions 2024-09-03 19:09:51 +10:00
Nick Brassel
4d46e95ea8
whitespace 2024-09-03 17:32:23 +10:00
Nick Brassel
397e8d4583
deferred variable resolve 2024-09-03 17:27:07 +10:00
Nick Brassel
21756ada63
thievery 2024-09-03 17:21:56 +10:00
Nick Brassel
5917a1dcd5
generic_features.mk to automatically pick up nvm repositories 2024-09-03 17:12:48 +10:00
Nick Brassel
0f4fe7e1f9
more whack-a-mole 2024-09-03 16:30:34 +10:00
Nick Brassel
0cd53997ea
omnikeyish 2024-09-03 16:09:53 +10:00
Nick Brassel
9f4be17fbc
satisfaction75 2024-09-03 15:33:31 +10:00
Nick Brassel
263b514ab4
more keyboard whack-a-mole 2024-09-03 13:37:26 +10:00
Nick Brassel
a368efc4d7
satisfaction75 2024-09-03 13:23:36 +10:00
Nick Brassel
1bd68df217
satisfaction75 2024-09-03 12:41:57 +10:00
Nick Brassel
357494852a
wilba leds 2024-09-03 12:14:33 +10:00
Nick Brassel
8ee730992d
Commentary. 2024-09-03 11:34:08 +10:00
Nick Brassel
1a0d8c459d
Fix filename. 2024-09-03 11:31:41 +10:00
Nick Brassel
4be3846269
via, dynamic_keymap. 2024-09-03 11:14:44 +10:00
Nick Brassel
298f360eb1
Offset and length for datablocks. 2024-09-03 09:46:06 +10:00
Nick Brassel
f78412d841
First batch of eeconfig conversions. 2024-09-03 09:07:54 +10:00
158 changed files with 3733 additions and 1007 deletions

View File

@ -29,6 +29,8 @@ QUANTUM_SRC += \
$(QUANTUM_DIR)/logging/debug.c \ $(QUANTUM_DIR)/logging/debug.c \
$(QUANTUM_DIR)/logging/sendchar.c \ $(QUANTUM_DIR)/logging/sendchar.c \
include $(QUANTUM_DIR)/nvm/rules.mk
VPATH += $(QUANTUM_DIR)/logging VPATH += $(QUANTUM_DIR)/logging
# Fall back to lib/printf if there is no platform provided print # Fall back to lib/printf if there is no platform provided print
ifeq ("$(wildcard $(PLATFORM_PATH)/$(PLATFORM_KEY)/printf.mk)","") ifeq ("$(wildcard $(PLATFORM_PATH)/$(PLATFORM_KEY)/printf.mk)","")
@ -215,7 +217,7 @@ else
COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash
COMMON_VPATH += $(DRIVER_PATH)/flash COMMON_VPATH += $(DRIVER_PATH)/flash
SRC += eeprom_driver.c eeprom_legacy_emulated_flash.c legacy_flash_ops.c SRC += eeprom_driver.c eeprom_legacy_emulated_flash.c legacy_flash_ops.c
else ifneq ($(filter $(MCU_SERIES),STM32F1xx STM32F3xx STM32F4xx STM32L4xx STM32G4xx WB32F3G71xx WB32FQ95xx GD32VF103),) else ifneq ($(filter $(MCU_SERIES),STM32F1xx STM32F3xx STM32F4xx STM32L4xx STM32G4xx WB32F3G71xx WB32FQ95xx AT32F415 GD32VF103),)
# Wear-leveling EEPROM implementation, backed by MCU flash # Wear-leveling EEPROM implementation, backed by MCU flash
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_WEAR_LEVELING OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_WEAR_LEVELING
SRC += eeprom_driver.c eeprom_wear_leveling.c SRC += eeprom_driver.c eeprom_wear_leveling.c
@ -456,6 +458,10 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations
COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations/runners COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations/runners
POST_CONFIG_H += $(QUANTUM_DIR)/rgb_matrix/post_config.h POST_CONFIG_H += $(QUANTUM_DIR)/rgb_matrix/post_config.h
# TODO: Remove this
SRC += $(QUANTUM_DIR)/process_keycode/process_underglow.c
SRC += $(QUANTUM_DIR)/process_keycode/process_rgb_matrix.c SRC += $(QUANTUM_DIR)/process_keycode/process_rgb_matrix.c
SRC += $(QUANTUM_DIR)/color.c SRC += $(QUANTUM_DIR)/color.c
SRC += $(QUANTUM_DIR)/rgb_matrix/rgb_matrix.c SRC += $(QUANTUM_DIR)/rgb_matrix/rgb_matrix.c

View File

@ -36,6 +36,7 @@ GENERIC_FEATURES = \
HAPTIC \ HAPTIC \
KEY_LOCK \ KEY_LOCK \
KEY_OVERRIDE \ KEY_OVERRIDE \
LAYER_LOCK \
LEADER \ LEADER \
MAGIC \ MAGIC \
MOUSEKEY \ MOUSEKEY \
@ -59,6 +60,7 @@ define HANDLE_GENERIC_FEATURE
SRC += $$(wildcard $$(QUANTUM_DIR)/process_keycode/process_$2.c) SRC += $$(wildcard $$(QUANTUM_DIR)/process_keycode/process_$2.c)
SRC += $$(wildcard $$(QUANTUM_DIR)/$2/$2.c) SRC += $$(wildcard $$(QUANTUM_DIR)/$2/$2.c)
SRC += $$(wildcard $$(QUANTUM_DIR)/$2.c) SRC += $$(wildcard $$(QUANTUM_DIR)/$2.c)
SRC += $$(wildcard $$(QUANTUM_DIR)/nvm/$$(NVM_DRIVER_LOWER)/nvm_$2.c)
VPATH += $$(wildcard $$(QUANTUM_DIR)/$2/) VPATH += $$(wildcard $$(QUANTUM_DIR)/$2/)
OPT_DEFS += -D$1_ENABLE OPT_DEFS += -D$1_ENABLE
endef endef

View File

@ -3,5 +3,12 @@
"0x7C20": "!delete!", // old QK_OUTPUT_AUTO "0x7C20": "!delete!", // old QK_OUTPUT_AUTO
"0x7C21": "!delete!", // old QK_OUTPUT_USB "0x7C21": "!delete!", // old QK_OUTPUT_USB
"0x7C22": "!delete!", // old QK_OUTPUT_BLUETOOTH "0x7C22": "!delete!", // old QK_OUTPUT_BLUETOOTH
"0x7C7B": {
"group": "quantum",
"key": "QK_LAYER_LOCK",
"aliases": [
"QK_LLCK"
]
}
} }
} }

View File

@ -64,6 +64,9 @@
"WEAR_LEVELING_BACKING_SIZE": {"info_key": "eeprom.wear_leveling.backing_size", "value_type": "int", "to_json": false}, "WEAR_LEVELING_BACKING_SIZE": {"info_key": "eeprom.wear_leveling.backing_size", "value_type": "int", "to_json": false},
"WEAR_LEVELING_LOGICAL_SIZE": {"info_key": "eeprom.wear_leveling.logical_size", "value_type": "int", "to_json": false}, "WEAR_LEVELING_LOGICAL_SIZE": {"info_key": "eeprom.wear_leveling.logical_size", "value_type": "int", "to_json": false},
// Layer locking
"LAYER_LOCK_IDLE_TIMEOUT": {"info_key": "layer_lock.timeout", "value_type": "int"},
// Indicators // Indicators
"LED_CAPS_LOCK_PIN": {"info_key": "indicators.caps_lock"}, "LED_CAPS_LOCK_PIN": {"info_key": "indicators.caps_lock"},
"LED_NUM_LOCK_PIN": {"info_key": "indicators.num_lock"}, "LED_NUM_LOCK_PIN": {"info_key": "indicators.num_lock"},

View File

@ -92,6 +92,7 @@
"GD32VF103", "GD32VF103",
"WB32F3G71", "WB32F3G71",
"WB32FQ95", "WB32FQ95",
"AT32F415",
"atmega16u2", "atmega16u2",
"atmega32u2", "atmega32u2",
"atmega16u4", "atmega16u4",
@ -216,6 +217,7 @@
"type": "string", "type": "string",
"enum": [ "enum": [
"apm32-dfu", "apm32-dfu",
"at32-dfu",
"atmel-dfu", "atmel-dfu",
"bootloadhid", "bootloadhid",
"caterina", "caterina",
@ -373,6 +375,12 @@
} }
}, },
"keycodes": {"$ref": "qmk.definitions.v1#/keycode_decl_array"}, "keycodes": {"$ref": "qmk.definitions.v1#/keycode_decl_array"},
"layer_lock": {
"type": "object",
"properties": {
"timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}
}
},
"layout_aliases": { "layout_aliases": {
"type": "object", "type": "object",
"additionalProperties": {"$ref": "qmk.definitions.v1#/layout_macro"} "additionalProperties": {"$ref": "qmk.definitions.v1#/layout_macro"}

View File

@ -123,6 +123,7 @@
{ "text": "Key Lock", "link": "/features/key_lock" }, { "text": "Key Lock", "link": "/features/key_lock" },
{ "text": "Key Overrides", "link": "/features/key_overrides" }, { "text": "Key Overrides", "link": "/features/key_overrides" },
{ "text": "Layers", "link": "/feature_layers" }, { "text": "Layers", "link": "/feature_layers" },
{ "text": "Layer Lock", "link": "/features/layer_lock" },
{ "text": "One Shot Keys", "link": "/one_shot_keys" }, { "text": "One Shot Keys", "link": "/one_shot_keys" },
{ "text": "OS Detection", "link": "/features/os_detection" }, { "text": "OS Detection", "link": "/features/os_detection" },
{ "text": "Raw HID", "link": "/features/rawhid" }, { "text": "Raw HID", "link": "/features/rawhid" },

View File

@ -4,7 +4,7 @@ This page attempts to introduce developers to the QMK Compiler. It does not go i
# Overview # Overview
The QMK Compile API consists of a few movings parts: The QMK Compile API consists of a few moving parts:
![Architecture Diagram](https://raw.githubusercontent.com/qmk/qmk_api/master/docs/architecture.svg) ![Architecture Diagram](https://raw.githubusercontent.com/qmk/qmk_api/master/docs/architecture.svg)

View File

@ -57,6 +57,10 @@ You can also use any ARM chip with USB that [ChibiOS](https://www.chibios.org) s
* [WB32F3G71xx](http://www.westberrytech.com) * [WB32F3G71xx](http://www.westberrytech.com)
* [WB32FQ95xx](http://www.westberrytech.com) * [WB32FQ95xx](http://www.westberrytech.com)
### Artery (AT32)
* [AT32F415](https://www.arterychip.com/en/product/AT32F415.jsp)
### NXP (Kinetis) ### NXP (Kinetis)
* [MKL26Z64](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/kl-series-cortex-m0-plus/kinetis-kl2x-72-96-mhz-usb-ultra-low-power-microcontrollers-mcus-based-on-arm-cortex-m0-plus-core:KL2x) * [MKL26Z64](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/kl-series-cortex-m0-plus/kinetis-kl2x-72-96-mhz-usb-ultra-low-power-microcontrollers-mcus-based-on-arm-cortex-m0-plus-core:KL2x)

View File

@ -98,6 +98,7 @@ The device name here is the name that appears in Zadig, and may not be what the
|`bootloadhid` |HIDBoot |`16C0:05DF` |HidUsb | |`bootloadhid` |HIDBoot |`16C0:05DF` |HidUsb |
|`usbasploader`|USBasp |`16C0:05DC` |libusbK| |`usbasploader`|USBasp |`16C0:05DC` |libusbK|
|`apm32-dfu` |APM32 DFU ISP Mode |`314B:0106` |WinUSB | |`apm32-dfu` |APM32 DFU ISP Mode |`314B:0106` |WinUSB |
|`at32-dfu` |AT32 Bootloader DFU |`2E3C:DF11` |WinUSB |
|`stm32-dfu` |STM32 BOOTLOADER |`0483:DF11` |WinUSB | |`stm32-dfu` |STM32 BOOTLOADER |`0483:DF11` |WinUSB |
|`gd32v-dfu` |GD32V BOOTLOADER |`28E9:0189` |WinUSB | |`gd32v-dfu` |GD32V BOOTLOADER |`28E9:0189` |WinUSB |
|`kiibohd` |Kiibohd DFU Bootloader |`1C11:B007` |WinUSB | |`kiibohd` |Kiibohd DFU Bootloader |`1C11:B007` |WinUSB |

View File

@ -17,6 +17,9 @@ These functions allow you to activate layers in various ways. Note that layers a
* `TO(layer)` - activates *layer* and de-activates all other layers (except your default layer). This function is special, because instead of just adding/removing one layer to your active layer stack, it will completely replace your current active layers, uniquely allowing you to replace higher layers with a lower one. This is activated on keydown (as soon as the key is pressed). * `TO(layer)` - activates *layer* and de-activates all other layers (except your default layer). This function is special, because instead of just adding/removing one layer to your active layer stack, it will completely replace your current active layers, uniquely allowing you to replace higher layers with a lower one. This is activated on keydown (as soon as the key is pressed).
* `TT(layer)` - Layer Tap-Toggle. If you hold the key down, *layer* is activated, and then is de-activated when you let go (like `MO`). If you repeatedly tap it, the layer will be toggled on or off (like `TG`). It needs 5 taps by default, but you can change this by defining `TAPPING_TOGGLE` -- for example, `#define TAPPING_TOGGLE 2` to toggle on just two taps. * `TT(layer)` - Layer Tap-Toggle. If you hold the key down, *layer* is activated, and then is de-activated when you let go (like `MO`). If you repeatedly tap it, the layer will be toggled on or off (like `TG`). It needs 5 taps by default, but you can change this by defining `TAPPING_TOGGLE` -- for example, `#define TAPPING_TOGGLE 2` to toggle on just two taps.
See also the [Layer Lock key](features/layer_lock), which locks the highest
active layer until pressed again.
### Caveats {#caveats} ### Caveats {#caveats}
Currently, the `layer` argument of `LT()` is limited to layers 0-15, and the `kc` argument to the [Basic Keycode set](keycodes_basic), meaning you can't use keycodes like `LCTL()`, `KC_TILD`, or anything greater than `0xFF`. This is because QMK uses 16-bit keycodes, of which 4 bits are used for the function identifier and 4 bits for the layer, leaving only 8 bits for the keycode. Currently, the `layer` argument of `LT()` is limited to layers 0-15, and the `kc` argument to the [Basic Keycode set](keycodes_basic), meaning you can't use keycodes like `LCTL()`, `KC_TILD`, or anything greater than `0xFF`. This is because QMK uses 16-bit keycodes, of which 4 bits are used for the function identifier and 4 bits for the layer, leaving only 8 bits for the keycode.

139
docs/features/layer_lock.md Normal file
View File

@ -0,0 +1,139 @@
# Layer Lock
Some [layer switches](../feature_layers#switching-and-toggling-layers) access
the layer by holding the key, including momentary layer `MO(layer)` and layer
tap `LT(layer, key)` keys. You may sometimes need to stay on the layer for a
long period of time. Layer Lock "locks" the current layer to stay on, supposing
it was accessed by one of:
* `MO(layer)` momentary layer switch
* `LT(layer, key)` layer tap
* `OSL(layer)` one-shot layer
* `TT(layer)` layer tap toggle
* `LM(layer, mod)` layer-mod key (the layer is locked, but not the mods)
Press the Layer Lock key again to unlock the layer. Additionally, when a layer
is locked, layer switch keys that turn off the layer such as `TO(other_layer)`
will unlock it.
## How do I enable Layer Lock
In your rules.mk, add:
```make
LAYER_LOCK_ENABLE = yes
```
Pick a key in your keymap on a layer you intend to lock, and assign it the
keycode `QK_LAYER_LOCK` (short alias `QK_LLCK`). Note that locking the base
layer has no effect, so typically, this key is used on layers above the base
layer.
## Example use
Consider a keymap with the following base layer.
![Base layer with a MO(NAV) key.](https://i.imgur.com/DkEhj9x.png)
The highlighted key is a momentary layer switch `MO(NAV)`. Holding it accesses a
navigation layer.
![Nav layer with a Layer Lock key.](https://i.imgur.com/2wUZNWk.png)
Holding the NAV key is fine for brief use, but awkward to continue holding when
using navigation functions continuously. The Layer Lock key comes to the rescue:
1. Hold the NAV key, activating the navigation layer.
2. Tap Layer Lock.
3. Release NAV. The navigation layer stays on.
4. Make use of the arrow keys, etc.
5. Tap Layer Lock or NAV again to turn the navigation layer back off.
A variation that would also work is to put the Layer Lock key on the base layer
and make other layers transparent (`KC_TRNS`) in that position. Pressing the
Layer Lock key locks (or unlocks) the highest active layer, regardless of which
layer the Layer Lock key is on.
## Idle timeout
Optionally, Layer Lock may be configured to unlock if the keyboard is idle
for some time. In config.h, define `LAYER_LOCK_IDLE_TIMEOUT` in units of
milliseconds:
```c
#define LAYER_LOCK_IDLE_TIMEOUT 60000 // Turn off after 60 seconds.
```
## Functions
Use the following functions to query and manipulate the layer lock state.
| Function | Description |
|----------------------------|------------------------------------|
| `is_layer_locked(layer)` | Checks whether `layer` is locked. |
| `layer_lock_on(layer)` | Locks and turns on `layer`. |
| `layer_lock_off(layer)` | Unlocks and turns off `layer`. |
| `layer_lock_invert(layer)` | Toggles whether `layer` is locked. |
## Representing the current Layer Lock state
There is an optional callback `layer_lock_set_user()` that gets called when a
layer is locked or unlocked. This is useful to represent the current lock state
for instance by setting an LED. In keymap.c, define
```c
bool layer_lock_set_user(layer_state_t locked_layers) {
// Do something like `set_led(is_layer_locked(NAV));`
return true;
}
```
The argument `locked_layers` is a bitfield in which the kth bit is on if the kth
layer is locked. Alternatively, you can use `is_layer_locked(layer)` to check if
a given layer is locked.
## Combine Layer Lock with a mod-tap
It is possible to create a [mod-tap MT key](../mod_tap) that acts as a modifier
on hold and Layer Lock on tap. Since Layer Lock is not a [basic
keycode](../keycodes_basic), attempting `MT(mod, QK_LLCK)` is invalid does not
work directly, yet this effect can be achieved through [changing the tap
function](../mod_tap#changing-tap-function). For example, the following
implements a `SFTLLCK` key that acts as Shift on hold and Layer Lock on tap:
```c
#define SFTLLCK LSFT_T(KC_0)
// Use SFTLLCK in your keymap...
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case SFTLLCK:
if (record->tap.count) {
if (record->event.pressed) {
// Toggle the lock on the highest layer.
layer_lock_invert(get_highest_layer(layer_state));
}
return false;
}
break;
// Other macros...
}
return true;
}
```
In the above, `KC_0` is an arbitrary placeholder for the tapping keycode. This
keycode will never be sent, so any basic keycode will do. In
`process_record_user()`, the tap press event is changed to toggle the lock on
the highest layer. Layer Lock can be combined with a [layer-tap LT
key](../feature_layers#switching-and-toggling-layers) similarly.

View File

@ -59,6 +59,10 @@ Changing the **Value** sets the overall brightness.<br>
## Keycodes ## Keycodes
::: warning
These keycodes also simultaneously control [RGB Matrix](rgb_matrix), if enabled. This behaviour is in the process of being deprecated, so during this time it is recommended to additionally include the dedicated RGB Matrix keycodes to your keymap, and add `#define RGB_MATRIX_DISABLE_SHARED_KEYCODES` to `config.h`.
:::
|Key |Aliases |Description | |Key |Aliases |Description |
|------------------------------|----------|---------------------------------------------------------------------| |------------------------------|----------|---------------------------------------------------------------------|
|`QK_UNDERGLOW_TOGGLE` |`UG_TOGG` |Toggle RGB lighting on or off | |`QK_UNDERGLOW_TOGGLE` |`UG_TOGG` |Toggle RGB lighting on or off |

View File

@ -345,6 +345,39 @@ Flashing sequence:
3. Flash a .bin file 3. Flash a .bin file
4. Reset the device into application mode (may be done automatically) 4. Reset the device into application mode (may be done automatically)
## AT32 DFU
All AT32 MCUs come preloaded with a factory bootloader that cannot be modified nor deleted.
To ensure compatibility with the AT32-DFU bootloader, make sure this block is present in your `rules.mk`:
```make
# Bootloader selection
BOOTLOADER = at32-dfu
```
Compatible flashers:
* [dfu-util](https://dfu-util.sourceforge.net/) / `:dfu-util` target in QMK (recommended command line)
```
dfu-util -a 0 -d 2E3C:DF11 -s 0x8000000:leave -D <filename>
```
Flashing sequence:
1. Enter the bootloader using any of the following methods:
* Tap the `QK_BOOT` keycode
* If a reset circuit is present, tap the `RESET` button on the PCB; some boards may also have a toggle switch that must be flipped
* Otherwise, you need to bridge `BOOT0` to VCC (via `BOOT0` button or jumper), short `RESET` to GND (via `RESET` button or jumper), and then let go of the `BOOT0` bridge
2. Wait for the OS to detect the device
3. Flash a .bin file
4. Reset the device into application mode (may be done automatically)
### `make` Targets
* `:dfu-util`: Waits until an AT32 bootloader device is available, and then flashes the firmware.
* `:dfu-util-split-left` and `:dfu-util-split-right`: Flashes the firmware as with `:dfu-util`, but also sets the handedness setting in EEPROM.
## tinyuf2 ## tinyuf2
Keyboards may opt into supporting the tinyuf2 bootloader. This is currently only supported on F303/F401/F411. Keyboards may opt into supporting the tinyuf2 bootloader. This is currently only supported on F303/F401/F411.

View File

@ -387,6 +387,14 @@ See also: [Key Lock](features/key_lock)
|---------|--------------------------------------------------------------| |---------|--------------------------------------------------------------|
|`QK_LOCK`|Hold down the next key pressed, until the key is pressed again| |`QK_LOCK`|Hold down the next key pressed, until the key is pressed again|
## Layer Lock {#layer-lock}
See also: [Layer Lock](features/layer_lock)
|Key |Aliases |Description |
|---------------|---------|----------------------------------|
|`QK_LAYER_LOCK`|`QK_LLCK`|Locks or unlocks the highest layer|
## Layer Switching {#layer-switching} ## Layer Switching {#layer-switching}
See also: [Layer Switching](feature_layers#switching-and-toggling-layers) See also: [Layer Switching](feature_layers#switching-and-toggling-layers)

View File

@ -4,52 +4,51 @@ This page describes the support for [Compatible Microcontrollers](compatible_mic
If you have not yet you should read the [Keyboard Guidelines](hardware_keyboard_guidelines) to get a sense of how keyboards fit into QMK. If you have not yet you should read the [Keyboard Guidelines](hardware_keyboard_guidelines) to get a sense of how keyboards fit into QMK.
QMK has a number of features to simplify working with keyboards. For most, you don't have to write a single line of code. To get started, run `qmk new-keyboard`: QMK has a number of features to simplify working with keyboards. For most, you don't have to write a single line of code. To get started, run `qmk new-keyboard`:
``` ```
$ qmk new-keyboard $ qmk new-keyboard
Ψ Generating a new QMK keyboard directory Ψ Generating a new QMK keyboard directory
Name Your Keyboard Project Ψ Name Your Keyboard Project
For more infomation, see: Ψ For more information, see:
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboardproject https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project
Keyboard Name? mycoolkeeb
keyboard Name? mycoolkeeb Ψ Attribution
Ψ Used for maintainer, copyright, etc.
Attribution
Used for maintainer, copyright, etc
Your GitHub Username? [jsmith] Your GitHub Username? [jsmith]
Ψ More Attribution
More Attribution Ψ Used for maintainer, copyright, etc.
Used for maintainer, copyright, etc
Your Real Name? [John Smith] Your Real Name? [John Smith]
Ψ Pick Base Layout
Pick Base Layout Ψ As a starting point, one of the common layouts can be used to
As a starting point, one of the common layouts can be used to bootstrap the process bootstrap the process
Default Layout? Default Layout?
1. 60_ansi 1. 60_abnt2
... ...
50. tkl_iso 65. none of the above
51. none of the above Please enter your choice: [65]
Please enter your choice: [51] Ψ What Powers Your Project
Ψ Is your board using a separate development board, such as a Pro Micro,
or is the microcontroller integrated onto the PCB?
What Powers Your Project For more information, see:
For more infomation, see: https://docs.qmk.fm/compatible_microcontrollers
https://docs.qmk.fm/#/compatible_microcontrollers Using a Development Board? [y/n] y
Ψ Select Development Board
MCU? Ψ For more information, see:
1. atmega32u4 https://docs.qmk.fm/compatible_microcontrollers
Development Board?
1. bit_c_pro
... ...
22. STM32F303 14. promicro
Please enter your choice: [12] ...
18. svlinky
Please enter your choice: [14]
Ψ Created a new keyboard called mycoolkeeb. Ψ Created a new keyboard called mycoolkeeb.
Ψ To start working on things, `cd` into keyboards/mycoolkeeb, Ψ Build Command: qmk compile -kb mycoolkeeb -km default.
Ψ or open the directory in your preferred text editor. Ψ Project Location: /Users/jsmith/qmk_firmware/keyboards/mycoolkeeb.
Ψ And build with qmk compile -kb mycoolkeeb -km default. Ψ Now update the config files to match the hardware!
``` ```
This will create all the files needed to support your new keyboard, and populate the settings with default values. Now you just need to customize it for your keyboard. This will create all the files needed to support your new keyboard, and populate the settings with default values. Now you just need to customize it for your keyboard.
@ -58,13 +57,13 @@ This will create all the files needed to support your new keyboard, and populate
This is where you'll describe your keyboard. Please follow the [Keyboard Readme Template](documentation_templates#keyboard-readmemd-template) when writing your `readme.md`. You're encouraged to place an image at the top of your `readme.md`, please use an external service such as [Imgur](https://imgur.com) to host the images. This is where you'll describe your keyboard. Please follow the [Keyboard Readme Template](documentation_templates#keyboard-readmemd-template) when writing your `readme.md`. You're encouraged to place an image at the top of your `readme.md`, please use an external service such as [Imgur](https://imgur.com) to host the images.
## `info.json` ## `keyboard.json`
The `info.json` file is where you configure the hardware and feature set for your keyboard. There are a lot of options that can be placed in that file, too many to list here. For a complete overview of available options see the [Data Driven Configuration Options](reference_info_json) page. The `keyboard.json` file is where you configure the hardware and feature set for your keyboard. There are a lot of options that can be placed in that file, too many to list here. For a complete overview of available options see the [Data Driven Configuration Options](reference_info_json) page.
### Hardware Configuration ### Hardware Configuration
At the top of the `info.json` you'll find USB related settings. These control how your keyboard appears to the Operating System. If you don't have a good reason to change you should leave the `usb.vid` as `0xFEED`. For the `usb.pid` you should pick a number that is not yet in use. At the top of the `keyboard.json` you'll find USB related settings. These control how your keyboard appears to the Operating System. If you don't have a good reason to change you should leave the `usb.vid` as `0xFEED`. For the `usb.pid` you should pick a number that is not yet in use.
Do change the `manufacturer` and `keyboard_name` lines to accurately reflect your keyboard. Do change the `manufacturer` and `keyboard_name` lines to accurately reflect your keyboard.
@ -82,10 +81,11 @@ Do change the `manufacturer` and `keyboard_name` lines to accurately reflect you
Windows and macOS will display the `manufacturer` and `keyboard_name` in the list of USB devices. `lsusb` on Linux instead prefers the values in the list maintained by the [USB ID Repository](http://www.linux-usb.org/usb-ids.html). By default, it will only use `manufacturer` and `keyboard_name` if the list does not contain that `usb.vid` / `usb.pid`. `sudo lsusb -v` will show the values reported by the device, and they are also present in kernel logs after plugging it in. Windows and macOS will display the `manufacturer` and `keyboard_name` in the list of USB devices. `lsusb` on Linux instead prefers the values in the list maintained by the [USB ID Repository](http://www.linux-usb.org/usb-ids.html). By default, it will only use `manufacturer` and `keyboard_name` if the list does not contain that `usb.vid` / `usb.pid`. `sudo lsusb -v` will show the values reported by the device, and they are also present in kernel logs after plugging it in.
::: :::
### Matrix Configuration ### Matrix Configuration
The next section of the `info` file deals with your keyboard's matrix. The first thing you should define is which pins on your MCU are connected to rows and columns. To do so simply specify the names of those pins: The next section of the `keyboard.json` deals with your keyboard's matrix. The first thing you should define is which pins on your MCU are connected to rows and columns. To do so simply specify the names of those pins:
#### Diode Matrix
```json ```json
"matrix_pins": { "matrix_pins": {
@ -94,7 +94,7 @@ The next section of the `info` file deals with your keyboard's matrix. The first
}, },
``` ```
The size of the `matrix_pins.cols` and `matrix_pins.rows` arrays infer the size of the matrix (previously `MATRIX_ROWS` and `MATRIX_COLS`). The matrix dimensions are inferred from the length of the `matrix_pins.cols` and `matrix_pins.rows` arrays (previously specified explicitly in `config.h` with `MATRIX_ROWS` and `MATRIX_COLS`).
Finally, you can specify the direction your diodes point. This can be `COL2ROW` or `ROW2COL`. Finally, you can specify the direction your diodes point. This can be `COL2ROW` or `ROW2COL`.
@ -103,7 +103,8 @@ Finally, you can specify the direction your diodes point. This can be `COL2ROW`
``` ```
#### Direct Pin Matrix #### Direct Pin Matrix
To configure a keyboard where each switch is connected to a separate pin and ground instead of sharing row and column pins, use `matrix_pins.direct`. The mapping defines the pins of each switch in rows and columns, from left to right. The size of the `matrix_pins.direct` array infers the size of the matrix. Use `NO_PIN` to fill in blank spaces. Overrides the behaviour of `diode_direction`, `matrix_pins.cols` and `matrix_pins.rows`.
To configure a keyboard where each switch is connected to a separate pin and ground instead of sharing row and column pins, use `matrix_pins.direct`. This overrides the behaviour of `diode_direction`, `matrix_pins.cols` and `matrix_pins.rows`, and they should not be specified together.
```json ```json
"matrix_pins": { "matrix_pins": {
@ -111,14 +112,16 @@ To configure a keyboard where each switch is connected to a separate pin and gro
["F1", "E6", "B0", "B2", "B3"], ["F1", "E6", "B0", "B2", "B3"],
["F5", "F0", "B1", "B7", "D2"], ["F5", "F0", "B1", "B7", "D2"],
["F6", "F7", "C7", "D5", "D3"], ["F6", "F7", "C7", "D5", "D3"],
["B5", "C6", "B6", "NO_PIN", "NO_PIN"] ["B5", "C6", "B6", null, null]
] ]
}, },
``` ```
### Layout macros Here, the matrix dimensions are inferred directly from the dimensions of the `matrix_pins.direct` array. Since there are no row or column pins to prescribe the matrix dimensions, you can arrange it however you like. Each "row" must contain the same number of "column"s; use `null` to fill in blank spaces, but try to minimize them.
Next is configuring Layout Macro(s). These define the physical arrangement of keys, and its position within the matrix that a switch are connected to. This allows you to have a physical arrangement of keys that differs from the wiring matrix. ### Layout Macros
Next is configuring layout macro(s). These define the physical arrangement of keys, and their position within the matrix that switches are connected to. This allows you to have a physical arrangement of keys that differs from the wiring matrix.
```json ```json
"layouts": { "layouts": {
@ -143,14 +146,13 @@ Next is configuring Layout Macro(s). These define the physical arrangement of ke
] ]
} }
} }
``` ```
In the above example, In the above example,
* `LAYOUT_ortho_4x4` defines the name of the layout macro * `LAYOUT_ortho_4x4` defines the name of the layout macro
* It must conform to the [layout guidelines](hardware_keyboard_guidelines#keyboard-name-h) * It must conform to the [layout guidelines](hardware_keyboard_guidelines#keyboard-name-h)
* `"matrix": [0, 0]` defines the electrical position * `"matrix": [0, 0]` defines the matrix row and column that the key is associated with
::: tip ::: tip
See also: [Split Keyboard Layout Macro](features/split_keyboard#layout-macro) and [Matrix to Physical Layout](understanding_qmk#matrix-to-physical-layout-map). See also: [Split Keyboard Layout Macro](features/split_keyboard#layout-macro) and [Matrix to Physical Layout](understanding_qmk#matrix-to-physical-layout-map).
@ -158,9 +160,10 @@ See also: [Split Keyboard Layout Macro](features/split_keyboard#layout-macro) an
## Additional Configuration ## Additional Configuration
There are a lot of features that can be turned on or off, configured or tuned. Some of these have yet to be migrated over to [Data Driven Configuration](data_driven_config). The following sections cover the process for when an `info.json` option is unavailable. There are a lot of features that can be turned on or off, configured or tuned. Some of these have yet to be migrated over to [Data Driven Configuration](data_driven_config). The following sections cover the process for when a data-driven option is unavailable.
### Configuration Options ### Configuration Options
For available options for `config.h`, you should see the [Config Options](config_options#the-configh-file) page for more details. For available options for `config.h`, you should see the [Config Options](config_options#the-configh-file) page for more details.
### Build Options ### Build Options

View File

@ -20,6 +20,6 @@
The size of the transient EEPROM buffer size. The size of the transient EEPROM buffer size.
*/ */
#ifndef TRANSIENT_EEPROM_SIZE #ifndef TRANSIENT_EEPROM_SIZE
# include "eeconfig.h" # include "nvm_eeprom_eeconfig_internal.h"
# define TRANSIENT_EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO # define TRANSIENT_EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
#endif #endif

View File

@ -164,7 +164,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (record->event.pressed) { if (record->event.pressed) {
set_single_persistent_default_layer(MAC_B); set_single_persistent_default_layer(MAC_B);
keymap_config.no_gui = 0; keymap_config.no_gui = 0;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
case QK_RGB_MATRIX_TOGGLE: case QK_RGB_MATRIX_TOGGLE:

View File

@ -53,6 +53,22 @@ void board_init(void) {
SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP); SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP);
} }
uint32_t read_custom_config(void *data, uint32_t offset, uint32_t length) {
#ifdef VIA_ENABLE
return via_read_custom_config(data, offset, length);
#else
return eeconfig_read_kb_datablock(data, offset, length);
#endif
}
uint32_t write_custom_config(const void *data, uint32_t offset, uint32_t length) {
#ifdef VIA_ENABLE
return via_update_custom_config(data, offset, length);
#else
return eeconfig_update_kb_datablock(data, offset, length);
#endif
}
void keyboard_post_init_kb(void) { void keyboard_post_init_kb(void) {
/* /*
This is a workaround to some really weird behavior This is a workaround to some really weird behavior
@ -78,7 +94,7 @@ void custom_set_value(uint8_t *data) {
switch ( *value_id ) { switch ( *value_id ) {
case id_oled_default_mode: case id_oled_default_mode:
{ {
eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, value_data[0]); write_custom_config(&value_data[0], EEPROM_DEFAULT_OLED_OFFSET, 1);
break; break;
} }
case id_oled_mode: case id_oled_mode:
@ -92,7 +108,7 @@ void custom_set_value(uint8_t *data) {
uint8_t index = value_data[0]; uint8_t index = value_data[0];
uint8_t enable = value_data[1]; uint8_t enable = value_data[1];
enabled_encoder_modes = (enabled_encoder_modes & ~(1<<index)) | (enable<<index); enabled_encoder_modes = (enabled_encoder_modes & ~(1<<index)) | (enable<<index);
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes); write_custom_config(&enabled_encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
break; break;
} }
case id_encoder_custom: case id_encoder_custom:
@ -113,7 +129,8 @@ void custom_get_value(uint8_t *data) {
switch ( *value_id ) { switch ( *value_id ) {
case id_oled_default_mode: case id_oled_default_mode:
{ {
uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); uint8_t default_oled;
read_custom_config(&default_oled, EEPROM_DEFAULT_OLED_OFFSET, 1);
value_data[0] = default_oled; value_data[0] = default_oled;
break; break;
} }
@ -179,7 +196,6 @@ void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
} }
#endif #endif
void read_host_led_state(void) { void read_host_led_state(void) {
led_t led_state = host_keyboard_led_state(); led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) { if (led_state.num_lock) {
@ -290,25 +306,25 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
} }
void custom_config_reset(void){ void custom_config_reset(void){
void *p = (void*)(VIA_EEPROM_CUSTOM_CONFIG_ADDR); for(int i = 0; i < VIA_EEPROM_CUSTOM_CONFIG_SIZE; ++i) {
void *end = (void*)(VIA_EEPROM_CUSTOM_CONFIG_ADDR+VIA_EEPROM_CUSTOM_CONFIG_SIZE); uint8_t dummy = 0;
while ( p != end ) { write_custom_config(&dummy, i, 1);
eeprom_update_byte(p, 0);
++p;
} }
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, 0x1F);
uint8_t encoder_modes = 0x1F;
write_custom_config(&encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
} }
void custom_config_load(void){ void custom_config_load(void){
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
oled_mode = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); read_custom_config(&oled_mode, EEPROM_DEFAULT_OLED_OFFSET, 1);
enabled_encoder_modes = eeprom_read_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES); read_custom_config(&enabled_encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
#endif #endif
} }
// Called from via_init() if VIA_ENABLE // Called from via_init() if VIA_ENABLE
// Called from matrix_init_kb() if not VIA_ENABLE // Called from matrix_init_kb() if not VIA_ENABLE
void via_init_kb(void) void satisfaction_core_init(void)
{ {
// This checks both an EEPROM reset (from bootmagic lite, keycodes) // This checks both an EEPROM reset (from bootmagic lite, keycodes)
// and also firmware build date (from via_eeprom_is_valid()) // and also firmware build date (from via_eeprom_is_valid())
@ -326,8 +342,7 @@ void via_init_kb(void)
void matrix_init_kb(void) void matrix_init_kb(void)
{ {
#ifndef VIA_ENABLE #ifndef VIA_ENABLE
via_init_kb(); satisfaction_core_init();
via_eeprom_set_valid(true);
#endif // VIA_ENABLE #endif // VIA_ENABLE
rtcGetTime(&RTCD1, &last_timespec); rtcGetTime(&RTCD1, &last_timespec);
@ -335,6 +350,11 @@ void matrix_init_kb(void)
oled_request_wakeup(); oled_request_wakeup();
} }
#ifdef VIA_ENABLE
void via_init_kb(void) {
satisfaction_core_init();
}
#endif // VIA_ENABLE
void housekeeping_task_kb(void) { void housekeeping_task_kb(void) {
rtcGetTime(&RTCD1, &last_timespec); rtcGetTime(&RTCD1, &last_timespec);
@ -345,52 +365,3 @@ void housekeeping_task_kb(void) {
oled_request_repaint(); oled_request_repaint();
} }
} }
//
// In the case of VIA being disabled, we still need to check if
// keyboard level EEPROM memory is valid before loading.
// Thus these are copies of the same functions in VIA, since
// the backlight settings reuse VIA's EEPROM magic/version,
// and the ones in via.c won't be compiled in.
//
// Yes, this is sub-optimal, and is only here for completeness
// (i.e. catering to the 1% of people that want wilba.tech LED bling
// AND want persistent settings BUT DON'T want to use dynamic keymaps/VIA).
//
#ifndef VIA_ENABLE
bool via_eeprom_is_valid(void)
{
char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 &&
eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 &&
eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 );
}
// Sets VIA/keyboard level usage of EEPROM to valid/invalid
// Keyboard level code (eg. via_init_kb()) should not call this
void via_eeprom_set_valid(bool valid)
{
char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF);
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF);
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF);
}
void via_eeprom_reset(void)
{
// Set the VIA specific EEPROM state as invalid.
via_eeprom_set_valid(false);
// Set the TMK/QMK EEPROM state as invalid.
eeconfig_disable();
}
#endif // VIA_ENABLE

View File

@ -6,12 +6,14 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <hal.h>
#include "via.h" // only for EEPROM address #include "via.h" // only for EEPROM address
#include "satisfaction_keycodes.h" #include "satisfaction_keycodes.h"
#define EEPROM_ENABLED_ENCODER_MODES (VIA_EEPROM_CUSTOM_CONFIG_ADDR) #define EEPROM_ENABLED_ENCODER_MODES_OFFSET 0
#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1) #define EEPROM_DEFAULT_OLED_OFFSET 1
#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2) #define EEPROM_CUSTOM_ENCODER_OFFSET 2
enum s75_keyboard_value_id { enum s75_keyboard_value_id {
id_encoder_modes = 1, id_encoder_modes = 1,
@ -94,3 +96,6 @@ void oled_request_repaint(void);
bool oled_task_needs_to_repaint(void); bool oled_task_needs_to_repaint(void);
void custom_config_load(void); void custom_config_load(void);
uint32_t read_custom_config(void *data, uint32_t offset, uint32_t length);
uint32_t write_custom_config(const void *data, uint32_t offset, uint32_t length);

View File

@ -215,10 +215,13 @@ uint16_t handle_encoder_press(void){
uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){ uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); uint32_t offset = EEPROM_CUSTOM_ENCODER_OFFSET + (encoder_idx * 6) + (behavior * 2);
//big endian //big endian
uint16_t keycode = eeprom_read_byte(addr) << 8; uint8_t hi, lo;
keycode |= eeprom_read_byte(addr + 1); read_custom_config(&hi, offset+0, 1);
read_custom_config(&lo, offset+1, 1);
uint16_t keycode = hi << 8;
keycode |= lo;
return keycode; return keycode;
#else #else
return 0; return 0;
@ -227,8 +230,10 @@ uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){
void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code){ void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code){
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); uint32_t offset = EEPROM_CUSTOM_ENCODER_OFFSET + (encoder_idx * 6) + (behavior * 2);
eeprom_update_byte(addr, (uint8_t)(new_code >> 8)); uint8_t hi = new_code >> 8;
eeprom_update_byte(addr + 1, (uint8_t)(new_code & 0xFF)); uint8_t lo = new_code & 0xFF;
write_custom_config(&hi, offset+0, 1);
write_custom_config(&lo, offset+1, 1);
#endif #endif
} }

View File

@ -8,7 +8,6 @@
#include "matrix.h" #include "matrix.h"
#include "led.h" #include "led.h"
#include "host.h" #include "host.h"
#include "oled_driver.h"
#include "progmem.h" #include "progmem.h"
#include <stdio.h> #include <stdio.h>
@ -16,6 +15,7 @@ void draw_default(void);
void draw_clock(void); void draw_clock(void);
#ifdef OLED_ENABLE #ifdef OLED_ENABLE
#include "oled_driver.h"
oled_rotation_t oled_init_kb(oled_rotation_t rotation) { return OLED_ROTATION_0; } oled_rotation_t oled_init_kb(oled_rotation_t rotation) { return OLED_ROTATION_0; }

View File

@ -60,6 +60,14 @@
"resync": true "resync": true
} }
}, },
"encoder": {
"rotary": [
{"pin_a": "B12", "pin_b": "B11", "resolution": 2},
{"pin_a": "B12", "pin_b": "B11", "resolution": 2},
{"pin_a": "B12", "pin_b": "B11", "resolution": 2},
{"pin_a": "B12", "pin_b": "B11", "resolution": 2}
]
},
"layouts": { "layouts": {
"LAYOUT_default": { "LAYOUT_default": {
"layout": [ "layout": [

View File

@ -44,3 +44,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
) )
}; };
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = { ENCODER_CCW_CW(KC_MS_WH_UP, KC_MS_WH_DOWN), ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(UG_HUED, UG_HUEU), ENCODER_CCW_CW(UG_SATD, UG_SATU) },
[1] = { ENCODER_CCW_CW(UG_VALD, UG_VALU), ENCODER_CCW_CW(UG_SPDD, UG_SPDU), ENCODER_CCW_CW(UG_PREV, UG_NEXT), ENCODER_CCW_CW(KC_RIGHT, KC_LEFT) },
};
#endif

View File

@ -0,0 +1,2 @@
ENCODER_ENABLE = yes
ENCODER_MAP_ENABLE = yes

View File

@ -0,0 +1,40 @@
// Copyright 2024 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
#if defined(ENCODER_ENABLE) || defined(ENCODER_MAP_ENABLE)
# if !defined(ENCODER_SETTLE_PIN_STATE_DELAY_US)
# define ENCODER_SETTLE_PIN_STATE_DELAY_US 2
# endif
static pin_t matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
void encoder_driver_task(void) {
// Set all relevant rows to output, which is different to the matrix expectations
for (uint8_t i = 0; i < 4; i++) {
gpio_set_pin_output(matrix_row_pins[i]);
}
// Read each encoder
for (uint8_t i = 0; i < 4; i++) {
// Set the row pin low for the corresponding encoder...
for (uint8_t j = 0; j < 4; j++) {
gpio_write_pin(matrix_row_pins[j], (i == j) ? 0 : 1);
}
// ...and let them settle.
wait_us(ENCODER_SETTLE_PIN_STATE_DELAY_US);
// Run the normal encoder handling
extern void encoder_quadrature_handle_read(uint8_t index, uint8_t pin_a_state, uint8_t pin_b_state);
extern uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b);
encoder_quadrature_handle_read(i, encoder_quadrature_read_pin(i, false), encoder_quadrature_read_pin(i, true));
}
// Set all rows back to input-high as per matrix expectations
for (uint8_t i = 0; i < 4; i++) {
gpio_set_pin_input_high(matrix_row_pins[i]);
}
}
#endif // defined(ENCODER_ENABLE) || defined(ENCODER_MAP_ENABLE)

View File

@ -42,4 +42,7 @@
// 6 for 3x custom encoder settings, left, right, and press (18 bytes) // 6 for 3x custom encoder settings, left, right, and press (18 bytes)
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 20 #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 20
// And if VIA isn't enabled, fall back to using standard QMK for configuration
#ifndef VIA_ENABLE
#define EECONFIG_KB_DATA_SIZE VIA_EEPROM_CUSTOM_CONFIG_SIZE
#endif

View File

@ -40,5 +40,10 @@
// 6 for 3x custom encoder settings, left, right, and press (18 bytes) // 6 for 3x custom encoder settings, left, right, and press (18 bytes)
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 20 #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 20
// And if VIA isn't enabled, fall back to using standard QMK for configuration
#ifndef VIA_ENABLE
#define EECONFIG_KB_DATA_SIZE VIA_EEPROM_CUSTOM_CONFIG_SIZE
#endif
// VIA lighting is handled by the keyboard-level code // VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE #define VIA_CUSTOM_LIGHTING_ENABLE

View File

@ -36,7 +36,7 @@ void eeconfig_init_kb(void) {
} }
} }
// Write default value to EEPROM now // Write default value to EEPROM now
eeconfig_update_kb_datablock(&eeprom_ec_config); eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
eeconfig_init_user(); eeconfig_init_user();
} }
@ -44,7 +44,7 @@ void eeconfig_init_kb(void) {
// On Keyboard startup // On Keyboard startup
void keyboard_post_init_kb(void) { void keyboard_post_init_kb(void) {
// Read custom menu variables from memory // Read custom menu variables from memory
eeconfig_read_kb_datablock(&eeprom_ec_config); eeconfig_read_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
// Set runtime values to EEPROM values // Set runtime values to EEPROM values
ec_config.actuation_mode = eeprom_ec_config.actuation_mode; ec_config.actuation_mode = eeprom_ec_config.actuation_mode;

View File

@ -1,26 +0,0 @@
/* Copyright 2023 Cipulot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "eeprom.h"
#if (EECONFIG_KB_DATA_SIZE) > 0
# define EEPROM_KB_PARTIAL_UPDATE(__struct, __field) eeprom_update_block(&(__struct.__field), (void *)((void *)(EECONFIG_KB_DATABLOCK) + offsetof(typeof(__struct), __field)), sizeof(__struct.__field))
#endif
#if (EECONFIG_USER_DATA_SIZE) > 0
# define EEPROM_USER_PARTIAL_UPDATE(__struct, __field) eeprom_update_block(&(__struct.__field), (void *)((void *)(EECONFIG_USER_DATABLOCK) + offsetof(typeof(__struct), __field)), sizeof(__struct.__field))
#endif

View File

@ -73,7 +73,7 @@ void via_config_set_value(uint8_t *data) {
uprintf("# Actuation Mode: Rapid Trigger #\n"); uprintf("# Actuation Mode: Rapid Trigger #\n");
uprintf("#################################\n"); uprintf("#################################\n");
} }
EEPROM_KB_PARTIAL_UPDATE(eeprom_ec_config, actuation_mode); eeconfig_update_kb_datablock_field(eeprom_ec_config, actuation_mode);
break; break;
} }
case id_mode_0_actuation_threshold: { case id_mode_0_actuation_threshold: {
@ -293,7 +293,7 @@ void ec_save_threshold_data(uint8_t option) {
ec_rescale_values(3); ec_rescale_values(3);
ec_rescale_values(4); ec_rescale_values(4);
} }
eeconfig_update_kb_datablock(&eeprom_ec_config); eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
uprintf("####################################\n"); uprintf("####################################\n");
uprintf("# New thresholds applied and saved #\n"); uprintf("# New thresholds applied and saved #\n");
uprintf("####################################\n"); uprintf("####################################\n");
@ -321,7 +321,7 @@ void ec_save_bottoming_reading(void) {
ec_rescale_values(2); ec_rescale_values(2);
ec_rescale_values(3); ec_rescale_values(3);
ec_rescale_values(4); ec_rescale_values(4);
eeconfig_update_kb_datablock(&eeprom_ec_config); eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
} }
// Show the calibration data // Show the calibration data

View File

@ -44,7 +44,7 @@ void eeconfig_init_kb(void) {
} }
} }
// Write default value to EEPROM now // Write default value to EEPROM now
eeconfig_update_kb_datablock(&eeprom_ec_config); eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
eeconfig_init_user(); eeconfig_init_user();
} }
@ -52,7 +52,7 @@ void eeconfig_init_kb(void) {
// On Keyboard startup // On Keyboard startup
void keyboard_post_init_kb(void) { void keyboard_post_init_kb(void) {
// Read custom menu variables from memory // Read custom menu variables from memory
eeconfig_read_kb_datablock(&eeprom_ec_config); eeconfig_read_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
// Set runtime values to EEPROM values // Set runtime values to EEPROM values
ec_config.actuation_mode = eeprom_ec_config.actuation_mode; ec_config.actuation_mode = eeprom_ec_config.actuation_mode;

View File

@ -44,7 +44,7 @@ void eeconfig_init_kb(void) {
} }
} }
// Write default value to EEPROM now // Write default value to EEPROM now
eeconfig_update_kb_datablock(&eeprom_ec_config); eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
eeconfig_init_user(); eeconfig_init_user();
} }
@ -52,7 +52,7 @@ void eeconfig_init_kb(void) {
// On Keyboard startup // On Keyboard startup
void keyboard_post_init_kb(void) { void keyboard_post_init_kb(void) {
// Read custom menu variables from memory // Read custom menu variables from memory
eeconfig_read_kb_datablock(&eeprom_ec_config); eeconfig_read_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
// Set runtime values to EEPROM values // Set runtime values to EEPROM values
ec_config.actuation_mode = eeprom_ec_config.actuation_mode; ec_config.actuation_mode = eeprom_ec_config.actuation_mode;

View File

@ -240,9 +240,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
break; break;

View File

@ -329,9 +329,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
break; break;

View File

@ -0,0 +1,10 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include_next <board.h>
#undef AT32F415KB
#define AT32F415RC

View File

@ -0,0 +1,10 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define ADC_PIN A0
#define BACKLIGHT_PWM_DRIVER PWMD5
#define BACKLIGHT_PWM_CHANNEL 1

View File

@ -0,0 +1,13 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define HAL_USE_ADC TRUE
#define HAL_USE_I2C TRUE
#define HAL_USE_PWM TRUE
#include_next <halconf.h>

View File

@ -0,0 +1,20 @@
{
"keyboard_name": "Onekey AT-START-F415",
"processor": "AT32F415",
"bootloader": "at32-dfu",
"usb": {
"shared_endpoint": {
"keyboard": true
}
},
"matrix_pins": {
"cols": ["B3"],
"rows": ["B4"]
},
"backlight": {
"pin": "A0"
},
"ws2812": {
"pin": "B0"
}
}

View File

@ -0,0 +1,16 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include_next <mcuconf.h>
#undef AT32_ADC_USE_ADC1
#define AT32_ADC_USE_ADC1 TRUE
#undef AT32_I2C_USE_I2C1
#define AT32_I2C_USE_I2C1 TRUE
#undef AT32_PWM_USE_TMR5
#define AT32_PWM_USE_TMR5 TRUE

View File

@ -0,0 +1,3 @@
# Artery AT-START-F415 Board Onekey
To trigger keypress, short together pins *B3* and *B4*.

View File

@ -199,9 +199,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
break; break;

View File

@ -32,7 +32,7 @@ void set_mac_mode_kb(bool macmode) {
* https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81 * https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81
*/ */
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode; keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
void matrix_init_kb(void) { void matrix_init_kb(void) {

View File

@ -27,7 +27,7 @@ void set_mac_mode(bool macmode) {
* https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81 * https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81
*/ */
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode; keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
#ifdef DIP_SWITCH_ENABLE #ifdef DIP_SWITCH_ENABLE

View File

@ -27,7 +27,7 @@ void set_mac_mode(bool macmode) {
* https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81 * https://github.com/qmk/qmk_firmware/blob/fb4a6ad30ea7a648acd59793ed4a30c3a8d8dc32/quantum/process_keycode/process_magic.c#L80-L81
*/ */
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode; keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = !macmode;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
#ifdef DIP_SWITCH_ENABLE #ifdef DIP_SWITCH_ENABLE

View File

@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <lib/lib8tion/lib8tion.h> #include <lib/lib8tion/lib8tion.h>
#include "eeconfig.h"
#define LED_TRAIL 10 #define LED_TRAIL 10
@ -105,7 +106,7 @@ static void swirl_set_color(hsv_t hsv) {
traverse_matrix(); traverse_matrix();
if (!(top <= bottom && left <= right)) { if (!(top <= bottom && left <= right)) {
eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); eeconfig_read_rgb_matrix(&rgb_matrix_config);
rgb_matrix_mode_noeeprom(rgb_matrix_config.mode); rgb_matrix_mode_noeeprom(rgb_matrix_config.mode);
return; return;
} }

View File

@ -20,3 +20,5 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND #define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC #define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -20,3 +20,5 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND #define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC #define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -317,7 +317,7 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
} }
if(active){ if(active){
keymap_config.no_gui = 0; keymap_config.no_gui = 0;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return true; return true;
} }

View File

@ -472,9 +472,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
case EXT_PLV: case EXT_PLV:

View File

@ -16,3 +16,5 @@
#pragma once #pragma once
#define IS31FL3733_I2C_ADDRESS_1 IS31FL3733_I2C_ADDRESS_GND_GND #define IS31FL3733_I2C_ADDRESS_1 IS31FL3733_I2C_ADDRESS_GND_GND
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -17,3 +17,5 @@
#pragma once #pragma once
#define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND #define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -2,3 +2,5 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND #define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_SDA #define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_SDA
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -2,3 +2,5 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND #define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_SDA #define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_SDA
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -190,7 +190,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
set_single_persistent_default_layer(MAC_B); set_single_persistent_default_layer(MAC_B);
layer_state_set(1<<MAC_B); layer_state_set(1<<MAC_B);
keymap_config.no_gui = 0; keymap_config.no_gui = 0;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
case QK_RGB_MATRIX_TOGGLE: case QK_RGB_MATRIX_TOGGLE:

View File

@ -163,7 +163,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (record->event.pressed) { if (record->event.pressed) {
set_single_persistent_default_layer(MAC_B); set_single_persistent_default_layer(MAC_B);
keymap_config.no_gui = 0; keymap_config.no_gui = 0;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
case GU_TOGG: case GU_TOGG:

View File

@ -1,5 +1,6 @@
#include "omnikeyish.h" #include "omnikeyish.h"
#include <string.h> #include <string.h>
#include "eeprom.h"
dynamic_macro_t dynamic_macros[DYNAMIC_MACRO_COUNT]; dynamic_macro_t dynamic_macros[DYNAMIC_MACRO_COUNT];

View File

@ -18,3 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND #define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -18,3 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND #define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -233,9 +233,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
break; break;

View File

@ -270,9 +270,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
return false; return false;
break; break;

View File

@ -30,3 +30,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2 #define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2
#define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND #define IS31FL3741_I2C_ADDRESS_1 IS31FL3741_I2C_ADDRESS_GND
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include "keycode_lookup.h" #include "keycode_lookup.h"
#include "quantum_keycodes.h" #include "quantum_keycodes.h"
#include "keymap_us.h" #include "keymap_us.h"

View File

@ -214,9 +214,9 @@ void plover(keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
} }

View File

@ -214,9 +214,9 @@ void plover(keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
} }

View File

@ -214,9 +214,9 @@ void plover(keyrecord_t *record) {
if (!eeconfig_is_enabled()) { if (!eeconfig_is_enabled()) {
eeconfig_init(); eeconfig_init();
} }
keymap_config.raw = eeconfig_read_keymap(); eeconfig_read_keymap(&keymap_config);
keymap_config.nkro = 1; keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(&keymap_config);
} }
} }

View File

@ -16,6 +16,7 @@
*/ */
#include "quantum.h" #include "quantum.h"
#include "eeprom.h"
#include "usb_mux.h" #include "usb_mux.h"

View File

@ -12,7 +12,7 @@ bool is_keyboard_left(void) {
gpio_set_pin_input(SPLIT_HAND_PIN); gpio_set_pin_input(SPLIT_HAND_PIN);
return x; return x;
#elif defined(EE_HANDS) #elif defined(EE_HANDS)
return eeprom_read_byte(EECONFIG_HANDEDNESS); return eeconfig_read_handedness();
#endif #endif
return is_keyboard_master(); return is_keyboard_master();

View File

@ -33,7 +33,7 @@
// Called from via_init() if VIA_ENABLE // Called from via_init() if VIA_ENABLE
// Called from matrix_init_kb() if not VIA_ENABLE // Called from matrix_init_kb() if not VIA_ENABLE
void via_init_kb(void) void wt_main_init(void)
{ {
// This checks both an EEPROM reset (from bootmagic lite, keycodes) // This checks both an EEPROM reset (from bootmagic lite, keycodes)
// and also firmware build date (from via_eeprom_is_valid()) // and also firmware build date (from via_eeprom_is_valid())
@ -64,11 +64,9 @@ void via_init_kb(void)
void matrix_init_kb(void) void matrix_init_kb(void)
{ {
// If VIA is disabled, we still need to load backlight settings. // If VIA is disabled, we still need to load backlight settings.
// Call via_init_kb() the same way as via_init(), with setting // Call via_init_kb() the same way as via_init_kb() does.
// EEPROM valid afterwards.
#ifndef VIA_ENABLE #ifndef VIA_ENABLE
via_init_kb(); wt_main_init();
via_eeprom_set_valid(true);
#endif // VIA_ENABLE #endif // VIA_ENABLE
matrix_init_user(); matrix_init_user();
@ -109,6 +107,10 @@ void suspend_wakeup_init_kb(void)
// Moving this to the bottom of this source file is a workaround // Moving this to the bottom of this source file is a workaround
// for an intermittent compiler error for Atmel compiler. // for an intermittent compiler error for Atmel compiler.
#ifdef VIA_ENABLE #ifdef VIA_ENABLE
void via_init_kb(void) {
wt_main_init();
}
void via_custom_value_command_kb(uint8_t *data, uint8_t length) { void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
uint8_t *command_id = &(data[0]); uint8_t *command_id = &(data[0]);
uint8_t *channel_id = &(data[1]); uint8_t *channel_id = &(data[1]);
@ -159,50 +161,3 @@ void via_set_device_indication(uint8_t value)
} }
#endif // VIA_ENABLE #endif // VIA_ENABLE
//
// In the case of VIA being disabled, we still need to check if
// keyboard level EEPROM memory is valid before loading.
// Thus these are copies of the same functions in VIA, since
// the backlight settings reuse VIA's EEPROM magic/version,
// and the ones in via.c won't be compiled in.
//
// Yes, this is sub-optimal, and is only here for completeness
// (i.e. catering to the 1% of people that want wilba.tech LED bling
// AND want persistent settings BUT DON'T want to use dynamic keymaps/VIA).
//
#ifndef VIA_ENABLE
bool via_eeprom_is_valid(void)
{
char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 &&
eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 &&
eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 );
}
void via_eeprom_set_valid(bool valid)
{
char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF);
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF);
eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF);
}
void via_eeprom_reset(void)
{
// Set the VIA specific EEPROM state as invalid.
via_eeprom_set_valid(false);
// Set the TMK/QMK EEPROM state as invalid.
eeconfig_disable();
}
#endif // VIA_ENABLE

View File

@ -25,6 +25,8 @@
#include "progmem.h" #include "progmem.h"
#include "eeprom.h" #include "eeprom.h"
#include "nvm_eeprom_eeconfig_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
#include "nvm_eeprom_via_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
#include "via.h" // uses EEPROM address, lighting value IDs #include "via.h" // uses EEPROM address, lighting value IDs
#define MONO_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR) #define MONO_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)

View File

@ -66,6 +66,8 @@
#include "quantum/color.h" #include "quantum/color.h"
#include "eeprom.h" #include "eeprom.h"
#include "nvm_eeprom_eeconfig_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
#include "nvm_eeprom_via_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
#include "via.h" // uses EEPROM address, lighting value IDs #include "via.h" // uses EEPROM address, lighting value IDs
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR) #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)

View File

@ -18,3 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#define RGBLIGHT_DI_PIN E6 #define RGBLIGHT_DI_PIN E6
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -9,3 +9,5 @@
#define WORK_LOUDER_LED_PIN_1 B6 #define WORK_LOUDER_LED_PIN_1 B6
#define WORK_LOUDER_LED_PIN_2 B7 #define WORK_LOUDER_LED_PIN_2 B7
#define WORK_LOUDER_LED_PIN_3 B5 #define WORK_LOUDER_LED_PIN_3 B5
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -18,3 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#define RGBLIGHT_DI_PIN C7 #define RGBLIGHT_DI_PIN C7
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -5,3 +5,5 @@
#define RGBLIGHT_DI_PIN D2 #define RGBLIGHT_DI_PIN D2
#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_GRADIENT + 9 #define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_GRADIENT + 9
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -20,3 +20,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGBLIGHT_DI_PIN D2 #define RGBLIGHT_DI_PIN D2
#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_GRADIENT + 9 #define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_GRADIENT + 9
#define RGB_MATRIX_DISABLE_SHARED_KEYCODES

View File

@ -31,7 +31,7 @@ static void startup_animation_setleds(effect_params_t* params, bool dots) {
} else if (num == 0 || num == 1 || num == 2) { } else if (num == 0 || num == 1 || num == 2) {
return; return;
} else if (num >= 22) { } else if (num >= 22) {
eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); eeconfig_read_rgb_matrix(&rgb_matrix_config);
rgb_matrix_mode_noeeprom(rgb_matrix_config.mode); rgb_matrix_mode_noeeprom(rgb_matrix_config.mode);
return; return;
} }

View File

@ -8,7 +8,7 @@ from pathlib import Path
from dotty_dict import dotty from dotty_dict import dotty
from milc import cli from milc import cli
from milc.questions import choice, question from milc.questions import choice, question, yesno
from qmk.git import git_get_username from qmk.git import git_get_username
from qmk.json_schema import load_jsonschema from qmk.json_schema import load_jsonschema
@ -131,60 +131,70 @@ def _question(*args, **kwargs):
return ret return ret
def prompt_keyboard(): def prompt_heading_subheading(heading, subheading):
prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all} cli.log.info(f"{{fg_yellow}}{heading}{{style_reset_all}}")
For more infomation, see: cli.log.info(subheading)
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project
Keyboard Name? """
def prompt_keyboard():
prompt_heading_subheading("Name Your Keyboard Project", """For more information, see:
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project""")
errmsg = 'Keyboard already exists! Please choose a different name:' errmsg = 'Keyboard already exists! Please choose a different name:'
return _question(prompt, reprompt=errmsg, validate=lambda x: not keyboard(x).exists()) return _question("Keyboard Name?", reprompt=errmsg, validate=lambda x: not keyboard(x).exists())
def prompt_user(): def prompt_user():
prompt = """ prompt_heading_subheading("Attribution", "Used for maintainer, copyright, etc.")
{fg_yellow}Attribution{style_reset_all}
Used for maintainer, copyright, etc
Your GitHub Username? """ return question("Your GitHub Username?", default=git_get_username())
return question(prompt, default=git_get_username())
def prompt_name(def_name): def prompt_name(def_name):
prompt = """ prompt_heading_subheading("More Attribution", "Used for maintainer, copyright, etc.")
{fg_yellow}More Attribution{style_reset_all}
Used for maintainer, copyright, etc
Your Real Name? """ return question("Your Real Name?", default=def_name)
return question(prompt, default=def_name)
def prompt_layout(): def prompt_layout():
prompt = """ prompt_heading_subheading("Pick Base Layout", """As a starting point, one of the common layouts can be used to
{fg_yellow}Pick Base Layout{style_reset_all} bootstrap the process""")
As a starting point, one of the common layouts can be used to bootstrap the process
Default Layout? """
# avoid overwhelming user - remove some? # avoid overwhelming user - remove some?
filtered_layouts = [x for x in available_layouts if not any(xs in x for xs in ['_split', '_blocker', '_tsangan', '_f13'])] filtered_layouts = [x for x in available_layouts if not any(xs in x for xs in ['_split', '_blocker', '_tsangan', '_f13'])]
filtered_layouts.append("none of the above") filtered_layouts.append("none of the above")
return choice(prompt, filtered_layouts, default=len(filtered_layouts) - 1) return choice("Default Layout?", filtered_layouts, default=len(filtered_layouts) - 1)
def prompt_mcu_type():
prompt_heading_subheading(
"What Powers Your Project", """Is your board using a separate development board, such as a Pro Micro,
or is the microcontroller integrated onto the PCB?
For more information, see:
https://docs.qmk.fm/compatible_microcontrollers"""
)
return yesno("Using a Development Board?")
def prompt_dev_board():
prompt_heading_subheading("Select Development Board", """For more information, see:
https://docs.qmk.fm/compatible_microcontrollers""")
return choice("Development Board?", dev_boards, default=dev_boards.index("promicro"))
def prompt_mcu(): def prompt_mcu():
prompt = """ prompt_heading_subheading("Select Microcontroller", """For more information, see:
{fg_yellow}What Powers Your Project{style_reset_all} https://docs.qmk.fm/compatible_microcontrollers""")
For more infomation, see:
https://docs.qmk.fm/#/compatible_microcontrollers
MCU? """
# remove any options strictly used for compatibility # remove any options strictly used for compatibility
filtered_mcu = [x for x in (dev_boards + mcu_types) if not any(xs in x for xs in ['cortex', 'unknown'])] filtered_mcu = [x for x in mcu_types if not any(xs in x for xs in ['cortex', 'unknown'])]
return choice(prompt, filtered_mcu, default=filtered_mcu.index("atmega32u4")) return choice("Microcontroller?", filtered_mcu, default=filtered_mcu.index("atmega32u4"))
@cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name) @cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name)
@ -211,7 +221,11 @@ def new_keyboard(cli):
user_name = cli.config.new_keyboard.name if cli.config.new_keyboard.name else prompt_user() user_name = cli.config.new_keyboard.name if cli.config.new_keyboard.name else prompt_user()
real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name) real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name)
default_layout = cli.args.layout if cli.args.layout else prompt_layout() default_layout = cli.args.layout if cli.args.layout else prompt_layout()
mcu = cli.args.type if cli.args.type else prompt_mcu()
if cli.args.type:
mcu = cli.args.type
else:
mcu = prompt_dev_board() if prompt_mcu_type() else prompt_mcu()
config = {} config = {}
if mcu in dev_boards: if mcu in dev_boards:

View File

@ -1,5 +1,6 @@
"""This script automates the copying of the default keymap into your own keymap. """This script automates the copying of the default keymap into your own keymap.
""" """
import re
import shutil import shutil
from milc import cli from milc import cli
@ -13,6 +14,13 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.userspace import UserspaceDefs from qmk.userspace import UserspaceDefs
def validate_keymap_name(name):
"""Returns True if the given keymap name contains only a-z, 0-9 and underscore characters.
"""
regex = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_]+$')
return bool(regex.match(name))
def prompt_keyboard(): def prompt_keyboard():
prompt = """{fg_yellow}Select Keyboard{style_reset_all} prompt = """{fg_yellow}Select Keyboard{style_reset_all}
If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}. If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
@ -60,6 +68,10 @@ def new_keymap(cli):
cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!') cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
return False return False
if not validate_keymap_name(user_name):
cli.log.error('Keymap names must contain only {fg_cyan}a-z{fg_reset}, {fg_cyan}0-9{fg_reset} and {fg_cyan}_{fg_reset}! Please choose a different name.')
return False
if keymap_path_new.exists(): if keymap_path_new.exists():
cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.') cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
return False return False

View File

@ -60,9 +60,7 @@ def painter_convert_graphics(cli):
return return
# Work out the text substitutions for rendering the output data # Work out the text substitutions for rendering the output data
args_str = " ".join((f"--{arg} {getattr(cli.args, arg.replace('-', '_'))}" for arg in ["input", "output", "format", "no-rle", "no-deltas"])) subs = generate_subs(cli, out_bytes, image_metadata=metadata, command_name="painter_convert_graphics")
command = f"qmk painter-convert-graphics {args_str}"
subs = generate_subs(cli, out_bytes, image_metadata=metadata, command=command)
# Render and write the header file # Render and write the header file
header_text = render_header(subs) header_text = render_header(subs)

View File

@ -61,10 +61,8 @@ def painter_convert_font_image(cli):
return return
# Work out the text substitutions for rendering the output data # Work out the text substitutions for rendering the output data
args_str = " ".join((f"--{arg} {getattr(cli.args, arg.replace('-', '_'))}" for arg in ["input", "output", "no-ascii", "unicode-glyphs", "format", "no-rle"]))
command = f"qmk painter-convert-font-image {args_str}"
metadata = {"glyphs": _generate_font_glyphs_list(not cli.args.no_ascii, cli.args.unicode_glyphs)} metadata = {"glyphs": _generate_font_glyphs_list(not cli.args.no_ascii, cli.args.unicode_glyphs)}
subs = generate_subs(cli, out_bytes, font_metadata=metadata, command=command) subs = generate_subs(cli, out_bytes, font_metadata=metadata, command_name="painter_convert_font_image")
# Render and write the header file # Render and write the header file
header_text = render_header(subs) header_text = render_header(subs)

View File

@ -29,6 +29,7 @@ def _convert_macros(via_macros):
if len(via_macros) == 0: if len(via_macros) == 0:
return list() return list()
split_regex = re.compile(r'(}\,)|(\,{)') split_regex = re.compile(r'(}\,)|(\,{)')
macro_group_regex = re.compile(r'({.+?})')
macros = list() macros = list()
for via_macro in via_macros: for via_macro in via_macros:
# Split VIA macro to its elements # Split VIA macro to its elements
@ -38,13 +39,28 @@ def _convert_macros(via_macros):
macro_data = list() macro_data = list()
for m in macro: for m in macro:
if '{' in m or '}' in m: if '{' in m or '}' in m:
# Found keycode(s) # Split macro groups
keycodes = m.split(',') macro_groups = macro_group_regex.findall(m)
# Remove whitespaces and curly braces from around keycodes for macro_group in macro_groups:
keycodes = list(map(lambda s: s.strip(' {}'), keycodes)) # Remove whitespaces and curly braces from around group
# Remove the KC prefix macro_group = macro_group.strip(' {}')
keycodes = list(map(lambda s: s.replace('KC_', ''), keycodes))
macro_data.append({"action": "tap", "keycodes": keycodes}) macro_action = 'tap'
macro_keycodes = []
if macro_group[0] == '+':
macro_action = 'down'
macro_keycodes.append(macro_group[1:])
elif macro_group[0] == '-':
macro_action = 'up'
macro_keycodes.append(macro_group[1:])
else:
macro_keycodes.extend(macro_group.split(',') if ',' in macro_group else [macro_group])
# Remove the KC prefixes
macro_keycodes = list(map(lambda s: s.replace('KC_', ''), macro_keycodes))
macro_data.append({"action": macro_action, "keycodes": macro_keycodes})
else: else:
# Found text # Found text
macro_data.append(m) macro_data.append(m)
@ -54,13 +70,13 @@ def _convert_macros(via_macros):
def _fix_macro_keys(keymap_data): def _fix_macro_keys(keymap_data):
macro_no = re.compile(r'MACRO0?([0-9]{1,2})') macro_no = re.compile(r'MACRO0?\(([0-9]{1,2})\)')
for i in range(0, len(keymap_data)): for i in range(0, len(keymap_data)):
for j in range(0, len(keymap_data[i])): for j in range(0, len(keymap_data[i])):
kc = keymap_data[i][j] kc = keymap_data[i][j]
m = macro_no.match(kc) m = macro_no.match(kc)
if m: if m:
keymap_data[i][j] = f'MACRO_{m.group(1)}' keymap_data[i][j] = f'MC_{m.group(1)}'
return keymap_data return keymap_data

View File

@ -22,7 +22,7 @@ QMK_FIRMWARE_UPSTREAM = 'qmk/qmk_firmware'
MAX_KEYBOARD_SUBFOLDERS = 5 MAX_KEYBOARD_SUBFOLDERS = 5
# Supported processor types # Supported processor types
CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32H723', 'STM32H733', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95' CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32H723', 'STM32H733', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95', 'AT32F415'
LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None
VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85'
@ -55,6 +55,7 @@ MCU2BOOTLOADER = {
"GD32VF103": "gd32v-dfu", "GD32VF103": "gd32v-dfu",
"WB32F3G71": "wb32-dfu", "WB32F3G71": "wb32-dfu",
"WB32FQ95": "wb32-dfu", "WB32FQ95": "wb32-dfu",
"AT32F415": "at32-dfu",
"atmega16u2": "atmel-dfu", "atmega16u2": "atmel-dfu",
"atmega32u2": "atmel-dfu", "atmega32u2": "atmel-dfu",
"atmega16u4": "atmel-dfu", "atmega16u4": "atmel-dfu",
@ -93,6 +94,7 @@ BOOTLOADER_VIDS_PIDS = {
'apm32-dfu': {("314b", "0106")}, 'apm32-dfu': {("314b", "0106")},
'gd32v-dfu': {("28e9", "0189")}, 'gd32v-dfu': {("28e9", "0189")},
'wb32-dfu': {("342d", "dfa0")}, 'wb32-dfu': {("342d", "dfa0")},
'at32-dfu': {("2e3c", "df11")},
'bootloadhid': {("16c0", "05df")}, 'bootloadhid': {("16c0", "05df")},
'usbasploader': {("16c0", "05dc")}, 'usbasploader': {("16c0", "05dc")},
'usbtinyisp': {("1782", "0c9f")}, 'usbtinyisp': {("1782", "0c9f")},

View File

@ -3,6 +3,7 @@
import datetime import datetime
import math import math
import re import re
from pathlib import Path
from string import Template from string import Template
from PIL import Image, ImageOps from PIL import Image, ImageOps
@ -137,10 +138,31 @@ def _render_image_metadata(metadata):
return "\n".join(lines) return "\n".join(lines)
def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command): def command_args_str(cli, command_name):
"""Given a command name, introspect milc to get the arguments passed in."""
args = {}
max_length = 0
for arg_name, was_passed in cli.args_passed[command_name].items():
max_length = max(max_length, len(arg_name))
val = getattr(cli.args, arg_name.replace("-", "_"))
# do not leak full paths, keep just file name
if isinstance(val, Path):
val = val.name
args[arg_name] = val
return "\n".join(f"// {arg_name.ljust(max_length)} | {val}" for arg_name, val in args.items())
def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command_name):
if font_metadata is not None and image_metadata is not None: if font_metadata is not None and image_metadata is not None:
raise ValueError("Cant generate subs for font and image at the same time") raise ValueError("Cant generate subs for font and image at the same time")
args = command_args_str(cli, command_name)
subs = { subs = {
"year": datetime.date.today().strftime("%Y"), "year": datetime.date.today().strftime("%Y"),
"input_file": cli.args.input.name, "input_file": cli.args.input.name,
@ -148,7 +170,8 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
"byte_count": len(out_bytes), "byte_count": len(out_bytes),
"bytes_lines": render_bytes(out_bytes), "bytes_lines": render_bytes(out_bytes),
"format": cli.args.format, "format": cli.args.format,
"generator_command": command, "generator_command": command_name.replace("_", "-"),
"command_args": args,
} }
if font_metadata is not None: if font_metadata is not None:
@ -167,7 +190,7 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
subs.update({ subs.update({
"generated_type": "image", "generated_type": "image",
"var_prefix": "gfx", "var_prefix": "gfx",
"generator_command": command, "generator_command": command_name,
"metadata": _render_image_metadata(image_metadata), "metadata": _render_image_metadata(image_metadata),
}) })
@ -183,7 +206,8 @@ license_template = """\
// Copyright ${year} QMK -- generated source code only, ${generated_type} retains original copyright // Copyright ${year} QMK -- generated source code only, ${generated_type} retains original copyright
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// This file was auto-generated by `${generator_command}` // This file was auto-generated by `${generator_command}` with arguments:
${command_args}
""" """

View File

@ -0,0 +1,101 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
ChibiOS - Copyright (C) 2023..2024 HorrorTroll
ChibiOS - Copyright (C) 2023..2024 Zhaqian
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "hal.h"
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/**
* @brief PAL setup.
* @details Digital I/O ports static configuration as defined in @p board.h.
* This variable is used by the HAL when initializing the PAL driver.
*/
#if HAL_USE_PAL || defined(__DOXYGEN__)
const PALConfig pal_default_config =
{
{VAL_GPIOAODT, VAL_GPIOACFGLR, VAL_GPIOACFGHR},
{VAL_GPIOBODT, VAL_GPIOBCFGLR, VAL_GPIOBCFGHR},
#if AT32_HAS_GPIOC
{VAL_GPIOCODT, VAL_GPIOCCFGLR, VAL_GPIOCCFGHR},
#endif
{VAL_GPIODODT, VAL_GPIODCFGLR, VAL_GPIODCFGHR},
#if AT32_HAS_GPIOF
{VAL_GPIOFODT, VAL_GPIOFCFGLR, VAL_GPIOFCFGHR},
#endif
};
#endif
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Early initialization code.
* @details System clocks are initialized before everything else.
*/
void __early_init(void) {
at32_clock_init();
}
#if HAL_USE_SDC || defined(__DOXYGEN__)
/**
* @brief SDC card detection.
*/
bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
static bool last_status = false;
if (blkIsTransferring(sdcp))
return last_status;
return last_status = (bool)palReadPad(GPIOC, GPIOC_PIN11);
}
/**
* @brief SDC card write protection detection.
*/
bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
(void)sdcp;
return false;
}
#endif /* HAL_USE_SDC */
/**
* @brief Board-specific initialization code.
* @note You can add your board-specific code here.
*/
void boardInit(void) {
IOMUX->REMAP |= IOMUX_REMAP_SWJTAG_MUX_JTAGDIS;
}

View File

@ -0,0 +1,207 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
ChibiOS - Copyright (C) 2023..2024 HorrorTroll
ChibiOS - Copyright (C) 2023..2024 Zhaqian
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _BOARD_H_
#define _BOARD_H_
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*
* Setup for a Generic AT32F415 board.
*/
/*
* Board identifier.
*/
#define BOARD_GENERIC_AT32_F415XX
#define BOARD_NAME "GENERIC AT32F415 board"
/*
* Board oscillators-related settings.
*/
#if !defined(AT32_LEXTCLK)
#define AT32_LEXTCLK 32768
#endif
#if !defined(AT32_HEXTCLK)
#define AT32_HEXTCLK 8000000
#endif
/*
* MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
*/
#define AT32F415KB
/*
* IO pins assignments.
*/
#define GPIOA_PIN0 0U
#define GPIOA_PIN1 1U
#define GPIOA_PIN2 2U
#define GPIOA_PIN3 3U
#define GPIOA_PIN4 4U
#define GPIOA_PIN5 5U
#define GPIOA_PIN6 6U
#define GPIOA_PIN7 7U
#define GPIOA_PIN8 8U
#define GPIOA_PIN9 9U
#define GPIOA_PIN10 10U
#define GPIOA_PIN11 11U
#define GPIOA_PIN12 12U
#define GPIOA_SWDIO 13U
#define GPIOA_SWCLK 14U
#define GPIOA_PIN15 15U
#define GPIOB_PIN0 0U
#define GPIOB_PIN1 1U
#define GPIOB_PIN2 2U
#define GPIOB_PIN3 3U
#define GPIOB_PIN4 4U
#define GPIOB_PIN5 5U
#define GPIOB_PIN6 6U
#define GPIOB_PIN7 7U
#define GPIOB_PIN8 8U
#define GPIOB_PIN9 9U
#define GPIOB_PIN10 10U
#define GPIOB_PIN11 11U
#define GPIOB_PIN12 12U
#define GPIOB_PIN13 13U
#define GPIOB_PIN14 14U
#define GPIOB_PIN15 15U
#define GPIOC_PIN0 0U
#define GPIOC_PIN1 1U
#define GPIOC_PIN2 2U
#define GPIOC_PIN3 3U
#define GPIOC_PIN4 4U
#define GPIOC_PIN5 5U
#define GPIOC_PIN6 6U
#define GPIOC_PIN7 7U
#define GPIOC_PIN8 8U
#define GPIOC_PIN9 9U
#define GPIOC_PIN10 10U
#define GPIOC_PIN11 11U
#define GPIOC_PIN12 12U
#define GPIOC_PIN13 13U
#define GPIOC_PIN14 14U
#define GPIOC_PIN15 15U
#define GPIOD_HEXT_IN 0U
#define GPIOD_HEXT_OUT 1U
#define GPIOD_PIN2 2U
#define GPIOF_PIN4 4U
#define GPIOF_PIN5 5U
#define GPIOF_PIN6 6U
#define GPIOF_PIN7 7U
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*
* I/O ports initial setup, this configuration is established soon after reset
* in the initialization code.
*
* The digits have the following meaning:
* 0 - Analog input.
* 1 - Push Pull output 10MHz.
* 2 - Push Pull output 2MHz.
* 3 - Push Pull output 50MHz.
* 4 - Digital input.
* 5 - Open Drain output 10MHz.
* 6 - Open Drain output 2MHz.
* 7 - Open Drain output 50MHz.
* 8 - Digital input with Pull-Up or Pull-Down resistor depending on ODT.
* 9 - Alternate Push Pull output 10MHz.
* A - Alternate Push Pull output 2MHz.
* B - Alternate Push Pull output 50MHz.
* C - Reserved.
* D - Alternate Open Drain output 10MHz.
* E - Alternate Open Drain output 2MHz.
* F - Alternate Open Drain output 50MHz.
* Please refer to the AT32 Reference Manual for details.
*/
/*
* Port A setup.
*/
#define VAL_GPIOACFGLR 0x88888B88 /* PA7...PA0 */
#define VAL_GPIOACFGHR 0x888888B8 /* PA15...PA8 */
#define VAL_GPIOAODT 0xFFFFFFFF
/*
* Port B setup.
*/
#define VAL_GPIOBCFGLR 0x88888888 /* PB7...PB0 */
#define VAL_GPIOBCFGHR 0x88888888 /* PB15...PB8 */
#define VAL_GPIOBODT 0xFFFFFFFF
/*
* Port C setup.
*/
#define VAL_GPIOCCFGLR 0x88888888 /* PC7...PC0 */
#define VAL_GPIOCCFGHR 0x88888888 /* PC15...PC8 */
#define VAL_GPIOCODT 0xFFFFFFFF
/*
* Port D setup.
* Everything input with pull-up except:
* PD0 - Normal input (GPIOD_HEXT_IN).
* PD1 - Normal input (GPIOD_HEXT_OUT).
*/
#define VAL_GPIODCFGLR 0x88888844 /* PD7...PD0 */
#define VAL_GPIODCFGHR 0x88888888 /* PD15...PD8 */
#define VAL_GPIODODT 0xFFFFFFFF
/*
* Port F setup.
*/
#define VAL_GPIOFCFGLR 0x88888888 /* PF7...PF0 */
#define VAL_GPIOFCFGHR 0x88888888 /* PF15...PF8 */
#define VAL_GPIOFODT 0xFFFFFFFF
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
void boardInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _FROM_ASM_ */
#endif /* _BOARD_H_ */

View File

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

View File

@ -0,0 +1,13 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define BOARD_OTG_VBUSIG
#define USB_ENDPOINTS_ARE_REORDERABLE
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE
#endif

View File

@ -0,0 +1,236 @@
/*
ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio
ChibiOS - Copyright (C) 2023..2024 HorrorTroll
ChibiOS - Copyright (C) 2023..2024 Zhaqian
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MCUCONF_H
#define MCUCONF_H
/*
* AT32F415 drivers configuration.
* The following settings override the default settings present in
* the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h.
*
* IRQ priorities:
* 15...0 Lowest...Highest.
*
* DMA priorities:
* 0...3 Lowest...Highest.
*/
#define AT32F415_MCUCONF
/*
* General settings.
*/
#define AT32_NO_INIT FALSE
/*
* HAL driver system settings.
*/
#define AT32_HICK_ENABLED TRUE
#define AT32_LICK_ENABLED FALSE
#define AT32_HEXT_ENABLED TRUE
#define AT32_LEXT_ENABLED FALSE
#define AT32_SCLKSEL AT32_SCLKSEL_PLL
#define AT32_PLLRCS AT32_PLLRCS_HEXT
#define AT32_PLLHEXTDIV AT32_PLLHEXTDIV_DIV1
#define AT32_PLLCFGEN AT32_PLLCFGEN_SOLID
#define AT32_PLLMULT_VALUE 18
#define AT32_PLL_FR_VALUE 4
#define AT32_PLL_MS_VALUE 1
#define AT32_PLL_NS_VALUE 72
#define AT32_AHBDIV AT32_AHBDIV_DIV1
#define AT32_APB1DIV AT32_APB1DIV_DIV2
#define AT32_APB2DIV AT32_APB2DIV_DIV2
#define AT32_ADCDIV AT32_ADCDIV_DIV4
#define AT32_USB_CLOCK_REQUIRED TRUE
#define AT32_USBDIV AT32_USBDIV_DIV3
#define AT32_CLKOUT_SEL AT32_CLKOUT_SEL_NOCLOCK
#define AT32_CLKOUTDIV AT32_CLKOUTDIV_DIV1
#define AT32_ERTCSEL AT32_ERTCSEL_HEXTDIV
#define AT32_PVM_ENABLE FALSE
#define AT32_PVMSEL AT32_PVMSEL_LEV1
/*
* IRQ system settings.
*/
#define AT32_IRQ_EXINT0_PRIORITY 6
#define AT32_IRQ_EXINT1_PRIORITY 6
#define AT32_IRQ_EXINT2_PRIORITY 6
#define AT32_IRQ_EXINT3_PRIORITY 6
#define AT32_IRQ_EXINT4_PRIORITY 6
#define AT32_IRQ_EXINT5_9_PRIORITY 6
#define AT32_IRQ_EXINT10_15_PRIORITY 6
#define AT32_IRQ_EXINT16_PRIORITY 6
#define AT32_IRQ_EXINT17_PRIORITY 15
#define AT32_IRQ_EXINT18_PRIORITY 6
#define AT32_IRQ_EXINT19_PRIORITY 6
#define AT32_IRQ_EXINT20_PRIORITY 6
#define AT32_IRQ_EXINT21_PRIORITY 15
#define AT32_IRQ_EXINT22_PRIORITY 15
#define AT32_IRQ_TMR1_BRK_TMR9_PRIORITY 7
#define AT32_IRQ_TMR1_OVF_TMR10_PRIORITY 7
#define AT32_IRQ_TMR1_HALL_TMR11_PRIORITY 7
#define AT32_IRQ_TMR1_CH_PRIORITY 7
#define AT32_IRQ_TMR2_PRIORITY 7
#define AT32_IRQ_TMR3_PRIORITY 7
#define AT32_IRQ_TMR4_PRIORITY 7
#define AT32_IRQ_TMR5_PRIORITY 7
#define AT32_IRQ_USART1_PRIORITY 12
#define AT32_IRQ_USART2_PRIORITY 12
#define AT32_IRQ_USART3_PRIORITY 12
#define AT32_IRQ_UART4_PRIORITY 12
#define AT32_IRQ_UART5_PRIORITY 12
/*
* ADC driver system settings.
*/
#define AT32_ADC_USE_ADC1 FALSE
#define AT32_ADC_ADC1_DMA_PRIORITY 2
#define AT32_ADC_ADC1_IRQ_PRIORITY 6
/*
* CAN driver system settings.
*/
#define AT32_CAN_USE_CAN1 FALSE
#define AT32_CAN_CAN1_IRQ_PRIORITY 11
/*
* DMA driver system settings.
*/
#define AT32_DMA_USE_DMAMUX TRUE
/*
* GPT driver system settings.
*/
#define AT32_GPT_USE_TMR1 FALSE
#define AT32_GPT_USE_TMR2 FALSE
#define AT32_GPT_USE_TMR3 FALSE
#define AT32_GPT_USE_TMR4 FALSE
#define AT32_GPT_USE_TMR5 FALSE
#define AT32_GPT_USE_TMR9 FALSE
#define AT32_GPT_USE_TMR10 FALSE
#define AT32_GPT_USE_TMR11 FALSE
/*
* I2C driver system settings.
*/
#define AT32_I2C_USE_I2C1 FALSE
#define AT32_I2C_USE_I2C2 FALSE
#define AT32_I2C_BUSY_TIMEOUT 50
#define AT32_I2C_I2C1_IRQ_PRIORITY 5
#define AT32_I2C_I2C2_IRQ_PRIORITY 5
#define AT32_I2C_I2C1_DMA_PRIORITY 3
#define AT32_I2C_I2C2_DMA_PRIORITY 3
#define AT32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
/*
* ICU driver system settings.
*/
#define AT32_ICU_USE_TMR1 FALSE
#define AT32_ICU_USE_TMR2 FALSE
#define AT32_ICU_USE_TMR3 FALSE
#define AT32_ICU_USE_TMR4 FALSE
#define AT32_ICU_USE_TMR5 FALSE
#define AT32_ICU_USE_TMR9 FALSE
#define AT32_ICU_USE_TMR10 FALSE
#define AT32_ICU_USE_TMR11 FALSE
/*
* PWM driver system settings.
*/
#define AT32_PWM_USE_TMR1 FALSE
#define AT32_PWM_USE_TMR2 FALSE
#define AT32_PWM_USE_TMR3 FALSE
#define AT32_PWM_USE_TMR4 FALSE
#define AT32_PWM_USE_TMR5 FALSE
#define AT32_PWM_USE_TMR9 FALSE
#define AT32_PWM_USE_TMR10 FALSE
#define AT32_PWM_USE_TMR11 FALSE
/*
* RTC driver system settings.
*/
#define AT32_ERTC_DIVA_VALUE 32
#define AT32_ERTC_DIVB_VALUE 1024
#define AT32_ERTC_CTRL_INIT 0
#define AT32_ERTC_TAMP_INIT 0
/*
* SDC driver system settings.
*/
#define AT32_SDC_SDIO_DMA_PRIORITY 3
#define AT32_SDC_SDIO_IRQ_PRIORITY 9
#define AT32_SDC_WRITE_TIMEOUT_MS 1000
#define AT32_SDC_READ_TIMEOUT_MS 1000
#define AT32_SDC_CLOCK_ACTIVATION_DELAY 10
#define AT32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
/*
* SERIAL driver system settings.
*/
#define AT32_SERIAL_USE_USART1 FALSE
#define AT32_SERIAL_USE_USART2 FALSE
#define AT32_SERIAL_USE_USART3 FALSE
#define AT32_SERIAL_USE_UART4 FALSE
#define AT32_SERIAL_USE_UART5 FALSE
/*
* SPI driver system settings.
*/
#define AT32_SPI_USE_SPI1 FALSE
#define AT32_SPI_USE_SPI2 FALSE
#define AT32_SPI_SPI1_DMA_PRIORITY 1
#define AT32_SPI_SPI2_DMA_PRIORITY 1
#define AT32_SPI_SPI1_IRQ_PRIORITY 10
#define AT32_SPI_SPI2_IRQ_PRIORITY 10
#define AT32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
/*
* ST driver system settings.
*/
#define AT32_ST_IRQ_PRIORITY 8
#define AT32_ST_USE_TIMER 2
/*
* UART driver system settings.
*/
#define AT32_UART_USE_USART1 FALSE
#define AT32_UART_USE_USART2 FALSE
#define AT32_UART_USE_USART3 FALSE
#define AT32_UART_USART1_DMA_PRIORITY 0
#define AT32_UART_USART2_DMA_PRIORITY 0
#define AT32_UART_USART3_DMA_PRIORITY 0
#define AT32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
/*
* USB driver system settings.
*/
#define AT32_USB_USE_OTG1 TRUE
#define AT32_USB_OTG1_IRQ_PRIORITY 14
#define AT32_USB_OTG1_RX_FIFO_SIZE 512
/*
* WDG driver system settings.
*/
#define AT32_WDG_USE_WDT FALSE
#endif /* MCUCONF_H */

View File

@ -26,6 +26,7 @@
# stm32-dfu STM32 USB DFU in ROM # stm32-dfu STM32 USB DFU in ROM
# apm32-dfu APM32 USB DFU in ROM # apm32-dfu APM32 USB DFU in ROM
# wb32-dfu WB32 USB DFU in ROM # wb32-dfu WB32 USB DFU in ROM
# at32-dfu AT32 USB DFU in ROM
# tinyuf2 TinyUF2 # tinyuf2 TinyUF2
# rp2040 Raspberry Pi RP2040 # rp2040 Raspberry Pi RP2040
# Current options for RISC-V: # Current options for RISC-V:
@ -119,6 +120,14 @@ ifeq ($(strip $(BOOTLOADER)), wb32-dfu)
OPT_DEFS += -DBOOTLOADER_WB32_DFU OPT_DEFS += -DBOOTLOADER_WB32_DFU
BOOTLOADER_TYPE = wb32_dfu BOOTLOADER_TYPE = wb32_dfu
endif endif
ifeq ($(strip $(BOOTLOADER)), at32-dfu)
OPT_DEFS += -DBOOTLOADER_AT32_DFU
BOOTLOADER_TYPE = at32_dfu
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 2E3C:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 2E3C -p DF11
endif
ifeq ($(strip $(BOOTLOADER_TYPE)),) ifeq ($(strip $(BOOTLOADER_TYPE)),)
ifneq ($(strip $(BOOTLOADER)),) ifneq ($(strip $(BOOTLOADER)),)

View File

@ -0,0 +1,83 @@
// Copyright 2021-2023 QMK
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "bootloader.h"
#include "util.h"
#include <ch.h>
#include <hal.h>
#include "wait.h"
#ifndef AT32_BOOTLOADER_RAM_SYMBOL
# define AT32_BOOTLOADER_RAM_SYMBOL __ram0_end__
#endif
extern uint32_t AT32_BOOTLOADER_RAM_SYMBOL;
/* This code should be checked whether it runs correctly on platforms */
#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
#define BOOTLOADER_MAGIC 0xDEADBEEF
#define MAGIC_ADDR (unsigned long *)(SYMVAL(AT32_BOOTLOADER_RAM_SYMBOL) - 4)
__attribute__((weak)) void bootloader_marker_enable(void) {
uint32_t *marker = (uint32_t *)MAGIC_ADDR;
*marker = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
}
__attribute__((weak)) bool bootloader_marker_active(void) {
const uint32_t *marker = (const uint32_t *)MAGIC_ADDR;
return (*marker == BOOTLOADER_MAGIC) ? true : false;
}
__attribute__((weak)) void bootloader_marker_disable(void) {
uint32_t *marker = (uint32_t *)MAGIC_ADDR;
*marker = 0;
}
__attribute__((weak)) void bootloader_jump(void) {
bootloader_marker_enable();
NVIC_SystemReset();
}
__attribute__((weak)) void mcu_reset(void) {
NVIC_SystemReset();
}
void enter_bootloader_mode_if_requested(void) {
if (bootloader_marker_active()) {
bootloader_marker_disable();
struct system_memory_vector_t {
uint32_t stack_top;
void (*entrypoint)(void);
};
const struct system_memory_vector_t *bootloader = (const struct system_memory_vector_t *)(AT32_BOOTLOADER_ADDRESS);
__disable_irq();
#if defined(__MPU_PRESENT) && (__MPU_PRESENT == 1U)
ARM_MPU_Disable();
#endif
SysTick->CTRL = 0;
SysTick->VAL = 0;
SysTick->LOAD = 0;
// Clear interrupt enable and interrupt pending registers
for (int i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
__set_CONTROL(0);
__set_MSP(bootloader->stack_top);
__enable_irq();
// Jump to bootloader
bootloader->entrypoint();
while (true) {
}
}
}

View File

@ -142,6 +142,19 @@
# endif # endif
#endif #endif
// AT32 compatibility
#if defined(MCU_AT32)
# define CPU_CLOCK AT32_SYSCLK
# if defined(AT32F415)
# define USE_GPIOV1
# define USE_I2CV1
# define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_AT32_ALTERNATE_OPENDRAIN
# define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_AT32_ALTERNATE_PUSHPULL
# define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
# endif
#endif
#if defined(GD32VF103) #if defined(GD32VF103)
/* This chip has the same API as STM32F103, but uses different names for literally the same thing. /* This chip has the same API as STM32F103, but uses different names for literally the same thing.
* As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake * As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake

View File

@ -22,7 +22,7 @@
# error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC." # error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC."
#endif #endif
#if !RP_ADC_USE_ADC1 && !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4 && !WB32_ADC_USE_ADC1 #if !RP_ADC_USE_ADC1 && !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4 && !WB32_ADC_USE_ADC1 && !AT32_ADC_USE_ADC1
# error "You need to set one of the 'xxx_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC." # error "You need to set one of the 'xxx_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC."
#endif #endif
@ -45,7 +45,7 @@
// Otherwise assume V3 // Otherwise assume V3
#if defined(STM32F0XX) || defined(STM32L0XX) #if defined(STM32F0XX) || defined(STM32L0XX)
# define USE_ADCV1 # define USE_ADCV1
#elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) #elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415)
# define USE_ADCV2 # define USE_ADCV2
#endif #endif
@ -82,7 +82,7 @@
/* User configurable ADC options */ /* User configurable ADC options */
#ifndef ADC_COUNT #ifndef ADC_COUNT
# if defined(RP2040) || defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) # if defined(RP2040) || defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415)
# define ADC_COUNT 1 # define ADC_COUNT 1
# elif defined(STM32F3XX) || defined(STM32G4XX) # elif defined(STM32F3XX) || defined(STM32G4XX)
# define ADC_COUNT 4 # define ADC_COUNT 4
@ -142,11 +142,16 @@ static ADCConversionGroup adcConversionGroup = {
.cfgr1 = ADC_CFGR1_CONT | ADC_RESOLUTION, .cfgr1 = ADC_CFGR1_CONT | ADC_RESOLUTION,
.smpr = ADC_SAMPLING_RATE, .smpr = ADC_SAMPLING_RATE,
#elif defined(USE_ADCV2) #elif defined(USE_ADCV2)
# if !defined(STM32F1XX) && !defined(GD32VF103) && !defined(WB32F3G71xx) && !defined(WB32FQ95xx) # if !defined(STM32F1XX) && !defined(GD32VF103) && !defined(WB32F3G71xx) && !defined(WB32FQ95xx) && !defined(AT32F415)
.cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without... .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without...
# endif # endif
# if defined(AT32F415)
.spt2 = ADC_SPT2_CSPT_AN0(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN1(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN2(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN3(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN4(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN5(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN6(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN7(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN8(ADC_SAMPLING_RATE) | ADC_SPT2_CSPT_AN9(ADC_SAMPLING_RATE),
.spt1 = ADC_SPT1_CSPT_AN10(ADC_SAMPLING_RATE) | ADC_SPT1_CSPT_AN11(ADC_SAMPLING_RATE) | ADC_SPT1_CSPT_AN12(ADC_SAMPLING_RATE) | ADC_SPT1_CSPT_AN13(ADC_SAMPLING_RATE) | ADC_SPT1_CSPT_AN14(ADC_SAMPLING_RATE) | ADC_SPT1_CSPT_AN15(ADC_SAMPLING_RATE),
# else
.smpr2 = ADC_SMPR2_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN9(ADC_SAMPLING_RATE), .smpr2 = ADC_SMPR2_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN9(ADC_SAMPLING_RATE),
.smpr1 = ADC_SMPR1_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN15(ADC_SAMPLING_RATE), .smpr1 = ADC_SMPR1_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN15(ADC_SAMPLING_RATE),
# endif
#elif defined(RP2040) #elif defined(RP2040)
// RP2040 does not have any extra config here // RP2040 does not have any extra config here
#else #else
@ -242,7 +247,7 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 ); case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 );
case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 ); case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 );
# endif # endif
#elif defined(STM32F1XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) #elif defined(STM32F1XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415)
case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 ); case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 ); case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
@ -344,7 +349,7 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
static inline ADCDriver* intToADCDriver(uint8_t adcInt) { static inline ADCDriver* intToADCDriver(uint8_t adcInt) {
switch (adcInt) { switch (adcInt) {
#if RP_ADC_USE_ADC1 || STM32_ADC_USE_ADC1 || WB32_ADC_USE_ADC1 #if RP_ADC_USE_ADC1 || STM32_ADC_USE_ADC1 || WB32_ADC_USE_ADC1 || AT32_ADC_USE_ADC1
case 0: case 0:
return &ADCD1; return &ADCD1;
#endif #endif
@ -391,7 +396,11 @@ int16_t adc_read(adc_mux mux) {
// TODO: fix previous assumption of only 1 input... // TODO: fix previous assumption of only 1 input...
adcConversionGroup.chselr = 1 << mux.input; /*no macro to convert N to ADC_CHSELR_CHSEL1*/ adcConversionGroup.chselr = 1 << mux.input; /*no macro to convert N to ADC_CHSELR_CHSEL1*/
#elif defined(USE_ADCV2) #elif defined(USE_ADCV2)
# if defined(AT32F415)
adcConversionGroup.osq3 = ADC_OSQ3_OSN1_N(mux.input);
# else
adcConversionGroup.sqr3 = ADC_SQR3_SQ1_N(mux.input); adcConversionGroup.sqr3 = ADC_SQR3_SQ1_N(mux.input);
# endif
#elif defined(RP2040) #elif defined(RP2040)
adcConversionGroup.channel_mask = 1 << mux.input; adcConversionGroup.channel_mask = 1 << mux.input;
#else #else

View File

@ -9,6 +9,17 @@
#if defined(SERIAL_USART_CONFIG) #if defined(SERIAL_USART_CONFIG)
static QMKSerialConfig serial_config = SERIAL_USART_CONFIG; static QMKSerialConfig serial_config = SERIAL_USART_CONFIG;
#elif defined(MCU_AT32) /* AT32 MCUs */
static QMKSerialConfig serial_config = {
.speed = (SERIAL_USART_SPEED),
.ctrl1 = (SERIAL_USART_CTRL1),
.ctrl2 = (SERIAL_USART_CTRL2),
# if !defined(SERIAL_USART_FULL_DUPLEX)
.ctrl3 = ((SERIAL_USART_CTRL3) | USART_CTRL3_SLBEN) /* activate half-duplex mode */
# else
.ctrl3 = (SERIAL_USART_CTRL3)
# endif
};
#elif defined(MCU_STM32) /* STM32 MCUs */ #elif defined(MCU_STM32) /* STM32 MCUs */
static QMKSerialConfig serial_config = { static QMKSerialConfig serial_config = {
# if HAL_USE_SERIAL # if HAL_USE_SERIAL
@ -160,7 +171,7 @@ inline bool serial_transport_receive_blocking(uint8_t* destination, const size_t
* @brief Initiate pins for USART peripheral. Half-duplex configuration. * @brief Initiate pins for USART peripheral. Half-duplex configuration.
*/ */
__attribute__((weak)) void usart_init(void) { __attribute__((weak)) void usart_init(void) {
# if defined(MCU_STM32) /* STM32 MCUs */ # if defined(MCU_STM32) || defined(MCU_AT32) /* STM32 and AT32 MCUs */
# if defined(USE_GPIOV1) # if defined(USE_GPIOV1)
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_OPENDRAIN); palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_OPENDRAIN);
# else # else
@ -183,7 +194,7 @@ __attribute__((weak)) void usart_init(void) {
* @brief Initiate pins for USART peripheral. Full-duplex configuration. * @brief Initiate pins for USART peripheral. Full-duplex configuration.
*/ */
__attribute__((weak)) void usart_init(void) { __attribute__((weak)) void usart_init(void) {
# if defined(MCU_STM32) /* STM32 MCUs */ # if defined(MCU_STM32) || defined(MCU_AT32) /* STM32 and AT32 MCUs */
# if defined(USE_GPIOV1) # if defined(USE_GPIOV1)
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_PUSHPULL); palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_PUSHPULL);
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT); palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);

View File

@ -74,6 +74,7 @@ typedef SIOConfig QMKSerialConfig;
# endif # endif
#endif #endif
#if defined(MCU_STM32) /* STM32 MCUs */
# if !defined(USART_CR1_M0) # if !defined(USART_CR1_M0)
# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so # define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
# endif # endif
@ -111,3 +112,37 @@ typedef SIOConfig QMKSerialConfig;
(AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \ (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \
} while (0) } while (0)
# endif # endif
#elif defined(MCU_AT32) /* AT32 MCUs */
# if !defined(USART_CTRL1_DBN0)
# define USART_CTRL1_DBN0 USART_CTRL1_DBN
# endif
# if !defined(SERIAL_USART_CTRL1)
# define SERIAL_USART_CTRL1 (USART_CTRL1_PEN | USART_CTRL1_PSEL | USART_CTRL1_DBN0) // parity enable, odd parity, 9 bit length
# endif
# if !defined(SERIAL_USART_CTRL2)
# define SERIAL_USART_CTRL2 (USART_CTRL2_STOPBN_1) // 2 stop bits
# endif
# if !defined(SERIAL_USART_CTRL3)
# define SERIAL_USART_CTRL3 0
# endif
# if defined(USART1_REMAP)
# define USART_REMAP \
do { \
(IOMUX->REMAP |= IOMUX_REMAP_USART1_MUX); \
} while (0)
# elif defined(USART3_PARTIALREMAP)
# define USART_REMAP \
do { \
(IOMUX->REMAP |= IOMUX_REMAP_USART3_MUX_MUX1); \
} while (0)
# elif defined(USART3_FULLREMAP)
# define USART_REMAP \
do { \
(IOMUX->REMAP |= IOMUX_REMAP_USART3_MUX_MUX2); \
} while (0)
# endif
#endif

View File

@ -103,10 +103,16 @@ bool spi_start_extended(spi_start_config_t *start_config) {
roundedDivisor <<= 1; roundedDivisor <<= 1;
} }
# if defined(AT32F415)
if (roundedDivisor < 2 || roundedDivisor > 1024) {
return false;
}
# else
if (roundedDivisor < 2 || roundedDivisor > 256) { if (roundedDivisor < 2 || roundedDivisor > 256) {
return false; return false;
} }
# endif # endif
#endif
#if defined(K20x) || defined(KL2x) #if defined(K20x) || defined(KL2x)
spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1); spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1);
@ -240,6 +246,59 @@ bool spi_start_extended(spi_start_config_t *start_config) {
spiConfig.SSPCR0 |= SPI_SSPCR0_SPH; // Clock phase: sample on second edge transition spiConfig.SSPCR0 |= SPI_SSPCR0_SPH; // Clock phase: sample on second edge transition
break; break;
} }
#elif defined(AT32F415)
spiConfig.ctrl1 = 0;
if (lsbFirst) {
spiConfig.ctrl1 |= SPI_CTRL1_LTF;
}
switch (mode) {
case 0:
break;
case 1:
spiConfig.ctrl1 |= SPI_CTRL1_CLKPHA;
break;
case 2:
spiConfig.ctrl1 |= SPI_CTRL1_CLKPOL;
break;
case 3:
spiConfig.ctrl1 |= SPI_CTRL1_CLKPHA | SPI_CTRL1_CLKPOL;
break;
}
switch (roundedDivisor) {
case 2:
break;
case 4:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_0;
break;
case 8:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_1;
break;
case 16:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_1 | SPI_CTRL1_MDIV_0;
break;
case 32:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_2;
break;
case 64:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_0;
break;
case 128:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_1;
break;
case 256:
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_1 | SPI_CTRL1_MDIV_0;
break;
case 512:
spiConfig.ctrl2 |= SPI_CTRL1_MDIV_3;
break;
case 1024:
spiConfig.ctrl2 |= SPI_CTRL1_MDIV_3;
spiConfig.ctrl1 |= SPI_CTRL1_MDIV_0;
break;
}
#else #else
spiConfig.cr1 = 0; spiConfig.cr1 = 0;

View File

@ -33,7 +33,7 @@ static inline uint32_t detect_flash_size(void) {
#elif defined(FLASH_SIZE) #elif defined(FLASH_SIZE)
return FLASH_SIZE; return FLASH_SIZE;
#elif defined(FLASHSIZE_BASE) #elif defined(FLASHSIZE_BASE)
# if defined(QMK_MCU_SERIES_STM32F0XX) || defined(QMK_MCU_SERIES_STM32F1XX) || defined(QMK_MCU_SERIES_STM32F3XX) || defined(QMK_MCU_SERIES_STM32F4XX) || defined(QMK_MCU_SERIES_STM32G4XX) || defined(QMK_MCU_SERIES_STM32L0XX) || defined(QMK_MCU_SERIES_STM32L4XX) || defined(QMK_MCU_SERIES_GD32VF103) # if defined(QMK_MCU_SERIES_STM32F0XX) || defined(QMK_MCU_SERIES_STM32F1XX) || defined(QMK_MCU_SERIES_STM32F3XX) || defined(QMK_MCU_SERIES_STM32F4XX) || defined(QMK_MCU_SERIES_STM32G4XX) || defined(QMK_MCU_SERIES_STM32L0XX) || defined(QMK_MCU_SERIES_STM32L4XX) || defined(QMK_MCU_SERIES_AT32F415) || defined(QMK_MCU_SERIES_GD32VF103)
return ((*(uint32_t *)FLASHSIZE_BASE) & 0xFFFFU) << 10U; // this register has the flash size in kB, so we convert it to bytes return ((*(uint32_t *)FLASHSIZE_BASE) & 0xFFFFU) << 10U; // this register has the flash size in kB, so we convert it to bytes
# elif defined(QMK_MCU_SERIES_STM32L1XX) # elif defined(QMK_MCU_SERIES_STM32L1XX)
# error This MCU family has an uncommon flash size register definition and has not been implemented. Perhaps try using the true EEPROM on the MCU instead? # error This MCU family has an uncommon flash size register definition and has not been implemented. Perhaps try using the true EEPROM on the MCU instead?

View File

@ -16,6 +16,8 @@
# define BACKING_STORE_WRITE_SIZE 4 // from hal_efl_lld.c # define BACKING_STORE_WRITE_SIZE 4 // from hal_efl_lld.c
# elif defined(QMK_MCU_FAMILY_WB32) # elif defined(QMK_MCU_FAMILY_WB32)
# define BACKING_STORE_WRITE_SIZE 8 // from hal_efl_lld.c # define BACKING_STORE_WRITE_SIZE 8 // from hal_efl_lld.c
# elif defined(QMK_MCU_FAMILY_AT32)
# define BACKING_STORE_WRITE_SIZE 2 // from hal_efl_lld.c
# elif defined(QMK_MCU_FAMILY_STM32) # elif defined(QMK_MCU_FAMILY_STM32)
# if defined(STM32_FLASH_LINE_SIZE) // from some family's stm32_registry.h file # if defined(STM32_FLASH_LINE_SIZE) // from some family's stm32_registry.h file
# define BACKING_STORE_WRITE_SIZE (STM32_FLASH_LINE_SIZE) # define BACKING_STORE_WRITE_SIZE (STM32_FLASH_LINE_SIZE)

View File

@ -11,7 +11,7 @@
/* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */ /* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */
#ifndef WS2812_BITBANG_NOP_FUDGE #ifndef WS2812_BITBANG_NOP_FUDGE
# if defined(STM32F0XX) || defined(STM32F1XX) || defined(GD32VF103) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(WB32F3G71xx) || defined(WB32FQ95xx) # if defined(STM32F0XX) || defined(STM32F1XX) || defined(GD32VF103) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415)
# define WS2812_BITBANG_NOP_FUDGE 0.4 # define WS2812_BITBANG_NOP_FUDGE 0.4
# else # else
# if defined(RP2040) # if defined(RP2040)

View File

@ -40,6 +40,9 @@
#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_PWM_DMAMUX_ID) #if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_PWM_DMAMUX_ID)
# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_PWM_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_PWM_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
#endif #endif
#if (AT32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_PWM_DMAMUX_CHANNEL) && !defined(WS2812_PWM_DMAMUX_ID)
# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_PWM_DMAMUX_CHANNEL 1, #define WS2812_PWM_DMAMUX_ID AT32_DMAMUX_TMR?_OVERFLOW"
#endif
/* Summarize https://www.st.com/resource/en/application_note/an4013-stm32-crossseries-timer-overview-stmicroelectronics.pdf to /* Summarize https://www.st.com/resource/en/application_note/an4013-stm32-crossseries-timer-overview-stmicroelectronics.pdf to
* figure out if we are using a 32bit timer. This is needed to setup the DMA controller correctly. * figure out if we are using a 32bit timer. This is needed to setup the DMA controller correctly.
@ -269,6 +272,14 @@ typedef uint32_t ws2812_buffer_t;
# define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD # define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD
typedef uint16_t ws2812_buffer_t; typedef uint16_t ws2812_buffer_t;
# endif # endif
#elif defined(AT32F415)
# define WS2812_PWM_DMA_MEMORY_WIDTH AT32_DMA_CCTRL_MWIDTH_BYTE
# if defined(WS2812_PWM_TIMER_32BIT)
# define WS2812_PWM_DMA_PERIPHERAL_WIDTH AT32_DMA_CCTRL_PWIDTH_WORD
# else
# define WS2812_PWM_DMA_PERIPHERAL_WIDTH AT32_DMA_CCTRL_PWIDTH_HWORD
# endif
typedef uint8_t ws2812_buffer_t;
#else #else
# define WS2812_PWM_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_BYTE # define WS2812_PWM_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_BYTE
# if defined(WS2812_PWM_TIMER_32BIT) # if defined(WS2812_PWM_TIMER_32BIT)
@ -309,8 +320,13 @@ void ws2812_init(void) {
[0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled
[WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about
}, },
#if defined(AT32F415)
.ctrl2 = 0,
.iden = AT32_TMR_IDEN_OVFDEN, // DMA on update event for next period
#else
.cr2 = 0, .cr2 = 0,
.dier = TIM_DIER_UDE, // DMA on update event for next period .dier = TIM_DIER_UDE, // DMA on update event for next period
#endif
}; };
//#pragma GCC diagnostic pop // Restore command-line warning options //#pragma GCC diagnostic pop // Restore command-line warning options
@ -321,6 +337,11 @@ void ws2812_init(void) {
dmaStreamSetSource(WS2812_PWM_DMA_STREAM, ws2812_frame_buffer); dmaStreamSetSource(WS2812_PWM_DMA_STREAM, ws2812_frame_buffer);
dmaStreamSetDestination(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register dmaStreamSetDestination(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
dmaStreamSetMode(WS2812_PWM_DMA_STREAM, WB32_DMA_CHCFG_HWHIF(WS2812_PWM_DMA_CHANNEL) | WB32_DMA_CHCFG_DIR_M2P | WB32_DMA_CHCFG_PSIZE_WORD | WB32_DMA_CHCFG_MSIZE_WORD | WB32_DMA_CHCFG_MINC | WB32_DMA_CHCFG_CIRC | WB32_DMA_CHCFG_TCIE | WB32_DMA_CHCFG_PL(3)); dmaStreamSetMode(WS2812_PWM_DMA_STREAM, WB32_DMA_CHCFG_HWHIF(WS2812_PWM_DMA_CHANNEL) | WB32_DMA_CHCFG_DIR_M2P | WB32_DMA_CHCFG_PSIZE_WORD | WB32_DMA_CHCFG_MSIZE_WORD | WB32_DMA_CHCFG_MINC | WB32_DMA_CHCFG_CIRC | WB32_DMA_CHCFG_TCIE | WB32_DMA_CHCFG_PL(3));
#elif defined(AT32F415)
dmaStreamAlloc(WS2812_PWM_DMA_STREAM - AT32_DMA_STREAM(0), 10, NULL, NULL);
dmaStreamSetPeripheral(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tmr->CDT[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
dmaStreamSetMemory0(WS2812_PWM_DMA_STREAM, ws2812_frame_buffer);
dmaStreamSetMode(WS2812_PWM_DMA_STREAM, AT32_DMA_CCTRL_DTD_M2P | WS2812_PWM_DMA_PERIPHERAL_WIDTH | WS2812_PWM_DMA_MEMORY_WIDTH | AT32_DMA_CCTRL_MINCM | AT32_DMA_CCTRL_LM | AT32_DMA_CCTRL_CHPL(3));
#else #else
dmaStreamAlloc(WS2812_PWM_DMA_STREAM - STM32_DMA_STREAM(0), 10, NULL, NULL); dmaStreamAlloc(WS2812_PWM_DMA_STREAM - STM32_DMA_STREAM(0), 10, NULL, NULL);
dmaStreamSetPeripheral(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register dmaStreamSetPeripheral(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
@ -335,6 +356,11 @@ void ws2812_init(void) {
dmaSetRequestSource(WS2812_PWM_DMA_STREAM, WS2812_PWM_DMAMUX_ID); dmaSetRequestSource(WS2812_PWM_DMA_STREAM, WS2812_PWM_DMAMUX_ID);
#endif #endif
#if (AT32_DMA_SUPPORTS_DMAMUX == TRUE)
// If the MCU has a DMAMUX we need to assign the correct resource
dmaSetRequestSource(WS2812_PWM_DMA_STREAM, WS2812_PWM_DMAMUX_CHANNEL, WS2812_PWM_DMAMUX_ID);
#endif
// Start DMA // Start DMA
dmaStreamEnable(WS2812_PWM_DMA_STREAM); dmaStreamEnable(WS2812_PWM_DMA_STREAM);

View File

@ -40,6 +40,32 @@
// Define SPI config speed // Define SPI config speed
// baudrate should target 3.2MHz // baudrate should target 3.2MHz
#if defined(AT32F415)
# if WS2812_SPI_DIVISOR == 2
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (0)
# elif WS2812_SPI_DIVISOR == 4
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_0)
# elif WS2812_SPI_DIVISOR == 8
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_1)
# elif WS2812_SPI_DIVISOR == 16 // default
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_1 | SPI_CTRL1_MDIV_0)
# elif WS2812_SPI_DIVISOR == 32
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_2)
# elif WS2812_SPI_DIVISOR == 64
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_0)
# elif WS2812_SPI_DIVISOR == 128
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_1)
# elif WS2812_SPI_DIVISOR == 256
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_2 | SPI_CTRL1_MDIV_1 | SPI_CTRL1_MDIV_0)
# elif WS2812_SPI_DIVISOR == 512
# define WS2812_SPI_DIVISOR_CTRL2_MDIV_X (SPI_CTRL1_MDIV_3)
# elif WS2812_SPI_DIVISOR == 1024
# define WS2812_SPI_DIVISOR_CTRL2_MDIV_X (SPI_CTRL1_MDIV_3)
# define WS2812_SPI_DIVISOR_CTRL1_MDIV_X (SPI_CTRL1_MDIV_0)
# else
# error "Configured WS2812_SPI_DIVISOR value is not supported at this time."
# endif
#else
// F072 fpclk = 48MHz // F072 fpclk = 48MHz
// 48/16 = 3Mhz // 48/16 = 3Mhz
# if WS2812_SPI_DIVISOR == 2 # if WS2812_SPI_DIVISOR == 2
@ -61,6 +87,7 @@
# else # else
# error "Configured WS2812_SPI_DIVISOR value is not supported at this time." # error "Configured WS2812_SPI_DIVISOR value is not supported at this time."
# endif # endif
#endif
// Use SPI circular buffer // Use SPI circular buffer
#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
@ -176,8 +203,16 @@ void ws2812_init(void) {
NULL, // error_cb NULL, // error_cb
PAL_PORT(WS2812_DI_PIN), PAL_PORT(WS2812_DI_PIN),
PAL_PAD(WS2812_DI_PIN), PAL_PAD(WS2812_DI_PIN),
# if defined(AT32F415)
WS2812_SPI_DIVISOR_CTRL1_MDIV_X,
# if (WS2812_SPI_DIVISOR == 512 || WS2812_SPI_DIVISOR == 1024)
WS2812_SPI_DIVISOR_CTRL2_MDIV_X,
# endif
0
# else
WS2812_SPI_DIVISOR_CR1_BR_X, WS2812_SPI_DIVISOR_CR1_BR_X,
0 0
# endif
#endif #endif
}; };

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