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.

139 lines
4.5 KiB

8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. Copyright 2012 Jun Wako <wakojun@gmail.com>
  3. Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
  4. Copyright 2015 ZSA Technology Labs Inc (@zsa)
  5. Copyright 2020 Christopher Courtney <drashna@live.com> (@drashna)
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include "quantum.h"
  19. #include <stdint.h>
  20. #include <stdbool.h>
  21. #include "i2c_master.h"
  22. // I2C aliases and register addresses (see "mcp23018.md")
  23. #define I2C_ADDR (0b0100000<<1)
  24. #define IODIRA 0x00 // i/o direction register
  25. #define IODIRB 0x01
  26. #define GPPUA 0x0C // GPIO pull-up resistor register
  27. #define GPPUB 0x0D
  28. #define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
  29. #define GPIOB 0x13
  30. #define OLATA 0x14 // output latch register
  31. #define OLATB 0x15
  32. extern i2c_status_t mcp23018_status;
  33. #define ERGODOX_EZ_I2C_TIMEOUT 100
  34. void init_ergodox(void);
  35. void ergodox_blink_all_leds(void);
  36. uint8_t init_mcp23018(void);
  37. uint8_t ergodox_left_leds_update(void);
  38. #ifndef LED_BRIGHTNESS_LO
  39. #define LED_BRIGHTNESS_LO 15
  40. #endif
  41. #ifndef LED_BRIGHTNESS_HI
  42. #define LED_BRIGHTNESS_HI 255
  43. #endif
  44. inline void ergodox_board_led_on(void) { DDRD |= (1<<6); PORTD |= (1<<6); }
  45. inline void ergodox_right_led_1_on(void) { DDRB |= (1<<5); PORTB |= (1<<5); }
  46. inline void ergodox_right_led_2_on(void) { DDRB |= (1<<6); PORTB |= (1<<6); }
  47. inline void ergodox_right_led_3_on(void) { DDRB |= (1<<7); PORTB |= (1<<7); }
  48. inline void ergodox_right_led_on(uint8_t led) { DDRB |= (1<<(led+4)); PORTB |= (1<<(led+4)); }
  49. inline void ergodox_board_led_off(void) { DDRD &= ~(1<<6); PORTD &= ~(1<<6); }
  50. inline void ergodox_right_led_1_off(void) { DDRB &= ~(1<<5); PORTB &= ~(1<<5); }
  51. inline void ergodox_right_led_2_off(void) { DDRB &= ~(1<<6); PORTB &= ~(1<<6); }
  52. inline void ergodox_right_led_3_off(void) { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
  53. inline void ergodox_right_led_off(uint8_t led) { DDRB &= ~(1<<(led+4)); PORTB &= ~(1<<(led+4)); }
  54. #ifdef LEFT_LEDS
  55. bool ergodox_left_led_1;
  56. bool ergodox_left_led_2;
  57. bool ergodox_left_led_3;
  58. inline void ergodox_left_led_1_on(void) { ergodox_left_led_1 = 1; }
  59. inline void ergodox_left_led_2_on(void) { ergodox_left_led_2 = 1; }
  60. inline void ergodox_left_led_3_on(void) { ergodox_left_led_3 = 1; }
  61. inline void ergodox_left_led_1_off(void) { ergodox_left_led_1 = 0; }
  62. inline void ergodox_left_led_2_off(void) { ergodox_left_led_2 = 0; }
  63. inline void ergodox_left_led_3_off(void) { ergodox_left_led_3 = 0; }
  64. #endif // LEFT_LEDS
  65. inline void ergodox_led_all_on(void) {
  66. ergodox_board_led_on();
  67. ergodox_right_led_1_on();
  68. ergodox_right_led_2_on();
  69. ergodox_right_led_3_on();
  70. #ifdef LEFT_LEDS
  71. ergodox_left_led_1_on();
  72. ergodox_left_led_2_on();
  73. ergodox_left_led_3_on();
  74. #endif // LEFT_LEDS
  75. }
  76. inline void ergodox_led_all_off(void)
  77. {
  78. ergodox_board_led_off();
  79. ergodox_right_led_1_off();
  80. ergodox_right_led_2_off();
  81. ergodox_right_led_3_off();
  82. #ifdef LEFT_LEDS
  83. ergodox_left_led_1_off();
  84. ergodox_left_led_2_off();
  85. ergodox_left_led_3_off();
  86. #endif // LEFT_LEDS
  87. }
  88. inline void ergodox_right_led_1_set(uint8_t n) { OCR1A = n; }
  89. inline void ergodox_right_led_2_set(uint8_t n) { OCR1B = n; }
  90. inline void ergodox_right_led_3_set(uint8_t n) { OCR1C = n; }
  91. inline void ergodox_right_led_set(uint8_t led, uint8_t n) {
  92. (led == 1) ? (OCR1A = n) :
  93. (led == 2) ? (OCR1B = n) :
  94. (OCR1C = n);
  95. }
  96. inline void ergodox_led_all_set(uint8_t n) {
  97. ergodox_right_led_1_set(n);
  98. ergodox_right_led_2_set(n);
  99. ergodox_right_led_3_set(n);
  100. }
  101. enum ergodox_ez_keycodes {
  102. LED_LEVEL = QK_KB_0,
  103. TOGGLE_LAYER_COLOR,
  104. };
  105. #ifndef WEBUSB_ENABLE
  106. # define WEBUSB_PAIR KC_NO
  107. #endif
  108. typedef union {
  109. uint32_t raw;
  110. struct {
  111. uint8_t led_level :3;
  112. bool disable_layer_led :1;
  113. bool rgb_matrix_enable :1;
  114. };
  115. } keyboard_config_t;
  116. extern keyboard_config_t keyboard_config;