From be57b10c56885315ad56b78cc2f65a955029bccf Mon Sep 17 00:00:00 2001
From: Pete Johanson <peter@peterjohanson.com>
Date: Mon, 10 Aug 2020 11:29:16 -0400
Subject: [PATCH 1/5] Initial Corne shield definition.

* Also include a build for Clueboard California macropad.
---
 .github/workflows/build.yml                   |  5 ++
 app/boards/shields/corne/Kconfig.defconfig    | 58 ++++++++++++++
 app/boards/shields/corne/Kconfig.shield       |  8 ++
 .../shields/corne/boards/nice_nano.overlay    | 29 +++++++
 app/boards/shields/corne/corne.conf           |  4 +
 app/boards/shields/corne/corne.dtsi           | 79 +++++++++++++++++++
 app/boards/shields/corne/corne.keymap         | 22 ++++++
 app/boards/shields/corne/corne_left.conf      |  2 +
 app/boards/shields/corne/corne_left.overlay   | 18 +++++
 app/boards/shields/corne/corne_right.conf     |  2 +
 app/boards/shields/corne/corne_right.overlay  | 23 ++++++
 11 files changed, 250 insertions(+)
 create mode 100644 app/boards/shields/corne/Kconfig.defconfig
 create mode 100644 app/boards/shields/corne/Kconfig.shield
 create mode 100644 app/boards/shields/corne/boards/nice_nano.overlay
 create mode 100644 app/boards/shields/corne/corne.conf
 create mode 100644 app/boards/shields/corne/corne.dtsi
 create mode 100644 app/boards/shields/corne/corne.keymap
 create mode 100644 app/boards/shields/corne/corne_left.conf
 create mode 100644 app/boards/shields/corne/corne_left.overlay
 create mode 100644 app/boards/shields/corne/corne_right.conf
 create mode 100644 app/boards/shields/corne/corne_right.overlay

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 41091612..5eb79716 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -10,10 +10,15 @@ jobs:
       matrix:
         board: [proton_c, nice_nano]
         shield:
+          - corne_left
+          - corne_right
           - kyria_left
           - kyria_right
           - lily58_left
           - lily58_right
+        include:
+          - board: proton_c
+            shield: clueboard_california
     steps:
       # To use this repository's private action,
       # you must check out the repository
