logo

qmk_firmware

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

rgb_driver.c (1786B)


  1. /* Copyright 2022 Jose Pablo Ramirez <jp.ramangulo@gmail.com>
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifdef RGB_MATRIX_ENABLE
  17. # include "rgb_matrix.h"
  18. # include "ap2_led.h"
  19. uint8_t led_pos[RGB_MATRIX_LED_COUNT];
  20. void init(void) {
  21. unsigned int i = 0;
  22. for (unsigned int y = 0; y < NUM_ROW; y++) {
  23. for (unsigned int x = 0; x < NUM_COLUMN; x++) {
  24. if (g_led_config.matrix_co[y][x] != NO_LED) {
  25. led_pos[g_led_config.matrix_co[y][x]] = i;
  26. }
  27. i++;
  28. }
  29. }
  30. }
  31. void flush(void) {
  32. for (uint8_t row = 0; row < NUM_ROW; row++)
  33. ap2_led_colors_set_row(row);
  34. }
  35. void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
  36. led_colors[led_pos[index]] = (ap2_led_t){
  37. .p.blue = b,
  38. .p.red = r,
  39. .p.green = g,
  40. .p.alpha = 0xff,
  41. };
  42. }
  43. void set_color_all(uint8_t r, uint8_t g, uint8_t b) {
  44. for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++)
  45. set_color(i, r, g, b);
  46. }
  47. const rgb_matrix_driver_t rgb_matrix_driver = {
  48. .init = init,
  49. .flush = flush,
  50. .set_color = set_color,
  51. .set_color_all = set_color_all,
  52. };
  53. #endif