| 12 | static ledc_channel_t backlightChannel; |
| 13 | |
| 14 | bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) { |
| 15 | backlightPin = pin; |
| 16 | backlightTimer = timer; |
| 17 | backlightChannel = channel; |
| 18 | |
| 19 | LOGGER.info("Init"); |
| 20 | ledc_timer_config_t ledc_timer = { |
| 21 | .speed_mode = LEDC_LOW_SPEED_MODE, |
| 22 | .duty_resolution = LEDC_TIMER_8_BIT, |
| 23 | .timer_num = backlightTimer, |
| 24 | .freq_hz = frequencyHz, |
| 25 | .clk_cfg = LEDC_AUTO_CLK, |
| 26 | .deconfigure = false |
| 27 | }; |
| 28 | |
| 29 | if (ledc_timer_config(&ledc_timer) != ESP_OK) { |
| 30 | LOGGER.error("Timer config failed"); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | ledc_channel_config_t ledc_channel = { |
| 35 | .gpio_num = backlightPin, |
| 36 | .speed_mode = LEDC_LOW_SPEED_MODE, |
| 37 | .channel = backlightChannel, |
| 38 | .intr_type = LEDC_INTR_DISABLE, |
| 39 | .timer_sel = backlightTimer, |
| 40 | .duty = 0, |
| 41 | .hpoint = 0, |
| 42 | .sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD, |
| 43 | .flags = { |
| 44 | .output_invert = 0 |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | if (ledc_channel_config(&ledc_channel) != ESP_OK) { |
| 49 | LOGGER.error("Channel config failed"); |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | isBacklightInitialized = true; |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | bool setBacklightDuty(uint8_t duty) { |
| 59 | if (!isBacklightInitialized) { |