Skip to content

new Core 3.x API: combine setup + attach#14

Merged
end2endzone merged 2 commits intoend2endzone:masterfrom
ryanhz:master
Oct 10, 2025
Merged

new Core 3.x API: combine setup + attach#14
end2endzone merged 2 commits intoend2endzone:masterfrom
ryanhz:master

Conversation

@ryanhz
Copy link
Contributor

@ryanhz ryanhz commented Oct 1, 2025

ledcSetup and ledcAttachPin have been removed and merged into ledcAttach new API in ESP32 Core 3.x API

@ryanhz
Copy link
Contributor Author

ryanhz commented Oct 1, 2025

this fix #13

In Arduino-ESP32 Core 3.x, the ledcSetup(...) and ledcAttachPin(...) APIs were removed and replaced by a new ledcAttach(...) API that merges setup + attach.
Copy link
Owner

@end2endzone end2endzone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution!

@end2endzone end2endzone merged commit 6964795 into end2endzone:master Oct 10, 2025
1 check passed
@end2endzone
Copy link
Owner

end2endzone commented Oct 10, 2025

@ryanhz Hi. How did you come up about macro ARDUINO_ESP32_MAJOR ? I am searching multiple locations and I cannot find a reference about to this macro. I've installed esp32 core v3.3.1 and this macro do not seems to be resolving properly.
I am expecting to have this macro available.

If I compile the following code on esp32:esp32:

#if defined(ESP32)
  #if ARDUINO_ESP32_MAJOR >= 3
    aaa
  #elif ARDUINO_ESP32_MAJOR >= 2
    bbb
  #elif ARDUINO_ESP32_MAJOR >= 1
    ccc
  #else
    yyy
  #endif
#endif

the compilation fails with error: 'yyy' was not declared in this scope. In other words, the macro does not seems to be defined as you expect.

The macro ARDUINO_ESP32_MAJOR does not seems to be available in arduino-esp32 core:
https://github.com/search?q=repo%3Aespressif%2Farduino-esp32%20ARDUINO_ESP32_MAJOR%20&type=code

I've installed the esp32 core 3.3.1. Please advise.

@end2endzone
Copy link
Owner

end2endzone commented Oct 10, 2025

@ryanhz
Yeah, the macro is not defined:

  #if !defined(ARDUINO_ESP32_MAJOR)
    it_is_undefined
  #endif

fails with error: 'it_is_undefined' was not declared in this scope.

Are you using a custom framework for compiling your esp32 projects ?

The appropriate way seems to be with the following:

#if defined(ESP32)
  #ifdef ESP_ARDUINO_VERSION
    #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
      // Code specific to ESP32 core 3.x
      q111
    #elif ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
      // Code specific to ESP32 core 2.x
      q222
    #else
      #error ESP32 arduino version unsupported
    #endif
  #else
    // Fallback for older versions (pre-2.x)
    #error ESP32 arduino version unsupported
  #endif
#endif

which fails as expected with error: 'q111' was not declared in this scope; did you mean 'B111'?.

Reference: arduino-esp32's Compatibility Guide for ESP32 Arduino Core.

@ryanhz
Copy link
Contributor Author

ryanhz commented Oct 11, 2025

@end2endzone Sorry, the macro should be ESP_ARDUINO_VERSION_MAJOR. ChatGPT sometimes gave me wrong code.
I thought this is just a 2 lines fix, the pull request was created before I found it not working in ESP32 Core 3.x. There are other places hardcoded channel 0 like

void tone(int frq) {
  ledcWriteTone(0, frq); // channel, freq
  ledcWrite(0, 255); // channel, volume
}

So eventually, I rewrote the whole file at the help of GPT (this commit in my fork), which is working in Core 3.x as I tested, but I haven't test back on core.x. Do you want to to create another pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants