Merge branch 'zmkfirmware:main' into main

This commit is contained in:
Will 2024-05-13 23:29:39 +10:00 committed by GitHub
commit d7cc41d844
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 208 additions and 38 deletions

View file

@ -53,5 +53,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -36,4 +36,21 @@
low-power-enable;
};
};
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 28)>,
<NRF_PSEL(SPIM_MISO, 0, 3)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 28)>,
<NRF_PSEL(SPIM_MISO, 0, 3)>;
low-power-enable;
};
};
};

View file

@ -67,6 +67,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -55,5 +55,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -36,4 +36,21 @@
low-power-enable;
};
};
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 13)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 13)>;
low-power-enable;
};
};
};

View file

@ -66,6 +66,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -53,5 +53,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -36,4 +36,21 @@
low-power-enable;
};
};
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 11)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 11)>;
low-power-enable;
};
};
};

View file

@ -50,6 +50,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -55,5 +55,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -55,5 +55,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -53,5 +53,5 @@
pro_micro_d: &pro_micro {};
pro_micro_i2c: &i2c0 {};
pro_micro_spi: &spi0 {};
pro_micro_spi: &spi1 {};
pro_micro_serial: &uart0 {};

View file

@ -36,4 +36,21 @@
low-power-enable;
};
};
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 9)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 6)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 9)>,
<NRF_PSEL(SPIM_MOSI, 0, 10)>,
<NRF_PSEL(SPIM_MISO, 1, 6)>;
low-power-enable;
};
};
};

View file

@ -36,4 +36,21 @@
low-power-enable;
};
};
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 28)>,
<NRF_PSEL(SPIM_MISO, 0, 3)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 0, 28)>,
<NRF_PSEL(SPIM_MISO, 0, 3)>;
low-power-enable;
};
};
};

View file

@ -54,6 +54,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -54,6 +54,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -66,6 +66,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -66,6 +66,13 @@
pinctrl-names = "default", "sleep";
};
&spi1 {
compatible = "nordic,nrf-spim";
pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
};
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;

View file

@ -125,9 +125,9 @@ nice_view_spi: &arduino_spi {
toggle-mode;
input-gpios
= <&arduino_header 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
, <&arduino_header 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
, <&arduino_header 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
= <&arduino_header 4 GPIO_ACTIVE_LOW>
, <&arduino_header 3 GPIO_ACTIVE_LOW>
, <&arduino_header 2 GPIO_ACTIVE_LOW>
;
};

View file

