blob: f7381375d0e731e7508e958f6f102be606453ec8 (
plain)
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
|
// vim: tabstop=4 shiftwidth=4 noexpandtab
/*
ws2812
This low-level library gives you access to ws2812 LEDs and
LED strips via libopencm3. Please use it like this:
- connect the data pin (DIN) of the ws2812 to a GPIO of
your MCU
- initialize clock to a sysclock speed of 72 MHz
- initialize the GPIO pin with GPIO_MODE_OUTPUT_50_MHZ and
GPIO_CNF_OUTPUT_PUSHPULL
- create a WS2812_ARRAY control struct
- create a uint8_t[ARRAY_LENGTH * 3] buffer
- call ws2812_init() with your control struct and buffer
- adjust values on the buffer
- use ws2812_write_buffer_to_leds() to set the LEDs
The uint8_t buffer has the following structure:
----------------------------------------------------- ...
| | | | | | | | | | ...
| R | G | B | R | G | B | R | G | B | ...
| | | | | | | | | | ...
----------------------------------------------------- ...
first led second led third led ...
Please mention that this library will never have features
to make fancy animations and so on. It is designed just to
access the LEDs on a physical layer. To avoid bad code
quality due to unnecessary features it will never do more
than this ...
Technical note: This library is based on delays. This is not
the best way. Maybe it will change to interrupt or DMA use in
the future.
*/
#ifndef WS2812_H
#define WS2812_H
#include <stdlib.h>
#include <libopencm3/stm32/gpio.h>
#define WS2812_NUMBER_OF_COLORS 3
typedef struct WS2812_ARRAY{
uint32_t gpio_port;
uint16_t gpio_pin;
uint8_t *array_buffer;
uint32_t array_length;
}WS2812_ARRAY;
// public API functions:
void ws2812_init(WS2812_ARRAY *control_struct, uint32_t port, uint16_t pin, uint8_t *buffer_ptr, uint32_t array_length);
void ws2812_clear_buffer(WS2812_ARRAY *control_struct);
void ws2812_write_buffer_to_leds(WS2812_ARRAY *control_struct);
// internal functions:
void ws2812_send_reset(WS2812_ARRAY *control_struct);
void ws2812_send_zero(WS2812_ARRAY *control_struct);
void ws2812_send_one(WS2812_ARRAY *control_struct);
void ws2812_send_byte(WS2812_ARRAY *control_struct, uint8_t data);
#endif /* WS2812_H */
|