ws2812.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @file ws2812.h
  3. * @author Austin Glaser <austin.glaser@gmail.com>
  4. * @brief Interface to WS2812 LED driver
  5. *
  6. * Copyright (C) 2016 Austin Glaser
  7. *
  8. * This software may be modified and distributed under the terms
  9. * of the MIT license. See the LICENSE file for details.
  10. *
  11. * @todo Put in names and descriptions of variables which need to be defined to use this file
  12. */
  13. #ifndef WS2812_H_
  14. #define WS2812_H_
  15. /**
  16. * @defgroup WS2812 WS2812 Driver
  17. * @{
  18. *
  19. * @brief DMA-based WS2812 LED driver
  20. *
  21. * A driver for WS2812 LEDs
  22. */
  23. /* --- PUBLIC DEPENDENCIES -------------------------------------------------- */
  24. // Standard
  25. #include <stdint.h>
  26. #include "rgblight_types.h"
  27. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  28. /**
  29. * @brief Return codes from ws2812 interface functions
  30. */
  31. typedef enum {
  32. WS2812_SUCCESS = 0x00, /**< Operation completeed successfully */
  33. WS2812_LED_INVALID, /**< Attempted to index an invalid LED (@ref WS2812_N_LEDS) */
  34. MAX_WS2812_ERR, /**< Total number of possible error codes */
  35. WS2812_ERR_INVALID /**< Invalid error value */
  36. } ws2812_err_t;
  37. /* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
  38. /**
  39. * @brief Initialize the driver
  40. *
  41. * After this function is called, all necessary background tasks will be started.
  42. * The frame is initially dark.
  43. */
  44. void ws2812_init(void);
  45. /**
  46. * @brief Write the value of a single LED in the chain
  47. *
  48. * The color value is written to a frame buffer, and will not
  49. * be updated until the next frame is written. Frames are written
  50. * at the maximum possible speed -- the longest latency between a
  51. * call to this function and the value being displayed is
  52. * 1.25uS*(24*@ref WS2812_LED_N + 50)
  53. *
  54. * @param[in] led_number: The index of the LED to be written. Must be strictly less than
  55. * @ref WS2812_N_LEDS
  56. * @param[in] r: The red level of the LED
  57. * @param[in] g: The green level of the LED
  58. * @param[in] b: The blue level of the LED
  59. *
  60. * @retval WS2812_SUCCESS: The write was successful
  61. * @retval WS2812_LED_INVALID: The write was to an invalid LED index
  62. */
  63. ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b);
  64. /** @} defgroup WS2812 */
  65. void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
  66. void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
  67. /**
  68. * @brief Concatenates two symbols s1 and s2 exactly, without expanding either
  69. *
  70. * @param[in] s1: The first symbol to concatenate
  71. * @param[in] s2: The second symbol to concatenate
  72. *
  73. * @return A single symbol containing s1 and s2 concatenated without expansion
  74. */
  75. #define CONCAT_SYMBOLS(s1, s2) s1##s2
  76. /**
  77. * @brief Concatenate the symbols s1 and s2, expanding both of them
  78. *
  79. * This is important because simply applying s1##s2 doesn't expand them if they're
  80. * preprocessor tokens themselves
  81. *
  82. * @param[in] s1: The first symbol to concatenate
  83. * @param[in] s2: The second symbol to concatenate
  84. *
  85. * @return A single symbol containing s1 expanded followed by s2 expanded
  86. */
  87. #define CONCAT_EXPANDED_SYMBOLS(s1, s2) CONCAT_SYMBOLS(s1, s2)
  88. #endif /* WS2812_H_ */