-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeoPixel_WS2812B.h
87 lines (65 loc) · 2.02 KB
/
NeoPixel_WS2812B.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Using SPI interface
* SPI Bandwidth required 4.5Mbit/S
*/
#ifndef NEOPIXEL_WS2812B_H
#define NEOPIXEL_WS2812B_H
#include "stm32f1xx_hal.h"
#include "spi.h"
#define BIT1 0x78 // b 0111 1000
#define BIT0 0x60 // b 0110 0000
/*The lower limit for H*/
#define HUE_LOWER_LIMIT (0.0)
/*The upper limit for H*/
#define HUE_UPPER_LIMIT (360.0)
typedef enum
{
BUSY = 0x00U,
READY = 0x01U,
UPDATE = 0x02U
} BSP_UpdateEnumDef;
typedef struct
{
SPI_HandleTypeDef* hspi;
uint32_t* pPixelBuffer; /*!< 缓存指针 */
uint8_t* pSendBuffer; /*!< 发送指针 */
//uint8_t Brightness; /*!< 亮度参数 */
uint16_t PixelLen; /*!< 像素数量 */
uint16_t BuffLen; /*!< 缓存长度 */
__IO BSP_UpdateEnumDef state; /*!< 状态 */
} WS28_HandleTypeDef;
void WS28_init(WS28_HandleTypeDef *hws28);
// Color data covert.
/*
* Converting RGB to 0xFFFFFF format color code.
*
*/uint32_t WS28_RGB2COLOR(uint8_t r, uint8_t g, uint8_t b);
/*
* Converting HSL to 0xFFFFFF format color code.
* Para: H - Hue 0~360, S - Sat 0~100, L - Lightness 0~100
*
*/uint32_t WS28_HSL2COLOR(double H, double S, double L);
// Command function.
/*
* Change current "lightness" for all LED.
* Prarm: hws28 - WS2812 Handle,
* scale - new lightness, 0~100
*
*/void WS28_SET_BRIGHTNESS(WS28_HandleTypeDef *hws28, uint8_t scale);
/*
* Set color for all color pixel.
* Prarm: hws28 - WS2812 Handle,
* color - coverted color in 0xFFFFFF format.
*
*/void WS28_SET_COLOR_ALL(WS28_HandleTypeDef *hws28, uint32_t color);
/*
* Set color for all color pixel.
* Prarm: hws28 - WS2812 Handle,
* pos - index of pixel, base 0.
* color - coverted color in 0xFFFFFF format.
*
*/void WS28_SET_COLOR_PIXEL(WS28_HandleTypeDef *hws28, uint8_t pos, uint32_t color);
// Private Function, not declear for extern use.
//void WS28_COLOR2BIT(uint32_t color, uint8_t *colorbit);
//void WS28_REFRESH(WS28_HandleTypeDef *hws28);
#endif