Skip to content

Commit eb9e803

Browse files
authored
Merge pull request MoonModules#224 from troyhacks/P4_experimental
P4 experimental
2 parents a20de01 + 25cfe63 commit eb9e803

29 files changed

+519
-297
lines changed

boards/lolin_s3_mini.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "esp32s3_out.ld",
5+
"memory_type": "qio_qspi"
6+
},
7+
"core": "esp32",
8+
"extra_flags": [
9+
"-DBOARD_HAS_PSRAM",
10+
"-DARDUINO_LOLIN_S3_MINI",
11+
"-DARDUINO_USB_MODE=1"
12+
],
13+
"f_cpu": "240000000L",
14+
"f_flash": "80000000L",
15+
"flash_mode": "qio",
16+
"hwids": [
17+
[
18+
"0x303A",
19+
"0x8167"
20+
]
21+
],
22+
"mcu": "esp32s3",
23+
"variant": "lolin_s3_mini"
24+
},
25+
"connectivity": [
26+
"bluetooth",
27+
"wifi"
28+
],
29+
"debug": {
30+
"openocd_target": "esp32s3.cfg"
31+
},
32+
"frameworks": [
33+
"arduino",
34+
"espidf"
35+
],
36+
"name": "WEMOS LOLIN S3 Mini",
37+
"upload": {
38+
"flash_size": "4MB",
39+
"maximum_ram_size": 327680,
40+
"maximum_size": 4194304,
41+
"require_upload_port": true,
42+
"speed": 460800
43+
},
44+
"url": "https://www.wemos.cc/en/latest/s3/index.html",
45+
"vendor": "WEMOS"
46+
}
47+

platformio.ini

Lines changed: 64 additions & 143 deletions
Large diffs are not rendered by default.

usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ class PIRsensorSwitch : public Usermod
294294
void loop()
295295
{
296296
// only check sensors 4x/s
297-
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating()) return;
297+
if (!enabled || millis() - lastLoop < 250) return;
298+
if (strip.isUpdating() && (millis() - lastLoop < 250)) return; // WLEDMM be nice, but not too nice
298299
lastLoop = millis();
299300

