ESP32_RTOS_SDK V1.1.0

- Main Page
- Modules
- Data Structures
- Files

- File List

pwm.h
1 /*
2 * ESPRSSIF MIT License
3 *
4 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5 *
6 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP32 only, in which case,
7 * it is free of charge, to any person obtaining a copy of this software and associated
8 * documentation files (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 * to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or
14 * substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25
26 #ifndef __PWM_H__
27 #define __PWM_H__
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 //#include "Ledc_reg.h"
34 //#include "ets_sys.h"
35 //#include "eagle_soc.h"
36
37
54 #define PWM_CHANNEL_NUM_MAX 8
55
56 #define TIMER0 0
57 #define TIMER1 1
58 #define TIMER2 2
59 #define TIMER3 3
60
61 #define CHANNEL0 0
62 #define CHANNEL1 1
63 #define CHANNEL2 2
64 #define CHANNEL3 3
65 #define CHANNEL4 4
66 #define CHANNEL5 5
67 #define CHANNEL6 6
68 #define CHANNEL7 7
69
70 #define OUTPUT_LOW 0
71 #define OUTPUT_HIGH 1
72
73 #define REF_TICK_CLK 0
74 #define APB_CLK 1
75
76 struct pwm_param {
77 uint32 period;
78 uint32 freq;
79 uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8
80 };
81
96 void pwm_init(uint32 period, uint32 *duty, uint32 pwm_channel_num, uint32(*pin_info_list)[3]);
97
112 void pwm_set_duty(uint32 duty, uint8 channel);
113
123 uint32 pwm_get_duty(uint8 channel);
124
136 void pwm_set_period(uint32 period);
137
145 uint32 pwm_get_period(void);
146
156 void pwm_start(void);
157
166 void ledc_set_base_hclk(uint8 timer_sel, uint8 apb_clk_sel);
167
176 void ledc_set_base_lclk(uint8 timer_sel, uint8 apb_clk_sel);
177
189 void ledc_set_hperiod(uint8 timer_sel, uint32 div_num, uint8 timer_lim);
190
202 void ledc_set_lperiod(uint8 timer_sel, uint32 div_num, uint8 timer_lim);
203
212 void ledc_set_ltimer(uint8 chan_num, uint8 timer_sel);
213
222 void ledc_set_htimer(uint8 chan_num, uint8 timer_sel);
223
232 void ledc_set_idle_hlevel(uint8 chan_num, uint8 idle_level);
233
242 void ledc_set_idle_llevel(uint8 chan_num, uint8 idle_level);
243
257 void ledc_set_hduty(uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale);
258
272 void ledc_set_lduty(uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale);
273
281 void ledc_hstart(uint8 chan_num);
282
290 void ledc_lstart(uint8 chan_num);
291
299 void ledc_timer_hpause(uint8 timer_sel);
300
308 void ledc_timer_lpause(uint8 timer_sel);
309
317 void ledc_timer_hunpause(uint8 timer_sel);
318
326 void ledc_timer_lunpause(uint8 timer_sel);
327
335 void ledc_timer_hstop(uint8 timer_sel);
336
344 void ledc_timer_lstop(uint8 timer_sel);
345
354 #ifdef __cplusplus
355 }
356
357 #endif
358
359 #endif
ledc_set_base_hclk
void ledc_set_base_hclk(uint8 timer_sel, uint8 apb_clk_sel)
Set high_speed channel base clock.
ledc_lstart
void ledc_lstart(uint8 chan_num)
Enable one low_speed channel.
pwm_start
void pwm_start(void)
Starts PWM.
pwm_get_period
uint32 pwm_get_period(void)
Get PWM period, unit : us.
ledc_set_hduty
void ledc_set_hduty(uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale)
Set high_speed channel duty.
ledc_timer_lpause
void ledc_timer_lpause(uint8 timer_sel)
Pause one of the timers for low_speed channel.
ledc_hstart
void ledc_hstart(uint8 chan_num)
Enable one high_speed channel.
ledc_timer_hunpause
void ledc_timer_hunpause(uint8 timer_sel)
Unpause one of the timers for high_speed channel.
ledc_set_idle_llevel
void ledc_set_idle_llevel(uint8 chan_num, uint8 idle_level)
Set low_speed channel output (as high or low) when idle.
pwm_init
void pwm_init(uint32 period, uint32 *duty, uint32 pwm_channel_num, uint32(*pin_info_list)[3])
PWM function initialization, including GPIO, frequency and duty cycle.
ledc_set_base_lclk
void ledc_set_base_lclk(uint8 timer_sel, uint8 apb_clk_sel)
Set low_speed channel base clock.
pwm_set_period
void pwm_set_period(uint32 period)
Set PWM period, unit : us.
ledc_set_hperiod
void ledc_set_hperiod(uint8 timer_sel, uint32 div_num, uint8 timer_lim)
Set high_speed channel frequency.
ledc_set_ltimer
void ledc_set_ltimer(uint8 chan_num, uint8 timer_sel)
Select one timer for one low_speed channel.
pwm_set_duty
void pwm_set_duty(uint32 duty, uint8 channel)
Set the duty cycle of a PWM channel.
ledc_set_idle_hlevel
void ledc_set_idle_hlevel(uint8 chan_num, uint8 idle_level)
Set high_speed channel output (as high or low) when idle.
ledc_timer_lstop
void ledc_timer_lstop(uint8 timer_sel)
Stop one of the timers for low_speed channel.
pwm_get_duty
uint32 pwm_get_duty(uint8 channel)
Get the duty cycle of a PWM channel.
ledc_set_htimer
void ledc_set_htimer(uint8 chan_num, uint8 timer_sel)
Select one timer for one high_speed channel.
ledc_timer_hpause
void ledc_timer_hpause(uint8 timer_sel)
Pause one of the timers for high_speed channel.
pwm_param
Definition: pwm.h:76
ledc_set_lperiod
void ledc_set_lperiod(uint8 timer_sel, uint32 div_num, uint8 timer_lim)
Set low_speed channel frequency.
ledc_timer_lunpause
void ledc_timer_lunpause(uint8 timer_sel)
Unpause one of the timers for low_speed channel.
ledc_timer_hstop
void ledc_timer_hstop(uint8 timer_sel)
Stop one of the timers for high_speed channel.
ledc_set_lduty
void ledc_set_lduty(uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale)
Set low_speed channel duty.