2018年12月21日 星期五

DIY - ESP32:ESP32 LEDC 控制 API 函數(五十六)

DIY - ESP32:ESP32 LEDC 控制 API 函數(五十六):

ESP32 在 IDF 內已經有 LEDC(LED 控制)API 函數模塊,主要用於設定和控制 LEDC 輸出。

ESP32 LEDC(LED 控制)
功能 - ledc_channel_config
原型:esp_err_t ledc_channel_config(const ledc_channel_config_t *ledc_conf)
參數:ledc_conf: Pointer of LEDC channel configure struct
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:LEDC channel configuration Configure LEDC channel with the given channel/output gpio_num/interrupt/source timer/frequency(Hz)/LEDC duty resolution.
範例:

功能 - ledc_timer_config
原型:esp_err_t ledc_timer_config(const ledc_timer_config_t *timer_conf)
參數:timer_conf: Pointer of LEDC timer configure struct
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
            ESP_FAIL Can not find a proper pre-divider number base on the given frequency and the current duty_resolution.
說明:LEDC timer configuration Configure LEDC timer with the given source timer/frequency(Hz)/duty_resolution.
範例:

功能 - ledc_update_duty
原型:esp_err_t ledc_update_duty(ledc_mode_t speed_mode, ledc_channel_t channel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode,
            channel: LEDC channel (0-7), select from ledc_channel_t
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:LEDC update channel parameters.
Note Call this function to activate the LEDC updated parameters. After ledc_set_duty, we need to call this function to update the settings.
Noteledc_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
範例:

功能 - ledc_stop
原型:esp_err_t ledc_stop(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t idle_level
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
            idle_level: Set output idle level after LEDC stops.
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:LEDC stop. Disable LEDC output, and set idle level.
範例:

功能 - ledc_set_freq
原型:esp_err_t ledc_set_freq(ledc_mode_t speed_mode, ledc_timer_t timer_num, uint32_t freq_hz)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_num: LEDC timer index (0-3), select from ledc_timer_t
            freq_hz: Set the LEDC frequency
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
            ESP_FAIL Can not find a proper pre-divider number base on the given frequency and the current duty_resolution.
說明:LEDC set channel frequency (Hz)
範例:

功能 - ledc_get_freq
原型:uint32_t ledc_get_freq(ledc_mode_t speed_mode, ledc_timer_t timer_num)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_num: LEDC timer index (0-3), select from ledc_timer_t
返回:0 error
            Others Current LEDC frequency
說明:LEDC get channel frequency (Hz)
範例:

功能 - ledc_set_duty_with_hpoint
原型:esp_err_t ledc_set_duty_with_hpoint(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t duty, uint32_t hpoint)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
            duty: Set the LEDC duty, the range of duty setting is [0, (2**duty_resolution)]
            hpoint: Set the LEDC hpoint value(max: 0xfffff)
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:LEDC set duty and hpoint value Only after calling ledc_update_duty will the duty update.
Noteledc_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
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_get_hpoint
原型:int ledc_get_hpoint(ledc_mode_t speed_mode, ledc_channel_t channel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
返回:LEDC_ERR_VAL if parameter error
            Others Current hpoint value of LEDC channel
說明:LEDC get hpoint value, the counter value when the output is set high level.
範例:

功能 - ledc_set_duty
原型:esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t duty)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
            duty: Set the LEDC duty, the range of duty setting is [0, (2**duty_resolution)]
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明: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.
Noteledc_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.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_get_duty
原型:uint32_t ledc_get_duty(ledc_mode_t speed_mode, ledc_channel_t channel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
返回:LEDC_ERR_DUTY if parameter error
            Others Current LEDC duty
說明:LEDC get duty.
範例:

功能 - ledc_set_fade
原型:esp_err_t ledc_set_fade(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t duty, ledc_duty_direction_t fade_direction, uint32_t step_num, uint32_t duty_cyle_num, uint32_t duty_scale)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
            duty: Set the start of the gradient duty, the range of duty setting is [0, (2**duty_resolution)]
            fade_direction: Set the direction of the gradient
            step_num: Set the number of the gradient
            duty_cyle_num: Set how many LEDC tick each time the gradient lasts
            duty_scale: Set gradient change amplitude
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:LEDC set gradient Set LEDC gradient, After the function calls the ledc_update_duty function, the function can take effect.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_isr_register
原型:esp_err_t ledc_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, ledc_isr_handle_t *handle, )
參數:fn: Interrupt handler function.
            arg: User-supplied argument passed to the handler function.
            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.
            arg: Parameter for handler function
            handle: Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Function pointer error.
說明: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.
範例:

功能 - ledc_timer_set
原型: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)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_sel: Timer index (0-3), there are 4 timers in LEDC module
            clock_divider: Timer clock divide value, the timer clock is divided from the selected clock source
            duty_resolution: Resolution of duty setting in number of bits. The range of duty values is [0, (2**duty_resolution)]
            clk_src: Select LEDC source clock.
返回: (-1) Parameter error
            Other Current LEDC duty
說明:Configure LEDC settings.
範例:

功能 - ledc_timer_rst
原型:esp_err_t ledc_timer_rst(ledc_mode_t speed_mode, uint32_t timer_sel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_sel: LEDC timer index (0-3), select from ledc_timer_t
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Reset LEDC timer.
範例:

功能 - ledc_timer_pause
原型:esp_err_t ledc_timer_pause(ledc_mode_t speed_mode, uint32_t timer_sel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_sel: LEDC timer index (0-3), select from ledc_timer_t
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Pause LEDC timer counter.
範例:

功能 - ledc_timer_resume
原型:esp_err_t ledc_timer_resume(ledc_mode_t speed_mode, uint32_t timer_sel)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            timer_sel: LEDC timer index (0-3), select from ledc_timer_t
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Resume LEDC timer.
範例:

功能 - ledc_bind_channel_timer
原型:esp_err_t ledc_bind_channel_timer(ledc_mode_t speed_mode, uint32_t channel, uint32_t timer_idx)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel index (0-7), select from ledc_channel_t
            timer_idx: LEDC timer index (0-3), select from ledc_timer_t
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Bind LEDC channel with the selected timer.
範例:

功能 - ledc_set_fade_with_step
原型: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)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode,
            channel: LEDC channel index (0-7), select from ledc_channel_t
            target_duty: Target duty of fading [0, (2**duty_resolution) - 1]
            scale: Controls the increase or decrease step scale.
            cycle_num: increase or decrease the duty every cycle_num cycles
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function not installed.
            ESP_FAIL Fade function init error
說明:Set LEDC fade function.

NoteCall ledc_fade_func_install() once before calling this function. Call ledc_fade_start() after this to start fading.
Noteledc_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
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_set_fade_with_time
原型: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)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode,
            channel: LEDC channel index (0-7), select from ledc_channel_t
            target_duty: Target duty of fading.( 0 - (2 ** duty_resolution - 1)))
            max_fade_time_ms: The maximum time of the fading ( ms ).
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function not installed.
            ESP_FAIL Fade function init error      
