[Keyboard] Sol keyboard conversion to split common (#5773)

* Split common conversion

* Updated serial and encoder pins

* Fixing default folder until r2

* Fixing oled driver on slave split common

* Fixing keymap compile errors

* Fixing oled inactivity timer on slave split common

* Hoisted oled driver task, init, & activity to keyboard.c

* Update keyboards/sol/config.h

Co-Authored-By: XScorpion2 <rcalt2vt@gmail.com>

* Remove TAPPING_FORCE_HOLD
This commit is contained in:
XScorpion2 2019-05-06 17:06:43 -05:00 committed by Drashna Jaelre
parent 99500243e1
commit e01b2d518a
27 changed files with 250 additions and 1062 deletions

View File

@ -1,71 +0,0 @@
#include "knob_v2.h"
bool knob_prev_a = false;
static knob_report_t knob_report = {.dir = 0, .phase = 0};
void knob_init(void) {
// I use pins D1 (ISR1) & D4 for a knob.
// Set pin mode for D4 as input.
DDRD &= ~(0UL << ENCODER_PIN_2);
// Enable internal pull-up for D4.
// This is done by "writing" 1 to a pin that has its mode set to input.
PORTD |= (1 << ENCODER_PIN_2);
// Enable interrupt for D1
// For more info on the below flags see this awesome section 11.1 (pages 89-90) here:
// https://cdn-shop.adafruit.com/datasheets/atmel-7766-8-bit-avr-atmega16u4-32u4_datasheet.pdf
// Set pin mode & pull-up.
DDRD &= ~(0UL << ENCODER_PIN_1);
PORTD |= (1UL << ENCODER_PIN_1);
// INT: 33221100
EICRA |= 0b00010000; // 0b01 - any edge
// INT: 6 3210
EIMSK |= 0b00000100;
}
ISR(ENCODER_INT) {
bool a = PIND & (1 << ENCODER_PIN_1);
if (knob_prev_a != a) {
// "A" channel has REALLY changed.
knob_report.phase = a;
knob_prev_a = a;
bool b = PIND & (1 << ENCODER_PIN_2);
if (a == b) {
// Halfway through CCW rotation (A == B)
//
// +---YOU ARE HERE (A=1, B=1)
// | +---OR HERE (A=0, B=0)
// | |
// v v
// A: _____/^^^^^\__
// B: __/^^^^^\_____
knob_report.dir++;
} else {
// Halfway through CW rotation (A != B)
//
// +---YOU ARE HERE (A=1, B=0)
// | +---OR HERE (A=0, B=1)
// | |
// v v
// A: _____/^^^^^\_____
// B: ________/^^^^^\__
knob_report.dir--;
}
}
}
knob_report_t knob_report_read(void) {
// Return knob report.
return knob_report;
}
void knob_report_reset(void) {
// Call this ASAP once you've processed the previous knob report.
// TODO: This should probably be called within `knob_report_read`.
knob_report.dir = 0;
knob_report.phase = 0;
}

View File

@ -1,28 +0,0 @@
// Rotary knob implementation - Version 2.
// Uses 2 digital pins - D2 (via interrupt) & D6.
// #include "rev1.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#ifndef ENCODER_PIN_1
#define ENCODER_PIN_1 PD2
#endif
#ifndef ENCODER_PIN_2
#define ENCODER_PIN_2 PD6
#endif
#ifndef ENCODER_INT
#define ENCODER_INT INT2_vect
#endif
typedef struct knob_report_t {
int8_t dir; // Contains number of rotations that happened
int8_t phase; // Contains 0 if last rotation happened on 90 degrees, 1 if on 270
} knob_report_t;
void knob_init(void);
knob_report_t knob_report_read(void);
void knob_report_reset(void);
bool knob_prev_a;
int8_t knob_dir;

View File

@ -20,3 +20,73 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config_common.h"
#define TAPPING_TERM 150
/* Select hand configuration */
#define SOFT_SERIAL_PIN D3
#define EE_HANDS
/* key matrix size */
// Rows are doubled-up
#define MATRIX_ROWS 12
#define MATRIX_ROW_PINS { C6, B6, B5, B4, D7, E6}
// wiring of each half
#define MATRIX_COLS 7
#define MATRIX_COL_PINS { F0, F1, F4, F5, F6, F7, C7 }
// Encoder support
#define NUMBER_OF_ENCODERS 1
#define ENCODERS_PAD_A { D2 }
#define ENCODERS_PAD_B { D6 }
/* Set 0 if debouncing isn't needed */
#define DEBOUNCING_DELAY 5
/* ws2812 RGB LED */
#define RGB_DI_PIN B3
#ifdef IOS_DEVICE_ENABLE
#define RGBLIGHT_LIMIT_VAL 40
#elif RGBLIGHT_FULL_POWER
#define RGBLIGHT_LIMIT_VAL 255
#else
#define RGBLIGHT_LIMIT_VAL 120
#endif
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS RGBLIGHT_LIMIT_VAL
#define LED_HITS_TO_REMEMBER 5
#define RGBLIGHT_ANIMATIONS
#if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE)
// USB_MAX_POWER_CONSUMPTION value for Helix keyboard
// 120 RGBoff, OLEDoff
// 120 OLED
// 330 RGB 6
// 300 RGB 32
// 310 OLED & RGB 32
#define USB_MAX_POWER_CONSUMPTION 500
#else
// fix iPhone and iPad power adapter issue
// iOS device need lessthan 100
#define USB_MAX_POWER_CONSUMPTION 100
#endif
/*
* 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

View File

@ -11,8 +11,6 @@ extern keymap_config_t keymap_config;
extern rgblight_config_t rgblight_config;
#endif
extern uint8_t is_master;
// 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
@ -59,8 +57,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
LCTL, LALT, FN, LGUI, RGB_MOD, SPC, DEL, BSPC, SPC, ADJ, LGUI, FN, LALT, LCTL,
//|--------+--------+--------+--------+--------+--+--------+--------| |--------+--+--------+--------+--------+--------+--------+--------|
VOLD, VOLU, SPC, ENT, ENT, SPC, DOWN, UP
// Rotary Left |--------+--------| |--------+-----------+ Rotary Right
SPC, ENT, ENT, SPC
// |--------+--------| |--------+-----------+
),
/* FN
@ -90,8 +88,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--+--------+--------| |--------+--+--------+--------+--------+--------+--------+--------|
VOLD, VOLU, _______, _______, _______, _______, UP, DOWN
// Rotary Left |--------+--------| |--------+-----------+ Rotary Right
_______, _______, _______, _______
// |--------+--------| |--------+-----------+
),
/* ADJ
@ -122,8 +120,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
//|--------+--------+--------+--------+--------+--+--------+--------| |--------+--------+--+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______ \
// Rotary Left |--------+--------| |--------+--------+ Rotary Right
_______, _______, _______, _______ \
// |--------+--------| |--------+--------+
)
};
@ -132,6 +130,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
bool TOG_STATUS = false;
int RGB_current_mode;
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
} else if (index == 1) { /* Second encoder*/
if (clockwise) {
tap_code(KC_UP);
} else {
tap_code(KC_DOWN);
}
}
}
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
@ -182,7 +198,7 @@ void matrix_init_user(void) {
#ifdef OLED_DRIVER_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!has_usb())
if (!is_keyboard_master())
return OLED_ROTATION_180; // flip 180 for offhand
return rotation;
}
@ -244,7 +260,7 @@ static void render_status(void) {
}
void oled_task_user(void) {
if (is_master)
if (is_keyboard_master())
render_status();
else
render_logo();

View File

@ -17,18 +17,12 @@ RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy
RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
UNICODE_ENABLE = no # Unicode
SWAP_HANDS_ENABLE = no # Enable one-hand typing
ENCODER_ENABLE_CUSTOM = yes # Enable rotary encoder (+90)
OLED_DRIVER_ENABLE = yes # Enable the OLED Driver (+5000)
IOS_DEVICE_ENABLE = no # Limit max brightness to connect to IOS device (iPad,iPhone)
# Do not edit past here
ifeq ($(strip $(ENCODER_ENABLE_CUSTOM)), yes)
OPT_DEFS += -DENCODER_ENABLE_CUSTOM
SRC += common/knob_v2.c
endif
ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes)
OPT_DEFS += -DIOS_DEVICE_ENABLE
else ifeq ($(strip $(RGBLIGHT_FULL_POWER)), yes)

