Skip to content

Commit

Permalink
Add parallel output mode for segments
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jan 12, 2023
1 parent e7b43cf commit bc2fb57
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 44 deletions.
2 changes: 1 addition & 1 deletion include/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Base
// static data buffer for the loop
uint8_t buffer[MAX_BUFFER];
// handle to tasks
TaskHandle_t processTaskHandle;
TaskHandle_t processTaskHandle = nullptr;
// current queue position
uint16_t queueCurrent = 0;
// queue end position
Expand Down
17 changes: 12 additions & 5 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ void processData()
unsigned long currentTime = millis();
unsigned long deltaTime = currentTime - statistics.getStartTime();

if (base.queueCurrent != base.queueEnd && deltaTime >= 1000)
if (base.queueCurrent != base.queueEnd && deltaTime >= 990 && deltaTime <= 1090 && statistics.getGoodFrames()>3)
{
statistics.update(currentTime);
}
else if (deltaTime >= 3000)
{
frameState.setState(AwaProtocol::HEADER_A);
statistics.print(currentTime, base.processTaskHandle);
vTaskDelay(50);
#if !defined(CONFIG_IDF_TARGET_ESP32S2)
statistics.print(currentTime, base.processTaskHandle);
vTaskDelay(50);
#endif
}

// render waiting frame if available
Expand Down Expand Up @@ -156,11 +158,16 @@ void processData()
{
if (input == 0x15)
{
SerialPort.println(HELLO_MESSAGE);
statistics.reset(deltaTime);
statistics.print(currentTime, base.processTaskHandle);
SerialPort.println(HELLO_MESSAGE);
vTaskDelay(50);
statistics.reset(currentTime);
}
else
{
statistics.print(currentTime, base.processTaskHandle);
vTaskDelay(50);
}

frameState.setState(AwaProtocol::HEADER_A);
}
Expand Down
8 changes: 5 additions & 3 deletions include/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ class
SerialPort.print(finalGoodFrames);
SerialPort.write(", incompl.: ");
SerialPort.print(finalTotalFrames - finalGoodFrames);
SerialPort.write(", mem: ");
SerialPort.print(uxTaskGetStackHighWaterMark(taskHandle));
if (taskHandle != nullptr)
{
SerialPort.write(", mem: ");
SerialPort.print(uxTaskGetStackHighWaterMark(taskHandle));
}
SerialPort.write(", heap: ");
SerialPort.print(ESP.getFreeHeap());
#if defined(NEOPIXEL_RGBW)
calibrationConfig.printCalibration();
#endif

}

