DAC peripheral driver interface. More...
DAC peripheral driver interface.
Similar to the ADC driver interface (ADC), the DAC interface uses the concept of lines, corresponds to a tuple of a DAC device and a DAC output channel.
The DAC interface expects data to be served as a 16-bit unsigned integer, independent of the actual resolution of the hardware device. It is up to the DAC driver, to scale the given value to the maximal width that can be handled. The device driver should, on the other hand, implement the DAC in a way, that it will use the bit width, that comes closest to 16-bit.
This kind of 'auto-scaling' is quite sufficient for this interface, as standard DAC peripherals use a fixed conversion resolution internally anyway, so that any particular bit-width configuration on this driver level would not have much effect...
The configured DAC peripherals are active (and consume power) from the point of initialization. When calling dac_poweroff(), the implementation should disable the given DAC line and put the DAC peripheral to sleep (e.g. through peripheral clock gating). When woken up again through dac_poweron(), the given DAC line should transparently continue it's previous operation.
The DAC driver implementation may need to block (and free) certain power modes in the driver's dac_init(), dac_poweron(), and the dac_poweroff() functions.
Files | |
file | dac.h |
DAC peripheral driver interface definition. | |
Macros | |
#define | DAC_UNDEF (UINT_MAX) |
Default DAC undefined value. | |
#define | DAC_LINE(x) (x) |
Default DAC access macro. | |
Typedefs | |
typedef unsigned int | dac_t |
Define default DAC type identifier. | |
Enumerations | |
enum | { DAC_OK = 0, DAC_NOLINE = -1 } |
Return codes used by the DAC driver interface. | |
Functions | |
int8_t | dac_init (dac_t line) |
Initialize the given DAC line. More... | |
void | dac_set (dac_t line, uint16_t value) |
Write a value onto DAC Device on a given Channel. More... | |
void | dac_poweron (dac_t line) |
Enable the given DAC line. More... | |
void | dac_poweroff (dac_t line) |
Disable the given DAC line. More... | |
int8_t dac_init | ( | dac_t | line | ) |
Initialize the given DAC line.
After initialization, the corresponding DAC line is active and its output is set to 0.
[in] | line | DAC line to initialize |
void dac_poweroff | ( | dac_t | line | ) |
Disable the given DAC line.
[in] | line | DAC line to power off |
void dac_poweron | ( | dac_t | line | ) |
Enable the given DAC line.
[in] | line | DAC line to power on |
void dac_set | ( | dac_t | line, |
uint16_t | value | ||
) |
Write a value onto DAC Device on a given Channel.
The value is always given as 16-bit value and is internally scaled to the actual resolution that the DAC unit provides (e.g. 12-bit). So to get the maximum output voltage, this function has to be called with value
set to 65535 (UINT16_MAX).
[in] | line | DAC line to set |
[in] | value | value to set line to |