61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
/*
|
|
* DAC.cpp
|
|
*
|
|
* Created on: Jun 25, 2023
|
|
* Author: Carst
|
|
*/
|
|
|
|
#include <stm32g0xx_ll_gpio.h>
|
|
#include <stm32g0xx_ll_dac.h>
|
|
#include "DAC.hpp"
|
|
|
|
namespace ElektronischeLast
|
|
{
|
|
iDAC::iDAC()
|
|
{
|
|
/**DAC1 GPIO Configuration
|
|
PA4 ------> DAC1_OUT1
|
|
PA5 ------> DAC1_OUT2
|
|
*/
|
|
LL_GPIO_InitTypeDef GPIO_InitStruct = {
|
|
.Pin = LL_GPIO_PIN_4,
|
|
.Mode = LL_GPIO_MODE_ANALOG,
|
|
.Pull = LL_GPIO_PULL_NO,
|
|
};
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/** DAC channel OUT1 config
|
|
*/
|
|
LL_DAC_InitTypeDef DAC_InitStruct = {
|
|
.TriggerSource = LL_DAC_TRIG_SOFTWARE,
|
|
.WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE,
|
|
.OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE,
|
|
.OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO,
|
|
.OutputMode = LL_DAC_OUTPUT_MODE_NORMAL,
|
|
};
|
|
LL_DAC_Init(DAC1, LL_DAC_CHANNEL_1, &DAC_InitStruct);
|
|
LL_DAC_DisableTrigger(DAC1, LL_DAC_CHANNEL_1);
|
|
LL_DAC_EnableDMAReq(DAC1, LL_DAC_CHANNEL_1);
|
|
LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_1);
|
|
|
|
/** DAC channel OUT2 config
|
|
*/
|
|
LL_DAC_Init(DAC1, LL_DAC_CHANNEL_2, &DAC_InitStruct);
|
|
LL_DAC_DisableTrigger(DAC1, LL_DAC_CHANNEL_2);
|
|
LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_2);
|
|
}
|
|
|
|
iDAC::~iDAC()
|
|
{
|
|
|
|
}
|
|
|
|
void iDAC::write(DAC_CHANNEL channel, uint32_t data)
|
|
{
|
|
LL_DAC_ConvertData12RightAligned(DAC, /*(channel == CHANNEL_1) ?*/ LL_DAC_CHANNEL_1 /*: LL_DAC_CHANNEL_2*/, data);
|
|
}
|
|
}
|