diff --git a/drivers/pwm/pwm_led_esp32.c b/drivers/pwm/pwm_led_esp32.c index 9bc18a1aca..915bbf2830 100644 --- a/drivers/pwm/pwm_led_esp32.c +++ b/drivers/pwm/pwm_led_esp32.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DT_DRV_COMPAT espressif_esp32_gpio +#define DT_DRV_COMPAT espressif_esp32_ledc /* Include esp-idf headers first to avoid redefining BIT() macro */ #include @@ -142,7 +142,6 @@ static void pwm_led_esp32_duty_config(int speed_mode, volatile uint32_t hpoint_addr; volatile uint32_t duty_addr; volatile uint32_t conf1_addr; - volatile uint32_t conf1_val; if (speed_mode == PWM_LED_ESP32_HIGH_SPEED) { hpoint_addr = PWM_ESP32_HSCH_HPOINT(channel); @@ -388,8 +387,6 @@ int pwm_led_esp32_init(const struct device *dev) #include #include -DEVICE_DECLARE(pwm_led_esp32_0); - #define CH_HS_TIMER(i) ((CONFIG_PWM_LED_ESP32_HS_CH ## i ## _TIMER) & 0x2) #define CH_HS_GPIO(i) ((CONFIG_PWM_LED_ESP32_HS_CH ## i ## _GPIO) & 0xfff) #define CH_LS_TIMER(i) ((CONFIG_PWM_LED_ESP32_LS_CH ## i ## _TIMER) & 0x2) @@ -503,7 +500,13 @@ const static struct pwm_led_esp32_config pwm_led_esp32_config = { }, }; -DEVICE_DEFINE(pwm_led_esp32_0, CONFIG_PWM_LED_ESP32_DEV_NAME_0, - pwm_led_esp32_init, NULL, NULL, - &pwm_led_esp32_config, POST_KERNEL, - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &pwm_led_esp32_api); +DEVICE_DT_DEFINE( + DT_NODELABEL(ledc0), + &pwm_led_esp32_init, + NULL, + NULL, + &pwm_led_esp32_config, + POST_KERNEL, + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, + &pwm_led_esp32_api +); diff --git a/dts/bindings/pwm/espressif,esp32-ledc.yaml b/dts/bindings/pwm/espressif,esp32-ledc.yaml new file mode 100644 index 0000000000..dfa81bff8a --- /dev/null +++ b/dts/bindings/pwm/espressif,esp32-ledc.yaml @@ -0,0 +1,17 @@ +description: ESP32 LEDC + +compatible: "espressif,esp32-ledc" + +include: [pwm-controller.yaml, base.yaml] + +properties: + label: + required: true + + "#pwm-cells": + const: 3 + +pwm-cells: + - channel + - period + - flags diff --git a/dts/xtensa/espressif/esp32.dtsi b/dts/xtensa/espressif/esp32.dtsi index 45b2061b16..89bb61f5ab 100644 --- a/dts/xtensa/espressif/esp32.dtsi +++ b/dts/xtensa/espressif/esp32.dtsi @@ -116,6 +116,15 @@ reg = <0x3ff49000 0x94>; }; + ledc0: ledc@3ff59000 { + compatible = "espressif,esp32-ledc"; + pwm-controller; + #pwm-cells = <3>; + reg = <0x3ff59000 0x800>; + label = "LEDC_0"; + status = "disabled"; + }; + gpio0: gpio@3ff44000 { compatible = "espressif,esp32-gpio"; gpio-controller; diff --git a/include/drivers/gpio/gpio_esp32.h b/include/drivers/gpio/gpio_esp32.h index 96c2b5f299..2cf49a8ec4 100644 --- a/include/drivers/gpio/gpio_esp32.h +++ b/include/drivers/gpio/gpio_esp32.h @@ -2,6 +2,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + #ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_ESP32_H_ #define ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_ESP32_H_