Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ferris 0.2 #12133

Merged
merged 10 commits into from
Apr 18, 2021
77 changes: 24 additions & 53 deletions keyboards/ferris/0_1/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,25 @@ uint8_t init_mcp23017(void) {
// - unused : input : 1
// - input : input : 1
// - driving : output : 0
mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_write(IODIRA, I2C_TIMEOUT);
if (mcp23017_status) goto out;
// This means: we will read all the bits on GPIOA
mcp23017_status = i2c_write(0b11111111, I2C_TIMEOUT);
if (mcp23017_status) goto out;
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
mcp23017_status = i2c_write(0b11110000, I2C_TIMEOUT);
if (mcp23017_status) goto out;
i2c_stop();

// set pull-up
// - unused : on : 1
// - input : on : 1
// - driving : off : 0
mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_write(GPPUA, I2C_TIMEOUT);
if (mcp23017_status) goto out;
// This means: we will read all the bits on GPIOA
mcp23017_status = i2c_write(0b11111111, I2C_TIMEOUT);
if (mcp23017_status) goto out;
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
mcp23017_status = i2c_write(0b11110000, I2C_TIMEOUT);
if (mcp23017_status) goto out;

out:
i2c_stop();
uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000};
mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
if (!mcp23017_status) {
// set pull-up
// - unused : on : 1
// - input : on : 1
// - driving : off : 0
// This means: we will read all the bits on GPIOA
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000};
mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, pullup_buf, sizeof(pullup_buf), I2C_TIMEOUT);
}
return mcp23017_status;
}

/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
static matrix_row_t matrix[MATRIX_ROWS]; // debounced values

static matrix_row_t read_cols(uint8_t row);
static void init_cols(void);
Expand All @@ -124,7 +109,7 @@ void matrix_init_custom(void) {

// initialize matrix state: all keys off
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
matrix[i] = 0;
matrix[i] = 0;
}
}

Expand Down Expand Up @@ -217,25 +202,18 @@ static matrix_row_t read_cols(uint8_t row) {
if (mcp23017_status) { // if there was an error
return 0;
} else {
uint8_t data = 0;
mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_write(GPIOA, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_read_nack(I2C_TIMEOUT);
if (mcp23017_status < 0) goto out;
uint8_t buf[] = {GPIOA};
mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
// We read all the pins on GPIOA.
// 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.
// 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.
// 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.
data = ~((uint8_t)mcp23017_status);
mcp23017_status = I2C_STATUS_SUCCESS;
out:
i2c_stop();
// return reverse_bits(data, MATRIX_COLS_PER_SIDE);
return data;
uint8_t data[] = {0};
if (!mcp23017_status) {
mcp23017_status = i2c_receive(I2C_ADDR_READ, data, sizeof(data), I2C_TIMEOUT);
data[0] = ~(data[0]);
}
return data[0];
}
}
}
Expand Down Expand Up @@ -266,17 +244,10 @@ static void select_row(uint8_t row) {
if (mcp23017_status) { // if there was an error
// do nothing
} else {
mcp23017_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT);
if (mcp23017_status) goto out;
mcp23017_status = i2c_write(GPIOB, I2C_TIMEOUT);
if (mcp23017_status) goto out;
// 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.
// 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.
mcp23017_status = i2c_write(0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE)), I2C_TIMEOUT);

if (mcp23017_status) goto out;
out:
i2c_stop();
uint8_t buf[] = {GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT);
}
}
}
17 changes: 17 additions & 0 deletions keyboards/ferris/0_1/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ferris 0.1

