summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpuerto96 <jpuerto96@hotmail.com>2022-09-01 19:32:47 -0400
committerGitHub <noreply@github.com>2022-09-01 16:32:47 -0700
commit101d7b533745947ef2b92a919d5f02a137428235 (patch)
tree45bc4af11716100256b7e578a0a5e04fea44440a
parent7adef85fa4178109998674c1ea9b6166e3dbc7bf (diff)
[Keyboard] Add Ingrained Keyboard (#15928)
Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Juan Puerto <jpuerto@psc.edu> Co-authored-by: jpuerto-psc <68066250+jpuerto-psc@users.noreply.github.com>
-rw-r--r--keyboards/ingrained/config.h51
-rw-r--r--keyboards/ingrained/info.json276
-rw-r--r--keyboards/ingrained/ingrained.c4
-rw-r--r--keyboards/ingrained/ingrained.h47
-rw-r--r--keyboards/ingrained/keymaps/3x5/keymap.c23
-rw-r--r--keyboards/ingrained/keymaps/3x5/readme.md1
-rw-r--r--keyboards/ingrained/keymaps/default/keymap.c23
-rw-r--r--keyboards/ingrained/keymaps/default/readme.md1
-rw-r--r--keyboards/ingrained/matrix.c253
-rw-r--r--keyboards/ingrained/readme.md19
-rw-r--r--keyboards/ingrained/rules.mk27
11 files changed, 725 insertions, 0 deletions
diff --git a/keyboards/ingrained/config.h b/keyboards/ingrained/config.h
new file mode 100644
index 0000000000..7741dde0f7
--- /dev/null
+++ b/keyboards/ingrained/config.h
@@ -0,0 +1,51 @@
1// Copyright 2021 s8erdude (@jpuerto96)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "config_common.h"
7
8/* key matrix size */
9#define MATRIX_ROWS 8
10#define MATRIX_COLS 12
11
12#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
13#define MATRIX_COLS_PER_SIDE (MATRIX_COLS / 2)
14
15#define UNUSED_MCU 13
16#define UNUSED_MCP 6
17
18
19// wiring
20#define MATRIX_ROW_PINS_MCU \
21 { B0, B1, B2, B3 }
22#define MATRIX_COL_PINS_MCU \
23 { F7, F6, F5, F4, F1, F0 }
24#define UNUSED_PINS_MCU \
25 { B4, B5, B6, B7, C6, C7, D2, D3, D4, D5, D6, D7, E6}
26#define MATRIX_ROW_PINS_MCP \
27 { B0, B1, B2, B3 }
28#define MATRIX_COL_PINS_MCP \
29 { A0, A1, A2, A3, A4, A5 }
30#define UNUSED_PINS_MCP \
31 { B4, B5, B6, B7, A6, A7 }
32
33/*
34 * Keyboard Matrix Assignments
35 *
36 * Change this to how you wired your keyboard
37 * COLS: AVR pins used for columns, left to right
38 * ROWS: AVR pins used for rows, top to bottom
39 * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
40 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
41 *
42 */
43
44/* COL2ROW, ROW2COL */
45#define DIODE_DIRECTION COL2ROW
46
47/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
48#define DEBOUNCE 5
49
50/* define if matrix has ghost (lacks anti-ghosting diodes) */
51//#define MATRIX_HAS_GHOST
diff --git a/keyboards/ingrained/info.json b/keyboards/ingrained/info.json
new file mode 100644
index 0000000000..1db1c930f6
--- /dev/null
+++ b/keyboards/ingrained/info.json
@@ -0,0 +1,276 @@
1{
2 "keyboard_name": "ingrained",
3 "manufacturer": "s8erdude"
4 "url": "https://github.com/jpuerto96",
5 "maintainer": "jpuerto96 (s8erdude)",
6 "usb": {
7 "vid": "0xB33F",
8 "pid": "0x58E4",
9 "device_version": "0.0.1"
10 },
11 "layouts": {
12 "LAYOUT_split_3x6_3": {
13 "layout": [
14 {
15 "label": "Esc",
16 "x": 0,
17 "y": 0.3
18 },
19 {
20 "label": "Q",
21 "x": 1,
22 "y": 0.3
23 },
24 {
25 "label": "W",
26 "x": 2,
27 "y": 0.1
28 },
29 {
30 "label": "E",
31 "x": 3,
32 "y": 0
33 },
34 {
35 "label": "R",
36 "x": 4,
37 "y": 0.1
38 },
39 {
40 "label": "T",
41 "x": 5,
42 "y": 0.2
43 },
44 {
45 "label": "Y",
46 "x": 9,
47 "y": 0.2
48 },
49 {
50 "label": "U",
51 "x": 10,
52 "y": 0.1
53 },
54 {
55 "label": "I",
56 "x": 11,
57 "y": 0
58 },
59 {
60 "label": "O",
61 "x": 12,
62 "y": 0.1
63 },
64 {
65 "label": "P",
66 "x": 13,
67 "y": 0.3
68 },
69 {
70 "label": "Back Space",
71 "x": 14,
72 "y": 0.3
73 },
74 {
75 "label": "Tab",
76 "x": 0,
77 "y": 1.3
78 },
79 {
80 "label": "A",
81 "x": 1,
82 "y": 1.3
83 },
84 {
85 "label": "S",
86 "x": 2,
87 "y": 1.1
88 },
89 {
90 "label": "D",
91 "x": 3,
92 "y": 1
93 },
94 {
95 "label": "F",
96 "x": 4,
97 "y": 1.1
98 },
99 {
100 "label": "G",
101 "x": 5,
102 "y": 1.2
103 },
104 {
105 "label": "H",
106 "x": 9,
107 "y": 1.2
108 },
109 {
110 "label": "J",
111 "x": 10,
112 "y": 1.1
113 },
114 {
115 "label": "K",
116 "x": 11,
117 "y": 1
118 },
119 {
120 "label": "L",
121 "x": 12,
122 "y": 1.1
123 },
124 {
125 "label": ";",
126 "x": 13,
127 "y": 1.3
128 },
129 {
130 "label": "'",
131 "x": 14,
132 "y": 1.3
133 },
134 {
135 "label": "Shift",
136 "x": 0,
137 "y": 2.3
138 },
139 {
140 "label": "Z",
141 "x": 1,
142 "y": 2.3
143 },
144 {
145 "label": "X",
146 "x": 2,
147 "y": 2.1
148 },
149 {
150 "label": "C",
151 "x": 3,
152 "y": 2
153 },
154 {
155 "label": "V",
156 "x": 4,
157 "y": 2.1
158 },
159 {
160 "label": "B",
161 "x": 5,
162 "y": 2.2
163 },
164 {
165 "label": "N",
166 "x": 9,
167 "y": 2.2
168 },
169 {
170 "label": "M",
171 "x": 10,
172 "y": 2.1
173 },
174 {
175 "label": ",",
176 "x": 11,
177 "y": 2
178 },
179 {
180 "label": ".",
181 "x": 12,
182 "y": 2.1
183 },
184 {
185 "label": "/",
186 "x": 13,
187 "y": 2.3
188 },
189 {
190 "label": "Shift",
191 "x": 14,
192 "y": 2.3
193 },
194 {
195 "label": "GUI",
196 "x": 4,
197 "y": 3.7
198 },
199 {
200 "label": "Lower",
201 "x": 5,
202 "y": 3.7
203 },
204 {
205 "label": "Space",
206 "x": 6,
207 "y": 3.2,
208 "h": 1.5
209 },
210 {
211 "label": "Enter",
212 "x": 8,
213 "y": 3.2,
214 "h": 1.5
215 },
216 {
217 "label": "Raise",
218 "x": 9,
219 "y": 3.7
220 },
221 {
222 "label": "Alt",
223 "x": 10,
224 "y": 3.7
225 }
226 ]
227 },
228 "LAYOUT_split_3x5_3": {
229 "layout": [
230 {"label":"Q", "x":0, "y":0.3},
231 {"label":"W", "x":1, "y":0.1},
232 {"label":"E", "x":2, "y":0},
233 {"label":"R", "x":3, "y":0.1},
234 {"label":"T", "x":4, "y":0.2},
235
236 {"label":"Y", "x":8, "y":0.2},
237 {"label":"U", "x":9, "y":0.1},
238 {"label":"I", "x":10, "y":0},
239 {"label":"O", "x":11, "y":0.1},
240 {"label":"P", "x":12, "y":0.3},
241
242 {"label":"A", "x":0, "y":1.3},
243 {"label":"S", "x":1, "y":1.1},
244 {"label":"D", "x":2, "y":1},
245 {"label":"F", "x":3, "y":1.1},
246 {"label":"G", "x":4, "y":1.2},
247
248 {"label":"H", "x":8, "y":1.2},
249 {"label":"J", "x":9, "y":1.1},
250 {"label":"K", "x":10, "y":1},
251 {"label":"L", "x":11, "y":1.1},
252 {"label":";", "x":12, "y":1.3},
253
254 {"label":"Z", "x":0, "y":2.3},
255 {"label":"X", "x":1, "y":2.1},
256 {"label":"C", "x":2, "y":2},
257 {"label":"V", "x":3, "y":2.1},
258 {"label":"B", "x":4, "y":2.2},
259
260 {"label":"N", "x":8, "y":2.2},
261 {"label":"M", "x":9, "y":2.1},
262 {"label":",", "x":10, "y":2},
263 {"label":".", "x":11, "y":2.1},
264 {"label":"/", "x":12, "y":2.3},
265
266 {"label":"GUI", "x":3, "y":3.7},
267 {"label":"Lower", "x":4, "y":3.7},
268 {"label":"Space", "x":5, "y":3.2, "h":1.5},
269
270 {"label":"Enter", "x":7, "y":3.2, "h":1.5},
271 {"label":"Raise", "x":8, "y":3.7},
272 {"label":"Alt", "x":9, "y":3.7}
273 ]
274 }
275 }
276}
diff --git a/keyboards/ingrained/ingrained.c b/keyboards/ingrained/ingrained.c
new file mode 100644
index 0000000000..80aa82f840
--- /dev/null
+++ b/keyboards/ingrained/ingrained.c
@@ -0,0 +1,4 @@
1// Copyright 2021 s8erdude (@jpuerto96)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "ingrained.h"
diff --git a/keyboards/ingrained/ingrained.h b/keyboards/ingrained/ingrained.h
new file mode 100644
index 0000000000..d2e3055951
--- /dev/null
+++ b/keyboards/ingrained/ingrained.h
@@ -0,0 +1,47 @@
1// Copyright 2021 s8erdude (@jpuerto96)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "quantum.h"
7
8/* This is a shortcut to help you visually see your layout.
9 *
10 * The first section contains all of the arguments representing the physical
11 * layout of the board and position of the keys.
12 *
13 * The second converts the arguments into a two-dimensional array which
14 * represents the switch matrix.
15 */
16#define XXX KC_NO
17
18#define LAYOUT_split_3x6_3( \
19 k00, k01, k02, k03, k04, k05, k011, k010, k09, k08, k07, k06,\
20 k10, k11, k12, k13, k14, k15, k111, k110, k19, k18, k17, k16,\
21 k20, k21, k22, k23, k24, k25, k211, k210, k29, k28, k27, k26,\
22 k33, k34, k35, k311, k310, k39\
23) { \
24 { k00, k01, k02, k03, k04, k05 },\
25 { k10, k11, k12, k13, k14, k15 },\
26 { k20, k21, k22, k23, k24, k25 },\
27 { XXX, XXX, XXX, k33, k34, k35 },\
28 { k06, k07, k08, k09, k010, k011 },\
29 { k16, k17, k18, k19, k110, k111 },\
30 { k26, k27, k28, k29, k210, k211 },\
31 { XXX, XXX, XXX, k39, k310, k311 }\
32}
33#define LAYOUT_split_3x5_3( \
34 k01, k02, k03, k04, k05, k011, k010, k09, k08, k07,\
35 k11, k12, k13, k14, k15, k111, k110, k19, k18, k17,\
36 k21, k22, k23, k24, k25, k211, k210, k29, k28, k27,\
37 k33, k34, k35, k311, k310, k39\
38) { \
39 { XXX, k01, k02, k03, k04, k05 },\
40 { XXX, k11, k12, k13, k14, k15 },\
41 { XXX, k21, k22, k23, k24, k25 },\
42 { XXX, XXX, XXX, k33, k34, k35 },\
43 { XXX, k07, k08, k09, k010, k011 },\
44 { XXX, k17, k18, k19, k110, k111 },\
45 { XXX, k27, k28, k29, k210, k211 },\
46 { XXX, XXX, XXX, k39, k310, k311 }\
47}
diff --git a/keyboards/ingrained/keymaps/3x5/keymap.c b/keyboards/ingrained/keymaps/3x5/keymap.c
new file mode 100644
index 0000000000..ed34809b42
--- /dev/null
+++ b/keyboards/ingrained/keymaps/3x5/keymap.c
@@ -0,0 +1,23 @@
1// Copyright 2021 s8erdude (@jpuerto96)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include QMK_KEYBOARD_H
5
6
7// Each layer gets a name for readability, which is then used in the keymap matrix below.
8// The underscores don't mean anything - you can have a layer called STUFF or any other name.
9// Layer names don't all need to be of the same length, obviously, and you can also skip them
10// entirely and just use numbers.
11
12enum layer_names {
13 _BASE,
14};
15
16const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
17 [_BASE] = LAYOUT_split_3x5_3(
18 KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,
19 KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,
20 KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH,
21 KC_LGUI, KC_SPC, KC_TAB, KC_BSPC, KC_ENT, KC_RALT
22 )
23};
diff --git a/keyboards/ingrained/keymaps/3x5/readme.md b/keyboards/ingrained/keymaps/3x5/readme.md
new file mode 100644
index 0000000000..c2a997fcbf
--- /dev/null
+++ b/keyboards/ingrained/keymaps/3x5/readme.md
@@ -0,0 +1 @@
# The 3x5 keymap for ingrained
diff --git a/keyboards/ingrained/keymaps/default/keymap.c b/keyboards/ingrained/keymaps/default/keymap.c
new file mode 100644
index 0000000000..b09702e9ee
--- /dev/null
+++ b/keyboards/ingrained/keymaps/default/keymap.c
@@ -0,0 +1,23 @@
1// Copyright 2021 s8erdude (@jpuerto96)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include QMK_KEYBOARD_H
5
6
7// Each layer gets a name for readability, which is then used in the keymap matrix below.
8// The underscores don't mean anything - you can have a layer called STUFF or any other name.
9// Layer names don't all need to be of the same length, obviously, and you can also skip them
10// entirely and just use numbers.
11
12enum layer_names {
13 _BASE,
14};
15
16const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
17 [_BASE] = LAYOUT_split_3x6_3(
18 KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
19 KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
20 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
21 KC_LGUI, KC_SPC, KC_TAB, KC_BSPC, KC_ENT, KC_RALT
22 ),
23};
diff --git a/keyboards/ingrained/keymaps/default/readme.md b/keyboards/ingrained/keymaps/default/readme.md
new file mode 100644
index 0000000000..804feead66
--- /dev/null
+++ b/keyboards/ingrained/keymaps/default/readme.md
@@ -0,0 +1 @@
# The default keymap for ingrained
diff --git a/keyboards/ingrained/matrix.c b/keyboards/ingrained/matrix.c
new file mode 100644
index 0000000000..0dfb150b6c
--- /dev/null
+++ b/keyboards/ingrained/matrix.c
@@ -0,0 +1,253 @@
1/*
2Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
3 2020 Pierre Chevalier <pierrechevalier83@gmail.com>
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/*
20 * This code was heavily inspired by the ergodox_ez keymap, and modernized
21 * to take advantage of the quantum.h microcontroller agnostics gpio control
22 * abstractions and use the macros defined in config.h for the wiring as opposed
23 * to repeating that information all over the place.
24 */
25
26#include QMK_KEYBOARD_H
27#include "i2c_master.h"
28
29extern i2c_status_t mcp23017_status;
30#define I2C_TIMEOUT 1000
31
32// For a better understanding of the i2c protocol, this is a good read:
33// https://www.robot-electronics.co.uk/i2c-tutorial
34
35// I2C address:
36// See the datasheet, section 3.3.1 on addressing I2C devices and figure 3-6 for an
37// illustration
38// http://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf
39// All address pins of the mcp23017 are connected to the ground on the ferris
40// | 0 | 1 | 0 | 0 | A2 | A1 | A0 |
41// | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
42#define I2C_ADDR 0b0100000
43#define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE)
44#define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ)
45
46// Register addresses
47// See https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/Adafruit_MCP23017.h
48#define IODIRA 0x00 // i/o direction register
49#define IODIRB 0x01
50#define GPPUA 0x0C // GPIO pull-up resistor register
51#define GPPUB 0x0D
52#define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
53#define GPIOB 0x13
54#define OLATA 0x14 // output latch register
55#define OLATB 0x15
56
57bool i2c_initialized = 0;
58i2c_status_t mcp23017_status = I2C_ADDR;
59
60uint8_t init_mcp23017(void) {
61 print("starting init");
62 mcp23017_status = I2C_ADDR;
63
64 // I2C subsystem
65 if (i2c_initialized == 0) {
66 i2c_init(); // on pins D(1,0)
67 i2c_initialized = true;
68 wait_ms(I2C_TIMEOUT);
69 }
70
71 // set pin direction
72 // - unused : input : 1
73 // - input : input : 1
74 // - driving : output : 0
75 // This means: we will read all the bits on GPIOA
76 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
77 uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000};
78 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
79 if (!mcp23017_status) {
80 // set pull-up
81 // - unused : on : 1
82 // - input : on : 1
83 // - driving : off : 0
84 // This means: we will read all the bits on GPIOA
85 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
86 uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000};
87 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, pullup_buf, sizeof(pullup_buf), I2C_TIMEOUT);
88 }
89 return mcp23017_status;
90}
91
92/* matrix state(1:on, 0:off) */
93static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
94
95static matrix_row_t read_cols(uint8_t row);
96static void init_cols(void);
97static void unselect_rows(void);
98static void select_row(uint8_t row);
99
100static uint8_t mcp23017_reset_loop;
101
102void matrix_init_custom(void) {
103 // initialize row and col
104
105 mcp23017_status = init_mcp23017();
106
107 unselect_rows();
108 init_cols();
109
110 // initialize matrix state: all keys off
111 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
112 matrix[i] = 0;
113 }
114}
115
116void matrix_power_up(void) {
117 mcp23017_status = init_mcp23017();
118
119 unselect_rows();
120 init_cols();
121
122 // initialize matrix state: all keys off
123 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
124 matrix[i] = 0;
125 }
126}
127
128// Reads and stores a row, returning
129// whether a change occurred.
130static inline bool store_matrix_row(matrix_row_t current_matrix[], uint8_t index) {
131 matrix_row_t temp = read_cols(index);
132 if (current_matrix[index] != temp) {
133 current_matrix[index] = temp;
134 return true;
135 }
136 return false;
137}
138
139bool matrix_scan_custom(matrix_row_t current_matrix[]) {
140 if (mcp23017_status) { // if there was an error
141 if (++mcp23017_reset_loop == 0) {
142 // if (++mcp23017_reset_loop >= 1300) {
143 // since mcp23017_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
144 // this will be approx bit more frequent than once per second
145 dprint("trying to reset mcp23017\n");
146 mcp23017_status = init_mcp23017();
147 if (mcp23017_status) {
148 dprint("right side not responding\n");
149 } else {
150 dprint("right side attached\n");
151 }
152 }
153 }
154
155 bool changed = false;
156 for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) {
157 // select rows from left and right hands
158 uint8_t left_index = i;
159 uint8_t right_index = i + MATRIX_ROWS_PER_SIDE;
160 select_row(left_index);
161 select_row(right_index);
162
163 // we don't need a 30us delay anymore, because selecting a
164 // left-hand row requires more than 30us for i2c.
165
166 changed |= store_matrix_row(current_matrix, left_index);
167 changed |= store_matrix_row(current_matrix, right_index);
168
169 unselect_rows();
170 }
171
172 return changed;
173}
174
175static void init_cols(void) {
176 // init on mcp23017
177 // not needed, already done as part of init_mcp23017()
178
179 // init on mcu
180 pin_t matrix_col_pins_mcu[MATRIX_COLS_PER_SIDE] = MATRIX_COL_PINS_MCU;
181 for (int pin_index = 0; pin_index < MATRIX_COLS_PER_SIDE; pin_index++) {
182 pin_t pin = matrix_col_pins_mcu[pin_index];
183 setPinInput(pin);
184 writePinHigh(pin);
185 }
186}
187
188static matrix_row_t read_cols(uint8_t row) {
189 if (row < MATRIX_ROWS_PER_SIDE) {
190 pin_t matrix_col_pins_mcu[MATRIX_COLS_PER_SIDE] = MATRIX_COL_PINS_MCU;
191 matrix_row_t current_row_value = 0;
192 // For each col...
193 for (uint8_t col_index = 0; col_index < MATRIX_COLS_PER_SIDE; col_index++) {
194 // Select the col pin to read (active low)
195 uint8_t pin_state = readPin(matrix_col_pins_mcu[col_index]);
196
197 // Populate the matrix row with the state of the col pin
198 current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
199 }
200 return current_row_value;
201 } else {
202 if (mcp23017_status) { // if there was an error
203 return 0;
204 } else {
205 uint8_t buf[] = {GPIOA};
206 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
207 // We read all the pins on GPIOA.
208 // The initial state was all ones and any depressed key at a given column for the currently selected row will have its bit flipped to zero.
209 // The return value is a row as represented in the generic matrix code were the rightmost bits represent the lower columns and zeroes represent non-depressed keys while ones represent depressed keys.
210 // Since the pins connected to eact columns are sequential, and counting from zero up (col 5 -> GPIOA0, col 6 -> GPIOA1 and so on), the only transformation needed is a bitwise not to swap all zeroes and ones.
211 uint8_t data[] = {0};
212 if (!mcp23017_status) {
213 mcp23017_status = i2c_receive(I2C_ADDR_READ, data, sizeof(data), I2C_TIMEOUT);
214 data[0] = ~(data[0]);
215 }
216 return data[0];
217 }
218 }
219}
220
221static void unselect_rows(void) {
222 // no need to unselect on mcp23017, because the select step sets all
223 // the other row bits high, and it's not changing to a different
224 // direction
225
226 // unselect rows on microcontroller
227 pin_t matrix_row_pins_mcu[MATRIX_ROWS_PER_SIDE] = MATRIX_ROW_PINS_MCU;
228 for (int pin_index = 0; pin_index < MATRIX_ROWS_PER_SIDE; pin_index++) {
229 pin_t pin = matrix_row_pins_mcu[pin_index];
230 setPinInput(pin);
231 writePinLow(pin);
232 }
233}
234
235static void select_row(uint8_t row) {
236 if (row < MATRIX_ROWS_PER_SIDE) {
237 // select on atmega32u4
238 pin_t matrix_row_pins_mcu[MATRIX_ROWS_PER_SIDE] = MATRIX_ROW_PINS_MCU;
239 pin_t pin = matrix_row_pins_mcu[row];
240 setPinOutput(pin);
241 writePinLow(pin);
242 } else {
243 // select on mcp23017
244 if (mcp23017_status) { // if there was an error
245 // do nothing
246 } else {
247 // Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
248 // Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
249 uint8_t buf[] = {GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
250 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
251 }
252 }
253}
diff --git a/keyboards/ingrained/readme.md b/keyboards/ingrained/readme.md
new file mode 100644
index 0000000000..3e616e52bb
--- /dev/null
+++ b/keyboards/ingrained/readme.md
@@ -0,0 +1,19 @@
1# ingrained
2
3This PCB is an integrated, USB-C to USB-C, Corne replacement.
4
5* Keyboard Maintainer: [s8erdude](https://github.com/jpuerto96)
6* Hardware Supported: Ingrained PCB
7* Hardware Availability: [Open Source PCB](https://github.com/jpuerto96/crkbd)
8
9Make example for this keyboard (after setting up your build environment):
10
11 make ingrained:default
12
13Flashing example for this keyboard:
14
15 make ingrained:default:flash
16
17To reset the board, you will want to short the pad labeled RESET on the main half (near the USB-C interconnect).
18
19See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
diff --git a/keyboards/ingrained/rules.mk b/keyboards/ingrained/rules.mk
new file mode 100644
index 0000000000..03e074deda
--- /dev/null
+++ b/keyboards/ingrained/rules.mk
@@ -0,0 +1,27 @@
1# MCU name
2MCU = atmega32u4
3
4# Bootloader selection
5BOOTLOADER = atmel-dfu
6
7# Build Options
8# change yes to no to disable
9#
10BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite
11MOUSEKEY_ENABLE = yes # Mouse keys
12EXTRAKEY_ENABLE = yes # Audio control and System control
13CONSOLE_ENABLE = no # Console for debug
14COMMAND_ENABLE = no # Commands for debug and configuration
15NKRO_ENABLE = no # Enable N-Key Rollover
16BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
17RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
18AUDIO_ENABLE = no # Audio output
19UNICODE_ENABLE = yes
20CUSTOM_MATRIX = lite
21NO_USB_STARTUP_CHECK = yes
22LTO_ENABLE = yes
23
24SRC += matrix.c
25QUANTUM_LIB_SRC += i2c_master.c
26
27LAYOUTS = split_3x5_3 split_3x6_3