/**
Expand Down
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ build_flags = -DSERIALCOM_SPEED=2000000
;==========================================================
[esp32]
platform = espressif32@>=5.3.0
lib_deps = makuna/NeoPixelBus@>=2.7.1
;lib_deps = makuna/NeoPixelBus@>=2.7.1
lib_deps = https://github.com/awawa-dev/NeoPixelBus.git#HyperSerialESP32
test_ignore =

[env:SK6812_RGBW_COLD]
Expand Down Expand Up @@ -83,7 +84,8 @@ test_ignore = ${esp32.test_ignore}
;==========================================================
[esp32_lolin_s2_mini]
platform = espressif32@>=5.3.0
lib_deps = makuna/NeoPixelBus@>=2.7.1
;lib_deps = makuna/NeoPixelBus@>=2.7.1
lib_deps = https://github.com/awawa-dev/NeoPixelBus.git#HyperSerialESP32
test_ignore = *

[env:s2_mini_SK6812_RGBW_COLD]
Expand Down
119 changes: 86 additions & 33 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,53 @@
#pragma message(VAR_NAME_VALUE2(LED_DRIVER))

#if defined(SECOND_SEGMENT_START_INDEX)
#if defined(NEOPIXEL_RGBW) || defined(NEOPIXEL_RGB)
#define PARALLEL_MODE
#endif

#if defined(PARALLEL_MODE)
#pragma message("Using parallel mode for segments")
#endif

#if defined(ARDUINO_LOLIN_S2_MINI)
#ifdef NEOPIXEL_RGBW
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32Rmt0Sk6812Method>
#ifdef PARALLEL_MODE
#undef LED_DRIVER
#define LED_DRIVER NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s0X8Sk6812Method>
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s0X8Sk6812Method>
#else
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32Rmt0Sk6812Method>
#endif
#elif NEOPIXEL_RGB
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0Ws2812xMethod>
#ifdef PARALLEL_MODE
#undef LED_DRIVER
#define LED_DRIVER NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0X8Ws2812Method>
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0X8Ws2812Method>
#else
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0Ws2812xMethod>
#endif
#elif SPILED_APA102
#define LED_DRIVER2 NeoPixelBus<DotStarBgrFeature, DotStarEsp32DmaHspiMethod>
#elif SPILED_WS2801
#define LED_DRIVER2 NeoPixelBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod>
#endif
#else
#ifdef NEOPIXEL_RGBW
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s0Sk6812Method>
#ifdef PARALLEL_MODE
#undef LED_DRIVER
#define LED_DRIVER NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s1X8Sk6812Method>
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s1X8Sk6812Method>
#else
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s0Sk6812Method>
#endif
#elif NEOPIXEL_RGB
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0Ws2812xMethod>
#ifdef PARALLEL_MODE
#undef LED_DRIVER
#define LED_DRIVER NeoPixelBus<NeoGrbFeature, NeoEsp32I2s1X8Ws2812Method>
#define LED_DRIVER2 NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s1X8Ws2812Method>
#else
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0Ws2812xMethod>
#endif
#elif SPILED_APA102
#define LED_DRIVER2 NeoPixelBus<DotStarBgrFeature, DotStarEsp32DmaVspiMethod>
#elif SPILED_WS2801
Expand Down Expand Up @@ -140,55 +172,76 @@ void processTask(void * parameters)

void setup()
{
bool multicore = true;

#if defined(PARALLEL_MODE) && !defined(ARDUINO_LOLIN_S2_MINI)
multicore = false;
#endif

// Init serial port
Serial.setRxBufferSize(MAX_BUFFER);
Serial.setTimeout(50);
Serial.begin(SERIALCOM_SPEED);
while (!Serial) continue;

// Display config
Serial.println(HELLO_MESSAGE);
#if defined(SECOND_SEGMENT_START_INDEX)
SerialPort.write("SECOND_SEGMENT_START_INDEX = ");
SerialPort.println(SECOND_SEGMENT_START_INDEX);
#endif

// Colorspace/Led type info
#if defined(NEOPIXEL_RGBW) || defined(NEOPIXEL_RGB)
#ifdef NEOPIXEL_RGBW
#ifdef COLD_WHITE
calibrationConfig.setParamsAndPrepareCalibration(0xFF, 0xA0, 0xA0, 0xA0);
Serial.println("NeoPixelBus SK6812 cold GRBW.");
#else
calibrationConfig.setParamsAndPrepareCalibration(0xFF, 0xB0, 0xB0, 0x70);
Serial.println("NeoPixelBus SK6812 neutral GRBW.");
#endif
calibrationConfig.printCalibration();
#else
Serial.println("NeoPixelBus ws281x type (GRB).");
#endif
#elif defined(SPILED_APA102)
Serial.println("SPI APA102 compatible type (BGR).");
#elif defined(SPILED_WS2801)
Serial.println("SPI WS2801 (RBG).");
#endif

Serial.flush();
delay(50);

// create new task for handling received serial data on core 0
xTaskCreatePinnedToCore(
processTask,
"processTask",
4096,
NULL,
5,
&base.processTaskHandle,
0);
#if !defined(CONFIG_IDF_TARGET_ESP32S2)
// Display config
Serial.println(HELLO_MESSAGE);
#if defined(SECOND_SEGMENT_START_INDEX)
SerialPort.write("SECOND_SEGMENT_START_INDEX = ");
SerialPort.println(SECOND_SEGMENT_START_INDEX);
#endif

// Colorspace/Led type info
#if defined(NEOPIXEL_RGBW) || defined(NEOPIXEL_RGB)
#ifdef NEOPIXEL_RGBW
#ifdef COLD_WHITE
Serial.println("NeoPixelBus SK6812 cold GRBW.");
#else
Serial.println("NeoPixelBus SK6812 neutral GRBW.");
#endif
calibrationConfig.printCalibration();
#else
Serial.println("NeoPixelBus ws281x type (GRB).");
#endif
#elif defined(SPILED_APA102)
Serial.println("SPI APA102 compatible type (BGR).");
#elif defined(SPILED_WS2801)
Serial.println("SPI WS2801 (RBG).");
#endif

//Serial.flush();
delay(50);
#endif

if (multicore)
{
// create new task for handling received serial data on core 0
xTaskCreatePinnedToCore(
processTask,
"processTask",
4096,
NULL,
5,
&base.processTaskHandle,
0);
}
}

void loop()
{
serialTaskHandler();
if (base.processTaskHandle == NULL)
processData();
}

0 comments on commit bc2fb57

Please sign in to comment.