Class hal::dac
Digital to Analog Converter (DAC) hardware abstraction interface. More...
#include <dac.hpp>
Inherited by the following classes: hal::mock::dac, hal::soft::inert_dac
Classes
Type | Name |
---|---|
struct | write_t Feedback from writing a voltage to the dac. |
Public Functions
Type | Name |
---|---|
result< write_t > | write (float p_percentage) Set the output voltage of the DAC. |
virtual | ~dac () = default |
Detailed Description
Use this interface for devices and peripherals that can create arbitrary analog voltages between a defined Vss (negative reference) and Vcc (positive reference) voltage.
Public Functions Documentation
function write
Set the output voltage of the DAC.
inline result< write_t > hal::dac::write (
float p_percentage
)
The input value p_percentage
is a 32-bit floating point value from 0.0f to +1.0f.
The floating point value is linearly proportional to the output voltage relative to the Vss and Vcc such that if Vss is 0V (gnd) and Vcc is 5V then 0.0 is 0V, 0.25 is 1.25V, 0.445 is 2.225V and 1.0 is 5V.
This function clamps the input value between 0.0f and 1.0f and thus values passed to driver implementations are guaranteed to be within this range. Callers of this function do not need to clamp their values before passing them into this function as it would be redundant. The rationale for doing this at the interface layer is that it allows callers and driver implementors to omit redundant clamping code, reducing code bloat.
Parameters:
p_percentage
- value from 0.0f to +1.0f representing the proportion of the output voltage from the Vss to Vcc.
Returns:
result<write_t> - success or failure
function ~dac
virtual hal::dac::~dac () = default
The documentation for this class was generated from the following file libraries/include/libhal/dac.hpp