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.

105 lines
2.8 KiB

  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. void matrix_init_kb(void) {
  40. #ifdef RGBLIGHT_ENABLE
  41. aw9523b_init(AW9523B_ADDR);
  42. #endif
  43. matrix_init_user();
  44. }
  45. void housekeeping_task_kb(void) {
  46. #ifdef RGBLIGHT_ENABLE
  47. aw9523b_update_pwm_buffers(AW9523B_ADDR);
  48. #endif
  49. }
  50. #ifdef RGBLIGHT_ENABLE
  51. #include "rgblight.h"
  52. #include "ws2812.h"
  53. #include "i2c_master.h"
  54. const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
  55. {AW9523B_P12_PWM, AW9523B_P11_PWM, AW9523B_P10_PWM},
  56. {AW9523B_P01_PWM, AW9523B_P00_PWM, AW9523B_P13_PWM},
  57. {AW9523B_P04_PWM, AW9523B_P03_PWM, AW9523B_P02_PWM},
  58. {AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
  59. };
  60. void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
  61. {
  62. uint8_t num = num_leds < AW9523B_RGB_NUM ? num_leds : AW9523B_RGB_NUM;
  63. ws2812_setleds(start_led, num);
  64. for (int i = 0; i < num; i++) {
  65. aw9523b_set_color(i, start_led[i].r, start_led[i].g, start_led[i].b);
  66. }
  67. }
  68. const rgblight_driver_t rgblight_driver = {
  69. .init = ws2812_init,
  70. .setleds = setleds_custom,
  71. };
  72. #endif
  73. static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
  74. static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 0);
  75. bool led_update_kb(led_t led_state) {
  76. bool res = led_update_user(led_state);
  77. if (res) {
  78. led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin);
  79. led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin);
  80. }
  81. return res;
  82. }
  83. #define REBOOT_MAGIC 0x41544B42
  84. void bootloader_jump(void) {
  85. *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
  86. NVIC_SystemReset();
  87. }