diff --git a/app/boards/shields/corne/Kconfig.defconfig b/app/boards/shields/corne/Kconfig.defconfig
new file mode 100644
index 00000000..8878da3d
--- /dev/null
+++ b/app/boards/shields/corne/Kconfig.defconfig
@@ -0,0 +1,58 @@
+
+if SHIELD_CORNE_LEFT
+
+config ZMK_KEYBOARD_NAME
+	default "Corne Left"
+
+endif
+
+
+if SHIELD_CORNE_RIGHT
+
+config ZMK_KEYBOARD_NAME
+	default "Corne Right"
+
+endif
+
+if SHIELD_CORNE_LEFT || SHIELD_CORNE_RIGHT
+
+config ZMK_SPLIT
+	default y
+ 
+if ZMK_DISPLAY
+
+config I2C
+	default y
+
+config SSD1306
+	default y
+
+config SSD1306_REVERSE_MODE
+	default y
+
+endif # ZMK_DISPLAY
+
+if LVGL
+
+config LVGL_HOR_RES
+	default 128
+
+config LVGL_VER_RES
+	default 32
+
+config LVGL_VDB_SIZE
+	default 64
+
+config LVGL_DPI
+	default 148
+
+config LVGL_BITS_PER_PIXEL
+	default 1
+
+choice LVGL_COLOR_DEPTH
+	default LVGL_COLOR_DEPTH_1
+endchoice
+
+endif # LVGL
+
+endif
diff --git a/app/boards/shields/corne/Kconfig.shield b/app/boards/shields/corne/Kconfig.shield
new file mode 100644
index 00000000..3cac86fe
--- /dev/null
+++ b/app/boards/shields/corne/Kconfig.shield
@@ -0,0 +1,8 @@
+# Copyright (c) 2020 Pete Johanson
+# SPDX-License-Identifier: MIT
+
+config SHIELD_CORNE_LEFT
+	def_bool $(shields_list_contains,corne_left)
+
+config SHIELD_CORNE_RIGHT
+	def_bool $(shields_list_contains,corne_right)
diff --git a/app/boards/shields/corne/boards/nice_nano.overlay b/app/boards/shields/corne/boards/nice_nano.overlay
new file mode 100644
index 00000000..c7c3eb8e
--- /dev/null
+++ b/app/boards/shields/corne/boards/nice_nano.overlay
@@ -0,0 +1,29 @@
+&spi1 {
+	compatible = "nordic,nrf-spi";
+	/* Cannot be used together with i2c0. */
+	status = "okay";
+	mosi-pin = <6>;
+	// Unused pins, needed for SPI definition, but not used by the ws2812 driver itself.
+	sck-pin = <5>;
+	miso-pin = <7>;
+
+	led_strip: ws2812@0 {
+		compatible = "worldsemi,ws2812-spi";
+		label = "SK6812mini";
+
+		/* SPI */
+		reg = <0>; /* ignored, but necessary for SPI bindings */
+		spi-max-frequency = <4000000>;
+
+		/* WS2812 */
+		chain-length = <6>; /* There are per-key RGB, but the first 6 are underglow */
+		spi-one-frame = <0x70>;
+		spi-zero-frame = <0x40>;
+	};
+};
+
+/ {
+	chosen {
+		zmk,underglow = &led_strip;
+	};
+};
diff --git a/app/boards/shields/corne/corne.conf b/app/boards/shields/corne/corne.conf
new file mode 100644
index 00000000..2723b038
--- /dev/null
+++ b/app/boards/shields/corne/corne.conf
@@ -0,0 +1,4 @@
+# TODO: Add lines about underglow!
+
+# Uncomment the following line to enable the Corne OLED Display
+# CONFIG_ZMK_DISPLAY=y
diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi
new file mode 100644
index 00000000..da48d62c
--- /dev/null
+++ b/app/boards/shields/corne/corne.dtsi
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2020 Pete Johanson
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <dt-bindings/zmk/matrix-transform.h>
+
+/ {
+	chosen {
+		zmk,kscan = &kscan0;
+		zmk,matrix_transform = &default_transform;
+	};
+
+	default_transform: keymap_transform_0 {
+		compatible = "zmk,matrix-transform";
+		columns = <12>;
+		rows = <4>;
+// | SW1  | SW2  | SW3  | SW4  | SW5  | SW6  |   | SW6  | SW5  | SW4  | SW3  | SW2  | SW1  |
+// | SW7  | SW8  | SW9  | SW10 | SW11 | SW12 |   | SW12 | SW11 | SW10 | SW9  | SW8  | SW7  |
+// | SW13 | SW14 | SW15 | SW16 | SW17 | SW18 |   | SW18 | SW17 | SW16 | SW15 | SW14 | SW13 |
+//                      | SW19 | SW20 | SW21 |   | SW21 | SW20 | SW19 |
+		map = <
+RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5)  RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,12)
+RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5)  RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,12)
+RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5)  RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,12)
+                        RC(3,3) RC(3,4) RC(3,5)  RC(3,6) RC(3,7) RC(3,8)
+		>;
+	};
+
+	five_column_transform: keymap_transform_1 {
+		compatible = "zmk,matrix-transform";
+		columns = <10>;
+		rows = <4>;
+// | SW2  | SW3  | SW4  | SW5  | SW6  |   | SW6  | SW5  | SW4  | SW3  | SW2  |
+// | SW8  | SW9  | SW10 | SW11 | SW12 |   | SW12 | SW11 | SW10 | SW9  | SW8  |
+// | SW14 | SW15 | SW16 | SW17 | SW18 |   | SW18 | SW17 | SW16 | SW15 | SW14 |
+//                      | SW19 | SW20 | SW21 |   | SW21 | SW20 | SW19 |
+		map = <
+RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5)  RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10)
+RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5)  RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10)
+RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5)  RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10)
+                        RC(3,3) RC(3,4) RC(3,5)  RC(3,6) RC(3,7) RC(3,8)
+		>;
+	};
+
+	kscan0: kscan {
+		compatible = "zmk,kscan-gpio-matrix";
+		label = "KSCAN";
+
+		diode-direction = "col2row";
+		row-gpios
+			= <&pro_micro_d 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
+			, <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
+			, <&pro_micro_d 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
+			, <&pro_micro_d 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
+			;
+		
+	};
+
+	// TODO: RGB node(s)
+};
+
+&pro_micro_i2c {
+	status = "okay";
+
+	ssd1306@3c {
+		compatible = "solomon,ssd1306fb";
+		reg = <0x3c>;
+		label = "DISPLAY";
+		width = <128>;
+		height = <32>;
+		segment-offset = <0>;
+		page-offset = <0>;
+		display-offset = <0>;
+		multiplex-ratio = <63>;
+		prechargep = <0x22>;
+	};
+};
diff --git a/app/boards/shields/corne/corne.keymap b/app/boards/shields/corne/corne.keymap
new file mode 100644
index 00000000..2f7f38b9
--- /dev/null
+++ b/app/boards/shields/corne/corne.keymap
@@ -0,0 +1,22 @@
+#include <behaviors.dtsi>
+#include <dt-bindings/zmk/keys.h>
+
+/ {
+	keymap {
+		compatible = "zmk,keymap";
+
+		default_layer {
+// ---------------------------------------------------------------------------------------------------------------------------------
+// |  ESC  |  Q  |  W  |  E   |  R   |  T   |   |  Y   |  U    |  I    |  O   |   P   |   \  |
+// |  TAB  |  A  |  S  |  D   |  F   |  G   |   |  H   |  J    |  K    |  L   |   ;   |   '  |
+// | SHIFT |  Z  |  X  |  C   |  V   |  B   |   |  N   |  M    |  ,    |  .   |   /   | CTRL |
+//                     | GUI  | DEL  | RET  |   | TAB  | BSPC  | R-ALT |
+			bindings = <
+	&kp ESC  &kp Q &kp W &kp E &kp R &kp T  &kp Y &kp U  &kp I    &kp O   &kp P    &kp BSLH
+	&kp TAB  &kp A &kp S &kp D &kp F &kp G  &kp H &kp J  &kp K    &kp L   &kp SCLN &kp QUOT
+	&kp LSFT &kp Z &kp X &kp C &kp V &kp B  &kp N &kp M  &kp CMMA &kp DOT &kp FSLH &kp RCTL
+	              &kp LGUI &kp DEL &kp RET  &kp TAB &kp BKSP &kp RALT
+			>;
+		};
+	};
+};
diff --git a/app/boards/shields/corne/corne_left.conf b/app/boards/shields/corne/corne_left.conf
new file mode 100644
index 00000000..e51dee44
--- /dev/null
+++ b/app/boards/shields/corne/corne_left.conf
@@ -0,0 +1,2 @@
+CONFIG_ZMK_SPLIT=y
+CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y
\ No newline at end of file
diff --git a/app/boards/shields/corne/corne_left.overlay b/app/boards/shields/corne/corne_left.overlay
new file mode 100644
index 00000000..399bddd1
--- /dev/null
+++ b/app/boards/shields/corne/corne_left.overlay
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2020 Pete Johanson
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "corne.dtsi"
+
+&kscan0 {
+	col-gpios
+		= <&pro_micro_a  3 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  2 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  1 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  0 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_d 15 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_d 14 GPIO_ACTIVE_HIGH>
+		;
+};
diff --git a/app/boards/shields/corne/corne_right.conf b/app/boards/shields/corne/corne_right.conf
new file mode 100644
index 00000000..a835adc1
--- /dev/null
+++ b/app/boards/shields/corne/corne_right.conf
@@ -0,0 +1,2 @@
+CONFIG_ZMK_SPLIT=y
+CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y
\ No newline at end of file
diff --git a/app/boards/shields/corne/corne_right.overlay b/app/boards/shields/corne/corne_right.overlay
new file mode 100644
index 00000000..652d5edd
--- /dev/null
+++ b/app/boards/shields/corne/corne_right.overlay
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2020 Pete Johanson
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "corne.dtsi"
+
+&default_transform {
+	col-offset = <6>;
+};
+
+&kscan0 {
+	col-gpios
+		= <&pro_micro_d 14 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_d 15 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  0 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  1 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  2 GPIO_ACTIVE_HIGH>
+		, <&pro_micro_a  3 GPIO_ACTIVE_HIGH>
+		;
+};
+