View File

@ -11,8 +11,6 @@ extern keymap_config_t keymap_config;
extern rgblight_config_t rgblight_config;
#endif
extern uint8_t is_master;
// 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
@ -64,7 +62,7 @@ LAYOUT( \
KC_CAPS, _10, _11, _12, _13, _14, KC_LCBR, KC_RCBR, _15, _16, _17, _18, _19, KC_QUOT, \
KC_LSFT, _20, _21, _22, _23, _24, KC_GRV, KC_BSLS, _25, _26, _27, _28, _29, KC_RSFT, \
KC_LEFT, KC_DOWN, KC_LCTRL, KC_LALT, KC_LGUI, KC_BSPC, FN, ADJ, KC_SPC, KC_RGUI, KC_RALT, KC_RCTRL, KC_UP, KC_RIGHT, \
KC_VOLU, KC_VOLD, KC_BSPC, FN, ADJ, KC_SPC, KC_VOLU, KC_VOLD \
KC_BSPC, FN, ADJ, KC_SPC \
)
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
@ -132,7 +130,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_END, \
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MPLY, KC_MUTE, KC_VOLD, KC_VOLU, KC_MRWD, KC_MFFD, \
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX \
XXXXXXX, _______, XXXXXXX, XXXXXXX \
),
/* ADJ
@ -157,7 +155,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX, RGB_SAD, RGB_VAI, RGB_SAI, XXXXXXX, XXXXXXX, COLEMAK, XXXXXXX, KC_P4, KC_P5, KC_P6, KC_PENT, XXXXXXX, XXXXXXX, \
XXXXXXX, RGB_HUD, RGB_VAD, RGB_HUI, XXXXXXX, XXXXXXX, QWERTY, XXXXXXX, KC_P1, KC_P2, KC_P3, KC_SPC, XXXXXXX, XXXXXXX, \
XXXXXXX, RGBRST, RGB_TOG, RGB_MOD, RGB_RMOD, XXXXXXX, XXXXXXX, _______, XXXXXXX, KC_P0, KC_PDOT, KC_BSPC, XXXXXXX, XXXXXXX, \
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX \
XXXXXXX, XXXXXXX, _______, XXXXXXX \
)
};
@ -165,6 +163,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
bool TOG_STATUS = false;
int RGB_current_mode;
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
} else if (index == 1) { /* Second encoder*/
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
}
#endif
// Setting ADJ layer RGB back to default
void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
@ -308,7 +324,7 @@ static void render_status(void) {
}
void oled_task_user(void) {
if (is_master)
if (is_keyboard_master())
render_status();
else
render_logo();

View File

@ -17,18 +17,12 @@ RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy
RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
UNICODE_ENABLE = no # Unicode
SWAP_HANDS_ENABLE = no # Enable one-hand typing
ENCODER_ENABLE_CUSTOM = yes # Enable rotary encoder (+90)
OLED_DRIVER_ENABLE = no # Enable the OLED Driver (+5000)
IOS_DEVICE_ENABLE = no # Limit max brightness to connect to IOS device (iPad,iPhone)
# Do not edit past here
ifeq ($(strip $(ENCODER_ENABLE_CUSTOM)), yes)
OPT_DEFS += -DENCODER_ENABLE_CUSTOM
SRC += common/knob_v2.c
endif
ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes)
OPT_DEFS += -DIOS_DEVICE_ENABLE
else ifeq ($(strip $(RGBLIGHT_FULL_POWER)), yes)

View File

