diff options
| -rw-r--r-- | keyboards/handwired/xealousbrown/README.md | 8 | ||||
| -rw-r--r-- | keyboards/handwired/xealousbrown/config.h | 5 | ||||
| -rw-r--r-- | keyboards/handwired/xealousbrown/keymaps/default/keymap.c | 4 | ||||
| -rw-r--r-- | keyboards/handwired/xealousbrown/matrix.c | 112 | ||||
| -rw-r--r-- | keyboards/handwired/xealousbrown/rules.mk | 34 | ||||
| -rw-r--r-- | keyboards/handwired/xealousbrown/xealousbrown.c | 41 |
6 files changed, 188 insertions, 16 deletions
diff --git a/keyboards/handwired/xealousbrown/README.md b/keyboards/handwired/xealousbrown/README.md index e6092ebb0..970f9444c 100644 --- a/keyboards/handwired/xealousbrown/README.md +++ b/keyboards/handwired/xealousbrown/README.md | |||
| @@ -7,5 +7,11 @@ https://sites.google.com/site/xaelous/keyboards/handwired-keyboard | |||
| 7 | 7 | ||
| 8 | Make example for this keyboard (after setting up your build environment): | 8 | Make example for this keyboard (after setting up your build environment): |
| 9 | 9 | ||
| 10 | make handwired/xealous-brown:default | 10 | make handwired/xealousbrown:default |
| 11 | 11 | ||
| 12 | |||
| 13 | The brief list of speedhacks to make this keyboard blazing fast: | ||
| 14 | 1) bit-bash implementation of scanning rows, columns. Very short delay between pin waiting. | ||
| 15 | 2) Compiling with a few extra flags | ||
| 16 | 3) Eager-per-key Debouncing algorithm (no 5ms delay before message is sent) | ||
| 17 | 4) 1000hz polling | ||
diff --git a/keyboards/handwired/xealousbrown/config.h b/keyboards/handwired/xealousbrown/config.h index 17aa6c94e..bf15637a4 100644 --- a/keyboards/handwired/xealousbrown/config.h +++ b/keyboards/handwired/xealousbrown/config.h | |||
| @@ -29,7 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | /* key matrix size */ | 29 | /* key matrix size */ |
| 30 | #define MATRIX_ROWS 5 | 30 | #define MATRIX_ROWS 5 |
| 31 | #define MATRIX_COLS 13 | 31 | #define MATRIX_COLS 13 |
| 32 | 32 | #define DEBOUNCE 10 | |
| 33 | #define USB_POLLING_INTERVAL_MS 1 | ||
| 34 | /* layer optimization */ | ||
| 35 | #define LAYER_STATE_8BIT | ||
| 33 | /* | 36 | /* |
| 34 | * Keyboard Matrix Assignments | 37 | * Keyboard Matrix Assignments |
| 35 | * | 38 | * |
diff --git a/keyboards/handwired/xealousbrown/keymaps/default/keymap.c b/keyboards/handwired/xealousbrown/keymaps/default/keymap.c index 6597c5667..908e54133 100644 --- a/keyboards/handwired/xealousbrown/keymaps/default/keymap.c +++ b/keyboards/handwired/xealousbrown/keymaps/default/keymap.c | |||
| @@ -10,8 +10,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 10 | ), | 10 | ), |
| 11 | [1] = LAYOUT( /* FN_Layer */ | 11 | [1] = LAYOUT( /* FN_Layer */ |
| 12 | 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, \ | 12 | 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, \ |
| 13 | KC_CAPS, KC_TRNS, KC_UP, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_UP, KC_PGDN, KC_PSCR, KC_SLCK,KC_PAUS,\ | 13 | KC_CAPS, KC_PGUP, KC_UP, KC_PGDN, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_UP, KC_PGDN, KC_PSCR, KC_SLCK,KC_PAUS,\ |
| 14 | KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_DEL, KC_TRNS, \ | 14 | KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_HOME, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_DEL, KC_TRNS, \ |
| 15 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS,KC_TRNS, | 15 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS,KC_TRNS, |
| 16 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL \ | 16 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL \ |
| 17 | ) | 17 | ) |
diff --git a/keyboards/handwired/xealousbrown/matrix.c b/keyboards/handwired/xealousbrown/matrix.c new file mode 100644 index 000000000..cce0d06eb --- /dev/null +++ b/keyboards/handwired/xealousbrown/matrix.c | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2019 Alex Ong | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <stdint.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "wait.h" | ||
| 20 | #include "util.h" | ||
| 21 | #include "matrix.h" | ||
| 22 | #include "debounce.h" | ||
| 23 | #include "quantum.h" | ||
| 24 | |||
| 25 | /* matrix state(1:on, 0:off) */ | ||
| 26 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | ||
| 27 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values | ||
| 28 | |||
| 29 | // matrix code | ||
| 30 | // super fast read_cols code. | ||
| 31 | static matrix_row_t read_cols(void) { | ||
| 32 | return (PINC & (1 << 6) ? 0 : (1UL << 0)) | | ||
| 33 | (PIND & (1 << 7) ? 0 : (1UL << 1)) | | ||
| 34 | (PINE & (1 << 6) ? 0 : (1UL << 2)) | | ||
| 35 | (PINB & (1 << 4) ? 0 : (1UL << 3)) | | ||
| 36 | (PINB & (1 << 5) ? 0 : (1UL << 4)) | | ||
| 37 | (PINB & (1 << 6) ? 0 : (1UL << 5)) | | ||
| 38 | (PINB & (1 << 2) ? 0 : (1UL << 6)) | | ||
| 39 | (PINB & (1 << 3) ? 0 : (1UL << 7)) | | ||
| 40 | (PINB & (1 << 1) ? 0 : (1UL << 8)) | | ||
| 41 | (PINF & (1 << 7) ? 0 : (1UL << 9)) | | ||
| 42 | (PINF & (1 << 6) ? 0 : (1UL << 10)) | | ||
| 43 | (PINF & (1 << 5) ? 0 : (1UL << 11)) | | ||
| 44 | (PINF & (1 << 4) ? 0 : (1UL << 12)); | ||
| 45 | } | ||
| 46 | |||
| 47 | static void unselect_rows(void) { | ||
| 48 | DDRD &= ~0b00011111; | ||
| 49 | PORTD &= ~0b00011111; | ||
| 50 | } | ||
| 51 | |||
| 52 | static void select_row(uint8_t row) { | ||
| 53 | switch (row) { | ||
| 54 | case 0: | ||
| 55 | DDRD |= (1 << 3); | ||
| 56 | PORTD &= ~(1 << 3); | ||
| 57 | break; | ||
| 58 | case 1: | ||
| 59 | DDRD |= (1 << 2); | ||
| 60 | PORTD &= ~(1 << 2); | ||
| 61 | break; | ||
| 62 | case 2: | ||
| 63 | DDRD |= (1 << 1); | ||
| 64 | PORTD &= ~(1 << 1); | ||
| 65 | break; | ||
| 66 | case 3: | ||
| 67 | DDRD |= (1 << 0); | ||
| 68 | PORTD &= ~(1 << 0); | ||
| 69 | break; | ||
| 70 | case 4: | ||
| 71 | DDRD |= (1 << 4); | ||
| 72 | PORTD &= ~(1 << 4); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | static void init_pins(void) { | ||
| 78 | DDRC &= ~(1 << 6); | ||
| 79 | PORTC |= (1 << 6); | ||
| 80 | DDRD &= ~(1 << 7); | ||
| 81 | PORTD |= (1 << 7); | ||
| 82 | DDRE &= ~(1 << 6); | ||
| 83 | PORTE |= (1 << 6); | ||
| 84 | DDRB &= ~(1 << 4 | 1 << 5 | 1 << 6 | 1 << 2 | 1 << 3 | 1 << 1); | ||
| 85 | PORTB |= (1 << 4 | 1 << 5 | 1 << 6 | 1 << 2 | 1 << 3 | 1 << 1); | ||
| 86 | DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4); | ||
| 87 | PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4); | ||
| 88 | } | ||
| 89 | |||
| 90 | // Only need to init the pins. Debounce / raw matrix are initialized already for us. | ||
| 91 | void matrix_init_custom(void) { | ||
| 92 | // initialize key pins | ||
| 93 | init_pins(); | ||
| 94 | } | ||
| 95 | |||
| 96 | // Only need to scan the result into current_matrix, and return changed. | ||
| 97 | uint8_t matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 98 | bool changed = false; | ||
| 99 | |||
| 100 | // Set row, read cols | ||
| 101 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | ||
| 102 | select_row(current_row); | ||
| 103 | asm volatile("nop"); | ||
| 104 | asm volatile("nop"); | ||
| 105 | matrix_row_t cols = read_cols(); | ||
| 106 | changed |= (current_matrix[current_row] != cols); | ||
| 107 | current_matrix[current_row] = cols; | ||
| 108 | unselect_rows(); | ||
| 109 | } | ||
| 110 | |||
| 111 | return changed; | ||
| 112 | } | ||
diff --git a/keyboards/handwired/xealousbrown/rules.mk b/keyboards/handwired/xealousbrown/rules.mk index c346ef6c9..887663580 100644 --- a/keyboards/handwired/xealousbrown/rules.mk +++ b/keyboards/handwired/xealousbrown/rules.mk | |||
| @@ -14,17 +14,27 @@ BOOTLOADER = caterina | |||
| 14 | # Build Options | 14 | # Build Options |
| 15 | # change yes to no to disable | 15 | # change yes to no to disable |
| 16 | # | 16 | # |
| 17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 17 | BOOTMAGIC_ENABLE = full # Virtual DIP switch configuration |
| 18 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | 18 | MOUSEKEY_ENABLE = no # Mouse keys |
| 19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 19 | EXTRAKEY_ENABLE = yes # Audio control and System control |
| 20 | CONSOLE_ENABLE = yes # Console for debug(+400) | 20 | CONSOLE_ENABLE = yes # Console for debug |
| 21 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
| 22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
| 24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
| 25 | NKRO_ENABLE = yes # USB Nkey Rollover | 25 | NKRO_ENABLE = yes # USB Nkey Rollover |
| 26 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default | 26 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default |
| 27 | MIDI_ENABLE = no # MIDI controls | 27 | MIDI_ENABLE = no # MIDI controls |
| 28 | UNICODE_ENABLE = no # Unicode | 28 | UNICODE_ENABLE = no # Unicode |
| 29 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 29 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 30 | AUDIO_ENABLE = no # Audio output on port C6 | 30 | AUDIO_ENABLE = no # Audio output on port C6 |
| 31 | SPACE_CADET_ENABLE = no # Unneeded feature. | ||
| 32 | |||
| 33 | |||
| 34 | # special sauce for this keyboard | ||
| 35 | DEBOUNCE_TYPE = eager_pk # Debounce using eager_pk. | ||
| 36 | CUSTOM_MATRIX = lite # Custom matrix that polls at 7000hz instead of a measly 2000hz. | ||
| 37 | LTO_ENABLE = yes # smaller binary | ||
| 38 | SRC += matrix.c | ||
| 39 | |||
| 40 | # Also remember to open tmk's rules.mk and set compilation optimization to 3 | ||
diff --git a/keyboards/handwired/xealousbrown/xealousbrown.c b/keyboards/handwired/xealousbrown/xealousbrown.c index 5c8e2fb18..39def8ade 100644 --- a/keyboards/handwired/xealousbrown/xealousbrown.c +++ b/keyboards/handwired/xealousbrown/xealousbrown.c | |||
| @@ -6,3 +6,44 @@ void matrix_init_kb(void) { | |||
| 6 | 6 | ||
| 7 | matrix_init_user(); | 7 | matrix_init_user(); |
| 8 | } | 8 | } |
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | #ifdef BENCHMARK_MATRIX | ||
| 13 | # include "timer.h" | ||
| 14 | # include <stdint.h> | ||
| 15 | # include <stdbool.h> | ||
| 16 | # include "wait.h" | ||
| 17 | # include "util.h" | ||
| 18 | # include "matrix.h" | ||
| 19 | # include "quantum.h" | ||
| 20 | |||
| 21 | static int scans = 0; | ||
| 22 | static uint16_t last_print_out = 0; | ||
| 23 | static int last_timer = 0; | ||
| 24 | void matrix_scan_user(void) { | ||
| 25 | scans++; | ||
| 26 | uint16_t timer = timer_read(); | ||
| 27 | |||
| 28 | if (timer != last_timer && timer != last_timer + 1) { | ||
| 29 | print("MS:\n"); | ||
| 30 | print_dec(timer); | ||
| 31 | print("->"); | ||
| 32 | print_dec(last_timer); | ||
| 33 | print("\n"); | ||
| 34 | } | ||
| 35 | |||
| 36 | last_timer = timer; | ||
| 37 | if ((timer % 1000 == 0) && (timer != last_print_out)) { | ||
| 38 | print("Benchmark:"); | ||
| 39 | print("\n"); | ||
| 40 | print_dec(timer); | ||
| 41 | print("\n"); | ||
| 42 | print_dec(scans); | ||
| 43 | print("\n"); | ||
| 44 | print("-------"); | ||
| 45 | scans = 0; | ||
| 46 | last_print_out = timer; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | #endif | ||
