1 /*
2  * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include "soc/soc_caps.h"
16 #include "soc/clk_tree_defs.h"
17 
18 typedef enum {
19 #if SOC_LEDC_SUPPORT_HS_MODE
20     LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */
21 #endif
22     LEDC_LOW_SPEED_MODE,      /*!< LEDC low speed speed_mode */
23     LEDC_SPEED_MODE_MAX,      /*!< LEDC speed limit */
24 } ledc_mode_t;
25 
26 typedef enum {
27     LEDC_INTR_DISABLE = 0,    /*!< Disable LEDC interrupt */
28     LEDC_INTR_FADE_END,       /*!< Enable LEDC interrupt */
29     LEDC_INTR_MAX,
30 } ledc_intr_type_t;
31 
32 typedef enum {
33     LEDC_DUTY_DIR_DECREASE = 0,    /*!< LEDC duty decrease direction */
34     LEDC_DUTY_DIR_INCREASE = 1,    /*!< LEDC duty increase direction */
35     LEDC_DUTY_DIR_MAX,
36 } ledc_duty_direction_t;
37 
38 /**
39  * @brief LEDC global clock sources
40  */
41 typedef enum {
42     LEDC_SLOW_CLK_RC_FAST = LEDC_USE_RC_FAST_CLK, /*!< LEDC low speed timer clock source is RC_FAST clock*/
43 #if SOC_LEDC_SUPPORT_APB_CLOCK
44     LEDC_SLOW_CLK_APB = LEDC_USE_APB_CLK,         /*!< LEDC low speed timer clock source is 80MHz APB clock*/
45 #endif
46 #if SOC_LEDC_SUPPORT_PLL_DIV_CLOCK
47     LEDC_SLOW_CLK_PLL_DIV = LEDC_USE_PLL_DIV_CLK, /*!< LEDC low speed timer clock source is a PLL_DIV clock*/
48 #endif
49 #if SOC_LEDC_SUPPORT_XTAL_CLOCK
50     LEDC_SLOW_CLK_XTAL = LEDC_USE_XTAL_CLK,       /*!< LEDC low speed timer clock source XTAL clock*/
51 #endif
52 
53     LEDC_SLOW_CLK_RTC8M __attribute__((deprecated)) = LEDC_SLOW_CLK_RC_FAST,    /*!< Alias of 'LEDC_SLOW_CLK_RC_FAST'*/
54 } ledc_slow_clk_sel_t;
55 
56 /**
57  * @brief LEDC clock source configuration struct
58  *
59  * In theory, the following enumeration shall be placed in LEDC driver's header.
60  * However, as the next enumeration, `ledc_clk_src_t`, makes the use of some of
61  * these values and to avoid mutual inclusion of the headers, we must define it
62  * here.
63  */
64 typedef soc_periph_ledc_clk_src_legacy_t ledc_clk_cfg_t;
65 
66 /**
67  * @brief LEDC timer-specific clock sources
68  *
69  * Note: Setting numeric values to match ledc_clk_cfg_t values are a hack to avoid collision with
70  * LEDC_AUTO_CLK in the driver, as these enums have very similar names and user may pass
71  * one of these by mistake.
72  */
73 typedef enum  {
74 #if SOC_LEDC_SUPPORT_REF_TICK
75     LEDC_REF_TICK = LEDC_USE_REF_TICK, /*!< LEDC timer clock divided from reference tick (1Mhz) */
76 #endif
77 #if SOC_LEDC_SUPPORT_APB_CLOCK
78     LEDC_APB_CLK = LEDC_USE_APB_CLK,  /*!< LEDC timer clock divided from APB clock (80Mhz) */
79     LEDC_SCLK = LEDC_USE_APB_CLK,     /*!< Selecting this value for LEDC_TICK_SEL_TIMER let the hardware take its source clock from LEDC_APB_CLK_SEL */
80 #elif SOC_LEDC_SUPPORT_PLL_DIV_CLOCK
81     LEDC_SCLK = LEDC_USE_PLL_DIV_CLK, /*!< Selecting this value for LEDC_TICK_SEL_TIMER let the hardware take its source clock from LEDC_CLK_SEL */
82 #endif
83 } ledc_clk_src_t;
84 
85 typedef enum {
86     LEDC_TIMER_0 = 0, /*!< LEDC timer 0 */
87     LEDC_TIMER_1,     /*!< LEDC timer 1 */
88     LEDC_TIMER_2,     /*!< LEDC timer 2 */
89     LEDC_TIMER_3,     /*!< LEDC timer 3 */
90     LEDC_TIMER_MAX,
91 } ledc_timer_t;
92 
93 typedef enum {
94     LEDC_CHANNEL_0 = 0, /*!< LEDC channel 0 */
95     LEDC_CHANNEL_1,     /*!< LEDC channel 1 */
96     LEDC_CHANNEL_2,     /*!< LEDC channel 2 */
97     LEDC_CHANNEL_3,     /*!< LEDC channel 3 */
98     LEDC_CHANNEL_4,     /*!< LEDC channel 4 */
99     LEDC_CHANNEL_5,     /*!< LEDC channel 5 */
100 #if SOC_LEDC_CHANNEL_NUM > 6
101     LEDC_CHANNEL_6,     /*!< LEDC channel 6 */
102     LEDC_CHANNEL_7,     /*!< LEDC channel 7 */
103 #endif
104     LEDC_CHANNEL_MAX,
105 } ledc_channel_t;
106 
107 typedef enum {
108     LEDC_TIMER_1_BIT = 1,   /*!< LEDC PWM duty resolution of  1 bits */
109     LEDC_TIMER_2_BIT,       /*!< LEDC PWM duty resolution of  2 bits */
110     LEDC_TIMER_3_BIT,       /*!< LEDC PWM duty resolution of  3 bits */
111     LEDC_TIMER_4_BIT,       /*!< LEDC PWM duty resolution of  4 bits */
112     LEDC_TIMER_5_BIT,       /*!< LEDC PWM duty resolution of  5 bits */
113     LEDC_TIMER_6_BIT,       /*!< LEDC PWM duty resolution of  6 bits */
114     LEDC_TIMER_7_BIT,       /*!< LEDC PWM duty resolution of  7 bits */
115     LEDC_TIMER_8_BIT,       /*!< LEDC PWM duty resolution of  8 bits */
116     LEDC_TIMER_9_BIT,       /*!< LEDC PWM duty resolution of  9 bits */
117     LEDC_TIMER_10_BIT,      /*!< LEDC PWM duty resolution of 10 bits */
118     LEDC_TIMER_11_BIT,      /*!< LEDC PWM duty resolution of 11 bits */
119     LEDC_TIMER_12_BIT,      /*!< LEDC PWM duty resolution of 12 bits */
120     LEDC_TIMER_13_BIT,      /*!< LEDC PWM duty resolution of 13 bits */
121     LEDC_TIMER_14_BIT,      /*!< LEDC PWM duty resolution of 14 bits */
122 #if SOC_LEDC_TIMER_BIT_WIDTH > 14
123     LEDC_TIMER_15_BIT,      /*!< LEDC PWM duty resolution of 15 bits */
124     LEDC_TIMER_16_BIT,      /*!< LEDC PWM duty resolution of 16 bits */
125     LEDC_TIMER_17_BIT,      /*!< LEDC PWM duty resolution of 17 bits */
126     LEDC_TIMER_18_BIT,      /*!< LEDC PWM duty resolution of 18 bits */
127     LEDC_TIMER_19_BIT,      /*!< LEDC PWM duty resolution of 19 bits */
128     LEDC_TIMER_20_BIT,      /*!< LEDC PWM duty resolution of 20 bits */
129 #endif
130     LEDC_TIMER_BIT_MAX,
131 } ledc_timer_bit_t;
132 
133 typedef enum {
134     LEDC_FADE_NO_WAIT = 0,  /*!< LEDC fade function will return immediately */
135     LEDC_FADE_WAIT_DONE,    /*!< LEDC fade function will block until fading to the target duty */
136     LEDC_FADE_MAX,
137 } ledc_fade_mode_t;
138 
139 #ifdef __cplusplus
140 }
141 #endif
142