lamparray_rgb_matrix.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2024 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "lamparray.h"
  4. #include "lamparray_surface.h"
  5. #include "rgb_matrix.h"
  6. /**
  7. * \brief Get feature specific lamp info.
  8. *
  9. * Scales the LED config with the assumed RGB Matrix dimensions (224x64), for simplicity, as a completely flat device.
  10. * Assumes all keys are either on the top or bottom of the resulting rectangle.
  11. */
  12. __attribute__((weak)) void lamparray_get_lamp_impl(uint16_t lamp_id, lamparray_attributes_response_t* data) {
  13. data->position.x = (LAMPARRAY_WIDTH / 224) * g_led_config.point[lamp_id].x;
  14. data->position.y = (LAMPARRAY_HEIGHT / 64) * g_led_config.point[lamp_id].y;
  15. if (g_led_config.flags[lamp_id] & LED_FLAG_UNDERGLOW) {
  16. data->position.z = LAMPARRAY_DEPTH;
  17. data->purposes = LAMP_PURPOSE_ACCENT;
  18. } else if (g_led_config.flags[lamp_id] & LED_FLAG_INDICATOR) {
  19. data->position.z = 0;
  20. data->purposes = LAMP_PURPOSE_STATUS;
  21. } else {
  22. data->position.z = 0;
  23. data->purposes = LAMP_PURPOSE_CONTROL;
  24. }
  25. }
  26. /**
  27. * \brief Query a HID usage for a given lamp
  28. */
  29. __attribute__((weak)) uint8_t lamparray_get_lamp_binding_impl(uint16_t lamp_id) {
  30. for (uint8_t i_row = 0; i_row < MATRIX_ROWS; i_row++) {
  31. for (uint8_t i_col = 0; i_col < MATRIX_COLS; i_col++) {
  32. if (g_led_config.matrix_co[i_row][i_col] == lamp_id) {
  33. return lamparray_binding_at_keymap_location(i_row, i_col);
  34. }
  35. }
  36. }
  37. return 0;
  38. }
  39. // TODO: temporay binding of storage and render
  40. #include "rgb_matrix/overlay.c"
  41. void lamparray_surface_enable(bool enable) {
  42. rgb_matrix_overlay_enable(enable);
  43. }
  44. void lamparray_surface_set_item(uint16_t index, lamp_state_t color) {
  45. rgb_matrix_overlay_set(index, (rgba_t){color.red, color.green, color.blue, color.intensity ? 0xFF : 0});
  46. }
  47. void lamparray_surface_update_finished(void) {
  48. rgb_matrix_overlay_flush();
  49. }