@ -12,8 +12,6 @@ extern keymap_config_t keymap_config;
extern rgblight_config_t rgblight_config;
#endif
extern uint8_t is_master;
// 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
@ -70,7 +68,7 @@ LAYOUT( \
FN_CAPS, _10, _11, _12, _13, _14, KC_LPRN, KC_RPRN, _15, _16, _17, _18, _19, KC_QUOT, \
KC_LSFT, _20, _21, _22, _23, _24, KC_LCBR, KC_RCBR, _25, _26, _27, _28, _29, KC_ENT, \
KC_LCTL, KC_LGUI, KC_LALT, RGB_TOG, ADJ, KC_SPC, KC_DEL, KC_ENT, KC_SPC, FN, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, \
KC_VOLU, KC_VOLD, KC_SPC, KC_DEL, KC_ENT, KC_SPC, KC_VOLU, KC_VOLD \
KC_SPC, KC_DEL, KC_ENT, KC_SPC \
)
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
@ -138,7 +136,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_END, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, \
KC_VOLU, KC_VOLD, _______, _______, _______, _______, KC_VOLU, KC_VOLD \
_______, _______, _______, _______ \
),
/* ADJ
@ -163,7 +161,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, RGB_HUD, RGB_VAD, RGB_HUI, RGBRST, _______, _______, _______, _______, QWERTY, COLEMAK, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
_______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, _______, RGB_RMOD,RGB_HUD, RGB_SAD, RGB_VAD, \
KC_VOLU, KC_VOLD, _______, _______, _______, _______, KC_VOLU, KC_VOLD \
_______, _______, _______, _______ \
)
};
@ -173,6 +171,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
bool TOG_STATUS = false;
int RGB_current_mode;
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
} else if (index == 1) { /* Second encoder*/
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
}
#endif
// Setting ADJ layer RGB back to default
void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
@ -316,7 +332,7 @@ static void render_status(void) {
}
void oled_task_user(void) {
if (is_master)
if (is_keyboard_master())
render_status();
else
render_logo();

View File

@ -17,18 +17,12 @@ RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy
RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
UNICODE_ENABLE = no # Unicode
SWAP_HANDS_ENABLE = no # Enable one-hand typing
ENCODER_ENABLE_CUSTOM = yes # Enable rotary encoder (+90)
OLED_DRIVER_ENABLE = no # Enable the OLED Driver (+5000)
IOS_DEVICE_ENABLE = no # Limit max brightness to connect to IOS device (iPad,iPhone)
# Do not edit past here
ifeq ($(strip $(ENCODER_ENABLE_CUSTOM)), yes)
OPT_DEFS += -DENCODER_ENABLE_CUSTOM
SRC += common/knob_v2.c
endif
ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes)
OPT_DEFS += -DIOS_DEVICE_ENABLE
else ifeq ($(strip $(RGBLIGHT_FULL_POWER)), yes)

View File

@ -35,7 +35,7 @@ EXPAND_LAYOUT( \
FN_ESC, _10, _11, _12, _13, _14, RGB_SAI, RGB_VAI, _15, _16, _17, _18, _19, KC_QUOT, \
KC_LSPO, _20, _21, _22, _23, _24, RGB_SAD, RGB_VAD, _25, _26, _27, _28, _29, KC_RSPC, \
KC_LCTL, KC_LGUI, KC_LGUI, KC_LALT, FN, KC_SPC, FN, FN, KC_SPC, KC_MINS, KC_EQL, KC_DOWN, KC_PGUP, KC_PGDN, \
KC_VOLD, KC_VOLU, KC_SPC, KC_BSPC, KC_ENT, KC_SPC, KC_VOLD, KC_VOLU \
KC_SPC, KC_BSPC, KC_ENT, KC_SPC \
)
#define BASE_LAYOUT(...) _BASE_LAYOUT(__VA_ARGS__)
@ -65,15 +65,33 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
________________FUNCTION_L3________________, _______, _______, ________________FUNCTION_R3________________, \
________________FUNCTION_L4________________, _______, _______, ________________FUNCTION_R4________________, \
________________FUNCTION_L5________________, ADJ, ADJ, ________________FUNCTION_R5________________, \
KC_VOLD, KC_VOLU, _______, KC_DEL, _______, _______, KC_VOLD, KC_VOLU \
_______, KC_DEL, _______, _______ \
),
[_ADJ] = EXPAND_LAYOUT( \
[_ADJ] = EXPAND_LAYOUT( \
_________________ADJUST_L1_________________, _______, _______, _________________ADJUST_R1_________________, \
_________________ADJUST_L2_________________, _______, _______, _________________ADJUST_R2_________________, \
_________________ADJUST_L3_________________, _______, _______, _________________ADJUST_R3_________________, \
_________________ADJUST_L4_________________, _______, _______, _________________ADJUST_R4_________________, \
_________________ADJUST_L5_________________, _______, _______, _________________ADJUST_R5_________________, \
KC_VOLD, KC_VOLU, _______, _______, _______, _______, KC_VOLD, KC_VOLU \
_______, _______, _______, _______ \
)
};
#ifdef ENCODER_ENABLE
void encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
} else if (index == 1) { /* Second encoder*/
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
}
#endif

View File

@ -17,18 +17,12 @@ RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy
RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
UNICODE_ENABLE = no # Unicode
SWAP_HANDS_ENABLE = no # Enable one-hand typing
ENCODER_ENABLE_CUSTOM = yes # Enable rotary encoder (+90)
OLED_DRIVER_ENABLE = no # Enable the OLED Driver (+5000)
IOS_DEVICE_ENABLE = no # Limit max brightness to connect to IOS device (iPad,iPhone)
# Do not edit past here
ifeq ($(strip $(ENCODER_ENABLE_CUSTOM)), yes)
OPT_DEFS += -DENCODER_ENABLE_CUSTOM
SRC += common/knob_v2.c
endif
ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes)
OPT_DEFS += -DIOS_DEVICE_ENABLE
else ifeq ($(strip $(RGBLIGHT_FULL_POWER)), yes)

View File

