ws2812.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef _WS2812_H
  2. #define _WS2812_H
  3. #define WSGPIO 0
  4. #include "c_types.h"
  5. #include "user_interface.h"
  6. #include "ets_sys.h"
  7. #include "gpio.h"
  8. #include "ets_sys.h"
  9. #include "osapi.h"
  10. #include "math.h"
  11. #include "log/esp_log.h"
  12. /*------------------------------------------------------------------------------*/
  13. // Configuration Parameters
  14. /*------------------------------------------------------------------------------*/
  15. #define WS2811_COMPATIBLE 0 // set to make driver backwards compatable.
  16. #define WS2812_REFRESH_INTERVAL 60 // timer to update WS2812
  17. #define WS2812_RED_INDEX 1
  18. #define WS2812_GREEN_INDEX 0
  19. #define WS2812_BLUE_INDEX 2
  20. typedef enum {
  21. WS2812_OFF = 0,
  22. WS2812_RED,
  23. WS2812_BLUE,
  24. WS2812_GREEN,
  25. WS2812_MAGENTA,
  26. WS2812_ORANGE
  27. } WS2812_COLOR_et;
  28. typedef enum {
  29. WS2812_SOLID = 0,
  30. WS2812_PULSE
  31. } WS2812_PATTERN_et;
  32. typedef enum {
  33. WS2812_UP = 0,
  34. WS2812_DOWN
  35. } WS2812_DIRECTION_et;
  36. typedef struct {
  37. WS2812_COLOR_et color;
  38. WS2812_PATTERN_et pattern;
  39. uint8_t color_mask[3];
  40. uint32_t led_state;
  41. WS2812_DIRECTION_et direction;
  42. } WS2812_CONFIG_t;
  43. /*------------------------------------------------------------------------------*/
  44. //You will have to os_intr_lock(); os_intr_unlock();
  45. /*
  46. NOTE: The first byte stored is the last byte sent. 50us is required for sent data to latch to all LEDS
  47. Data is stored in the following format:
  48. [ byte1: green, byte2: red, byte3: blue]
  49. NOTE: Every function except ws2812_outBuffer is stored in Flash.
  50. */
  51. /*------------------------------------------------------------------------------*/
  52. // Function Prototypes
  53. /*------------------------------------------------------------------------------*/
  54. void WS2812_OutBuffer(int8_t * buffer, uint16_t length);
  55. void WS2812_SetColor(WS2812_COLOR_et color, WS2812_PATTERN_et pattern);
  56. // void ws2812_green(void);
  57. // void ws2812_red(void);
  58. // void ws2812_blue(void);
  59. // void ws2812_clear(void);
  60. /*------------------------------------------------------------------------------*/
  61. #endif