@ -6,7 +6,7 @@
/ {
behaviors {
/omit-if-no-ref/ soft_off: keymap_soft_off {
/omit-if-no-ref/ soft_off: z_so_off {
compatible = "zmk,behavior-soft-off";
#binding-cells = <0>;
split-peripheral-off-on-press;

View file

@ -6,6 +6,8 @@
#pragma once
#include <zephyr/sys/util.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/class/usb_hid.h>
@ -200,7 +202,7 @@ struct zmk_hid_keyboard_report_body {
zmk_mod_flags_t modifiers;
uint8_t _reserved;
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO)
uint8_t keys[(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8];
uint8_t keys[DIV_ROUND_UP(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1, 8)];
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO)
uint8_t keys[CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE];
#endif

View file

@ -80,7 +80,7 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = {
DT_INST_PROP_OR(n, split_peripheral_off_on_press, false), \
}; \
static struct behavior_soft_off_data bso_data_##n = {}; \
BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \
BEHAVIOR_DT_INST_DEFINE(n, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_soft_off_driver_api);

View file

@ -126,7 +126,7 @@ zmk_hid_boot_report_t *zmk_hid_get_boot_report(void) {
memset(&boot_report.keys, 0, HID_BOOT_KEY_LEN);
int ix = 0;
uint8_t base_code = 0;
for (int i = 0; i < (ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8; ++i) {
for (int i = 0; i < sizeof(keyboard_report.body.keys); ++i) {
if (ix == keys_held) {
break;
}

View file

@ -173,7 +173,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action
struct ksbb_data ksbb_data_##n = {}; \
PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \
DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \
&ksbb_config_##n, POST_KERNEL, \
&ksbb_config_##n, APPLICATION, \
CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY, &ksbb_api);
DT_INST_FOREACH_STATUS_OKAY(KSBB_INST)

View file

@ -82,7 +82,7 @@ static struct zmk_led_hsb hsb_scale_zero_max(struct zmk_led_hsb hsb) {
}
static struct led_rgb hsb_to_rgb(struct zmk_led_hsb hsb) {
float r, g, b;
float r = 0, g = 0, b = 0;
uint8_t i = hsb.h / 60;
float v = hsb.b / ((float)BRT_MAX);
@ -468,17 +468,31 @@ int zmk_rgb_underglow_change_spd(int direction) {
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) || \
IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB)
static int rgb_underglow_auto_state(bool *prev_state, bool new_state) {
if (state.on == new_state) {
struct rgb_underglow_sleep_state {
bool is_awake;
bool rgb_state_before_sleeping;
};
static int rgb_underglow_auto_state(bool target_wake_state) {
static struct rgb_underglow_sleep_state sleep_state = {
is_awake : true,
rgb_state_before_sleeping : false
};
// wake up event while awake, or sleep event while sleeping -> no-op
if (target_wake_state == sleep_state.is_awake) {
return 0;
}
if (new_state) {
state.on = *prev_state;
*prev_state = false;
return zmk_rgb_underglow_on();
sleep_state.is_awake = target_wake_state;
if (sleep_state.is_awake) {
if (sleep_state.rgb_state_before_sleeping) {
return zmk_rgb_underglow_on();
} else {
return zmk_rgb_underglow_off();
}
} else {
state.on = false;
*prev_state = true;
sleep_state.rgb_state_before_sleeping = state.on;
return zmk_rgb_underglow_off();
}
}
@ -487,16 +501,13 @@ static int rgb_underglow_event_listener(const zmk_event_t *eh) {
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE)
if (as_zmk_activity_state_changed(eh)) {
static bool prev_state = false;
return rgb_underglow_auto_state(&prev_state,
zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE);
return rgb_underglow_auto_state(zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE);
}
#endif
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB)
if (as_zmk_usb_conn_state_changed(eh)) {
static bool prev_state = false;
return rgb_underglow_auto_state(&prev_state, zmk_usb_is_powered());
return rgb_underglow_auto_state(zmk_usb_is_powered());
}
#endif

View file

@ -81,10 +81,6 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml](
| `toggle-mode` | bool | Use toggle switch mode. | n |
| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n |
By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver flip between pull up and down as the switch is toggled to optimize for power.
`toggle-mode` applies to all switches handled by the instance of the driver. To use a toggle switch with other, non-toggle, direct GPIO switches, create two instances of the direct GPIO driver, one with `toggle-mode` and the other without. Then, use a [composite driver](#composite-driver) to combine them.
Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](https://docs.zephyrproject.org/3.5.0/hardware/peripherals/gpio.html#api-reference) for the elements in `input-gpios` should be `(GPIO_ACTIVE_LOW | GPIO_PULL_UP)`:
```dts
@ -98,6 +94,25 @@ Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](http
};
```
By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver enable and disable the internal pull up/down resistor as needed when the switch is toggled to minimise power draw. For `toggle-mode` to work correctly each pole of the switch needs a dedicated GPIO pin.
`toggle-mode` applies to all switches handled by the instance of the driver. To use a toggle switch with other, non-toggle, direct GPIO switches, create two instances of the direct GPIO driver, one with `toggle-mode` and the other without. Then, use a [composite driver](#composite-driver) to combine them. The state of the switch is read on power on, so if the switch is moved whilst the board is off this will get correctly interpreted by the driver.
When using `toggle-mode` the pull resistors get automatically set by the driver and should not be set in the devicetree via GPIO flags. Assuming the common pole of the switch is connected to ground with an SP3T switch:
```dts
kscan_sp3t_toggle: kscan_sp3t_toggle {
compatible = "zmk,kscan-gpio-direct";
toggle-mode;
input-gpios
= <&pro_micro 4 GPIO_ACTIVE_LOW>
, <&pro_micro 3 GPIO_ACTIVE_LOW>
, <&pro_micro 2 GPIO_ACTIVE_LOW>
;
};
```
## Matrix Driver
Keyboard scan driver where keys are arranged on a matrix with one GPIO per row and column.

View file

@ -67,6 +67,10 @@ mkdir boards/shields/<keyboard_name>
## Base Kconfig Files
:::tip[Example shields]
You can check out the [`shields` folder](https://github.com/zmkfirmware/zmk/tree/main/app/boards/shields) in the ZMK repo that houses [the in-tree supported shields](../hardware.mdx) in order to copy and modify as a starting point.
:::
There are two required Kconfig files that need to be created for your new keyboard
shield to get it picked up for ZMK, `Kconfig.shield` and `Kconfig.defconfig`.
@ -229,8 +233,9 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,2) RC(4,9) RC(3,6) RC(3,7)
kscan0: kscan {
compatible = "zmk,kscan-gpio-matrix";
diode-direction = "col2row";
wakeup-source;
row-gpios
= <&pro_micro 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // Row A from the schematic file
, <&pro_micro 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // Row B from the schematic file
@ -344,6 +349,8 @@ Here is an example for the [nice60](https://github.com/Nicell/nice60), which use
zmk,matrix-transform = &default_transform;
};
/* define kscan node with label `kscan0`... */
default_transform: keymap_transform_0 {
compatible = "zmk,matrix-transform";
columns = <8>;
@ -361,6 +368,9 @@ RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(5,3) RC(6,4) RC(5,4) RC(6,5) RC(5,5) RC
RC(7,0) RC(7,1) RC(7,2) RC(7,3) RC(7,5) RC(7,6) RC(6,7) RC(7,7)
>;
};
/* potentially other overlay nodes... */
};
```
Some important things to note:

View file

@ -48,7 +48,7 @@ If you are reviewing these errors in the GitHub Actions tab, they can be found i
If you get an error stating `Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set` this is an indication that the build process cannot find the keymap. Double check that the `<keyboard>.keymap` file is present and has been discovered by the build process. This can be checked by looking for a line in the build log stating `-- Using keymap file: /path/to/keymap/file/<keyboard>.keymap`. Inside the keymap file ensure the keymap node has `compatible = zmk,keymap` and it's not misspelled. For more information see the [Keymap](features/keymaps.mdx) and [Config](config/index.md) documentation.
#### devicetree error
#### Devicetree errors
A `devicetree error` followed by a reference to the line number on `<keyboard>.keymap` refers to an issue at the exact line position in that file. For example, below error message indicates a missing `;` at line 109 of the `cradio.keymap` file:
@ -64,12 +64,10 @@ devicetree error: <Node /soc/gpio@50000300 in '/tmp/tmp.vJq9sMwkcY/zephyr/misc/e
This error can be triggered by incorrect binding syntax such as `&kp BT_SEL 0` instead of `&bt BT_SEL 0`.
#### devicetree_unfixed.h error
A `devicetree_unfixed.h` error that follows with an "undeclared here" string indicates a problem with key bindings, like behavior nodes (e.g. `&kp` or `&mt`) with incorrect number of parameters:
A `devicetree_generated.h` error that follows with an "undeclared here" string indicates a problem with key bindings, like behavior nodes (e.g. `&kp` or `&mt`) with incorrect number of parameters:
```
/__w/zmk-config/zmk-config/build/zephyr/include/generated/devicetree_unfixed.h:3756:145: error: 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label' undeclared here (not in a function); did you mean 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_16_PH'?
/__w/zmk-config/zmk-config/build/zephyr/include/generated/devicetree_generated.h:3756:145: error: 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label' undeclared here (not in a function); did you mean 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_16_PH'?
```
In this example, the error string `DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label` indicates a problem with the key binding in position `12` in the `symbol_layer` of the keymap.