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

Helix add split common option #7718

Merged
merged 12 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 0 additions & 3 deletions keyboards/helix/local_drivers/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <stdbool.h>
#include "i2c.h"

#ifdef USE_I2C

// Limits the amount of we wait for any one i2c transaction.
// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
// 9 bits, a single transaction will take around 90μs to complete.
Expand Down Expand Up @@ -159,4 +157,3 @@ ISR(TWI_vect) {
// Reset everything, so we are ready for the next TWI interrupt
TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
}
#endif
1 change: 0 additions & 1 deletion keyboards/helix/pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define TAPPING_TERM 100

/* Use I2C or Serial */
#define USE_I2C
#define USE_SERIAL
//#define USE_MATRIX_I2C

Expand Down
42 changes: 34 additions & 8 deletions keyboards/helix/pico/local_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ define HELIX_CUSTOMISE_MSG
$(info - OLED_ENABLE = $(OLED_ENABLE))
$(info - LED_BACK_ENABLE = $(LED_BACK_ENABLE))
$(info - LED_UNDERGLOW_ENABLE = $(LED_UNDERGLOW_ENABLE))
$(info - LED_ANIMATION = $(LED_ANIMATIONS))
$(info - LED_ANIMATIONS = $(LED_ANIMATIONS))
$(info - IOS_DEVICE_ENABLE = $(IOS_DEVICE_ENABLE))
$(info )
endef
Expand Down Expand Up @@ -43,12 +43,34 @@ endef
ifeq ($(findstring ios,$(HELIX)), ios)
IOS_DEVICE_ENABLE = yes
endif
ifeq ($(findstring scan,$(HELIX)), scan)
# use DEBUG_MATRIX_SCAN_RATE
# see docs/newbs_testing_debugging.md
OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE
CONSOLE_ENABLE = yes
SHOW_VERBOSE_INFO = yes
endif
ifeq ($(findstring verbose,$(HELIX)), verbose)
SHOW_VERBOSE_INFO = yes
SHOW_VERBOSE_INFO = yes
endif
SHOW_HELIX_OPTIONS = yes
endif

ifneq ($(strip $(SPLIT_KEYBOARD)), yes)
SRC += local_drivers/serial.c
KEYBOARD_PATHS += $(HELIX_TOP_DIR)/local_drivers

# A workaround until #7089 is merged.
# serial.c must not be compiled with the -lto option.
# The current LIB_SRC has a side effect with the -fno-lto option, so use it.
LIB_SRC += local_drivers/serial.c

CUSTOM_MATRIX = yes

SRC += pico/matrix.c
SRC += pico/split_util.c
endif

########
# convert Helix-specific options (that represent combinations of standard options)
# into QMK standard options.
Expand All @@ -73,11 +95,13 @@ ifeq ($(strip $(LED_ANIMATIONS)), yes)
endif

ifeq ($(strip $(OLED_ENABLE)), yes)
SRC += local_drivers/i2c.c
SRC += local_drivers/ssd1306.c
KEYBOARD_PATHS += $(HELIX_TOP_DIR)/local_drivers
OPT_DEFS += -DOLED_ENABLE
endif

ifeq ($(strip $(LOCAL_GLCDFONT)), yes)
OPT_DEFS += -DLOCAL_GLCDFONT
ifeq ($(strip $(LOCAL_GLCDFONT)), yes)
OPT_DEFS += -DLOCAL_GLCDFONT
endif
endif

ifeq ($(strip $(AUDIO_ENABLE)),yes)
Expand All @@ -92,8 +116,10 @@ endif
ifneq ($(strip $(SHOW_HELIX_OPTIONS)),)
$(eval $(call HELIX_CUSTOMISE_MSG))
ifneq ($(strip $(SHOW_VERBOSE_INFO)),)
$(info -- RGBLIGHT_ENABLE = $(RGBLIGHT_ENABLE))
$(info -- OPT_DEFS = $(OPT_DEFS))
$(info -- RGBLIGHT_ENABLE = $(RGBLIGHT_ENABLE))
$(info -- OLED_DRIVER_ENABLE = $(OLED_DRIVER_ENABLE))
$(info -- CONSOLE_ENABLE = $(CONSOLE_ENABLE))
$(info -- OPT_DEFS = $(OPT_DEFS))
$(info -- LINK_TIME_OPTIMIZATION_ENABLE = $(LINK_TIME_OPTIMIZATION_ENABLE))
$(info )
endif
Expand Down
10 changes: 3 additions & 7 deletions keyboards/helix/pico/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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;
Expand Down Expand Up @@ -94,9 +93,8 @@ uint8_t matrix_cols(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();
Expand All @@ -111,8 +109,6 @@ void matrix_init(void)
matrix_debouncing[i] = 0;
}

is_master = has_usb();

matrix_init_quantum();
}

