lamparray.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright 2024 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #include "util.h" // PACKED
  7. #define LAMPARRAY_REPORT_ID_ATTRIBUTES 0x01
  8. #define LAMPARRAY_REPORT_ID_ATTRIBUTES_REQUEST 0x02
  9. #define LAMPARRAY_REPORT_ID_ATTRIBUTES_RESPONSE 0x03
  10. #define LAMPARRAY_REPORT_ID_MULTI_UPDATE 0x04
  11. #define LAMPARRAY_REPORT_ID_RANGE_UPDATE 0x05
  12. #define LAMPARRAY_REPORT_ID_CONTROL 0x06
  13. // 26.2.1 LampArrayKind Values
  14. #define LAMPARRAY_KIND_UNDEFINED 0x00
  15. #define LAMPARRAY_KIND_KEYBOARD 0x01
  16. #define LAMPARRAY_KIND_MOUSE 0x02
  17. #define LAMPARRAY_KIND_GAMECONTROLLER 0x03
  18. #define LAMPARRAY_KIND_PERIPHERAL 0x04
  19. #define LAMPARRAY_KIND_SCENE 0x05
  20. #define LAMPARRAY_KIND_NOTIFICATION 0x06
  21. #define LAMPARRAY_KIND_CHASSIS 0x07
  22. #define LAMPARRAY_KIND_WEARABLE 0x08
  23. #define LAMPARRAY_KIND_FURNITURE 0x09
  24. #define LAMPARRAY_KIND_ART 0x0A
  25. // 26.3.1 LampPurposes Flags
  26. #define LAMP_PURPOSE_CONTROL 0x01
  27. #define LAMP_PURPOSE_ACCENT 0x02
  28. #define LAMP_PURPOSE_BRANDING 0x04
  29. #define LAMP_PURPOSE_STATUS 0x08
  30. #define LAMP_PURPOSE_ILLUMINATION 0x10
  31. #define LAMP_PURPOSE_PRESENTATION 0x20
  32. // 26.4.1 LampUpdate Flags
  33. #define LAMP_UPDATE_FLAG_COMPLETE 0x01
  34. typedef struct PACKED {
  35. uint8_t red;
  36. uint8_t green;
  37. uint8_t blue;
  38. uint8_t intensity;
  39. } lamp_state_t;
  40. typedef struct PACKED {
  41. uint16_t lamp_count;
  42. struct {
  43. uint32_t width;
  44. uint32_t height;
  45. uint32_t depth;
  46. } bounds;
  47. uint32_t kind;
  48. uint32_t update_interval;
  49. } lamparray_attributes_t;
  50. typedef struct PACKED {
  51. uint16_t lamp_id;
  52. struct {
  53. int32_t x;
  54. int32_t y;
  55. int32_t z;
  56. } position;
  57. int32_t update_latency;
  58. int32_t purposes;
  59. lamp_state_t levels;
  60. uint8_t is_programmable;
  61. uint8_t input_binding;
  62. } lamparray_attributes_response_t;
  63. typedef struct PACKED {
  64. uint8_t flags;
  65. uint16_t start;
  66. uint16_t end;
  67. lamp_state_t color;
  68. } lamparray_range_update_t;
  69. #define LAMP_MULTI_UPDATE_LAMP_COUNT 8
  70. typedef struct PACKED {
  71. uint8_t count;
  72. uint8_t flags;
  73. uint16_t ids[LAMP_MULTI_UPDATE_LAMP_COUNT];
  74. lamp_state_t colors[LAMP_MULTI_UPDATE_LAMP_COUNT];
  75. } lamparray_multi_update_t;
  76. typedef struct PACKED universal_lamparray_response_t {
  77. uint8_t report_id;
  78. union {
  79. struct {
  80. uint16_t lamp_id;
  81. };
  82. struct {
  83. uint8_t autonomous;
  84. };
  85. lamparray_range_update_t range_update;
  86. lamparray_multi_update_t multi_update;
  87. };
  88. } universal_lamparray_response_t;
  89. typedef struct PACKED lamparray_attributes_report_t {
  90. uint8_t report_id;
  91. lamparray_attributes_t attributes;
  92. } lamparray_attributes_report_t;
  93. typedef struct PACKED lamparray_attributes_response_report_t {
  94. uint8_t report_id;
  95. lamparray_attributes_response_t attributes_response;
  96. } lamparray_attributes_response_report_t;
  97. /**
  98. * \brief Gets LampArrayAttributesReport data
  99. */
  100. void lamparray_get_attributes(lamparray_attributes_t* data);
  101. /**
  102. * \brief Sets LampAttributesRequestReport data
  103. */
  104. void lamparray_set_attributes_response(uint16_t lamp_id);
  105. /**
  106. * \brief Gets LampAttributesResponseReport data
  107. */
  108. void lamparray_get_attributes_response(lamparray_attributes_response_t* data);
  109. /**
  110. * \brief Sets LampRangeUpdateReport data
  111. */
  112. void lamparray_set_range(lamparray_range_update_t* data);
  113. /**
  114. * \brief Sets LampMultiUpdateReport data
  115. */
  116. void lamparray_set_items(lamparray_multi_update_t* data);
  117. /**
  118. * \brief Sets LampArrayControlReport data
  119. */
  120. void lamparray_set_control_response(uint8_t autonomous);
  121. //****************************************************************************
  122. // utils
  123. uint8_t lamparray_binding_at_keymap_location(uint8_t row, uint8_t col);
  124. void lamparray_queue_request(universal_lamparray_response_t* report);
  125. //****************************************************************************
  126. // feature hooks
  127. void lamparray_init(void);
  128. void lamparray_task(void);
  129. //****************************************************************************
  130. // lighting framework bindings
  131. void lamparray_get_lamp_impl(uint16_t lamp_id, lamparray_attributes_response_t* data);
  132. uint8_t lamparray_get_lamp_binding_impl(uint16_t lamp_id);