diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-01-26 16:05:27 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-01-26 16:05:27 +0100 |
commit | 60849a62e04769aff854781e6cafa67b7025ed73 (patch) | |
tree | abe07c2472e3b43795fb7dec611f36d5df23f95f /libraries/ws2812.h | |
parent | 17857f69f675141a814c80975545afb7c13dc675 (diff) | |
download | stm32f103c8-examples-60849a62e04769aff854781e6cafa67b7025ed73.tar stm32f103c8-examples-60849a62e04769aff854781e6cafa67b7025ed73.tar.zst stm32f103c8-examples-60849a62e04769aff854781e6cafa67b7025ed73.zip |
Diffstat (limited to 'libraries/ws2812.h')
-rw-r--r-- | libraries/ws2812.h | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/libraries/ws2812.h b/libraries/ws2812.h index c6c85d9..f738137 100644 --- a/libraries/ws2812.h +++ b/libraries/ws2812.h @@ -1,3 +1,42 @@ +// 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 @@ -20,18 +59,19 @@ typedef struct WS2812_ARRAY{ }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); -void ws2812_send_led(WS2812_ARRAY *control_struct, uint8_t red, uint8_t green, uint8_t blue); - -void ws2812_write_leds(WS2812_ARRAY *control_struct); -void ws2812_set_array_led(WS2812_ARRAY *control_struct, uint32_t index, uint8_t red, uint8_t green, uint8_t blue); -void ws2812_clear_buffer(WS2812_ARRAY *control_struct); #endif /* WS2812_H */ |