Expand Down Expand Up @@ -197,7 +193,7 @@ int serial_transaction(void) {

uint8_t matrix_scan(void)
{
if (is_master) {
if (is_helix_master()) {
matrix_master_scan();
}else{
matrix_slave_scan();
Expand Down
21 changes: 21 additions & 0 deletions keyboards/helix/pico/pico.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "helix.h"

// Each keymap.c should use is_keyboard_master() instead of 'is_master'.
// But keep 'is_master' for a while for backwards compatibility
// for the old keymap.c.
uint8_t is_master = false;

#ifdef SSD1306OLED
#include "ssd1306.h"
Expand All @@ -15,6 +19,23 @@ void led_set_kb(uint8_t usb_led) {
#endif

void matrix_init_kb(void) {
// Each keymap.c should use is_keyboard_master() instead of is_master.
// But keep is_master for a while for backwards compatibility
// for the old keymap.c.
is_master = is_keyboard_master();

matrix_init_user();
};

void keyboard_post_init_kb(void) {
#if defined(DEBUG_MATRIX_SCAN_RATE)
debug_enable = true;
#endif
keyboard_post_init_user();
}

#if defined(SPLIT_KEYBOARD) && defined(SSD1306OLED)
void matrix_slave_scan_user(void) {
matrix_scan_user();
}
#endif
18 changes: 8 additions & 10 deletions keyboards/helix/pico/pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

#include "quantum.h"

#ifdef RGBLIGHT_ENABLE
//rgb led driver
#include "ws2812.h"
#ifndef SPLIT_KEYBOARD
extern bool is_helix_master(void);
#define is_keyboard_master() is_helix_master()
#endif

#ifdef USE_I2C
#include <stddef.h>
#ifdef __AVR__
#include <avr/io.h>
#include <avr/interrupt.h>
#endif
#endif
// Each keymap.c should use is_keyboard_master() instead of 'is_master', 'has_usb()'.
// But keep 'is_master' for a while for backwards compatibility
// for the old keymap.c.
extern uint8_t is_master; // 'is_master' will be obsolete, it is recommended to use 'is_keyboard_master ()' instead.
#define has_usb() is_keyboard_master()

#ifndef FLIP_HALF
// Standard Keymap
Expand Down
7 changes: 7 additions & 0 deletions keyboards/helix/pico/post_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#if defined(SPLIT_KEYBOARD) /* if use split_common */
# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_SPLIT)
# define RGBLIGHT_SPLIT /* helix hardware need this */
# endif
#endif
15 changes: 0 additions & 15 deletions keyboards/helix/pico/rules.mk
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
KEYBOARD_LOCAL_FEATURES_MK := $(dir $(lastword $(MAKEFILE_LIST)))local_features.mk

SRC += local_drivers/i2c.c
SRC += local_drivers/serial.c
SRC += local_drivers/ssd1306.c
KEYBOARD_PATHS += $(HELIX_TOP_DIR)/local_drivers

# A workaround until #7089 is merged.
# serial.c must not be compiled with the -lto option.
# The current LIB_SRC has a side effect with the -fno-lto option, so use it.
LIB_SRC += local_drivers/serial.c

CUSTOM_MATRIX = yes

SRC += pico/matrix.c
SRC += pico/split_util.c

# Helix Spacific Build Options default values
OLED_ENABLE = no # OLED_ENABLE
LOCAL_GLCDFONT = no # use each keymaps "helixfont.h" insted of "common/glcdfont.c"
Expand Down
1 change: 1 addition & 0 deletions keyboards/helix/pico/sc/back/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LED_BACK_ENABLE = yes
1 change: 1 addition & 0 deletions keyboards/helix/pico/sc/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SPLIT_KEYBOARD = yes
1 change: 1 addition & 0 deletions keyboards/helix/pico/sc/under/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LED_UNDERGLOW_ENABLE = yes
82 changes: 58 additions & 24 deletions keyboards/helix/pico/split_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,73 @@
#include "split_util.h"
#include "matrix.h"
#include "keyboard.h"
#include "wait.h"

#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else
# include "serial.h"
#endif

#ifdef EE_HANDS
# include "eeconfig.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;
}

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_helix_master();
#endif

return is_helix_master();
}

bool is_helix_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) {

#ifdef USE_MATRIX_I2C
Expand All @@ -47,24 +92,13 @@ 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
}

void split_keyboard_setup(void) {
setup_handedness();
isLeftHand = is_keyboard_left();

if (has_usb()) {
if (is_helix_master()) {
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();
}
2 changes: 1 addition & 1 deletion keyboards/helix/pico/split_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern volatile bool isLeftHand;
void matrix_slave_scan(void);

void split_keyboard_setup(void);
bool has_usb(void);
bool is_helix_master(void);

void matrix_master_OLED_init (void);

Expand Down
1 change: 0 additions & 1 deletion keyboards/helix/rev2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define TAPPING_TERM 100

/* Use I2C or Serial */
#define USE_I2C
#define USE_SERIAL
//#define USE_MATRIX_I2C

Expand Down
2 changes: 2 additions & 0 deletions keyboards/helix/rev2/keymaps/xulkal/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ OLED_DRIVER_ENABLE = yes
OPT_DEFS += -DOLED_FONT_H=\"common/glcdfont.c\"
# Xulkal specific oled define
OPT_DEFS += -DOLED_90ROTATION

SPLIT_KEYBOARD = yes
Loading