2021-05-23 19:50:04 -04:00
/*
2022-01-05 03:17:12 -05:00
* SPDX - FileCopyrightText : 2015 - 2022 Espressif Systems ( Shanghai ) CO LTD
2021-05-23 19:50:04 -04:00
*
* SPDX - License - Identifier : Apache - 2.0
*/
2016-09-22 21:21:37 -04:00
2019-08-09 08:30:19 -04:00
# pragma once
2016-09-22 21:21:37 -04:00
# include "esp_err.h"
2019-08-09 08:30:19 -04:00
# include "esp_intr_alloc.h"
# include "hal/ledc_types.h"
2016-09-22 21:21:37 -04:00
# include "driver/gpio.h"
# ifdef __cplusplus
extern " C " {
# endif
2021-06-02 08:19:09 -04:00
# define LEDC_APB_CLK_HZ (APB_CLK_FREQ)
# define LEDC_REF_CLK_HZ (REF_CLK_FREQ)
# define LEDC_ERR_DUTY (0xFFFFFFFF)
# define LEDC_ERR_VAL (-1)
/**
* @ brief Configuration parameters of LEDC channel for ledc_channel_config function
*/
typedef struct {
int gpio_num ; /*!< the LEDC output gpio_num, if you want to use gpio16, gpio_num = 16 */
ledc_mode_t speed_mode ; /*!< LEDC speed speed_mode, high-speed mode or low-speed mode */
ledc_channel_t channel ; /*!< LEDC channel (0 - 7) */
ledc_intr_type_t intr_type ; /*!< configure interrupt, Fade interrupt enable or Fade interrupt disable */
ledc_timer_t timer_sel ; /*!< Select the timer source of channel (0 - 3) */
uint32_t duty ; /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */
int hpoint ; /*!< LEDC channel hpoint value, the max value is 0xfffff */
struct {
unsigned int output_invert : 1 ; /*!< Enable (1) or disable (0) gpio output invert */
} flags ; /*!< LEDC flags */
} ledc_channel_config_t ;
/**
* @ brief Configuration parameters of LEDC Timer timer for ledc_timer_config function
*/
typedef struct {
ledc_mode_t speed_mode ; /*!< LEDC speed speed_mode, high-speed mode or low-speed mode */
union {
ledc_timer_bit_t duty_resolution ; /*!< LEDC channel duty resolution */
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 */
} ;
ledc_timer_t timer_num ; /*!< The timer source of channel (0 - 3) */
uint32_t freq_hz ; /*!< LEDC timer frequency (Hz) */
ledc_clk_cfg_t clk_cfg ; /*!< Configure LEDC source clock.
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 .
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 */
} ledc_timer_config_t ;
2016-09-28 11:20:34 -04:00
2016-12-07 08:30:21 -05:00
typedef intr_handle_t ledc_isr_handle_t ;
2016-09-28 11:20:34 -04:00
2021-07-08 05:47:05 -04:00
/**
* @ brief LEDC callback event type
*/
typedef enum {
LEDC_FADE_END_EVT /**< LEDC fade end event */
} ledc_cb_event_t ;
/**
* @ brief LEDC callback parameter
*/
typedef struct {
ledc_cb_event_t event ; /**< Event name */
uint32_t speed_mode ; /**< Speed mode of the LEDC channel group */
uint32_t channel ; /**< LEDC channel (0 - LEDC_CHANNEL_MAX-1) */
uint32_t duty ; /**< LEDC current duty of the channel, the range of duty is [0, (2**duty_resolution) - 1] */
} ledc_cb_param_t ;
/**
* @ brief Type of LEDC event callback
* @ param param LEDC callback parameter
* @ param user_arg User registered data
*/
typedef bool ( * ledc_cb_t ) ( const ledc_cb_param_t * param , void * user_arg ) ;
/**
* @ brief Group of supported LEDC callbacks
* @ note The callbacks are all running under ISR environment
*/
typedef struct {
ledc_cb_t fade_cb ; /**< LEDC fade_end callback function */
} ledc_cbs_t ;
2016-09-28 11:20:34 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC channel configuration
2017-10-22 23:32:47 -04:00
* Configure LEDC channel with the given channel / output gpio_num / interrupt / source timer / frequency ( Hz ) / LEDC duty resolution
2016-09-28 11:20:34 -04:00
*
2016-12-25 10:11:24 -05:00
* @ param ledc_conf Pointer of LEDC channel configure struct
2016-09-28 11:20:34 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2016-09-28 11:20:34 -04:00
*/
2017-04-13 13:33:33 -04:00
esp_err_t ledc_channel_config ( const ledc_channel_config_t * ledc_conf ) ;
2016-09-22 21:21:37 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC timer configuration
2017-10-22 23:32:47 -04:00
* Configure LEDC timer with the given source timer / frequency ( Hz ) / duty_resolution
2016-09-28 11:20:34 -04:00
*
2016-10-31 23:48:32 -04:00
* @ param timer_conf Pointer of LEDC timer configure struct
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2017-10-22 23:32:47 -04:00
* - ESP_FAIL Can not find a proper pre - divider number base on the given frequency and the current duty_resolution .
2016-09-22 21:21:37 -04:00
*/
2017-04-13 13:33:33 -04:00
esp_err_t ledc_timer_config ( const ledc_timer_config_t * timer_conf ) ;
2016-09-22 21:21:37 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC update channel parameters
2018-04-12 03:38:39 -04:00
* @ note Call this function to activate the LEDC updated parameters .
* After ledc_set_duty , we need to call this function to update the settings .
2021-07-28 07:46:33 -04:00
* And the new LEDC parameters don ' t take effect until the next PWM cycle .
2018-04-12 03:38:39 -04:00
* @ note ledc_set_duty , ledc_set_duty_with_hpoint and ledc_update_duty are not thread - safe , do not call these functions to
* control one LEDC channel in different tasks at the same time .
* A thread - safe version of API is ledc_set_duty_and_update
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2016-09-22 21:21:37 -04:00
*
*/
2016-09-28 11:20:34 -04:00
esp_err_t ledc_update_duty ( ledc_mode_t speed_mode , ledc_channel_t channel ) ;
2016-09-22 21:21:37 -04:00
2018-10-31 18:01:00 -04:00
/**
* @ brief Set LEDC output gpio .
2022-01-17 01:45:56 -05:00
*
* @ note This function only routes the LEDC signal to GPIO through matrix , other LEDC resources initialization are not involved .
* Please use ` ledc_channel_config ( ) ` instead to fully configure a LEDC channel .
2018-10-31 18:01:00 -04:00
*
* @ param gpio_num The LEDC output gpio
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param ledc_channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2018-10-31 18:01:00 -04:00
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
2022-01-17 01:45:56 -05:00
esp_err_t ledc_set_pin ( int gpio_num , ledc_mode_t speed_mode , ledc_channel_t ledc_channel ) ;
2016-09-22 21:21:37 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC stop .
* Disable LEDC output , and set idle level
2016-09-22 21:21:37 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2016-11-15 12:31:02 -05:00
* @ param idle_level Set output idle level after LEDC stops .
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2016-09-22 21:21:37 -04:00
*/
esp_err_t ledc_stop ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t idle_level ) ;
/**
2017-10-22 23:32:47 -04:00
* @ brief LEDC set channel frequency ( Hz )
2016-09-22 21:21:37 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_num LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-10-31 23:48:32 -04:00
* @ param freq_hz Set the LEDC frequency
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2017-10-22 23:32:47 -04:00
* - ESP_FAIL Can not find a proper pre - divider number base on the given frequency and the current duty_resolution .
2016-09-22 21:21:37 -04:00
*/
2016-09-25 21:56:03 -04:00
esp_err_t ledc_set_freq ( ledc_mode_t speed_mode , ledc_timer_t timer_num , uint32_t freq_hz ) ;
2016-09-22 21:21:37 -04:00
/**
2017-10-22 23:32:47 -04:00
* @ brief LEDC get channel frequency ( Hz )
2016-09-22 21:21:37 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_num LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - 0 error
* - Others Current LEDC frequency
2016-09-22 21:21:37 -04:00
*/
2016-09-25 21:56:03 -04:00
uint32_t ledc_get_freq ( ledc_mode_t speed_mode , ledc_timer_t timer_num ) ;
2016-09-22 21:21:37 -04:00
/**
2018-04-12 03:38:39 -04:00
* @ brief LEDC set duty and hpoint value
2016-12-25 10:11:24 -05:00
* Only after calling ledc_update_duty will the duty update .
2018-04-12 03:38:39 -04:00
* @ note ledc_set_duty , ledc_set_duty_with_hpoint and ledc_update_duty are not thread - safe , do not call these functions to
* control one LEDC channel in different tasks at the same time .
* A thread - safe version of API is ledc_set_duty_and_update
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param duty Set the LEDC duty , the range of duty setting is [ 0 , ( 2 * * duty_resolution ) - 1 ]
2018-04-12 03:38:39 -04:00
* @ param hpoint Set the LEDC hpoint value ( max : 0xfffff )
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t ledc_set_duty_with_hpoint ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t duty , uint32_t hpoint ) ;
/**
* @ brief LEDC get hpoint value , the counter value when the output is set high level .
2016-09-22 21:21:37 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2018-04-12 03:38:39 -04:00
* @ return
* - LEDC_ERR_VAL if parameter error
* - Others Current hpoint value of LEDC channel
*/
int ledc_get_hpoint ( ledc_mode_t speed_mode , ledc_channel_t channel ) ;
/**
* @ brief LEDC set duty
* This function do not change the hpoint value of this channel . if needed , please call ledc_set_duty_with_hpoint .
* only after calling ledc_update_duty will the duty update .
* @ note ledc_set_duty , ledc_set_duty_with_hpoint and ledc_update_duty are not thread - safe , do not call these functions to
* control one LEDC channel in different tasks at the same time .
* A thread - safe version of API is ledc_set_duty_and_update .
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param duty Set the LEDC duty , the range of duty setting is [ 0 , ( 2 * * duty_resolution ) - 1 ]
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2016-09-22 21:21:37 -04:00
*/
esp_err_t ledc_set_duty ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t duty ) ;
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC get duty
2021-07-28 07:46:33 -04:00
* This function returns the duty at the present PWM cycle .
* You shouldn ' t expect the function to return the new duty in the same cycle of calling ledc_update_duty ,
* because duty update doesn ' t take effect until the next cycle .
2016-09-22 21:21:37 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
2017-05-11 22:43:37 -04:00
* - LEDC_ERR_DUTY if parameter error
2016-10-31 23:48:32 -04:00
* - Others Current LEDC duty
2016-09-22 21:21:37 -04:00
*/
2017-05-11 22:43:37 -04:00
uint32_t ledc_get_duty ( ledc_mode_t speed_mode , ledc_channel_t channel ) ;
2016-09-22 21:21:37 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief LEDC set gradient
* Set LEDC gradient , After the function calls the ledc_update_duty function , the function can take effect .
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param duty Set the start of the gradient duty , the range of duty setting is [ 0 , ( 2 * * duty_resolution ) - 1 ]
2018-04-12 03:38:39 -04:00
* @ param fade_direction Set the direction of the gradient
* @ param step_num Set the number of the gradient
2019-08-09 08:30:19 -04:00
* @ param duty_cycle_num Set how many LEDC tick each time the gradient lasts
2018-04-12 03:38:39 -04:00
* @ param duty_scale Set gradient change amplitude
2016-09-22 21:21:37 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
2016-09-22 21:21:37 -04:00
*/
2018-04-12 03:38:39 -04:00
esp_err_t ledc_set_fade ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t duty , ledc_duty_direction_t fade_direction ,
2019-08-09 08:30:19 -04:00
uint32_t step_num , uint32_t duty_cycle_num , uint32_t duty_scale ) ;
2016-09-22 21:21:37 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Register LEDC interrupt handler , the handler is an ISR .
* The handler will be attached to the same CPU core that this function is running on .
2016-11-25 04:33:51 -05:00
*
2016-12-25 10:11:24 -05:00
* @ param fn Interrupt handler function .
* @ param arg User - supplied argument passed to the handler function .
* @ param intr_alloc_flags Flags used to allocate the interrupt . One or multiple ( ORred )
* ESP_INTR_FLAG_ * values . See esp_intr_alloc . h for more info .
* @ param handle Pointer to return handle . If non - NULL , a handle for the interrupt will
* be returned here .
2016-10-31 23:48:32 -04:00
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Function pointer error .
2016-09-22 21:21:37 -04:00
*/
2016-12-07 08:30:21 -05:00
esp_err_t ledc_isr_register ( void ( * fn ) ( void * ) , void * arg , int intr_alloc_flags , ledc_isr_handle_t * handle ) ;
2016-09-22 21:21:37 -04:00
2016-09-25 21:56:03 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Configure LEDC settings
2016-09-25 21:56:03 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_sel Timer index ( 0 - 3 ) , there are 4 timers in LEDC module
* @ param clock_divider Timer clock divide value , the timer clock is divided from the selected clock source
2018-04-12 03:38:39 -04:00
* @ param duty_resolution Resolution of duty setting in number of bits . The range of duty values is [ 0 , ( 2 * * duty_resolution ) ]
2016-12-25 10:11:24 -05:00
* @ param clk_src Select LEDC source clock .
2016-09-25 21:56:03 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ( - 1 ) Parameter error
* - Other Current LEDC duty
2016-09-25 21:56:03 -04:00
*/
2017-10-22 23:32:47 -04:00
esp_err_t ledc_timer_set ( ledc_mode_t speed_mode , ledc_timer_t timer_sel , uint32_t clock_divider , uint32_t duty_resolution , ledc_clk_src_t clk_src ) ;
2016-09-25 21:56:03 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Reset LEDC timer
2016-09-25 21:56:03 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_sel LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-09-25 21:56:03 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
2016-09-25 21:56:03 -04:00
*/
2019-08-09 08:30:19 -04:00
esp_err_t ledc_timer_rst ( ledc_mode_t speed_mode , ledc_timer_t timer_sel ) ;
2016-09-22 21:21:37 -04:00
2016-09-25 21:56:03 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Pause LEDC timer counter
2016-09-25 21:56:03 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_sel LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-09-25 21:56:03 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
2016-09-25 21:56:03 -04:00
*
*/
2019-08-09 08:30:19 -04:00
esp_err_t ledc_timer_pause ( ledc_mode_t speed_mode , ledc_timer_t timer_sel ) ;
2016-09-22 21:21:37 -04:00
2016-09-25 21:56:03 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Resume LEDC timer
2016-09-25 21:56:03 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2017-10-22 23:32:47 -04:00
* @ param timer_sel LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-09-25 21:56:03 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
2016-09-25 21:56:03 -04:00
*/
2019-08-09 08:30:19 -04:00
esp_err_t ledc_timer_resume ( ledc_mode_t speed_mode , ledc_timer_t timer_sel ) ;
2016-09-22 21:21:37 -04:00
2016-09-25 21:56:03 -04:00
/**
2016-12-25 10:11:24 -05:00
* @ brief Bind LEDC channel with the selected timer
2016-09-25 21:56:03 -04:00
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2019-08-09 08:30:19 -04:00
* @ param timer_sel LEDC timer index ( 0 - 3 ) , select from ledc_timer_t
2016-09-25 21:56:03 -04:00
*
2016-12-25 10:11:24 -05:00
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
*/
2019-08-09 08:30:19 -04:00
esp_err_t ledc_bind_channel_timer ( ledc_mode_t speed_mode , ledc_channel_t channel , ledc_timer_t timer_sel ) ;
2016-12-25 10:11:24 -05:00
/**
2018-04-12 03:38:39 -04:00
* @ brief Set LEDC fade function .
* @ note Call ledc_fade_func_install ( ) once before calling this function .
2016-12-25 10:11:24 -05:00
* Call ledc_fade_start ( ) after this to start fading .
2018-04-12 03:38:39 -04:00
* @ note ledc_set_fade_with_step , ledc_set_fade_with_time and ledc_fade_start are not thread - safe , do not call these functions to
* control one LEDC channel in different tasks at the same time .
* A thread - safe version of API is ledc_set_fade_step_and_start
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode . ,
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2017-10-22 23:32:47 -04:00
* @ param target_duty Target duty of fading [ 0 , ( 2 * * duty_resolution ) - 1 ]
2016-12-25 10:11:24 -05:00
* @ param scale Controls the increase or decrease step scale .
* @ param cycle_num increase or decrease the duty every cycle_num cycles
2016-09-25 21:56:03 -04:00
*
2016-10-31 23:48:32 -04:00
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
2016-12-25 10:11:24 -05:00
* - ESP_ERR_INVALID_STATE Fade function not installed .
2017-02-08 06:52:18 -05:00
* - ESP_FAIL Fade function init error
2016-09-25 21:56:03 -04:00
*/
2018-04-12 03:38:39 -04:00
esp_err_t ledc_set_fade_with_step ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t target_duty , uint32_t scale , uint32_t cycle_num ) ;
2016-12-25 10:11:24 -05:00
/**
2018-04-12 03:38:39 -04:00
* @ brief Set LEDC fade function , with a limited time .
* @ note Call ledc_fade_func_install ( ) once before calling this function .
2016-12-25 10:11:24 -05:00
* Call ledc_fade_start ( ) after this to start fading .
2018-04-12 03:38:39 -04:00
* @ note ledc_set_fade_with_step , ledc_set_fade_with_time and ledc_fade_start are not thread - safe , do not call these functions to
* control one LEDC channel in different tasks at the same time .
* A thread - safe version of API is ledc_set_fade_step_and_start
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode . ,
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param target_duty Target duty of fading [ 0 , ( 2 * * duty_resolution ) - 1 ]
2016-12-25 10:11:24 -05:00
* @ param max_fade_time_ms The maximum time of the fading ( ms ) .
*
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
2017-02-08 06:52:18 -05:00
* - ESP_FAIL Fade function init error
2016-09-22 21:21:37 -04:00
*/
2017-05-11 22:43:37 -04:00
esp_err_t ledc_set_fade_with_time ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t target_duty , int max_fade_time_ms ) ;
2016-09-22 21:21:37 -04:00
2016-12-25 10:11:24 -05:00
/**
2018-04-12 03:38:39 -04:00
* @ brief Install LEDC fade function . This function will occupy interrupt of LEDC module .
2016-12-25 10:11:24 -05:00
* @ param intr_alloc_flags Flags used to allocate the interrupt . One or multiple ( ORred )
* ESP_INTR_FLAG_ * values . See esp_intr_alloc . h for more info .
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function already installed .
*/
esp_err_t ledc_fade_func_install ( int intr_alloc_flags ) ;
2016-09-22 21:21:37 -04:00
2016-12-25 10:11:24 -05:00
/**
* @ brief Uninstall LEDC fade function .
*
*/
2019-07-16 05:33:30 -04:00
void ledc_fade_func_uninstall ( void ) ;
2016-09-22 21:21:37 -04:00
2016-12-25 10:11:24 -05:00
/**
* @ brief Start LEDC fading .
2018-04-12 03:38:39 -04:00
* @ note Call ledc_fade_func_install ( ) once before calling this function .
* Call this API right after ledc_set_fade_with_time or ledc_set_fade_with_step before to start fading .
2022-01-10 08:07:58 -05:00
* @ note Starting fade operation with this API is not thread - safe , use with care .
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2016-12-25 10:11:24 -05:00
* @ param channel LEDC channel number
2021-07-29 01:54:17 -04:00
* @ param fade_mode Whether to block until fading done . See ledc_types . h ledc_fade_mode_t for more info .
* Note that this function will not return until fading to the target duty if LEDC_FADE_WAIT_DONE mode is selected .
2016-12-25 10:11:24 -05:00
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
* - ESP_ERR_INVALID_ARG Parameter error .
*/
2018-04-12 03:38:39 -04:00
esp_err_t ledc_fade_start ( ledc_mode_t speed_mode , ledc_channel_t channel , ledc_fade_mode_t fade_mode ) ;
2022-01-10 08:07:58 -05:00
# if SOC_LEDC_SUPPORT_FADE_STOP
/**
* @ brief Stop LEDC fading . Duty of the channel will stay at its present vlaue .
* @ note This API can be called if a new fixed duty or a new fade want to be set while the last fade operation is still running in progress .
* @ note Call this API will abort the fading operation only if it was started by calling ledc_fade_start with LEDC_FADE_NO_WAIT mode .
* @ note If a fade was started with LEDC_FADE_WAIT_DONE mode , calling this API afterwards is no use in stopping the fade . Fade will continue until it reachs the target duty .
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
* @ param channel LEDC channel number
*
* @ return
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
* - ESP_ERR_INVALID_ARG Parameter error .
*/
esp_err_t ledc_fade_stop ( ledc_mode_t speed_mode , ledc_channel_t channel ) ;
# endif
2018-04-12 03:38:39 -04:00
/**
2018-07-09 13:25:31 -04:00
* @ brief A thread - safe API to set duty for LEDC channel and return when duty updated .
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
*
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param duty Set the LEDC duty , the range of duty setting is [ 0 , ( 2 * * duty_resolution ) - 1 ]
2018-04-12 03:38:39 -04:00
* @ param hpoint Set the LEDC hpoint value ( max : 0xfffff )
*
*/
esp_err_t ledc_set_duty_and_update ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t duty , uint32_t hpoint ) ;
2016-09-22 21:21:37 -04:00
2018-04-12 03:38:39 -04:00
/**
* @ brief A thread - safe API to set and start LEDC fade function , with a limited time .
* @ note Call ledc_fade_func_install ( ) once , before calling this function .
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param target_duty Target duty of fading [ 0 , ( 2 * * duty_resolution ) - 1 ]
2018-04-12 03:38:39 -04:00
* @ param max_fade_time_ms The maximum time of the fading ( ms ) .
* @ param fade_mode choose blocking or non - blocking mode
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
* - ESP_FAIL Fade function init error
*/
esp_err_t ledc_set_fade_time_and_start ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t target_duty , uint32_t max_fade_time_ms , ledc_fade_mode_t fade_mode ) ;
/**
* @ brief A thread - safe API to set and start LEDC fade function .
* @ note Call ledc_fade_func_install ( ) once before calling this function .
2022-01-10 08:07:58 -05:00
* @ note For ESP32 , hardware does not support any duty change while a fade operation is running in progress on that channel .
2018-04-12 03:38:39 -04:00
* Other duty operations will have to wait until the fade operation has finished .
2020-02-09 18:33:27 -05:00
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
2021-07-08 05:47:05 -04:00
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
2018-04-12 03:38:39 -04:00
* @ param target_duty Target duty of fading [ 0 , ( 2 * * duty_resolution ) - 1 ]
* @ param scale Controls the increase or decrease step scale .
* @ param cycle_num increase or decrease the duty every cycle_num cycles
* @ param fade_mode choose blocking or non - blocking mode
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
* - ESP_FAIL Fade function init error
*/
esp_err_t ledc_set_fade_step_and_start ( ledc_mode_t speed_mode , ledc_channel_t channel , uint32_t target_duty , uint32_t scale , uint32_t cycle_num , ledc_fade_mode_t fade_mode ) ;
2021-07-08 05:47:05 -04:00
/**
* @ brief LEDC callback registration function
* @ note The callback is called from an ISR , it must never attempt to block , and any FreeRTOS API called must be ISR capable .
* @ param speed_mode Select the LEDC channel group with specified speed mode . Note that not all targets support high speed mode .
* @ param channel LEDC channel index ( 0 - LEDC_CHANNEL_MAX - 1 ) , select from ledc_channel_t
* @ param cbs Group of LEDC callback functions
* @ param user_arg user registered data for the callback function
* @ return
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE Fade function not installed .
* - ESP_FAIL Fade function init error
*/
esp_err_t ledc_cb_register ( ledc_mode_t speed_mode , ledc_channel_t channel , ledc_cbs_t * cbs , void * user_arg ) ;
2021-12-23 18:05:43 -05:00
# ifdef __cplusplus
}
# endif