keyboard layout for qmk firmware
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.

77 lines
1.5 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 "config.h"
  11. #include "timer.h"
  12. #include "i2c.h"
  13. volatile bool isLeftHand = true;
  14. static void setup_handedness(void) {
  15. #ifdef EE_HANDS
  16. isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
  17. #else
  18. // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c
  19. #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
  20. isLeftHand = !has_usb();
  21. #else
  22. isLeftHand = has_usb();
  23. #endif
  24. #endif
  25. }
  26. static void keyboard_master_setup(void) {
  27. i2c_master_init();
  28. }
  29. static void keyboard_slave_setup(void) {
  30. timer_init();
  31. i2c_slave_init(SLAVE_I2C_ADDRESS);
  32. }
  33. bool has_usb(void) {
  34. USBCON |= (1 << OTGPADE); //enables VBUS pad
  35. _delay_us(5);
  36. return (USBSTA & (1<<VBUS)); //checks state of VBUS
  37. }
  38. void split_keyboard_setup(void) {
  39. setup_handedness();
  40. #ifdef USE_50ONE_LEDS
  41. _led_init();
  42. _led_boot_animation();
  43. #endif
  44. if (has_usb()) {
  45. keyboard_master_setup();
  46. } else {
  47. keyboard_slave_setup();
  48. }
  49. sei();
  50. }
  51. void keyboard_slave_loop(void) {
  52. matrix_init();
  53. while (1) {
  54. matrix_slave_scan();
  55. }
  56. }
  57. // this code runs before the usb and keyboard is initialized
  58. void matrix_setup(void) {
  59. split_keyboard_setup();
  60. if (!has_usb()) {
  61. keyboard_slave_loop();
  62. }
  63. }