You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.2 KiB

[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
  1. #include <avr/io.h>
  2. #include <avr/wdt.h>
  3. #include <avr/power.h>
  4. #include <avr/interrupt.h>
  5. #include <util/delay.h>
  6. #include <avr/eeprom.h>
  7. #include "split_util.h"
  8. #include "matrix.h"
  9. #include "keyboard.h"
  10. #include "wait.h"
  11. #ifdef USE_MATRIX_I2C
  12. # include "i2c.h"
  13. #else
  14. # include "serial.h"
  15. #endif
  16. #ifdef EE_HANDS
  17. # include "eeconfig.h"
  18. #endif
  19. #ifndef SPLIT_USB_TIMEOUT
  20. #define SPLIT_USB_TIMEOUT 2500
  21. #endif
  22. volatile bool isLeftHand = true;
  23. bool waitForUsb(void) {
  24. for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) {
  25. // This will return true of a USB connection has been established
  26. if (UDADDR & _BV(ADDEN)) {
  27. return true;
  28. }
  29. wait_ms(100);
  30. }
  31. // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
  32. (USBCON &= ~(_BV(USBE) | _BV(OTGPADE)));
  33. return false;
  34. }
  35. bool is_keyboard_left(void) {
  36. #if defined(SPLIT_HAND_PIN)
  37. // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
  38. setPinInput(SPLIT_HAND_PIN);
  39. return readPin(SPLIT_HAND_PIN);
  40. #elif defined(EE_HANDS)
  41. return eeconfig_read_handedness();
  42. #elif defined(MASTER_RIGHT)
  43. return !is_helix_master();
  44. #endif
  45. return is_helix_master();
  46. }
  47. bool is_helix_master(void) {
  48. static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
  49. // only check once, as this is called often
  50. if (usbstate == UNKNOWN) {
  51. #if defined(SPLIT_USB_DETECT)
  52. usbstate = waitForUsb() ? MASTER : SLAVE;
  53. #elif defined(__AVR__)
  54. USBCON |= (1 << OTGPADE); // enables VBUS pad
  55. wait_us(5);
  56. usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
  57. #else
  58. usbstate = MASTER;
  59. #endif
  60. }
  61. return (usbstate == MASTER);
  62. }
  63. static void keyboard_master_setup(void) {
  64. #ifdef USE_MATRIX_I2C
  65. i2c_master_init();
  66. #else
  67. serial_master_init();
  68. #endif
  69. }
  70. static void keyboard_slave_setup(void) {
  71. #ifdef USE_MATRIX_I2C
  72. i2c_slave_init(SLAVE_I2C_ADDRESS);
  73. #else
  74. serial_slave_init();
  75. #endif
  76. }
  77. void split_keyboard_setup(void) {
  78. isLeftHand = is_keyboard_left();
  79. if (is_helix_master()) {
  80. keyboard_master_setup();
  81. } else {
  82. keyboard_slave_setup();
  83. }
  84. sei();
  85. }