300301
if (!updatePIRsensorState()) {

usermods/audioreactive/audio_reactive.h

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,54 +1836,62 @@ class AudioReactive : public Usermod {
18361836
agcSensitivity = 128.0f; // substitute - V1 format does not include this value
18371837
}
18381838

1839-
bool receiveAudioData() // check & process new data. return TRUE in case that new audio data was received.
1840-
{
1839+
bool receiveAudioData() {
18411840
if (!udpSyncConnected) return false;
18421841
bool haveFreshData = false;
1843-
18441842
size_t packetSize = 0;
1845-
// WLEDMM use exception handler to catch out-of-memory errors
1846-
#if __cpp_exceptions
1847-
try{
1843+
static uint8_t fftUdpBuffer[UDPSOUND_MAX_PACKET + 1] = {0};
1844+
size_t lastValidPacketSize = 0;
1845+
1846+
// Loop to read all available packets
1847+
while (true) {
1848+
#if __cpp_exceptions
1849+
try {
18481850
packetSize = fftUdp.parsePacket();
1849-
} catch(...) {
1850-
packetSize = 0; // low heap memory -> discard packet.
1851-
#ifdef ARDUINO_ARCH_ESP32
1852-
fftUdp.flush(); // this does not work on 8266
1853-
#endif
1851+
} catch (...) {
1852+
packetSize = 0;
1853+
#ifdef ARDUINO_ARCH_ESP32
1854+
fftUdp.flush();
1855+
#endif
18541856
DEBUG_PRINTLN(F("receiveAudioData: parsePacket out of memory exception caught!"));
18551857
USER_FLUSH();
1858+
continue; // Skip to next iteration
18561859
}
1857-
#else
1860+
#else
18581861
packetSize = fftUdp.parsePacket();
1859-
#endif
1862+
#endif
18601863

1861-
#ifdef ARDUINO_ARCH_ESP32
1862-
if ((packetSize > 0) && ((packetSize < 5) || (packetSize > UDPSOUND_MAX_PACKET))) fftUdp.flush(); // discard invalid packets (too small or too big)
1863-
#endif
1864-
if ((packetSize > 5) && (packetSize <= UDPSOUND_MAX_PACKET)) {
1865-
static uint8_t fftUdpBuffer[UDPSOUND_MAX_PACKET+1] = { 0 }; // static buffer for receiving, to reuse the same memory and avoid heap fragmentation
1866-
//DEBUGSR_PRINTLN("Received UDP Sync Packet");
1867-
fftUdp.read(fftUdpBuffer, packetSize);
1864+
#ifdef ARDUINO_ARCH_ESP32
1865+
if ((packetSize > 0) && ((packetSize < 5) || (packetSize > UDPSOUND_MAX_PACKET))) {
1866+
fftUdp.flush();
1867+
continue; // Skip invalid packets
1868+
}
1869+
#endif
1870+
1871+
if (packetSize == 0) break; // No more packets available
18681872

1869-
// VERIFY THAT THIS IS A COMPATIBLE PACKET
1870-
if (packetSize == sizeof(audioSyncPacket) && (isValidUdpSyncVersion((const char *)fftUdpBuffer))) {
1873+
if ((packetSize > 5) && (packetSize <= UDPSOUND_MAX_PACKET)) {
1874+
fftUdp.read(fftUdpBuffer, packetSize);
1875+
lastValidPacketSize = packetSize;
1876+
}
1877+
}
1878+
1879+
// Process only the last valid packet
1880+
if (lastValidPacketSize > 0) {
1881+
if (lastValidPacketSize == sizeof(audioSyncPacket) && (isValidUdpSyncVersion((const char *)fftUdpBuffer))) {
18711882
receivedFormat = 2;
1872-
haveFreshData = decodeAudioData(packetSize, fftUdpBuffer);
1873-
//DEBUGSR_PRINTLN("Finished parsing UDP Sync Packet v2");
1883+
haveFreshData = decodeAudioData(lastValidPacketSize, fftUdpBuffer);
1884+
} else if (lastValidPacketSize == sizeof(audioSyncPacket_v1) && (isValidUdpSyncVersion_v1((const char *)fftUdpBuffer))) {
1885+
decodeAudioData_v1(lastValidPacketSize, fftUdpBuffer);
1886+
receivedFormat = 1;
1887+
haveFreshData = true;
18741888
} else {
1875-
if (packetSize == sizeof(audioSyncPacket_v1) && (isValidUdpSyncVersion_v1((const char *)fftUdpBuffer))) {
1876-
decodeAudioData_v1(packetSize, fftUdpBuffer);
1877-
receivedFormat = 1;
1878-
//DEBUGSR_PRINTLN("Finished parsing UDP Sync Packet v1");
1879-
haveFreshData = true;
1880-
} else receivedFormat = 0; // unknown format
1889+
receivedFormat = 0; // unknown format
18811890
}
18821891
}
18831892
return haveFreshData;
18841893
}
18851894

1886-
18871895
//////////////////////
18881896
// usermod functions//
18891897
//////////////////////
@@ -2319,6 +2327,7 @@ class AudioReactive : public Usermod {
23192327
static float syncVolumeSmth = 0;
23202328
bool have_new_sample = false;
23212329
if (millis() - lastTime > delayMs) {
2330+
// DEBUG_PRINTF(F("AR reading at %d compared to %d max\n"), millis() - lastTime, delayMs); // TroyHacks
23222331
have_new_sample = receiveAudioData();
23232332
if (have_new_sample) {
23242333
last_UDPTime = millis();

usermods/audioreactive/audio_source.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class ES8311Source : public I2SSource {
677677

678678
void _es8311InitAdc() {
679679
//
680-
// Currently only tested with the ESP32-P4 EV board with the onboard mic.
680+
// Currently only tested with the ESP32-P4 boards with the onboard mic.
681681
// Datasheet with I2C commands: https://dl.xkwy2018.com/downloads/RK3588/01_Official%20Release/04_Product%20Line%20Branch_NVR/02_Key%20Device%20Specifications/ES8311%20DS.pdf
682682
//
683683
_es8311I2cBegin();
@@ -693,24 +693,23 @@ class ES8311Source : public I2SSource {
693693
_es8311I2cWrite(0x08, 0b11111111); // 22050hz calculated
694694
_es8311I2cWrite(0x06, 0b11100011); // 22050hz calculated
695695

696-
_es8311I2cWrite(0x16, 0b00100100); // ADC was 0b00000011 trying 0b00100100 was good, trying ...111 (...111 is better?)
696+
_es8311I2cWrite(0x16, 0b00100100); // ADC was 0b00000011 trying 0b00100100 was good
697697
_es8311I2cWrite(0x0B, 0b00000000); // SYSTEM at default
698698
_es8311I2cWrite(0x0C, 0b00100000); // SYSTEM was 0b00001111 trying 0b00100000
699699
_es8311I2cWrite(0x10, 0b00010011); // SYSTEM was 0b00011111 trying 0b00010011
700700
_es8311I2cWrite(0x11, 0b01111100); // SYSTEM was 0b01111111 trying 0b01111100
701701
_es8311I2cWrite(0x00, 0b11000000); // *** RESET (again - seems important?)
702702
_es8311I2cWrite(0x01, 0b00111010); // *** CLOCK MANAGER was 0b00111111 trying 0b00111010 (again?? seems important)
703-
_es8311I2cWrite(0x14, 0b00010000); // *** SYSTEM was 0b00011010 trying 0b00010000 (or 0b01111010) (PGA gain)
703+
_es8311I2cWrite(0x14, 0b00010000); // *** SYSTEM was 0b00011010 trying 0b00010000 (PGA gain)
704704
_es8311I2cWrite(0x0A, 0b00001000); // *** SDP OUT, was 0b00001100 trying 0b00001000 (I2S 32-bit)
705-
_es8311I2cWrite(0x0E, 0b00000010); // *** SYSTEM was 0b00000010 trying 0b00011010 (seems best so far!) (or 0b00000010)
705+
_es8311I2cWrite(0x0E, 0b00000010); // *** SYSTEM was 0b00000010 trying 0b00000010
706706
_es8311I2cWrite(0x0F, 0b01000100); // SYSTEM was 0b01000100
707707
_es8311I2cWrite(0x15, 0b00010000); // ADC soft ramp (disabled 0000xxxx)
708708
_es8311I2cWrite(0x1B, 0b00000101); // ADC soft-mute was 0b00000101
709-
_es8311I2cWrite(0x1C, 0b01100101); // ADC EQ and offset freeze was 0b01100101 (bad at 0b00101100)
710-
_es8311I2cWrite(0x17, 0b10111111); // ADC volume was 0b11111111 trying ADC volume 0b10111111 = 0db (maxgain) 0x16
709+
_es8311I2cWrite(0x1C, 0b01100101); // ADC EQ and offset freeze at 0b01100101 (bad at 0b00101100)
710+
_es8311I2cWrite(0x17, 0b10111111); // ADC volume was 0b11111111 trying ADC volume 0b10111111 = 0db (maxgain)
711711
_es8311I2cWrite(0x18, 0b10000001); // ADC ALC enabled and AutoMute disabled.
712-
// _es8311I2cWrite(0x19, 0b11110100); // ADC ALC max and min
713-
712+
// _es8311I2cWrite(0x19, 0b11110100); // ADC ALC max and min - not sure how best to use this, default seems fine
714713
}
715714

716715
public:

usermods/rgb-rotary-encoder/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The actual / original code that controls the LED modes is from Adam Zeloof. I ta
99
It was quite a bit more work than I hoped, but I got there eventually :)
1010

1111
## Requirements
12-
* "ESP Rotary" by Lennart Hennigs, v1.5.0 or higher: https://github.com/LennartHennigs/ESPRotary
12+
* "ESP Rotary" by Lennart Hennigs, v2.1.1 or higher: https://github.com/LennartHennigs/ESPRotary
1313

1414
## Usermod installation
1515
Simply copy the below block (build task) to your `platformio_override.ini` and compile WLED using this new build task. Or use an existing one and add the buildflag `-D RGB_ROTARY_ENCODER`.
@@ -20,7 +20,7 @@ ESP32:
2020
extends = env:esp32dev
2121
build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32 -D RGB_ROTARY_ENCODER
2222
lib_deps = ${esp32.lib_deps}
23-
lennarthennigs/ESP Rotary@^1.5.0
23+
lennarthennigs/ESP Rotary@^2.1.1
2424
```
2525

2626
ESP8266 / D1 Mini:
@@ -29,7 +29,7 @@ ESP8266 / D1 Mini:
2929
extends = env:d1_mini
3030
build_flags = ${common.build_flags_esp8266} -D RGB_ROTARY_ENCODER
3131
lib_deps = ${esp8266.lib_deps}
32-
lennarthennigs/ESP Rotary@^1.5.0
32+
lennarthennigs/ESP Rotary@^2.1.1
3333
```
3434

3535
## How to connect the board to your ESP

wled00/FX.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,18 @@ typedef struct Segment {
607607
// transition functions
608608
void startTransition(uint16_t dur); // transition has to start before actual segment values change
609609
void handleTransition(void);
610-
uint16_t progress(void) const; //transition progression between 0-65535
610+
// transition progression between 0-65535
611+
[[gnu::hot]] inline uint16_t progress() const {
612+
if (!transitional || !_t) return 0xFFFFU;
613+
unsigned long timeNow = millis();
614+
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
615+
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
616+
}
611617

612618
// WLEDMM method inlined for speed (its called at each setPixelColor)
613-
inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
614-
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
615-
if (transitional && _t && prog < 0xFFFFU) {
619+
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) const {
620+
uint32_t prog = progress();
621+
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
616622
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
617623
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
618624
} else {
@@ -703,15 +709,15 @@ typedef struct Segment {
703709
void deletejMap(); //WLEDMM jMap
704710

705711
#ifndef WLED_DISABLE_2D
706-
inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) const { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed
712+
[[gnu::hot]] inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) const { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed
707713
uint_fast16_t width = max(uint16_t(1), virtualWidth()); // segment width in logical pixels -- softhack007 avoid div/0
708714
uint_fast16_t height = max(uint16_t(1), virtualHeight()); // segment height in logical pixels -- softhack007 avoid div/0
709715
return (x%width) + (y%height) * width;
710716
}
711717

712718
#ifdef WLEDMM_FASTPATH
713719
// WLEDMM this is a "gateway" function - we either call _fast or fall back to "slow"
714-
inline void setPixelColorXY(int x, int y, uint32_t col) {
720+
[[gnu::hot]] inline void setPixelColorXY(int x, int y, uint32_t col) {
715721
if (!_isSimpleSegment) { // slow path
716722
setPixelColorXY_slow(x, y, col);
717723
} else { // fast path
@@ -724,7 +730,7 @@ typedef struct Segment {
724730
setPixelColorXY_fast(x, y, col, scaled_col, int(_2dWidth), int(_2dHeight)); // call "fast" function
725731
}
726732
}
727-
inline uint32_t getPixelColorXY(int x, int y) const {
733+
[[gnu::hot]] inline uint32_t getPixelColorXY(int x, int y) const {
728734
// minimal sanity checks
729735
if (!_isValid2D) return 0; // not active
730736
if ((unsigned(x) >= _2dWidth) || (unsigned(y) >= _2dHeight)) return 0 ; // check if (x,y) are out-of-range - due to 2's complement, this also catches negative values
@@ -1081,7 +1087,7 @@ class WS2812FX { // 96 bytes
10811087
#endif
10821088

10831089
std::vector<segment> _segments;
1084-
friend class Segment;
1090+
friend struct Segment;
10851091

10861092
uint32_t getPixelColorXYRestored(uint16_t x, uint16_t y) const; // WLEDMM gets the original color from the driver (without downscaling by _bri)
10871093

wled00/FX_2Dfcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void WS2812FX::setUpMatrix() {
6868
if (!needLedMap) size = 0; // softhack007
6969
USER_PRINTF("setupmatrix customMappingTable alloc %d from %d\n", size, customMappingTableSize);
7070
//if (customMappingTable != nullptr) delete[] customMappingTable;
71-
//customMappingTable = new uint16_t[size];
71+
//customMappingTable = new(std::nothrow) uint16_t[size];
7272

7373
// don't use new / delete
7474
if ((size > 0) && (customMappingTable != nullptr)) { // resize
@@ -129,7 +129,7 @@ void WS2812FX::setUpMatrix() {
129129
JsonArray map = doc.as<JsonArray>();
130130
gapSize = map.size();
131131
if (!map.isNull() && (gapSize > 0) && gapSize >= customMappingSize) { // not an empty map //softhack also check gapSize>0
132-
gapTable = new int8_t[gapSize];
132+
gapTable = new(std::nothrow) int8_t[gapSize];
133133
if (gapTable) for (size_t i = 0; i < gapSize; i++) {
134134
gapTable[i] = constrain(map[i], -1, 1);
135135
}

0 commit comments

Comments
 (0)