Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update to xealousbrown. #8215

Merged
merged 6 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion keyboards/handwired/xealousbrown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ https://sites.google.com/site/xaelous/keyboards/handwired-keyboard

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

make handwired/xealous-brown:default
make handwired/xealousbrown:default


The brief list of speedhacks to make this keyboard blazing fast:
1) bit-bash implementation of scanning rows, columns. Very short delay between pin waiting.
2) Compiling with a few extra flags
3) Eager-per-key Debouncing algorithm (no 5ms delay before message is sent)
4) 1000hz polling
5 changes: 4 additions & 1 deletion keyboards/handwired/xealousbrown/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* key matrix size */
#define MATRIX_ROWS 5
#define MATRIX_COLS 13

#define DEBOUNCE 10
#define USB_POLLING_INTERVAL_MS 1
/* layer optimization */
#define LAYER_STATE_8BIT
/*
* Keyboard Matrix Assignments
*
Expand Down
4 changes: 2 additions & 2 deletions keyboards/handwired/xealousbrown/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
[1] = LAYOUT( /* FN_Layer */
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_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,\
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, \
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,\
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, \
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,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL \
)
Expand Down
112 changes: 112 additions & 0 deletions keyboards/handwired/xealousbrown/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2019 Alex Ong

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

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

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdbool.h>
#include "wait.h"
#include "util.h"
#include "matrix.h"
#include "debounce.h"
#include "quantum.h"

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

// matrix code
// super fast read_cols code.
static matrix_row_t read_cols(void) {
return (PINC & (1 << 6) ? 0 : (1UL << 0)) |
(PIND & (1 << 7) ? 0 : (1UL << 1)) |
(PINE & (1 << 6) ? 0 : (1UL << 2)) |
(PINB & (1 << 4) ? 0 : (1UL << 3)) |
(PINB & (1 << 5) ? 0 : (1UL << 4)) |
(PINB & (1 << 6) ? 0 : (1UL << 5)) |
(PINB & (1 << 2) ? 0 : (1UL << 6)) |
(PINB & (1 << 3) ? 0 : (1UL << 7)) |
(PINB & (1 << 1) ? 0 : (1UL << 8)) |
(PINF & (1 << 7) ? 0 : (1UL << 9)) |
(PINF & (1 << 6) ? 0 : (1UL << 10)) |
(PINF & (1 << 5) ? 0 : (1UL << 11)) |
(PINF & (1 << 4) ? 0 : (1UL << 12));
}

static void unselect_rows(void) {
DDRD &= ~0b00011111;
PORTD &= ~0b00011111;
}

static void select_row(uint8_t row) {
switch (row) {
case 0:
DDRD |= (1 << 3);
PORTD &= ~(1 << 3);
break;
case 1:
DDRD |= (1 << 2);
PORTD &= ~(1 << 2);
break;
case 2:
DDRD |= (1 << 1);
PORTD &= ~(1 << 1);
break;
case 3:
DDRD |= (1 << 0);
PORTD &= ~(1 << 0);
break;
case 4:
DDRD |= (1 << 4);
PORTD &= ~(1 << 4);
break;
}
}

static void init_pins(void) {
DDRC &= ~(1 << 6);
PORTC |= (1 << 6);
DDRD &= ~(1 << 7);
PORTD |= (1 << 7);
DDRE &= ~(1 << 6);
PORTE |= (1 << 6);
DDRB &= ~(1 << 4 | 1 << 5 | 1 << 6 | 1 << 2 | 1 << 3 | 1 << 1);
PORTB |= (1 << 4 | 1 << 5 | 1 << 6 | 1 << 2 | 1 << 3 | 1 << 1);
DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4);
PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4);
}

// Only need to init the pins. Debounce / raw matrix are initialized already for us.
void matrix_init_custom(void) {
// initialize key pins
init_pins();
}

// Only need to scan the result into current_matrix, and return changed.
uint8_t matrix_scan_custom(matrix_row_t current_matrix[]) {
bool changed = false;

// Set row, read cols
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
select_row(current_row);
asm volatile("nop");
asm volatile("nop");
matrix_row_t cols = read_cols();
changed |= (current_matrix[current_row] != cols);
current_matrix[current_row] = cols;
unselect_rows();
}

return changed;
}
34 changes: 22 additions & 12 deletions keyboards/handwired/xealousbrown/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ BOOTLOADER = caterina
# Build Options
# change yes to no to disable
#
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
BOOTMAGIC_ENABLE = full # 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)
alex-ong marked this conversation as resolved.
Show resolved Hide resolved
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
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 controls
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
NKRO_ENABLE = yes # USB Nkey Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE = no # MIDI controls
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
SPACE_CADET_ENABLE = no # Unneeded feature.


# special sauce for this keyboard
DEBOUNCE_TYPE = eager_pk # Debounce using eager_pk.
CUSTOM_MATRIX = lite # Custom matrix that polls at 7000hz instead of a measly 2000hz.
LINK_TIME_OPTIMIZATION_ENABLE = yes # smaller binary
alex-ong marked this conversation as resolved.
Show resolved Hide resolved
SRC += matrix.c

# Also remember to open tmk's rules.mk and set compilation optimization to 3
41 changes: 41 additions & 0 deletions keyboards/handwired/xealousbrown/xealousbrown.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,44 @@ void matrix_init_kb(void) {

matrix_init_user();
}



#ifdef BENCHMARK_MATRIX
# include "timer.h"
# include <stdint.h>
# include <stdbool.h>
# include "wait.h"
# include "util.h"
# include "matrix.h"
# include "quantum.h"

static int scans = 0;
static uint16_t last_print_out = 0;
static int last_timer = 0;
void matrix_scan_user(void) {
scans++;
uint16_t timer = timer_read();

if (timer != last_timer && timer != last_timer + 1) {
print("MS:\n");
print_dec(timer);
print("->");
print_dec(last_timer);
print("\n");
}

last_timer = timer;
if ((timer % 1000 == 0) && (timer != last_print_out)) {
print("Benchmark:");
print("\n");
print_dec(timer);
print("\n");
print_dec(scans);
print("\n");
print("-------");
scans = 0;
last_print_out = timer;
}
}
#endif