From aebeb7a153eb11e2f53b8def7235a021effd7e1f Mon Sep 17 00:00:00 2001
From: Pete Johanson <peter@peterjohanson.com>
Date: Mon, 10 Aug 2020 12:36:12 -0400
Subject: [PATCH 2/5] Updated config note about underglow.

---
 app/boards/shields/corne/corne.conf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/boards/shields/corne/corne.conf b/app/boards/shields/corne/corne.conf
index 2723b038..c8e3c00c 100644
--- a/app/boards/shields/corne/corne.conf
+++ b/app/boards/shields/corne/corne.conf
@@ -1,4 +1,5 @@
-# TODO: Add lines about underglow!
+# Uncomment the following line to enable the Corne RGB Underglow
+# ZMK_RGB_UNDERGLOW=y
 
 # Uncomment the following line to enable the Corne OLED Display
 # CONFIG_ZMK_DISPLAY=y

From 851d54ad960cbcb914cef83c9d1f7fcec49ecf21 Mon Sep 17 00:00:00 2001
From: Pete Johanson <peter@peterjohanson.com>
Date: Mon, 10 Aug 2020 12:37:05 -0400
Subject: [PATCH 3/5] Add Corne to setup.sh script.

---
 docs/static/setup.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/docs/static/setup.sh b/docs/static/setup.sh
