1 // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include "soc/soc_caps.h" 24 25 typedef enum { 26 #if SOC_LEDC_SUPPORT_HS_MODE 27 LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */ 28 #endif 29 LEDC_LOW_SPEED_MODE, /*!< LEDC low speed speed_mode */ 30 LEDC_SPEED_MODE_MAX, /*!< LEDC speed limit */ 31 } ledc_mode_t; 32 33 typedef enum { 34 LEDC_INTR_DISABLE = 0, /*!< Disable LEDC interrupt */ 35 LEDC_INTR_FADE_END, /*!< Enable LEDC interrupt */ 36 LEDC_INTR_MAX, 37 } ledc_intr_type_t; 38 39 typedef enum { 40 LEDC_DUTY_DIR_DECREASE = 0, /*!< LEDC duty decrease direction */ 41 LEDC_DUTY_DIR_INCREASE = 1, /*!< LEDC duty increase direction */ 42 LEDC_DUTY_DIR_MAX, 43 } ledc_duty_direction_t; 44 45 typedef enum { 46 LEDC_SLOW_CLK_RTC8M = 0, /*!< LEDC low speed timer clock source is 8MHz RTC clock*/ 47 LEDC_SLOW_CLK_APB, /*!< LEDC low speed timer clock source is 80MHz APB clock*/ 48 #if SOC_LEDC_SUPPORT_XTAL_CLOCK 49 LEDC_SLOW_CLK_XTAL, /*!< LEDC low speed timer clock source XTAL clock*/ 50 #endif 51 } ledc_slow_clk_sel_t; 52 53 typedef enum { 54 LEDC_AUTO_CLK = 0, /*!< The driver will automatically select the source clock(REF_TICK or APB) based on the giving resolution and duty parameter when init the timer*/ 55 LEDC_USE_REF_TICK, /*!< LEDC timer select REF_TICK clock as source clock*/ 56 LEDC_USE_APB_CLK, /*!< LEDC timer select APB clock as source clock*/ 57 LEDC_USE_RTC8M_CLK, /*!< LEDC timer select RTC8M_CLK as source clock. Only for low speed channels and this parameter must be the same for all low speed channels*/ 58 #if SOC_LEDC_SUPPORT_XTAL_CLOCK 59 LEDC_USE_XTAL_CLK, /*!< LEDC timer select XTAL clock as source clock*/ 60 #endif 61 } ledc_clk_cfg_t; 62 63 /* Note: Setting numeric values to match ledc_clk_cfg_t values are a hack to avoid collision with 64 LEDC_AUTO_CLK in the driver, as these enums have very similar names and user may pass 65 one of these by mistake. */ 66 typedef enum { 67 LEDC_REF_TICK = LEDC_USE_REF_TICK, /*!< LEDC timer clock divided from reference tick (1Mhz) */ 68 LEDC_APB_CLK = LEDC_USE_APB_CLK, /*!< LEDC timer clock divided from APB clock (80Mhz) */ 69 } ledc_clk_src_t; 70 71 72 typedef enum { 73 LEDC_TIMER_0 = 0, /*!< LEDC timer 0 */ 74 LEDC_TIMER_1, /*!< LEDC timer 1 */ 75 LEDC_TIMER_2, /*!< LEDC timer 2 */ 76 LEDC_TIMER_3, /*!< LEDC timer 3 */ 77 LEDC_TIMER_MAX, 78 } ledc_timer_t; 79 80 typedef enum { 81 LEDC_CHANNEL_0 = 0, /*!< LEDC channel 0 */ 82 LEDC_CHANNEL_1, /*!< LEDC channel 1 */ 83 LEDC_CHANNEL_2, /*!< LEDC channel 2 */ 84 LEDC_CHANNEL_3, /*!< LEDC channel 3 */ 85 LEDC_CHANNEL_4, /*!< LEDC channel 4 */ 86 LEDC_CHANNEL_5, /*!< LEDC channel 5 */ 87 #if SOC_LEDC_CHANNEL_NUM > 6 88 LEDC_CHANNEL_6, /*!< LEDC channel 6 */ 89 LEDC_CHANNEL_7, /*!< LEDC channel 7 */ 90 #endif 91 LEDC_CHANNEL_MAX, 92 } ledc_channel_t; 93 94 typedef enum { 95 LEDC_TIMER_1_BIT = 1, /*!< LEDC PWM duty resolution of 1 bits */ 96 LEDC_TIMER_2_BIT, /*!< LEDC PWM duty resolution of 2 bits */ 97 LEDC_TIMER_3_BIT, /*!< LEDC PWM duty resolution of 3 bits */ 98 LEDC_TIMER_4_BIT, /*!< LEDC PWM duty resolution of 4 bits */ 99 LEDC_TIMER_5_BIT, /*!< LEDC PWM duty resolution of 5 bits */ 100 LEDC_TIMER_6_BIT, /*!< LEDC PWM duty resolution of 6 bits */ 101 LEDC_TIMER_7_BIT, /*!< LEDC PWM duty resolution of 7 bits */ 102 LEDC_TIMER_8_BIT, /*!< LEDC PWM duty resolution of 8 bits */ 103 LEDC_TIMER_9_BIT, /*!< LEDC PWM duty resolution of 9 bits */ 104 LEDC_TIMER_10_BIT, /*!< LEDC PWM duty resolution of 10 bits */ 105 LEDC_TIMER_11_BIT, /*!< LEDC PWM duty resolution of 11 bits */ 106 LEDC_TIMER_12_BIT, /*!< LEDC PWM duty resolution of 12 bits */ 107 LEDC_TIMER_13_BIT, /*!< LEDC PWM duty resolution of 13 bits */ 108 LEDC_TIMER_14_BIT, /*!< LEDC PWM duty resolution of 14 bits */ 109 #if SOC_LEDC_TIMER_BIT_WIDE_NUM > 14 110 LEDC_TIMER_15_BIT, /*!< LEDC PWM duty resolution of 15 bits */ 111 LEDC_TIMER_16_BIT, /*!< LEDC PWM duty resolution of 16 bits */ 112 LEDC_TIMER_17_BIT, /*!< LEDC PWM duty resolution of 17 bits */ 113 LEDC_TIMER_18_BIT, /*!< LEDC PWM duty resolution of 18 bits */ 114 LEDC_TIMER_19_BIT, /*!< LEDC PWM duty resolution of 19 bits */ 115 LEDC_TIMER_20_BIT, /*!< LEDC PWM duty resolution of 20 bits */ 116 #endif 117 LEDC_TIMER_BIT_MAX, 118 } ledc_timer_bit_t; 119 120 typedef enum { 121 LEDC_FADE_NO_WAIT = 0, /*!< LEDC fade function will return immediately */ 122 LEDC_FADE_WAIT_DONE, /*!< LEDC fade function will block until fading to the target duty */ 123 LEDC_FADE_MAX, 124 } ledc_fade_mode_t; 125 126 /** 127 * @brief Configuration parameters of LEDC channel for ledc_channel_config function 128 */ 129 typedef struct { 130 int gpio_num; /*!< the LEDC output gpio_num, if you want to use gpio16, gpio_num = 16 */ 131 ledc_mode_t speed_mode; /*!< LEDC speed speed_mode, high-speed mode or low-speed mode */ 132 ledc_channel_t channel; /*!< LEDC channel (0 - 7) */ 133 ledc_intr_type_t intr_type; /*!< configure interrupt, Fade interrupt enable or Fade interrupt disable */ 134 ledc_timer_t timer_sel; /*!< Select the timer source of channel (0 - 3) */ 135 uint32_t duty; /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */ 136 int hpoint; /*!< LEDC channel hpoint value, the max value is 0xfffff */ 137 struct { 138 unsigned int output_invert: 1;/*!< Enable (1) or disable (0) gpio output invert */ 139 } flags; /*!< LEDC flags */ 140 141 } ledc_channel_config_t; 142 143 /** 144 * @brief Configuration parameters of LEDC Timer timer for ledc_timer_config function 145 */ 146 typedef struct { 147 ledc_mode_t speed_mode; /*!< LEDC speed speed_mode, high-speed mode or low-speed mode */ 148 union { 149 ledc_timer_bit_t duty_resolution; /*!< LEDC channel duty resolution */ 150 ledc_timer_bit_t bit_num __attribute__((deprecated)); /*!< Deprecated in ESP-IDF 3.0. This is an alias to 'duty_resolution' for backward compatibility with ESP-IDF 2.1 */ 151 }; 152 ledc_timer_t timer_num; /*!< The timer source of channel (0 - 3) */ 153 uint32_t freq_hz; /*!< LEDC timer frequency (Hz) */ 154 ledc_clk_cfg_t clk_cfg; /*!< Configure LEDC source clock. 155 For low speed channels and high speed channels, you can specify the source clock using LEDC_USE_REF_TICK, LEDC_USE_APB_CLK or LEDC_AUTO_CLK. 156 For low speed channels, you can also specify the source clock using LEDC_USE_RTC8M_CLK, in this case, all low speed channel's source clock must be RTC8M_CLK*/ 157 } ledc_timer_config_t; 158 159 #ifdef __cplusplus 160 } 161 #endif 162