mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
dac: update API and file format aligning to the rule
This commit is contained in:
@@ -110,7 +110,7 @@ endif()
|
||||
if(CONFIG_SOC_DAC_SUPPORTED)
|
||||
list(APPEND srcs "dac/dac_oneshot.c"
|
||||
"dac/dac_cosine.c"
|
||||
"dac/dac_conti.c"
|
||||
"dac/dac_continuous.c"
|
||||
"dac/dac_common.c"
|
||||
"dac/${target}/dac_dma.c"
|
||||
"deprecated/dac_common_legacy.c"
|
||||
|
@@ -14,18 +14,17 @@
|
||||
|
||||
#include "rom/lldesc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
|
||||
#include "dac_priv_common.h"
|
||||
#include "dac_priv_dma.h"
|
||||
|
||||
#include "esp_check.h"
|
||||
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
// The local log level must be defined before including esp_log.h
|
||||
// Set the maximum log level for this source file
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#endif
|
||||
#include "esp_check.h"
|
||||
#if CONFIG_PM_ENABLE
|
||||
#include "esp_pm.h"
|
||||
#endif
|
||||
@@ -59,9 +58,9 @@
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
struct dac_conti_s {
|
||||
struct dac_continuous_s {
|
||||
uint32_t chan_cnt;
|
||||
dac_conti_config_t cfg;
|
||||
dac_continuous_config_t cfg;
|
||||
atomic_bool is_enabled;
|
||||
atomic_bool is_cyclic;
|
||||
atomic_bool is_running;
|
||||
@@ -86,7 +85,7 @@ struct dac_conti_s {
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
static const char *TAG = "dac_conti";
|
||||
static const char *TAG = "dac_continuous";
|
||||
|
||||
static bool s_dma_in_use = false;
|
||||
static portMUX_TYPE desc_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
@@ -97,7 +96,7 @@ static portMUX_TYPE desc_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
#define DESC_ENTER_CRITICAL_ISR() portENTER_CRITICAL_ISR(&desc_spinlock)
|
||||
#define DESC_EXIT_CRITICAL_ISR() portEXIT_CRITICAL_ISR(&desc_spinlock)
|
||||
|
||||
static void s_dac_free_dma_desc(dac_conti_handle_t handle)
|
||||
static void s_dac_free_dma_desc(dac_continuous_handle_t handle)
|
||||
{
|
||||
STAILQ_INIT(&handle->head);
|
||||
if (handle->desc != NULL) {
|
||||
@@ -120,7 +119,7 @@ static void s_dac_free_dma_desc(dac_conti_handle_t handle)
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t s_dac_alloc_dma_desc(dac_conti_handle_t handle)
|
||||
static esp_err_t s_dac_alloc_dma_desc(dac_continuous_handle_t handle)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
@@ -155,7 +154,7 @@ err:
|
||||
|
||||
static void IRAM_ATTR s_dac_default_intr_handler(void *arg)
|
||||
{
|
||||
dac_conti_handle_t handle = (dac_conti_handle_t)arg;
|
||||
dac_continuous_handle_t handle = (dac_continuous_handle_t)arg;
|
||||
uint32_t dummy;
|
||||
BaseType_t need_awoke = pdFALSE;
|
||||
BaseType_t tmp = pdFALSE;
|
||||
@@ -199,22 +198,22 @@ static void IRAM_ATTR s_dac_default_intr_handler(void *arg)
|
||||
}
|
||||
|
||||
|
||||
esp_err_t dac_new_conti_channels(const dac_conti_config_t *conti_cfg, dac_conti_handle_t *ret_handle)
|
||||
esp_err_t dac_continuous_new_channels(const dac_continuous_config_t *cont_cfg, dac_continuous_handle_t *ret_handle)
|
||||
{
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
/* Parameters validation */
|
||||
DAC_NULL_POINTER_CHECK(conti_cfg);
|
||||
DAC_NULL_POINTER_CHECK(cont_cfg);
|
||||
DAC_NULL_POINTER_CHECK(ret_handle);
|
||||
ESP_RETURN_ON_FALSE(conti_cfg->chan_mask <= DAC_CHANNEL_MASK_ALL, ESP_ERR_INVALID_ARG, TAG, "invalid dac channel id");
|
||||
ESP_RETURN_ON_FALSE(conti_cfg->desc_num > 1, ESP_ERR_INVALID_STATE, TAG, "at least two DMA descriptor needed");
|
||||
ESP_RETURN_ON_FALSE(cont_cfg->chan_mask <= DAC_CHANNEL_MASK_ALL, ESP_ERR_INVALID_ARG, TAG, "invalid dac channel id");
|
||||
ESP_RETURN_ON_FALSE(cont_cfg->desc_num > 1, ESP_ERR_INVALID_STATE, TAG, "at least two DMA descriptor needed");
|
||||
ESP_RETURN_ON_FALSE(!s_dma_in_use, ESP_ERR_INVALID_STATE, TAG, "DMA already in use");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
/* Register the channels */
|
||||
for (uint32_t i = 0, mask = conti_cfg->chan_mask; mask; mask >>= 1, i++) {
|
||||
for (uint32_t i = 0, mask = cont_cfg->chan_mask; mask; mask >>= 1, i++) {
|
||||
if (mask & 0x01) {
|
||||
ESP_GOTO_ON_ERROR(dac_priv_register_channel(i, "dac continuous"),
|
||||
err4, TAG, "register dac channel %"PRIu32" failed", i);
|
||||
@@ -222,13 +221,13 @@ esp_err_t dac_new_conti_channels(const dac_conti_config_t *conti_cfg, dac_conti_
|
||||
}
|
||||
|
||||
/* Allocate continuous mode struct */
|
||||
dac_conti_handle_t handle = heap_caps_calloc(1, sizeof(struct dac_conti_s), DAC_MEM_ALLOC_CAPS);
|
||||
dac_continuous_handle_t handle = heap_caps_calloc(1, sizeof(struct dac_continuous_s), DAC_MEM_ALLOC_CAPS);
|
||||
ESP_RETURN_ON_FALSE(handle, ESP_ERR_NO_MEM, TAG, "no memory for the dac continuous mode structure");
|
||||
|
||||
/* Allocate static queue */
|
||||
handle->desc_pool_storage = (uint8_t *)heap_caps_calloc(conti_cfg->desc_num, sizeof(lldesc_t *), DAC_MEM_ALLOC_CAPS);
|
||||
handle->desc_pool_storage = (uint8_t *)heap_caps_calloc(cont_cfg->desc_num, sizeof(lldesc_t *), DAC_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(handle->desc_pool_storage, ESP_ERR_NO_MEM, err3, TAG, "no memory for message queue storage");
|
||||
handle->desc_pool = xQueueCreateStatic(conti_cfg->desc_num, sizeof(lldesc_t *), handle->desc_pool_storage, &handle->desc_pool_struct);
|
||||
handle->desc_pool = xQueueCreateStatic(cont_cfg->desc_num, sizeof(lldesc_t *), handle->desc_pool_storage, &handle->desc_pool_struct);
|
||||
ESP_GOTO_ON_FALSE(handle->desc_pool, ESP_ERR_NO_MEM, err3, TAG, "no memory for message queue");
|
||||
|
||||
/* Allocate static mutex */
|
||||
@@ -237,11 +236,11 @@ esp_err_t dac_new_conti_channels(const dac_conti_config_t *conti_cfg, dac_conti_
|
||||
|
||||
/* Create PM lock */
|
||||
#if CONFIG_PM_ENABLE
|
||||
esp_pm_lock_type_t pm_lock_type = conti_cfg->clk_src == DAC_DIGI_CLK_SRC_APLL ? ESP_PM_NO_LIGHT_SLEEP : ESP_PM_APB_FREQ_MAX;
|
||||
esp_pm_lock_type_t pm_lock_type = cont_cfg->clk_src == DAC_DIGI_CLK_SRC_APLL ? ESP_PM_NO_LIGHT_SLEEP : ESP_PM_APB_FREQ_MAX;
|
||||
ESP_GOTO_ON_ERROR(esp_pm_lock_create(pm_lock_type, 0, "dac_driver", &handle->pm_lock), err3, TAG, "Failed to create DAC pm lock");
|
||||
#endif
|
||||
handle->chan_cnt = __builtin_popcount(conti_cfg->chan_mask);
|
||||
memcpy(&(handle->cfg), conti_cfg, sizeof(dac_conti_config_t));
|
||||
handle->chan_cnt = __builtin_popcount(cont_cfg->chan_mask);
|
||||
memcpy(&(handle->cfg), cont_cfg, sizeof(dac_continuous_config_t));
|
||||
|
||||
atomic_init(&handle->is_enabled, false);
|
||||
atomic_init(&handle->is_cyclic, false);
|
||||
@@ -252,9 +251,9 @@ esp_err_t dac_new_conti_channels(const dac_conti_config_t *conti_cfg, dac_conti_
|
||||
ESP_GOTO_ON_ERROR(s_dac_alloc_dma_desc(handle), err2, TAG, "Failed to allocate memory for DMA buffers");
|
||||
|
||||
/* Initialize DAC DMA peripheral */
|
||||
ESP_GOTO_ON_ERROR(dac_dma_periph_init(conti_cfg->freq_hz,
|
||||
conti_cfg->chan_mode == DAC_CHANNEL_MODE_ALTER,
|
||||
conti_cfg->clk_src == DAC_DIGI_CLK_SRC_APLL),
|
||||
ESP_GOTO_ON_ERROR(dac_dma_periph_init(cont_cfg->freq_hz,
|
||||
cont_cfg->chan_mode == DAC_CHANNEL_MODE_ALTER,
|
||||
cont_cfg->clk_src == DAC_DIGI_CLK_SRC_APLL),
|
||||
err2, TAG, "Failed to initialize DAC DMA peripheral");
|
||||
/* Register DMA interrupt */
|
||||
ESP_GOTO_ON_ERROR(esp_intr_alloc(dac_dma_periph_get_intr_signal(), DAC_INTR_ALLOC_FLAGS,
|
||||
@@ -285,7 +284,7 @@ err3:
|
||||
free(handle);
|
||||
err4:
|
||||
/* Deregister the channels */
|
||||
for (uint32_t i = 0, mask = conti_cfg->chan_mask; mask; mask >>= 1, i++) {
|
||||
for (uint32_t i = 0, mask = cont_cfg->chan_mask; mask; mask >>= 1, i++) {
|
||||
if (mask & 0x01) {
|
||||
dac_priv_deregister_channel(i);
|
||||
}
|
||||
@@ -293,7 +292,7 @@ err4:
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t dac_del_conti_channels(dac_conti_handle_t handle)
|
||||
esp_err_t dac_continuous_del_channels(dac_continuous_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(!atomic_load(&handle->is_enabled), ESP_ERR_INVALID_STATE, TAG, "dac continuous output not disabled yet");
|
||||
@@ -343,7 +342,7 @@ esp_err_t dac_del_conti_channels(dac_conti_handle_t handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_register_event_callback(dac_conti_handle_t handle, const dac_event_callbacks_t *callbacks, void *user_data)
|
||||
esp_err_t dac_continuous_register_event_callback(dac_continuous_handle_t handle, const dac_event_callbacks_t *callbacks, void *user_data)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
if (!callbacks) {
|
||||
@@ -367,7 +366,7 @@ esp_err_t dac_conti_register_event_callback(dac_conti_handle_t handle, const dac
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_enable(dac_conti_handle_t handle)
|
||||
esp_err_t dac_continuous_enable(dac_continuous_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(!atomic_load(&handle->is_enabled), ESP_ERR_INVALID_STATE, TAG, "dac continuous has already enabled");
|
||||
@@ -396,7 +395,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_disable(dac_conti_handle_t handle)
|
||||
esp_err_t dac_continuous_disable(dac_continuous_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&handle->is_enabled), ESP_ERR_INVALID_STATE, TAG, "dac continuous has already disabled");
|
||||
@@ -418,7 +417,7 @@ esp_err_t dac_conti_disable(dac_conti_handle_t handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_start_async_writing(dac_conti_handle_t handle)
|
||||
esp_err_t dac_continuous_start_async_writing(dac_continuous_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&handle->is_enabled), ESP_ERR_INVALID_STATE, TAG, "dac continuous has not been enabled");
|
||||
@@ -447,7 +446,7 @@ esp_err_t dac_conti_start_async_writing(dac_conti_handle_t handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_stop_async_writing(dac_conti_handle_t handle)
|
||||
esp_err_t dac_continuous_stop_async_writing(dac_continuous_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&handle->is_async), ESP_ERR_INVALID_STATE, TAG, "dac asynchronous writing has not been started");
|
||||
@@ -470,7 +469,7 @@ esp_err_t dac_conti_stop_async_writing(dac_conti_handle_t handle)
|
||||
#define DAC_16BIT_ALIGN_COEFF 1
|
||||
#endif
|
||||
|
||||
static size_t s_dac_load_data_into_buf(dac_conti_handle_t handle, uint8_t *dest, size_t dest_len, const uint8_t *src, size_t src_len)
|
||||
static size_t s_dac_load_data_into_buf(dac_continuous_handle_t handle, uint8_t *dest, size_t dest_len, const uint8_t *src, size_t src_len)
|
||||
{
|
||||
size_t load_bytes = 0;
|
||||
#if CONFIG_DAC_DMA_AUTO_16BIT_ALIGN
|
||||
@@ -489,7 +488,7 @@ static size_t s_dac_load_data_into_buf(dac_conti_handle_t handle, uint8_t *dest,
|
||||
return load_bytes;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_write_asynchronously(dac_conti_handle_t handle, uint8_t *dma_buf,
|
||||
esp_err_t dac_continuous_write_asynchronously(dac_continuous_handle_t handle, uint8_t *dma_buf,
|
||||
size_t dma_buf_len, const uint8_t *data,
|
||||
size_t data_len, size_t *bytes_loaded)
|
||||
{
|
||||
@@ -513,7 +512,7 @@ esp_err_t dac_conti_write_asynchronously(dac_conti_handle_t handle, uint8_t *dma
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_write_cyclically(dac_conti_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded)
|
||||
esp_err_t dac_continuous_write_cyclically(dac_continuous_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&handle->is_enabled), ESP_ERR_INVALID_STATE, TAG, "This set of DAC channels has not been enabled");
|
||||
@@ -560,7 +559,7 @@ esp_err_t dac_conti_write_cyclically(dac_conti_handle_t handle, uint8_t *buf, si
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t s_dac_wait_to_load_dma_data(dac_conti_handle_t handle, uint8_t *buf, size_t buf_size, size_t *w_size, TickType_t timeout_tick)
|
||||
static esp_err_t s_dac_wait_to_load_dma_data(dac_continuous_handle_t handle, uint8_t *buf, size_t buf_size, size_t *w_size, TickType_t timeout_tick)
|
||||
{
|
||||
lldesc_t *desc;
|
||||
/* Try to get the descriptor from the pool */
|
||||
@@ -593,7 +592,7 @@ static esp_err_t s_dac_wait_to_load_dma_data(dac_conti_handle_t handle, uint8_t
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t dac_conti_write(dac_conti_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded, int timeout_ms)
|
||||
esp_err_t dac_continuous_write(dac_continuous_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded, int timeout_ms)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
DAC_NULL_POINTER_CHECK(buf);
|
@@ -10,13 +10,13 @@
|
||||
#include "hal/clk_tree_ll.h"
|
||||
#include "dac_priv_common.h"
|
||||
#include "clk_ctrl_os.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
// The local log level must be defined before including esp_log.h
|
||||
// Set the maximum log level for this source file
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#endif
|
||||
#include "esp_check.h"
|
||||
#if CONFIG_PM_ENABLE
|
||||
#include "esp_pm.h"
|
||||
#endif
|
||||
@@ -35,7 +35,7 @@ static uint32_t s_cwg_refer_cnt = 0;
|
||||
/* The frequency of cosine wave generator */
|
||||
static uint32_t s_cwg_freq = 0;
|
||||
|
||||
esp_err_t dac_new_cosine_channel(const dac_cosine_config_t *cos_cfg, dac_cosine_handle_t *ret_handle)
|
||||
esp_err_t dac_cosine_new_channel(const dac_cosine_config_t *cos_cfg, dac_cosine_handle_t *ret_handle)
|
||||
{
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
@@ -87,7 +87,7 @@ err1:
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t dac_del_cosine_channel(dac_cosine_handle_t handle)
|
||||
esp_err_t dac_cosine_del_channel(dac_cosine_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
ESP_RETURN_ON_FALSE(!handle->is_started, ESP_ERR_INVALID_STATE, TAG,
|
||||
|
@@ -8,13 +8,13 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#include "dac_priv_common.h"
|
||||
#include "driver/dac_oneshot.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
// The local log level must be defined before including esp_log.h
|
||||
// Set the maximum log level for this source file
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#endif
|
||||
#include "esp_check.h"
|
||||
#if CONFIG_PM_ENABLE
|
||||
#include "esp_pm.h"
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
static const char *TAG = "dac_oneshot";
|
||||
|
||||
esp_err_t dac_new_oneshot_channel(const dac_oneshot_config_t *oneshot_cfg, dac_oneshot_handle_t *ret_handle)
|
||||
esp_err_t dac_oneshot_new_channel(const dac_oneshot_config_t *oneshot_cfg, dac_oneshot_handle_t *ret_handle)
|
||||
{
|
||||
#if CONFIG_DAC_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
@@ -55,7 +55,7 @@ err2:
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t dac_del_oneshot_channel(dac_oneshot_handle_t handle)
|
||||
esp_err_t dac_oneshot_del_channel(dac_oneshot_handle_t handle)
|
||||
{
|
||||
DAC_NULL_POINTER_CHECK(handle);
|
||||
|
||||
|
@@ -142,5 +142,5 @@ static void check_dac_legacy_driver_conflict(void)
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The new DAC driver is not allowed to be used together with the legacy driver");
|
||||
abort();
|
||||
}
|
||||
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/dac_oneshot.h`, `driver/dac_cosine.h` or `driver/dac_conti.h` instead");
|
||||
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/dac_oneshot.h`, `driver/dac_cosine.h` or `driver/dac_continuous.h` instead");
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@
|
||||
#include "driver/dac_types_legacy.h"
|
||||
|
||||
#if !CONFIG_DAC_SUPPRESS_DEPRECATE_WARN
|
||||
#warning "The legacy DAC driver is deprecated, please use `driver/dac_oneshot.h`, `driver/dac_cosine.h` or `driver/dac_conti.h` instead"
|
||||
#warning "The legacy DAC driver is deprecated, please use `driver/dac_oneshot.h`, `driver/dac_cosine.h` or `driver/dac_continuous.h` instead"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -25,7 +25,7 @@ typedef enum {
|
||||
DAC_CHANNEL_MASK_ALL = BIT(0) | BIT(1), /*!< Both DAC channel 0 and channel 1 */
|
||||
} dac_channel_mask_t;
|
||||
|
||||
typedef struct dac_conti_s *dac_conti_handle_t; /*!< DAC continuous channel handle */
|
||||
typedef struct dac_continuous_s *dac_continuous_handle_t; /*!< DAC continuous channel handle */
|
||||
|
||||
/**
|
||||
* @brief DAC continuous channels' configurations
|
||||
@@ -53,11 +53,11 @@ typedef struct {
|
||||
* Typically not suggest to set the frequency higher than 2 MHz, otherwise the severe distortion will appear
|
||||
*/
|
||||
int8_t offset; /*!< The offset of the DAC digital data. Range -128~127 */
|
||||
dac_conti_digi_clk_src_t clk_src; /*!< The clock source of digital controller, which can affect the range of supported frequency
|
||||
dac_continuous_digi_clk_src_t clk_src; /*!< The clock source of digital controller, which can affect the range of supported frequency
|
||||
* Currently `DAC_DIGI_CLK_SRC_DEFAULT` and `DAC_DIGI_CLK_SRC_APLL` are available
|
||||
*/
|
||||
dac_conti_channel_mode_t chan_mode; /*!< The channel mode of continuous mode, only take effect when multiple channels enabled, depends converting the buffer alternately or simultaneously */
|
||||
} dac_conti_config_t;
|
||||
dac_continuous_channel_mode_t chan_mode; /*!< The channel mode of continuous mode, only take effect when multiple channels enabled, depends converting the buffer alternately or simultaneously */
|
||||
} dac_continuous_config_t;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,19 +65,19 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
void *buf; /*!< The pointer of DMA buffer that just finished sending */
|
||||
size_t buf_size; /*!< The writable buffer size of the DMA buffer, equal to 'dac_conti_config_t::buf_size' */
|
||||
size_t buf_size; /*!< The writable buffer size of the DMA buffer, equal to 'dac_continuous_config_t::buf_size' */
|
||||
size_t write_bytes; /*!< The number of bytes that be written successfully */
|
||||
} dac_event_data_t;
|
||||
|
||||
/**
|
||||
* @brief DAC event callback
|
||||
* @param[in] handle DAC channel handle, created from `dac_new_conti_channels()`
|
||||
* @param[in] handle DAC channel handle, created from `dac_continuous_new_channels()`
|
||||
* @param[in] event DAC event data
|
||||
* @param[in] user_data User registered context, passed from `dac_conti_register_event_callback()`
|
||||
* @param[in] user_data User registered context, passed from `dac_continuous_register_event_callback()`
|
||||
*
|
||||
* @return Whether a high priority task has been waken up by this callback function
|
||||
*/
|
||||
typedef bool (*dac_isr_callback_t)(dac_conti_handle_t handle, const dac_event_data_t *event, void *user_data);
|
||||
typedef bool (*dac_isr_callback_t)(dac_continuous_handle_t handle, const dac_event_data_t *event, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Group of DAC callbacks
|
||||
@@ -101,7 +101,7 @@ typedef struct {
|
||||
* @brief Allocate new DAC channels in continuous mode
|
||||
* @note The DAC channels can't be registered to continuous mode separately
|
||||
*
|
||||
* @param[in] conti_cfg Continuous mode configuration
|
||||
* @param[in] cont_cfg Continuous mode configuration
|
||||
* @param[out] ret_handle The returned continuous mode handle
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
@@ -110,41 +110,63 @@ typedef struct {
|
||||
* - ESP_ERR_NO_MEM No memory for the DAC continuous mode resources
|
||||
* - ESP_OK Allocate the new DAC continuous mode success
|
||||
*/
|
||||
esp_err_t dac_new_conti_channels(const dac_conti_config_t *conti_cfg, dac_conti_handle_t *ret_handle);
|
||||
esp_err_t dac_continuous_new_channels(const dac_continuous_config_t *cont_cfg, dac_continuous_handle_t *ret_handle);
|
||||
|
||||
/**
|
||||
* @brief Delete the DAC continuous handle
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
* - ESP_ERR_INVALID_STATE The channels have already been deregistered or not disabled
|
||||
* - ESP_OK Delete the continuous channels success
|
||||
*/
|
||||
esp_err_t dac_del_conti_channels(dac_conti_handle_t handle);
|
||||
esp_err_t dac_continuous_del_channels(dac_continuous_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Enabled the DAC continuous mode
|
||||
* @note Must enable the channels before
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
* - ESP_ERR_INVALID_STATE The channels have been enabled already
|
||||
* - ESP_OK Enable the continuous output success
|
||||
*/
|
||||
esp_err_t dac_conti_enable(dac_conti_handle_t handle);
|
||||
esp_err_t dac_continuous_enable(dac_continuous_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Disable the DAC continuous mode
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
* - ESP_ERR_INVALID_STATE The channels have been enabled already
|
||||
* - ESP_OK Disable the continuous output success
|
||||
*/
|
||||
esp_err_t dac_conti_disable(dac_conti_handle_t handle);
|
||||
esp_err_t dac_continuous_disable(dac_continuous_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Write DAC data continuously
|
||||
* @note The data in buffer will only be converted one time,
|
||||
* This function will be blocked until all data loaded or timeout
|
||||
* then the DAC output will keep outputting the voltage of the last data in the buffer
|
||||
* @note Specially, on ESP32, the data bit width of DAC continuous data is fixed to 16 bits while only the high 8 bits are available,
|
||||
* The driver will help to expand the inputted buffer automatically by default,
|
||||
* you can also align the data to 16 bits manually by clearing `CONFIG_DAC_DMA_AUTO_16BIT_ALIGN` in menuconfig.
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @param[in] buf The digital data buffer to convert
|
||||
* @param[in] buf_size The buffer size of digital data buffer
|
||||
* @param[out] bytes_loaded The bytes that has been loaded into DMA buffer, can be NULL if don't need it
|
||||
* @param[in] timeout_ms The timeout time in millisecond, set a minus value means will block forever
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
* - ESP_ERR_INVALID_STATE The DAC continuous mode has not been enabled yet
|
||||
* - ESP_ERR_TIMEOUT Waiting for semaphore or message queue timeout
|
||||
* - ESP_OK Success to output the acyclic DAC data
|
||||
*/
|
||||
esp_err_t dac_continuous_write(dac_continuous_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Write DAC continuous data cyclically
|
||||
@@ -158,7 +180,7 @@ esp_err_t dac_conti_disable(dac_conti_handle_t handle);
|
||||
* The driver will help to expand the inputted buffer automatically by default,
|
||||
* you can also align the data to 16 bits manually by clearing `CONFIG_DAC_DMA_AUTO_16BIT_ALIGN` in menuconfig.
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @param[in] buf The digital data buffer to convert
|
||||
* @param[in] buf_size The buffer size of digital data buffer
|
||||
* @param[out] bytes_loaded The bytes that has been loaded into DMA buffer, can be NULL if don't need it
|
||||
@@ -167,29 +189,7 @@ esp_err_t dac_conti_disable(dac_conti_handle_t handle);
|
||||
* - ESP_ERR_INVALID_STATE The DAC continuous mode has not been enabled yet
|
||||
* - ESP_OK Success to output the acyclic DAC data
|
||||
*/
|
||||
esp_err_t dac_conti_write_cyclically(dac_conti_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded);
|
||||
|
||||
/**
|
||||
* @brief Write DAC data continuously
|
||||
* @note The data in buffer will only be converted one time,
|
||||
* This function will be blocked until all data loaded or timeout
|
||||
* then the DAC output will keep outputting the voltage of the last data in the buffer
|
||||
* @note Specially, on ESP32, the data bit width of DAC continuous data is fixed to 16 bits while only the high 8 bits are available,
|
||||
* The driver will help to expand the inputted buffer automatically by default,
|
||||
* you can also align the data to 16 bits manually by clearing `CONFIG_DAC_DMA_AUTO_16BIT_ALIGN` in menuconfig.
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] buf The digital data buffer to convert
|
||||
* @param[in] buf_size The buffer size of digital data buffer
|
||||
* @param[out] bytes_loaded The bytes that has been loaded into DMA buffer, can be NULL if don't need it
|
||||
* @param[in] timeout_ms The timeout time in millisecond, set a minus value means will block forever
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG The input parameter is invalid
|
||||
* - ESP_ERR_INVALID_STATE The DAC continuous mode has not been enabled yet
|
||||
* - ESP_ERR_TIMEOUT Waiting for semaphore or message queue timeout
|
||||
* - ESP_OK Success to output the acyclic DAC data
|
||||
*/
|
||||
esp_err_t dac_conti_write(dac_conti_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded, int timeout_ms);
|
||||
esp_err_t dac_continuous_write_cyclically(dac_continuous_handle_t handle, uint8_t *buf, size_t buf_size, size_t *bytes_loaded);
|
||||
|
||||
/**
|
||||
* @brief Set event callbacks for DAC continuous mode
|
||||
@@ -198,46 +198,46 @@ esp_err_t dac_conti_write(dac_conti_handle_t handle, uint8_t *buf, size_t buf_si
|
||||
* @note When CONFIG_DAC_ISR_IRAM_SAFE is enabled, the callback itself and functions called by it should be placed in IRAM.
|
||||
* The variables used in this function, including the `user_data`, should be in the internal RAM as well.
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @param[in] callbacks Group of callback functions, input NULL to clear the former callbacks
|
||||
* @param[in] user_data User data, which will be passed to callback functions directly
|
||||
* @return
|
||||
* - ESP_OK Set event callbacks successfully
|
||||
* - ESP_ERR_INVALID_ARG Set event callbacks failed because of invalid argument
|
||||
*/
|
||||
esp_err_t dac_conti_register_event_callback(dac_conti_handle_t handle, const dac_event_callbacks_t *callbacks, void *user_data);
|
||||
esp_err_t dac_continuous_register_event_callback(dac_continuous_handle_t handle, const dac_event_callbacks_t *callbacks, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Start the async writing
|
||||
* @note When the asynchronous writing start, the DAC will keep outputting '0' until the data are loaded into the DMA buffer.
|
||||
* To loaded the data into DMA buffer, 'on_convert_done' callback is required,
|
||||
* which can be registered by 'dac_conti_register_event_callback' before enabling
|
||||
* which can be registered by 'dac_continuous_register_event_callback' before enabling
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @return
|
||||
* - ESP_OK Start asynchronous writing successfully
|
||||
* - ESP_ERR_INVALID_ARG The handle is NULL
|
||||
* - ESP_ERR_INVALID_STATE The channel is not enabled or the 'on_convert_done' callback is not registered
|
||||
*/
|
||||
esp_err_t dac_conti_start_async_writing(dac_conti_handle_t handle);
|
||||
esp_err_t dac_continuous_start_async_writing(dac_continuous_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Stop the sync writing
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @return
|
||||
* - ESP_OK Stop asynchronous writing successfully
|
||||
* - ESP_ERR_INVALID_ARG The handle is NULL
|
||||
* - ESP_ERR_INVALID_STATE Asynchronous writing has not started
|
||||
*/
|
||||
esp_err_t dac_conti_stop_async_writing(dac_conti_handle_t handle);
|
||||
esp_err_t dac_continuous_stop_async_writing(dac_continuous_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Write DAC data asynchronously
|
||||
* @note This function can be called when the asynchronous writing started, and it can be called in the callback directly
|
||||
* but recommend to writing data in a task, referring to :example:`peripherals/dac/dac_continuous/dac_audio`
|
||||
*
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_new_conti_channels'
|
||||
* @param[in] handle The DAC continuous channel handle that obtained from 'dac_continuous_new_channels'
|
||||
* @param[in] dma_buf The DMA buffer address, it can be acquired from 'dac_event_data_t' in the 'on_convert_done' callback
|
||||
* @param[in] dma_buf_len The DMA buffer length, it can be acquired from 'dac_event_data_t' in the 'on_convert_done' callback
|
||||
* @param[in] data The data that need to be written
|
||||
@@ -249,12 +249,12 @@ esp_err_t dac_conti_stop_async_writing(dac_conti_handle_t handle);
|
||||
* - ESP_ERR_INVALID_STATE The channels haven't start the asynchronous writing
|
||||
* - ESP_ERR_NOT_FOUND The param 'dam_buf' not match any existed DMA buffer
|
||||
*/
|
||||
esp_err_t dac_conti_write_asynchronously(dac_conti_handle_t handle,
|
||||
uint8_t *dma_buf,
|
||||
size_t dma_buf_len,
|
||||
const uint8_t *data,
|
||||
size_t data_len,
|
||||
size_t *bytes_loaded);
|
||||
esp_err_t dac_continuous_write_asynchronously(dac_continuous_handle_t handle,
|
||||
uint8_t *dma_buf,
|
||||
size_t dma_buf_len,
|
||||
const uint8_t *data,
|
||||
size_t data_len,
|
||||
size_t *bytes_loaded);
|
||||
|
||||
#endif // SOC_DAC_SUPPORTED
|
||||
|
@@ -55,7 +55,7 @@ typedef struct {
|
||||
* - ESP_ERR_NO_MEM No memory for the DAC cosine wave channel resources
|
||||
* - ESP_OK Allocate the new DAC cosine wave channel success
|
||||
*/
|
||||
esp_err_t dac_new_cosine_channel(const dac_cosine_config_t *cos_cfg, dac_cosine_handle_t *ret_handle);
|
||||
esp_err_t dac_cosine_new_channel(const dac_cosine_config_t *cos_cfg, dac_cosine_handle_t *ret_handle);
|
||||
|
||||
/**
|
||||
* @brief Delete the DAC cosine wave channel
|
||||
@@ -66,7 +66,7 @@ esp_err_t dac_new_cosine_channel(const dac_cosine_config_t *cos_cfg, dac_cosine_
|
||||
* - ESP_ERR_INVALID_STATE The channel has already been deregistered
|
||||
* - ESP_OK Delete the cosine wave channel success
|
||||
*/
|
||||
esp_err_t dac_del_cosine_channel(dac_cosine_handle_t handle);
|
||||
esp_err_t dac_cosine_del_channel(dac_cosine_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Start outputting the cosine wave on the channel
|
||||
|
@@ -37,7 +37,7 @@ typedef struct {
|
||||
* - ESP_ERR_NO_MEM No memory for the DAC oneshot channel resources
|
||||
* - ESP_OK Allocate the new DAC oneshot channel success
|
||||
*/
|
||||
esp_err_t dac_new_oneshot_channel(const dac_oneshot_config_t *oneshot_cfg, dac_oneshot_handle_t *ret_handle);
|
||||
esp_err_t dac_oneshot_new_channel(const dac_oneshot_config_t *oneshot_cfg, dac_oneshot_handle_t *ret_handle);
|
||||
|
||||
/**
|
||||
* @brief Delete the DAC oneshot channel
|
||||
@@ -49,7 +49,7 @@ esp_err_t dac_new_oneshot_channel(const dac_oneshot_config_t *oneshot_cfg, dac_o
|
||||
* - ESP_ERR_INVALID_STATE The channel has already been de-registered
|
||||
* - ESP_OK Delete the oneshot channel success
|
||||
*/
|
||||
esp_err_t dac_del_oneshot_channel(dac_oneshot_handle_t handle);
|
||||
esp_err_t dac_oneshot_del_channel(dac_oneshot_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Output the voltage
|
||||
|
@@ -35,13 +35,13 @@ extern "C" {
|
||||
typedef enum {
|
||||
DAC_CHANNEL_MODE_SIMUL, /*!< The data in the DMA buffer is simultaneously output to the enable channel of the DAC. */
|
||||
DAC_CHANNEL_MODE_ALTER, /*!< The data in the DMA buffer is alternately output to the enable channel of the DAC. */
|
||||
} dac_conti_channel_mode_t;
|
||||
} dac_continuous_channel_mode_t;
|
||||
|
||||
/**
|
||||
* @brief DAC DMA (digitial controller) clock source
|
||||
*
|
||||
*/
|
||||
typedef soc_periph_dac_digi_clk_src_t dac_conti_digi_clk_src_t;
|
||||
typedef soc_periph_dac_digi_clk_src_t dac_continuous_digi_clk_src_t;
|
||||
|
||||
/**
|
||||
* @brief DAC cosine wave generator clock source
|
||||
|
@@ -19,6 +19,6 @@ entries:
|
||||
sdm: sdm_channel_set_duty (noflash)
|
||||
if DAC_CTRL_FUNC_IN_IRAM = y:
|
||||
dac_oneshot: dac_oneshot_output_voltage (noflash)
|
||||
dac_conti: dac_conti_write_asynchronously (noflash)
|
||||
dac_continuous: dac_continuous_write_asynchronously (noflash)
|
||||
if MCPWM_CTRL_FUNC_IN_IRAM = y:
|
||||
mcpwm_cmpr: mcpwm_comparator_set_compare_value (noflash)
|
||||
|
@@ -10,7 +10,7 @@
|
||||
#include "unity_test_utils.h"
|
||||
#include "driver/dac_oneshot.h"
|
||||
#include "driver/dac_cosine.h"
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_err.h"
|
||||
@@ -39,13 +39,13 @@ TEST_CASE("DAC_API_basic_logic_test", "[dac]")
|
||||
{
|
||||
/* Constant API test */
|
||||
dac_oneshot_handle_t oneshot_chan0_handle;
|
||||
TEST_ESP_OK(dac_new_oneshot_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_0}, &oneshot_chan0_handle));
|
||||
TEST_ESP_OK(dac_oneshot_new_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_0}, &oneshot_chan0_handle));
|
||||
TEST_ESP_OK(dac_oneshot_output_voltage(oneshot_chan0_handle, 128));
|
||||
TEST_ESP_OK(dac_del_oneshot_channel(oneshot_chan0_handle));
|
||||
TEST_ESP_OK(dac_oneshot_del_channel(oneshot_chan0_handle));
|
||||
dac_oneshot_handle_t oneshot_chan1_handle;
|
||||
TEST_ESP_OK(dac_new_oneshot_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_1}, &oneshot_chan1_handle));
|
||||
TEST_ESP_OK(dac_oneshot_new_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_1}, &oneshot_chan1_handle));
|
||||
TEST_ESP_OK(dac_oneshot_output_voltage(oneshot_chan1_handle, 100));
|
||||
TEST_ESP_OK(dac_del_oneshot_channel(oneshot_chan1_handle));
|
||||
TEST_ESP_OK(dac_oneshot_del_channel(oneshot_chan1_handle));
|
||||
|
||||
/* Cosine wave API test */
|
||||
dac_cosine_handle_t cos_chan0_handle;
|
||||
@@ -68,24 +68,24 @@ TEST_CASE("DAC_API_basic_logic_test", "[dac]")
|
||||
.atten = DAC_COSINE_ATTEN_DB_6,
|
||||
.flags.force_set_freq = false,
|
||||
};
|
||||
TEST_ESP_OK(dac_new_cosine_channel(&cos0_cfg, &cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_new_channel(&cos0_cfg, &cos_chan0_handle));
|
||||
/* Try to update the frequency without force set */
|
||||
TEST_ASSERT(dac_new_cosine_channel(&cos1_cfg, &cos_chan1_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ASSERT(dac_cosine_new_channel(&cos1_cfg, &cos_chan1_handle) == ESP_ERR_INVALID_STATE);
|
||||
/* Force update the frequnecy */
|
||||
cos1_cfg.flags.force_set_freq = true;
|
||||
TEST_ESP_OK(dac_new_cosine_channel(&cos1_cfg, &cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_cosine_new_channel(&cos1_cfg, &cos_chan1_handle));
|
||||
TEST_ASSERT(dac_cosine_stop(cos_chan0_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_cosine_start(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_start(cos_chan1_handle));
|
||||
TEST_ASSERT(dac_del_cosine_channel(cos_chan0_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ASSERT(dac_cosine_del_channel(cos_chan0_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_cosine_stop(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_stop(cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_del_cosine_channel(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_del_cosine_channel(cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_cosine_del_channel(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_del_channel(cos_chan1_handle));
|
||||
|
||||
/* DMA API test */
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -100,25 +100,25 @@ TEST_CASE("DAC_API_basic_logic_test", "[dac]")
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
TEST_ASSERT(spicommon_periph_claim(SPI3_HOST, "dac_test"));
|
||||
#endif
|
||||
TEST_ASSERT(dac_new_conti_channels(&conti_cfg, &conti_handle) == ESP_ERR_NOT_FOUND);
|
||||
TEST_ASSERT(dac_continuous_new_channels(&cont_cfg, &cont_handle) == ESP_ERR_NOT_FOUND);
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
TEST_ESP_OK(i2s_platform_release_occupation(0));
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
TEST_ASSERT(spicommon_periph_free(SPI3_HOST));
|
||||
#endif
|
||||
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ASSERT(dac_conti_disable(conti_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ASSERT(dac_del_conti_channels(conti_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ASSERT(dac_continuous_disable(cont_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
TEST_ASSERT(dac_continuous_del_channels(cont_handle) == ESP_ERR_INVALID_STATE);
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("DAC_memory_leak_test", "[dac]")
|
||||
{
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -133,21 +133,21 @@ TEST_CASE("DAC_memory_leak_test", "[dac]")
|
||||
buf[i] = i % 256;
|
||||
}
|
||||
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(conti_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(cont_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
|
||||
uint32_t initial_size = esp_get_free_heap_size();
|
||||
printf("Initial free heap size: %"PRIu32"\n", initial_size);
|
||||
for (int i = 0; i < 20; i++) {
|
||||
printf("# %d: ---------------------------------\n", i + 1);
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(conti_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(cont_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
printf("current heap size: %"PRIu32"\n", esp_get_free_heap_size());
|
||||
TEST_ASSERT(initial_size == esp_get_free_heap_size());
|
||||
}
|
||||
@@ -161,7 +161,7 @@ TEST_CASE("DAC_set_voltage_test", "[dac]")
|
||||
dac_oneshot_config_t onshot_cfg = {
|
||||
.chan_id = DAC_CHAN_0,
|
||||
};
|
||||
TEST_ESP_OK(dac_new_oneshot_channel(&onshot_cfg, &oneshot_chan0_handle));
|
||||
TEST_ESP_OK(dac_oneshot_new_channel(&onshot_cfg, &oneshot_chan0_handle));
|
||||
|
||||
/* Prepare ADC2 */
|
||||
adc_oneshot_unit_handle_t adc2_handle;
|
||||
@@ -188,14 +188,14 @@ TEST_CASE("DAC_set_voltage_test", "[dac]")
|
||||
}
|
||||
last_adc = curr_adc;
|
||||
}
|
||||
TEST_ESP_OK(dac_del_oneshot_channel(oneshot_chan0_handle));
|
||||
TEST_ESP_OK(dac_oneshot_del_channel(oneshot_chan0_handle));
|
||||
TEST_ESP_OK(adc_oneshot_del_unit(adc2_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("DAC_dma_write_test", "[dac]")
|
||||
{
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 1024,
|
||||
@@ -210,17 +210,17 @@ TEST_CASE("DAC_dma_write_test", "[dac]")
|
||||
buf[i] = i % 104;
|
||||
}
|
||||
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(conti_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(cont_handle, buf, len, NULL));
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
for (int j = 0; j < 10; j++) {
|
||||
TEST_ESP_OK(dac_conti_write(conti_handle, buf, len, NULL, 1000));
|
||||
TEST_ESP_OK(dac_continuous_write(cont_handle, buf, len, NULL, 1000));
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
}
|
||||
|
||||
/* Test the conversion frequency by counting the pulse of WS signal
|
||||
@@ -261,8 +261,8 @@ TEST_CASE("DAC_dma_conver_frequency_test", "[dac]")
|
||||
data[i] = i % 256;
|
||||
}
|
||||
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -271,9 +271,9 @@ TEST_CASE("DAC_dma_conver_frequency_test", "[dac]")
|
||||
.clk_src = DAC_DIGI_CLK_SRC_DEFAULT,
|
||||
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
|
||||
};
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(conti_handle, data, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(cont_handle, data, len, NULL));
|
||||
|
||||
int expt_pulse = 2000;
|
||||
int real_pulse;
|
||||
@@ -284,18 +284,18 @@ TEST_CASE("DAC_dma_conver_frequency_test", "[dac]")
|
||||
TEST_ESP_OK(pcnt_unit_stop(pcnt_unit));
|
||||
TEST_ESP_OK(pcnt_unit_get_count(pcnt_unit, &real_pulse));
|
||||
/* Delete DAC continuous handle */
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
|
||||
printf("[PLL | 20000 Hz] %d pulses, expected %d, err %d\n", real_pulse, expt_pulse, real_pulse - expt_pulse);
|
||||
TEST_ASSERT_INT_WITHIN(expt_pulse * 0.01, expt_pulse, real_pulse);
|
||||
|
||||
conti_cfg.clk_src = DAC_DIGI_CLK_SRC_APLL;
|
||||
cont_cfg.clk_src = DAC_DIGI_CLK_SRC_APLL;
|
||||
/* Initialize DAC to test APLL clock */
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
/* Start transmitting data on line */
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(conti_handle, data, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(cont_handle, data, len, NULL));
|
||||
|
||||
/* Count pulse by PCNT */
|
||||
TEST_ESP_OK(pcnt_unit_clear_count(pcnt_unit));
|
||||
@@ -304,8 +304,8 @@ TEST_CASE("DAC_dma_conver_frequency_test", "[dac]")
|
||||
TEST_ESP_OK(pcnt_unit_stop(pcnt_unit));
|
||||
TEST_ESP_OK(pcnt_unit_get_count(pcnt_unit, &real_pulse));
|
||||
/* Delete DAC handle */
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
|
||||
printf("[APLL | 20000 Hz] %d pulses, expected %d, err %d\n", real_pulse, expt_pulse, real_pulse - expt_pulse);
|
||||
TEST_ASSERT_INT_WITHIN(expt_pulse * 0.01, expt_pulse, real_pulse);
|
||||
@@ -339,8 +339,8 @@ TEST_CASE("DAC_cosine_wave_test", "[dac]")
|
||||
.atten = DAC_COSINE_ATTEN_DB_6,
|
||||
.flags.force_set_freq = false,
|
||||
};
|
||||
TEST_ESP_OK(dac_new_cosine_channel(&cos0_cfg, &cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_new_cosine_channel(&cos1_cfg, &cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_cosine_new_channel(&cos0_cfg, &cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_new_channel(&cos1_cfg, &cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_cosine_start(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_start(cos_chan1_handle));
|
||||
|
||||
@@ -349,13 +349,13 @@ TEST_CASE("DAC_cosine_wave_test", "[dac]")
|
||||
|
||||
TEST_ESP_OK(dac_cosine_stop(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_stop(cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_del_cosine_channel(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_del_cosine_channel(cos_chan1_handle));
|
||||
TEST_ESP_OK(dac_cosine_del_channel(cos_chan0_handle));
|
||||
TEST_ESP_OK(dac_cosine_del_channel(cos_chan1_handle));
|
||||
}
|
||||
|
||||
static void dac_cyclically_write_task(void *arg)
|
||||
{
|
||||
dac_conti_handle_t dac_handle = (dac_conti_handle_t)arg;
|
||||
dac_continuous_handle_t dac_handle = (dac_continuous_handle_t)arg;
|
||||
size_t len = 1000;
|
||||
uint8_t buf[len];
|
||||
uint8_t max_val = 50;
|
||||
@@ -365,7 +365,7 @@ static void dac_cyclically_write_task(void *arg)
|
||||
buf[i] = i % max_val;
|
||||
}
|
||||
printf("Write cyclically\n");
|
||||
TEST_ESP_OK(dac_conti_write_cyclically(dac_handle, buf, len, NULL));
|
||||
TEST_ESP_OK(dac_continuous_write_cyclically(dac_handle, buf, len, NULL));
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
@@ -373,7 +373,7 @@ static void dac_cyclically_write_task(void *arg)
|
||||
|
||||
static void dac_continuously_write_task(void *arg)
|
||||
{
|
||||
dac_conti_handle_t dac_handle = (dac_conti_handle_t)arg;
|
||||
dac_continuous_handle_t dac_handle = (dac_continuous_handle_t)arg;
|
||||
size_t len = 2048;
|
||||
uint8_t buf[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -381,7 +381,7 @@ static void dac_continuously_write_task(void *arg)
|
||||
}
|
||||
while (1) {
|
||||
printf("Write continuously\n");
|
||||
TEST_ESP_OK(dac_conti_write(dac_handle, buf, len, NULL, 100));
|
||||
TEST_ESP_OK(dac_continuous_write(dac_handle, buf, len, NULL, 100));
|
||||
vTaskDelay(pdMS_TO_TICKS(300));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
@@ -389,8 +389,8 @@ static void dac_continuously_write_task(void *arg)
|
||||
|
||||
TEST_CASE("DAC_continuous_mode_concurrency_test", "[dac]")
|
||||
{
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 1024,
|
||||
@@ -400,19 +400,19 @@ TEST_CASE("DAC_continuous_mode_concurrency_test", "[dac]")
|
||||
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
|
||||
};
|
||||
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
|
||||
TaskHandle_t cyc_task;
|
||||
TaskHandle_t con_task;
|
||||
xTaskCreate(dac_cyclically_write_task, "dac_cyclically_write_task", 4096, conti_handle, 5, &cyc_task);
|
||||
xTaskCreate(dac_continuously_write_task, "dac_continuously_write_task", 4096, conti_handle, 5, &con_task);
|
||||
xTaskCreate(dac_cyclically_write_task, "dac_cyclically_write_task", 4096, cont_handle, 5, &cyc_task);
|
||||
xTaskCreate(dac_continuously_write_task, "dac_continuously_write_task", 4096, cont_handle, 5, &con_task);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
|
||||
vTaskDelete(cyc_task);
|
||||
vTaskDelete(con_task);
|
||||
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include "unity_test_utils.h"
|
||||
#include "unity_test_utils_cache.h"
|
||||
#include "driver/dac_oneshot.h"
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
@@ -43,7 +43,7 @@ static void IRAM_ATTR test_dac_dma_intr_iram_safety(void *usr_ctx)
|
||||
data->result = data->cnt > 0;
|
||||
}
|
||||
|
||||
static bool IRAM_ATTR test_dac_on_convert_done_cb(dac_conti_handle_t handle, const dac_event_data_t *event, void *user_data)
|
||||
static bool IRAM_ATTR test_dac_on_convert_done_cb(dac_continuous_handle_t handle, const dac_event_data_t *event, void *user_data)
|
||||
{
|
||||
test_dac_intr_data_t *data = (test_dac_intr_data_t *)user_data;
|
||||
data->cnt++;
|
||||
@@ -53,15 +53,15 @@ static bool IRAM_ATTR test_dac_on_convert_done_cb(dac_conti_handle_t handle, con
|
||||
TEST_CASE("DAC_IRAM_safe_test", "[dac]")
|
||||
{
|
||||
dac_oneshot_handle_t oneshot_handle;
|
||||
TEST_ESP_OK(dac_new_oneshot_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_0}, &oneshot_handle));
|
||||
TEST_ESP_OK(dac_oneshot_new_channel(&(dac_oneshot_config_t){.chan_id = DAC_CHAN_0}, &oneshot_handle));
|
||||
|
||||
/* Test direct voltage setting safety */
|
||||
unity_utils_run_cache_disable_stub(test_dac_direct_set_safety, oneshot_handle);
|
||||
|
||||
TEST_ESP_OK(dac_del_oneshot_channel(oneshot_handle));
|
||||
TEST_ESP_OK(dac_oneshot_del_channel(oneshot_handle));
|
||||
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -79,7 +79,7 @@ TEST_CASE("DAC_IRAM_safe_test", "[dac]")
|
||||
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
|
||||
};
|
||||
/* Allocate continuous channel */
|
||||
TEST_ESP_OK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
/* Register a callback to check if the interrupt can still triggered when cache is disabled */
|
||||
dac_event_callbacks_t cbs = {
|
||||
.on_convert_done = test_dac_on_convert_done_cb,
|
||||
@@ -89,9 +89,9 @@ TEST_CASE("DAC_IRAM_safe_test", "[dac]")
|
||||
.cnt = 0,
|
||||
.result = false,
|
||||
};
|
||||
TEST_ESP_OK(dac_conti_register_event_callback(conti_handle, &cbs, &intr_data));
|
||||
TEST_ESP_OK(dac_continuous_register_event_callback(cont_handle, &cbs, &intr_data));
|
||||
/* Enable the channels in the group */
|
||||
TEST_ESP_OK(dac_conti_enable(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_enable(cont_handle));
|
||||
|
||||
/* Real data in internal memory */
|
||||
uint8_t *data = (uint8_t *)heap_caps_calloc(1, BUF_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
@@ -99,12 +99,12 @@ TEST_CASE("DAC_IRAM_safe_test", "[dac]")
|
||||
for (int i = 0; i < BUF_SIZE; i++) {
|
||||
data[i] = i % 256;
|
||||
}
|
||||
dac_conti_write_cyclically(conti_handle, data, BUF_SIZE, NULL);
|
||||
dac_continuous_write_cyclically(cont_handle, data, BUF_SIZE, NULL);
|
||||
unity_utils_run_cache_disable_stub(test_dac_dma_iram_safety, data);
|
||||
unity_utils_run_cache_disable_stub(test_dac_dma_intr_iram_safety, &intr_data);
|
||||
TEST_ASSERT(intr_data.result);
|
||||
|
||||
TEST_ESP_OK(dac_conti_disable(conti_handle));
|
||||
TEST_ESP_OK(dac_del_conti_channels(conti_handle));
|
||||
TEST_ESP_OK(dac_continuous_disable(cont_handle));
|
||||
TEST_ESP_OK(dac_continuous_del_channels(cont_handle));
|
||||
free(data);
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ INPUT = \
|
||||
$(PROJECT_PATH)/components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h \
|
||||
$(PROJECT_PATH)/components/bt/include/esp32/include/esp_bt.h \
|
||||
$(PROJECT_PATH)/components/console/esp_console.h \
|
||||
$(PROJECT_PATH)/components/driver/include/driver/dac_conti.h \
|
||||
$(PROJECT_PATH)/components/driver/include/driver/dac_continuous.h \
|
||||
$(PROJECT_PATH)/components/driver/include/driver/dac_cosine.h \
|
||||
$(PROJECT_PATH)/components/driver/include/driver/dac_oneshot.h \
|
||||
$(PROJECT_PATH)/components/driver/include/driver/dac_types.h \
|
||||
|
@@ -32,11 +32,11 @@ DAC File Structure
|
||||
- ``dac.h``: The top header file of legacy DAC driver, only included in the apps which use legacy driver API
|
||||
- ``dac_oneshot.h``: The top header file of new DAC driver, should be included in the apps which use the new driver API with oneshot mode.
|
||||
- ``dac_cosine.h``: The top header file of new DAC driver, should be included in the apps which use the new driver API with cosine mode.
|
||||
- ``dac_conti.h``: The top header file of new DAC driver, should be included in the apps which use the new driver API with continuous mode.
|
||||
- ``dac_continuous.h``: The top header file of new DAC driver, should be included in the apps which use the new driver API with continuous mode.
|
||||
|
||||
.. note::
|
||||
|
||||
The legacy driver can't coexist with the new driver. Including ``dac.h`` to use the legacy driver or ``dac_oneshot.h``, ``dac_cosine.h`` and ``dac_conti.h`` to use the new driver. The legacy driver might be removed in future.
|
||||
The legacy driver can't coexist with the new driver. Including ``dac.h`` to use the legacy driver or ``dac_oneshot.h``, ``dac_cosine.h`` and ``dac_continuous.h`` to use the new driver. The legacy driver might be removed in future.
|
||||
|
||||
Functional Overview
|
||||
-------------------
|
||||
@@ -44,21 +44,21 @@ Functional Overview
|
||||
Resources Management
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The DAC on {IDF_TARGET_NAME} has two channels, due to the software resources are separate, they could be managed by the :cpp:type:`dac_oneshot_handle_t`, :cpp:type:`dac_cosine_handle_t`:cpp:type:`dac_conti_handle_t` according to the usage. Of cause, registering different modes on a same DAC channel is not allowed.
|
||||
The DAC on {IDF_TARGET_NAME} has two channels, due to the software resources are separate, they could be managed by the :cpp:type:`dac_oneshot_handle_t`, :cpp:type:`dac_cosine_handle_t`:cpp:type:`dac_continuous_handle_t` according to the usage. Of cause, registering different modes on a same DAC channel is not allowed.
|
||||
|
||||
Direct Voltage Output (One-shot/Direct Mode)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The DAC channels in the group can convert a 8-bit digital value into the analog every time calling :cpp:func:`dac_oneshot_output_voltage` (it can be called in ISR), and then the analog voltage will be kept on the DAC channel until next conversion start. To start to convert the voltage, the DAC channels need to be registered by :cpp:func:`dac_new_oneshot_channel` first, and the channel will be enabled after it is registered.
|
||||
The DAC channels in the group can convert a 8-bit digital value into the analog every time calling :cpp:func:`dac_oneshot_output_voltage` (it can be called in ISR), and then the analog voltage will be kept on the DAC channel until next conversion start. To start to convert the voltage, the DAC channels need to be registered by :cpp:func:`dac_oneshot_new_channel` first, and the channel will be enabled after it is registered.
|
||||
|
||||
Continuous Wave Output (Continuous/DMA Mode)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
DAC channels can convert digital data continuously via the DMA. There are three ways to writing DAC data:
|
||||
|
||||
1. Normal writing (synchronous): It can transmit the data one time and keep blocking until all data has been loaded into the DMA buffer, and the voltage will be kept according to the last conversion value while no more data inputted, usually it is used to transport a long signal like an audio. To convert data continuously, the continuous channel handle need to be allocated by calling :cpp:func:`dac_new_conti_channels` and the DMA conversion should be enabled by :cpp:func:`dac_conti_enable`, then data can be written by :cpp:func:`dac_conti_write` synchronously. Referring to :example:`peripherals/dac/dac_continuous/dac_audio` for example.
|
||||
2. Cyclical writing: It can convert a piece of data cyclically without blocking, no more operation needed after the data are loaded into the DMA buffer,but note that the inputted buffer size is limited by the descriptor number and the DMA buffer size, usually it is used to transport some short signal that need to be repeated, for example, a sine wave. To achieve cyclical writing, :cpp:func:`dac_conti_write_cyclically` can be called after the DAC continuous mode is enabled. For the cyclical writing example, please refer to :example:`peripherals/dac/dac_continuous/signal_generator`
|
||||
3. Asynchronous writing: It can transmit the data asynchronously based on the event callback. Thus :cpp:member:`dac_event_callbacks_t::on_convert_done` must be registered to use asynchronous mode, and then users can get the :cpp:type:`dac_event_data_t` in the callback which contains the DMA buffer address and length, allowing user to load the data into it directly. As mentioned, to use the asynchronous writing, :cpp:func:`dac_conti_register_event_callback` need to be called to register the :cpp:member:`dac_event_callbacks_t::on_convert_done` before enabling, and then calling :cpp:func:`dac_conti_start_async_writing` to start the asynchronous writing, note that once the asynchronous writing started, the callback function will be triggered continuously, :cpp:func:`dac_conti_write_asynchronously` can help to load the data either in a separate task or the callback directly. For the asynchronous example, please refer to :example:`peripherals/dac/dac_continuous/dac_audio` as well.
|
||||
1. Normal writing (synchronous): It can transmit the data one time and keep blocking until all data has been loaded into the DMA buffer, and the voltage will be kept according to the last conversion value while no more data inputted, usually it is used to transport a long signal like an audio. To convert data continuously, the continuous channel handle need to be allocated by calling :cpp:func:`dac_continuous_new_channels` and the DMA conversion should be enabled by :cpp:func:`dac_continuous_enable`, then data can be written by :cpp:func:`dac_continuous_write` synchronously. Referring to :example:`peripherals/dac/dac_continuous/dac_audio` for example.
|
||||
2. Cyclical writing: It can convert a piece of data cyclically without blocking, no more operation needed after the data are loaded into the DMA buffer,but note that the inputted buffer size is limited by the descriptor number and the DMA buffer size, usually it is used to transport some short signal that need to be repeated, for example, a sine wave. To achieve cyclical writing, :cpp:func:`dac_continuous_write_cyclically` can be called after the DAC continuous mode is enabled. For the cyclical writing example, please refer to :example:`peripherals/dac/dac_continuous/signal_generator`
|
||||
3. Asynchronous writing: It can transmit the data asynchronously based on the event callback. Thus :cpp:member:`dac_event_callbacks_t::on_convert_done` must be registered to use asynchronous mode, and then users can get the :cpp:type:`dac_event_data_t` in the callback which contains the DMA buffer address and length, allowing user to load the data into it directly. As mentioned, to use the asynchronous writing, :cpp:func:`dac_continuous_register_event_callback` need to be called to register the :cpp:member:`dac_event_callbacks_t::on_convert_done` before enabling, and then calling :cpp:func:`dac_continuous_start_async_writing` to start the asynchronous writing, note that once the asynchronous writing started, the callback function will be triggered continuously, :cpp:func:`dac_continuous_write_asynchronously` can help to load the data either in a separate task or the callback directly. For the asynchronous example, please refer to :example:`peripherals/dac/dac_continuous/dac_audio` as well.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
@@ -66,8 +66,8 @@ DAC channels can convert digital data continuously via the DMA. There are three
|
||||
|
||||
The clock of DAC digital controller comes from I2S0 as well, so there are two kinds of clock source can be selected:
|
||||
|
||||
- :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_PLL_D2` can support frequency between 19.6 KHz to several MHz. It is the default clock which can also be selected by :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_DEFAULT`.
|
||||
- :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_APLL` can support frequency between 648 Hz to several MHz, however, it might be occupied by other peripherals, then it may not provide the required frequency. But it doesn't mean APLL is not available in this case, it can still work as long as it can be divided to the target DAC DMA frequency correctly.
|
||||
- :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_PLL_D2` can support frequency between 19.6 KHz to several MHz. It is the default clock which can also be selected by :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_DEFAULT`.
|
||||
- :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_APLL` can support frequency between 648 Hz to several MHz, however, it might be occupied by other peripherals, then it may not provide the required frequency. But it doesn't mean APLL is not available in this case, it can still work as long as it can be divided to the target DAC DMA frequency correctly.
|
||||
|
||||
.. only:: esp32s2
|
||||
|
||||
@@ -75,14 +75,14 @@ DAC channels can convert digital data continuously via the DMA. There are three
|
||||
|
||||
The clock source of DAC digital controller are:
|
||||
|
||||
- :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_APB` can support frequency between 77 Hz to several MHz. It is the default clock which can also be selected by :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_DEFAULT`.
|
||||
- :cpp:enumerator:`dac_conti_digi_clk_src_t::DAC_DIGI_CLK_SRC_APLL` can support frequency between 6 Hz to several MHz, however, it might be occupied by other peripherals, then it may not provide the required frequency. But it doesn't mean APLL is not available in this case, it can still work as long as it can be divided to the target DAC DMA frequency correctly.
|
||||
- :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_APB` can support frequency between 77 Hz to several MHz. It is the default clock which can also be selected by :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_DEFAULT`.
|
||||
- :cpp:enumerator:`dac_continuous_digi_clk_src_t::DAC_DIGI_CLK_SRC_APLL` can support frequency between 6 Hz to several MHz, however, it might be occupied by other peripherals, then it may not provide the required frequency. But it doesn't mean APLL is not available in this case, it can still work as long as it can be divided to the target DAC DMA frequency correctly.
|
||||
|
||||
|
||||
Cosine Wave Output (Cosine Mode)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The DAC peripheral has one cosine wave generator, it can generate cosine wave on the channels, users can specify the frequency, amplitude and phase of the cosine wave. To output the cosine wave, please acquire the DAC to cosine mode handle by :cpp:func:`dac_new_cosine_channel` first, and then start the cosine wave generator by :cpp:func:`dac_cosine_start`.
|
||||
The DAC peripheral has one cosine wave generator, it can generate cosine wave on the channels, users can specify the frequency, amplitude and phase of the cosine wave. To output the cosine wave, please acquire the DAC to cosine mode handle by :cpp:func:`dac_cosine_new_channel` first, and then start the cosine wave generator by :cpp:func:`dac_cosine_start`.
|
||||
|
||||
Currently, the source clock of the cosine wave generator only comes from ``RTC_FAST`` which can be chosen by :cpp:enumerator:`dac_cosine_clk_src_t::DAC_COSINE_CLK_SRC_RTC_FAST`, it is also the default clock source which is same as :cpp:enumerator:`dac_cosine_clk_src_t::DAC_COSINE_CLK_SRC_RTC_DEFAULT`.
|
||||
|
||||
@@ -91,7 +91,7 @@ Power Management
|
||||
|
||||
When the power management is enabled (i.e. :ref:`CONFIG_PM_ENABLE` is on), the system will adjust or stop the source clock of DAC before going into light sleep, thus potentially influence to the DAC signals may lead the data conversion goes wrong.
|
||||
|
||||
When using DAC driver in continuous mode, it can prevent the system from changing or stopping the source clock in DMA or cosine wave mode by acquiring a power management lock. When the source clock is generated from APB, the lock type will be set to :cpp:enumerator:`esp_pm_lock_type_t::ESP_PM_APB_FREQ_MAX` and when the source clock is APLL (only in DMA mode), it will be set to :cpp:enumerator:`esp_pm_lock_type_t::ESP_PM_NO_LIGHT_SLEEP`. Whenever the DAC is converting (i.e. DMA or cosine wave generator is working), the driver will guarantee that the power management lock is acquired after calling :cpp:func:`dac_conti_enable`. Likewise, the driver will release the lock when :cpp:func:`dac_conti_disable` is called.
|
||||
When using DAC driver in continuous mode, it can prevent the system from changing or stopping the source clock in DMA or cosine wave mode by acquiring a power management lock. When the source clock is generated from APB, the lock type will be set to :cpp:enumerator:`esp_pm_lock_type_t::ESP_PM_APB_FREQ_MAX` and when the source clock is APLL (only in DMA mode), it will be set to :cpp:enumerator:`esp_pm_lock_type_t::ESP_PM_NO_LIGHT_SLEEP`. Whenever the DAC is converting (i.e. DMA or cosine wave generator is working), the driver will guarantee that the power management lock is acquired after calling :cpp:func:`dac_continuous_enable`. Likewise, the driver will release the lock when :cpp:func:`dac_continuous_disable` is called.
|
||||
|
||||
IRAM Safe
|
||||
^^^^^^^^^
|
||||
@@ -136,6 +136,6 @@ API Reference
|
||||
|
||||
.. include-build-file:: inc/dac_oneshot.inc
|
||||
.. include-build-file:: inc/dac_cosine.inc
|
||||
.. include-build-file:: inc/dac_conti.inc
|
||||
.. include-build-file:: inc/dac_continuous.inc
|
||||
.. include-build-file:: inc/components/driver/include/driver/dac_types.inc
|
||||
.. include-build-file:: inc/components/hal/include/hal/dac_types.inc
|
||||
|
@@ -8,7 +8,7 @@ Peripherals
|
||||
DAC
|
||||
---
|
||||
|
||||
DAC driver has been redesigned (see :doc:`DAC API Reference <../../../api-reference/peripherals/dac>`), which aims to unify and extend the usage of DAC peripheral. Although it's recommended to use the new driver APIs, the legacy driver is still available in the previous include path ``driver/dac.h``. However, by default, including ``driver/dac.h`` will bring a build warning like `The legacy DAC driver is deprecated, please use 'driver/dac_oneshot.h', 'driver/dac_cosine.h' or 'driver/dac_conti.h' instead`. The warning can be suppressed by the Kconfig option :ref:`CONFIG_DAC_SUPPRESS_DEPRECATE_WARN`.
|
||||
DAC driver has been redesigned (see :doc:`DAC API Reference <../../../api-reference/peripherals/dac>`), which aims to unify and extend the usage of DAC peripheral. Although it's recommended to use the new driver APIs, the legacy driver is still available in the previous include path ``driver/dac.h``. However, by default, including ``driver/dac.h`` will bring a build warning like `The legacy DAC driver is deprecated, please use 'driver/dac_oneshot.h', 'driver/dac_cosine.h' or 'driver/dac_continuous.h' instead`. The warning can be suppressed by the Kconfig option :ref:`CONFIG_DAC_SUPPRESS_DEPRECATE_WARN`.
|
||||
|
||||
The major breaking changes in concept and usage are listed as follows:
|
||||
|
||||
@@ -23,7 +23,7 @@ Peripherals
|
||||
.. only:: esp32s2
|
||||
|
||||
- ``dac_digi_convert_mode_t`` is removed. The driver now can transmit DMA data in different ways by calling :cpp:func:`dac_channels_write_continuously` or :cpp:func:`dac_channels_write_cyclically`.
|
||||
- ``dac_digi_config_t`` is replaced by :cpp:type:`dac_conti_config_t`.
|
||||
- ``dac_digi_config_t`` is replaced by :cpp:type:`dac_continuous_config_t`.
|
||||
|
||||
Breaking Changes in Usage
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -34,16 +34,16 @@ Peripherals
|
||||
- ``dac_output_disable`` is removed, for oneshot mode, it will be disabled before the channel deleted.
|
||||
- ``dac_cw_generator_enable`` is replaced by :cpp:func:`dac_cosine_start`.
|
||||
- ``dac_cw_generator_disable`` is replaced by :cpp:func:`dac_cosine_stop`.
|
||||
- ``dac_cw_generator_config`` is replaced by :cpp:func:`dac_new_cosine_channel`.
|
||||
- ``dac_cw_generator_config`` is replaced by :cpp:func:`dac_cosine_new_channel`.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
- ``dac_i2s_enable`` is replaced by :cpp:func:`dac_conti_enable`, but it needs to allocate the continuous DAC channel first by :cpp:func:`dac_new_conti_channels`.
|
||||
- ``dac_i2s_disable`` is replaced by :cpp:func:`dac_conti_disable`.
|
||||
- ``dac_i2s_enable`` is replaced by :cpp:func:`dac_continuous_enable`, but it needs to allocate the continuous DAC channel first by :cpp:func:`dac_continuous_new_channels`.
|
||||
- ``dac_i2s_disable`` is replaced by :cpp:func:`dac_continuous_disable`.
|
||||
|
||||
.. only:: esp32s2
|
||||
|
||||
- ``dac_digi_init`` and ``dac_digi_controller_config`` is merged into :cpp:func:`dac_new_conti_channels`.
|
||||
- ``dac_digi_deinit`` is replaced by :cpp:func:`dac_del_conti_channels`.
|
||||
- ``dac_digi_start``, ``dac_digi_fifo_reset`` and ``dac_digi_reset`` are merged into :cpp:func:`dac_conti_enable`.
|
||||
- ``dac_digi_stop`` is replaced by :cpp:func:`dac_conti_disable`.
|
||||
- ``dac_digi_init`` and ``dac_digi_controller_config`` is merged into :cpp:func:`dac_continuous_new_channels`.
|
||||
- ``dac_digi_deinit`` is replaced by :cpp:func:`dac_continuous_del_channels`.
|
||||
- ``dac_digi_start``, ``dac_digi_fifo_reset`` and ``dac_digi_reset`` are merged into :cpp:func:`dac_continuous_enable`.
|
||||
- ``dac_digi_stop`` is replaced by :cpp:func:`dac_continuous_disable`.
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#else
|
||||
#include "driver/i2s_std.h"
|
||||
#endif
|
||||
@@ -89,7 +89,7 @@ static bool s_volume_notify; /* notify volume change or not */
|
||||
#ifndef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
i2s_chan_handle_t tx_chan = NULL;
|
||||
#else
|
||||
dac_conti_handle_t tx_chan;
|
||||
dac_continuous_handle_t tx_chan;
|
||||
#endif
|
||||
|
||||
/********************************
|
||||
@@ -170,7 +170,7 @@ static void bt_av_notify_evt_handler(uint8_t event_id, esp_avrc_rn_param_t *even
|
||||
void bt_i2s_driver_install(void)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -180,9 +180,9 @@ void bt_i2s_driver_install(void)
|
||||
.chan_mode = DAC_CHANNEL_MODE_ALTER,
|
||||
};
|
||||
/* Allocate continuous channels */
|
||||
ESP_ERROR_CHECK(dac_new_conti_channels(&conti_cfg, &tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_new_channels(&cont_cfg, &tx_chan));
|
||||
/* Enable the continuous channels */
|
||||
ESP_ERROR_CHECK(dac_conti_enable(tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_enable(tx_chan));
|
||||
#else
|
||||
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
||||
chan_cfg.auto_clear = true;
|
||||
@@ -212,8 +212,8 @@ void bt_i2s_driver_install(void)
|
||||
void bt_i2s_driver_uninstall(void)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
ESP_ERROR_CHECK(dac_conti_disable(tx_chan));
|
||||
ESP_ERROR_CHECK(dac_del_conti_channels(tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_disable(tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_del_channels(tx_chan));
|
||||
#else
|
||||
ESP_ERROR_CHECK(i2s_channel_disable(tx_chan));
|
||||
ESP_ERROR_CHECK(i2s_del_channel(tx_chan));
|
||||
@@ -314,9 +314,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
||||
ch_count = 1;
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_disable(tx_chan);
|
||||
dac_del_conti_channels(tx_chan);
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_disable(tx_chan);
|
||||
dac_continuous_del_channels(tx_chan);
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -326,9 +326,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
||||
.chan_mode = (ch_count == 1) ? DAC_CHANNEL_MODE_SIMUL : DAC_CHANNEL_MODE_ALTER,
|
||||
};
|
||||
/* Allocate continuous channels */
|
||||
dac_new_conti_channels(&conti_cfg, &tx_chan);
|
||||
dac_continuous_new_channels(&cont_cfg, &tx_chan);
|
||||
/* Enable the continuous channels */
|
||||
dac_conti_enable(tx_chan);
|
||||
dac_continuous_enable(tx_chan);
|
||||
#else
|
||||
i2s_channel_disable(tx_chan);
|
||||
i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(sample_rate);
|
||||
|
@@ -16,7 +16,7 @@
|
||||
#include "esp_log.h"
|
||||
#include "bt_app_core.h"
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#else
|
||||
#include "driver/i2s_std.h"
|
||||
#endif
|
||||
@@ -62,7 +62,7 @@ static uint16_t ringbuffer_mode = RINGBUFFER_MODE_PROCESSING;
|
||||
#ifndef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
extern i2s_chan_handle_t tx_chan;
|
||||
#else
|
||||
extern dac_conti_handle_t tx_chan;
|
||||
extern dac_continuous_handle_t tx_chan;
|
||||
#endif
|
||||
|
||||
/*******************************
|
||||
@@ -140,7 +140,7 @@ static void bt_i2s_task_handler(void *arg)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_write(tx_chan, data, item_size, &bytes_written, -1);
|
||||
dac_continuous_write(tx_chan, data, item_size, &bytes_written, -1);
|
||||
#else
|
||||
i2s_channel_write(tx_chan, data, item_size, &bytes_written, portMAX_DELAY);
|
||||
#endif
|
||||
|
@@ -22,7 +22,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#else
|
||||
#include "driver/i2s_std.h"
|
||||
#endif
|
||||
@@ -55,7 +55,7 @@ static bool s_volume_notify;
|
||||
#ifndef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
extern i2s_chan_handle_t tx_chan;
|
||||
#else
|
||||
extern dac_conti_handle_t tx_chan;
|
||||
extern dac_continuous_handle_t tx_chan;
|
||||
#endif
|
||||
|
||||
/* callback for A2DP sink */
|
||||
@@ -172,9 +172,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
||||
sample_rate = 48000;
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_disable(tx_chan);
|
||||
dac_del_conti_channels(tx_chan);
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_disable(tx_chan);
|
||||
dac_continuous_del_channels(tx_chan);
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -184,9 +184,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
||||
.chan_mode = DAC_CHANNEL_MODE_ALTER,
|
||||
};
|
||||
/* Allocate continuous channels */
|
||||
dac_new_conti_channels(&conti_cfg, &tx_chan);
|
||||
dac_continuous_new_channels(&cont_cfg, &tx_chan);
|
||||
/* Enable the continuous channels */
|
||||
dac_conti_enable(tx_chan);
|
||||
dac_continuous_enable(tx_chan);
|
||||
#else
|
||||
i2s_channel_disable(tx_chan);
|
||||
i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(sample_rate);
|
||||
|
@@ -16,7 +16,7 @@
|
||||
#include "bt_app_core.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#else
|
||||
#include "driver/i2s_std.h"
|
||||
#endif
|
||||
@@ -32,7 +32,7 @@ static RingbufHandle_t s_ringbuf_i2s = NULL;
|
||||
#ifndef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
extern i2s_chan_handle_t tx_chan;
|
||||
#else
|
||||
extern dac_conti_handle_t tx_chan;
|
||||
extern dac_continuous_handle_t tx_chan;
|
||||
#endif
|
||||
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
|
||||
@@ -133,7 +133,7 @@ static void bt_i2s_task_handler(void *arg)
|
||||
data = (uint8_t *)xRingbufferReceive(s_ringbuf_i2s, &item_size, (TickType_t)portMAX_DELAY);
|
||||
if (item_size != 0){
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_write(tx_chan, data, item_size, &bytes_written, -1);
|
||||
dac_continuous_write(tx_chan, data, item_size, &bytes_written, -1);
|
||||
#else
|
||||
i2s_channel_write(tx_chan, data, item_size, &bytes_written, portMAX_DELAY);
|
||||
#endif
|
||||
|
@@ -36,7 +36,7 @@
|
||||
#include "esp_a2dp_api.h"
|
||||
#include "esp_avrc_api.h"
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#else
|
||||
#include "driver/i2s_std.h"
|
||||
#endif
|
||||
@@ -77,7 +77,7 @@ static prepare_type_env_t b_prepare_write_env;
|
||||
#ifndef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
i2s_chan_handle_t tx_chan;
|
||||
#else
|
||||
dac_conti_handle_t tx_chan;
|
||||
dac_continuous_handle_t tx_chan;
|
||||
#endif
|
||||
|
||||
//Declare the static function
|
||||
@@ -692,7 +692,7 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_A2DP_SINK_OUTPUT_INTERNAL_DAC
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -702,9 +702,9 @@ void app_main(void)
|
||||
.chan_mode = DAC_CHANNEL_MODE_ALTER,
|
||||
};
|
||||
/* Allocate continuous channels */
|
||||
ESP_ERROR_CHECK(dac_new_conti_channels(&conti_cfg, &tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_new_channels(&cont_cfg, &tx_chan));
|
||||
/* Enable the continuous channels */
|
||||
ESP_ERROR_CHECK(dac_conti_enable(tx_chan));
|
||||
ESP_ERROR_CHECK(dac_continuous_enable(tx_chan));
|
||||
#else
|
||||
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
||||
chan_cfg.auto_clear = true;
|
||||
|
@@ -9,14 +9,14 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#include "esp_check.h"
|
||||
#include "audio_example_file.h"
|
||||
|
||||
static const char *TAG = "dac_audio";
|
||||
|
||||
#if CONFIG_EXAMPLE_DAC_WRITE_ASYNC
|
||||
static bool IRAM_ATTR dac_on_convert_done_callback(dac_conti_handle_t handle, const dac_event_data_t *event, void *user_data)
|
||||
static bool IRAM_ATTR dac_on_convert_done_callback(dac_continuous_handle_t handle, const dac_event_data_t *event, void *user_data)
|
||||
{
|
||||
QueueHandle_t que = (QueueHandle_t)user_data;
|
||||
BaseType_t need_awoke;
|
||||
@@ -30,7 +30,7 @@ static bool IRAM_ATTR dac_on_convert_done_callback(dac_conti_handle_t handle, c
|
||||
return need_awoke;
|
||||
}
|
||||
|
||||
static void dac_write_data_asynchronously(dac_conti_handle_t handle, QueueHandle_t que, uint8_t *data, size_t data_size)
|
||||
static void dac_write_data_asynchronously(dac_continuous_handle_t handle, QueueHandle_t que, uint8_t *data, size_t data_size)
|
||||
{
|
||||
ESP_LOGI(TAG, "Audio size %d bytes, played at frequency %d Hz asynchronously", data_size, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE);
|
||||
uint32_t cnt = 1;
|
||||
@@ -42,11 +42,11 @@ static void dac_write_data_asynchronously(dac_conti_handle_t handle, QueueHandle
|
||||
while (byte_written < data_size) {
|
||||
xQueueReceive(que, &evt_data, portMAX_DELAY);
|
||||
size_t loaded_bytes = 0;
|
||||
ESP_ERROR_CHECK(dac_conti_write_asynchronously(handle, evt_data.buf, evt_data.buf_size,
|
||||
ESP_ERROR_CHECK(dac_continuous_write_asynchronously(handle, evt_data.buf, evt_data.buf_size,
|
||||
data + byte_written, data_size - byte_written, &loaded_bytes));
|
||||
byte_written += loaded_bytes;
|
||||
}
|
||||
/* Clear the legacy data in DMA, clear times equal to the 'dac_conti_config_t::desc_num' */
|
||||
/* Clear the legacy data in DMA, clear times equal to the 'dac_continuous_config_t::desc_num' */
|
||||
for (int i = 0; i < 4; i++) {
|
||||
xQueueReceive(que, &evt_data, portMAX_DELAY);
|
||||
memset(evt_data.buf, 0, evt_data.buf_size);
|
||||
@@ -55,13 +55,13 @@ static void dac_write_data_asynchronously(dac_conti_handle_t handle, QueueHandle
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void dac_write_data_synchronously(dac_conti_handle_t handle, uint8_t *data, size_t data_size)
|
||||
static void dac_write_data_synchronously(dac_continuous_handle_t handle, uint8_t *data, size_t data_size)
|
||||
{
|
||||
ESP_LOGI(TAG, "Audio size %d bytes, played at frequency %d Hz synchronously", data_size, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE);
|
||||
uint32_t cnt = 1;
|
||||
while (1) {
|
||||
printf("Play count: %"PRIu32"\n", cnt++);
|
||||
ESP_ERROR_CHECK(dac_conti_write(handle, data, data_size, NULL, -1));
|
||||
ESP_ERROR_CHECK(dac_continuous_write(handle, data, data_size, NULL, -1));
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
@@ -72,8 +72,8 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "DAC audio example start");
|
||||
ESP_LOGI(TAG, "--------------------------------------");
|
||||
|
||||
dac_conti_handle_t dac_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t dac_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 4,
|
||||
.buf_size = 2048,
|
||||
@@ -91,7 +91,7 @@ void app_main(void)
|
||||
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
|
||||
};
|
||||
/* Allocate continuous channels */
|
||||
ESP_ERROR_CHECK(dac_new_conti_channels(&conti_cfg, &dac_handle));
|
||||
ESP_ERROR_CHECK(dac_continuous_new_channels(&cont_cfg, &dac_handle));
|
||||
#if CONFIG_EXAMPLE_DAC_WRITE_ASYNC
|
||||
/* Create a queue to transport the interrupt event data */
|
||||
QueueHandle_t que = xQueueCreate(10, sizeof(dac_event_data_t));
|
||||
@@ -101,15 +101,15 @@ void app_main(void)
|
||||
.on_stop = NULL,
|
||||
};
|
||||
/* Must register the callback if using asynchronous writing */
|
||||
ESP_ERROR_CHECK(dac_conti_register_event_callback(dac_handle, &cbs, que));
|
||||
ESP_ERROR_CHECK(dac_continuous_register_event_callback(dac_handle, &cbs, que));
|
||||
#endif
|
||||
/* Enable the continuous channels */
|
||||
ESP_ERROR_CHECK(dac_conti_enable(dac_handle));
|
||||
ESP_ERROR_CHECK(dac_continuous_enable(dac_handle));
|
||||
ESP_LOGI(TAG, "DAC initialized success, DAC DMA is ready");
|
||||
|
||||
size_t audio_size = sizeof(audio_table);
|
||||
#if CONFIG_EXAMPLE_DAC_WRITE_ASYNC
|
||||
ESP_ERROR_CHECK(dac_conti_start_async_writing(dac_handle));
|
||||
ESP_ERROR_CHECK(dac_continuous_start_async_writing(dac_handle));
|
||||
dac_write_data_asynchronously(dac_handle, que, (uint8_t *)audio_table, audio_size);
|
||||
#else
|
||||
dac_write_data_synchronously(dac_handle, (uint8_t *)audio_table, audio_size);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
set(srcs "dac_conti_example_main.c"
|
||||
"dac_conti_example_dma.c"
|
||||
"dac_conti_example_timer.c")
|
||||
set(srcs "dac_continuous_example_main.c"
|
||||
"dac_continuous_example_dma.c"
|
||||
"dac_continuous_example_timer.c")
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS ".")
|
||||
|
@@ -7,9 +7,9 @@
|
||||
#include <math.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/dac_conti.h"
|
||||
#include "driver/dac_continuous.h"
|
||||
#include "esp_check.h"
|
||||
#include "dac_conti_example.h"
|
||||
#include "dac_continuous_example.h"
|
||||
|
||||
#define EXAMPLE_WAVE_FREQ_HZ 2000 // Default wave frequency 2000 Hz, it can't be too low
|
||||
#define EXAMPLE_CONVERT_FREQ_HZ (EXAMPLE_ARRAY_LEN * EXAMPLE_WAVE_FREQ_HZ) // The frequency that DAC convert every data in the wave array
|
||||
@@ -24,7 +24,7 @@ static const char wav_name[DAC_WAVE_MAX][15] = {"sine", "triangle", "sawtooth",
|
||||
|
||||
static void dac_dma_write_task(void *args)
|
||||
{
|
||||
dac_conti_handle_t handle = (dac_conti_handle_t)args;
|
||||
dac_continuous_handle_t handle = (dac_continuous_handle_t)args;
|
||||
dac_example_wave_type_t wav_sel = DAC_SINE_WAVE; // Start from sine wave
|
||||
|
||||
size_t buf_len = EXAMPLE_ARRAY_LEN;
|
||||
@@ -33,16 +33,16 @@ static void dac_dma_write_task(void *args)
|
||||
/* The wave in the buffer will be converted cyclically */
|
||||
switch (wav_sel) {
|
||||
case DAC_SINE_WAVE:
|
||||
ESP_ERROR_CHECK(dac_conti_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL));
|
||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL));
|
||||
break;
|
||||
case DAC_TRIANGLE_WAVE:
|
||||
ESP_ERROR_CHECK(dac_conti_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL));
|
||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL));
|
||||
break;
|
||||
case DAC_SAWTOOTH_WAVE:
|
||||
ESP_ERROR_CHECK(dac_conti_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL));
|
||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL));
|
||||
break;
|
||||
case DAC_SQUARE_WAVE:
|
||||
ESP_ERROR_CHECK(dac_conti_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL));
|
||||
ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -57,8 +57,8 @@ static void dac_dma_write_task(void *args)
|
||||
|
||||
void example_dac_continuous_by_dma(void)
|
||||
{
|
||||
dac_conti_handle_t conti_handle;
|
||||
dac_conti_config_t conti_cfg = {
|
||||
dac_continuous_handle_t cont_handle;
|
||||
dac_continuous_config_t cont_cfg = {
|
||||
.chan_mask = DAC_CHANNEL_MASK_ALL,
|
||||
.desc_num = 8,
|
||||
.buf_size = 2048,
|
||||
@@ -76,12 +76,12 @@ void example_dac_continuous_by_dma(void)
|
||||
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
|
||||
};
|
||||
/* Allocate continuous channel */
|
||||
ESP_ERROR_CHECK(dac_new_conti_channels(&conti_cfg, &conti_handle));
|
||||
ESP_ERROR_CHECK(dac_continuous_new_channels(&cont_cfg, &cont_handle));
|
||||
/* Enable the channels in the group */
|
||||
ESP_ERROR_CHECK(dac_conti_enable(conti_handle));
|
||||
ESP_ERROR_CHECK(dac_continuous_enable(cont_handle));
|
||||
|
||||
example_log_info(EXAMPLE_CONVERT_FREQ_HZ, EXAMPLE_WAVE_FREQ_HZ);
|
||||
|
||||
/* Start to convert wave */
|
||||
xTaskCreate(dac_dma_write_task, "dac_dma_write_task", 4096, conti_handle, 5, NULL);
|
||||
xTaskCreate(dac_dma_write_task, "dac_dma_write_task", 4096, cont_handle, 5, NULL);
|
||||
}
|
@@ -11,7 +11,7 @@
|
||||
#include "soc/dac_channel.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_check.h"
|
||||
#include "dac_conti_example.h"
|
||||
#include "dac_continuous_example.h"
|
||||
|
||||
/**
|
||||
* There are two ways to convert digital data to analog signal continuously:
|
@@ -15,7 +15,7 @@
|
||||
#include "driver/gptimer.h"
|
||||
#include "driver/dac_oneshot.h"
|
||||
#include "esp_log.h"
|
||||
#include "dac_conti_example.h"
|
||||
#include "dac_continuous_example.h"
|
||||
|
||||
#define EXAMPLE_TIMER_RESOLUTION 1000000 // 1MHz, 1 tick = 1us
|
||||
#define EXAMPLE_WAVE_FREQ_HZ 50 // Default wave frequency 50 Hz, it can't be too high
|
||||
@@ -86,11 +86,11 @@ void example_dac_continuous_by_timer(void)
|
||||
dac_oneshot_config_t dac0_cfg = {
|
||||
.chan_id = DAC_CHAN_0,
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_oneshot_channel(&dac0_cfg, &chan0_handle));
|
||||
ESP_ERROR_CHECK(dac_oneshot_new_channel(&dac0_cfg, &chan0_handle));
|
||||
dac_oneshot_config_t dac1_cfg = {
|
||||
.chan_id = DAC_CHAN_1,
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_oneshot_channel(&dac1_cfg, &chan1_handle));
|
||||
ESP_ERROR_CHECK(dac_oneshot_new_channel(&dac1_cfg, &chan1_handle));
|
||||
|
||||
example_log_info(EXAMPLE_CONVERT_FREQ_HZ, EXAMPLE_WAVE_FREQ_HZ);
|
||||
|
@@ -61,8 +61,8 @@ void app_main(void)
|
||||
.atten = DAC_COSINE_ATTEN_DB_6,
|
||||
.flags.force_set_freq = true, // set true will allow to overwrite the frequency that set before
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_cosine_channel(&cos0_cfg, &chan0_handle));
|
||||
ESP_ERROR_CHECK(dac_new_cosine_channel(&cos1_cfg, &chan1_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_new_channel(&cos0_cfg, &chan0_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_new_channel(&cos1_cfg, &chan1_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_start(chan0_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_start(chan1_handle));
|
||||
|
||||
|
@@ -55,13 +55,13 @@ void app_main(void)
|
||||
dac_oneshot_config_t chan0_cfg = {
|
||||
.chan_id = DAC_CHAN_0,
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_oneshot_channel(&chan0_cfg, &chan0_handle));
|
||||
ESP_ERROR_CHECK(dac_oneshot_new_channel(&chan0_cfg, &chan0_handle));
|
||||
|
||||
dac_oneshot_handle_t chan1_handle;
|
||||
dac_oneshot_config_t chan1_cfg = {
|
||||
.chan_id = DAC_CHAN_1,
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_oneshot_channel(&chan1_cfg, &chan1_handle));
|
||||
ESP_ERROR_CHECK(dac_oneshot_new_channel(&chan1_cfg, &chan1_handle));
|
||||
|
||||
/* DAC oneshot outputting threads */
|
||||
xTaskCreate(dac_output_task, "dac_chan0_output_task", 4096, chan0_handle, 5, NULL);
|
||||
|
@@ -43,7 +43,7 @@ static void enable_cosine_generator(void)
|
||||
.atten = DAC_COSINE_ATTEN_DEFAULT,
|
||||
.flags.force_set_freq = false,
|
||||
};
|
||||
ESP_ERROR_CHECK(dac_new_cosine_channel(&cos_cfg, &dac_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_new_channel(&cos_cfg, &dac_handle));
|
||||
ESP_ERROR_CHECK(dac_cosine_start(dac_handle));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user