summaryrefslogtreecommitdiffstats
path: root/keyboards/gergo
diff options
context:
space:
mode:
authorJeremy Bernhardt <jeremythegeek@gmail.com>2019-01-12 02:44:06 +0100
committerDrashna Jaelre <drashna@live.com>2019-01-12 02:44:06 +0100
commitd8eace35ebae454923f3ed30fc93ad357640d804 (patch)
tree433209389a8f24aee55ee61f6441cdf4c1014b19 /keyboards/gergo
parent52ccd8d89f7e4c8fca0dc15c269e8b140de520d9 (diff)
downloadqmk_firmware-d8eace35ebae454923f3ed30fc93ad357640d804.tar.gz
qmk_firmware-d8eace35ebae454923f3ed30fc93ad357640d804.tar.xz
[Keyboard] Adding support for Gergo (#4792)
* Commited into clean repo * Gergo initial release * Cleaning up * Cleaning up * Update readme.md * Updated image, fixed MD formatting, added clairity * Moved keymap to keyboard subdir, modified rules.mk * Cleaned header guards * Cleaned header guards. Read the rest of the PR comments * Update keyboards/gergo/keymaps/default/keymap.c Co-Authored-By: germ <jeremythegeek@gmail.com> * Update keyboards/gergo/readme.md Co-Authored-By: germ <jeremythegeek@gmail.com> * Moved makefiles to keymap mod-area-thingy-with-overrides * Update rules.mk Slow the roll on the defaults while I wait for merge * Update rules.mk * Cleaning cleaning cleaning * More housekeeping. Keeping optdefs * moved keyboard specfic conf to config.h. Can we merge yet? * added info.json
Diffstat (limited to 'keyboards/gergo')
-rw-r--r--keyboards/gergo/config.h73
-rw-r--r--keyboards/gergo/gergo.c66
-rw-r--r--keyboards/gergo/gergo.h58
-rw-r--r--keyboards/gergo/i2cmaster.h178
-rw-r--r--keyboards/gergo/info.json277
-rw-r--r--keyboards/gergo/keymaps/default/keymap.c151
-rw-r--r--keyboards/gergo/keymaps/default/readme.md10
-rw-r--r--keyboards/gergo/keymaps/default/rules.mk36
-rw-r--r--keyboards/gergo/matrix.c517
-rw-r--r--keyboards/gergo/readme.md26
-rw-r--r--keyboards/gergo/rules.mk20
11 files changed, 1412 insertions, 0 deletions
diff --git a/keyboards/gergo/config.h b/keyboards/gergo/config.h
new file mode 100644
index 000000000..a795f8dba
--- /dev/null
+++ b/keyboards/gergo/config.h
@@ -0,0 +1,73 @@
+/*
+Copyright 2012 Jun Wako <wakojun@gmail.com>
+Copyright 2013 Oleg Kostyuk <cub.uanic@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/>.
+*/
+
+// Copy and worked on with love from the EZ team
+
+#pragma once
+#include "config_common.h"
+
+/* Defaults */
+#ifndef BALLSTEP
+#define BALLSTEP 20
+#endif
+
+#ifndef SCROLLSTEP
+#define SCROLLSTEP 1
+#endif
+
+#define VERBOSE
+
+/* USB Device descriptor parameter */
+#define VENDOR_ID 0xFEED
+#define PRODUCT_ID 0x1307
+#define DEVICE_VER 0x0001
+#define MANUFACTURER g Heavy Industries
+#define PRODUCT Gergo
+#define DESCRIPTION QMK keyboard firmware for Gergo
+
+/* key matrix size */
+#define MATRIX_ROWS 14
+#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
+#define MATRIX_COLS 4
+
+#define MOUSEKEY_INTERVAL 20
+#define MOUSEKEY_DELAY 0
+#define MOUSEKEY_TIME_TO_MAX 60
+#define MOUSEKEY_MAX_SPEED 7
+#define MOUSEKEY_WHEEL_DELAY 0
+#define TAPPING_TOGGLE 1
+
+/* define if matrix has ghost */
+//#define MATRIX_HAS_GHOST
+
+#define TAPPING_TERM 200
+#define IGNORE_MOD_TAP_INTERRUPT // this makes it possible to do rolling combos (zx) with keys that convert to other keys on hold (z becomes ctrl when you hold it, and when this option isn't enabled, z rapidly followed by x actually sends Ctrl-x. That's bad.)
+
+/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
+#define LOCKING_SUPPORT_ENABLE
+/* Locking resynchronize hack */
+#define LOCKING_RESYNC_ENABLE
+
+/* key combination for command */
+#define IS_COMMAND() ( \
+ keyboard_report->mods == (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL)) || \
+ keyboard_report->mods == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) \
+)
+
+#define DEBOUNCE 5
+#define USB_MAX_POWER_CONSUMPTION 500
diff --git a/keyboards/gergo/gergo.c b/keyboards/gergo/gergo.c
new file mode 100644
index 000000000..c6ba91bb2
--- /dev/null
+++ b/keyboards/gergo/gergo.c
@@ -0,0 +1,66 @@
+#include QMK_KEYBOARD_H
+
+bool i2c_initialized = 0;
+i2c_status_t mcp23018_status = 0x20;
+
+void matrix_init_kb(void) {
+ // (tied to Vcc for hardware convenience)
+ //DDRB &= ~(1<<4); // set B(4) as input
+ //PORTB &= ~(1<<4); // set B(4) internal pull-up disabled
+
+ // unused pins - C7, D4, D5, D7, E6
+ // set as input with internal pull-up enabled
+ DDRC &= ~(1<<7);
+ DDRD &= ~(1<<5 | 1<<4 | 1<<6 | 1<<7);
+ DDRE &= ~(1<<6);
+ PORTC |= (1<<7);
+ PORTD |= (1<<5 | 1<<4 | 1<<6 | 1<<7);
+ PORTE |= (1<<6);
+
+ matrix_init_user();
+}
+
+
+uint8_t init_mcp23018(void) {
+ print("starting init");
+ mcp23018_status = 0x20;
+
+ // I2C subsystem
+
+ // uint8_t sreg_prev;
+ // sreg_prev=SREG;
+ // cli();
+
+ if (i2c_initialized == 0) {
+ i2c_init(); // on pins D(1,0)
+ i2c_initialized = true;
+ _delay_ms(1000);
+ }
+ // i2c_init(); // on pins D(1,0)
+ // _delay_ms(1000);
+
+ // set pin direction
+ // - unused : input : 1
+ // - input : input : 1
+ // - driving : output : 0
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(IODIRA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b10000000, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b11111111, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
+
+ // set pull-up
+ // - unused : on : 1
+ // - input : on : 1
+ // - driving : off : 0
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPPUA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b10000000, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b11111111, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+
+out:
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
+ // SREG=sreg_prev;
+ //uprintf("Init %x\n", mcp23018_status);
+ return mcp23018_status;
+}
diff --git a/keyboards/gergo/gergo.h b/keyboards/gergo/gergo.h
new file mode 100644
index 000000000..c0d885029
--- /dev/null
+++ b/keyboards/gergo/gergo.h
@@ -0,0 +1,58 @@
+#pragma once
+#include <util/delay.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include "quantum.h"
+#include "i2c_master.h"
+#include "matrix.h"
+
+
+extern i2c_status_t mcp23018_status;
+#define ERGODOX_EZ_I2C_TIMEOUT 1000
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+#define CPU_16MHz 0x00
+
+// I2C aliases and register addresses (see "mcp23018.md")
+//#define I2C_ADDR 0b0100000
+#define I2C_ADDR 0x20
+#define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
+#define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
+#define IODIRA 0x00 // i/o direction register
+#define IODIRB 0x01
+#define GPPUA 0x0C // GPIO pull-up resistor register
+#define GPPUB 0x0D
+#define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
+#define GPIOB 0x13
+#define OLATA 0x14 // output latch register
+#define OLATB 0x15
+
+void init_ergodox(void);
+uint8_t init_mcp23018(void);
+
+/* ---------- LEFT HAND ----------- ---------- RIGHT HAND ---------- */
+#define LAYOUT_GERGO( \
+ L00,L01,L02,L03,L04,L05, R00,R01,R02,R03,R04,R05, \
+ L10,L11,L12,L13,L14,L15,L16, R10,R11,R12,R13,R14,R15,R16, \
+ L20,L21,L22,L23,L24,L25,L26, R20,R21,R22,R23,R24,R25,R26, \
+ L31,L32, R33,R34, \
+ L30, R30, \
+ L33,L34, R31,R32) \
+ \
+ /* matrix positions */ \
+ { \
+ { KC_NO, L16, L26, L30}, \
+ { L05, L15, L25, L34}, \
+ { L04, L14, L24, L33}, \
+ { L03, L13, L23, L32}, \
+ { L02, L12, L22, L31}, \
+ { L01, L11, L21, KC_NO}, \
+ { L00, L10, L20, KC_NO}, \
+ \
+ { R10, KC_NO, R20, R30}, \
+ { R00, R11, R21, R31}, \
+ { R01, R12, R22, R32}, \
+ { R02, R13, R23, R33}, \
+ { R03, R14, R24, R34}, \
+ { R04, R15, R25, KC_NO}, \
+ { R05, R16, R26, KC_NO}, \
+}
diff --git a/keyboards/gergo/i2cmaster.h b/keyboards/gergo/i2cmaster.h
new file mode 100644
index 000000000..72e050849
--- /dev/null
+++ b/keyboards/gergo/i2cmaster.h
@@ -0,0 +1,178 @@
+#ifndef _I2CMASTER_H
+#define _I2CMASTER_H 1
+/*************************************************************************
+* Title: C include file for the I2C master interface
+* (i2cmaster.S or twimaster.c)
+* Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
+* File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $
+* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3
+* Target: any AVR device
+* Usage: see Doxygen manual
+**************************************************************************/
+
+#ifdef DOXYGEN
+/**
+ @defgroup pfleury_ic2master I2C Master library
+ @code #include <i2cmaster.h> @endcode
+
+ @brief I2C (TWI) Master Software Library
+
+ Basic routines for communicating with I2C slave devices. This single master
+ implementation is limited to one bus master on the I2C bus.
+
+ This I2c library is implemented as a compact assembler software implementation of the I2C protocol
+ which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c).
+ Since the API for these two implementations is exactly the same, an application can be linked either against the
+ software I2C implementation or the hardware I2C implementation.
+
+ Use 4.7k pull-up resistor on the SDA and SCL pin.
+
+ Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module
+ i2cmaster.S to your target when using the software I2C implementation !
+
+ Adjust the CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion.
+
+ @note
+ The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted
+ to GNU assembler and AVR-GCC C call interface.
+ Replaced the incorrect quarter period delays found in AVR300 with
+ half period delays.
+
+ @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury
+
+ @par API Usage Example
+ The following code shows typical usage of this library, see example test_i2cmaster.c
+
+ @code
+
+ #include <i2cmaster.h>
+
+
+ #define Dev24C02 0xA2 // device address of EEPROM 24C02, see datasheet
+
+ int main(void)
+ {
+ unsigned char ret;
+
+ i2c_init(); // initialize I2C library
+
+ // write 0x75 to EEPROM address 5 (Byte Write)
+ i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode
+ i2c_write(0x05); // write address = 5
+ i2c_write(0x75); // write value 0x75 to EEPROM
+ i2c_stop(); // set stop conditon = release bus
+
+
+ // read previously written value back from EEPROM address 5
+ i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode
+
+ i2c_write(0x05); // write address = 5
+ i2c_rep_start(Dev24C02+I2C_READ); // set device address and read mode
+
+ ret = i2c_readNak(); // read one byte from EEPROM
+ i2c_stop();
+
+ for(;;);
+ }
+ @endcode
+
+*/
+#endif /* DOXYGEN */
+
+/**@{*/
+
+#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
+#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
+#endif
+
+#include <avr/io.h>
+
+/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */
+#define I2C_READ 1
+
+/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */
+#define I2C_WRITE 0
+
+
+/**
+ @brief initialize the I2C master interace. Need to be called only once
+ @param void
+ @return none
+ */
+void i2c_init(void);
+
+
+/**
+ @brief Terminates the data transfer and releases the I2C bus
+ @param void
+ @return none
+ */
+void i2c_stop(void);
+
+
+/**
+ @brief Issues a start condition and sends address and transfer direction
+
+ @param addr address and transfer direction of I2C device
+ @retval 0 device accessible
+ @retval 1 failed to access device
+ */
+unsigned char i2c_start(unsigned char addr);
+
+
+/**
+ @brief Issues a repeated start condition and sends address and transfer direction
+
+ @param addr address and transfer direction of I2C device
+ @retval 0 device accessible
+ @retval 1 failed to access device
+ */
+unsigned char i2c_rep_start(unsigned char addr);
+
+
+/**
+ @brief Issues a start condition and sends address and transfer direction
+
+ If device is busy, use ack polling to wait until device ready
+ @param addr address and transfer direction of I2C device
+ @return none
+ */
+void i2c_start_wait(unsigned char addr);
+
+
+/**
+ @brief Send one byte to I2C device
+ @param data byte to be transfered
+ @retval 0 write successful
+ @retval 1 write failed
+ */
+unsigned char i2c_write(unsigned char data);
+
+
+/**
+ @brief read one byte from the I2C device, request more data from device
+ @return byte read from I2C device
+ */
+unsigned char i2c_readAck(void);
+
+/**
+ @brief read one byte from the I2C device, read is followed by a stop condition
+ @return byte read from I2C device
+ */
+unsigned char i2c_readNak(void);
+
+/**
+ @brief read one byte from the I2C device
+
+ Implemented as a macro, which calls either i2c_readAck or i2c_readNak
+
+ @param ack 1 send ack, request more data from device<br>
+ 0 send nak, read is followed by a stop condition
+ @return byte read from I2C device
+ */
+unsigned char i2c_read(unsigned char ack);
+#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
+
+
+/**@}*/
+#endif
diff --git a/keyboards/gergo/info.json b/keyboards/gergo/info.json
new file mode 100644
index 000000000..433582b54
--- /dev/null
+++ b/keyboards/gergo/info.json
@@ -0,0 +1,277 @@
+{
+ "maintainer": "germ",
+ "height": 4.75,
+ "width": 19.5,
+ "keyboard_name": "Gergo",
+ "url": "http://gboards.ca",
+ "layouts": {
+ "LAYOUT": {
+ "layout": [
+ {
+ "label": "L00",
+ "w": 1.5,
+ "x": 0,
+ "y": 0.38
+ },
+ {
+ "label": "L01",
+ "x": 1.5,
+ "y": 0.38
+ },
+ {
+ "label": "L02",
+ "x": 2.5,
+ "y": 0.13
+ },
+ {
+ "label": "L03",
+ "x": 3.5,
+ "y": 0
+ },
+ {
+ "label": "L04",
+ "x": 4.5,
+ "y": 0.13
+ },
+ {
+ "label": "L05",
+ "x": 5.5,
+ "y": 0.25
+ },
+ {
+ "label": "R00",
+ "x": 13,
+ "y": 0.25
+ },
+ {
+ "label": "R01",
+ "x": 14,
+ "y": 0.13
+ },
+ {
+ "label": "R02",
+ "x": 15,
+ "y": 0
+ },
+ {
+ "label": "R03",
+ "x": 16,
+ "y": 0.13
+ },
+ {
+ "label": "R04",
+ "x": 17,
+ "y": 0.38
+ },
+ {
+ "label": "R05",
+ "w": 1.5,
+ "x": 18,
+ "y": 0.38
+ },
+ {
+ "label": "L10",
+ "w": 1.5,
+ "x": 0,
+ "y": 1.3800000000000001
+ },
+ {
+ "label": "L11",
+ "x": 1.5,
+ "y": 1.3800000000000001
+ },
+ {
+ "label": "L12",
+ "x": 2.5,
+ "y": 1.1300000000000001
+ },
+ {
+ "label": "L13",
+ "x": 3.5,
+ "y": 1.0
+ },
+ {
+ "label": "L14",
+ "x": 4.5,
+ "y": 1.1300000000000001
+ },
+ {
+ "label": "L15",
+ "x": 5.5,
+ "y": 1.25
+ },
+ {
+ "h": 1.5,
+ "label": "L16",
+ "x": 6.5,
+ "y": 0.25
+ },
+ {
+ "h": 1.5,
+ "label": "R10",
+ "x": 12,
+ "y": 0.25
+ },
+ {
+ "label": "R11",
+ "x": 13,
+ "y": 1.25
+ },
+ {
+ "label": "R12",
+ "x": 14,
+ "y": 1.1300000000000001
+ },
+ {
+ "label": "R13",
+ "x": 15,
+ "y": 1.0
+ },
+ {
+ "label": "R14",
+ "x": 16,
+ "y": 1.1300000000000001
+ },
+ {
+ "label": "R15",
+ "x": 17,
+ "y": 1.3800000000000001
+ },
+ {
+ "label": "R16",
+ "w": 1.5,
+ "x": 18,
+ "y": 1.3800000000000001
+ },
+ {
+ "label": "L20",
+ "w": 1.5,
+ "x": 0,
+ "y": 2.38
+ },
+ {
+ "label": "L21",
+ "x": 1.5,
+ "y": 2.38
+ },
+ {
+ "label": "L22",
+ "x": 2.5,
+ "y": 2.13
+ },
+ {
+ "label": "L23",
+ "x": 3.5,
+ "y": 2
+ },
+ {
+ "label": "L24",
+ "x": 4.5,
+ "y": 2.13
+ },
+ {
+ "label": "L25",
+ "x": 5.5,
+ "y": 2.25
+ },
+ {
+ "h": 1.5,
+ "label": "L26",
+ "x": 6.5,
+ "y": 1.75
+ },
+ {
+ "h": 1.5,
+ "label": "R20",
+ "x": 12,
+ "y": 1.75
+ },
+ {
+ "label": "R21",
+ "x": 13,
+ "y": 2.25
+ },
+ {
+ "label": "R22",
+ "x": 14,
+ "y": 2.13
+ },
+ {
+ "label": "R23",
+ "x": 15,
+ "y": 2
+ },
+ {
+ "label": "R24",
+ "x": 16,
+ "y": 2.13
+ },
+ {
+ "label": "R25",
+ "x": 17,
+ "y": 2.38
+ },
+ {
+ "label": "R26",
+ "w": 1.5,
+ "x": 18,
+ "y": 2.38
+ },
+ {
+ "label": "L31",
+ "x": 4.75,
+ "y": 3.25
+ },
+ {
+ "label": "L32",
+ "x": 6,
+ "y": 3.63
+ },
+ {
+ "label": "R33",
+ "x": 12.5,
+ "y": 3.63
+ },
+ {
+ "label": "R34",
+ "x": 13.75,
+ "y": 3.25
+ },
+ {
+ "label": "L30",
+ "x": 8.25,
+ "y": 2.75
+ },
+ {
+ "label": "R30",
+ "x": 10.25,
+ "y": 2.75
+ },
+ {
+ "h": 2,
+ "label": "L33",
+ "x": 7.25,
+ "y": 3.75
+ },
+ {
+ "h": 2,
+ "label": "L34",
+ "x": 8.25,
+ "y": 3.75
+ },
+ {
+ "h": 2,
+ "label": "R31",
+ "x": 10.25,
+ "y": 3.75
+ },
+ {
+ "h": 2,
+ "label": "R32",
+ "x": 11.25,
+ "y": 3.75
+ }
+ ]
+ }
+ }
+}
diff --git a/keyboards/gergo/keymaps/default/keymap.c b/keyboards/gergo/keymaps/default/keymap.c
new file mode 100644
index 000000000..fabd945fe
--- /dev/null
+++ b/keyboards/gergo/keymaps/default/keymap.c
@@ -0,0 +1,151 @@
+/* Good on you for modifying your layout! if you don't have
+ * time to read the QMK docs, a list of keycodes can be found at
+ *
+ * https://github.com/qmk/qmk_firmware/blob/master/docs/keycodes.md
+ *
+ * There's also a template for adding new layers at the bottom of this file!
+ */
+
+#include QMK_KEYBOARD_H
+
+#define IGNORE_MOD_TAP_INTERRUPT
+#define BASE 0 // default layer
+#define SYMB 1 // symbols
+#define NUMB 2 // numbers/motion
+
+// Blank template at the bottom
+
+enum customKeycodes {
+ URL = 1
+};
+
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+/* Keymap 0: Basic layer
+ *
+ * ,-------------------------------------------. ,-------------------------------------------.
+ * | L1/ESC | Q | W | E | R | T | | Y | U | I | O | P | | \ |
+ * |--------+------+------+------+------+------|------. .------|------+------+------+------+------+--------|
+ * |Ctrl/BS | A | S | D | F | G | RMB | | | H | J | K | L | ; : | ' " |
+ * |--------+------+------+------+------+------|------| |------|------+------+------+------+------+--------|
+ * | LShift | Z | X | C | V | B | LMB | | | N | M | , < | . > | / ? | - _ |
+ * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
+ * .----------. .-------. .------. .-----.
+ * | Super/Del| |Ent/ALT| | Tab | |BKSP |
+ * '----------' '-------' `------. '-----'
+ * ,-------. ,-------.
+ * | MMB | | PgDn |
+ * ,------|-------| |-------|------.
+ * | SYMB | NUMB | | SYMB | NUMB |
+ * | Space| Escape| | Mod |Space |
+ * | | | | | |
+ * `--------------' `--------------'
+ */
+[BASE] = LAYOUT_GERGO(
+LT(NUMB, KC_ESC), KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_PIPE,
+MT(MOD_LCTL, KC_BSPC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_BTN2, KC_TRNS, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
+KC_RSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_BTN1, KC_BSPC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_MINS,
+
+ MT(MOD_LGUI, KC_DEL), MT(MOD_LALT, KC_ENT), KC_TAB, KC_BSPC,
+
+ KC_BTN3, KC_PGDN,
+ LT(SYMB, KC_SPC), LT(NUMB, KC_ESC), LT(SYMB, KC_ENT), LT(NUMB, KC_SPC)),
+/* Keymap 1: Symbols layer
+ *
+ * ,-------------------------------------------. ,-------------------------------------------.
+ * | | ! | @ | { | } | | | | | | | | | \ | |
+ * |--------+------+------+------+------+------|------. .------|------+------+------+------+------+--------|
+ * | | # | $ | ( | ) | ` | | | | + | - | / | * | % | ' " |
+ * |--------+------+------+------+------+------|------| |------|------+------+------+------+------+--------|
+ * | | % | ^ | [ | ] | ~ | | | | & | = | , | . | / ? | - _ |
+ * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
+ * .------. .------. .------. .-----.
+ * | | | | | | | DEL |
+ * '------' '------' `------. '-----'
+ * ,-------. ,-------.
+ * | | | PgUp |
+ * ,------|-------| |-------|------.
+ * | | | | | |
+ * | ; | = | | = | ; |
+ * | | | | | |
+ * `--------------' `--------------'
+ */
+[SYMB] = LAYOUT_GERGO(
+KC_TRNS, KC_EXLM, KC_AT, KC_LCBR,KC_RCBR, KC_PIPE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS,
+KC_TRNS, KC_HASH, KC_DLR, KC_LPRN,KC_RPRN, KC_GRV, KC_TRNS, KC_TRNS, KC_PLUS, KC_MINS, KC_SLSH, KC_ASTR, KC_PERC, KC_QUOT,
+KC_TRNS, KC_PERC, KC_CIRC,KC_LBRC,KC_RBRC, KC_TILD, KC_TRNS, KC_TRNS, KC_AMPR, KC_EQL, KC_COMM, KC_DOT, KC_SLSH, KC_MINS,
+
+ KC_TRNS, KC_TRNS, KC_PGUP, KC_DEL,
+ KC_TRNS, KC_TRNS,
+ KC_SCLN, KC_EQL, KC_EQL, KC_SCLN),
+/* Keymap 2: Pad/Function layer
+ *
+ * ,-------------------------------------------. ,-------------------------------------------.
+ * | | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | |
+ * |--------+------+------+------+------+------|------. .------|------+------+------+------+------+--------|
+ * | F1 | F2 | F3 | F4 | F5 | F6 | BTN1 | | | LEFT | DOWN | UP | RIGHT|VolDn | VolUp |
+ * |--------+------+------+------+------+------|------| |------|------+------+------+------+------+--------|
+ * | F7 | F8 | F9 | F10 | F11 | F12 | BTN2 | | | MLFT | MDWN | MUP | MRGHT|Ply/Pa| Skip |
+ * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
+ * .------. .------. .------. .-----.
+ * | | | | | | | |
+ * '------' '------' `------. '-----'
+ * ,-------. ,-------.
+ * | | | PgUp |
+ * ,------|-------| |-------|------.
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * `--------------' `--------------'
+ */
+[NUMB] = LAYOUT_GERGO(
+KC_TRNS, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_TRNS,
+KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_VOLD, KC_VOLU,
+KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_U, KC_MS_R, KC_MPLY, KC_MNXT,
+
+ KC_TRNS, KC_TRNS, KC_PGUP, KC_TRNS,
+ KC_TRNS, KC_TRNS,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
+};
+
+/* Keymap template
+ *
+ * ,-------------------------------------------. ,-------------------------------------------.
+ * | | | | | | | | | | | | | |
+ * |--------+------+------+------+------+------|------. .------|------+------+------+------+------+--------|
+ * | | | | | | | | | | | | | | | |
+ * |--------+------+------+------+------+------|------| |------|------+------+------+------+------+--------|
+ * | | | | | | | | | | | | | | | |
+ * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
+ * .------. .------. .------. .-----.
+ * | | | | | | | |
+ * '------' '------' `------. '-----'
+ * ,-------. ,-------.
+ * | | | |
+ * ,------|-------| |-------|------.
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * `--------------' `--------------'
+[SYMB] = LAYOUT_GERGO(
+KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
+KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
+KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
+
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
+ KC_TRNS, KC_TRNS,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
+ */
+
+// Runs just one time when the keyboard initializes.
+void matrix_init_user(void) {
+
+};
+
+// Runs constantly in the background, in a loop.
+void matrix_scan_user(void) {
+ //uint8_t layer = biton32(layer_state);
+ biton32(layer_state);
+};
+
+
diff --git a/keyboards/gergo/keymaps/default/readme.md b/keyboards/gergo/keymaps/default/readme.md
new file mode 100644
index 000000000..471a20fbd
--- /dev/null
+++ b/keyboards/gergo/keymaps/default/readme.md
@@ -0,0 +1,10 @@
+# [Gergo! By g Heavy Industries](http://gboards.ca)
+
+![Gergo image](https://4.bp.blogspot.com/-889nMXxgSM0/XCNxwnO5kUI/AAAAAAAA6mI/tZbWgZVCBW0dyZOCGJDkjN06DVax7j8XwCLcBGAs/s1600/48422820_967732713413298_485744639215665152_n.jpg)
+
+This is the default keymap for Gergo, it's based heavily off of the naps62 ErgoDox layout and is aimed at a programmer friendly keymap.
+
+## Settings
+To edit various settings, enable the 1u trackball and whatnot please modify /keyboards/gergo/keymaps/default/rules.mk
+
+Ideally you should copy this directory and make your changes there. If you come up with a good layout submit a PR!
diff --git a/keyboards/gergo/keymaps/default/rules.mk b/keyboards/gergo/keymaps/default/rules.mk
new file mode 100644
index 000000000..2f825a766
--- /dev/null
+++ b/keyboards/gergo/keymaps/default/rules.mk
@@ -0,0 +1,36 @@
+#----------------------------------------------------------------------------
+# make gergo:germ:dfu
+# Make sure you have dfu-programmer installed!
+#----------------------------------------------------------------------------
+# Firmware options
+BALLER = yes # Enable to ball out
+BALLSTEP = 20 # Multiple in px to move, multiplied by layer number
+SCROLLSTEP = 1 # Lines to scroll with ball
+MOUSEKEY_ENABLE = yes # Mouse keys(+4700), needed for baller
+
+#Debug options
+VERBOSE = yes
+DEBUG_MATRIX_SCAN_RATE = no
+DEBUG_BALLER = no
+DEBUG_MATRIX = no
+
+# A bunch of stuff that you shouldn't touch unless you
+# know what you're doing.
+#
+# No touchy, capiche?
+SRC += matrix.c i2c_master.c
+ifneq ($(strip $(BALLSTEP)),)
+ OPT_DEFS += -DTRKSTEP=$(strip $(BALLSTEP))
+endif
+ifneq ($(strip $(SCROLLSTEP)),)
+ OPT_DEFS += -DSCROLLSTEP=$(strip $(SCROLLSTEP))
+endif
+ifeq ($(strip $(BALLER)), yes)
+ OPT_DEFS += -DBALLER
+endif
+ifeq ($(strip $(DEBUG_BALLER)), yes)
+ OPT_DEFS += -DDEBUG_BALLER
+endif
+ifeq ($(strip $(DEBUG_MATRIX)), yes)
+ OPT_DEFS += -DDEBUG_MATRIX
+endif
diff --git a/keyboards/gergo/matrix.c b/keyboards/gergo/matrix.c
new file mode 100644
index 000000000..29fe48ccb
--- /dev/null
+++ b/keyboards/gergo/matrix.c
@@ -0,0 +1,517 @@
+/*
+Note for ErgoDox EZ customizers: Here be dragons!
+This is not a file you want to be messing with.
+All of the interesting stuff for you is under keymaps/ :)
+Love, Erez
+
+Copyright 2013 Oleg Kostyuk <cub.uanic@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 "matrix.h"
+#include <stdint.h>
+#include <stdbool.h>
+#include <avr/io.h>
+#include "wait.h"
+#include "action_layer.h"
+#include "print.h"
+#include "debug.h"
+#include "util.h"
+#include "pointing_device.h"
+#include QMK_KEYBOARD_H
+#ifdef DEBUG_MATRIX_SCAN_RATE
+#include "timer.h"
+#endif
+
+#ifdef BALLER
+#include <avr/interrupt.h>
+#endif
+
+#ifndef DEBOUNCE
+# define DEBOUNCE 5
+#endif
+
+// MCP Pin Defs
+#define RROW1 (1<<3)
+#define RROW2 (1<<2)
+#define RROW3 (1<<1)
+#define RROW4 (1<<0)
+#define COL0 (1<<0)
+#define COL1 (1<<1)
+#define COL2 (1<<2)
+#define COL3 (1<<3)
+#define COL4 (1<<4)
+#define COL5 (1<<5)
+#define COL6 (1<<6)
+
+// ATmega pin defs
+#define ROW1 (1<<6)
+#define ROW2 (1<<5)
+#define ROW3 (1<<4)
+#define ROW4 (1<<1)
+#define COL7 (1<<0)
+#define COL8 (1<<1)
+#define COL9 (1<<2)
+#define COL10 (1<<3)
+#define COL11 (1<<2)
+#define COL12 (1<<3)
+#define COL13 (1<<6)
+
+//Trackball pin defs
+#define TRKUP (1<<4)
+#define TRKDN (1<<5)
+#define TRKLT (1<<6)
+#define TRKRT (1<<7)
+#define TRKBTN (1<<6)
+
+
+// Multiple for mouse moves
+#ifndef TRKSTEP
+#define TRKSTEP 20
+#endif
+
+// multiple for mouse scroll
+#ifndef SCROLLSTEP
+#define SCROLLSTEP 5
+#endif
+
+// bit masks
+#define BMASK (COL7 | COL8 | COL9 | COL10)
+#define CMASK (COL13)
+#define DMASK (COL11 | COL12)
+#define FMASK (ROW1 | ROW2 | ROW3 | ROW4)
+#define RROWMASK (RROW1 | RROW2 | RROW3 | RROW4)
+#define MCPMASK (COL0 | COL1 | COL2 | COL3 | COL4 | COL5 | COL6)
+#define TRKMASK (TRKUP | TRKDN | TRKRT | TRKLT)
+
+// Trackball interrupts accumulate over here. Processed on scan
+// Stores prev state of mouse, high bits store direction
+uint8_t trkState = 0;
+uint8_t trkBtnState = 0;
+
+volatile uint8_t tbUpCnt = 0;
+volatile uint8_t tbDnCnt = 0;
+volatile uint8_t tbLtCnt = 0;
+volatile uint8_t tbRtCnt = 0;
+
+/* matrix state(1:on, 0:off) */
+static matrix_row_t matrix[MATRIX_ROWS];
+/*
+ * matrix state(1:on, 0:off)
+ * contains the raw values without debounce filtering of the last read cycle.
+ */
+static matrix_row_t raw_matrix[MATRIX_ROWS];
+
+// Debouncing: store for each key the number of scans until it's eligible to
+// change. When scanning the matrix, ignore any changes in keys that have
+// already changed in the last DEBOUNCE scans.
+static uint8_t debounce_matrix[MATRIX_ROWS * MATRIX_COLS];
+
+static matrix_row_t read_cols(uint8_t row);
+static void init_cols(void);
+static void unselect_rows(void);
+static void select_row(uint8_t row);
+static void enableInterrupts(void);
+
+static uint8_t mcp23018_reset_loop;
+// static uint16_t mcp23018_reset_loop;
+
+#ifdef DEBUG_MATRIX_SCAN_RATE
+uint32_t matrix_timer;
+uint32_t matrix_scan_count;
+#endif
+
+
+__attribute__ ((weak))
+void matrix_init_user(void) {}
+
+__attribute__ ((weak))
+void matrix_scan_user(void) {}
+
+__attribute__ ((weak))
+void matrix_init_kb(void) {
+ matrix_init_user();
+}
+
+__attribute__ ((weak))
+void matrix_scan_kb(void) {
+ matrix_scan_user();
+}
+
+inline
+uint8_t matrix_rows(void)
+{
+ return MATRIX_ROWS;
+}
+
+inline
+uint8_t matrix_cols(void)
+{
+ return MATRIX_COLS;
+}
+
+
+void matrix_init(void)
+{
+ // initialize row and col
+ mcp23018_status = init_mcp23018();
+ unselect_rows();
+ init_cols();
+
+ // initialize matrix state: all keys off
+ for (uint8_t i=0; i < MATRIX_ROWS; i++) {
+ matrix[i] = 0;
+ raw_matrix[i] = 0;
+ for (uint8_t j=0; j < MATRIX_COLS; ++j) {
+ debounce_matrix[i * MATRIX_COLS + j] = 0;
+ }
+ }
+
+#ifdef DEBUG_MATRIX_SCAN_RATE
+ matrix_timer = timer_read32();
+ matrix_scan_count = 0;
+#endif
+ matrix_init_quantum();
+}
+
+void matrix_power_up(void) {
+ mcp23018_status = init_mcp23018();
+
+ unselect_rows();
+ init_cols();
+
+ // initialize matrix state: all keys off
+ for (uint8_t i=0; i < MATRIX_ROWS; i++) {
+ matrix[i] = 0;
+ }
+
+#ifdef DEBUG_MATRIX_SCAN_RATE
+ matrix_timer = timer_read32();
+ matrix_scan_count = 0;
+#endif
+
+}
+
+// Returns a matrix_row_t whose bits are set if the corresponding key should be
+// eligible to change in this scan.
+matrix_row_t debounce_mask(matrix_row_t rawcols, uint8_t row) {
+ matrix_row_t result = 0;
+ matrix_row_t change = rawcols ^ raw_matrix[row];
+ raw_matrix[row] = rawcols;
+ for (uint8_t i = 0; i < MATRIX_COLS; ++i) {
+ if (debounce_matrix[row * MATRIX_COLS + i]) {
+ --debounce_matrix[row * MATRIX_COLS + i];
+ } else {
+ result |= (1 << i);
+ }
+ if (change & (1 << i)) {
+ debounce_matrix[row * MATRIX_COLS + i] = DEBOUNCE;
+ }
+ }
+ return result;
+}
+
+matrix_row_t debounce_read_cols(uint8_t row) {
+ // Read the row without debouncing filtering and store it for later usage.
+ matrix_row_t cols = read_cols(row);
+ // Get the Debounce mask.
+ matrix_row_t mask = debounce_mask(cols, row);
+ // debounce the row and return the result.
+ return (cols & mask) | (matrix[row] & ~mask);;
+}
+
+uint8_t matrix_scan(void)
+{
+ // TODO: Find what is trashing interrupts
+ enableInterrupts();
+
+ // First we handle the mouse inputs
+ #ifdef BALLER
+ uint8_t pBtn = PINE & TRKBTN;
+
+ #ifdef DEBUG_BALLER
+ // Compare to previous, mod report
+ if (tbUpCnt + tbDnCnt + tbLtCnt + tbRtCnt != 0)
+ xprintf("U: %d D: %d L: %d R: %d B: %d\n", tbUpCnt, tbDnCnt, tbLtCnt, tbRtCnt, (trkBtnState >> 6));
+ #endif
+
+ // Modify the report
+ report_mouse_t pRprt = pointing_device_get_report();
+
+ // Scroll by default, move on layer
+ if (layer_state == 0) {
+ pRprt.h += tbLtCnt * SCROLLSTEP; tbLtCnt = 0;
+ pRprt.h -= tbRtCnt * SCROLLSTEP; tbRtCnt = 0;
+ pRprt.v -= tbUpCnt * SCROLLSTEP; tbUpCnt = 0;
+ pRprt.v += tbDnCnt * SCROLLSTEP; tbDnCnt = 0;
+ } else {
+ pRprt.x -= tbLtCnt * TRKSTEP * (layer_state - 1); tbLtCnt = 0;
+ pRprt.x += tbRtCnt * TRKSTEP * (layer_state - 1); tbRtCnt = 0;
+ pRprt.y -= tbUpCnt * TRKSTEP * (layer_state - 1); tbUpCnt = 0;
+ pRprt.y += tbDnCnt * TRKSTEP * (layer_state - 1); tbDnCnt = 0;
+ }
+
+ #ifdef DEBUG_BALLER
+ if (pRprt.x != 0 || pRprt.y != 0)
+ xprintf("X: %d Y: %d\n", pRprt.x, pRprt.y);
+ #endif
+
+ if ((pBtn != trkBtnState) && ((pBtn >> 6) == 0)) pRprt.buttons |= MOUSE_BTN1;
+ if ((pBtn != trkBtnState) && ((pBtn >> 6) == 1)) pRprt.buttons &= ~MOUSE_BTN1;
+
+ // Save state, push update
+ if (pRprt.x != 0 || pRprt.y != 0 || pRprt.h != 0 || pRprt.v != 0 || (trkBtnState != pBtn))
+ pointing_device_set_report(pRprt);
+
+ trkBtnState = pBtn;
+ #endif
+
+ // Then the keyboard
+ if (mcp23018_status) { // if there was an error
+ if (++mcp23018_reset_loop == 0) {
+ // if (++mcp23018_reset_loop >= 1300) {
+ // since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
+ // this will be approx bit more frequent than once per second
+ print("trying to reset mcp23018\n");
+ mcp23018_status = init_mcp23018();
+ if (mcp23018_status) {
+ print("left side not responding\n");
+ } else {
+ print("left side attached\n");
+ }
+ }
+ }
+
+#ifdef DEBUG_MATRIX_SCAN_RATE
+ matrix_scan_count++;
+ uint32_t timer_now = timer_read32();
+ if (TIMER_DIFF_32(timer_now, matrix_timer)>1000) {
+ print("matrix scan frequency: ");
+ pdec(matrix_scan_count);
+ print("\n");
+
+ matrix_timer = timer_now;
+ matrix_scan_count = 0;
+ }
+#endif
+ for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) {
+ select_row(i);
+ // and select on left hand
+ select_row(i + MATRIX_ROWS_PER_SIDE);
+ // we don't need a 30us delay anymore, because selecting a
+ // left-hand row requires more than 30us for i2c.
+
+ // grab cols from left hand
+ matrix[i] = debounce_read_cols(i);
+ // grab cols from right hand
+ matrix[i + MATRIX_ROWS_PER_SIDE] = debounce_read_cols(i + MATRIX_ROWS_PER_SIDE);
+
+ unselect_rows();
+ }
+
+ matrix_scan_quantum();
+ enableInterrupts();
+
+#ifdef DEBUG_MATRIX
+ for (uint8_t c = 0; c < MATRIX_COLS; c++)
+ for (uint8_t r = 0; r < MATRIX_ROWS; r++)
+ if (matrix_is_on(r, c)) xprintf("r:%d c:%d \n", r, c);
+#endif
+
+ return 1;
+}
+
+bool matrix_is_modified(void) // deprecated and evidently not called.
+{
+ return true;
+}
+
+inline
+bool matrix_is_on(uint8_t row, uint8_t col)
+{
+ return (matrix[row] & ((matrix_row_t)1<<col));
+}
+
+inline
+matrix_row_t matrix_get_row(uint8_t row)
+{
+ return matrix[row];
+}
+
+void matrix_print(void)
+{
+ print("\nr/c 0123456789ABCDEF\n");
+ for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+ phex(row); print(": ");
+ pbin_reverse16(matrix_get_row(row));
+ print("\n");
+ }
+}
+
+uint8_t matrix_key_count(void)
+{
+ uint8_t count = 0;
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ count += bitpop16(matrix[i]);
+ }
+ return count;
+}
+
+// Remember this means ROWS
+static void init_cols(void)
+{
+ // init on mcp23018
+ // not needed, already done as part of init_mcp23018()
+
+ // Input with pull-up(DDR:0, PORT:1)
+ DDRF &= ~FMASK;
+ PORTF |= FMASK;
+}
+
+static matrix_row_t read_cols(uint8_t row)
+{
+ if (row < 7) {
+ if (mcp23018_status) { // if there was an error
+ return 0;
+ } else {
+ uint8_t data = 0;
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPIOB, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_start(I2C_ADDR_READ, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_read_nack(ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status < 0) goto out;
+ data = ~((uint8_t)mcp23018_status);
+ mcp23018_status = I2C_STATUS_SUCCESS;
+ out:
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
+
+#ifdef DEBUG_MATRIX
+ if (data != 0x00) xprintf("I2C: %d\n", data);
+#endif
+ return data;
+ }
+ } else {
+ /* read from teensy
+ * bitmask is 0b0111001, but we want the lower four
+ * we'll return 1s for the top two, but that's harmless.
+ */
+ // So I need to confuckulate all this
+ //return ~(((PIND & DMASK) >> 1 | ((PINC & CMASK) >> 6) | (PIN)));
+ //return ~((PINF & 0x03) | ((PINF & 0xF0) >> 2));
+ return ~(
+ (((PINF & ROW4) >> 1)
+ | ((PINF & (ROW1 | ROW2 | ROW3)) >> 3))
+ & 0xF);
+ }
+}
+
+// Row pin configuration
+static void unselect_rows(void)
+{
+ // no need to unselect on mcp23018, because the select step sets all
+ // the other row bits high, and it's not changing to a different
+ // direction
+ // Hi-Z(DDR:0, PORT:0) to unselect
+ DDRB &= ~(BMASK | TRKMASK);
+ PORTB &= ~(BMASK);
+ DDRC &= ~CMASK;
+ PORTC &= ~CMASK;
+ DDRD &= ~DMASK;
+ PORTD &= ~DMASK;
+
+ // Fix trashing of DDRB for TB
+ PORTB |= TRKMASK;
+}
+
+static void select_row(uint8_t row)
+{
+ if (row < 7) {
+ // select on mcp23018
+ if (mcp23018_status) { // do nothing on error
+ } else { // set active row low : 0 // set other rows hi-Z : 1
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPIOA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0xFF & ~(1<<row), ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ out:
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
+ }
+ } else {
+ // Output low(DDR:1, PORT:0) to select
+ switch (row) {
+ case 7:
+ DDRB |= COL7;
+ PORTB &= ~COL7;
+ break;
+ case 8:
+ DDRB |= COL8;
+ PORTB &= ~COL8;
+ break;
+ case 9:
+ DDRB |= COL9;
+ PORTB &= ~COL9;
+ break;
+ case 10:
+ DDRB |= COL10;
+ PORTB &= ~COL10;
+ break;
+ case 11:
+ DDRD |= COL11;
+ PORTD &= ~COL11;
+ break;
+ case 12:
+ DDRD |= COL12;
+ PORTD &= ~COL12;
+ break;
+ case 13:
+ DDRC |= COL13;
+ PORTC &= ~COL13;
+ break;
+ }
+ }
+}
+
+
+// Trackball Interrupts
+static void enableInterrupts(void) {
+ #ifdef BALLER
+ // Set interrupt mask
+ // Set port defs
+ DDRB &= ~TRKMASK;
+ PORTB |= TRKMASK;
+ DDRE &= ~TRKBTN;
+ PORTE |= TRKBTN;
+
+ // Interrupt shenanigans
+ //EIMSK |= (1 << PCIE0);
+ PCMSK0 |= TRKMASK;
+ PCICR |= (1 << PCIE0);
+ sei();
+ #endif
+
+ return;
+}
+#ifdef BALLER
+ISR (PCINT0_vect) {
+ // Don't get fancy, we're in a interrupt here
+ // PCINT reports a interrupt for a change on the bus
+ // We hand the button at scantime for debounce
+ volatile uint8_t pState = PINB & TRKMASK;
+ if ((pState & TRKUP) != (trkState & TRKUP)) tbUpCnt++;
+ if ((pState & TRKDN) != (trkState & TRKDN)) tbDnCnt++;
+ if ((pState & TRKLT) != (trkState & TRKLT)) tbLtCnt++;
+ if ((pState & TRKRT) != (trkState & TRKRT)) tbRtCnt++;
+ trkState = pState;
+
+}
+#endif
diff --git a/keyboards/gergo/readme.md b/keyboards/gergo/readme.md
new file mode 100644
index 000000000..8fefcfe8d
--- /dev/null
+++ b/keyboards/gergo/readme.md
@@ -0,0 +1,26 @@
+# Gergo
+
+![Gergo](https://cdn.pbrd.co/images/HVglSWD.jpg)
+
+A compact 50% (14x4) Split Keyboard compatible with i2c modules and a trackball.
+
+[More info on qmk.fm](http://qmk.fm/gergo/)
+
+Keyboard Maintainer: [Jeremy Bernhardt](https://github.com/germ)
+Hardware Supported: Gergo (Kit, Partial, Ready)
+Hardware Availability: [gboards.ca](http://gboards.ca)
+
+## Firmware building
+After cloning the QMK repo and installing dfu-programmer build and flash with. Be sure to reset your keyboard!
+
+ make gergo:germ:dfu
+
+To just test your build with the default keymap
+
+ make gergo:germ
+
+Gadgets and options can be enabled/disabled in keyboards/gergo/keymaps/default/rules.mk . Copy the default directory and make any changes to your layout, if you think they're worth sharing submit a PR!
+
+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).
+
+## Have an idea for a gadget? [Reach out to me!](mailto:bernhardtjeremy@gmail.com)
diff --git a/keyboards/gergo/rules.mk b/keyboards/gergo/rules.mk
new file mode 100644
index 000000000..aadc1c2ce
--- /dev/null
+++ b/keyboards/gergo/rules.mk
@@ -0,0 +1,20 @@
+#----------------------------------------------------------------------------
+# make gergo:germ:dfu
+# Make sure you have dfu-programmer installed!
+# Do not edit this file! Make a copy of keymaps/default and modify that!
+#----------------------------------------------------------------------------
+# Source includes
+SRC += matrix.c i2c_master.c
+
+# Hardware info
+MCU = atmega32u4
+F_CPU = 16000000
+ARCH = AVR8
+BOOTLOADER = atmel-dfu
+F_USB = $(F_CPU)
+
+CUSTOM_MATRIX = yes
+POINTING_DEVICE_ENABLE = yes
+EXTRAKEY_ENABLE = yes
+CONSOLE_ENABLE = yes
+COMMAND_ENABLE = yes