diff options
author | Alex Ong <the.onga@gmail.com> | 2018-08-29 10:08:07 +1000 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2018-08-28 17:08:07 -0700 |
commit | 9bd6d6112d698ea5823b268983809fe3b8d98b26 (patch) | |
tree | a47b90c36bc7c976bd57b5d69bdba0e905bcfd66 | |
parent | af5f59636eea83f66db6510f61510d31ee9dade4 (diff) | |
download | qmk_firmware-9bd6d6112d698ea5823b268983809fe3b8d98b26.tar.gz |
Keyboard: xealous (#3731)
* Keyboard: HandWired/XeaL60
* Updated rules.mk
* Mapping for layout was flipped
* Figured out how to re-map bad pins.
* Updated Keymap
* Enabled audio, Forced NKRO
* Added QMK_KEYS_PER_SCAN
* Removed more unnecessary files, since split_keyboards are in main QMK branch already.
* Simplified rules.mk in rev1
* Removed i2c from matrix.c
* Re-formatted to 4 spaces per tab,
* Changed note for NUMPAD
* Added I2C support back!
* Fixed keyboard mappings. Both sides work
* Moved i2c configuration from keymaps/default/config.h to config.h
* Changed SCL_CLOCK to 400000L
* Added DEBUG_MATRIX_SCAN_RATE for future optimization efforts
* Removed row2col code to clean up matrix.c
* Scan rate from 2100 -> 4200 by using Nop instead of waiting 30us between columns.
* Further optimized column reading via optimized_col_reader.
* Immediate key-recognition
* Switched back to own implementation of SPLIT_KEYBOARD. Will optimize so that slave interrupts master.
* Moved scanrate debug messages to another file.
* Made matrix_scanrate.c compile if CONSOLE_ENABLE is off. Updated to latest i2c.c
* Latest i2c uses a few bytes for lighting information
* Optimizations in i2c.h to determine buffer size.
* Disabled a whole bunch of features. TODO: Test that keyboard still works fine.
* Minimum #define NO_ACTION's with still working keyboard
* Fixed matrix not working due to offsets not being respected
* Added numlock button for keymap.
* Use I2C_KEYMAP_START offset
* Removed serial, Backlight and RGB support
* Removed need for split_flags.
* Added audio on and off for numlock.
* Renamed from xeal60 to xealous, simplified build system.
* Used more shared split_common code.
* Updated audio code.
* moved tone_qwerty and tone_numpad to config.h. Removed keymaps/default/config.h
* Added more shortcut keys in _FN layer. Increased debounce to 6ms due to fencepost error.
* DF used with incorrect argument. Custom_keycodes no longer required.
* Fixed bug in update_debounce_counters which was resulting in no debouncing!
* Removed unnecessary #include
-rw-r--r-- | keyboards/handwired/xealous/config.h | 48 | ||||
-rw-r--r-- | keyboards/handwired/xealous/info.json | 91 | ||||
-rw-r--r-- | keyboards/handwired/xealous/keymaps/default/keymap.c | 105 | ||||
-rw-r--r-- | keyboards/handwired/xealous/matrix.c | 376 | ||||
-rw-r--r-- | keyboards/handwired/xealous/matrix_scanrate.c | 39 | ||||
-rw-r--r-- | keyboards/handwired/xealous/matrix_scanrate.h | 4 | ||||
-rw-r--r-- | keyboards/handwired/xealous/readme.md | 166 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rev1/config.h | 90 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rev1/rev1.c | 6 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rev1/rev1.h | 32 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rev1/rules.mk | 0 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rules.mk | 73 |
12 files changed, 1030 insertions, 0 deletions
diff --git a/keyboards/handwired/xealous/config.h b/keyboards/handwired/xealous/config.h new file mode 100644 index 000000000..415a0dcf5 --- /dev/null +++ b/keyboards/handwired/xealous/config.h @@ -0,0 +1,48 @@ +/* +Copyright 2012 Jun Wako <wakojun@gmail.com> +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 <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "config_common.h" + +/* Use I2C or Serial, not both */ + +// #define USE_SERIAL +#define USE_I2C +#define SCL_CLOCK 400000UL + +/* Select hand configuration */ + +#define MASTER_LEFT +// #define MASTER_RIGHT +// #define EE_HANDS + + +//#define DEBUG_MATRIX_SCAN_RATE //Use this to determine scan-rate. +#define FORCE_NKRO + +#define QMK_KEYS_PER_SCAN 4 //if we press four keys simultaneously, lets process them simultaneously... +#define DIODE_DIRECTION COL2ROW + +#ifdef AUDIO_ENABLE + #define C6_AUDIO + #define STARTUP_SONG SONG(STARTUP_SOUND) + #define NO_MUSIC_MODE + #define TONE_QWERTY SONG(Q__NOTE(_E4)); + #define TONE_NUMPAD SONG(Q__NOTE(_D4)); +#endif + diff --git a/keyboards/handwired/xealous/info.json b/keyboards/handwired/xealous/info.json new file mode 100644 index 000000000..6d7e30f44 --- /dev/null +++ b/keyboards/handwired/xealous/info.json @@ -0,0 +1,91 @@ +{ + "keyboard_name": "Xealous", + "url": "", + "maintainer": "alex-ong", + "width": 15, + "height": 5, + "layouts": { + "LAYOUT_ANSI_DEFAULT": { + "key_count": 64, + "layout": [ + {"label":"Esc", "x":0, "y":0}, + {"label":"1", "x":1, "y":0}, + {"label":"2", "x":2, "y":0}, + {"label":"3", "x":3, "y":0}, + {"label":"4", "x":4, "y":0}, + {"label":"5", "x":5, "y":0}, + {"label":"6", "x":6, "y":0}, + + {"label":"7", "x":7, "y":0}, + {"label":"8", "x":8, "y":0}, + {"label":"9", "x":9, "y":0}, + {"label":"0", "x":10, "y":0}, + {"label":"-", "x":11, "y":0}, + {"label":"=", "x":12, "y":0}, + {"label":"Backspace", "x":13, "y":0, "w":2.0}, + + {"label":"Tab", "x":0, "y":1, "w":1.5}, + {"label":"Q", "x":1.5, "y":1}, + {"label":"W", "x":2.5, "y":1}, + {"label":"E", "x":3.5, "y":1}, + { + "label": "R", + "x": 4.5, + "y": 1 + }, + {"label":"T", "x":5.5, "y":1}, + + {"label":"Y", "x":6.5, "y":1}, + {"label":"U", "x":7.5, "y":1}, + {"label":"I", "x":8.5, "y":1}, + {"label":"O", "x":9.5, "y":1}, + {"label":"P", "x":10.5, "y":1}, + {"label":"[", "x":11.5, "y":1}, + {"label":"]", "x":12.5, "y":1}, + {"label":"\\", "x":13.5, "y":1, "w":1.5}, + + {"label":"CapsLock", "x":0, "y":2, "w":1.75}, + {"label":"A", "x":1.75, "y":2}, + {"label":"S", "x":2.75, "y":2}, + {"label":"D", "x":3.75, "y":2}, + {"label":"F", "x":4.75, "y":2}, + {"label":"G", "x":5.75, "y":2}, + + {"label":"H", "x":6.75, "y":2}, + {"label":"J", "x":7.75, "y":2}, + {"label":"K", "x":8.75, "y":2}, + {"label":"L", "x":9.75, "y":2}, + {"label":";", "x":10.75, "y":2}, + {"label":"'", "x":11.75, "y":2}, + {"label":"Enter", "x":12.75, "y":2, "w":2.25}, + + {"label":"Shift", "x":0, "y":3, "w":2.25}, + {"label":"Z", "x":2.25, "y":3}, + {"label":"X", "x":3.25, "y":3}, + {"label":"C", "x":4.25, "y":3}, + {"label":"V", "x":5.25, "y":3}, + {"label":"B", "x":6.25, "y":3}, + + {"label":"N", "x":7.25, "y":3}, + {"label":"M", "x":8.25, "y":3}, + {"label":",", "x":9.25, "y":3}, + {"label":".", "x":10.25, "y":3}, + {"label":"/", "x":11.25, "y":3}, + {"label":"Shift", "x":12.25, "y":3, "w":2.75}, + + {"label":"Ctrl", "x":0, "y":4, "w":1.25}, + {"label":"Win", "x":1.25, "y":4, "w":1.25}, + {"label":"Alt", "x":2.5, "y":4, "w":1.25}, + {"x":3.75, "y":4, "w":2.75}, + {"x":6.5, "y":4, "w":1.25}, + + {"x":7.75, "y":4, "w":1.25}, + {"x":9, "y":4, "w":2.0}, + {"label":"Alt", "x":11, "y":4}, + {"label":"Win", "x":12, "y":4}, + {"label":"Menu", "x":13, "y":4}, + {"label":"Ctrl", "x":14, "y":4} + ] + } + } +} diff --git a/keyboards/handwired/xealous/keymaps/default/keymap.c b/keyboards/handwired/xealous/keymaps/default/keymap.c new file mode 100644 index 000000000..a07e64fd7 --- /dev/null +++ b/keyboards/handwired/xealous/keymaps/default/keymap.c @@ -0,0 +1,105 @@ +#include QMK_KEYBOARD_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 _QWERTY 0 +#define _NUMPAD 1 +#define _FN 2 + +// Fillers to make layering more clear +#define _______ KC_TRNS +#define XXXXXXX KC_NO +#define FN MO(_FN) + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { +/* + * ,-----------------------------------------------------------. + * |Esc~| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | + * |-----------------------------------------------------------| + * |FN | A| S| D| F| G| H| J| K| L| ;| '|Return | + * |-----------------------------------------------------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /| Shift | + * |-----------------------------------------------------------| + * |Ctrl|Gui |Alt | NUM | Space | Space |Alt |FN |Menu |Ctrl | + * `-----------------------------------------------------------' + */ + /* Layer 0: Qwerty */ + [_QWERTY] = LAYOUT_split60( \ + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, \ + FN, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, \ + KC_LCTL, KC_LGUI, KC_LALT, DF(_NUMPAD), KC_SPC, KC_SPC, KC_RALT, FN, KC_APP, KC_RCTL \ + ), + +/* + * ,-----------------------------------------------------------. + * | | | | | | | |Nlck| /| *| -| | | | + * |-----------------------------------------------------------| + * | | | | | | | | 7| 8| 9| +| | | | + * |-----------------------------------------------------------| + * | | | | | | | | 4| 5| 6|Bspc| |Return | + * |-----------------------------------------------------------| + * | | | | | | | | 1| 2| 3| .| | + * |-----------------------------------------------------------| + * | | | | QWE | | 0 | . |A_ON |A_OFF| | + * `-----------------------------------------------------------' + */ + + /* Layer 1: Numpad */ + [_NUMPAD] = LAYOUT_split60( \ + _______, _______, _______, _______, _______, _______, _______, KC_NLCK, KC_PSLS, KC_PAST, KC_MINUS, _______, _______, KC_BSPC, \ + _______, _______, _______, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, KC_PLUS, _______, _______, KC_BSLS, \ + _______, _______, _______, _______, _______, _______, _______, KC_P4, KC_P5, KC_P6, KC_BSPC, _______, _______, \ + _______, _______, _______, _______, _______, _______, _______, KC_P1, KC_P2, KC_P3, KC_DOT, _______, \ + _______, _______, _______,DF(_QWERTY), _______, KC_P0, KC_PDOT, AU_ON, AU_OFF, _______ \ + ), + +/* + * ,-----------------------------------------------------------. + * | ` |F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| Delete| + * |-----------------------------------------------------------| + * | Caps|pUp| ^ |pDn| | | |pUp| ^ |pDn|PSR|SLK|Pau| | + * |-----------------------------------------------------------| + * | | < | v | > | |Hom|Hom| < | v | > |INS| DEL| | + * |-----------------------------------------------------------| + * | | | | | |End|End| |Vo-|Vo+|VoX| | + * |-----------------------------------------------------------| + * | | | | | | | | | | | + * `-----------------------------------------------------------' + */ + + /* Layer 2: RAISE */ + [_FN] = LAYOUT_split60( \ + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, \ + KC_CAPS, KC_PGUP, KC_UP, KC_PGDN, _______, _______, _______, KC_PGUP, KC_UP, KC_PGDN, KC_PSCR, KC_SLCK, KC_PAUS, _______, \ + _______, KC_LEFT, KC_DOWN,KC_RIGHT, _______, KC_HOME, KC_HOME, KC_LEFT, KC_DOWN, KC_RIGHT, KC_INS, KC_DEL, _______, \ + _______, _______, _______, _______, _______, KC_END, KC_END, AU_TOG, KC_VOLD, KC_VOLU, KC_MUTE, _______, \ + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ + ) + +}; + +#ifdef AUDIO_ENABLE +float tone_qwerty[][2] = TONE_QWERTY; +float tone_numpad[][2] = TONE_NUMPAD; + +uint32_t default_layer_state_set_kb(uint32_t state) { + if (state == 1UL<<_QWERTY) { + PLAY_SONG(tone_qwerty); + } else if (state == 1UL<<_NUMPAD) { + PLAY_SONG(tone_numpad); + } + return state; +} +#endif + +void led_set_keymap(uint8_t usb_led) { +} diff --git a/keyboards/handwired/xealous/matrix.c b/keyboards/handwired/xealous/matrix.c new file mode 100644 index 000000000..27fad0008 --- /dev/null +++ b/keyboards/handwired/xealous/matrix.c @@ -0,0 +1,376 @@ +/* +Copyright 2012 Jun Wako <wakojun@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/>. +*/ + +/* + * scan matrix + */ +#include <stdint.h> +#include <stdbool.h> +#include <avr/io.h> +#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" +#ifdef DEBUG_MATRIX_SCAN_RATE + #include "matrix_scanrate.h" +#endif + + + +#ifdef USE_I2C +# include "i2c.h" +#else // USE_SERIAL +# error "only i2c supported" +#endif + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#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 + +#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]; +static matrix_row_t* debouncing_matrix_hand_offsetted; //pointer to matrix_debouncing for our hand +static matrix_row_t* matrix_hand_offsetted; // pointer to matrix for our hand + +//Debouncing counters +typedef uint8_t debounce_counter_t; +#define DEBOUNCE_COUNTER_MODULO 250 +#define DEBOUNCE_COUNTER_INACTIVE 251 +static debounce_counter_t debounce_counters[MATRIX_ROWS * MATRIX_COLS]; +static debounce_counter_t *debounce_counters_hand_offsetted; + + +#if (DIODE_DIRECTION == ROW2COL) + error "Only Col2Row supported"; +#endif +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); +static void unselect_row(uint8_t row); +static matrix_row_t optimized_col_reader(void); + +__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) { +} + +__attribute__ ((weak)) +void matrix_slave_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<<JTD); + MCUCR |= (1<<JTD); +#endif + + debug_enable = true; + debug_matrix = false; + debug_mouse = false; + // initialize row and col + unselect_rows(); + init_cols(); + + TX_RX_LED_INIT; + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } + int my_hand_offset = isLeftHand ? 0 : (ROWS_PER_HAND); + debouncing_matrix_hand_offsetted = matrix_debouncing + my_hand_offset; + matrix_hand_offsetted = matrix + my_hand_offset; + debounce_counters_hand_offsetted = debounce_counters + my_hand_offset; + + for (uint8_t i = 0; i < MATRIX_ROWS * MATRIX_COLS; i++) { + debounce_counters[i] = DEBOUNCE_COUNTER_INACTIVE; + } + + matrix_init_quantum(); + +} + +//#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) +void update_debounce_counters(uint8_t current_time) +{ + debounce_counter_t *debounce_pointer = debounce_counters_hand_offsetted; + for (uint8_t row = 0; row < ROWS_PER_HAND; row++) + { + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + if (*debounce_pointer != DEBOUNCE_COUNTER_INACTIVE) + { + if (TIMER_DIFF(current_time, *debounce_pointer, DEBOUNCE_COUNTER_MODULO) >= + DEBOUNCING_DELAY) { + *debounce_pointer = DEBOUNCE_COUNTER_INACTIVE; + } + } + debounce_pointer++; + } + } +} + +void transfer_matrix_values(uint8_t current_time) +{ + //upload from debounce_matrix to final matrix; + debounce_counter_t *debounce_pointer = debounce_counters_hand_offsetted; + for (uint8_t row = 0; row < ROWS_PER_HAND; row++) + { + matrix_row_t row_value = matrix_hand_offsetted[row]; + matrix_row_t debounce_value = debouncing_matrix_hand_offsetted[row]; + + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + bool final_value = debounce_value & (1 << col); + bool current_value = row_value & (1 << col); + if (*debounce_pointer == DEBOUNCE_COUNTER_INACTIVE + && (current_value != final_value)) + { + *debounce_pointer = current_time; + row_value ^= (1 << col); + } + debounce_pointer++; + } + matrix_hand_offsetted[row] = row_value; + } +} + +uint8_t _matrix_scan(void) +{ + uint8_t current_time = timer_read() % DEBOUNCE_COUNTER_MODULO; + + // Set row, read cols + for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { + select_row(current_row); + asm volatile ("nop"); asm volatile("nop"); + + debouncing_matrix_hand_offsetted[current_row] = optimized_col_reader(); + // Unselect row + unselect_row(current_row); + } + + update_debounce_counters(current_time); + transfer_matrix_values(current_time); + + return 1; +} + + +// 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(I2C_KEYMAP_START); + if (err) goto i2c_error; + + // 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; +} + +uint8_t matrix_scan(void) +{ +#ifdef DEBUG_MATRIX_SCAN_RATE + matrix_check_scan_rate(); + matrix_time_between_scans(); +#endif + uint8_t ret = _matrix_scan(); + + if( i2c_transaction() ) { + // 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(); + return ret; +} + +void matrix_slave_scan(void) { + _matrix_scan(); + + int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; + + for (int i = 0; i < ROWS_PER_HAND; ++i) { + i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; + } + + matrix_slave_scan_user(); +} + +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; +} + +static void init_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 + } +} + +inline +static matrix_row_t optimized_col_reader(void) { + //MATRIX_COL_PINS { B6, B2, B3, B1, F7, F6, F5, F4 } + return (PINB & (1 << 6) ? 0 : (ROW_SHIFTER << 0)) | + (PINB & (1 << 2) ? 0 : (ROW_SHIFTER << 1)) | + (PINB & (1 << 3) ? 0 : (ROW_SHIFTER << 2)) | + (PINB & (1 << 1) ? 0 : (ROW_SHIFTER << 3)) | + (PINF & (1 << 7) ? 0 : (ROW_SHIFTER << 4)) | + (PINF & (1 << 6) ? 0 : (ROW_SHIFTER << 5)) | + (PINF & (1 << 5) ? 0 : (ROW_SHIFTER << 6)) | + (PINF & (1 << 4) ? 0 : (ROW_SHIFTER << 7)); +} + + +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 + } +} + diff --git a/keyboards/handwired/xealous/matrix_scanrate.c b/keyboards/handwired/xealous/matrix_scanrate.c new file mode 100644 index 000000000..f2c7cbe6e --- /dev/null +++ b/keyboards/handwired/xealous/matrix_scanrate.c @@ -0,0 +1,39 @@ +#include <stdint.h> +#include <stdbool.h> +#include <avr/io.h> +#include "wait.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "timer.h" + +#ifdef CONSOLE_ENABLE +static uint16_t matrix_scan_count = 0; +static uint32_t matrix_timer = 0; +void matrix_check_scan_rate(void) { + matrix_scan_count++; + if (matrix_scan_count > 1000) { + uint32_t timer_now = timer_read32(); + uint16_t ms_per_thousand = TIMER_DIFF_32(timer_now, matrix_timer); + uint16_t rate_per_second = 1000000UL / ms_per_thousand; + print("scan_rate: "); + pdec(rate_per_second); + print("\n"); + matrix_timer = timer_now; + matrix_scan_count = 0; + } +} + +static uint32_t last_scan_time = 0; +void matrix_time_between_scans(void) { + if (timer_elapsed(last_scan_time) > 1) + { + print(">1ms elapsed since last scan: "); + pdec(timer_elapsed(last_scan_time)); + print("\n"); + } + last_scan_time = timer_read(); + +} +#endif diff --git a/keyboards/handwired/xealous/matrix_scanrate.h b/keyboards/handwired/xealous/matrix_scanrate.h new file mode 100644 index 000000000..18d56cd5b --- /dev/null +++ b/keyboards/handwired/xealous/matrix_scanrate.h @@ -0,0 +1,4 @@ +__attribute__((weak)) +void matrix_check_scan_rate(void) {} +__attribute__((weak)) +void matrix_time_between_scans(void) {} diff --git a/keyboards/handwired/xealous/readme.md b/keyboards/handwired/xealous/readme.md new file mode 100644 index 000000000..97bebbfe3 --- /dev/null +++ b/keyboards/handwired/xealous/readme.md @@ -0,0 +1,166 @@ +XeaL60 +====== + +Split keyboard firmware for Arduino Pro Micro or other ATmega32u4 +based boards. + + +## Build Guide + +A build guide for putting together the Xealous can be found here: https://github.com/alex-ong/Split60 + + +## First Time Setup + +Download or clone the `qmk_firmware` repo and navigate to its top level directory. Once your build environment is setup, you'll be able to generate the default .hex using: + +``` +$ make handwired/xeal60/rev1:default +``` + +You will see a lot of output and if everything worked correctly you will see the built hex file: + +``` +handwired_xeal60_rev1_default.hex +``` + +If you would like to use one of the alternative keymaps, or create your own, copy one of the existing [keymaps](keymaps/) and run make like so: + + +``` +$ make handwired/xeal60/rev1:YOUR_KEYMAP_NAME +``` + +If everything worked correctly you will see a file: + +``` +handwired_xeal60_rev1_YOUR_KEYMAP_NAME.hex +``` + +For more information on customizing keymaps, take a look at the primary documentation for [Customizing Your Keymap](/docs/faq_keymap.md) in the main readme.md. + + +Features +-------- + +For the full Quantum Mechanical Keyboard feature list, see [the parent readme.md](/readme.md). + +Some features supported by the firmware: + +* Either half can connect to the computer via USB, or both halves can be used + independently. +* I2C connection between the two halves if for some + reason you require a faster connection between the two halves. Note this + requires an extra wire between halves and pull-up resistors on the data lines. + +Required Hardware +----------------- + +Apart from diodes and key switches for the keyboard matrix in each half, you +will need: + +* 2 Arduino Pro Micros. You can find these on AliExpress for ≈3.50USD each. +* 2 TRRS sockets and 1 TRRS cable, or 2 TRS sockets and 1 TRS cable + +Alternatively, you can use any sort of cable and socket that has at least 4 +wires. You will need a cable with at least 4 wires and 2x 4.7kΩ pull-up resistors + +Optional Hardware +----------------- + +A speaker can be hooked-up to either side to the `5` (`C6`) pin and `GND`, and turned on via `AUDIO_ENABLE`. + +Wiring +------ + +The 3 wires of the TRS/TRRS cable need to connect GND, VCC, and digital pin 3 (i.e. +PD0 on the ATmega32u4) between the two Pro Micros. + +Next, wire your key matrix to any of the remaining 17 IO pins of the pro micro +and modify the `matrix.c` accordingly. + +The wiring for serial: + +![serial wiring](https://i.imgur.com/C3D1GAQ.png) + + +Notes on Software Configuration +------------------------------- + +Configuring the firmware is similar to any other QMK project. One thing +to note is that `MATRIX_ROWS` in `config.h` is the total number of rows between +the two halves, i.e. if your split keyboard has 5 rows in each half, then use +`MATRIX_ROWS=10`. + +Also, the current implementation assumes a maximum of 8 columns, but it would +not be very difficult to adapt it to support more if required. + +Flashing +------- +From the top level `qmk_firmware` directory run `make KEYBOARD:KEYMAP:avrdude` for automatic serial port resolution and flashing. +Example: `make handwired/xeal60/rev1:default:avrdude` + + +Choosing which board to plug the USB cable into (choosing Master) +-------- +Because the two boards are identical, the firmware has logic to differentiate the left and right board. + +It uses two strategies to figure things out: looking at the EEPROM (memory on the chip) or looking if the current board has the usb cable. + +The EEPROM approach requires additional setup (flashing the eeprom) but allows you to swap the usb cable to either side. + +The USB cable approach is easier to setup and if you just want the usb cable on the left board, you do not need to do anything extra. + +### Setting the left hand as master +If you always plug the usb cable into the left board, nothing extra is needed as this is the default. Comment out `EE_HANDS` and comment out `I2C_MASTER_RIGHT` or `MASTER_RIGHT` if for some reason it was set. + +### Setting the right hand as master +If you always plug the usb cable into the right board, add an extra flag to your `config.h` +``` + #define MASTER_RIGHT +``` + +### Setting EE_hands to use either hands as master +If you define `EE_HANDS` in your `config.h`, you will need to set the +EEPROM for the left and right halves. + +The EEPROM is used to store whether the +half is left handed or right handed. This makes it so that the same firmware +file will run on both hands instead of having to flash left and right handed +versions of the firmware to each half. To flash the EEPROM file for the left +half run: +``` +avrdude -p atmega32u4 -P $(COM_PORT) -c avr109 -U eeprom:w:eeprom-lefthand.eep +// or the equivalent in dfu-programmer + +``` +and similarly for right half +``` +avrdude -p atmega32u4 -P $(COM_PORT) -c avr109 -U eeprom:w:eeprom-righhand.eep +// or the equivalent in dfu-programmer +``` + +NOTE: replace `$(COM_PORT)` with the port of your device (e.g. `/dev/ttyACM0`) + +After you have flashed the EEPROM, you then need to set `EE_HANDS` in your config.h, rebuild the hex files and reflash. + +Note that you need to program both halves, but you have the option of using +different keymaps for each half. You could program the left half with a QWERTY +layout and the right half with a Colemak layout using bootmagic's default layout option. +Then if you connect the left half to a computer by USB the keyboard will use QWERTY and Colemak when the +right half is connected. + + +Notes on Using Pro Micro 3.3V +----------------------------- + +Do update the `F_CPU` parameter in `rules.mk` to `8000000` which reflects +the frequency on the 3.3V board. + +Also, if the slave board is producing weird characters in certain columns, +update the following line in `matrix.c` to the following: + +``` +// _delay_us(30); // without this wait read unstable value. +_delay_us(300); // without this wait read unstable value. +``` diff --git a/keyboards/handwired/xealous/rev1/config.h b/keyboards/handwired/xealous/rev1/config.h new file mode 100644 index 000000000..6fc769b5f --- /dev/null +++ b/keyboards/handwired/xealous/rev1/config.h @@ -0,0 +1,90 @@ +/* +Copyright 2012 Jun Wako <wakojun@gmail.com> +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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef REV1_CONFIG_H +#define REV1_CONFIG_H + +#include "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0x4131 +#define PRODUCT_ID 0x5141 +#define DEVICE_VER 0x0001 +#define MANUFACTURER XeaLouS +#define PRODUCT XeaL60 +#define DESCRIPTION A split keyboard + +/* key matrix size */ +// Rows are doubled-up +#define MATRIX_ROWS 10 +#define MATRIX_COLS 8 + +// wiring of each half +// Ascii art of pro micro. Pin names PD3, PD2, etc. +//Usage| Name | Label Label| Name | Usage +// PORT +// | PD3 TX0 RAW | +// | PD2 RX1 GND |SerGnd +// | GND RESET | +// | GND VCC |SerVCc +// | PD1 2 A3 PF4 | Col7 +//Ser | PD0 3 A2 PF5 | Col6 +//Row4 | PD4 4 A1 PF6 | Col5 +//AUDIO| PC6 5 A0 PF7 | Col4 +//Row3 | PD7 6 15 PB1 | Col3 +//Row2 | PE6 7 14 PB3 | Col2 +//Row1 | PB4 8 13 PB2 | Col1 +//Row0 | PB5 9 10 PB6 | Col0 + +// Note reservation of C6 for audio +#define MATRIX_ROW_PINS { B5, B4, E6, D7, D4 } +#define MATRIX_COL_PINS { B6, B2, B3, B1, F7, F6, F5, F4 } + +/* define if matrix has ghost */ +//#define MATRIX_HAS_GHOST + +/* number of backlight levels */ +// #define BACKLIGHT_LEVELS 3 + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCING_DELAY 5 + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* + * 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 +#define IGNORE_MOD_TAP_INTERRUPT +#endif diff --git a/keyboards/handwired/xealous/rev1/rev1.c b/keyboards/handwired/xealous/rev1/rev1.c new file mode 100644 index 000000000..3e51421d8 --- /dev/null +++ b/keyboards/handwired/xealous/rev1/rev1.c @@ -0,0 +1,6 @@ +#include "quantum.h" +#include "rev1.h" + +void matrix_init_kb(void) { + matrix_init_user(); +} diff --git a/keyboards/handwired/xealous/rev1/rev1.h b/keyboards/handwired/xealous/rev1/rev1.h new file mode 100644 index 000000000..d195af49d --- /dev/null +++ b/keyboards/handwired/xealous/rev1/rev1.h @@ -0,0 +1,32 @@ +#ifndef REV1_H +#define REV1_H + +//void promicro_bootloader_jmp(bool program); +#include "quantum.h" + +//void promicro_bootloader_jmp(bool program); +#define XXX KC_NO + +#define LAYOUT( \ + L00, L01, L02, L03, L04, L05, L06, R06, R05, R04, R03, R02, R01, R00, \ + L10, L11, L12, L13, L14, L15, R17, R16, R15, R14, R13, R12, R11, R10, \ + L20, L21, L22, L23, L24, L25, R26, R25, R24, R23, R22, R21, R20, \ + L30, L31, L32, L33, L34, L35, R35, R34, R33, R32, R31, R30, \ + L40, L41, L42, L43, L44, R44, R43, R42, R41, R40 \ + ) \ + { \ + { XXX, L06, L05, L04, L03, L02, L01, L00 }, \ + { XXX, XXX, L15, L14, L13, L12, L11, L10 }, \ + { XXX, XXX, L25, L24, L23, L22, L21, L20 }, \ + { XXX, XXX, L35, L34, L33, L32, L31, L30 }, \ + { XXX, XXX, XXX, L44, L43, L42, L41, L40 }, \ + { R00, R01, R02, R03, R04, R05, R06, XXX }, \ + { R10, R11, R12, R13, R14, R15, R16, R17 }, \ + { R20, R21, R22, R23, R24, R25, R26, XXX }, \ + { R30, R31, R32, R33, R34, R35, XXX, XXX }, \ + { R40, R41, R42, R43, R44, XXX, XXX, XXX } \ + } + +#define LAYOUT_split60 LAYOUT + +#endif diff --git a/keyboards/handwired/xealous/rev1/rules.mk b/keyboards/handwired/xealous/rev1/rules.mk new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/keyboards/handwired/xealous/rev1/rules.mk diff --git a/keyboards/handwired/xealous/rules.mk b/keyboards/handwired/xealous/rules.mk new file mode 100644 index 000000000..717895960 --- /dev/null +++ b/keyboards/handwired/xealous/rules.mk @@ -0,0 +1,73 @@ +SRC += matrix_scanrate.c matrix.c + +# MCU name +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) + +# Bootloader +# This definition is optional, and if your keyboard supports multiple bootloaders of +# different sizes, comment this out, and the correct address will be loaded +# automatically (+60). See bootloader.mk for all options. +BOOTLOADER = caterina + +# Interrupt driven control endpoint task(+60) +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + +# Build Options +# change to "no" to disable the options, or define them in the Makefile in +# the appropriate keymap folder that will get included automatically +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = no # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +MIDI_ENABLE = no # MIDI controls +AUDIO_ENABLE = yes # Audio output on port C6 +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. +SPLIT_KEYBOARD = yes # Use shared split_common code +SUBPROJECT_rev1 = yes + +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend + +CUSTOM_MATRIX = yes + +LAYOUTS = split60 + +DEFAULT_FOLDER = handwired/xealous/rev1 |