better neopixel commands for sparse writing
This commit is contained in:
@@ -32,28 +32,16 @@ error_t UU_Npx_Load(Unit *unit, const uint8_t *packed_rgb, uint32_t nbytes)
|
||||
}
|
||||
|
||||
/* Load U32, LE or BE */
|
||||
static error_t load_u32(Unit *unit, const uint8_t *bytes, uint32_t nbytes, bool bige)
|
||||
error_t UU_Npx_Load32(Unit *unit, const uint8_t *bytes, uint32_t nbytes, bool order_bgr, bool zero_before)
|
||||
{
|
||||
CHECK_TYPE(unit, &UNIT_NEOPIXEL);
|
||||
|
||||
struct priv *priv = unit->data;
|
||||
if (nbytes != 4*priv->cfg.pixels) return E_BAD_COUNT;
|
||||
ws2812_load_sparse(priv->port, priv->ll_pin, bytes, priv->cfg.pixels, bige);
|
||||
ws2812_load_sparse(priv->port, priv->ll_pin, bytes, priv->cfg.pixels, order_bgr, zero_before);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
/* Load U32, LE */
|
||||
inline error_t UU_Npx_LoadU32LE(Unit *unit, const uint8_t *bytes, uint32_t nbytes)
|
||||
{
|
||||
return load_u32(unit, bytes, nbytes, false);
|
||||
}
|
||||
|
||||
/* Load U32, BE */
|
||||
inline error_t UU_Npx_LoadU32BE(Unit *unit, const uint8_t *bytes, uint32_t nbytes)
|
||||
{
|
||||
return load_u32(unit, bytes, nbytes, true);
|
||||
}
|
||||
|
||||
/* Get the pixel count */
|
||||
error_t UU_Npx_GetCount(Unit *unit, uint16_t *count)
|
||||
{
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
enum PinCmd_ {
|
||||
CMD_CLEAR = 0,
|
||||
CMD_LOAD = 1,
|
||||
CMD_LOAD_U32_LE = 2,
|
||||
CMD_LOAD_U32_BE = 3,
|
||||
CMD_GET_LEN = 4,
|
||||
CMD_LOAD_ZRGB = 0x08, // 0,0 - trail zero, bgr
|
||||
CMD_LOAD_ZBGR = 0x09, // 0,1
|
||||
CMD_LOAD_RGBZ = 0x0A, // 1,0
|
||||
CMD_LOAD_BGRZ = 0x0B, // 1,1
|
||||
CMD_GET_LEN = 0x10,
|
||||
};
|
||||
|
||||
/** Handle a request message */
|
||||
@@ -32,15 +34,15 @@ static error_t Npx_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Pa
|
||||
bytes = pp_tail(pp, &len);
|
||||
return UU_Npx_Load(unit, bytes, len);
|
||||
|
||||
/** Load sparse (uint32_t) colors, 0x00RRGGBB, little endian. */
|
||||
case CMD_LOAD_U32_LE:
|
||||
/** Load sparse (uint32_t) colors */
|
||||
case CMD_LOAD_ZRGB:
|
||||
case CMD_LOAD_ZBGR:
|
||||
case CMD_LOAD_RGBZ:
|
||||
case CMD_LOAD_BGRZ:
|
||||
bytes = pp_tail(pp, &len);
|
||||
return UU_Npx_LoadU32LE(unit, bytes, len);
|
||||
|
||||
/** Load sparse (uint32_t) colors, 0x00RRGGBB, big endian. */
|
||||
case CMD_LOAD_U32_BE:
|
||||
bytes = pp_tail(pp, &len);
|
||||
return UU_Npx_LoadU32BE(unit, bytes, len);
|
||||
bool trail_zero = (bool) (command & 0b10);
|
||||
bool order_bgr = (bool) (command & 0b01);
|
||||
return UU_Npx_Load32(unit, bytes, len, order_bgr, !trail_zero);
|
||||
|
||||
/** Get the Neopixel strip length */
|
||||
case CMD_GET_LEN:;
|
||||
|
||||
@@ -31,26 +31,15 @@ error_t UU_Npx_Clear(Unit *unit);
|
||||
error_t UU_Npx_Load(Unit *unit, const uint8_t *packed_rgb, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* Load the strip with sparse (uint32_t) colors 0x00RRGGBB as little endian bytes
|
||||
* (B, G, R, 0, ...)
|
||||
*
|
||||
* Load from 32-bit numbers
|
||||
* @param unit
|
||||
* @param bytes - bytes to load
|
||||
* @param nbytes - number of bytes, must be count*4
|
||||
* @param bytes
|
||||
* @param nbytes
|
||||
* @param order_bgr
|
||||
* @param zero_before
|
||||
* @return success
|
||||
*/
|
||||
error_t UU_Npx_LoadU32LE(Unit *unit, const uint8_t *bytes, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* Load the strip with sparse (uint32_t) colors 0x00RRGGBB as big endian bytes
|
||||
* (0, R, G, B, ...)
|
||||
*
|
||||
* @param unit
|
||||
* @param bytes - bytes to load
|
||||
* @param nbytes - number of bytes, must be count*4
|
||||
* @return success
|
||||
*/
|
||||
error_t UU_Npx_LoadU32BE(Unit *unit, const uint8_t *bytes, uint32_t nbytes);
|
||||
error_t UU_Npx_Load32(Unit *unit, const uint8_t *bytes, uint32_t nbytes, bool order_bgr, bool zero_before);
|
||||
|
||||
/**
|
||||
* Get number of pixels on the strip
|
||||
|
||||
@@ -45,13 +45,14 @@ void ws2812_load_raw(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs, u
|
||||
}
|
||||
|
||||
/** Set many RGBs from uint32 stream */
|
||||
void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs, uint32_t count, bool bigendian)
|
||||
void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs, uint32_t count,
|
||||
bool order_bgr, bool zero_before)
|
||||
{
|
||||
vPortEnterCritical();
|
||||
uint8_t b, g, r;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (bigendian) {
|
||||
rgbs++; // skip
|
||||
if (zero_before) rgbs++; // skip
|
||||
if (order_bgr) {
|
||||
b = *rgbs++;
|
||||
g = *rgbs++;
|
||||
r = *rgbs++;
|
||||
@@ -59,8 +60,8 @@ void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs
|
||||
r = *rgbs++;
|
||||
g = *rgbs++;
|
||||
b = *rgbs++;
|
||||
rgbs++; // skip
|
||||
}
|
||||
if (!zero_before) rgbs++; // skip
|
||||
|
||||
ws2812_byte(port, ll_pin, g);
|
||||
ws2812_byte(port, ll_pin, r);
|
||||
|
||||
@@ -28,8 +28,10 @@ void ws2812_clear(GPIO_TypeDef *port, uint32_t ll_pin, uint32_t count);
|
||||
* @param ll_pin
|
||||
* @param rgbs - payload
|
||||
* @param count - number of pixels
|
||||
* @param bigendian - big endian ordering
|
||||
* @param order_bgr - B,G,R colors, false - R,G,B
|
||||
* @param zero_before - insert padding byte before colors, false - after
|
||||
*/
|
||||
void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs, uint32_t count, bool bigendian);
|
||||
void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, const uint8_t *rgbs, uint32_t count,
|
||||
bool order_bgr, bool zero_before);
|
||||
|
||||
#endif //WS2812_H
|
||||
|
||||
Reference in New Issue
Block a user