File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -784,17 +784,23 @@ void analogWrite(uint8_t pin, int value) {
784
784
}
785
785
786
786
void 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
+ }
790
793
}
791
794
analog_frequency = freq ;
792
795
}
793
796
794
797
void 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
+ }
798
804
}
799
805
analog_resolution = resolution ;
800
806
}
You can’t perform that action at this time.
0 commit comments