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.

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