logo

qmk_firmware

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

abelx.c (2986B)


  1. /**
  2. * abelx.c
  3. *
  4. * Copyright 2020 astro <yuleiz@gmail.com>
  5. *
  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. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "abelx.h"
  20. #include "tca6424.h"
  21. #include "aw9523b.h"
  22. void set_pin(uint16_t pin)
  23. {
  24. uint8_t data = tca6424_read_port(GET_PORT(pin));
  25. data |= ( 1 << GET_PIN(pin));
  26. tca6424_write_port(GET_PORT(pin), data);
  27. }
  28. void clear_pin(uint16_t pin)
  29. {
  30. uint8_t data = tca6424_read_port(GET_PORT(pin));
  31. data &= ~( 1 << GET_PIN(pin));
  32. tca6424_write_port(GET_PORT(pin), data);
  33. }
  34. uint8_t read_pin(uint16_t pin)
  35. {
  36. uint8_t data = tca6424_read_port(GET_PORT(pin));
  37. return (data & (1<<GET_PIN(pin))) ? 1 : 0;
  38. }
  39. #ifdef RGBLIGHT_ENABLE
  40. #include "rgblight.h"
  41. #include "ws2812.h"
  42. #include "i2c_master.h"
  43. const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
  44. {AW9523B_P12_PWM, AW9523B_P11_PWM, AW9523B_P10_PWM},
  45. {AW9523B_P01_PWM, AW9523B_P00_PWM, AW9523B_P13_PWM},
  46. {AW9523B_P04_PWM, AW9523B_P03_PWM, AW9523B_P02_PWM},
  47. {AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
  48. };
  49. void init_custom(void) {
  50. aw9523b_init(AW9523B_ADDR);
  51. ws2812_init();
  52. }
  53. void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
  54. if (index < AW9523B_RGB_NUM) {
  55. aw9523b_set_color(index, red, green, blue);
  56. } else {
  57. ws2812_set_color(index - AW9523B_RGB_NUM, red, green, blue);
  58. }
  59. }
  60. void set_color_all_custom(uint8_t red, uint8_t green, uint8_t blue) {
  61. for (int i = 0; i < RGBLIGHT_LED_COUNT; i++) {
  62. set_color_custom(i, red, green, blue);
  63. }
  64. }
  65. void flush_custom(void) {
  66. aw9523b_update_pwm_buffers(AW9523B_ADDR);
  67. ws2812_flush();
  68. }
  69. const rgblight_driver_t rgblight_driver = {
  70. .init = init_custom,
  71. .set_color = set_color_custom,
  72. .set_color_all = set_color_all_custom,
  73. .flush = flush_custom,
  74. };
  75. #endif
  76. static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
  77. static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 0);
  78. bool led_update_kb(led_t led_state) {
  79. bool res = led_update_user(led_state);
  80. if (res) {
  81. led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin);
  82. led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin);
  83. }
  84. return res;
  85. }
  86. #define REBOOT_MAGIC 0x41544B42
  87. void bootloader_jump(void) {
  88. *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
  89. NVIC_SystemReset();
  90. }