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.

66 lines
1.9 KiB

  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[DRIVER_LED_TOTAL];
  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. void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
  33. if (r != led_colors[led_pos[index]].p.red ||
  34. g != led_colors[led_pos[index]].p.green ||
  35. b != led_colors[led_pos[index]].p.blue)
  36. {
  37. led_colors[led_pos[index]] = (ap2_led_t){
  38. .p.blue = b,
  39. .p.red = r,
  40. .p.green = g,
  41. .p.alpha = 0xff,
  42. };
  43. int row = led_pos[index] / NUM_COLUMN;
  44. rgb_row_changed[row] = 1;
  45. }
  46. }
  47. void set_color_all(uint8_t r, uint8_t g, uint8_t b) {
  48. for (int i=0; i<DRIVER_LED_TOTAL; i++)
  49. set_color(i, r, g, b);
  50. }
  51. const rgb_matrix_driver_t rgb_matrix_driver = {
  52. .init = init,
  53. .flush = flush,
  54. .set_color = set_color,
  55. .set_color_all = set_color_all,
  56. };
  57. #endif