libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::STM32DAC Class Reference

STM32 DAC 驱动实现 / STM32 DAC driver implementation. More...

#include <stm32_dac.hpp>

Inheritance diagram for LibXR::STM32DAC:
[legend]
Collaboration diagram for LibXR::STM32DAC:
[legend]

Public Member Functions

 STM32DAC (DAC_HandleTypeDef *hdac, uint32_t channel, float init_voltage=0.0f, float vref=3.3f)
 构造 DAC 对象 / Construct DAC object
 
ErrorCode Write (float voltage) override
 输出电压 / Output analog voltage
 
- Public Member Functions inherited from LibXR::DAC
 DAC ()=default
 默认构造函数 / Default constructor
 

Detailed Description

STM32 DAC 驱动实现 / STM32 DAC driver implementation.

Definition at line 17 of file stm32_dac.hpp.

Constructor & Destructor Documentation

◆ STM32DAC()

STM32DAC::STM32DAC ( DAC_HandleTypeDef * hdac,
uint32_t channel,
float init_voltage = 0.0f,
float vref = 3.3f )

构造 DAC 对象 / Construct DAC object

Definition at line 7 of file stm32_dac.cpp.

9 : hdac_(hadc), channel_(channel), vref_(vref)
10{
11// NOLINTBEGIN
12#if defined(DAC_ALIGN_12B_R)
13 align_ = DAC_ALIGN_12B_R;
14 resolution_ = 4095;
15#elif defined(DAC_ALIGN_8B_R)
16 align_ = DAC_ALIGN_8B_R;
17 resolution_ = 255;
18#else
19#error "No supported DAC_ALIGN_xxx defined"
20#endif
21 // NOLINTEND
22
23 Write(init_voltage);
24 HAL_DAC_Start(hdac_, channel_);
25}
ErrorCode Write(float voltage) override
输出电压 / Output analog voltage
Definition stm32_dac.cpp:27

Member Function Documentation

◆ Write()

ErrorCode STM32DAC::Write ( float voltage)
overridevirtual

输出电压 / Output analog voltage

Parameters
voltage模拟电压值 / Analog voltage value
Returns
ErrorCode 错误码 / Error code

Implements LibXR::DAC.

Definition at line 27 of file stm32_dac.cpp.

28{
29 voltage = std::clamp(voltage, 0.0f, vref_);
30 return HAL_DAC_SetValue(
31 hdac_, channel_, align_,
32 static_cast<uint16_t>(voltage / vref_ * static_cast<float>(resolution_))) ==
33 HAL_OK
36}
@ FAILED
操作失败 / Operation failed
@ OK
操作成功 / Operation successful

The documentation for this class was generated from the following files: