ws2812.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //WS2812灯带控制器
  2. #ifndef __WS2812_H__
  3. #define __WS2812_H__
  4. #include <stdint.h>
  5. #include "main.h"
  6. #define WS2812_NUM 5 //灯珠数量(分边)
  7. #define WS2812_IO PA3 //引脚
  8. #define BREATH_NUM 50 //呼吸灯变化次数
  9. typedef enum
  10. {
  11. BEEP_MUTE = 0x00,/*静默*/
  12. BEEP_ERR_HW = 0x01,/*设备故障*/
  13. BEEP_ERR_HM = 0x02,/*操作故障*/
  14. BEEP_SCANOK = 0x03,/*扫码成功*/
  15. BEEP_WORKEND = 0x04/*完成*/
  16. } BEEPTYPE;
  17. struct str_ws2812
  18. {
  19. uint32_t light_color[2];
  20. uint32_t light_color_use[2];
  21. uint8_t light_mode[2];
  22. uint16_t light_speed[2];
  23. uint8_t breath_count[2];
  24. uint8_t breath_dir[2];
  25. };
  26. enum light_mode_type
  27. {
  28. MODE_NORMAL, //常亮
  29. MODE_BLINK, //闪烁
  30. MODE_BREATH, //呼吸
  31. };
  32. enum light_color_type
  33. {
  34. COLOR_BLUE = 0x000088, //蓝
  35. COLOR_GREEN = 0x008800, //绿
  36. COLOR_RED = 0x880000, //红
  37. COLOR_YELLOW = 0x888800, //黄
  38. };
  39. void light_ctrl(void);
  40. void light_refresh(uint32_t rgb_left, uint32_t rgb_right);
  41. void light_set(uint8_t mode_select, uint16_t speed_ms, uint32_t rgb_color, uint8_t channel);
  42. void beep_set(BEEPTYPE beep);
  43. #endif