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.

56 lines
1.2 KiB

  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 "serial.h"
  11. volatile bool isLeftHand = true;
  12. static void setup_handedness(void) {
  13. #ifdef EE_HANDS
  14. isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
  15. #else
  16. // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c
  17. #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
  18. isLeftHand = !has_usb();
  19. #else
  20. isLeftHand = has_usb();
  21. #endif
  22. #endif
  23. }
  24. static void keyboard_master_setup(void) {
  25. serial_master_init();
  26. }
  27. static void keyboard_slave_setup(void) {
  28. serial_slave_init();
  29. }
  30. bool has_usb(void) {
  31. USBCON |= (1 << OTGPADE); //enables VBUS pad
  32. _delay_us(5);
  33. return (USBSTA & (1<<VBUS)); //checks state of VBUS
  34. }
  35. void split_keyboard_setup(void) {
  36. setup_handedness();
  37. if (has_usb()) {
  38. keyboard_master_setup();
  39. } else {
  40. keyboard_slave_setup();
  41. }
  42. sei();
  43. }
  44. // this code runs before the usb and keyboard is initialized
  45. void matrix_setup(void) {
  46. split_keyboard_setup();
  47. }