/*
 * Copyright (c) 2022 The ZMK Contributors
 *
 * SPDX-License-Identifier: MIT
 */

#include <dt-bindings/zmk/matrix_transform.h>

/ {
	chosen {
		zephyr,display = &oled;
		zmk,kscan = &kscan_composite;
		zmk,matrix_transform = &default_transform;
	};

	left_encoder: encoder_left {
		compatible = "alps,ec11";
		label = "LEFT_ENCODER";
		resolution = <4>;
		status = "disabled";
	};

	right_encoder: encoder_right {
		compatible = "alps,ec11";
		label = "RIGHT_ENCODER";
		resolution = <4>;
		status = "disabled";
	};

	default_transform: keymap_transform_0 {
		compatible = "zmk,matrix-transform";
		columns = <17>;
		rows = <6>;

//        | R0C06L | R0C05L | R0C04L | R0C03L | R0C02L | R0C01L | R0C00L | | R0C15R | R0C14R | R0C13R | R0C12R | R0C11R | R0C10R | R0C09R | R0C08R |
// R1C07L | R1C06L | R1C05L | R1C04L | R1C03L | R1C02L | R1C01L | R1C00L | | R1C15R | R1C14R | R1C13R | R1C12R | R1C11R | R1C10R | R1C09R | R1C08R | R2C0XR |
// R2C07L | R2C06L | R2C05L | R2C04L | R2C03L | R2C02L |          R2C00L | | R2C15R | R2C14R | R2C13R | R2C12R | R2C11R | R2C10R | R2C09R | R3C08R | R2C08R |
// R3C07L | R3C06L | R3C05L | R3C04L | R3C03L | R3C02L |          R3C00L | | R3C15R | R3C14R | R3C13R | R3C12R | R3C11R | R3C10R | R3C09R |          R4C08R |
// R4C07L | R4C06L | R4C05L | R4C04L | R4C03L | R4C02L | R4C01L | R4C00L | | R4C15R | R4C14R | R4C13R | R4C12R | R4C11R | R4C10R |          R4C09R | R5C08R |
// R5C07L | R5C06L | R5C05L | R5C04L |          R5C02L |          R5C00L | | R5C15R |                   R5C14R | R5C13R | R5C12R | R5C11R | R5C10R | R5C09R |
		
	map = <
		RC(0,6) RC(0,5) RC(0,4) RC(0,3) RC(0,2) RC(0,1) RC(0,0)    RC(0,15) RC(0,14) RC(0,13) RC(0,12) RC(0,11) RC(0,10) RC(0,9)  RC(0,8)
RC(1,7) RC(1,6) RC(1,5) RC(1,4) RC(1,3) RC(1,2) RC(1,1) RC(1,0)    RC(1,15) RC(1,14) RC(1,13) RC(1,12) RC(1,11) RC(1,10) RC(1,9)  RC(1,8)  RC(1,16)
RC(2,7) RC(2,6) RC(2,5) RC(2,4) RC(2,3) RC(2,2)         RC(2,0)    RC(2,15) RC(2,14) RC(2,13) RC(2,12) RC(2,11) RC(2,10) RC(2,9)  RC(3,8)  RC(2,8)
RC(3,7) RC(3,6) RC(3,5) RC(3,4) RC(3,3) RC(3,2)         RC(3,0)    RC(3,15) RC(3,14) RC(3,13) RC(3,12) RC(3,11) RC(3,10) RC(3,9)           RC(4,8)
RC(4,7) RC(4,6) RC(4,5) RC(4,4) RC(4,3) RC(4,2) RC(4,1) RC(4,0)    RC(4,15) RC(4,14) RC(4,13) RC(4,12) RC(4,11) RC(4,10)          RC(4,9)  RC(5,8)
RC(5,7) RC(5,6) RC(5,5) RC(5,4)         RC(5,2)         RC(5,0)    RC(5,15)                   RC(5,14) RC(5,13) RC(5,12) RC(5,11) RC(5,10) RC(5,9)
		>;
	};

	kscan_composite: kscan {
		compatible = "zmk,kscan-composite";
		label = "KSCAN";
		rows = <6>;
		columns = <17>;

		demux {
			kscan = <&kscan_demux>;
		};
	};

	kscan_demux: kscan_demux {
		compatible = "zmk,kscan-gpio-demux";
		label = "DEMUX";
		polling-interval-msec = <25>;
	};
};

&pro_micro_i2c {
	status = "okay";

	oled: ssd1306@3c {
		compatible = "solomon,ssd1306fb";
		reg = <0x3c>;
		label = "DISPLAY";
		width = <128>;
		height = <32>;
		segment-offset = <0>;
		page-offset = <0>;
		display-offset = <0>;
		multiplex-ratio = <31>;
		com-sequential;
		prechargep = <0x22>;
	};
};
