mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
sdm: added channel allocator for sigma delta module
This commit is contained in:
@@ -41,7 +41,7 @@ typedef bool (*gptimer_alarm_cb_t) (gptimer_handle_t timer, const gptimer_alarm_
|
||||
/**
|
||||
* @brief Group of supported GPTimer callbacks
|
||||
* @note The callbacks are all running under ISR environment
|
||||
* @note When CONFIG_GPTIMER_ISR_IRAM_SAFE is enabled, the callback itself and functions callbed by it should be placed in IRAM.
|
||||
* @note When CONFIG_GPTIMER_ISR_IRAM_SAFE is enabled, the callback itself and functions called by it should be placed in IRAM.
|
||||
*/
|
||||
typedef struct {
|
||||
gptimer_alarm_cb_t on_alarm; /*!< Timer alarm callback */
|
||||
|
111
components/driver/include/driver/sdm.h
Normal file
111
components/driver/include/driver/sdm.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal/sdm_types.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Type of Sigma Delta channel handle
|
||||
*/
|
||||
typedef struct sdm_channel_t *sdm_channel_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Sigma Delta channel configuration
|
||||
*/
|
||||
typedef struct {
|
||||
int gpio_num; /*!< GPIO number */
|
||||
sdm_clock_source_t clk_src; /*!< Clock source */
|
||||
uint32_t sample_rate_hz; /*!< Sample rate in Hz, it determines how frequent the modulator outputs a pulse */
|
||||
struct {
|
||||
uint32_t invert_out: 1; /*!< Whether to invert the output signal */
|
||||
uint32_t io_loop_back: 1; /*!< For debug/test, the signal output from the GPIO will be fed to the input path as well */
|
||||
} flags; /*!< Extra flags */
|
||||
} sdm_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create a new Sigma Delta channel
|
||||
*
|
||||
* @param[in] config SDM configuration
|
||||
* @param[out] ret_chan Returned SDM channel handle
|
||||
* @return
|
||||
* - ESP_OK: Create SDM channel successfully
|
||||
* - ESP_ERR_INVALID_ARG: Create SDM channel failed because of invalid argument
|
||||
* - ESP_ERR_NO_MEM: Create SDM channel failed because out of memory
|
||||
* - ESP_ERR_NOT_FOUND: Create SDM channel failed because all channels are used up and no more free one
|
||||
* - ESP_FAIL: Create SDM channel failed because of other error
|
||||
*/
|
||||
esp_err_t sdm_new_channel(const sdm_config_t *config, sdm_channel_handle_t *ret_chan);
|
||||
|
||||
/**
|
||||
* @brief Delete the Sigma Delta channel
|
||||
*
|
||||
* @param[in] chan SDM channel created by `sdm_new_channel`
|
||||
* @return
|
||||
* - ESP_OK: Delete the SDM channel successfully
|
||||
* - ESP_ERR_INVALID_ARG: Delete the SDM channel failed because of invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Delete the SDM channel failed because the channel is not in init state
|
||||
* - ESP_FAIL: Delete the SDM channel failed because of other error
|
||||
*/
|
||||
esp_err_t sdm_del_channel(sdm_channel_handle_t chan);
|
||||
|
||||
/**
|
||||
* @brief Enable the Sigma Delta channel
|
||||
*
|
||||
* @note This function will transit the channel state from init to enable.
|
||||
* @note This function will acquire a PM lock, if a specific source clock (e.g. APB) is selected in the `sdm_config_t`, while `CONFIG_PM_ENABLE` is enabled.
|
||||
*
|
||||
* @param[in] chan SDM channel created by `sdm_new_channel`
|
||||
* @return
|
||||
* - ESP_OK: Enable SDM channel successfully
|
||||
* - ESP_ERR_INVALID_ARG: Enable SDM channel failed because of invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Enable SDM channel failed because the channel is already enabled
|
||||
* - ESP_FAIL: Enable SDM channel failed because of other error
|
||||
*/
|
||||
esp_err_t sdm_channel_enable(sdm_channel_handle_t chan);
|
||||
|
||||
/**
|
||||
* @brief Disable the Sigma Delta channel
|
||||
*
|
||||
* @note This function will do the opposite work to the `sdm_channel_enable()`
|
||||
*
|
||||
* @param[in] chan SDM channel created by `sdm_new_channel`
|
||||
* @return
|
||||
* - ESP_OK: Disable SDM channel successfully
|
||||
* - ESP_ERR_INVALID_ARG: Disable SDM channel failed because of invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Disable SDM channel failed because the channel is not enabled yet
|
||||
* - ESP_FAIL: Disable SDM channel failed because of other error
|
||||
*/
|
||||
esp_err_t sdm_channel_disable(sdm_channel_handle_t chan);
|
||||
|
||||
/**
|
||||
* @brief Set the duty cycle of the PDM output signal.
|
||||
*
|
||||
* @note For PDM signals, duty cycle refers to the percentage of high level cycles to the whole statistical period.
|
||||
* The average output voltage could be Vout = VDD_IO / 256 * duty + VDD_IO / 2
|
||||
* @note If the duty is set to zero, the output signal is like a 50% duty cycle square wave, with a frequency around (sample_rate_hz / 4).
|
||||
* @note The duty is proportional to the equivalent output voltage after a low-pass-filter.
|
||||
* @note This function is allowed to run within ISR context
|
||||
* @note This function will be placed into IRAM if `CONFIG_SDM_CTRL_FUNC_IN_IRAM` is on, so that it's allowed to be executed when Cache is disabled
|
||||
*
|
||||
* @param[in] chan SDM channel created by `sdm_new_channel`
|
||||
* @param[in] duty Equivalent duty cycle of the PDM output signal, ranges from -128 to 127. But the range of [-90, 90] can provide a better randomness.
|
||||
* @return
|
||||
* - ESP_OK: Set duty cycle successfully
|
||||
* - ESP_ERR_INVALID_ARG: Set duty cycle failed because of invalid argument
|
||||
* - ESP_FAIL: Set duty cycle failed because of other error
|
||||
*/
|
||||
esp_err_t sdm_channel_set_duty(sdm_channel_handle_t chan, int8_t duty);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user