@ -36,7 +36,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_________________QWERTY_L3_________________, KC_GRV, KC_QUOT, _________________QWERTY_R3_________________, \
_________________QWERTY_L4_________________, RGB_TOG, RGBRST, _________________QWERTY_R4_________________, \
_________________QWERTY_L5_________________, RGB_RMOD, RGB_MOD, _________________QWERTY_R5_________________, \
KC_VOLU, KC_VOLD, KC_SPC, KC_DEL, KC_ENT, KC_SPC, KC_VOLU, KC_VOLD \
KC_SPC, KC_DEL, KC_ENT, KC_SPC \
),
#ifndef GAMELAYER_DISABLE
@ -46,7 +46,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
___________________GAME_L3_________________, KC_GRV, KC_QUOT, ___________________GAME_R3_________________, \
___________________GAME_L4_________________, RGB_TOG, RGBRST, ___________________GAME_R4_________________, \
___________________GAME_L5_________________, RGB_RMOD, RGB_MOD, ___________________GAME_R5_________________, \
KC_VOLU, KC_VOLD, KC_SPC, KC_DEL, KC_ENT, KC_SPC, KC_VOLU, KC_VOLD \
KC_SPC, KC_DEL, KC_ENT, KC_SPC \
),
#endif
@ -56,7 +56,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
__________________LOWER_L3_________________, _______, _______, __________________LOWER_R3_________________, \
__________________LOWER_L4_________________, _______, _______, __________________LOWER_R4_________________, \
__________________LOWER_L5_________________, _______, _______, __________________LOWER_R5_________________, \
_______, _______, _______, _______, _______, _______, _______, _______ \
_______, _______, _______, _______ \
),
[_RAISE] = EXPAND_LAYOUT( \
@ -65,7 +65,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
__________________RAISE_L3_________________, _______, _______, __________________RAISE_R3_________________, \
__________________RAISE_L4_________________, _______, _______, __________________RAISE_R4_________________, \
__________________RAISE_L5_________________, _______, _______, __________________RAISE_R5_________________, \
_______, _______, _______, _______, _______, _______, _______, _______ \
_______, _______, _______, _______ \
),
#ifdef TRILAYER_ENABLED
@ -75,7 +75,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_________________ADJUST_L3_________________, _______, _______, _________________ADJUST_R3_________________, \
_________________ADJUST_L4_________________, _______, _______, _________________ADJUST_R4_________________, \
_________________ADJUST_L5_________________, _______, _______, _________________ADJUST_R5_________________, \
_______, _______, _______, _______, _______, _______, _______, _______ \
_______, _______, _______, _______ \
),
#endif
};
@ -158,7 +158,7 @@ static void render_status(void) {
}
void oled_task_user(void) {
if (has_usb()) {
if (is_keyboard_master()) {
render_status();
} else {
render_logo();

View File

@ -16,17 +16,12 @@ RGB_MATRIX_KEYPRESSES = yes # Enable reactive per-key effects. Can be very l
RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
UNICODE_ENABLE = no # Unicode
SWAP_HANDS_ENABLE = no # Enable one-hand typing
ENCODER_ENABLE_CUSTOM = no # Enable rotary encoder (+90)
OLED_DRIVER_ENABLE = yes # Enable the OLED Driver (+5000)
ENCODER_ENABLE = no # Enable rotary encoder (+90)
IOS_DEVICE_ENABLE = no # Limit max brightness to connect to IOS device (iPad,iPhone)
# Do not edit past here
ifeq ($(strip $(ENCODER_ENABLE_CUSTOM)), yes)
OPT_DEFS += -DENCODER_ENABLE_CUSTOM
SRC += common/knob_v2.c
endif
ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes)
OPT_DEFS += -DIOS_DEVICE_ENABLE
else ifeq ($(strip $(RGBLIGHT_FULL_POWER)), yes)

View File

@ -16,8 +16,7 @@ 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
#pragma once
/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
@ -27,117 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT Sol
#define DESCRIPTION "An RGB, split, ortho-esque keyboard"
#define PREVENT_STUCK_MODIFIERS
#define TAPPING_FORCE_HOLD
#define TAPPING_TERM 150
#define USE_I2C
#define USE_SERIAL
#define USE_SERIAL_PD3
/* Select hand configuration */
#define MASTER_LEFT
// #define MASTER_RIGHT
// #define EE_HANDS
/* Select rows configuration */
// Rows are 4 or 5
// #define HELIX_ROWS 5 see ./rules.mk
/* key matrix size */
// Rows are doubled-up
#define MATRIX_ROWS 12
#define MATRIX_ROW_PINS { C6, B6, B5, B4, D7, E6}
// wiring of each half
#define MATRIX_COLS 7
#define MATRIX_COL_PINS { F0, F1, F4, F5, F6, F7, C7 }
// #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 */
//#define MATRIX_HAS_GHOST
/* number of backlight levels */
// #define BACKLIGHT_LEVELS 3
/* Set 0 if debouncing isn't needed */
#define DEBOUNCING_DELAY 5
/* 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
/* ws2812 RGB LED */
#define RGB_DI_PIN B3
#define RGBLIGHT_TIMER
//#define RGBLED_NUM 12 // Number of LEDs. see ./keymaps/default/config.h
#define ws2812_PORTREG PORTD
#define ws2812_DDRREG DDRD
#define DRIVER_COUNT 1
// #define RGB_MATRIX_KEYPRESSES
#define BACKLIGHT_PIN B7
#define BACKLIGHT_LEVELS 5
#ifdef LED_MIRRORED
#define RGBLED_NUM 35
#else
#define RGBLED_NUM 70
#endif
#define DRIVER_LED_TOTAL RGBLED_NUM
#define RGBLIGHT_RAINBOW_SWIRL_RANGE 1950
#ifdef IOS_DEVICE_ENABLE
#define RGBLIGHT_LIMIT_VAL 40
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 40
#elif RGBLIGHT_FULL_POWER
#define RGBLIGHT_LIMIT_VAL 255
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255
#else
#define RGBLIGHT_LIMIT_VAL 120
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 120
#endif
#define RGBLIGHT_VAL_STEP (RGBLIGHT_LIMIT_VAL / 10)
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_ANIMATIONS
#define LED_HITS_TO_REMEMBER 5
#if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE)
// USB_MAX_POWER_CONSUMPTION value for Helix keyboard
// 120 RGBoff, OLEDoff
// 120 OLED
// 330 RGB 6
// 300 RGB 32
// 310 OLED & RGB 32
#define USB_MAX_POWER_CONSUMPTION 500
#else
// fix iPhone and iPad power adapter issue
// iOS device need lessthan 100
#define USB_MAX_POWER_CONSUMPTION 100
#endif
/*
* 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
#endif

View File

@ -1,304 +0,0 @@
/*
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 <avr/wdt.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "print.h"
#include "debug.h"
#include "util.h"
#include "matrix.h"
#include "split_util.h"
#include <drivers/avr/pro_micro.h>
#include "serial.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
#ifdef ENCODER_ENABLE_CUSTOM
#include "common/knob_v2.h"
#endif
#define ERROR_DISCONNECT_COUNT 5
static uint8_t debouncing = DEBOUNCE;
static const int ROWS_PER_HAND = MATRIX_ROWS/2;
static uint8_t error_count = 0;
uint8_t is_master = 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 read_cols(void);
static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);
static uint8_t matrix_master_scan(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) {
}
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void)
{
debug_enable = true;
debug_matrix = true;
debug_mouse = true;
// 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;
}
is_master = has_usb();
#ifdef ENCODER_ENABLE_CUSTOM
knob_init(); //FOR ENCODER
#endif
matrix_init_quantum();
}
uint8_t _matrix_scan(void)
{
// Right hand is stored after the left in the matirx so, we need to offset it
int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
select_row(i);
_delay_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols();
if (matrix_debouncing[i+offset] != cols) {
matrix_debouncing[i+offset] = cols;
debouncing = DEBOUNCE;
}
unselect_rows();
}
if (debouncing) {
if (--debouncing) {
_delay_ms(1);
} else {
for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
matrix[i+offset] = matrix_debouncing[i+offset];
}
}
}
#ifdef ENCODER_ENABLE_CUSTOM
knob_report_t knob_report = knob_report_read();
knob_report_reset();
matrix[5 + offset] &= 0b11111100;
if (knob_report.phase) { // I check for phase to avoid handling the rotation twice (on 90 and 270 degrees).
if (knob_report.dir > 0) {
matrix[5 + offset] |= 0b00000001;
} else if (knob_report.dir < 0) {
matrix[5 + offset] |= 0b00000010;
}
}
#endif
return 1;
}
int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
int ret=serial_update_buffers();
if (ret ) {
return 1;
}
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[slaveOffset+i] = serial_slave_buffer[i];
}
return 0;
}
uint8_t matrix_scan(void)
{
if (is_master) {
matrix_master_scan();
}else{
matrix_slave_scan();
int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[offset+i] = serial_master_buffer[i];
}
matrix_scan_quantum();
}
return 1;
}
uint8_t matrix_master_scan(void) {
int ret = _matrix_scan();
int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_master_buffer[i] = matrix[offset+i];
}
if( serial_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) {
serial_slave_buffer[i] = matrix[offset+i];
}
}
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<<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(int x = 0; x < MATRIX_COLS; x++) {
_SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF);
_SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF);
}
}
static matrix_row_t read_cols(void)
{
matrix_row_t result = 0;
for(int x = 0; x < MATRIX_COLS; x++) {
result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
}
return result;
}
static void unselect_rows(void)
{
for(int x = 0; x < ROWS_PER_HAND; x++) {
_SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
_SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
}
}
static void select_row(uint8_t row)
{
_SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF);
_SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF);
}

View File

@ -1,4 +1,4 @@
#include "sol.h"
#include "quantum.h"
#ifdef RGB_MATRIX_ENABLE
rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
@ -81,7 +81,3 @@
};
#endif
void matrix_init_kb(void) {
matrix_init_user();
};

View File

@ -1,70 +1 @@
#ifndef REV1_H
#define REV1_H
#include "sol.h"
//void promicro_bootloader_jmp(bool program);
#include "quantum.h"
#ifdef RGBLIGHT_ENABLE
//rgb led driver
#include "ws2812.h"
#endif
#ifdef USE_I2C
#include <stddef.h>
#ifdef __AVR__
#include <avr/io.h>
#include <avr/interrupt.h>
#endif
#endif
//void promicro_bootloader_jmp(bool program);
// LEL/LER/REL/RER are
// LeftEncoderLeft, LeftEncoderRight, RightEncoderLeft, and RightEncoderRight
#define LAYOUT( \
L00, L01, L02, L03, L04, L05, L06, R06, R00, R01, R02, R03, R04, R05, \
L10, L11, L12, L13, L14, L15, L16, R16, R10, R11, R12, R13, R14, R15, \
L20, L21, L22, L23, L24, L25, L26, R26, R20, R21, R22, R23, R24, R25, \
L30, L31, L32, L33, L34, L35, L36, R36, R30, R31, R32, R33, R34, R35, \
L40, L41, L42, L43, L44, L45, L46, R46, R40, R41, R42, R43, R44, R45, \
LEL, LER, L55, L56, R56, R50, REL, RER \
) \
{ \
{ L00, L01, L02, L03, L04, L05, L06 }, \
{ L10, L11, L12, L13, L14, L15, L16 }, \
{ L20, L21, L22, L23, L24, L25, L26 }, \
{ L30, L31, L32, L33, L34, L35, L36 }, \
{ L40, L41, L42, L43, L44, L45, L46 }, \
{ LEL, LER, KC_NO, KC_NO, KC_NO, L55, L56 }, \
{ R05, R04, R03, R02, R01, R00, R06 }, \
{ R15, R14, R13, R12, R11, R10, R16 }, \
{ R25, R24, R23, R22, R21, R20, R26 }, \
{ R35, R34, R33, R32, R31, R30, R36 }, \
{ R45, R44, R43, R42, R41, R40, R46 }, \
{ REL, RER, KC_NO, KC_NO, KC_NO, R50, R56 } \
}
#define KC________ KC_TRNS
#define KC_RGB_MOD RGB_MOD
#define KC_FN FN
#define KC_ADJ ADJ
#define LAYOUT_kc( \
L00, L01, L02, L03, L04, L05, L06, R06, R00, R01, R02, R03, R04, R05, \
L10, L11, L12, L13, L14, L15, L16, R16, R10, R11, R12, R13, R14, R15, \
L20, L21, L22, L23, L24, L25, L26, R26, R20, R21, R22, R23, R24, R25, \
L30, L31, L32, L33, L34, L35, L36, R36, R30, R31, R32, R33, R34, R35, \
L40, L41, L42, L43, L44, L45, L46, R46, R40, R41, R42, R43, R44, R45, \
LEL, LER, L55, L56, R56, R50, REL, RER \
) \
LAYOUT( \
KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L06, KC_##R06, KC_##R00, KC_##R01, KC_##R02, KC_##R03, KC_##R04, KC_##R05, \
KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L16, KC_##R16, KC_##R10, KC_##R11, KC_##R12, KC_##R13, KC_##R14, KC_##R15, \
KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L26, KC_##R26, KC_##R20, KC_##R21, KC_##R22, KC_##R23, KC_##R24, KC_##R25, \
KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L36, KC_##R36, KC_##R30, KC_##R31, KC_##R32, KC_##R33, KC_##R34, KC_##R35, \
KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, KC_##L46, KC_##R46, KC_##R40, KC_##R41, KC_##R42, KC_##R43, KC_##R44, KC_##R45, \
KC_##LEL, KC_##LER, KC_##L55, KC_##L56, KC_##R56, KC_##R50, KC_##REL, KC_##RER \
)
#endif
#pragma once

View File

@ -1,2 +0,0 @@
SRC += rev1/matrix.c \
rev1/split_util.c

View File

@ -1,54 +0,0 @@
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include "split_util.h"
#include "matrix.h"
#include "keyboard.h"
#include "serial.h"
volatile bool isLeftHand = true;
static void setup_handedness(void) {
#ifdef EE_HANDS
isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
#else
#if defined(MASTER_RIGHT)
isLeftHand = !has_usb();
#else
isLeftHand = has_usb();
#endif
#endif
}
static void keyboard_master_setup(void) {
serial_master_init();
}
static void keyboard_slave_setup(void) {
serial_slave_init();
}
bool has_usb(void) {
USBCON |= (1 << OTGPADE); //enables VBUS pad
_delay_us(5);
return (USBSTA & (1<<VBUS)); //checks state of VBUS
}
void split_keyboard_setup(void) {
setup_handedness();
if (has_usb()) {
keyboard_master_setup();
} else {
keyboard_slave_setup();
}
sei();
}
// this code runs before the usb and keyboard is initialized
void matrix_setup(void) {
split_keyboard_setup();
}

View File

@ -1,15 +0,0 @@
#ifndef SPLIT_KEYBOARD_UTIL_H
#define SPLIT_KEYBOARD_UTIL_H
#include <stdbool.h>
#include "eeconfig.h"
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);
#endif

View File

@ -1,5 +1,3 @@
SRC += serial.c
# MCU name
#MCU = at90usb1287
MCU = atmega32u4
@ -48,6 +46,9 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Custom local font file
OPT_DEFS += -DOLED_FONT_H=\"common/glcdfont.c\"
SPLIT_KEYBOARD = yes
ENCODER_ENABLE = yes
# 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
@ -62,6 +63,4 @@ UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
CUSTOM_MATRIX = yes
DEFAULT_FOLDER = sol/rev1

View File

@ -1,288 +0,0 @@
/*
* WARNING: be careful changing this code, it is very timing dependent
*/
#ifndef F_CPU
#define F_CPU 16000000
#endif
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdbool.h>
#include "serial.h"
#ifdef USE_SERIAL
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
// Serial pulse period in microseconds.
#define SELECT_SERIAL_SPEED 1
#if SELECT_SERIAL_SPEED == 0
// Very High speed
#define SERIAL_DELAY 4 // micro sec
#define READ_WRITE_START_ADJUST 30 // cycles
#define READ_WRITE_WIDTH_ADJUST 10 // cycles
#elif SELECT_SERIAL_SPEED == 1
// High speed
#define SERIAL_DELAY 6 // micro sec
#define READ_WRITE_START_ADJUST 23 // cycles
#define READ_WRITE_WIDTH_ADJUST 10 // cycles
#elif SELECT_SERIAL_SPEED == 2
// Middle speed
#define SERIAL_DELAY 12 // micro sec
#define READ_WRITE_START_ADJUST 25 // cycles
#define READ_WRITE_WIDTH_ADJUST 10 // cycles
#elif SELECT_SERIAL_SPEED == 3
// Low speed
#define SERIAL_DELAY 24 // micro sec
#define READ_WRITE_START_ADJUST 25 // cycles
#define READ_WRITE_WIDTH_ADJUST 10 // cycles
#elif SELECT_SERIAL_SPEED == 4
// Very Low speed
#define SERIAL_DELAY 50 // micro sec
#define READ_WRITE_START_ADJUST 25 // cycles
#define READ_WRITE_WIDTH_ADJUST 10 // cycles
#else
#error Illegal Serial Speed
#endif
#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
#define SLAVE_INT_WIDTH 1
#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
#define SLAVE_DATA_CORRUPT (1<<0)
volatile uint8_t status = 0;
inline static
void serial_delay(void) {
_delay_us(SERIAL_DELAY);
}
inline static
void serial_delay_half1(void) {
_delay_us(SERIAL_DELAY_HALF1);
}
inline static
void serial_delay_half2(void) {
_delay_us(SERIAL_DELAY_HALF2);
}
inline static
void serial_output(void) {
SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
}
// make the serial pin an input with pull-up resistor
inline static
void serial_input_with_pullup(void) {
SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
}
inline static
uint8_t serial_read_pin(void) {
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
}
inline static
void serial_low(void) {
SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
}
inline static
void serial_high(void) {
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
}
void serial_master_init(void) {
serial_output();
serial_high();
}
void serial_slave_init(void) {
serial_input_with_pullup();
// Enable INT3
EIMSK |= _BV(INT3);
// Trigger on falling edge of INT3
EICRA &= ~(_BV(ISC30) | _BV(ISC31));
}
// Used by the sender to synchronize timing with the reciver.
static
void sync_recv(void) {
for (int i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
}
// This shouldn't hang if the slave disconnects because the
// serial line will float to high if the slave does disconnect.
while (!serial_read_pin());
}
// Used by the reciver to send a synchronization signal to the sender.
static
void sync_send(void) {
serial_low();
serial_delay();
serial_high();
}
// Reads a byte from the serial line
static
uint8_t serial_read_byte(void) {
uint8_t byte = 0;
_delay_sub_us(READ_WRITE_START_ADJUST);
for ( uint8_t i = 0; i < 8; ++i) {
serial_delay_half1(); // read the middle of pulses
byte = (byte << 1) | serial_read_pin();
_delay_sub_us(READ_WRITE_WIDTH_ADJUST);
serial_delay_half2();
}
return byte;
}
// Sends a byte with MSB ordering
static
void serial_write_byte(uint8_t data) {
uint8_t b = 1<<7;
while( b ) {
if(data & b) {
serial_high();
} else {
serial_low();
}
b >>= 1;
serial_delay();
}
serial_low(); // sync_send() / senc_recv() need raise edge
}
// interrupt handle to be used by the slave device
ISR(SERIAL_PIN_INTERRUPT) {
serial_output();
// slave send phase
uint8_t checksum = 0;
for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
sync_send();
serial_write_byte(serial_slave_buffer[i]);
checksum += serial_slave_buffer[i];
}
sync_send();
serial_write_byte(checksum);
// slave switch to input
sync_send(); //0
serial_delay_half1(); //1
serial_low(); //2
serial_input_with_pullup(); //2
serial_delay_half1(); //3
// slave recive phase
uint8_t checksum_computed = 0;
for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
sync_recv();
serial_master_buffer[i] = serial_read_byte();
checksum_computed += serial_master_buffer[i];
}
sync_recv();
uint8_t checksum_received = serial_read_byte();
if ( checksum_computed != checksum_received ) {
status |= SLAVE_DATA_CORRUPT;
} else {
status &= ~SLAVE_DATA_CORRUPT;
}
sync_recv(); //weit master output to high
}
inline
bool serial_slave_DATA_CORRUPT(void) {
return status & SLAVE_DATA_CORRUPT;
}
// Copies the serial_slave_buffer to the master and sends the
// serial_master_buffer to the slave.
//
// Returns:
// 0 => no error
// 1 => slave did not respond
// 2 => checksum error
int serial_update_buffers(void) {
// this code is very time dependent, so we need to disable interrupts
cli();
// signal to the slave that we want to start a transaction
serial_output();
serial_low();
_delay_us(SLAVE_INT_WIDTH);
// wait for the slaves response
serial_input_with_pullup();
_delay_us(SLAVE_INT_RESPONSE_TIME);
// check if the slave is present
if (serial_read_pin()) {
// slave failed to pull the line low, assume not present
serial_output();
serial_high();
sei();
return 1;
}
// master recive phase
// if the slave is present syncronize with it
uint8_t checksum_computed = 0;
// receive data from the slave
for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
sync_recv();
serial_slave_buffer[i] = serial_read_byte();
checksum_computed += serial_slave_buffer[i];
}
sync_recv();
uint8_t checksum_received = serial_read_byte();
if (checksum_computed != checksum_received) {
serial_output();
serial_high();
sei();
return 2;
}
// master switch to output
sync_recv(); //0
serial_delay(); //1
serial_low(); //3
serial_output(); // 3
serial_delay_half1(); //4
// master send phase
uint8_t checksum = 0;
for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
sync_send();
serial_write_byte(serial_master_buffer[i]);
checksum += serial_master_buffer[i];
}
sync_send();
serial_write_byte(checksum);
// always, release the line when not in use
sync_send();
sei();
return 0;
}
#endif

