From 2ce0779000ae3ca77f820d7ea910bab1dab1cb17 Mon Sep 17 00:00:00 2001 From: Alex <15167344+frostmorn@users.noreply.github.com> Date: Tue, 12 May 2026 11:30:40 +0000 Subject: [PATCH 1/5] UART Solder test --- lib/lilka/src/lilka/board.cpp | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/lilka/src/lilka/board.cpp b/lib/lilka/src/lilka/board.cpp index e96652c..11dd3f7 100644 --- a/lib/lilka/src/lilka/board.cpp +++ b/lib/lilka/src/lilka/board.cpp @@ -3,6 +3,9 @@ #include "board.h" #include "display.h" #include "config.h" +#include +#include +#include namespace lilka { @@ -10,6 +13,48 @@ Board::Board() { } void Board::begin() { +#define PIN_AWAIT_TIME 60 +#if LILKA_VERSION == 2 + ////////////////////////////////////////////////////////////////////////// + // Perform soldering test + ////////////////////////////////////////////////////////////////////////// + // For V2: + // GPIO19-20 USB + // GPIO0, GPIO3, GPIO45, GPIO 46 Strap pins + // GPIO26-32 Reserved for PSRAM + // GPIO33-37 Reserved for Octal PSRAM + ////////////////////////////////////////////////////////////////////////// + const int testPins[] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 21, 22, 23, 24, 25, 38, 39, 40, 41, 42, 43, 44, 47, 48}; + // Configure pin mode for all pins + for (auto pin : testPins) { + pinMode(pin, INPUT_PULLDOWN); + } + // Await pin to stabilize it's state(voltage, etc.) + delayMicroseconds(PIN_AWAIT_TIME); + + // Test connections based on a fact + // that pins shouldn't be shorted + for (int i = 0; i < sizeof(testPins) / sizeof(testPins[0]); i++) { + // Setup high on a testPin + pinMode(testPins[i], OUTPUT); + digitalWrite(testPins[i], HIGH); + delayMicroseconds(PIN_AWAIT_TIME); + + // Read other testPins to check on shorts + for (int j = i + 1; j < sizeof(testPins) / sizeof(testPins[0]); j++) { + bool shorted = digitalRead(testPins[j]) == HIGH; + if (shorted) { + lilka::serial.log("Found connection between GPIOs %d and %d\n", testPins[i], testPins[j]); + } + } + // Restore testPin state + digitalWrite(testPins[i], LOW); + pinMode(testPins[i], INPUT_PULLDOWN); + } + +#endif + // Iterate over the pins, set them as inputs #if LILKA_VERSION >= 2 for (int pin : LILKA_EXT_PINS) { From a329dbb75484d157d8afadda3c059c0b4d577933 Mon Sep 17 00:00:00 2001 From: Alex <15167344+frostmorn@users.noreply.github.com> Date: Tue, 12 May 2026 18:39:58 +0000 Subject: [PATCH 2/5] Use ADC power --- lib/lilka/src/lilka/board.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/lilka/src/lilka/board.cpp b/lib/lilka/src/lilka/board.cpp index 11dd3f7..f98fe21 100644 --- a/lib/lilka/src/lilka/board.cpp +++ b/lib/lilka/src/lilka/board.cpp @@ -3,6 +3,7 @@ #include "board.h" #include "display.h" #include "config.h" +#include "esp32-hal-adc.h" #include #include #include @@ -13,7 +14,9 @@ Board::Board() { } void Board::begin() { -#define PIN_AWAIT_TIME 60 +#define PIN_AWAIT_TIME 60 +#define ADC_SAMPLES 10 +#define ADC_READ_TRIGGER_VAL 4000 // Note: it's not a voltage #if LILKA_VERSION == 2 ////////////////////////////////////////////////////////////////////////// // Perform soldering test @@ -33,6 +36,9 @@ void Board::begin() { // Await pin to stabilize it's state(voltage, etc.) delayMicroseconds(PIN_AWAIT_TIME); + // Setup attenuation for ADC + analogSetAttenuation(ADC_11db); + // Test connections based on a fact // that pins shouldn't be shorted for (int i = 0; i < sizeof(testPins) / sizeof(testPins[0]); i++) { @@ -43,7 +49,24 @@ void Board::begin() { // Read other testPins to check on shorts for (int j = i + 1; j < sizeof(testPins) / sizeof(testPins[0]); j++) { - bool shorted = digitalRead(testPins[j]) == HIGH; + bool shorted = false; + // For esp32s3 + // ADC1 is acessible for GPIO(1-10) + // ADC2 is acessible for GPIO(11-20) + if (testPins[j] <= 20) { + unsigned long samplesSum = 0; + for (int k = 0; k < ADC_SAMPLES; k++) { + samplesSum += analogRead(testPins[j]); + delayMicroseconds(PIN_AWAIT_TIME); + } + unsigned long avgRead = (samplesSum / ADC_SAMPLES); + + if (avgRead >= ADC_READ_TRIGGER_VAL) shorted = true; + //lilka::serial.log("set HIGH on %d, measured voltage on %d is %lu", testPins[i], testPins[j], avgRead); + } else { + // This pin has no ADC power, use GPIO read instead + shorted = digitalRead(testPins[j]) == HIGH; + } if (shorted) { lilka::serial.log("Found connection between GPIOs %d and %d\n", testPins[i], testPins[j]); } @@ -52,7 +75,9 @@ void Board::begin() { digitalWrite(testPins[i], LOW); pinMode(testPins[i], INPUT_PULLDOWN); } - +# undef ADC_SAMPLES +# undef PIN_AWAIT_TIME +# undef ADC_READ_TRIGGER_VAL #endif // Iterate over the pins, set them as inputs From 60e71d7e3ec8d3c700fdd91d165a7cd3921ea962 Mon Sep 17 00:00:00 2001 From: Alex <15167344+frostmorn@users.noreply.github.com> Date: Tue, 12 May 2026 21:33:53 +0000 Subject: [PATCH 3/5] Try test on random pattern --- lib/lilka/src/lilka/board.cpp | 58 ++++++++++++++++------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/lilka/src/lilka/board.cpp b/lib/lilka/src/lilka/board.cpp index f98fe21..6be8e86 100644 --- a/lib/lilka/src/lilka/board.cpp +++ b/lib/lilka/src/lilka/board.cpp @@ -29,6 +29,10 @@ void Board::begin() { ////////////////////////////////////////////////////////////////////////// const int testPins[] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 38, 39, 40, 41, 42, 43, 44, 47, 48}; + + const int testPattern[] = { + HIGH, LOW, HIGH, HIGH, LOW, HIGH, LOW, LOW, HIGH, LOW, HIGH, HIGH, HIGH, LOW, HIGH, LOW, HIGH, LOW + }; // Configure pin mode for all pins for (auto pin : testPins) { pinMode(pin, INPUT_PULLDOWN); @@ -36,51 +40,41 @@ void Board::begin() { // Await pin to stabilize it's state(voltage, etc.) delayMicroseconds(PIN_AWAIT_TIME); - // Setup attenuation for ADC - analogSetAttenuation(ADC_11db); + for (int testPinAIndex = 0; testPinAIndex < sizeof(testPins) / sizeof(testPins[0]); testPinAIndex++) { + for (int testPatternIndex = 0; testPatternIndex < sizeof(testPattern) / sizeof(testPattern[0]); + testPatternIndex++) { + bool shorted = true; - // Test connections based on a fact - // that pins shouldn't be shorted - for (int i = 0; i < sizeof(testPins) / sizeof(testPins[0]); i++) { - // Setup high on a testPin - pinMode(testPins[i], OUTPUT); - digitalWrite(testPins[i], HIGH); - delayMicroseconds(PIN_AWAIT_TIME); + // Setup testPattern value on test pin + pinMode(testPins[testPinAIndex], OUTPUT); - // Read other testPins to check on shorts - for (int j = i + 1; j < sizeof(testPins) / sizeof(testPins[0]); j++) { - bool shorted = false; - // For esp32s3 - // ADC1 is acessible for GPIO(1-10) - // ADC2 is acessible for GPIO(11-20) - if (testPins[j] <= 20) { - unsigned long samplesSum = 0; - for (int k = 0; k < ADC_SAMPLES; k++) { - samplesSum += analogRead(testPins[j]); - delayMicroseconds(PIN_AWAIT_TIME); - } - unsigned long avgRead = (samplesSum / ADC_SAMPLES); + digitalWrite(testPins[testPinAIndex], testPattern[testPatternIndex]); + delayMicroseconds(PIN_AWAIT_TIME); - if (avgRead >= ADC_READ_TRIGGER_VAL) shorted = true; - //lilka::serial.log("set HIGH on %d, measured voltage on %d is %lu", testPins[i], testPins[j], avgRead); - } else { - // This pin has no ADC power, use GPIO read instead - shorted = digitalRead(testPins[j]) == HIGH; + // Read other testPins to check on shorts + int testPinBIndex = testPinAIndex + 1; + for (; testPinBIndex < sizeof(testPins) / sizeof(testPins[0]); testPinBIndex++) { + if (digitalRead(testPins[testPinBIndex]) != testPattern[testPatternIndex]) { + shorted = false; + break; + } } if (shorted) { - lilka::serial.log("Found connection between GPIOs %d and %d\n", testPins[i], testPins[j]); + lilka::serial.log( + "Found connection between GPIOs %d and %d\n", testPins[testPinAIndex], testPins[testPinBIndex] + ); } + // Restore testPin state + digitalWrite(testPins[testPinAIndex], LOW); + pinMode(testPins[testPinAIndex], INPUT_PULLDOWN); } - // Restore testPin state - digitalWrite(testPins[i], LOW); - pinMode(testPins[i], INPUT_PULLDOWN); } # undef ADC_SAMPLES # undef PIN_AWAIT_TIME # undef ADC_READ_TRIGGER_VAL #endif - // Iterate over the pins, set them as inputs +// Iterate over the pins, set them as inputs #if LILKA_VERSION >= 2 for (int pin : LILKA_EXT_PINS) { pinMode(pin, INPUT); From 0333d8f89766ab1db4b5d4ba367c72512f5e94ff Mon Sep 17 00:00:00 2001 From: Alex <15167344+frostmorn@users.noreply.github.com> Date: Tue, 12 May 2026 22:14:49 +0000 Subject: [PATCH 4/5] Fix logic, test through pins through pattern --- lib/lilka/src/lilka/board.cpp | 46 +++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/lilka/src/lilka/board.cpp b/lib/lilka/src/lilka/board.cpp index 6be8e86..fba51c3 100644 --- a/lib/lilka/src/lilka/board.cpp +++ b/lib/lilka/src/lilka/board.cpp @@ -14,9 +14,7 @@ Board::Board() { } void Board::begin() { -#define PIN_AWAIT_TIME 60 -#define ADC_SAMPLES 10 -#define ADC_READ_TRIGGER_VAL 4000 // Note: it's not a voltage +#define PIN_AWAIT_TIME 60 #if LILKA_VERSION == 2 ////////////////////////////////////////////////////////////////////////// // Perform soldering test @@ -40,38 +38,34 @@ void Board::begin() { // Await pin to stabilize it's state(voltage, etc.) delayMicroseconds(PIN_AWAIT_TIME); - for (int testPinAIndex = 0; testPinAIndex < sizeof(testPins) / sizeof(testPins[0]); testPinAIndex++) { - for (int testPatternIndex = 0; testPatternIndex < sizeof(testPattern) / sizeof(testPattern[0]); - testPatternIndex++) { - bool shorted = true; + auto testPinsCount = sizeof(testPins) / sizeof(testPins[0]); + auto testCount = sizeof(testPattern) / sizeof(testPattern[0]); - // Setup testPattern value on test pin - pinMode(testPins[testPinAIndex], OUTPUT); + for (int i = 0; i < testPinsCount; i++) { + // setup pin mode for a testPinA + pinMode(testPins[i], OUTPUT); - digitalWrite(testPins[testPinAIndex], testPattern[testPatternIndex]); - delayMicroseconds(PIN_AWAIT_TIME); + // iterate over all tested pins + for (int j = i + 1; j < testPinsCount; j++) { + // default i <> j pins tate + bool shorted = true; + // iterate over tested pattern + for (int k = 0; k < testCount; k++) { + digitalWrite(testPins[i], testPattern[k]); + delayMicroseconds(PIN_AWAIT_TIME); - // Read other testPins to check on shorts - int testPinBIndex = testPinAIndex + 1; - for (; testPinBIndex < sizeof(testPins) / sizeof(testPins[0]); testPinBIndex++) { - if (digitalRead(testPins[testPinBIndex]) != testPattern[testPatternIndex]) { + if (digitalRead(testPins[j]) != testPattern[k]) { shorted = false; - break; } } - if (shorted) { - lilka::serial.log( - "Found connection between GPIOs %d and %d\n", testPins[testPinAIndex], testPins[testPinBIndex] - ); - } - // Restore testPin state - digitalWrite(testPins[testPinAIndex], LOW); - pinMode(testPins[testPinAIndex], INPUT_PULLDOWN); + if (shorted) lilka::serial.err("Found short between GPIOs %d and %d\n", testPins[i], testPins[j]); } + // Restore testPin state + digitalWrite(testPins[i], LOW); + pinMode(testPins[i], INPUT_PULLDOWN); } -# undef ADC_SAMPLES + # undef PIN_AWAIT_TIME -# undef ADC_READ_TRIGGER_VAL #endif // Iterate over the pins, set them as inputs From cdf9d93d3bd05bd0a0211c3583bdfad976a0ae83 Mon Sep 17 00:00:00 2001 From: Alex <15167344+frostmorn@users.noreply.github.com> Date: Tue, 12 May 2026 22:52:24 +0000 Subject: [PATCH 5/5] Remove non existing pins from testPins --- lib/lilka/src/lilka/board.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/lilka/src/lilka/board.cpp b/lib/lilka/src/lilka/board.cpp index fba51c3..e0ca3f3 100644 --- a/lib/lilka/src/lilka/board.cpp +++ b/lib/lilka/src/lilka/board.cpp @@ -22,11 +22,12 @@ void Board::begin() { // For V2: // GPIO19-20 USB // GPIO0, GPIO3, GPIO45, GPIO 46 Strap pins + // GPIO22-25 Just do not exist[lol:D] // GPIO26-32 Reserved for PSRAM // GPIO33-37 Reserved for Octal PSRAM ////////////////////////////////////////////////////////////////////////// - const int testPins[] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 21, 22, 23, 24, 25, 38, 39, 40, 41, 42, 43, 44, 47, 48}; + const int testPins[] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 21, 38, 39, 40, 41, 42, 43, 44, 47, 48}; const int testPattern[] = { HIGH, LOW, HIGH, HIGH, LOW, HIGH, LOW, LOW, HIGH, LOW, HIGH, HIGH, HIGH, LOW, HIGH, LOW, HIGH, LOW @@ -53,9 +54,9 @@ void Board::begin() { for (int k = 0; k < testCount; k++) { digitalWrite(testPins[i], testPattern[k]); delayMicroseconds(PIN_AWAIT_TIME); - if (digitalRead(testPins[j]) != testPattern[k]) { shorted = false; + break; } } if (shorted) lilka::serial.err("Found short between GPIOs %d and %d\n", testPins[i], testPins[j]);