From ec8d0eb3282834573eb026c29fe8e01a56c7d724 Mon Sep 17 00:00:00 2001 From: MaxMalRichtig Date: Fri, 23 Mar 2018 20:01:19 +0100 Subject: [PATCH] first version for 50one keyboard --- 50one.c | 43 ++++ 50one.h | 51 ++++ config.h | 182 ++++++++++++++ eeprom-lefthand.eep | 2 + eeprom-righthand.eep | 2 + i2c.c | 162 +++++++++++++ i2c.h | 49 ++++ keymaps/default/config.h | 54 +++++ keymaps/default/keymap.c | 234 ++++++++++++++++++ keymaps/default/readme.md | 1 + keymaps/default/rules.mk | 5 + matrix.c | 499 ++++++++++++++++++++++++++++++++++++++ readme.md | 15 ++ rules.mk | 76 ++++++ split_leds.c | 106 ++++++++ split_leds.h | 102 ++++++++ split_util.c | 79 ++++++ split_util.h | 22 ++ 18 files changed, 1684 insertions(+) create mode 100644 50one.c create mode 100644 50one.h create mode 100644 config.h create mode 100644 eeprom-lefthand.eep create mode 100644 eeprom-righthand.eep create mode 100644 i2c.c create mode 100644 i2c.h create mode 100644 keymaps/default/config.h create mode 100644 keymaps/default/keymap.c create mode 100644 keymaps/default/readme.md create mode 100644 keymaps/default/rules.mk create mode 100644 matrix.c create mode 100644 readme.md create mode 100644 rules.mk create mode 100644 split_leds.c create mode 100644 split_leds.h create mode 100644 split_util.c create mode 100644 split_util.h diff --git a/50one.c b/50one.c new file mode 100644 index 0000000..a124d1f --- /dev/null +++ b/50one.c @@ -0,0 +1,43 @@ +/* Copyright 2017 REPLACE_WITH_YOUR_NAME + * + * 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 . + */ +#include "50one.h" + +void matrix_init_kb(void) { + // put your keyboard start-up code here + // runs once when the firmware starts up + + matrix_init_user(); +} + +void matrix_scan_kb(void) { + // put your looping keyboard code here + // runs every cycle (a lot) + + matrix_scan_user(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + // put your per-action keyboard code here + // runs for every action, just before processing by the firmware + + return process_record_user(keycode, record); +} + +void led_set_kb(uint8_t usb_led) { + // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here + + led_set_user(usb_led); +} diff --git a/50one.h b/50one.h new file mode 100644 index 0000000..74a1e2a --- /dev/null +++ b/50one.h @@ -0,0 +1,51 @@ +/* Copyright 2017 REPLACE_WITH_YOUR_NAME + * + * 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 . + */ +#ifndef FIFTY_ONE_H +#define FIFTY_ONE_H + +#include "quantum.h" + +#ifdef USE_I2C +#include +#ifdef __AVR__ + #include + #include +#endif +#endif + + +// This a shortcut to help you visually see your layout. +// The following is an example using the Planck MIT layout +// The first section contains all of the arguments +// The second converts the arguments into a two-dimensional array +#define KEYMAP( \ + L00, L01, L02, L03, L04, L05, R00, R01, R02, R03, R04, R05, \ + L10, L11, L12, L13, L14, L15, R10, R11, R12, R13, R14, R15, \ + L20, L21, L22, L23, L24, L25, R20, R21, R22, R23, R24, R25, \ + L30, L31, L32, L33, L34, L35, L36, R36, R30, R31, R32, R33, R34, R35 \ + ) \ + { \ + { L00, L01, L02, L03, L04, L05, KC_NO }, \ + { L10, L11, L12, L13, L14, L15, KC_NO }, \ + { L20, L21, L22, L23, L24, L25, KC_NO }, \ + { L30, L31, L32, L33, L34, L35, L36 }, \ + { R05, R04, R03, R02, R01, R00, KC_NO }, \ + { R15, R14, R13, R12, R11, R10, KC_NO }, \ + { R25, R24, R23, R22, R21, R20, KC_NO }, \ + { R35, R34, R33, R32, R31, R30, R36 } \ + } + +#endif diff --git a/config.h b/config.h new file mode 100644 index 0000000..2f542ff --- /dev/null +++ b/config.h @@ -0,0 +1,182 @@ +/* +Copyright 2017 REPLACE_WITH_YOUR_NAME + +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 . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x0001 +#define DEVICE_VER 0x0001 +#define MANUFACTURER Max malRichtig +#define PRODUCT Keyboard 50one +#define DESCRIPTION A basic but ergonomic 50 key split keyboard + +/* key matrix size */ +// Rows are doubled-up +#define MATRIX_ROWS 8 +#define MATRIX_COLS 7 + +// wiring of each half +#define MATRIX_ROW_PINS { B1, B3, B2, B6 } +#define MATRIX_COL_PINS { B5, B4, E6, D7, C6, D4, F7 } +#define UNUSED_PINS { F4, F5, F6 } // used for RGB LEDs - not for matrix + +/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ +#define DIODE_DIRECTION COL2ROW + +// #define BACKLIGHT_PIN B7 +// #define BACKLIGHT_BREATHING +// #define BACKLIGHT_LEVELS 3 + + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCING_DELAY 5 + +/* define if matrix has ghost (lacks anti-ghosting diodes) */ +//#define MATRIX_HAS_GHOST + +/* number of backlight levels */ + +/* 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 + +/* If defined, GRAVE_ESC will always act as ESC when CTRL is held. + * This is userful for the Windows task manager shortcut (ctrl+shift+esc). + */ +// #define GRAVE_ESC_CTRL_OVERRIDE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO + +/* + * Magic Key Options + * + * Magic keys are hotkey commands that allow control over firmware functions of + * the keyboard. They are best used in combination with the HID Listen program, + * found here: https://www.pjrc.com/teensy/hid_listen.html + * + * The options below allow the magic key functionality to be changed. This is + * useful if your keyboard/keypad is missing keys and you want magic key support. + * + */ + +/* key combination for magic key command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* control how magic key switches layers */ +//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true +//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true +//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false + +/* override magic key keymap */ +//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS +//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS +//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM +//#define MAGIC_KEY_HELP1 H +//#define MAGIC_KEY_HELP2 SLASH +//#define MAGIC_KEY_DEBUG D +//#define MAGIC_KEY_DEBUG_MATRIX X +//#define MAGIC_KEY_DEBUG_KBD K +//#define MAGIC_KEY_DEBUG_MOUSE M +//#define MAGIC_KEY_VERSION V +//#define MAGIC_KEY_STATUS S +//#define MAGIC_KEY_CONSOLE C +//#define MAGIC_KEY_LAYER0_ALT1 ESC +//#define MAGIC_KEY_LAYER0_ALT2 GRAVE +//#define MAGIC_KEY_LAYER0 0 +//#define MAGIC_KEY_LAYER1 1 +//#define MAGIC_KEY_LAYER2 2 +//#define MAGIC_KEY_LAYER3 3 +//#define MAGIC_KEY_LAYER4 4 +//#define MAGIC_KEY_LAYER5 5 +//#define MAGIC_KEY_LAYER6 6 +//#define MAGIC_KEY_LAYER7 7 +//#define MAGIC_KEY_LAYER8 8 +//#define MAGIC_KEY_LAYER9 9 +//#define MAGIC_KEY_BOOTLOADER PAUSE +//#define MAGIC_KEY_LOCK CAPS +//#define MAGIC_KEY_EEPROM E +//#define MAGIC_KEY_NKRO N +//#define MAGIC_KEY_SLEEP_LED Z + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +//#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 1 + +#endif diff --git a/eeprom-lefthand.eep b/eeprom-lefthand.eep new file mode 100644 index 0000000..bda23cd --- /dev/null +++ b/eeprom-lefthand.eep @@ -0,0 +1,2 @@ +:0F000000000000000000000000000000000001F0 +:00000001FF diff --git a/eeprom-righthand.eep b/eeprom-righthand.eep new file mode 100644 index 0000000..549cd1e --- /dev/null +++ b/eeprom-righthand.eep @@ -0,0 +1,2 @@ +:0F000000000000000000000000000000000000F1 +:00000001FF diff --git a/i2c.c b/i2c.c new file mode 100644 index 0000000..084c890 --- /dev/null +++ b/i2c.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include +#include +#include "i2c.h" + +#ifdef USE_I2C + +// Limits the amount of we wait for any one i2c transaction. +// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is +// 9 bits, a single transaction will take around 90μs to complete. +// +// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit +// poll loop takes at least 8 clock cycles to execute +#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8 + +#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE) + +volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; + +static volatile uint8_t slave_buffer_pos; +static volatile bool slave_has_register_set = false; + +// Wait for an i2c operation to finish +inline static +void i2c_delay(void) { + uint16_t lim = 0; + while(!(TWCR & (1<10. + // Check datasheets for more info. + TWBR = ((F_CPU/SCL_CLOCK)-16)/2; +} + +// Start a transaction with the given i2c slave address. The direction of the +// transfer is set with I2C_READ and I2C_WRITE. +// returns: 0 => success +// 1 => error +uint8_t i2c_master_start(uint8_t address) { + TWCR = (1< slave ACK +// 1 => slave NACK +uint8_t i2c_master_write(uint8_t data) { + TWDR = data; + TWCR = (1<= SLAVE_BUFFER_SIZE ) { + ack = 0; + slave_buffer_pos = 0; + } + slave_has_register_set = true; + } else { + i2c_slave_buffer[slave_buffer_pos] = TWDR; + BUFFER_POS_INC(); + } + break; + + case TW_ST_SLA_ACK: + case TW_ST_DATA_ACK: + // master has addressed this device as a slave transmitter and is + // requesting data. + TWDR = i2c_slave_buffer[slave_buffer_pos]; + BUFFER_POS_INC(); + break; + + case TW_BUS_ERROR: // something went wrong, reset twi state + TWCR = 0; + default: + break; + } + // Reset everything, so we are ready for the next TWI interrupt + TWCR |= (1< + +#ifndef F_CPU +#define F_CPU 16000000UL +#endif + +#define I2C_READ 1 +#define I2C_WRITE 0 + +#define I2C_ACK 1 +#define I2C_NACK 0 + +#define SLAVE_BUFFER_SIZE 0x10 //(MATRIX_BUFFER_SIZE + LED_STATE_BUFFER_SIZE) + +// i2c SCL clock frequency +#define SCL_CLOCK 400000L + +extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; + +void i2c_master_init(void); +uint8_t i2c_master_start(uint8_t address); +void i2c_master_stop(void); +uint8_t i2c_master_write(uint8_t data); +uint8_t i2c_master_read(int); +void i2c_reset_state(void); +void i2c_slave_init(uint8_t address); + + +static inline unsigned char i2c_start_read(unsigned char addr) { + return i2c_master_start((addr << 1) | I2C_READ); +} + +static inline unsigned char i2c_start_write(unsigned char addr) { + return i2c_master_start((addr << 1) | I2C_WRITE); +} + +// from SSD1306 scrips +extern unsigned char i2c_rep_start(unsigned char addr); +extern void i2c_start_wait(unsigned char addr); +extern unsigned char i2c_readAck(void); +extern unsigned char i2c_readNak(void); +extern unsigned char i2c_read(unsigned char ack); + +#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); + +#endif diff --git a/keymaps/default/config.h b/keymaps/default/config.h new file mode 100644 index 0000000..3f93da9 --- /dev/null +++ b/keymaps/default/config.h @@ -0,0 +1,54 @@ +/* +This is the c configuration file for the keymap + +Copyright 2012 Jun Wako +Copyright 2015 Jack Humbert + +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 . +*/ + +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +#define MOUSEKEY_INTERVAL 20 +#define MOUSEKEY_DELAY 50 +#define MOUSEKEY_TIME_TO_MAX 60 +#define MOUSEKEY_MAX_SPEED 10 +#define MOUSEKEY_WHEEL_MAX_SPEED 10 +#define MOUSEKEY_WHEEL_TIME_TO_MAX 255 + +#define TAPPING_TOGGLE 2 + +#define PERMISSIVE_HOLD +//#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.) + + +/* Use I2C! Serial not implemented yet. */ + +//#define USE_SERIAL +#define USE_I2C + +/* Select hand configuration */ + +//#define MASTER_LEFT +// #define MASTER_RIGHT +#define EE_HANDS + +/* Turn on/off the visualization with RGB LEDs */ +#define USE_50ONE_LEDS + +#endif diff --git a/keymaps/default/keymap.c b/keymaps/default/keymap.c new file mode 100644 index 0000000..46a82ae --- /dev/null +++ b/keymaps/default/keymap.c @@ -0,0 +1,234 @@ +#include "50one.h" +#include "action_layer.h" +#include "eeconfig.h" +#include "keymap_german.h" +#include "split_util.h" + +extern keymap_config_t keymap_config; + +// Each layer gets a name for readability, which is then used in the keymap matrix below. +// The underscores don't mean anything - you can have a layer called STUFF or any other name. +// Layer names don't all need to be of the same length, obviously, and you can also skip them +// entirely and just use numbers. +#define _CUSTOM 0 +#define _STANDARD 1 +#define _LOWER 14 +#define _RAISE 15 +#define _BOTH 16 + +#define LShTab LSFT_T(KC_TAB) +#define RShEnt RSFT_T(KC_ENT) + +//Tap Dance Declarations +enum { + L_SHLCK = 0, + R_SHLCK, + CPYCUT, + ESCCLS +}; + +enum custom_keycodes { + CUSTOM = SAFE_RANGE, + STANDARD, + LOWER, + RAISE, + BOTH +}; + +void td_escape_close (qk_tap_dance_state_t *state, void *user_data) { + if (state->count <= 2) { + register_code(KC_ESC); + unregister_code(KC_ESC); + } + else { + SEND_STRING(SS_DOWN(X_LALT)SS_TAP(X_F4)SS_UP(X_LALT)); + } +} + +//Tap Dance Definitions +qk_tap_dance_action_t tap_dance_actions[] = { + //Tap once for Esc, twice for Caps Lock + [L_SHLCK] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS), + [R_SHLCK] = ACTION_TAP_DANCE_DOUBLE(KC_RSFT, KC_CAPS), + [ESCCLS] = ACTION_TAP_DANCE_FN(td_escape_close), + [CPYCUT] = ACTION_TAP_DANCE_DOUBLE(KC_COPY, KC_CUT) +// Other declarations would go here, separated by commas, if you have them +}; + +// Fillers to make layering more clear +#define _______ KC_TRNS +#define XXXXXXX KC_NO + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + +/* Qwertz + * ,------------------------------------------ -----------------------------------------. + * | Esc | Q | W | E | R | T | | Y | U | I | O | P | ß | + * |------+------+------+------+------+------- -------+------+------+------+------+------| + * | Ctl | A | S | D | F | G | | H | J | K | L | Ö |Ü/Ctl | + * |------+------+------+------+------+------- -------+------+------+------+------+------| + * | Alt | Z | X | C | V | B | | N | M | , | . | - |Ä/Alt | + * |------+------+------+------+------+------+------+------+------+------+------+------+------+------| + * | GUI | Del | PDwn | PUp |Lower |Space |Tab/Sh|Ent/Sh|Space |Raise | Left | Down | Up |Right | + * `-------------------------------------------------------------------------------------------------' + */ +[_CUSTOM] = KEYMAP( \ + TD(ESCCLS),DE_Q, DE_W, DE_E, DE_R, DE_T, DE_Z, DE_U, DE_I, DE_O, DE_P, DE_SS, \ + KC_LCTRL, DE_A, DE_S, DE_D, DE_F, DE_G, DE_H, DE_J, DE_K, DE_L, DE_OE, RCTL_T(DE_UE), \ + KC_LALT, DE_Y, DE_X, DE_C, DE_V, DE_B, DE_N, DE_M, DE_COMM, DE_DOT, DE_MINS, RALT_T(DE_AE), \ + KC_LGUI, KC_DEL, TD(CPYCUT),KC_PASTE, LOWER, KC_SPC, LShTab, RShEnt, KC_BSPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ +), + +/* Lower + * ,-----------------------------------------------------------------------------------. + * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_LOWER] = KEYMAP( \ + _______, DE_AT, DE_EURO, DE_LBRC, DE_RBRC, DE_HASH, DE_ASTR, DE_BSLS, DE_SLSH, DE_GRV, DE_ACUT, KC_PSCR, \ + _______, DE_AMPR, DE_PIPE, DE_LPRN, DE_RPRN, DE_DLR, DE_PLUS, DE_EXLM, DE_QST, DE_DQOT, DE_QUOT, KC_RCTL, \ + _______, DE_TILD, DE_CIRC, DE_LCBR, DE_RCBR, DE_PERC, DE_EQL, DE_LESS, DE_MORE, DE_PARA, DE_RING, KC_RALT, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \ +), + +/* Raise + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_RAISE] = KEYMAP( \ + _______, KC_NO, KC_BTN1, KC_MS_U, KC_BTN2, KC_NO, KC_PCMM, KC_P7, KC_P8, KC_P9, KC_PENT, KC_NLCK, \ + _______, KC_BTN4, KC_MS_L, KC_MS_D, KC_MS_R, KC_BTN5, KC_PDOT, KC_P4, KC_P5, KC_P6, KC_PPLS, KC_PAST, \ + _______, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_BTN3, KC_P0, KC_P1, KC_P2, KC_P3, KC_PMNS, KC_PEQL, \ + _______, _______, _______, _______, _______, KC_BTN1, KC_BTN2, _______, _______, _______, _______, _______, _______, _______ \ +), + +/* Adjust (Lower + Raise) + * ,-----------------------------------------------------------------------------------. + * | | Reset| | | | | | | | | | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | | | | | | | | | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | | | | | + * `-----------------------------------------------------------------------------------' + */ +[_BOTH] = KEYMAP( \ + KC_F11, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F12, \ + _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_NO, \ + _______, KC_MPRV, KC_VOLD, KC_VOLU, KC_MPLY, KC_MNXT, KC_WSTP, KC_WSCH, KC_WBAK, KC_WHOM, KC_WREF, KC_WFWD, \ + _______, _______, _______, _______, _______, _______, CUSTOM,STANDARD,_______, _______, _______, _______, _______, _______ \ +), + +/* Qwertz + * ,-----------------------------------------------------------------------------------. + * | Esc | Q | W | E | R | T | Z | U | I | O | P | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Tab | A | S | D | F | G | H | J | K | L | + | # | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Y | X | C | V | B | N | M | , | . | - |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Ctrl | Alt | AltGr| GUI |Lower |Space |Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_STANDARD] = KEYMAP( \ + KC_ESC, DE_Q, DE_W, DE_E, DE_R, DE_T, DE_Z, DE_U, DE_I, DE_O, DE_P, DE_SS, \ + KC_TAB, DE_A, DE_S, DE_D, DE_F, DE_G, DE_H, DE_J, DE_K, DE_L, DE_OE, DE_UE, \ + KC_LSFT, DE_Y, DE_X, DE_C, DE_V, DE_B, DE_N, DE_M, DE_COMM, DE_DOT, DE_MINS, DE_AE , \ + KC_LCTL, KC_LALT, DE_ALGR, KC_LGUI, LOWER, KC_SPC, KC_BSPC, KC_ENT, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ +) + + +}; + +void persistent_default_layer_set(uint16_t default_layer) { + eeconfig_update_default_layer(default_layer); + default_layer_set(default_layer); +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case CUSTOM: + if (record->event.pressed) { + persistent_default_layer_set(1UL<<_CUSTOM); + } + return false; + break; + case STANDARD: + if (record->event.pressed) { + persistent_default_layer_set(1UL<<_STANDARD); + } + return false; + break; + case LOWER: + if (record->event.pressed) { + layer_on(_LOWER); + update_tri_layer(_LOWER, _RAISE, _BOTH); + } else { + layer_off(_LOWER); + update_tri_layer(_LOWER, _RAISE, _BOTH); + } + return false; + break; + case RAISE: + if (record->event.pressed) { + layer_on(_RAISE); + update_tri_layer(_LOWER, _RAISE, _BOTH); + } else { + layer_off(_RAISE); + update_tri_layer(_LOWER, _RAISE, _BOTH); + } + return false; + break; + case BOTH: + if (record->event.pressed) { + layer_on(_BOTH); + } else { + layer_off(_BOTH); + } + return false; + break; + } + return true; +} + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { + +#ifdef USE_50ONE_LEDS + uint8_t layer = biton32(layer_state); + + both_led_all_off(); + + switch (layer) { + case _LOWER: + both_led_set(LED_GREEN, LED_ON); + break; + case _RAISE: + both_led_set(LED_BLUE, LED_ON); + if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) { + right_led_set(LED_RED, LED_ON); + } + break; + case _BOTH: + both_led_set(LED_RED, LED_ON); + break; + default: + // none + break; + } +#endif +}; diff --git a/keymaps/default/readme.md b/keymaps/default/readme.md new file mode 100644 index 0000000..5c63f80 --- /dev/null +++ b/keymaps/default/readme.md @@ -0,0 +1 @@ +# The default keymap for 50one \ No newline at end of file diff --git a/keymaps/default/rules.mk b/keymaps/default/rules.mk new file mode 100644 index 0000000..a06b08e --- /dev/null +++ b/keymaps/default/rules.mk @@ -0,0 +1,5 @@ +ifndef QUANTUM_DIR + include ../../../../../Makefile +endif + +TAP_DANCE_ENABLE=yes diff --git a/matrix.c b/matrix.c new file mode 100644 index 0000000..eb39375 --- /dev/null +++ b/matrix.c @@ -0,0 +1,499 @@ +/* +Copyright 2012 Jun Wako + +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 . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include "wait.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "split_util.h" +#include "pro_micro.h" +#include "config.h" +#include "timer.h" + +#include "50one.h" + +#ifdef USE_I2C +# include "i2c.h" +#else // USE_SERIAL +# include "serial.h" +#endif + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#endif + +#if (DEBOUNCING_DELAY > 0) + static uint16_t debouncing_time; + static bool debouncing = false; +#endif + +#if (MATRIX_COLS <= 8) +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop(matrix[i]) +# define ROW_SHIFTER ((uint8_t)1) +#else +# error "Currently only supports 8 COLS" +#endif +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +#define ERROR_DISCONNECT_COUNT 5 + +#define ROWS_PER_HAND (MATRIX_ROWS/2) + +static uint8_t error_count = 0; + +static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +#if (DIODE_DIRECTION == COL2ROW) + static void init_cols(void); + static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); + static void unselect_rows(void); + static void select_row(uint8_t row); + static void unselect_row(uint8_t row); +#elif (DIODE_DIRECTION == ROW2COL) + static void init_rows(void); + static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); + static void unselect_cols(void); + static void unselect_col(uint8_t col); + static void select_col(uint8_t col); +#endif + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +__attribute__ ((weak)) +void matrix_init_user(void) { +} + +__attribute__ ((weak)) +void matrix_scan_user(void) { +} + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ +#ifdef DISABLE_JTAG + // JTAG disable for PORT F. write JTD bit twice within four cycles. + MCUCR |= (1< 0) + bool matrix_changed = read_cols_on_row(matrix_debouncing+offset, current_row); + + if (matrix_changed) { + debouncing = true; + debouncing_time = timer_read(); + PORTD ^= (1 << 2); + } + +# else + read_cols_on_row(matrix+offset, current_row); +# endif + + } + +#elif (DIODE_DIRECTION == ROW2COL) + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { +# if (DEBOUNCING_DELAY > 0) + bool matrix_changed = read_rows_on_col(matrix_debouncing+offset, current_col); + if (matrix_changed) { + debouncing = true; + debouncing_time = timer_read(); + } +# else + read_rows_on_col(matrix+offset, current_col); +# endif + + } +#endif + +# if (DEBOUNCING_DELAY > 0) + if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { + matrix[i+offset] = matrix_debouncing[i+offset]; + } + debouncing = false; + } +# endif + + return 1; +} + +#ifdef USE_I2C + +// Get rows from other half over i2c +int i2c_transaction(void) { + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + + int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); + if (err) goto i2c_error; + + // start of matrix stored at 0x00 + err = i2c_master_write(0x00); + if (err) goto i2c_error; + + #ifdef USE_50ONE_LEDS + err = i2c_master_write(_slave_led_1); + if (err) goto i2c_error; + err = i2c_master_write(_slave_led_2); + if (err) goto i2c_error; + err = i2c_master_write(_slave_led_3); + if (err) goto i2c_error; + #else + err = i2c_master_write(0x00); + if (err) goto i2c_error; + err = i2c_master_write(0x00); + if (err) goto i2c_error; + err = i2c_master_write(0x00); + if (err) goto i2c_error; + #endif + + + // Start read + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); + if (err) goto i2c_error; + + if (!err) { + int i; + for (i = 0; i < ROWS_PER_HAND-1; ++i) { + matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); + } + matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); + i2c_master_stop(); + } else { +i2c_error: // the cable is disconnceted, or something else went wrong + i2c_reset_state(); + return err; + } + + return 0; +} + +#else // USE_SERIAL + +int serial_transaction(void) { + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + + if (serial_update_buffers()) { + return 1; + } + + for (int i = 0; i < ROWS_PER_HAND; ++i) { + matrix[slaveOffset+i] = serial_slave_buffer[i]; + } + return 0; +} +#endif + +uint8_t matrix_scan(void) +{ + uint8_t ret = _matrix_scan(); + +#ifdef USE_I2C + if( i2c_transaction() ) { +#else // USE_SERIAL + if( serial_transaction() ) { +#endif + // turn on the indicator led when halves are disconnected + TXLED1; + + error_count++; + + if (error_count > ERROR_DISCONNECT_COUNT) { + // reset other half if disconnected + int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + for (int i = 0; i < ROWS_PER_HAND; ++i) { + matrix[slaveOffset+i] = 0; + } + } + } else { + // turn off the indicator led on no error + TXLED0; + error_count = 0; + } + matrix_scan_quantum(); + //i2c_transmit_led_state(); + return ret; +} + +void matrix_slave_scan(void) { + _matrix_scan(); + +#ifdef USE_50ONE_LEDS + _led_all_off(); + + if (i2c_slave_buffer[0] != 0) + _led_1_on(); + + if (i2c_slave_buffer[1] != 0) + _led_2_on(); + + if (i2c_slave_buffer[2] != 0) + _led_3_on(); +#endif + + int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; + +#ifdef USE_I2C + for (int i = 0; i < ROWS_PER_HAND; ++i) { + i2c_slave_buffer[i+3] = matrix[offset+i]; + } +#else // USE_SERIAL + for (int i = 0; i < ROWS_PER_HAND; ++i) { + serial_slave_buffer[i] = matrix[offset+i]; + } +#endif +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1<> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) +{ + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[current_row]; + + // Clear data in matrix row + current_matrix[current_row] = 0; + + // Select row and wait for row selecton to stabilize + select_row(current_row); + wait_us(30); + + // For each col... + for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + + // Select the col pin to read (active low) + uint8_t pin = col_pins[col_index]; + uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); + + // Populate the matrix row with the state of the col pin + current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + } + + // Unselect row + unselect_row(current_row); + + return (last_row_value != current_matrix[current_row]); +} + +static void select_row(uint8_t row) +{ + uint8_t pin = row_pins[row]; + _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW +} + +static void unselect_row(uint8_t row) +{ + uint8_t pin = row_pins[row]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI +} + +static void unselect_rows(void) +{ + for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { + uint8_t pin = row_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} + +#elif (DIODE_DIRECTION == ROW2COL) + +static void init_rows(void) +{ + for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { + uint8_t pin = row_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} + +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) +{ + bool matrix_changed = false; + + // Select col and wait for col selecton to stabilize + select_col(current_col); + wait_us(30); + + // For each row... + for(uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) + { + + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[row_index]; + + // Check row pin state + if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) + { + // Pin LO, set col bit + current_matrix[row_index] |= (ROW_SHIFTER << current_col); + } + else + { + // Pin HI, clear col bit + current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); + } + + // Determine if the matrix changed state + if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) + { + matrix_changed = true; + } + } + + // Unselect col + unselect_col(current_col); + + return matrix_changed; +} + +static void select_col(uint8_t col) +{ + uint8_t pin = col_pins[col]; + _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW +} + +static void unselect_col(uint8_t col) +{ + uint8_t pin = col_pins[col]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI +} + +static void unselect_cols(void) +{ + for(uint8_t x = 0; x < MATRIX_COLS; x++) { + uint8_t pin = col_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} + +#endif diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..503484d --- /dev/null +++ b/readme.md @@ -0,0 +1,15 @@ +# 50one + +![50one](imgur.com image replace me!) + +A short description of the keyboard/project + +Keyboard Maintainer: [You](https://github.com/yourusername) +Hardware Supported: The PCBs, controllers supported +Hardware Availability: links to where you can find this hardware + +Make example for this keyboard (after setting up your build environment): + + make 50one:default + +See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information. \ No newline at end of file diff --git a/rules.mk b/rules.mk new file mode 100644 index 0000000..5bbfb76 --- /dev/null +++ b/rules.mk @@ -0,0 +1,76 @@ +SRC += i2c.c \ + split_util.c \ + split_leds.c \ + matrix.c + +# MCU name +#MCU = at90usb1286 +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + +# Interrupt driven control endpoint task(+60) +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default +MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +AUDIO_ENABLE = no # Audio output on port C6 +FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches + +### Use the custom matrix.c provided by this keyboard instead of using the default one +CUSTOM_MATRIX=yes diff --git a/split_leds.c b/split_leds.c new file mode 100644 index 0000000..90649b3 --- /dev/null +++ b/split_leds.c @@ -0,0 +1,106 @@ +#include +#include "split_leds.h" + + +extern inline void _led_1_on(void); +extern inline void _led_2_on(void); +extern inline void _led_3_on(void); + +extern inline void _led_1_off(void); +extern inline void _led_2_off(void); +extern inline void _led_3_off(void); + +extern inline void _led_set_master(uint8_t num, led_state_t state); +extern inline void _led_set_slave(uint8_t num, led_state_t state); + +void left_led_set(uint8_t num, led_state_t state) +{ + if (has_usb() && isLeftHand) + { + _led_set_master(num, state); + } + else if (has_usb() && !isLeftHand) + { + _led_set_slave(num, state); + } +} + +void right_led_set(uint8_t num, led_state_t state) +{ + if (has_usb() && !isLeftHand) + { + _led_set_master(num, state); + } + else if (has_usb() && isLeftHand) + { + _led_set_slave(num, state); + } +} + +void both_led_set(uint8_t num, led_state_t state) +{ + right_led_set(num, state); + left_led_set(num, state); +} + + +void left_led_all_on(void) +{ + left_led_set(1, LED_ON); + left_led_set(2, LED_ON); + left_led_set(3, LED_ON); +} +void left_led_all_off(void) +{ + left_led_set(1, LED_OFF); + left_led_set(2, LED_OFF); + left_led_set(3, LED_OFF); +} + +void right_led_all_on(void) +{ + right_led_set(1, LED_ON); + right_led_set(2, LED_ON); + right_led_set(3, LED_ON); +} +void right_led_all_off(void) +{ + right_led_set(1, LED_OFF); + right_led_set(2, LED_OFF); + right_led_set(3, LED_OFF); +} + +void both_led_all_on(void) +{ + right_led_all_on(); + left_led_all_on(); +} +void both_led_all_off(void) +{ + right_led_all_off(); + left_led_all_off(); +} + + +void _led_init(void) +{ + DDRF |= (1< +#ifdef __AVR__ + #include + #include +#endif +#endif + +#include "split_util.h" + +#define LED_RED 1 +#define LED_GREEN 2 +#define LED_BLUE 3 + +enum led_state{ + LED_OFF = 0, + LED_ON +}; + +typedef enum led_state led_state_t; + +inline void _led_1_off(void) { DDRF &= ~(1< +#include +#include +#include +#include +#include +#include "split_util.h" +#include "matrix.h" +#include "keyboard.h" +#include "config.h" +#include "timer.h" + +#ifdef USE_I2C +# include "i2c.h" +#endif + + +volatile bool isLeftHand = true; + +static void setup_handedness(void) { + #ifdef EE_HANDS + isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); + #else + // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c + #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) + isLeftHand = !has_usb(); + #else + isLeftHand = has_usb(); + #endif + #endif +} + +static void keyboard_master_setup(void) { + i2c_master_init(); +} + +static void keyboard_slave_setup(void) { + timer_init(); + i2c_slave_init(SLAVE_I2C_ADDRESS); +} + +bool has_usb(void) { + USBCON |= (1 << OTGPADE); //enables VBUS pad + _delay_us(5); + return (USBSTA & (1< +#include "eeconfig.h" + +#ifdef USE_50ONE_LEDS + #include "split_leds.h" +#endif + +#define SLAVE_I2C_ADDRESS 0x32 + +extern volatile bool isLeftHand; + +// slave version of matix scan, defined in matrix.c +void matrix_slave_scan(void); + +void split_keyboard_setup(void); +bool has_usb(void); +void keyboard_slave_loop(void); + +#endif