Nathaniel Wesley Filardo 85df6b588d
LED strip refactor (#3158)
`ws2812` buffer extracted to new `pixbuf` module.

* The new pixbuf module has more functionality than the `ws2812`-specific buffer it replaces.
* This is work in progress towards https://github.com/nodemcu/nodemcu-firmware/issues/2916
* The LED driver modules `ws2812`, `ws2801`, `apa102`, and `tm1829` have sprouted `pixbuf` support.
* `NTest` tests for `pixbuf` now exist.

While here, document the ws2812 UART-based overlapping with mainline
execution.  Fixes https://github.com/nodemcu/nodemcu-firmware/issues/3140

Co-authored-by: Gregor Hartmann <HHHartmann@users.noreply.github.com>
2021-01-06 23:35:34 +00:00

51 lines
1.3 KiB
C

#ifndef APP_MODULES_PIXBUF_H_
#define APP_MODULES_PIXBUF_H_
typedef struct pixbuf {
const size_t npix;
const size_t nchan;
/* Flexible Array Member; true size is npix * pixbuf_channels_for(type) */
uint8_t values[];
} pixbuf;
enum pixbuf_fade {
PIXBUF_FADE_IN,
PIXBUF_FADE_OUT
};
enum pixbuf_shift {
PIXBUF_SHIFT_LOGICAL,
PIXBUF_SHIFT_CIRCULAR
};
pixbuf *pixbuf_from_lua_arg(lua_State *, int);
const size_t pixbuf_size(pixbuf *);
// Exported for backwards compat with ws2812 module
int pixbuf_new_lua(lua_State *);
/*
* WS2812_EFFECTS does pixbuf manipulation directly in C, which isn't the
* intended use case, but for backwards compat, we export just what it needs.
* Move this struct to pixbuf.c and mark these exports static instead once
* WS2812_EFFECTS is no more.
*/
struct pixbuf_shift_params {
enum pixbuf_shift type;
// 0 <= offset <= buffer length
size_t offset;
// 0 <= window + offset <= buffer length
size_t window;
// 0 <= shift <= window_size
size_t shift;
bool shiftLeft;
};
void pixbuf_shift(pixbuf *, struct pixbuf_shift_params *);
void pixbuf_prepare_shift(pixbuf *, struct pixbuf_shift_params *,
int val, enum pixbuf_shift, int start, int end);
const size_t pixbuf_channels(pixbuf *);
/* end WS2812_EFFECTS exports */
#endif