1010#include "driver/ledc.h"
1111#include "driver/gpio.h"
1212#include "esp_log.h"
13- #include "esp_rom_gpio.h" // for output signal inversion
1413#include "soc/ledc_periph.h" // to invert LEDC output on IDF version < v4.3
1514
1615typedef struct {
@@ -22,11 +21,16 @@ static const char *TAG = "disp_backlight";
2221
2322disp_backlight_h disp_backlight_new (const disp_backlight_config_t * config )
2423{
24+ // Check input parameters
2525 if (config == NULL )
2626 return NULL ;
27+ if (!GPIO_IS_VALID_OUTPUT_GPIO (config -> gpio_num )) {
28+ ESP_LOGW (TAG , "Invalid GPIO number" );
29+ return NULL ;
30+ }
2731 disp_backlight_t * bckl_dev = calloc (1 , sizeof (disp_backlight_t ));
2832 if (bckl_dev == NULL ){
29- ESP_LOGW (TAG , "Could not create new LCD backlight instance " );
33+ ESP_LOGW (TAG , "Not enough memory " );
3034 return NULL ;
3135 }
3236
@@ -52,15 +56,15 @@ disp_backlight_h disp_backlight_new(const disp_backlight_config_t *config)
5256
5357 ESP_ERROR_CHECK (ledc_timer_config (& LCD_backlight_timer ));
5458 ESP_ERROR_CHECK (ledc_channel_config (& LCD_backlight_channel ));
55- esp_rom_gpio_connect_out_signal (config -> gpio_num , ledc_periph_signal [LEDC_LOW_SPEED_MODE ].sig_out0_idx + config -> channel_idx , config -> output_invert , 0 );
59+ gpio_matrix_out (config -> gpio_num , ledc_periph_signal [LEDC_LOW_SPEED_MODE ].sig_out0_idx + config -> channel_idx , config -> output_invert , 0 );
5660 }
5761 else
5862 {
5963 // Configure GPIO for output
6064 bckl_dev -> index = config -> gpio_num ;
6165 gpio_pad_select_gpio (config -> gpio_num );
6266 ESP_ERROR_CHECK (gpio_set_direction (config -> gpio_num , GPIO_MODE_OUTPUT ));
63- esp_rom_gpio_connect_out_signal (config -> gpio_num , SIG_GPIO_OUT_IDX , config -> output_invert , false);
67+ gpio_matrix_out (config -> gpio_num , SIG_GPIO_OUT_IDX , config -> output_invert , false);
6468 }
6569
6670 return (disp_backlight_h )bckl_dev ;
0 commit comments