big refactoring and features added
This commit is contained in:
45
App/Devices/stm32_dac_output.c
Normal file
45
App/Devices/stm32_dac_output.c
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file stm32_dac_output.c
|
||||
* @brief STM32 internal DAC helper for the PA4 analogue output.
|
||||
*/
|
||||
|
||||
#include "stm32_dac_output.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define STM32_DAC_MAX_CODE 4095u
|
||||
|
||||
void stm32_dac_output_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init = {0};
|
||||
|
||||
__HAL_RCC_DAC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
gpio_init.Pin = GPIO_PIN_4;
|
||||
gpio_init.Mode = GPIO_MODE_ANALOG;
|
||||
gpio_init.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &gpio_init);
|
||||
|
||||
DAC->CR &= ~(DAC_CR_EN1 | DAC_CR_TEN1 | DAC_CR_DMAEN1);
|
||||
DAC->DHR12R1 = 0u;
|
||||
}
|
||||
|
||||
void stm32_dac_output_set(uint16_t dac_code, uint8_t enabled)
|
||||
{
|
||||
if (dac_code > STM32_DAC_MAX_CODE)
|
||||
{
|
||||
dac_code = STM32_DAC_MAX_CODE;
|
||||
}
|
||||
|
||||
DAC->DHR12R1 = dac_code;
|
||||
|
||||
if (enabled != 0u)
|
||||
{
|
||||
DAC->CR |= DAC_CR_EN1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DAC->CR &= ~DAC_CR_EN1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user