Keyboard firmwares for Atmel AVR and Cortex-M
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.

5 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "i2c.h"
  10. #include "serial.h"
  11. #include "keyboard.h"
  12. #include "config.h"
  13. volatile bool isLeftHand = true;
  14. static void setup_handedness(void) {
  15. isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
  16. }
  17. static void keyboard_master_setup(void) {
  18. #ifdef USE_I2C
  19. i2c_master_init();
  20. #else
  21. serial_master_init();
  22. #endif
  23. }
  24. static void keyboard_slave_setup(void) {
  25. #ifdef USE_I2C
  26. i2c_slave_init(SLAVE_I2C_ADDRESS);
  27. #else
  28. serial_slave_init();
  29. #endif
  30. }
  31. bool has_usb(void) {
  32. USBCON |= (1 << OTGPADE); //enables VBUS pad
  33. _delay_us(5);
  34. return (USBSTA & (1<<VBUS)); //checks state of VBUS
  35. }
  36. void split_keyboard_setup(void) {
  37. setup_handedness();
  38. if (has_usb()) {
  39. keyboard_master_setup();
  40. } else {
  41. keyboard_slave_setup();
  42. }
  43. sei();
  44. }
  45. void keyboard_slave_loop(void) {
  46. matrix_init();
  47. while (1) {
  48. matrix_slave_scan();
  49. }
  50. }
  51. // this code runs before the usb and keyboard is initialized
  52. void matrix_setup(void) {
  53. split_keyboard_setup();
  54. if (!has_usb()) {
  55. keyboard_slave_loop();
  56. }
  57. }