fm_ccjy/bsp/dacs.c

43 lines
1.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "dacs.h"
/**
* @brief 输出指定值到DAC。
* @param {dac_t} *dacDAC控制结构体指针。
* @param {uint16_t} value要输出的值。
* @return {void}
* @note: 此函数用于输出指定值到指定的DAC通道。
*/
static void _out(dac_t *dac, uint16_t value)
{
DAC_OUT(dac->dac, dac->dac_channel, value);
}
/**
* @brief 创建一个DAC处理对象。
* @param {DAC_TypeDef} *dacDAC外设寄存器地址。
* @param {uint16_t} dac_channelDAC通道。
* @return {dac_t *} DAC处理对象指针。
* @note: 此函数用于创建一个DAC处理对象用于输出指定值到指定的DAC通道。
*/
dac_t *dac_create(DAC_TypeDef *dac, uint16_t dac_channel)
{
dac_t *handle = (dac_t *)osel_mem_alloc(sizeof(dac_t));
DBG_ASSERT(handle != NULL __DBG_LINE);
handle->dac = dac;
handle->dac_channel = dac_channel;
handle->out = _out;
return handle;
}
/**
* @brief 释放DAC处理对象。
* @param {dac_t} *dacDAC处理对象指针。
* @return {void}
* @note: 此函数用于释放DAC处理对象占用的内存。
*/
void dac_free(dac_t *dac)
{
osel_mem_free(dac);
}