![Ferris 0.1 - base, top view](https://i.imgur.com/s6nTn0Ch.jpg)
![Ferris 0.1 - base, bottom view](https://i.imgur.com/Ymlac2Ah.jpg)

An 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)

* Keyboard Maintainer: [Pierre Chevalier](https://github.com/pierrechevalier83)
* Hardware Supported:
* Ferris 0.1: atmega32u4 chip. Comes in 4 variants: base, low, high and compact
* Hardware Availability: Pierre Chevalier has been selling keyboard kits (see the #ferris channel in the 40% discord chat). Wider availability is on the horizon.

Make examples for this keyboard (after setting up your build environment):

make ferris/0_1:default

See 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).
17 changes: 17 additions & 0 deletions keyboards/ferris/0_2/0_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "0_2.h"
43 changes: 43 additions & 0 deletions keyboards/ferris/0_2/0_2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "quantum.h"

// clang-format off

/* left hand right hand */
#define LAYOUT(\
K0_0, K0_1, K0_2, K0_3, K0_4, K0_5, K0_6, K0_7, K0_8, K0_9,\
K1_0, K1_1, K1_2, K1_3, K1_4, K1_5, K1_6, K1_7, K1_8, K1_9,\
K2_0, K2_1, K2_2, K2_3, K2_4, K2_5, K2_6, K2_7, K2_8, K2_9,\
K3_3, K3_4, K3_5, K3_6)\
/* matrix positions */\
{\
{K0_0, K0_1, K0_2, K0_3, K0_4},\
{K1_0, K1_1, K1_2, K1_3, K1_4},\
{K2_0, K2_1, K2_2, K2_3, K2_4},\
{KC_NO, KC_NO, KC_NO, K3_3, K3_4},\
\
{K0_5, K0_6, K0_7, K0_8, K0_9},\
{K1_5, K1_6, K1_7, K1_8, K1_9},\
{K2_5, K2_6, K2_7, K2_8, K2_9},\
{K3_5, K3_6, KC_NO, KC_NO, KC_NO}\
}

// clang-format on
40 changes: 40 additions & 0 deletions keyboards/ferris/0_2/chconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright 2020 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* This file was auto-generated by:
* `qmk chibios-confmigrate -i keyboards/ferris/0_2/chconf.h -r platforms/chibios/common/configs/chconf.h`
*/

#pragma once

#define CH_CFG_ST_FREQUENCY 10000

#define CH_CFG_OPTIMIZE_SPEED FALSE

#define CH_CFG_USE_REGISTRY TRUE

#define CH_CFG_USE_WAITEXIT TRUE

#define CH_CFG_USE_CONDVARS TRUE

#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE

#define CH_CFG_USE_MESSAGES TRUE

#define CH_CFG_USE_MAILBOXES TRUE

#include_next <chconf.h>
80 changes: 80 additions & 0 deletions keyboards/ferris/0_2/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2020 Pierre Chevalier <pierrechevalier83@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

/* USB Device descriptor parameter */
#define VENDOR_ID 0xC2AB
#define PRODUCT_ID 0x0001
#define DEVICE_VER 0x0002
#define MANUFACTURER Pierre
#define PRODUCT Ferris the keeb

/* key matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 10

#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
#define MATRIX_COLS_PER_SIDE (MATRIX_COLS / 2)

#define UNUSED_MCU 24
#define UNUSED_MCP 7

// wiring
#define MATRIX_ROW_PINS_MCU \
{ B7, B6, B5, A2 }
#define MATRIX_COL_PINS_MCU \
{ B8, B4, B3, A15, A14 }
#define UNUSED_PINS_MCU \
{ A0, A1, A3, A4, A5, A6, A7, A8, A9, A10, A13, B0, B1, B2, B9, B12, B13, B14, B15, C13, C14, C15, F0, F1 }
#define MATRIX_ROW_PINS_MCP \
{ B0, B1, B2, B3 }
#define MATRIX_COL_PINS_MCP \
{ A0, A1, A2, A3, A4 }
#define UNUSED_PINS_MCP \
{ B4, B5, B6, B7, A5, A6, A7 }

#define MATRIX_ROW_PINS \
{ B7, B6, B5, A2, A0, A0, A0, A0 }
#define MATRIX_COL_PINS \
{ B8, B4, B3, A15, A14, A1, A1, A1, A1, A1 }
#define UNUSED_PINS \
{ A3, A4, A5, A6, A7, A8, A9, A10, A13, B0, B1, B2, B9, B12, B13, B14, B15, C13, C14, C15, F0, F1 }

/* COL2ROW, ROW2COL*/
#define DIODE_DIRECTION COL2ROW

/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5

/* i2c settings */

#define I2C_DRIVER I2CD2
#define I2C1_SCL_BANK GPIOB
#define I2C1_SCL 10
#define I2C1_SDA_BANK GPIOB
#define I2C1_SDA 11
#define I2C1_TIMINGR_PRESC 2U
#define I2C1_TIMINGR_SCLDEL 1U
#define I2C1_TIMINGR_SDADEL 0U
#define I2C1_TIMINGR_SCLH 9U
#define I2C1_TIMINGR_SCLL 26U
#define I2C1_SCL_PAL_MODE 1
#define I2C1_SDA_PAL_MODE 1
30 changes: 30 additions & 0 deletions keyboards/ferris/0_2/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright 2020 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* This file was auto-generated by:
* `qmk chibios-confmigrate -i keyboards/ferris/0_2/halconf.h -r platforms/chibios/common/configs/halconf.h`
*/

#pragma once

#define HAL_USE_I2C TRUE

#define HAL_USE_PWM TRUE

#define HAL_USE_SPI TRUE

#include_next <halconf.h>
Loading