@@ -784,17 +784,23 @@ void analogWrite(uint8_t pin, int value) {
784784}
785785
786786void analogWriteFrequency (uint8_t pin , uint32_t freq ) {
787- if (ledcChangeFrequency (pin , freq , analog_resolution ) == 0 ) {
788- log_e ("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first" );
789- return ;
787+ ledc_channel_handle_t * bus = (ledc_channel_handle_t * )perimanGetPinBus (pin , ESP32_BUS_TYPE_LEDC );
788+ if (bus != NULL ) { // if pin is attached to LEDC change frequency, otherwise update the global frequency
789+ if (ledcChangeFrequency (pin , freq , analog_resolution ) == 0 ) {
790+ log_e ("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first" );
791+ return ;
792+ }
790793 }
791794 analog_frequency = freq ;
792795}
793796
794797void analogWriteResolution (uint8_t pin , uint8_t resolution ) {
795- if (ledcChangeFrequency (pin , analog_frequency , resolution ) == 0 ) {
796- log_e ("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first" );
797- return ;
798+ ledc_channel_handle_t * bus = (ledc_channel_handle_t * )perimanGetPinBus (pin , ESP32_BUS_TYPE_LEDC );
799+ if (bus != NULL ) { // if pin is attached to LEDC change resolution, otherwise update the global resolution
800+ if (ledcChangeFrequency (pin , analog_frequency , resolution ) == 0 ) {
801+ log_e ("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first" );
802+ return ;
803+ }
798804 }
799805 analog_resolution = resolution ;
800806}
0 commit comments