index 327fc84b..42089434 100644
--- a/docs/static/setup.sh
+++ b/docs/static/setup.sh
@@ -37,7 +37,7 @@ echo ""
 echo "Keyboard Shield Selection:"
 
 prompt="Pick an keyboard:"
-options=("Kyria" "Lily58")
+options=("Kyria" "Lily58" "Corne")
 
 PS3="$prompt "
 # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos.
@@ -48,6 +48,7 @@ select opt in "${options[@]}" "Quit"; do
 
     1 ) shield_title="Kyria" shield="kyria"; split="y"; break;;
     2 ) shield_title="Lily58" shield="lily58"; split="y"; break;;
+    3 ) shield_title="Corne" shield="corne"; split="y"; break;;
 
     # Add link to docs on adding your own custom shield in your ZMK config!
     # $(( ${#options[@]}+1 )) ) echo "Other!"; break;; 

From 030f0dbd074164dbe085a423bdf1de68515d8f02 Mon Sep 17 00:00:00 2001
From: Pete Johanson <peter@peterjohanson.com>
Date: Mon, 10 Aug 2020 12:51:01 -0400
Subject: [PATCH 4/5] Tweak note about per-key RGB.

---
 app/boards/shields/corne/corne.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi
index da48d62c..70d6495b 100644
--- a/app/boards/shields/corne/corne.dtsi
+++ b/app/boards/shields/corne/corne.dtsi
@@ -58,7 +58,7 @@ RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5)  RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10
 		
 	};
 
-	// TODO: RGB node(s)
+	// TODO: per-key RGB node(s)?
 };
 
 &pro_micro_i2c {

From 4da2070a5b896fa2c28d77f0dde8508c739d0deb Mon Sep 17 00:00:00 2001
From: Pete Johanson <peter@peterjohanson.com>
Date: Mon, 10 Aug 2020 12:54:34 -0400
Subject: [PATCH 5/5] Add Corne to hardware list.

---
 docs/docs/hardware.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/docs/hardware.md b/docs/docs/hardware.md
index 015b21db..951cee04 100644
--- a/docs/docs/hardware.md
+++ b/docs/docs/hardware.md
@@ -22,6 +22,7 @@ That being said, there are currently only a few specific [boards](/docs/faq#what
 ## Keyboard Shields
 
 - [Kyria](https://splitkb.com/products/kyria-pcb-kit) (`kyria_left` and `kyria_right`)
+- [Corne](https://github.com/foostan/crkbd) (`corne_left` and `corne_right`)
 - [Lily58](https://github.com/kata0510/Lily58) (`lily58_left` and `lily58_right`)
 
 ## Other Hardware