добавлены дефайны для теста разводки оптики

запущено все на s3
скорректированны пины и шим на s3
This commit is contained in:
2026-08-11 21:43:43 +03:00
parent 9d474eb62b
commit f56595f767
6 changed files with 109 additions and 13 deletions

View File

@@ -127,6 +127,7 @@ void App::update() {
else if (now - bootCheckStartedMs_ >= FACTORY_RESET_HOLD_MS) finishInitialization(true);
return;
}
serviceRxPinStateLog();
if (state_ != AppState::IDLE && state_ != AppState::MENU && state_ != AppState::FINISHED &&
startEvent == ButtonEvent::LONG) { abortTest(); return; }
if (state_ != AppState::IDLE && state_ != AppState::MENU && state_ != AppState::FINISHED &&
@@ -208,6 +209,19 @@ void App::sanitizeRange() {
settings_.endIndex %= countOf(END_FREQ_OPTIONS_HZ);
}
void App::serviceRxPinStateLog() {
#ifdef RX_PIN_CHANGE_TEST
const bool level = digitalRead(GPIO_RX) == HIGH;
const bool outsideTest = state_ == AppState::IDLE || state_ == AppState::MENU ||
state_ == AppState::SLAVE_READY || state_ == AppState::FINISHED;
if (rxPinStateKnown_ && level != rxPinState_ && outsideTest)
Log::printf("RX TEST", "GPIO=%u state=%s (%u)", GPIO_RX,
level ? "HIGH" : "LOW", level ? 1U : 0U);
rxPinState_ = level;
rxPinStateKnown_ = true;
#endif
}
void App::changeMenu(int d) {
sanitizeRange();
uint8_t *value = nullptr; size_t count = 0;

View File

@@ -48,6 +48,7 @@ class App {
void updateHeartbeat();
bool packetForCurrent(const ProtocolPacket &p) const;
void serviceIdlePowerSave();
void serviceRxPinStateLog();
void leaveIdlePowerSave(bool wakeDisplay = true);
bool idlePowerSaveAllowed() const;
void setActivePerformance(bool active);
@@ -81,4 +82,5 @@ class App {
bool stageStartConfirmed_ = false;
uint32_t lastUserActivityMs_ = 0;
bool idlePowerSave_ = false;
bool rxPinStateKnown_ = false, rxPinState_ = false;
};

View File

@@ -3,9 +3,22 @@
#include <Arduino.h>
// ------------------------- Hardware configuration -------------------------
// Uncomment for the hand-wired prototype. The production PCB assignments
// below follow the physical header positions shown in the schematic.
// #define MAKETKA
// Enabled for the hand-wired prototype. Comment out for the production PCB.
// Both profiles map S3 signals by physical header position with 5V/GND aligned.
#define MAKETKA
// Additionally log raw GPIO_RX level changes while no test is running.
//#define RX_PIN_CHANGE_TEST
// Standalone PWM output check. While enabled, the normal application is not
// started: GPIO_PWM continuously outputs the frequency and duty below.
// Comment this define out after the hardware check.
//#define PWM_OUTPUT_TEST
constexpr uint32_t PWM_OUTPUT_TEST_FREQUENCY_HZ = 1000;
constexpr uint32_t PWM_OUTPUT_TEST_SWEEP_PERIOD_MS = 2000;
constexpr uint32_t PWM_OUTPUT_TEST_UPDATE_MS = 10;
constexpr uint8_t PWM_OUTPUT_TEST_MIN_DUTY_PCT = 5;
constexpr uint8_t PWM_OUTPUT_TEST_MAX_DUTY_PCT = 95;
#if CONFIG_IDF_TARGET_ESP32C3
constexpr bool TARGET_IS_C3 = true;
@@ -25,12 +38,13 @@ constexpr uint8_t GPIO_SCL = 7;
#elif CONFIG_IDF_TARGET_ESP32S3
constexpr bool TARGET_IS_C3 = false;
#ifdef MAKETKA
constexpr uint8_t GPIO_PWM = 4;
constexpr uint8_t GPIO_RX = 5;
constexpr uint8_t GPIO_BUTTON_MODE = 0;
constexpr uint8_t GPIO_BUTTON_START = 1;
constexpr uint8_t GPIO_SDA = 8;
constexpr uint8_t GPIO_SCL = 9;
// Same physical header contacts as the C3 MAKETKA profile when 5V/GND align.
constexpr uint8_t GPIO_PWM = 12;
constexpr uint8_t GPIO_RX = 13;
constexpr uint8_t GPIO_BUTTON_MODE = 9;
constexpr uint8_t GPIO_BUTTON_START = 10;
constexpr uint8_t GPIO_SDA = 44;
constexpr uint8_t GPIO_SCL = 1;
#else
// The S3 SuperMini is fitted so its 5V and GND pins occupy the same PCB
// contacts as on the C3 SuperMini. Signals therefore follow header position.
@@ -58,7 +72,7 @@ constexpr bool SERIAL_MINIMAL_LOG = true;
#define BUTTON_ACTIVE_LEVEL LOW
#define RX_SIGNAL_INVERTED false
#define PWM_SAFE_LEVEL LOW
#define PWM_SAFE_LEVEL HIGH
#define PWM_SETTLE_CYCLES 5U
constexpr uint32_t BUTTON_DEBOUNCE_MS = 30;

View File

@@ -1,7 +1,57 @@
#include "App.h"
#include "Config.h"
#include <math.h>
#ifdef PWM_OUTPUT_TEST
PwmGenerator pwmOutputTest;
uint8_t pwmOutputTestDuty = 50;
uint32_t pwmOutputTestUpdatedMs = 0;
void setup() {
Serial.begin(SERIAL_BAUD);
delay(200);
Serial.printf("\nPWM OUTPUT TEST: GPIO=%u requested=%luHz duty=%u..%u%% sine=%lums safe=%s\n",
GPIO_PWM, PWM_OUTPUT_TEST_FREQUENCY_HZ,
PWM_OUTPUT_TEST_MIN_DUTY_PCT, PWM_OUTPUT_TEST_MAX_DUTY_PCT,
PWM_OUTPUT_TEST_SWEEP_PERIOD_MS,
PWM_SAFE_LEVEL == HIGH ? "HIGH" : "LOW");
pwmOutputTest.begin();
ActualPwm actual = {};
if (pwmOutputTest.start(PWM_OUTPUT_TEST_FREQUENCY_HZ,
pwmOutputTestDuty, actual)) {
Serial.printf("PWM OUTPUT TEST STARTED: actual=%luHz duty=%.2f%% bits=%u\n",
actual.actualHz, actual.actualDutyPct, actual.bits);
} else {
Serial.println("PWM OUTPUT TEST FAILED");
}
}
void loop() {
const uint32_t now = millis();
if (now - pwmOutputTestUpdatedMs < PWM_OUTPUT_TEST_UPDATE_MS) return;
pwmOutputTestUpdatedMs = now;
constexpr float PWM_TWO_PI = 6.28318530718f;
const float phase = PWM_TWO_PI * (now % PWM_OUTPUT_TEST_SWEEP_PERIOD_MS) /
PWM_OUTPUT_TEST_SWEEP_PERIOD_MS;
const float center = (PWM_OUTPUT_TEST_MIN_DUTY_PCT + PWM_OUTPUT_TEST_MAX_DUTY_PCT) * 0.5f;
const float amplitude = (PWM_OUTPUT_TEST_MAX_DUTY_PCT - PWM_OUTPUT_TEST_MIN_DUTY_PCT) * 0.5f;
const uint8_t duty = static_cast<uint8_t>(center + amplitude * sinf(phase) + 0.5f);
if (duty == pwmOutputTestDuty) return;
ActualPwm actual = {};
if (pwmOutputTest.start(PWM_OUTPUT_TEST_FREQUENCY_HZ, duty, actual)) {
pwmOutputTestDuty = duty;
} else {
Serial.printf("PWM OUTPUT TEST UPDATE FAILED: duty=%u%%\n", duty);
delay(100);
}
}
#else
App app;
void setup() { app.begin(); }
void loop() { app.update(); }
#endif

View File

@@ -155,7 +155,10 @@ bool PwmGenerator::start(uint32_t hz, uint8_t dutyPct, ActualPwm &a) {
stop();
bool ok = mcpwm_timer_set_period(mcpwmTimer, periodTicks) == ESP_OK;
ok = ok && mcpwm_comparator_set_compare_value(mcpwmComparator, activeTicks) == ESP_OK;
ok = ok && mcpwm_generator_set_force_level(mcpwmGenerator, -1, false) == ESP_OK;
// stop() applies a continuous force level (hold_on=true). Remove that same
// continuous-force action; hold_on=false addresses a different, one-shot
// force mechanism and would leave the safe level permanently active.
ok = ok && mcpwm_generator_set_force_level(mcpwmGenerator, -1, true) == ESP_OK;
ok = ok && mcpwm_timer_start_stop(mcpwmTimer, MCPWM_TIMER_START_NO_STOP) == ESP_OK;
if (!ok) {
mcpwm_generator_set_force_level(mcpwmGenerator, PWM_SAFE_LEVEL, true);

File diff suppressed because one or more lines are too long