Initial commit of Arduino libraries

This commit is contained in:
Sam
2025-05-23 10:47:41 +10:00
commit 5bfce5fc3e
2476 changed files with 1108481 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Repo: https://github.com/hpwit/I2SClockLessLedDriveresp32s3
commit: 48e9cb6d3db0e902703b0325bfaa153074f071d8

View File

@@ -0,0 +1,11 @@
#pragma once
#ifndef USE_FASTLED
#define USE_FASTLED
#endif // USE_FASTLED
#define COLOR_ORDER_RBG
#include "src/I2SClockLessLedDriveresp32s3.h"

View File

@@ -0,0 +1,506 @@
#if !__has_include("esp_memory_utils.h")
#error \
"esp_memory_utils.h is not available, are you using esp-idf 4.4 or earlier?"
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#pragma GCC diagnostic ignored "-Wvolatile"
#include "esp_attr.h"
#include "esp_check.h"
#include "esp_heap_caps.h"
#include "esp_intr_alloc.h"
#include "esp_memory_utils.h"
#include "esp_pm.h"
#include <stdint.h>
#include <stdio.h> // ok include
#include <string.h>
// #include "esp_lcd_panel_io_interface.h"
// #include "esp_lcd_panel_io.h"
#include "driver/gpio.h"
#include "esp_memory_utils.h"
#include "esp_private/gdma.h"
#include "esp_rom_gpio.h"
#include "hal/dma_types.h"
#include "hal/gpio_hal.h"
#include "soc/rtc.h" // for `rtc_clk_xtal_freq_get()`
#include "soc/soc_caps.h"
// #include "esp_private/periph_ctrl.h"
// #include "esp_lcd_common.h"
#include "hal/lcd_hal.h"
#include "hal/lcd_ll.h"
#include "soc/lcd_periph.h"
#include "esp_heap_caps.h"
#include "esp_lcd_panel_interface.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_io_interface.h"
#include "esp_lcd_panel_ops.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "soc/gdma_reg.h"
#include "platforms/esp/esp_version.h"
#define IDF_5_3_OR_EARLIER (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0))
// According to bug reports, this driver does not work well with the new WS2812-v5b. This is
// probably due to the extrrra long reset time requirements of this chipset. so we put in
// a hack that will always add 300 uS to the reset time.
#define FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS 300
#ifndef NUMSTRIPS
#define NUMSTRIPS 16
#endif
#ifndef SNAKEPATTERN
#define SNAKEPATTERN 1
#endif
#ifndef ALTERNATEPATTERN
#define ALTERNATEPATTERN 1
#endif
#define I2S_DEVICE 0
#define AA (0x00AA00AAL)
#define CC (0x0000CCCCL)
#define FF (0xF0F0F0F0L)
#define FF2 (0x0F0F0F0FL)
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define __OFFSET 0 // (24*3*2*2*2+2)
#define __OFFSET_END (24 * 3 * 2 * 2 * 2 + 2)
#ifndef HARDWARESPRITES
#define HARDWARESPRITES 0
#endif
#if HARDWARESPRITES == 1
#include "hardwareSprite.h"
#endif
#ifdef COLOR_ORDER_GRBW
#define _p_r 1
#define _p_g 0
#define _p_b 2
#define _nb_components 4
#else
#ifdef COLOR_ORDER_RGB
#define _p_r 0
#define _p_g 1
#define _p_b 2
#define _nb_components 3
#else
#ifdef COLOR_ORDER_RBG
#define _p_r 0
#define _p_g 2
#define _p_b 1
#define _nb_components 3
#else
#ifdef COLOR_ORDER_GBR
#define _p_r 2
#define _p_g 0
#define _p_b 1
#define _nb_components 3
#else
#ifdef COLOR_ORDER_BGR
#define _p_r 2
#define _p_g 1
#define _p_b 0
#define _nb_components 3
#else
#ifdef COLOR_ORDER_BRG
#define _p_r 1
#define _p_g 2
#define _p_b 0
#define _nb_components 3
#else
#ifdef COLOR_ORDER_GRB
#define _p_r 1
#define _p_g 0
#define _p_b 2
#define _nb_components 3
#else
#define _p_r 1
#define _p_g 0
#define _p_b 2
#define _nb_components 3
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#ifdef USE_PIXELSLIB
// #include "pixelslib.h"
#else
#include "___pixeltypes.h"
#endif
#define LCD_DRIVER_PSRAM_DATA_ALIGNMENT 64
#define CLOCKLESS_PIXEL_CLOCK_HZ (24 * 100 * 1000)
namespace fl {
static bool IRAM_ATTR flush_ready(esp_lcd_panel_io_handle_t panel_io,
esp_lcd_panel_io_event_data_t *edata,
void *user_ctx);
typedef union {
uint8_t bytes[16];
uint32_t shorts[8];
uint32_t raw[2];
} Lines;
enum colorarrangment {
ORDER_GRBW,
ORDER_RGB,
ORDER_RBG,
ORDER_GRB,
ORDER_GBR,
ORDER_BRG,
ORDER_BGR,
};
enum displayMode {
NO_WAIT,
WAIT,
LOOP,
LOOP_INTERUPT,
};
bool DRIVER_READY = true;
typedef struct led_driver_t led_driver_t;
struct led_driver_t {
size_t (*init)();
void (*update)(uint8_t *colors, size_t len);
};
volatile xSemaphoreHandle I2SClocklessLedDriverS3_sem = NULL;
volatile bool isDisplaying = false;
volatile bool iswaiting = false;
static void IRAM_ATTR transpose16x1_noinline2(unsigned char *A, uint16_t *B) {
uint32_t x, y, x1, y1, t;
y = *(unsigned int *)(A);
#if NUMSTRIPS > 4
x = *(unsigned int *)(A + 4);
#else
x = 0;
#endif
#if NUMSTRIPS > 8
y1 = *(unsigned int *)(A + 8);
#else
y1 = 0;
#endif
#if NUMSTRIPS > 12
x1 = *(unsigned int *)(A + 12);
#else
x1 = 0;
#endif
// pre-transform x
#if NUMSTRIPS > 4
t = (x ^ (x >> 7)) & AA;
x = x ^ t ^ (t << 7);
t = (x ^ (x >> 14)) & CC;
x = x ^ t ^ (t << 14);
#endif
#if NUMSTRIPS > 12
t = (x1 ^ (x1 >> 7)) & AA;
x1 = x1 ^ t ^ (t << 7);
t = (x1 ^ (x1 >> 14)) & CC;
x1 = x1 ^ t ^ (t << 14);
#endif
// pre-transform y
t = (y ^ (y >> 7)) & AA;
y = y ^ t ^ (t << 7);
t = (y ^ (y >> 14)) & CC;
y = y ^ t ^ (t << 14);
#if NUMSTRIPS > 8
t = (y1 ^ (y1 >> 7)) & AA;
y1 = y1 ^ t ^ (t << 7);
t = (y1 ^ (y1 >> 14)) & CC;
y1 = y1 ^ t ^ (t << 14);
#endif
// final transform
t = (x & FF) | ((y >> 4) & FF2);
y = ((x << 4) & FF) | (y & FF2);
x = t;
t = (x1 & FF) | ((y1 >> 4) & FF2);
y1 = ((x1 << 4) & FF) | (y1 & FF2);
x1 = t;
*((uint16_t *)(B)) =
(uint16_t)(((x & 0xff000000) >> 8 | ((x1 & 0xff000000))) >> 16);
*((uint16_t *)(B + 3)) =
(uint16_t)(((x & 0xff0000) >> 16 | ((x1 & 0xff0000) >> 8)));
*((uint16_t *)(B + 6)) =
(uint16_t)(((x & 0xff00) | ((x1 & 0xff00) << 8)) >> 8);
*((uint16_t *)(B + 9)) = (uint16_t)((x & 0xff) | ((x1 & 0xff) << 8));
*((uint16_t *)(B + 12)) =
(uint16_t)(((y & 0xff000000) >> 8 | ((y1 & 0xff000000))) >> 16);
*((uint16_t *)(B + 15)) =
(uint16_t)(((y & 0xff0000) | ((y1 & 0xff0000) << 8)) >> 16);
*((uint16_t *)(B + 18)) =
(uint16_t)(((y & 0xff00) | ((y1 & 0xff00) << 8)) >> 8);
*((uint16_t *)(B + 21)) = (uint16_t)((y & 0xff) | ((y1 & 0xff) << 8));
}
esp_lcd_panel_io_handle_t led_io_handle = NULL;
class I2SClocklessLedDriveresp32S3 {
public:
int testcount;
uint16_t *buffers[2];
uint16_t *led_output = NULL;
uint16_t *led_output2 = NULL;
uint8_t *ledsbuff = NULL;
int num_leds_per_strip;
int _numstrips;
int currentframe;
uint8_t __green_map[256];
uint8_t __blue_map[256];
uint8_t __red_map[256];
uint8_t __white_map[256];
uint8_t _brightness;
float _gammar, _gammab, _gammag, _gammaw;
void setBrightness(int brightness) {
_brightness = brightness;
float tmp;
for (int i = 0; i < 256; i++) {
tmp = powf((float)i / 255, 1 / _gammag);
__green_map[i] = (uint8_t)(tmp * brightness);
tmp = powf((float)i / 255, 1 / _gammag);
__blue_map[i] = (uint8_t)(tmp * brightness);
tmp = powf((float)i / 255, 1 / _gammag);
__red_map[i] = (uint8_t)(tmp * brightness);
tmp = powf((float)i / 255, 1 / _gammag);
__white_map[i] = (uint8_t)(tmp * brightness);
}
}
void setGamma(float gammar, float gammab, float gammag, float gammaw) {
_gammag = gammag;
_gammar = gammar;
_gammaw = gammaw;
_gammab = gammab;
setBrightness(_brightness);
}
void setGamma(float gammar, float gammab, float gammag) {
_gammag = gammag;
_gammar = gammar;
_gammab = gammab;
setBrightness(_brightness);
}
void _initled(uint8_t *leds, const int *pins, int numstrip,
int NUM_LED_PER_STRIP) {
// esp_lcd_panel_io_handle_t init_lcd_driver(unsigned int
// CLOCKLESS_PIXEL_CLOCK_HZ, size_t _nb_components) {
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config;
bus_config.clk_src = LCD_CLK_SRC_PLL160M;
bus_config.dc_gpio_num = 0;
bus_config.wr_gpio_num = 0;
// bus_config.data_gpio_nums = (int*)malloc(16*sizeof(int));
for (int i = 0; i < numstrip; i++) {
bus_config.data_gpio_nums[i] = pins[i];
}
if (numstrip < 16) {
for (int i = numstrip; i < 16; i++) {
bus_config.data_gpio_nums[i] = 0;
}
}
bus_config.bus_width = 16;
bus_config.max_transfer_bytes =
_nb_components * NUM_LED_PER_STRIP * 8 * 3 * 2 + __OFFSET + __OFFSET_END;
#if IDF_5_3_OR_EARLIER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
// In IDF 5.3, psram_trans_align became deprecated. We kick the can down
// the road a little bit and suppress the warning until idf 5.4 arrives.
bus_config.psram_trans_align = LCD_DRIVER_PSRAM_DATA_ALIGNMENT;
bus_config.sram_trans_align = 4;
#if IDF_5_3_OR_EARLIER
#pragma GCC diagnostic pop
#endif
ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
esp_lcd_panel_io_i80_config_t io_config;
io_config.cs_gpio_num = -1;
io_config.pclk_hz = CLOCKLESS_PIXEL_CLOCK_HZ;
io_config.trans_queue_depth = 1;
io_config.dc_levels = {
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
};
//.on_color_trans_done = flush_ready,
// .user_ctx = nullptr,
io_config.lcd_cmd_bits = 0;
io_config.lcd_param_bits = 0;
io_config.user_ctx = this;
io_config.on_color_trans_done = flush_ready;
ESP_ERROR_CHECK(
esp_lcd_new_panel_io_i80(i80_bus, &io_config, &led_io_handle));
}
void initled(uint8_t *leds, const int *pins, int numstrip,
int NUM_LED_PER_STRIP) {
currentframe = 0;
_gammab = 1;
_gammar = 1;
_gammag = 1;
_gammaw = 1;
setBrightness(255);
if (I2SClocklessLedDriverS3_sem == NULL) {
I2SClocklessLedDriverS3_sem = xSemaphoreCreateBinary();
}
// esp_lcd_panel_io_handle_t init_lcd_driver(unsigned int
// CLOCKLESS_PIXEL_CLOCK_HZ, size_t _nb_components) {
led_output = (uint16_t *)heap_caps_aligned_alloc(
LCD_DRIVER_PSRAM_DATA_ALIGNMENT,
8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
__OFFSET_END,
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
memset(led_output, 0,
8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
__OFFSET_END);
led_output2 = (uint16_t *)heap_caps_aligned_alloc(
LCD_DRIVER_PSRAM_DATA_ALIGNMENT,
8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
__OFFSET_END,
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
memset(led_output2, 0,
8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
__OFFSET_END);
buffers[0] = led_output;
buffers[1] = led_output2;
// led_output[0] = 0xFFFF; //the +1 because it's like the first value
// doesnt get pushed do not ask me why for now
// led_output2[0] = 0xFFFF;
led_output2 += __OFFSET / 2;
led_output += __OFFSET / 2;
for (int i = 0; i < NUM_LED_PER_STRIP * _nb_components * 8; i++) {
led_output[3 * i + 1] =
0xFFFF; // the +1 because it's like the first value doesnt get
// pushed do not ask me why for now
led_output2[3 * i + 1] = 0xFFFF;
}
ledsbuff = leds;
_numstrips = numstrip;
num_leds_per_strip = NUM_LED_PER_STRIP;
_initled(leds, pins, numstrip, NUM_LED_PER_STRIP);
}
void transposeAll(uint16_t *ledoutput) {
uint16_t ledToDisplay = 0;
Lines secondPixel[_nb_components];
uint16_t *buff =
ledoutput + 2; //+1 pour le premier empty +1 pour le 1 systématique
uint16_t jump = num_leds_per_strip * _nb_components;
for (int j = 0; j < num_leds_per_strip; j++) {
uint8_t *poli = ledsbuff + ledToDisplay * _nb_components;
for (int i = 0; i < _numstrips; i++) {
secondPixel[_p_g].bytes[i] = __green_map[*(poli + 1)];
secondPixel[_p_r].bytes[i] = __red_map[*(poli + 0)];
secondPixel[_p_b].bytes[i] = __blue_map[*(poli + 2)];
if (_nb_components > 3)
secondPixel[3].bytes[i] = __white_map[*(poli + 3)];
// #endif
poli += jump;
}
ledToDisplay++;
transpose16x1_noinline2(secondPixel[0].bytes, buff);
buff += 24;
transpose16x1_noinline2(secondPixel[1].bytes, buff);
buff += 24;
transpose16x1_noinline2(secondPixel[2].bytes, buff);
buff += 24;
if (_nb_components > 3) {
transpose16x1_noinline2(secondPixel[3].bytes, buff);
buff += 24;
}
}
}
void show() {
transposeAll(buffers[currentframe]);
if (isDisplaying) {
// Serial.println("on display dejà");
iswaiting = true;
if (I2SClocklessLedDriverS3_sem == NULL)
I2SClocklessLedDriverS3_sem = xSemaphoreCreateBinary();
xSemaphoreTake(I2SClocklessLedDriverS3_sem, portMAX_DELAY);
}
isDisplaying = true;
if (FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS) {
delayMicroseconds(FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS);
}
led_io_handle->tx_color(led_io_handle, 0x2C, buffers[currentframe],
_nb_components * num_leds_per_strip * 8 * 3 *
2 +
__OFFSET + __OFFSET_END);
currentframe = (currentframe + 1) % 2;
}
};
static bool IRAM_ATTR flush_ready(esp_lcd_panel_io_handle_t panel_io,
esp_lcd_panel_io_event_data_t *edata,
void *user_ctx) {
// printf("we're here");
DRIVER_READY = true;
isDisplaying = false;
I2SClocklessLedDriveresp32S3 *cont =
(I2SClocklessLedDriveresp32S3 *)user_ctx;
cont->testcount++;
if (iswaiting) {
portBASE_TYPE HPTaskAwoken = 0;
iswaiting = false;
xSemaphoreGiveFromISR(I2SClocklessLedDriverS3_sem, &HPTaskAwoken);
if (HPTaskAwoken == pdTRUE)
portYIELD_FROM_ISR(HPTaskAwoken);
}
return false;
}
#pragma GCC diagnostic pop
} // namespace fl
#endif // __has_include("esp_memory_utils.h")

View File

@@ -0,0 +1,334 @@
#include <stdint.h>
#include <string.h>
#ifdef USE_FASTLED
#include "FastLED.h"
#endif
// #include "Arduino.h"
#define _OUT_OF_BOUND -12
namespace fl {
#ifdef COLOR_RGBW
struct Pixel {
union {
uint8_t raw[4];
struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t white;
};
};
inline Pixel(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
__attribute__((always_inline))
: red(r), green(g), blue(b), white(w) {
// brigthness =0xE0 |(br&31);
}
inline Pixel(uint8_t r, uint8_t g, uint8_t b) __attribute__((always_inline))
: red(r), green(g), blue(b) {
white = MIN(red, green);
white = MIN(white, blue);
red = red - white;
green = green - white;
blue = blue - white;
}
inline Pixel() __attribute__((always_inline)) {}
#ifdef USE_FASTLED
inline Pixel &operator=(const CRGB &rhs) __attribute__((always_inline)) {
red = rhs.r;
green = rhs.g;
blue = rhs.b;
white = MIN(red, green);
white = MIN(white, blue);
red = red - white;
green = green - white;
blue = blue - white;
return *this;
}
#endif
inline Pixel(const Pixel &rhs) __attribute__((always_inline)) {
// brigthness=rhs.brigthness;
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
white = rhs.white;
}
inline Pixel &operator=(const uint32_t colorcode)
__attribute__((always_inline)) {
// rgb colorg;
red = (colorcode >> 24) & 0xFF;
green = (colorcode >> 16) & 0xFF;
blue = (colorcode >> 8) & 0xFF;
white = colorcode & 0xFF;
return *this;
}
};
#else
struct Pixel {
union {
uint8_t raw[3];
struct {
uint8_t red;
uint8_t green;
uint8_t blue;
};
};
inline Pixel(uint8_t r, uint8_t g, uint8_t b) __attribute__((always_inline))
: red(r), green(g), blue(b) {
// brigthness =0xE0 |(br&31);
}
inline Pixel() __attribute__((always_inline)) {}
#ifdef USE_FASTLED
inline Pixel &operator=(const CRGB &rhs) __attribute__((always_inline)) {
red = rhs.r;
green = rhs.g;
blue = rhs.b;
return *this;
}
inline Pixel &operator=(CRGB &rhs) __attribute__((always_inline)) {
red = rhs.r;
green = rhs.g;
blue = rhs.b;
return *this;
}
inline Pixel(const CRGB &rhs) __attribute__((always_inline)) {
red = rhs.r;
green = rhs.g;
blue = rhs.b;
}
#endif
inline Pixel(const Pixel &rhs) __attribute__((always_inline)) {
// brigthness=rhs.brigthness;
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
}
inline Pixel &operator=(const uint32_t colorcode)
__attribute__((always_inline)) {
// rgb colorg;
red = (colorcode >> 16) & 0xFF;
green = (colorcode >> 8) & 0xFF;
blue = (colorcode >> 0) & 0xFF;
return *this;
}
inline __attribute__((always_inline)) bool operator==(const Pixel &rhs) {
return (red == rhs.red) && (green == rhs.green) && (blue == rhs.blue);
}
inline __attribute__((always_inline)) bool operator!=(const Pixel &rhs) {
return !((red == rhs.red) && (green == rhs.green) &&
(blue == rhs.blue));
}
};
#endif
enum class leddirection { FORWARD, BACKWARD, MAP };
class Pixels {
public:
inline Pixels() __attribute__((always_inline)) {}
inline Pixels(const Pixels &rhs) __attribute__((always_inline)) {
_size = rhs._size;
_direction = rhs._direction;
_num_strips = rhs._num_strips;
for (int i = 0; i < _num_strips; i++) {
_sizes[i] = rhs._sizes[i];
}
ledpointer = rhs.ledpointer;
mapFunction = rhs.mapFunction;
// parent=rhs.parent;
}
Pixels(int size, Pixel *ledpoi) {
Pixels(size, ledpoi, leddirection::FORWARD);
}
Pixels(int size, Pixel *ledpoi, leddirection direction) {
__Pixels(size, ledpoi, direction, this);
}
void __Pixels(int size, Pixel *ledpoi, leddirection direction,
Pixels *pib) {
pib->_size = size;
pib->ledpointer = ledpoi;
pib->_num_strips = 0;
pib->_direction = direction;
// pib->nb_child=0;
}
Pixels(int num_led_per_strip, int num_strips) {
int sizes[16];
for (int i = 0; i < num_strips; i++) {
sizes[i] = num_led_per_strip;
}
__Pixels(sizes, num_strips, leddirection::FORWARD, this);
}
Pixels(int *sizes, int num_strips) {
__Pixels(sizes, num_strips, leddirection::FORWARD, this);
}
Pixels(int *sizes, int num_strips, leddirection direction) {
__Pixels(sizes, num_strips, direction, this);
}
void __Pixels(int *sizes, int num_strips, leddirection direction,
Pixels *pib) {
int size = 0;
for (int i = 0; i < num_strips; i++) {
size += sizes[i];
pib->_sizes[i] = sizes[i];
}
pib->_num_strips = num_strips;
ledpointer = (Pixel *)calloc(size, sizeof(Pixel));
if (ledpointer == NULL) {
pib->_size = 0;
} else {
pib->_size = size;
}
pib->_direction = direction;
}
Pixel &operator[](int i) {
switch (_direction) {
case (leddirection::FORWARD):
return *(ledpointer + i % _size);
break;
case (leddirection::BACKWARD):
return *(ledpointer + (_size - i % (_size)-1));
break;
case (leddirection::MAP):
if (mapFunction) {
int offset = mapFunction(i, arguments);
// printf("%d %d\n",i,offset);
if (offset == _OUT_OF_BOUND) {
return offPixel;
} else
return *(ledpointer + (mapFunction(i, arguments) % _size));
}
else
return *(ledpointer);
break;
default:
return *(ledpointer);
break;
}
}
void copy(Pixels ori) { copy(ori, leddirection::FORWARD); }
void copy(Pixels ori, leddirection dir) {
leddirection ledd = _direction;
if (_direction == leddirection::MAP)
ledd = leddirection::FORWARD;
for (int i = 0; i < ori._size; i++) {
if (ledd == dir) {
(*this)[i] = ori[i];
} else {
(*this)[i] = ori[ori._size - i % (ori._size) - 1];
}
}
}
Pixels getStrip(int num_strip, leddirection direction) {
if (_num_strips == 0 or _num_strips < num_strip) {
int d[0];
return Pixels(d, 1, direction);
} else {
uint32_t off = 0;
for (int i = 0; i < num_strip % _num_strips; i++) {
off += _sizes[i];
}
return Pixels(_sizes[num_strip], ledpointer + off, direction);
}
}
Pixels getStrip(int num_strip) {
return getStrip(num_strip, leddirection::FORWARD);
}
int *getLengths() { return _sizes; }
int getNumStrip() { return _num_strips; }
uint8_t *getPixels() { return (uint8_t *)ledpointer; }
void clear() {
// memset(ledpointer,0,_size*sizeof(Pixel));
}
Pixels createSubset(int start, int length) {
return createSubset(start, length, leddirection::FORWARD);
}
Pixels createSubset(int start, leddirection direction) {
if (start < 0)
start = 0;
return Pixels(_size, ledpointer + start, direction);
}
Pixels createSubset(int start, int length, leddirection direction) {
if (start < 0)
start = 0;
if (length <= 0)
length = 1;
return Pixels(length, ledpointer + start, direction);
}
/*
Pixels getParent()
{
return *parent;
}
Pixels * getChild(int i)
{
return children[i%nb_child];
}
*/
inline void setMapFunction(int (*fptr)(int i, void *args), void *args,
int size) {
mapFunction = fptr;
if (arguments == NULL)
arguments = (void *)malloc(sizeof(size));
memcpy(arguments, args, size);
}
private:
Pixel *ledpointer;
size_t _size = 0;
int _sizes[16];
int _num_strips = 0;
leddirection _direction;
// int nb_child;
// Pixels *parent;
void *arguments;
// Pixels **children;
int (*mapFunction)(int i, void *args);
/*
* this is the pixel to retuen when out of bound
*/
Pixel offPixel;
};
} // namespace fl