Merge branch 'zmkfirmware:main' into toolchain-docs

This commit is contained in:
Nicolas Munnich 2024-05-12 11:39:01 +02:00 committed by GitHub
commit 9d2a275b20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 189 additions and 29 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

@ -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

@ -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

@ -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.