說明:Set LEDC fade function, with a limited time.
NoteCall ledc_fade_func_install() once before calling this function. Call ledc_fade_start() after this to start fading.
Noteledc_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
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_fade_func_install
原型:esp_err_t ledc_fade_func_install(int intr_alloc_flags)
參數: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.
返回:ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function already installed.
說明:Install LEDC fade function. This function will occupy interrupt of LEDC module.
範例:

功能 - ledc_fade_func_uninstall
原型:void ledc_fade_func_uninstall()
參數:
返回:
說明:Uninstall LEDC fade function.
範例:

功能 - ledc_fade_start
原型:esp_err_t ledc_fade_start(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_fade_mode_t fade_mode)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel number
            fade_mode: Whether to block until fading done.
返回:ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function not installed.
            ESP_ERR_INVALID_ARG Parameter error.
說明:Start LEDC fading.
NoteCall 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.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_set_duty_and_update
原型:esp_err_t ledc_set_duty_and_update(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t duty, uint32_t hpoint)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode
            channel: LEDC channel (0-7), select from ledc_channel_t
            duty: Set the LEDC duty, the range of duty setting is [0, (2**duty_resolution)]
            hpoint: Set the LEDC hpoint value(max: 0xfffff)
返回:
說明:A thread-safe API to set duty for LEDC channel and return when duty updated.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_set_fade_time_and_start
原型: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)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode,
            channel: LEDC channel index (0-7), select from ledc_channel_t
            target_duty: Target duty of fading.( 0 - (2 ** duty_resolution - 1)))
            max_fade_time_ms: The maximum time of the fading ( ms ).
            fade_mode: choose blocking or non-blocking mode
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function not installed.
            ESP_FAIL Fade function init error
說明:A thread-safe API to set and start LEDC fade function, with a limited time.
NoteCall ledc_fade_func_install() once, before calling this function.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

功能 - ledc_set_fade_step_and_start
原型: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)
參數:speed_mode: Select the LEDC speed_mode, high-speed mode and low-speed mode,
            channel: LEDC channel index (0-7), select from ledc_channel_t
            target_duty: Target duty of fading [0, (2**duty_resolution) - 1]
            scale: Controls the increase or decrease step scale.
            cycle_num: increase or decrease the duty every cycle_num cycles
            fade_mode: choose blocking or non-blocking mode
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
            ESP_ERR_INVALID_STATE Fade function not installed.
            ESP_FAIL Fade function init error
說明:A thread-safe API to set and start LEDC fade function.
NoteCall ledc_fade_func_install() once before calling this function.
NoteIf a fade operation is running in progress on that channel, the driver would not allow it to be stopped. Other duty operations will have to wait until the fade operation has finished.
範例:

相關網址:
※ DIY - ESP32:ESP32 LEDC 控制模塊介紹(五十三)
※ DIY - ESP32:ESP32 頻率產生器 Frequency Generator 電路(五十四)
※ DIY - ESP32:ESP32 頻率產生器 Frequency Generator 程式(五十五)
※ DIY - ESP32:ESP32 LEDC 控制 API 函數結構件及其它(五十七)

2018年 12月 21日 天氣報告
氣溫:22.9@ 20:10
相對濕度:百分之 75%
天氣:大致多雲

沒有留言:

張貼留言