motor_f407/User/system/bsp/dacs.c

53 lines
1.3 KiB
C

/**
* @file dacs.c
* @brief This file contains the implementation of the DAC module.
* It provides functions to initialize and de-initialize a DAC instance,
* as well as write a 16-bit value to the specified DAC channel.
* @author xxx
* @date 2023-12-27 14:44:03
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
*/
#include "dacs.h"
/**
* @brief Writes a 16-bit value to the specified DAC channel
*
* @param dac pointer to the DAC instance
* @param value 16-bit value to write to the DAC
*/
static void _out(dac_t *dac, uint16_t value)
{
DBG_ASSERT(dac != NULL __DBG_LINE);
DAC_OUT(dac->dac, dac->dac_channel, value);
}
/**
* @brief Initializes a DAC instance
*
* @param dac pointer to the DAC instance
* @param dac_channel DAC channel to use
* @return pointer to the initialized DAC instance
*/
dac_t *dac_create(DAC_TypeDef *dac, uint16_t dac_channel)
{
DBG_ASSERT(dac != NULL __DBG_LINE);
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 De-initializes a DAC instance
*
* @param dac pointer to the DAC instance
*/
void dac_free(dac_t *dac)
{
DBG_ASSERT(dac != NULL __DBG_LINE);
osel_mem_free(dac);
}