logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

ergodox_ez.h (4899B)


  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. #define ERGODOX_EZ_BOARD_LED_PIN D6
  45. #define ERGODOX_EZ_RIGHT_LED_1_PIN B5
  46. #define ERGODOX_EZ_RIGHT_LED_2_PIN B6
  47. #define ERGODOX_EZ_RIGHT_LED_3_PIN B7
  48. inline void ergodox_board_led_on(void) {
  49. gpio_set_pin_output(ERGODOX_EZ_BOARD_LED_PIN);
  50. gpio_write_pin_high(ERGODOX_EZ_BOARD_LED_PIN);
  51. }
  52. inline void ergodox_right_led_1_on(void) {
  53. gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_1_PIN);
  54. gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_1_PIN);
  55. }
  56. inline void ergodox_right_led_2_on(void) {
  57. gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_2_PIN);
  58. gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_2_PIN);
  59. }
  60. inline void ergodox_right_led_3_on(void) {
  61. gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_3_PIN);
  62. gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_3_PIN);
  63. }
  64. inline void ergodox_board_led_off(void) {
  65. gpio_set_pin_input(ERGODOX_EZ_BOARD_LED_PIN);
  66. }
  67. inline void ergodox_right_led_1_off(void) {
  68. gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_1_PIN);
  69. }
  70. inline void ergodox_right_led_2_off(void) {
  71. gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_2_PIN);
  72. }
  73. inline void ergodox_right_led_3_off(void) {
  74. gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_3_PIN);
  75. }
  76. #ifdef LEFT_LEDS
  77. bool ergodox_left_led_1;
  78. bool ergodox_left_led_2;
  79. bool ergodox_left_led_3;
  80. inline void ergodox_left_led_1_on(void) { ergodox_left_led_1 = 1; }
  81. inline void ergodox_left_led_2_on(void) { ergodox_left_led_2 = 1; }
  82. inline void ergodox_left_led_3_on(void) { ergodox_left_led_3 = 1; }
  83. inline void ergodox_left_led_1_off(void) { ergodox_left_led_1 = 0; }
  84. inline void ergodox_left_led_2_off(void) { ergodox_left_led_2 = 0; }
  85. inline void ergodox_left_led_3_off(void) { ergodox_left_led_3 = 0; }
  86. #endif // LEFT_LEDS
  87. inline void ergodox_led_all_on(void) {
  88. ergodox_board_led_on();
  89. ergodox_right_led_1_on();
  90. ergodox_right_led_2_on();
  91. ergodox_right_led_3_on();
  92. #ifdef LEFT_LEDS
  93. ergodox_left_led_1_on();
  94. ergodox_left_led_2_on();
  95. ergodox_left_led_3_on();
  96. #endif // LEFT_LEDS
  97. }
  98. inline void ergodox_led_all_off(void)
  99. {
  100. ergodox_board_led_off();
  101. ergodox_right_led_1_off();
  102. ergodox_right_led_2_off();
  103. ergodox_right_led_3_off();
  104. #ifdef LEFT_LEDS
  105. ergodox_left_led_1_off();
  106. ergodox_left_led_2_off();
  107. ergodox_left_led_3_off();
  108. #endif // LEFT_LEDS
  109. }
  110. inline void ergodox_right_led_1_set(uint8_t n) { OCR1A = n; }
  111. inline void ergodox_right_led_2_set(uint8_t n) { OCR1B = n; }
  112. inline void ergodox_right_led_3_set(uint8_t n) { OCR1C = n; }
  113. inline void ergodox_right_led_set(uint8_t led, uint8_t n) {
  114. (led == 1) ? (OCR1A = n) :
  115. (led == 2) ? (OCR1B = n) :
  116. (OCR1C = n);
  117. }
  118. inline void ergodox_led_all_set(uint8_t n) {
  119. ergodox_right_led_1_set(n);
  120. ergodox_right_led_2_set(n);
  121. ergodox_right_led_3_set(n);
  122. }
  123. enum ergodox_ez_keycodes {
  124. LED_LEVEL = QK_KB_0,
  125. TOGGLE_LAYER_COLOR,
  126. };
  127. #ifndef WEBUSB_ENABLE
  128. # define WEBUSB_PAIR KC_NO
  129. #endif
  130. typedef union {
  131. uint32_t raw;
  132. struct {
  133. uint8_t led_level :3;
  134. bool disable_layer_led :1;
  135. bool rgb_matrix_enable :1;
  136. };
  137. } keyboard_config_t;
  138. extern keyboard_config_t keyboard_config;