aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/crkbd/rev1
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/crkbd/rev1')
-rw-r--r--keyboards/crkbd/rev1/config.h6
-rw-r--r--keyboards/crkbd/rev1/matrix.c5
-rw-r--r--keyboards/crkbd/rev1/rev1.c104
-rw-r--r--keyboards/crkbd/rev1/rev1.h26
-rw-r--r--keyboards/crkbd/rev1/rules.mk12
-rw-r--r--keyboards/crkbd/rev1/split_util.c82
6 files changed, 128 insertions, 107 deletions
diff --git a/keyboards/crkbd/rev1/config.h b/keyboards/crkbd/rev1/config.h
index 4ea8ff38c..f7f278f2c 100644
--- a/keyboards/crkbd/rev1/config.h
+++ b/keyboards/crkbd/rev1/config.h
@@ -23,17 +23,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT_ID 0x3060
#define DEVICE_VER 0x0001
#define MANUFACTURER foostan
-#define PRODUCT Crkbd
+#define PRODUCT Corne Keyboard (crkbd)
#define DESCRIPTION A split keyboard with 3x6 vertically staggered keys and 3 thumb keys
/* key matrix size */
// Rows are doubled-up
#define MATRIX_ROWS 8
-#define MATRIX_COLS 7
+#define MATRIX_COLS 6
#define MATRIX_ROW_PINS { D4, C6, D7, E6 }
// wiring of each half
-#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3, B2 }
+#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 }
// #define MATRIX_COL_PINS { B2, B3, B1, F7, F6, F5, F4 } //uncomment this line and comment line above if you need to reverse left-to-right key order
/* define if matrix has ghost */
diff --git a/keyboards/crkbd/rev1/matrix.c b/keyboards/crkbd/rev1/matrix.c
index dd93506db..9d86879d6 100644
--- a/keyboards/crkbd/rev1/matrix.c
+++ b/keyboards/crkbd/rev1/matrix.c
@@ -133,9 +133,8 @@ void rx_led_off(void)
void matrix_init(void)
{
- debug_enable = true;
- debug_matrix = true;
- debug_mouse = true;
+ split_keyboard_setup();
+
// initialize row and col
unselect_rows();
init_cols();
diff --git a/keyboards/crkbd/rev1/rev1.c b/keyboards/crkbd/rev1/rev1.c
index b969b5e28..b26292af5 100644
--- a/keyboards/crkbd/rev1/rev1.c
+++ b/keyboards/crkbd/rev1/rev1.c
@@ -1,11 +1,5 @@
#include "crkbd.h"
-
-#ifdef AUDIO_ENABLE
- float tone_startup[][2] = SONG(STARTUP_SOUND);
- float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
-#endif
-
#ifdef RGB_MATRIX_ENABLE
// Logical Layout
@@ -44,46 +38,15 @@
// 05 06 06 05
// 15 14 07 07 14 15 3
-
-#ifdef RGB_MATRIX_SPLIT_RIGHT
-led_config_t g_led_config = { {
- { 51, 50, 45, 44, 37, 36, NO_LED },
- { 52, 49, 46, 43, 38, 35, NO_LED },
- { 53, 48, 47, 42, 39, 34, NO_LED },
- { NO_LED, NO_LED, NO_LED, 41, 40, 33, NO_LED },
- { 24, 23, 18, 17, 10, 9, NO_LED },
- { 25, 22, 19, 16, 11, 8, NO_LED },
- { 26, 21, 20, 15, 12, 7, NO_LED },
- { NO_LED, NO_LED, NO_LED, 14, 13, 6, NO_LED }
-}, {
- { 139, 16 }, { 174, 13 }, { 208, 20 }, { 208, 38 }, { 174, 48 }, { 139, 52 }, { 129, 63 },
- { 139, 39 }, { 139, 21 }, { 139, 4 }, { 156, 2 }, { 156, 19 }, { 156, 37 }, { 144, 58 },
- { 164, 55 }, { 174, 35 }, { 174, 13 }, { 174, 0 }, { 191, 3 }, { 191, 20 }, { 191, 37 },
- { 208, 42 }, { 208, 24 }, { 208, 7 }, { 224, 7 }, { 224, 24 }, { 224, 41 }, { 85, 16 },
- { 50, 13 }, { 16, 20 }, { 16, 38 }, { 50, 48 }, { 85, 52 }, { 95, 63 }, { 85, 39 },
- { 85, 21 }, { 85, 4 }, { 68, 2 }, { 68, 19 }, { 68, 37 }, { 80, 58 }, { 60, 55 },
- { 50, 35 }, { 50, 13 }, { 50, 0 }, { 33, 3 }, { 33, 20 }, { 33, 37 }, { 16, 42 },
- { 16, 24 }, { 16, 7 }, { 0, 7 }, { 0, 24 }, { 0, 41 }
-}, {
- 2, 2, 2, 2, 2, 2, 1,
- 4, 4, 4, 4, 4, 4, 1,
- 1, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 1, 1, 1, 2,
- 2, 2, 2, 2, 2, 1, 4,
- 4, 4, 4, 4, 4, 1, 1,
- 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 1, 1, 1
-} };
-#else
led_config_t g_led_config = { {
- { 24, 23, 18, 17, 10, 9, NO_LED },
- { 25, 22, 19, 16, 11, 8, NO_LED },
- { 26, 21, 20, 15, 12, 7, NO_LED },
- { NO_LED, NO_LED, NO_LED, 14, 13, 6, NO_LED },
- { 51, 50, 45, 44, 37, 36, NO_LED },
- { 52, 49, 46, 43, 38, 35, NO_LED },
- { 53, 48, 47, 42, 39, 34, NO_LED },
- { NO_LED, NO_LED, NO_LED, 41, 40, 33, NO_LED }
+ { 24, 23, 18, 17, 10, 9 },
+ { 25, 22, 19, 16, 11, 8 },
+ { 26, 21, 20, 15, 12, 7 },
+ { NO_LED, NO_LED, NO_LED, 14, 13, 6 },
+ { 51, 50, 45, 44, 37, 36 },
+ { 52, 49, 46, 43, 38, 35 },
+ { 53, 48, 47, 42, 39, 34 },
+ { NO_LED, NO_LED, NO_LED, 41, 40, 33 }
}, {
{ 85, 16 }, { 50, 13 }, { 16, 20 }, { 16, 38 }, { 50, 48 }, { 85, 52 }, { 95, 63 },
{ 85, 39 }, { 85, 21 }, { 85, 4 }, { 68, 2 }, { 68, 19 }, { 68, 37 }, { 80, 58 },
@@ -105,21 +68,42 @@ led_config_t g_led_config = { {
} };
#endif
-#endif
-void matrix_init_kb(void) {
-
- #ifdef AUDIO_ENABLE
- _delay_ms(20); // gets rid of tick
- PLAY_SONG(tone_startup);
- #endif
+__attribute__((weak))
+void matrix_init_user(void) {}
- matrix_init_user();
-};
+void matrix_init_kb(void) {
-void shutdown_kb(void) {
- #ifdef AUDIO_ENABLE
- PLAY_SONG(tone_goodbye);
- _delay_ms(150);
- stop_all_notes();
- #endif
+#ifdef RGB_MATRIX_ENABLE
+ if (!isLeftHand) {
+ g_led_config = (led_config_t){ {
+ { 51, 50, 45, 44, 37, 36 },
+ { 52, 49, 46, 43, 38, 35 },
+ { 53, 48, 47, 42, 39, 34 },
+ { NO_LED, NO_LED, NO_LED, 41, 40, 33 },
+ { 24, 23, 18, 17, 10, 9 },
+ { 25, 22, 19, 16, 11, 8 },
+ { 26, 21, 20, 15, 12, 7 },
+ { NO_LED, NO_LED, NO_LED, 14, 13, 6 }
+ }, {
+ { 139, 16 }, { 174, 13 }, { 208, 20 }, { 208, 38 }, { 174, 48 }, { 139, 52 }, { 129, 63 },
+ { 139, 39 }, { 139, 21 }, { 139, 4 }, { 156, 2 }, { 156, 19 }, { 156, 37 }, { 144, 58 },
+ { 164, 55 }, { 174, 35 }, { 174, 13 }, { 174, 0 }, { 191, 3 }, { 191, 20 }, { 191, 37 },
+ { 208, 42 }, { 208, 24 }, { 208, 7 }, { 224, 7 }, { 224, 24 }, { 224, 41 }, { 85, 16 },
+ { 50, 13 }, { 16, 20 }, { 16, 38 }, { 50, 48 }, { 85, 52 }, { 95, 63 }, { 85, 39 },
+ { 85, 21 }, { 85, 4 }, { 68, 2 }, { 68, 19 }, { 68, 37 }, { 80, 58 }, { 60, 55 },
+ { 50, 35 }, { 50, 13 }, { 50, 0 }, { 33, 3 }, { 33, 20 }, { 33, 37 }, { 16, 42 },
+ { 16, 24 }, { 16, 7 }, { 0, 7 }, { 0, 24 }, { 0, 41 }
+ }, {
+ 2, 2, 2, 2, 2, 2, 1,
+ 4, 4, 4, 4, 4, 4, 1,
+ 1, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 1, 1, 1, 2,
+ 2, 2, 2, 2, 2, 1, 4,
+ 4, 4, 4, 4, 4, 1, 1,
+ 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 1, 1, 1
+ } };
+ }
+#endif
+ matrix_init_user();
}
diff --git a/keyboards/crkbd/rev1/rev1.h b/keyboards/crkbd/rev1/rev1.h
index cdd61d2bf..5e90de72a 100644
--- a/keyboards/crkbd/rev1/rev1.h
+++ b/keyboards/crkbd/rev1/rev1.h
@@ -1,24 +1,27 @@
#pragma once
-#include "../crkbd.h"
+#include "crkbd.h"
-//void promicro_bootloader_jmp(bool program);
#include "quantum.h"
-#ifdef RGBLIGHT_ENABLE
-//rgb led driver
-#include "ws2812.h"
+#ifdef PROTOCOL_LUFA
+ #include "lufa.h"
+ #include "split_util.h"
#endif
-#ifdef USE_I2C
-#include <stddef.h>
-#ifdef __AVR__
- #include <avr/io.h>
- #include <avr/interrupt.h>
+#ifdef SSD1306OLED
+ #include "ssd1306.h"
#endif
+
+#ifdef USE_I2C
+ #include <stddef.h>
+ #ifdef __AVR__
+ #include <avr/interrupt.h>
+ #include <avr/io.h>
+ #endif
#endif
-//void promicro_bootloader_jmp(bool program);
+// clang-format off
#define LAYOUT( \
L00, L01, L02, L03, L04, L05, R00, R01, R02, R03, R04, R05, \
L10, L11, L12, L13, L14, L15, R10, R11, R12, R13, R14, R15, \
@@ -48,3 +51,4 @@
KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##R20, KC_##R21, KC_##R22, KC_##R23, KC_##R24, KC_##R25, \
KC_##L30, KC_##L31, KC_##L32, KC_##R30, KC_##R31, KC_##R32 \
)
+// clang-format on
diff --git a/keyboards/crkbd/rev1/rules.mk b/keyboards/crkbd/rev1/rules.mk
index f12849f98..ab9bed09c 100644
--- a/keyboards/crkbd/rev1/rules.mk
+++ b/keyboards/crkbd/rev1/rules.mk
@@ -1,9 +1,3 @@
-RGB_MATRIX_SPLIT_RIGHT = no # if no, order LEDs for left hand, if yes, order LEDs for right hand
-
-ifeq ($(strip $(RGB_MATRIX_SPLIT_RIGHT)), yes)
- OPT_DEFS += -DRGB_MATRIX_SPLIT_RIGHT
-endif
-
-SRC += rev1/matrix.c
-SRC += rev1/split_util.c
-SRC += rev1/split_scomm.c
+SRC += matrix.c \
+ split_util.c \
+ split_scomm.c
diff --git a/keyboards/crkbd/rev1/split_util.c b/keyboards/crkbd/rev1/split_util.c
index e1ff8b437..c0d44af29 100644
--- a/keyboards/crkbd/rev1/split_util.c
+++ b/keyboards/crkbd/rev1/split_util.c
@@ -7,6 +7,11 @@
#include "split_util.h"
#include "matrix.h"
#include "keyboard.h"
+#include "wait.h"
+
+#ifdef EE_HANDS
+# include "eeconfig.h"
+#endif
#ifdef USE_MATRIX_I2C
# include "i2c.h"
@@ -14,19 +19,59 @@
# include "split_scomm.h"
#endif
+#ifndef SPLIT_USB_TIMEOUT
+# define SPLIT_USB_TIMEOUT 2500
+#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
+bool waitForUsb(void) {
+ for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) {
+ // This will return true of a USB connection has been established
+ if (UDADDR & _BV(ADDEN)) {
+ return true;
+ }
+ wait_ms(100);
+ }
+
+ // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
+ (USBCON &= ~(_BV(USBE) | _BV(OTGPADE)));
+
+ return false;
+}
+
+__attribute__((weak)) bool is_keyboard_left(void) {
+#if defined(SPLIT_HAND_PIN)
+ // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
+ setPinInput(SPLIT_HAND_PIN);
+ return readPin(SPLIT_HAND_PIN);
+#elif defined(EE_HANDS)
+ return eeconfig_read_handedness();
+#elif defined(MASTER_RIGHT)
+ return !is_keyboard_master();
+#endif
+
+ return is_keyboard_master();
+}
+
+__attribute__((weak)) bool is_keyboard_master(void) {
+ static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
+
+ // only check once, as this is called often
+ if (usbstate == UNKNOWN) {
+#if defined(SPLIT_USB_DETECT)
+ usbstate = waitForUsb() ? MASTER : SLAVE;
+#elif defined(__AVR__)
+ USBCON |= (1 << OTGPADE); // enables VBUS pad
+ wait_us(5);
+
+ usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
+#else
+ usbstate = MASTER;
+#endif
+ }
+
+ return (usbstate == MASTER);
}
static void keyboard_master_setup(void) {
@@ -47,14 +92,9 @@ static void keyboard_slave_setup(void) {
#endif
}
-bool has_usb(void) {
- USBCON |= (1 << OTGPADE); //enables VBUS pad
- _delay_us(5);
- return (USBSTA & (1<<VBUS)); //checks state of VBUS
-}
-
+// this code runs before the usb and keyboard is initialized
void split_keyboard_setup(void) {
- setup_handedness();
+ isLeftHand = is_keyboard_left();
if (has_usb()) {
keyboard_master_setup();
@@ -64,7 +104,7 @@ void split_keyboard_setup(void) {
sei();
}
-// this code runs before the usb and keyboard is initialized
-void matrix_setup(void) {
- split_keyboard_setup();
+// backwards compat
+bool has_usb(void) {
+ return is_keyboard_master();
}