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.

150 lines
3.7 KiB

  1. /* Copyright 2017 Jason Williams
  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. #pragma once
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. // clang-format off
  20. /*
  21. * RGB Colors
  22. */
  23. #define RGB_AZURE 0x99, 0xF5, 0xFF
  24. #define RGB_BLACK 0x00, 0x00, 0x00
  25. #define RGB_BLUE 0x00, 0x00, 0xFF
  26. #define RGB_CHARTREUSE 0x80, 0xFF, 0x00
  27. #define RGB_CORAL 0xFF, 0x7C, 0x4D
  28. #define RGB_CYAN 0x00, 0xFF, 0xFF
  29. #define RGB_GOLD 0xFF, 0xD9, 0x00
  30. #define RGB_GOLDENROD 0xD9, 0xA5, 0x21
  31. #define RGB_GREEN 0x00, 0xFF, 0x00
  32. #define RGB_MAGENTA 0xFF, 0x00, 0xFF
  33. #define RGB_ORANGE 0xFF, 0x80, 0x00
  34. #define RGB_PINK 0xFF, 0x80, 0xBF
  35. #define RGB_PURPLE 0x7A, 0x00, 0xFF
  36. #define RGB_RED 0xFF, 0x00, 0x00
  37. #define RGB_SPRINGGREEN 0x00, 0xFF, 0x80
  38. #define RGB_TEAL 0x00, 0x80, 0x80
  39. #define RGB_TURQUOISE 0x47, 0x6E, 0x6A
  40. #define RGB_WHITE 0xFF, 0xFF, 0xFF
  41. #define RGB_YELLOW 0xFF, 0xFF, 0x00
  42. #define RGB_OFF RGB_BLACK
  43. /*
  44. * HSV Colors
  45. *
  46. * All values (including hue) are scaled to 0-255
  47. */
  48. #define HSV_AZURE 132, 102, 255
  49. #define HSV_BLACK 0, 0, 0
  50. #define HSV_BLUE 170, 255, 255
  51. #define HSV_CHARTREUSE 64, 255, 255
  52. #define HSV_CORAL 11, 176, 255
  53. #define HSV_CYAN 128, 255, 255
  54. #define HSV_GOLD 36, 255, 255
  55. #define HSV_GOLDENROD 30, 218, 218
  56. #define HSV_GREEN 85, 255, 255
  57. #define HSV_MAGENTA 213, 255, 255
  58. #define HSV_ORANGE 28, 255, 255
  59. #define HSV_PINK 234, 128, 255
  60. #define HSV_PURPLE 191, 255, 255
  61. #define HSV_RED 0, 255, 255
  62. #define HSV_SPRINGGREEN 106, 255, 255
  63. #define HSV_TEAL 128, 255, 128
  64. #define HSV_TURQUOISE 123, 90, 112
  65. #define HSV_WHITE 0, 0, 255
  66. #define HSV_YELLOW 43, 255, 255
  67. #define HSV_OFF HSV_BLACK
  68. // clang-format on
  69. #if defined(__GNUC__)
  70. # define PACKED __attribute__((__packed__))
  71. #else
  72. # define PACKED
  73. #endif
  74. #if defined(_MSC_VER)
  75. # pragma pack(push, 1)
  76. #endif
  77. #ifdef RGBW
  78. # define LED_TYPE cRGBW
  79. #else
  80. # define LED_TYPE RGB
  81. #endif
  82. #define WS2812_BYTE_ORDER_RGB 0
  83. #define WS2812_BYTE_ORDER_GRB 1
  84. #define WS2812_BYTE_ORDER_BGR 2
  85. #ifndef WS2812_BYTE_ORDER
  86. # define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB
  87. #endif
  88. typedef struct PACKED {
  89. #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
  90. uint8_t g;
  91. uint8_t r;
  92. uint8_t b;
  93. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
  94. uint8_t r;
  95. uint8_t g;
  96. uint8_t b;
  97. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
  98. uint8_t b;
  99. uint8_t g;
  100. uint8_t r;
  101. #endif
  102. } cRGB;
  103. typedef cRGB RGB;
  104. // WS2812 specific layout
  105. typedef struct PACKED {
  106. #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
  107. uint8_t g;
  108. uint8_t r;
  109. uint8_t b;
  110. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
  111. uint8_t r;
  112. uint8_t g;
  113. uint8_t b;
  114. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
  115. uint8_t b;
  116. uint8_t g;
  117. uint8_t r;
  118. #endif
  119. uint8_t w;
  120. } cRGBW;
  121. typedef struct PACKED {
  122. uint8_t h;
  123. uint8_t s;
  124. uint8_t v;
  125. } HSV;
  126. #if defined(_MSC_VER)
  127. # pragma pack(pop)
  128. #endif
  129. RGB hsv_to_rgb(HSV hsv);
  130. RGB hsv_to_rgb_nocie(HSV hsv);
  131. #ifdef RGBW
  132. void convert_rgb_to_rgbw(LED_TYPE *led);
  133. #endif