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