Skip to content

Commit

Permalink
ZMK firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
rschenk committed Jun 23, 2024
1 parent 29020bd commit 383c99b
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,35 @@ Compared to the original Egret, besides having two thumb buttons per side, the R

![Re-gret Underglow](images/IMG_0812.jpeg)

## Build guide

Check the docs for a [PCB Build Guide](docs/pcb_build_guide.md) and [Case Build Guide](docs/case_build_guide.md).

## RGB Underglow

I powered the RGB underglow directly from the USB 5v, so it will automagically turn itself off when in wireless bluetooth mode. There's no need for ZMK's [External Power Control](https://zmk.dev/docs/behaviors/power#external-power-control) because you physically can't run the LEDs from battery power even if you wanted to. There's a [clever trick](https://hackaday.com/2017/01/20/cheating-at-5v-ws2812-control-to-use-a-3-3v-data-line/) using a diode that allows the 5v LEDs to be controlled by the Xiao's 3.3v logic.

## Firmware

### ZMK

Copy the contents of `firmware/zmk/config/boards/shields/regret/` into `[your-zmk-config]/config/boards/shields/regret/`

Be advised that right now the underglow only works on the XIAO nRF52840 board, and does not work on the XIAO RP2040 (although it [might in the future](https://github.com/zmkfirmware/zmk/issues/1085)). The original XIAO SAMD21 should work but I haven't tested it.

| Board | Chip | USB Wired | Bluetooth Wireless | RGB Underglow | Comments |
| --------------------- | -------- | ------------------ | ------------------ | ------------------ | ------------------------------------------------------------ |
| XIAO | SAMD21 | :white_check_mark: | :x: | :x: | Should work but untested |
| Adafruit Qt PY | SAMD21 | :white_check_mark: | :x: | :x: | Should work but untested |
| XIAO BLE | nRF52840 | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| XIAO RP2040 | RP2040 | :white_check_mark: | :x: | :x: for now | Underglow [maybe someday](https://github.com/zmkfirmware/zmk/issues/1085) |
| Adafruit Qt PY RP2040 | RP2040 | :white_check_mark: | :x: | :x: for now | Should work but untested |

### QMK

I have not written QMK firmware yet, but maybe I will for the RP2040.

## Related

* I cribbed the Xiao footprint, pogo pin idea, and battery from the [revxlp](https://gitlab.com/lpgalaxy/revxlp)
* My original 36 key [Egret](https://github.com/rschenk/egret) was the starting point
6 changes: 6 additions & 0 deletions firmware/zmk/config/boards/shields/regret/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if SHIELD_REGRET

config ZMK_KEYBOARD_NAME
default "Re-gret"

endif
3 changes: 3 additions & 0 deletions firmware/zmk/config/boards/shields/regret/Kconfig.shield
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config SHIELD_REGRET
def_bool $(shields_list_contains,regret)
select SPI
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_SPI=y
CONFIG_ZMK_KSCAN_MATRIX_POLLING=y
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SPI=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Shift register */

&spi2_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 1, 15)>;
};
};

&spi2_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MOSI, 1, 15)>;
};
};


/* LED underglow */

#include <dt-bindings/led/led.h>

&pinctrl {
spi3_default: spi3_default {
group1 {
psels = <NRF_PSEL(SPIM_MOSI, 0, 2)>;
};
};

spi3_sleep: spi3_sleep {
group1 {
psels = <NRF_PSEL(SPIM_MOSI, 0, 2)>;
low-power-enable;
};
};
};

&spi3 {
compatible = "nordic,nrf-spim";
status = "okay";

pinctrl-0 = <&spi3_default>;
pinctrl-1 = <&spi3_sleep>;
pinctrl-names = "default", "sleep";

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-spi";

/* SPI */
reg = <0>; /* ignored, but necessary for SPI bindings */
spi-max-frequency = <4000000>;

/* WS2812 */
chain-length = <11>; /* number of LEDs */
spi-one-frame = <0x70>;
spi-zero-frame = <0x40>;
color-mapping = <LED_COLOR_ID_GREEN
LED_COLOR_ID_RED
LED_COLOR_ID_BLUE>;
};
};

/ {
chosen {
zmk,underglow = &led_strip;
};
};
6 changes: 6 additions & 0 deletions firmware/zmk/config/boards/shields/regret/regret.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Uncomment the following lines to enable RGB underglow
# CONFIG_ZMK_RGB_UNDERGLOW=y
CONFIG_WS2812_STRIP=y
CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=n
CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB=y

22 changes: 22 additions & 0 deletions firmware/zmk/config/boards/shields/regret/regret.keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>

/ {
keymap {
compatible = "zmk,keymap";

default_layer {
// ------------------------------------------------------------------------------------------------------
// | Q | W | E | R | T | Y | U | I | O | P |
// | A | S | D | F | G | H | J | K | L | ; |
// | Z | X | C | V | B | N | M | , | . | / |
// | ESC | SPACE | RETURN | BSPC |
bindings = <
&kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P
&kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI
&kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH
&kp ESC &kp SPACE &kp RET &kp BSPC
>;
};
};
};
61 changes: 61 additions & 0 deletions firmware/zmk/config/boards/shields/regret/regret.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <dt-bindings/zmk/matrix_transform.h>

&xiao_serial { status = "disabled"; };

&xiao_spi {
status = "okay";
cs-gpios = <&xiao_d 9 GPIO_ACTIVE_LOW>;
shifter: 595@0 {
compatible = "zmk,gpio-595";
status = "okay";
gpio-controller;
spi-max-frequency = <200000>;
reg = <0>;
#gpio-cells = <2>;
ngpios = <8>;
};
};

/ {
chosen {
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
};

default_transform: keymap_transform_0 {
compatible = "zmk,matrix-transform";
columns = <5>;
rows = <8>;
map = <
RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(4,4) RC(4,3) RC(4,2) RC(4,1) RC(4,0)
RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(5,4) RC(5,3) RC(5,2) RC(5,1) RC(5,0)
RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(6,4) RC(6,3) RC(6,2) RC(6,1) RC(6,0)
RC(3,3) RC(3,4) RC(7,4) RC(7,3)
>;
};

kscan0: kscan_0 {
compatible = "zmk,kscan-gpio-matrix";
diode-direction = "row2col";
wakeup-source;

col-gpios
= <&xiao_d 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
, <&xiao_d 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
, <&xiao_d 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
, <&xiao_d 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
, <&xiao_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
;

row-gpios
= <&shifter 7 GPIO_ACTIVE_HIGH>
, <&shifter 6 GPIO_ACTIVE_HIGH>
, <&shifter 5 GPIO_ACTIVE_HIGH>
, <&shifter 4 GPIO_ACTIVE_HIGH>
, <&shifter 0 GPIO_ACTIVE_HIGH>
, <&shifter 1 GPIO_ACTIVE_HIGH>
, <&shifter 2 GPIO_ACTIVE_HIGH>
, <&shifter 3 GPIO_ACTIVE_HIGH>
;
};
};
8 changes: 8 additions & 0 deletions firmware/zmk/config/boards/shields/regret/regret.zmk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
file_format: "1"
id: regret
name: Re-gret
type: shield
url: https://github.com/rschenk/regret
requires: [seeed_xiao]
features:
- keys

0 comments on commit 383c99b

Please sign in to comment.