View File

@ -1,26 +0,0 @@
#ifndef MY_SERIAL_H
#define MY_SERIAL_H
#include <stdbool.h>
/* TODO: some defines for interrupt setup */
#define SERIAL_PIN_DDR DDRD
#define SERIAL_PIN_PORT PORTD
#define SERIAL_PIN_INPUT PIND
#define SERIAL_PIN_MASK _BV(PD3) //SErial pin goes here, D0-D3
#define SERIAL_PIN_INTERRUPT INT3_vect //"INT#" of your serial pin
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
// Buffers for master - slave communication
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(void);
bool serial_slave_data_corrupt(void);
#endif

View File

@ -1,7 +1,53 @@
#ifndef SOL_H
#define SOL_H
#pragma once
#include "rev1.h"
#include "quantum.h"
#ifdef KEYBOARD_sol_rev1
#include "rev1.h"
#elif KEYBOARD_sol_rev2
#include "rev2.h"
#endif
#define LAYOUT( \
L00, L01, L02, L03, L04, L05, L06, R06, R00, R01, R02, R03, R04, R05, \
L10, L11, L12, L13, L14, L15, L16, R16, R10, R11, R12, R13, R14, R15, \
L20, L21, L22, L23, L24, L25, L26, R26, R20, R21, R22, R23, R24, R25, \
L30, L31, L32, L33, L34, L35, L36, R36, R30, R31, R32, R33, R34, R35, \
L40, L41, L42, L43, L44, L45, L46, R46, R40, R41, R42, R43, R44, R45, \
L55, L56, R56, R50 \
) \
{ \
{ L00, L01, L02, L03, L04, L05, L06 }, \
{ L10, L11, L12, L13, L14, L15, L16 }, \
{ L20, L21, L22, L23, L24, L25, L26 }, \
{ L30, L31, L32, L33, L34, L35, L36 }, \
{ L40, L41, L42, L43, L44, L45, L46 }, \
{ KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, L55, L56 }, \
{ R05, R04, R03, R02, R01, R00, R06 }, \
{ R15, R14, R13, R12, R11, R10, R16 }, \
{ R25, R24, R23, R22, R21, R20, R26 }, \
{ R35, R34, R33, R32, R31, R30, R36 }, \
{ R45, R44, R43, R42, R41, R40, R46 }, \
{ KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, R50, R56 } \
}
#define KC________ KC_TRNS
#define KC_RGB_MOD RGB_MOD
#define KC_FN FN
#define KC_ADJ ADJ
#define LAYOUT_kc( \
L00, L01, L02, L03, L04, L05, L06, R06, R00, R01, R02, R03, R04, R05, \
L10, L11, L12, L13, L14, L15, L16, R16, R10, R11, R12, R13, R14, R15, \
L20, L21, L22, L23, L24, L25, L26, R26, R20, R21, R22, R23, R24, R25, \
L30, L31, L32, L33, L34, L35, L36, R36, R30, R31, R32, R33, R34, R35, \
L40, L41, L42, L43, L44, L45, L46, R46, R40, R41, R42, R43, R44, R45, \
L55, L56, R56, R50 \
) \
LAYOUT( \
KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##L06, KC_##R06, KC_##R00, KC_##R01, KC_##R02, KC_##R03, KC_##R04, KC_##R05, \
KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##L16, KC_##R16, KC_##R10, KC_##R11, KC_##R12, KC_##R13, KC_##R14, KC_##R15, \
KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##L26, KC_##R26, KC_##R20, KC_##R21, KC_##R22, KC_##R23, KC_##R24, KC_##R25, \
KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L36, KC_##R36, KC_##R30, KC_##R31, KC_##R32, KC_##R33, KC_##R34, KC_##R35, \
KC_##L40, KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##L45, KC_##L46, KC_##R46, KC_##R40, KC_##R41, KC_##R42, KC_##R43, KC_##R44, KC_##R45, \
KC_##L55, KC_##L56, KC_##R56, KC_##R50 \
)

