ws2812_f4.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 "color.h"
  27. /* --- PUBLIC MACROS -------------------------------------------------------- */
  28. /**
  29. * @brief Concatenates two symbols s1 and s2 exactly, without expanding either
  30. *
  31. * @param[in] s1: The first symbol to concatenate
  32. * @param[in] s2: The second symbol to concatenate
  33. *
  34. * @return A single symbol containing s1 and s2 concatenated without expansion
  35. */
  36. #define CONCAT_SYMBOLS(s1, s2) s1##s2
  37. /**
  38. * @brief Concatenate the symbols s1 and s2, expanding both of them
  39. *
  40. * This is important because simply applying s1##s2 doesn't expand them if they're
  41. * preprocessor tokens themselves
  42. *
  43. * @param[in] s1: The first symbol to concatenate
  44. * @param[in] s2: The second symbol to concatenate
  45. *
  46. * @return A single symbol containing s1 expanded followed by s2 expanded
  47. */
  48. #define CONCAT_EXPANDED_SYMBOLS(s1, s2) CONCAT_SYMBOLS(s1, s2)
  49. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  50. /**
  51. * @brief Return codes from ws2812 interface functions
  52. */
  53. typedef enum {
  54. WS2812_SUCCESS = 0x00, /**< Operation completeed successfully */
  55. WS2812_LED_INVALID, /**< Attempted to index an invalid LED (@ref WS2812_N_LEDS) */
  56. MAX_WS2812_ERR, /**< Total number of possible error codes */
  57. WS2812_ERR_INVALID /**< Invalid error value */
  58. } ws2812_err_t;
  59. /* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
  60. /**
  61. * @brief Initialize the driver
  62. *
  63. * After this function is called, all necessary background tasks will be started.
  64. * The frame is initially dark.
  65. */
  66. void ws2812_init(void);
  67. /**
  68. * @brief Write the value of a single LED in the chain
  69. *
  70. * The color value is written to a frame buffer, and will not
  71. * be updated until the next frame is written. Frames are written
  72. * at the maximum possible speed -- the longest latency between a
  73. * call to this function and the value being displayed is
  74. * 1.25uS*(24*@ref WS2812_LED_N + 50)
  75. *
  76. * @param[in] led_number: The index of the LED to be written. Must be strictly less than
  77. * @ref WS2812_N_LEDS
  78. * @param[in] r: The red level of the LED
  79. * @param[in] g: The green level of the LED
  80. * @param[in] b: The blue level of the LED
  81. *
  82. * @retval WS2812_SUCCESS: The write was successful
  83. * @retval WS2812_LED_INVALID: The write was to an invalid LED index
  84. */
  85. ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b);
  86. void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
  87. /** @} defgroup WS2812 */
  88. #endif // ifndef WS2812_H_