Files
qmk/quantum/split_common/split_util.c
T

88 lines
1.8 KiB
C
Raw Normal View History

2018-07-16 19:25:02 -07:00
#include "split_util.h"
#include "matrix.h"
#include "keyboard.h"
#include "config.h"
#include "timer.h"
#include "split_flags.h"
#include "transport.h"
#include "quantum.h"
2018-07-16 19:25:02 -07:00
2019-01-03 14:30:23 +11:00
#ifdef EE_HANDS
# include "tmk_core/common/eeprom.h"
# include "eeconfig.h"
2018-07-16 19:25:02 -07:00
#endif
volatile bool isLeftHand = true;
__attribute__((weak))
bool is_keyboard_left(void) {
2018-07-16 19:25:02 -07:00
#ifdef 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);
2018-07-16 19:25:02 -07:00
#else
#ifdef EE_HANDS
return eeprom_read_byte(EECONFIG_HANDEDNESS);
2018-07-16 19:25:02 -07:00
#else
2018-12-28 13:37:23 -08:00
#ifdef MASTER_RIGHT
return !is_keyboard_master();
2018-07-16 19:25:02 -07:00
#else
return is_keyboard_master();
2018-07-16 19:25:02 -07:00
#endif
#endif
#endif
}
bool is_keyboard_master(void)
{
#ifdef __AVR__
static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
// only check once, as this is called often
if (usbstate == UNKNOWN)
{
USBCON |= (1 << OTGPADE); // enables VBUS pad
wait_us(5);
usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
}
return (usbstate == MASTER);
#else
return true;
#endif
}
2018-07-16 19:25:02 -07:00
static void keyboard_master_setup(void) {
#if defined(USE_I2C) || defined(EH)
#ifdef SSD1306OLED
matrix_master_OLED_init ();
#endif
#endif
transport_master_init();
2018-07-16 19:25:02 -07:00
// For master the Backlight info needs to be sent on startup
// Otherwise the salve won't start with the proper info until an update
BACKLIT_DIRTY = true;
2018-07-16 19:25:02 -07:00
}
static void keyboard_slave_setup(void)
{
transport_slave_init();
2018-07-16 19:25:02 -07:00
}
// this code runs before the usb and keyboard is initialized
void matrix_setup(void)
{
isLeftHand = is_keyboard_left();
2018-07-16 19:25:02 -07:00
if (is_keyboard_master())
{
keyboard_master_setup();
}
else
{
keyboard_slave_setup();
}
2018-07-16 19:25:02 -07:00
}