View File

@ -247,12 +247,6 @@ bool process_record_quantum(keyrecord_t *record) {
preprocess_tap_dance(keycode, record);
#endif
#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT)
// Wake up oled if user is using those fabulous keys!
if (record->event.pressed)
oled_on();
#endif
if (!(
#if defined(KEY_LOCK_ENABLE)
// Must run first to be able to mask key_up events.
@ -976,9 +970,6 @@ void matrix_init_quantum() {
#ifdef OUTPUT_AUTO_ENABLE
set_output(OUTPUT_AUTO);
#endif
#ifdef OLED_DRIVER_ENABLE
oled_init(OLED_ROTATION_0);
#endif
matrix_init_kb();
}
@ -1015,10 +1006,6 @@ void matrix_scan_quantum() {
haptic_task();
#endif
#ifdef OLED_DRIVER_ENABLE
oled_task();
#endif
matrix_scan_kb();
}
#if defined(BACKLIGHT_ENABLE) && (defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS))
@ -1214,10 +1201,10 @@ void backlight_task(void) {
// (which is not possible since the backlight is not wired to PWM pins on the
// CPU), we do the LED on/off by oursleves.
// The timer is setup to count up to 0xFFFF, and we set the Output Compare
// register to the current 16bits backlight level (after CIE correction).
// This means the CPU will trigger a compare match interrupt when the counter
// reaches the backlight level, where we turn off the LEDs,
// but also an overflow interrupt when the counter rolls back to 0,
// register to the current 16bits backlight level (after CIE correction).
// This means the CPU will trigger a compare match interrupt when the counter
// reaches the backlight level, where we turn off the LEDs,
// but also an overflow interrupt when the counter rolls back to 0,
// in which we're going to turn on the LEDs.
// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz.
@ -1229,7 +1216,7 @@ ISR(TIMERx_COMPA_vect) {
}
// Triggered when the counter reaches the TOP value
// this one triggers at F_CPU/65536 =~ 244 Hz
// this one triggers at F_CPU/65536 =~ 244 Hz
ISR(TIMERx_OVF_vect) {
#ifdef BACKLIGHT_BREATHING
breathing_task();

View File

@ -299,7 +299,7 @@ uint8_t _matrix_scan(void) {
debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed);
return 1;
return (uint8_t)changed;
}
uint8_t matrix_scan(void) {

View File

@ -75,6 +75,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef QWIIC_ENABLE
# include "qwiic.h"
#endif
#ifdef OLED_DRIVER_ENABLE
#include "oled_driver.h"
#endif
#ifdef VELOCIKEY_ENABLE
#include "velocikey.h"
#endif
@ -205,6 +208,9 @@ void keyboard_init(void) {
#ifdef QWIIC_ENABLE
qwiic_init();
#endif
#ifdef OLED_DRIVER_ENABLE
oled_init(OLED_ROTATION_0);
#endif
#ifdef PS2_MOUSE_ENABLE
ps2_mouse_init();
#endif
@ -262,7 +268,11 @@ void keyboard_task(void)
uint8_t keys_processed = 0;
#endif
#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT)
uint8_t ret = matrix_scan();
#else
matrix_scan();
#endif
if (is_keyboard_master()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
@ -306,6 +316,15 @@ MATRIX_LOOP_END:
qwiic_task();
#endif
#ifdef OLED_DRIVER_ENABLE
oled_task();
#ifndef OLED_DISABLE_TIMEOUT
// Wake up oled if user is using those fabulous keys!
if (ret)
oled_on();
#endif
#endif
#ifdef MOUSEKEY_ENABLE
// mousekey repeat & acceleration
mousekey_task();