ares.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "ares.h"
  15. #ifdef RGBLIGHT_ENABLE
  16. #include <string.h>
  17. #include "i2c_master.h"
  18. #include "rgblight.h"
  19. extern rgblight_config_t rgblight_config;
  20. void matrix_init_kb(void) {
  21. i2c_init();
  22. // call user level keymaps, if any
  23. matrix_init_user();
  24. }
  25. // custom RGB driver
  26. void rgblight_set(void) {
  27. if (!rgblight_config.enable) {
  28. memset(led, 0, 3 * RGBLED_NUM);
  29. }
  30. i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
  31. }
  32. bool rgb_init = false;
  33. void matrix_scan_kb(void) {
  34. // if LEDs were previously on before poweroff, turn them back on
  35. if (rgb_init == false && rgblight_config.enable) {
  36. i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
  37. rgb_init = true;
  38. }
  39. rgblight_task();
  40. matrix_scan_user();
  41. }
  42. #endif
  43. #ifdef BACKLIGHT_ENABLE
  44. void backlight_init_ports(void) {
  45. setPinOutput(D0);
  46. setPinOutput(D1);
  47. setPinOutput(D4);
  48. setPinOutput(D6);
  49. }
  50. void backlight_set(uint8_t level) {
  51. if (level == 0) {
  52. // Turn out the lights
  53. writePinLow(D0);
  54. writePinLow(D1);
  55. writePinLow(D4);
  56. writePinLow(D6);
  57. } else {
  58. // Turn on the lights
  59. writePinHigh(D0);
  60. writePinHigh(D1);
  61. writePinHigh(D4);
  62. writePinHigh(D6);
  63. }
  64. }
  65. #endif
  66. // Optional override functions below.
  67. // You can leave any or all of these undefined.
  68. // These are only required if you want to perform custom actions.
  69. /*
  70. void matrix_init_kb(void) {
  71. // put your keyboard start-up code here
  72. // runs once when the firmware starts up
  73. matrix_init_user();
  74. }
  75. void matrix_scan_kb(void) {
  76. // put your looping keyboard code here
  77. // runs every cycle (a lot)
  78. matrix_scan_user();
  79. }
  80. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  81. // put your per-action keyboard code here
  82. // runs for every action, just before processing by the firmware
  83. return process_record_user(keycode, record);
  84. }
  85. void led_set_kb(uint8_t usb_led) {
  86. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  87. led_set_user(usb_led);
  88. }
  89. */