Migrate all ESP32 envs to Arduino-ESP32 3.x (pioarduino)
The registry espressif32 platform still ships Arduino core 2.0.17, which
lacks ESP32-C6 support. Switch every ESP32 env to the pioarduino fork
(Arduino-ESP32 3.x) via a shared ${common.platform_esp32} variable and
consolidate shared settings into [env].
Rewrite the PWM code for the 3.x LEDC API:
- ledcSetup + ledcAttachPin -> ledcAttach(pin, freq, res)
- ledcDetachPin -> ledcDetach
- ledcWrite now addresses PWM by pin instead of channel index
Adds the esp32-c6-devkitc-1 env; all four ESP32 envs build clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+7
-9
@@ -152,7 +152,7 @@ static void attachMeters() {
|
||||
|
||||
// Release the channel if it's no longer used or its pin changed.
|
||||
if (attachedPin[i] != -1 && attachedPin[i] != pin) {
|
||||
ledcDetachPin(attachedPin[i]);
|
||||
ledcDetach(attachedPin[i]);
|
||||
pinMode(attachedPin[i], OUTPUT);
|
||||
digitalWrite(attachedPin[i], LOW); // drive freed pin low so the meter reads zero
|
||||
Serial.printf("[PWM] detach ch%d pin%d\n", i, attachedPin[i]);
|
||||
@@ -160,8 +160,7 @@ static void attachMeters() {
|
||||
}
|
||||
|
||||
if (pin > 0 && attachedPin[i] != pin) {
|
||||
ledcSetup(i, PWM_FREQ, PWM_RES);
|
||||
ledcAttachPin(pin, i);
|
||||
ledcAttach(pin, PWM_FREQ, PWM_RES);
|
||||
attachedPin[i] = pin;
|
||||
Serial.printf("[PWM] attach ch%d pin%d\n", i, pin);
|
||||
}
|
||||
@@ -173,7 +172,7 @@ static void applyMeters() {
|
||||
if (meters[i].pin <= 0 || meters[i].maxDuty <= 0) continue;
|
||||
float pct = meters[i].currentValue / 100.0f * meters[i].maxDuty / 100.0f;
|
||||
int duty = constrain((int)(pct * 1023), 0, 1023);
|
||||
ledcWrite(i, duty);
|
||||
ledcWrite(meters[i].pin, duty);
|
||||
Serial.printf("[PWM] ch%d duty=%d (cur=%.1f maxD=%.1f)\n", i, duty, meters[i].currentValue, meters[i].maxDuty);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +221,7 @@ static void mqttCallback(char* topic, byte* payload, unsigned int len) {
|
||||
meters[idx].currentValue = physicalToPct(val, idx);
|
||||
if (meters[idx].pin > 0 && meters[idx].maxDuty > 0) {
|
||||
float pct = meters[idx].currentValue / 100.0f * meters[idx].maxDuty / 100.0f;
|
||||
ledcWrite(idx, constrain((int)(pct * 1023), 0, 1023));
|
||||
ledcWrite(meters[idx].pin, constrain((int)(pct * 1023), 0, 1023));
|
||||
}
|
||||
mqttPublishCurrent(idx);
|
||||
}
|
||||
@@ -686,7 +685,7 @@ static void handleSet() {
|
||||
if (meters[idx].pin > 0 && meters[idx].maxDuty > 0) {
|
||||
float pct = val / 100.0f * meters[idx].maxDuty / 100.0f;
|
||||
int duty = constrain((int)(pct * 1023), 0, 1023);
|
||||
ledcWrite(idx, duty);
|
||||
ledcWrite(meters[idx].pin, duty);
|
||||
}
|
||||
mqttPublishCurrent(idx);
|
||||
server.send(200);
|
||||
@@ -763,8 +762,7 @@ static void factoryReset(bool clearWifi) {
|
||||
// Attach meters temporarily for the sweep acknowledgement
|
||||
for (int i = 0; i < count && i < 8; i++) {
|
||||
if (meters[i].pin > 0) {
|
||||
ledcSetup(i, PWM_FREQ, PWM_RES);
|
||||
ledcAttachPin(meters[i].pin, i);
|
||||
ledcAttach(meters[i].pin, PWM_FREQ, PWM_RES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,7 +774,7 @@ static void factoryReset(bool clearWifi) {
|
||||
for (int i = 0; i < count && i < 8; i++) {
|
||||
if (meters[i].pin > 0 && meters[i].maxDuty > 0) {
|
||||
float duty = pct / 100.0f * meters[i].maxDuty / 100.0f;
|
||||
ledcWrite(i, constrain((int)(duty * 1023), 0, 1023));
|
||||
ledcWrite(meters[i].pin, constrain((int)(duty * 1023), 0, 1023));
|
||||
}
|
||||
}
|
||||
delay(50);
|
||||
|
||||
Reference in New Issue
Block a user