aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ferris
diff options
context:
space:
mode:
authorPierre Chevalier <pierrechevalier83@gmail.com>2021-04-18 16:51:45 +0100
committerGitHub <noreply@github.com>2021-04-18 17:51:45 +0200
commitd0973e1cfb9f0a2643a30128ba119e76c6fe2f3c (patch)
treeba66dc60ceee797b62b205e9c1c0da78a7e03df0 /keyboards/ferris
parentc32264d9b7382e86c7df75edfe3bc4154d714e25 (diff)
downloadqmk_firmware-d0973e1cfb9f0a2643a30128ba119e76c6fe2f3c.tar.gz
qmk_firmware-d0973e1cfb9f0a2643a30128ba119e76c6fe2f3c.zip
Add ferris 0.2 (#12133)
Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/ferris')
-rw-r--r--keyboards/ferris/0_1/matrix.c77
-rw-r--r--keyboards/ferris/0_1/readme.md17
-rw-r--r--keyboards/ferris/0_2/0_2.c17
-rw-r--r--keyboards/ferris/0_2/0_2.h43
-rw-r--r--keyboards/ferris/0_2/chconf.h40
-rw-r--r--keyboards/ferris/0_2/config.h80
-rw-r--r--keyboards/ferris/0_2/halconf.h30
-rw-r--r--keyboards/ferris/0_2/matrix.c255
-rw-r--r--keyboards/ferris/0_2/mcuconf.h36
-rw-r--r--keyboards/ferris/0_2/readme.md17
-rw-r--r--keyboards/ferris/0_2/rules.mk25
-rw-r--r--keyboards/ferris/keymaps/test/config.h20
-rw-r--r--keyboards/ferris/keymaps/test/keymap.c13
-rw-r--r--keyboards/ferris/keymaps/test/readme.md5
-rw-r--r--keyboards/ferris/keymaps/test/rules.mk1
-rw-r--r--keyboards/ferris/readme.md5
-rw-r--r--keyboards/ferris/sweep/readme.md18
17 files changed, 644 insertions, 55 deletions
diff --git a/keyboards/ferris/0_1/matrix.c b/keyboards/ferris/0_1/matrix.c
index e13c35d35..0dfb150b6 100644
--- a/keyboards/ferris/0_1/matrix.c
+++ b/keyboards/ferris/0_1/matrix.c
@@ -72,40 +72,25 @@ uint8_t init_mcp23017(void) {
72 // - unused : input : 1 72 // - unused : input : 1
73 // - input : input : 1 73 // - input : input : 1
74 // - driving : output : 0 74 // - driving : output : 0
75 mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
76 if (mcp23017_status) goto out;
77 mcp23017_status = i2c_write(IODIRA, I2C_TIMEOUT);
78 if (mcp23017_status) goto out;
79 // This means: we will read all the bits on GPIOA 75 // This means: we will read all the bits on GPIOA
80 mcp23017_status = i2c_write(0b11111111, I2C_TIMEOUT);
81 if (mcp23017_status) goto out;
82 // This means: we will write to the pins 0-4 on GPIOB (in select_rows) 76 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
83 mcp23017_status = i2c_write(0b11110000, I2C_TIMEOUT); 77 uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000};
84 if (mcp23017_status) goto out; 78 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
85 i2c_stop(); 79 if (!mcp23017_status) {
86 80 // set pull-up
87 // set pull-up 81 // - unused : on : 1
88 // - unused : on : 1 82 // - input : on : 1
89 // - input : on : 1 83 // - driving : off : 0
90 // - driving : off : 0 84 // This means: we will read all the bits on GPIOA
91 mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); 85 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
92 if (mcp23017_status) goto out; 86 uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000};
93 mcp23017_status = i2c_write(GPPUA, I2C_TIMEOUT); 87 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, pullup_buf, sizeof(pullup_buf), I2C_TIMEOUT);
94 if (mcp23017_status) goto out; 88 }
95 // This means: we will read all the bits on GPIOA
96 mcp23017_status = i2c_write(0b11111111, I2C_TIMEOUT);
97 if (mcp23017_status) goto out;
98 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
99 mcp23017_status = i2c_write(0b11110000, I2C_TIMEOUT);
100 if (mcp23017_status) goto out;
101
102out:
103 i2c_stop();
104 return mcp23017_status; 89 return mcp23017_status;
105} 90}
106 91
107/* matrix state(1:on, 0:off) */ 92/* matrix state(1:on, 0:off) */
108static matrix_row_t matrix[MATRIX_ROWS]; // debounced values 93static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
109 94
110static matrix_row_t read_cols(uint8_t row); 95static matrix_row_t read_cols(uint8_t row);
111static void init_cols(void); 96static void init_cols(void);
@@ -124,7 +109,7 @@ void matrix_init_custom(void) {
124 109
125 // initialize matrix state: all keys off 110 // initialize matrix state: all keys off
126 for (uint8_t i = 0; i < MATRIX_ROWS; i++) { 111 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
127 matrix[i] = 0; 112 matrix[i] = 0;
128 } 113 }
129} 114}
130 115
@@ -217,25 +202,18 @@ static matrix_row_t read_cols(uint8_t row) {
217 if (mcp23017_status) { // if there was an error 202 if (mcp23017_status) { // if there was an error
218 return 0; 203 return 0;
219 } else { 204 } else {
220 uint8_t data = 0; 205 uint8_t buf[] = {GPIOA};
221 mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); 206 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
222 if (mcp23017_status) goto out;
223 mcp23017_status = i2c_write(GPIOA, I2C_TIMEOUT);
224 if (mcp23017_status) goto out;
225 mcp23017_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT);
226 if (mcp23017_status) goto out;
227 mcp23017_status = i2c_read_nack(I2C_TIMEOUT);
228 if (mcp23017_status < 0) goto out;
229 // We read all the pins on GPIOA. 207 // We read all the pins on GPIOA.
230 // 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. 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.
231 // 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. 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.
232 // 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. 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.
233 data = ~((uint8_t)mcp23017_status); 211 uint8_t data[] = {0};
234 mcp23017_status = I2C_STATUS_SUCCESS; 212 if (!mcp23017_status) {
235 out: 213 mcp23017_status = i2c_receive(I2C_ADDR_READ, data, sizeof(data), I2C_TIMEOUT);
236 i2c_stop(); 214 data[0] = ~(data[0]);
237 // return reverse_bits(data, MATRIX_COLS_PER_SIDE); 215 }
238 return data; 216 return data[0];
239 } 217 }
240 } 218 }
241} 219}
@@ -266,17 +244,10 @@ static void select_row(uint8_t row) {
266 if (mcp23017_status) { // if there was an error 244 if (mcp23017_status) { // if there was an error
267 // do nothing 245 // do nothing
268 } else { 246 } else {
269 mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
270 if (mcp23017_status) goto out;
271 mcp23017_status = i2c_write(GPIOB, I2C_TIMEOUT);
272 if (mcp23017_status) goto out;
273 // 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. 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.
274 // 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. 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.
275 mcp23017_status = i2c_write(0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE)), I2C_TIMEOUT); 249 uint8_t buf[] = {GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
276 250 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
277 if (mcp23017_status) goto out;
278 out:
279 i2c_stop();
280 } 251 }
281 } 252 }
282} 253}
diff --git a/keyboards/ferris/0_1/readme.md b/keyboards/ferris/0_1/readme.md
new file mode 100644
index 000000000..336ee3863
--- /dev/null
+++ b/keyboards/ferris/0_1/readme.md
@@ -0,0 +1,17 @@
1# Ferris 0.1
2
3![Ferris 0.1 - base, top view](https://i.imgur.com/s6nTn0Ch.jpg)
4![Ferris 0.1 - base, bottom view](https://i.imgur.com/Ymlac2Ah.jpg)
5
6An atmega32u4 based split 34 keys column staggered keyboard named and decorated after the rustlang mascott. All PCB files and some thoughts on the design are available on the [project's github page](https://github.com/pierrechevalier83/ferris)
7
8* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83)
9* Hardware Supported:
10 * Ferris 0.1: atmega32u4 chip. Comes in 4 variants: base, low, high and compact
11* Hardware Availability: Pierre Chevalier has been selling keyboard kits (see the #ferris channel in the 40% discord chat). Wider availability is on the horizon.
12
13Make examples for this keyboard (after setting up your build environment):
14
15 make ferris/0_1:default
16
17See 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/ferris/0_2/0_2.c b/keyboards/ferris/0_2/0_2.c
new file mode 100644
index 000000000..519961dd3
--- /dev/null
+++ b/keyboards/ferris/0_2/0_2.c
@@ -0,0 +1,17 @@
1/*
2Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "0_2.h"
diff --git a/keyboards/ferris/0_2/0_2.h b/keyboards/ferris/0_2/0_2.h
new file mode 100644
index 000000000..4602637ca
--- /dev/null
+++ b/keyboards/ferris/0_2/0_2.h
@@ -0,0 +1,43 @@
1/*
2Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20#include "quantum.h"
21
22// clang-format off
23
24/* left hand right hand */
25#define LAYOUT(\
26 K0_0, K0_1, K0_2, K0_3, K0_4, K0_5, K0_6, K0_7, K0_8, K0_9,\
27 K1_0, K1_1, K1_2, K1_3, K1_4, K1_5, K1_6, K1_7, K1_8, K1_9,\
28 K2_0, K2_1, K2_2, K2_3, K2_4, K2_5, K2_6, K2_7, K2_8, K2_9,\
29 K3_3, K3_4, K3_5, K3_6)\
30/* matrix positions */\
31{\
32 {K0_0, K0_1, K0_2, K0_3, K0_4},\
33 {K1_0, K1_1, K1_2, K1_3, K1_4},\
34 {K2_0, K2_1, K2_2, K2_3, K2_4},\
35 {KC_NO, KC_NO, KC_NO, K3_3, K3_4},\
36 \
37 {K0_5, K0_6, K0_7, K0_8, K0_9},\
38 {K1_5, K1_6, K1_7, K1_8, K1_9},\
39 {K2_5, K2_6, K2_7, K2_8, K2_9},\
40 {K3_5, K3_6, KC_NO, KC_NO, KC_NO}\
41}
42
43// clang-format on
diff --git a/keyboards/ferris/0_2/chconf.h b/keyboards/ferris/0_2/chconf.h
new file mode 100644
index 000000000..c72955f65
--- /dev/null
+++ b/keyboards/ferris/0_2/chconf.h
@@ -0,0 +1,40 @@
1/* Copyright 2020 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/*
18 * This file was auto-generated by:
19 * `qmk chibios-confmigrate -i keyboards/ferris/0_2/chconf.h -r platforms/chibios/common/configs/chconf.h`
20 */
21
22#pragma once
23
24#define CH_CFG_ST_FREQUENCY 10000
25
26#define CH_CFG_OPTIMIZE_SPEED FALSE
27
28#define CH_CFG_USE_REGISTRY TRUE
29
30#define CH_CFG_USE_WAITEXIT TRUE
31
32#define CH_CFG_USE_CONDVARS TRUE
33
34#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE
35
36#define CH_CFG_USE_MESSAGES TRUE
37
38#define CH_CFG_USE_MAILBOXES TRUE
39
40#include_next <chconf.h>
diff --git a/keyboards/ferris/0_2/config.h b/keyboards/ferris/0_2/config.h
new file mode 100644
index 000000000..958cf4356
--- /dev/null
+++ b/keyboards/ferris/0_2/config.h
@@ -0,0 +1,80 @@
1/*
2Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20/* USB Device descriptor parameter */
21#define VENDOR_ID 0xC2AB
22#define PRODUCT_ID 0x0001
23#define DEVICE_VER 0x0002
24#define MANUFACTURER Pierre
25#define PRODUCT Ferris the keeb
26
27/* key matrix size */
28#define MATRIX_ROWS 8
29#define MATRIX_COLS 10
30
31#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
32#define MATRIX_COLS_PER_SIDE (MATRIX_COLS / 2)
33
34#define UNUSED_MCU 24
35#define UNUSED_MCP 7
36
37// wiring
38#define MATRIX_ROW_PINS_MCU \
39 { B7, B6, B5, A2 }
40#define MATRIX_COL_PINS_MCU \
41 { B8, B4, B3, A15, A14 }
42#define UNUSED_PINS_MCU \
43 { A0, A1, A3, A4, A5, A6, A7, A8, A9, A10, A13, B0, B1, B2, B9, B12, B13, B14, B15, C13, C14, C15, F0, F1 }
44#define MATRIX_ROW_PINS_MCP \
45 { B0, B1, B2, B3 }
46#define MATRIX_COL_PINS_MCP \
47 { A0, A1, A2, A3, A4 }
48#define UNUSED_PINS_MCP \
49 { B4, B5, B6, B7, A5, A6, A7 }
50
51#define MATRIX_ROW_PINS \
52 { B7, B6, B5, A2, A0, A0, A0, A0 }
53#define MATRIX_COL_PINS \
54 { B8, B4, B3, A15, A14, A1, A1, A1, A1, A1 }
55#define UNUSED_PINS \
56 { A3, A4, A5, A6, A7, A8, A9, A10, A13, B0, B1, B2, B9, B12, B13, B14, B15, C13, C14, C15, F0, F1 }
57
58/* COL2ROW, ROW2COL*/
59#define DIODE_DIRECTION COL2ROW
60
61/* define if matrix has ghost (lacks anti-ghosting diodes) */
62//#define MATRIX_HAS_GHOST
63
64/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
65#define DEBOUNCE 5
66
67/* i2c settings */
68
69#define I2C_DRIVER I2CD2
70#define I2C1_SCL_BANK GPIOB
71#define I2C1_SCL 10
72#define I2C1_SDA_BANK GPIOB
73#define I2C1_SDA 11
74#define I2C1_TIMINGR_PRESC 2U
75#define I2C1_TIMINGR_SCLDEL 1U
76#define I2C1_TIMINGR_SDADEL 0U
77#define I2C1_TIMINGR_SCLH 9U
78#define I2C1_TIMINGR_SCLL 26U
79#define I2C1_SCL_PAL_MODE 1
80#define I2C1_SDA_PAL_MODE 1
diff --git a/keyboards/ferris/0_2/halconf.h b/keyboards/ferris/0_2/halconf.h
new file mode 100644
index 000000000..037cbbdb4
--- /dev/null
+++ b/keyboards/ferris/0_2/halconf.h
@@ -0,0 +1,30 @@
1/* Copyright 2020 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/*
18 * This file was auto-generated by:
19 * `qmk chibios-confmigrate -i keyboards/ferris/0_2/halconf.h -r platforms/chibios/common/configs/halconf.h`
20 */
21
22#pragma once
23
24#define HAL_USE_I2C TRUE
25
26#define HAL_USE_PWM TRUE
27
28#define HAL_USE_SPI TRUE
29
30#include_next <halconf.h>
diff --git a/keyboards/ferris/0_2/matrix.c b/keyboards/ferris/0_2/matrix.c
new file mode 100644
index 000000000..afa8a344c
--- /dev/null
+++ b/keyboards/ferris/0_2/matrix.c
@@ -0,0 +1,255 @@
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#include <print.h>
29
30extern i2c_status_t mcp23017_status;
31#define MCP23017_I2C_TIMEOUT 1000
32#define I2C_WRITE 0x00
33#define I2C_READ 0x01
34// For a better understanding of the i2c protocol, this is a good read:
35// https://www.robot-electronics.co.uk/i2c-tutorial
36
37// I2C address:
38// See the datasheet, section 3.3.1 on addressing I2C devices and figure 3-6 for an
39// illustration
40// http://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf
41// All address pins of the mcp23017 are connected to the ground on the ferris
42// | 0 | 1 | 0 | 0 | A2 | A1 | A0 |
43// | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
44#define I2C_ADDR 0b0100000
45#define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE)
46#define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ)
47
48// Register addresses
49// See https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/Adafruit_MCP23017.h
50#define IODIRA 0x00 // i/o direction register
51#define IODIRB 0x01
52#define GPPUA 0x0C // GPIO pull-up resistor register
53#define GPPUB 0x0D
54#define MCP23017_GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
55#define MCP23017_GPIOB 0x13
56#define OLATA 0x14 // output latch register
57#define OLATB 0x15
58
59bool i2c_initialized = 0;
60i2c_status_t mcp23017_status = I2C_ADDR;
61
62#define I2C2_SCL_BANK GPIOB
63#define I2C2_SCL 10
64#define I2C2_SDA_BANK GPIOB
65#define I2C2_SDA 11
66
67uint8_t init_mcp23017(void) {
68 print("init mcp23017\n");
69 mcp23017_status = I2C_ADDR;
70
71 // I2C subsystem
72 if (i2c_initialized == 0) {
73 i2c_init(); // on pins D(1,0)
74 i2c_initialized = true;
75 wait_ms(MCP23017_I2C_TIMEOUT);
76 }
77
78 // set pin direction
79 // - unused : input : 1
80 // - input : input : 1
81 // - driving : output : 0
82 // This means: we will read all the bits on GPIOA
83 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
84 uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000};
85 print("before transmit\n");
86 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
87 uprintf("after transmit %i\n", mcp23017_status);
88 if (!mcp23017_status) {
89 // set pull-up
90 // - unused : on : 1
91 // - input : on : 1
92 // - driving : off : 0
93 // This means: we will read all the bits on GPIOA
94 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
95 uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000};
96 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, pullup_buf, sizeof(pullup_buf), MCP23017_I2C_TIMEOUT);
97 uprintf("after transmit2 %i\n", mcp23017_status);
98 }
99 return mcp23017_status;
100}
101
102/* matrix state(1:on, 0:off) */
103static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
104
105static matrix_row_t read_cols(uint8_t row);
106static void unselect_row(uint8_t row);
107static void unselect_rows(void);
108static void unselect_cols(void);
109static void select_row(uint8_t row);
110
111static uint8_t mcp23017_reset_loop;
112
113static void init_mcu_pins(void) {
114 unselect_rows();
115 unselect_cols();
116}
117
118void matrix_init_custom(void) {
119 debug_enable = true;
120 debug_matrix = true;
121 dprint("matrix_init_custom\n");
122 // initialize row and col
123 init_mcu_pins();
124 mcp23017_status = init_mcp23017();
125
126 // initialize matrix state: all keys off
127 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
128 matrix[i] = 0;
129 }
130}
131
132// Reads and stores a row, returning
133// whether a change occurred.
134static inline bool store_matrix_row(matrix_row_t current_matrix[], uint8_t index) {
135 matrix_row_t temp = read_cols(index);
136 if (current_matrix[index] != temp) {
137 current_matrix[index] = temp;
138 return true;
139 }
140 return false;
141}
142
143bool matrix_scan_custom(matrix_row_t current_matrix[]) {
144 if (mcp23017_status) { // if there was an error
145 if (++mcp23017_reset_loop == 0) {
146 // if (++mcp23017_reset_loop >= 1300) {
147 // since mcp23017_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
148 // this will be approx bit more frequent than once per second
149 print("trying to reset mcp23017\n");
150 mcp23017_status = init_mcp23017();
151 if (mcp23017_status) {
152 print("right side not responding\n");
153 } else {
154 print("right side attached\n");
155 }
156 }
157 }
158
159 bool changed = false;
160 for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) {
161 // select rows from left and right hands
162 uint8_t left_index = i;
163 uint8_t right_index = i + MATRIX_ROWS_PER_SIDE;
164
165 changed |= store_matrix_row(current_matrix, left_index);
166 changed |= store_matrix_row(current_matrix, right_index);
167
168 unselect_rows();
169 }
170
171 return changed;
172}
173
174static matrix_row_t read_cols(uint8_t row) {
175 select_row(row);
176 if (row < MATRIX_ROWS_PER_SIDE) {
177 pin_t matrix_col_pins_mcu[MATRIX_COLS_PER_SIDE] = MATRIX_COL_PINS_MCU;
178 matrix_row_t current_row_value = 0;
179 matrix_io_delay();
180 // For each col...
181 for (uint8_t col_index = 0; col_index < MATRIX_COLS_PER_SIDE; col_index++) {
182 // Select the col pin to read (active low)
183 uint8_t pin_state = readPin(matrix_col_pins_mcu[col_index]);
184
185 // Populate the matrix row with the state of the col pin
186 current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
187 }
188 unselect_row(row);
189 return current_row_value;
190 } else {
191 // we don't need a 30us delay anymore, because selecting a
192 // right-hand row requires more than 30us for i2c.
193 if (mcp23017_status) { // if there was an error
194 return 0;
195 } else {
196 uint8_t buf[] = {MCP23017_GPIOA};
197 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
198 // We read all the pins on GPIOA.
199 // 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.
200 // 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.
201 // 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.
202 uint8_t data[] = {0};
203 if (!mcp23017_status) {
204 mcp23017_status = i2c_receive(I2C_ADDR_READ, data, sizeof(data), MCP23017_I2C_TIMEOUT);
205 data[0] = ~(data[0]);
206 }
207 return data[0];
208 }
209 }
210}
211
212static void unselect_row(uint8_t row) {
213 pin_t matrix_row_pins_mcu[MATRIX_ROWS_PER_SIDE] = MATRIX_ROW_PINS_MCU;
214 setPinInputHigh(matrix_row_pins_mcu[row]);
215}
216
217static void unselect_rows(void) {
218 // no need to unselect on mcp23017, because the select step sets all
219 // the other row bits high, and it's not changing to a different
220 // direction
221
222 // unselect rows on microcontroller
223 pin_t matrix_row_pins_mcu[MATRIX_ROWS_PER_SIDE] = MATRIX_ROW_PINS_MCU;
224 for (int pin_index = 0; pin_index < MATRIX_ROWS_PER_SIDE; pin_index++) {
225 pin_t pin = matrix_row_pins_mcu[pin_index];
226 setPinInputHigh(pin);
227 }
228}
229static void unselect_cols(void) {
230 pin_t matrix_col_pins_mcu[MATRIX_COLS_PER_SIDE] = MATRIX_COL_PINS_MCU;
231 for (int pin_index = 0; pin_index < MATRIX_COLS_PER_SIDE; pin_index++) {
232 pin_t pin = matrix_col_pins_mcu[pin_index];
233 setPinInputHigh(pin);
234 }
235}
236
237static void select_row(uint8_t row) {
238 if (row < MATRIX_ROWS_PER_SIDE) {
239 // select on MCU
240 pin_t matrix_row_pins_mcu[MATRIX_ROWS_PER_SIDE] = MATRIX_ROW_PINS_MCU;
241 pin_t pin = matrix_row_pins_mcu[row];
242 setPinOutput(pin);
243 writePinLow(pin);
244 } else {
245 // select on mcp23017
246 if (mcp23017_status) { // if there was an error
247 // do nothing
248 } else {
249 // 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.
250 // 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.
251 uint8_t buf[] = {MCP23017_GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
252 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
253 }
254 }
255}
diff --git a/keyboards/ferris/0_2/mcuconf.h b/keyboards/ferris/0_2/mcuconf.h
new file mode 100644
index 000000000..05d37e7bc
--- /dev/null
+++ b/keyboards/ferris/0_2/mcuconf.h
@@ -0,0 +1,36 @@
1/* Copyright 2020 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/*
18 * This file was auto-generated by:
19 * `qmk chibios-confmigrate -i keyboards/ferris/0_2/mcuconf.h -r platforms/chibios/GENERIC_STM32_F072XB/configs/mcuconf.h`
20 */
21
22#pragma once
23
24#include_next <mcuconf.h>
25
26#undef STM32_I2C_USE_I2C2
27#define STM32_I2C_USE_I2C2 TRUE
28
29#undef STM32_I2C_USE_DMA
30#define STM32_I2C_USE_DMA FALSE
31
32#undef STM32_PWM_USE_TIM3
33#define STM32_PWM_USE_TIM3 TRUE
34
35#undef STM32_SPI_USE_SPI2
36#define STM32_SPI_USE_SPI2 TRUE
diff --git a/keyboards/ferris/0_2/readme.md b/keyboards/ferris/0_2/readme.md
new file mode 100644
index 000000000..bd98ce8ad
--- /dev/null
+++ b/keyboards/ferris/0_2/readme.md
@@ -0,0 +1,17 @@
1# Ferris 0.2
2
3![Ferris 0.2 - bling, top view](https://i.imgur.com/LwKlmnzh.jpg)
4![Ferris 0.2 - bling, bottom view](https://i.imgur.com/qGnYGVOh.jpg)
5
6An stm32f072 based split 34 keys column staggered keyboard named and decorated after the rustlang mascott. All PCB files and some thoughts on the design are available on the [project's github page](https://github.com/pierrechevalier83/ferris)
7
8* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83)
9* Hardware Supported:
10 * Ferris 0.2: stm32f072 chip. Comes in 4 variants: bling, mini, high and compact
11* Hardware Availability: Pierre Chevalier has been selling keyboard kits (see the #ferris channel in the 40% discord chat). Wider availability is on the horizon.
12
13Make examples for this keyboard (after setting up your build environment):
14
15 make ferris/0_2:default
16
17See 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/ferris/0_2/rules.mk b/keyboards/ferris/0_2/rules.mk
new file mode 100644
index 000000000..5a7649b75
--- /dev/null
+++ b/keyboards/ferris/0_2/rules.mk
@@ -0,0 +1,25 @@
1# MCU name
2MCU = STM32F072
3
4# change yes to no to disable
5#
6BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
7MOUSEKEY_ENABLE = yes # Mouse keys
8EXTRAKEY_ENABLE = yes # Audio control and System control
9CONSOLE_ENABLE = no # Console for debug
10COMMAND_ENABLE = no # Commands for debug and configuration
11# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
12SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
13# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
14NKRO_ENABLE = no # USB Nkey Rollover
15BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
16RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
17BLUETOOTH_ENABLE = no # Enable Bluetooth
18AUDIO_ENABLE = no # Audio output
19UNICODE_ENABLE = yes
20CUSTOM_MATRIX = lite
21NO_USB_STARTUP_CHECK = yes
22LTO_ENABLE = no
23
24SRC += matrix.c
25QUANTUM_LIB_SRC += i2c_master.c
diff --git a/keyboards/ferris/keymaps/test/config.h b/keyboards/ferris/keymaps/test/config.h
new file mode 100644
index 000000000..f784af4d1
--- /dev/null
+++ b/keyboards/ferris/keymaps/test/config.h
@@ -0,0 +1,20 @@
1/*
2Copyright 2021 Pierre Chevalier <pierrechevalier83@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20#define DEBUG_MATRIX_SCAN_RATE
diff --git a/keyboards/ferris/keymaps/test/keymap.c b/keyboards/ferris/keymaps/test/keymap.c
new file mode 100644
index 000000000..30e2e9cff
--- /dev/null
+++ b/keyboards/ferris/keymaps/test/keymap.c
@@ -0,0 +1,13 @@
1#include QMK_KEYBOARD_H
2
3void matrix_init_user(void) {
4 debug_enable=true;
5 debug_matrix=true;
6 //debug_keyboard=true;
7 //debug_mouse=true;
8}
9
10const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
11 [0] = LAYOUT(KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_P0, DEBUG, KC_P2, KC_P3)
12};
13
diff --git a/keyboards/ferris/keymaps/test/readme.md b/keyboards/ferris/keymaps/test/readme.md
new file mode 100644
index 000000000..c3b3fe90e
--- /dev/null
+++ b/keyboards/ferris/keymaps/test/readme.md
@@ -0,0 +1,5 @@
1# A test keymap for the Ferris keyboard
2
3This keymap is not intended to be used to use the Ferris as a usable keyboard, but rather it is meant to be a very simple keymap used to test the hardware works properly. It can also be used to test firmware being written for new versions with a minimum amount of complexity coming from the keymap itself.
4
5The keymap is composed of a single qwerty layer with a unique digit bound to each non-alpha key.
diff --git a/keyboards/ferris/keymaps/test/rules.mk b/keyboards/ferris/keymaps/test/rules.mk
new file mode 100644
index 000000000..15b7f725b
--- /dev/null
+++ b/keyboards/ferris/keymaps/test/rules.mk
@@ -0,0 +1 @@
CONSOLE_ENABLE = yes
diff --git a/keyboards/ferris/readme.md b/keyboards/ferris/readme.md
index 74a08a38f..84ac85b57 100644
--- a/keyboards/ferris/readme.md
+++ b/keyboards/ferris/readme.md
@@ -1,19 +1,20 @@
1# Ferris 1# Ferris
2 2
3![Ferris, top view](https://imgur.com/V4QuaGs.jpg) 3![Ferris, familly pic](https://i.imgur.com/TCjkquRh.jpeg)
4![Ferris, bottom view](https://i.imgur.com/7DJYME8.jpg)
5 4
6A split 34 keys column staggered keyboard named and decorated after the rustlang mascott. All PCB files and some thoughts on the design are available on the [project's github page](https://github.com/pierrechevalier83/ferris) 5A split 34 keys column staggered keyboard named and decorated after the rustlang mascott. All PCB files and some thoughts on the design are available on the [project's github page](https://github.com/pierrechevalier83/ferris)
7 6
8* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83) 7* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83)
9* Hardware Supported: 8* Hardware Supported:
10 * Ferris 0.1 (With atmega32u4 chip. Comes in 4 variants: base, low, high and compact) 9 * Ferris 0.1 (With atmega32u4 chip. Comes in 4 variants: base, low, high and compact)
10 * Ferris 0.2 (With stm32f072 chip. Comes in 4 variants: bling, mini, high and compact)
11 * Ferris sweep (With pro-micro. Comes in a couple of PCB edge cuts shapes, but with identical pinout) 11 * Ferris sweep (With pro-micro. Comes in a couple of PCB edge cuts shapes, but with identical pinout)
12* Hardware Availability: Pierre Chevalier has been selling keyboard kits (see the #ferris channel in the 40% discord chat). Wider availability is on the horizon. 12* Hardware Availability: Pierre Chevalier has been selling keyboard kits (see the #ferris channel in the 40% discord chat). Wider availability is on the horizon.
13 13
14Make examples for this keyboard (after setting up your build environment): 14Make examples for this keyboard (after setting up your build environment):
15 15
16 make ferris/0_1:default 16 make ferris/0_1:default
17 make ferris/0_2:default
17 make ferris/sweep:default:avrdude-split-right 18 make ferris/sweep:default:avrdude-split-right
18 19
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). 20See 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/ferris/sweep/readme.md b/keyboards/ferris/sweep/readme.md
new file mode 100644
index 000000000..d7102aa1a
--- /dev/null
+++ b/keyboards/ferris/sweep/readme.md
@@ -0,0 +1,18 @@
1# Ferris sweep
2
3![Ferris sweep, top view](https://i.imgur.com/5qCZUv6h.jpg)
4![Ferris sweep, bottom view](https://i.imgur.com/ZC47CJth.jpg)
5
6A version of the Ferris keyboard that uses a daughterboard, designed by the fantastic @davidphilipbarr with some input from @pierrechevalier83 for the copper pad. All PCB files are available on the [project's github page](https://github.com/davidphilipbarr/Sweep)
7
8* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83)
9* Hardware Supported:
10 * Ferris sweep (With pro-micro. Comes in a couple of PCB edge cuts shapes, but with identical pinout)
11* Hardware Availability: @iamnotyourbroom in the 40% discord chat server may have some spares for you.
12
13Make examples for this keyboard (after setting up your build environment):
14
15 make ferris/sweep:default:avrdude-split-left
16 make ferris/sweep:default:avrdude-split-right
17
18See 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).