|
Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
|
Interfaces for Digital-to-Analog Converters. More...
Topics | |
| Device-specific DAC API extensions | |
Files | |
| file | dac.h |
| Main header file for DAC (Digital-to-Analog Converter) driver API. | |
Data Structures | |
| struct | dac_channel_cfg |
| Structure for specifying the configuration of a DAC channel. More... | |
| struct | dac_dt_spec |
| Container for DAC channel information specified in devicetree. More... | |
Macros | |
| #define | DAC_CHANNEL_BROADCAST 0xFF |
| Broadcast channel identifier for DACs that support it. | |
| #define | DAC_CHANNEL_CFG_DT(node_id) |
| Get DAC channel configuration from a given devicetree node. | |
| #define | DAC_DT_SPEC_GET_BY_NAME(node_id, name) |
| Get DAC io-channel information from devicetree by name. | |
| #define | DAC_DT_SPEC_GET_BY_NAME_OR(node_id, name, default_value) |
| Like DAC_DT_SPEC_GET_BY_NAME(), with a fallback to a default value. | |
| #define | DAC_DT_SPEC_INST_GET_BY_NAME(inst, name) |
| Get DAC io-channel information from a DT_DRV_COMPAT devicetree instance by name. | |
| #define | DAC_DT_SPEC_INST_GET_BY_NAME_OR(inst, name, default_value) |
| Like DAC_DT_SPEC_INST_GET_BY_NAME(), with a fallback to a default value. | |
| #define | DAC_DT_SPEC_GET_BY_IDX(node_id, idx) |
| Get DAC io-channel information from devicetree. | |
| #define | DAC_DT_SPEC_GET_BY_IDX_OR(node_id, idx, default_value) |
| Like DAC_DT_SPEC_GET_BY_IDX(), with a fallback to a default value. | |
| #define | DAC_DT_SPEC_INST_GET_BY_IDX(inst, idx) |
| Get DAC io-channel information from a DT_DRV_COMPAT devicetree instance. | |
| #define | DAC_DT_SPEC_INST_GET_BY_IDX_OR(inst, idx, default_value) |
| Like DAC_DT_SPEC_INST_GET_BY_IDX(), with a fallback to a default value. | |
| #define | DAC_DT_SPEC_GET(node_id) |
| Equivalent to DAC_DT_SPEC_GET_BY_IDX(node_id, 0). | |
| #define | DAC_DT_SPEC_GET_OR(node_id, default_value) |
| Equivalent to DAC_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value). | |
| #define | DAC_DT_SPEC_INST_GET(inst) |
| Equivalent to DAC_DT_SPEC_INST_GET_BY_IDX(inst, 0). | |
| #define | DAC_DT_SPEC_INST_GET_OR(inst, default_value) |
| Equivalent to DAC_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default). | |
Typedefs | |
| typedef int(* | dac_x_to_raw_fn) (uint32_t ref_mv, uint8_t resolution, uint32_t *valp) |
| Conversion from specified input units to raw DAC units. | |
Functions | |
| int | dac_channel_setup (const struct device *dev, const struct dac_channel_cfg *channel_cfg) |
| Configure a DAC channel. | |
| static int | dac_channel_setup_dt (const struct dac_dt_spec *spec) |
| Configure an DAC channel from a struct dac_dt_spec. | |
| int | dac_write_value (const struct device *dev, uint8_t channel, uint32_t value) |
| Write a single value to a DAC channel. | |
| static int | dac_write_value_dt (const struct dac_dt_spec *spec, uint32_t value) |
| Write a single value to a DAC channel from a struct dac_dt_spec. | |
| static int | dac_millivolts_to_raw (uint32_t ref_mv, uint8_t resolution, uint32_t *valp) |
| Convert a millivolts value to a raw DAC value. | |
| static int | dac_microvolts_to_raw (uint32_t ref_mv, uint8_t resolution, uint32_t *valp) |
| Convert a raw DAC value to microvolts. | |
| static int | dac_x_to_raw_dt_chan (dac_x_to_raw_fn conv_func, const struct dac_dt_spec *spec, uint32_t *valp) |
| Convert a raw DAC value to an arbitrary output unit. | |
| static int | dac_millivolts_to_raw_dt (const struct dac_dt_spec *spec, uint32_t *valp) |
| Convert a millivolts value to raw DAC using information stored in a struct dac_dt_spec. | |
| static int | dac_microvolts_to_raw_dt (const struct dac_dt_spec *spec, uint32_t *valp) |
| Convert a microvolts value to raw DAC value using information stored in a struct dac_dt_spec. | |
| static bool | dac_is_ready_dt (const struct dac_dt_spec *spec) |
| Validate that the DAC device is ready. | |
Interfaces for Digital-to-Analog Converters.
| #define DAC_CHANNEL_BROADCAST 0xFF |
#include <zephyr/drivers/dac.h>
Broadcast channel identifier for DACs that support it.
| #define DAC_CHANNEL_CFG_DT | ( | node_id | ) |
#include <zephyr/drivers/dac.h>
Get DAC channel configuration from a given devicetree node.
This returns a static initializer for a struct dac_channel_cfg filled with data from a given devicetree node.
Example devicetree fragment:
Example usage:
| node_id | Devicetree node identifier. |
| #define DAC_DT_SPEC_GET | ( | node_id | ) |
#include <zephyr/drivers/dac.h>
Equivalent to DAC_DT_SPEC_GET_BY_IDX(node_id, 0).
| node_id | Devicetree node identifier. |
| #define DAC_DT_SPEC_GET_BY_IDX | ( | node_id, | |
| idx ) |
#include <zephyr/drivers/dac.h>
Get DAC io-channel information from devicetree.
This returns a static initializer for an dac_dt_spec structure given a devicetree node and a channel index. The node must have the "io-channels" property defined.
Example devicetree fragment:
Example usage:
| node_id | Devicetree node identifier. |
| idx | Channel index. |
| #define DAC_DT_SPEC_GET_BY_IDX_OR | ( | node_id, | |
| idx, | |||
| default_value ) |
#include <zephyr/drivers/dac.h>
Like DAC_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
| node_id | Devicetree node identifier. |
| idx | Channel index. |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist.| #define DAC_DT_SPEC_GET_BY_NAME | ( | node_id, | |
| name ) |
#include <zephyr/drivers/dac.h>
Get DAC io-channel information from devicetree by name.
This returns a static initializer for an dac_dt_spec structure given a devicetree node and a channel name. The node must have the "io-channels" property defined.
Example devicetree fragment:
Example usage:
| node_id | Devicetree node identifier. |
| name | Channel name. |
| #define DAC_DT_SPEC_GET_BY_NAME_OR | ( | node_id, | |
| name, | |||
| default_value ) |
#include <zephyr/drivers/dac.h>
Like DAC_DT_SPEC_GET_BY_NAME(), with a fallback to a default value.
| node_id | Devicetree node identifier. |
| name | Channel name. |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist.| #define DAC_DT_SPEC_GET_OR | ( | node_id, | |
| default_value ) |
#include <zephyr/drivers/dac.h>
Equivalent to DAC_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value).
| node_id | Devicetree node identifier. |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist. | #define DAC_DT_SPEC_INST_GET | ( | inst | ) |
#include <zephyr/drivers/dac.h>
Equivalent to DAC_DT_SPEC_INST_GET_BY_IDX(inst, 0).
| inst | DT_DRV_COMPAT instance number |
| #define DAC_DT_SPEC_INST_GET_BY_IDX | ( | inst, | |
| idx ) |
#include <zephyr/drivers/dac.h>
Get DAC io-channel information from a DT_DRV_COMPAT devicetree instance.
| inst | DT_DRV_COMPAT instance number |
| idx | Channel index. |
| #define DAC_DT_SPEC_INST_GET_BY_IDX_OR | ( | inst, | |
| idx, | |||
| default_value ) |
#include <zephyr/drivers/dac.h>
Like DAC_DT_SPEC_INST_GET_BY_IDX(), with a fallback to a default value.
| inst | DT_DRV_COMPAT instance number |
| idx | Channel index. |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist.| #define DAC_DT_SPEC_INST_GET_BY_NAME | ( | inst, | |
| name ) |
#include <zephyr/drivers/dac.h>
Get DAC io-channel information from a DT_DRV_COMPAT devicetree instance by name.
| inst | DT_DRV_COMPAT instance number |
| name | Channel name. |
| #define DAC_DT_SPEC_INST_GET_BY_NAME_OR | ( | inst, | |
| name, | |||
| default_value ) |
#include <zephyr/drivers/dac.h>
Like DAC_DT_SPEC_INST_GET_BY_NAME(), with a fallback to a default value.
| inst | DT_DRV_COMPAT instance number |
| name | Channel name. |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist.| #define DAC_DT_SPEC_INST_GET_OR | ( | inst, | |
| default_value ) |
#include <zephyr/drivers/dac.h>
Equivalent to DAC_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default).
| inst | DT_DRV_COMPAT instance number |
| default_value | Fallback value to expand to. |
default_value if the node or property do not exist. #include <zephyr/drivers/dac.h>
Conversion from specified input units to raw DAC units.
This function performs the necessary conversion to transform a physical voltage to a raw DAC value.
| ref_mv | the reference voltage used for the value, in millivolts. |
| resolution | the number of bits in the absolute value of the output. |
| valp | pointer to the physical voltage value on input, and the corresponding raw output value on successful conversion. If conversion fails the stored value is left unchanged. |
| 0 | on successful conversion |
| int dac_channel_setup | ( | const struct device * | dev, |
| const struct dac_channel_cfg * | channel_cfg ) |
#include <zephyr/drivers/dac.h>
Configure a DAC channel.
It is required to call this function and configure each channel before it is selected for a write request.
| dev | Pointer to the device structure for the driver instance. |
| channel_cfg | Channel configuration. |
| 0 | On success. |
| -EINVAL | If a parameter with an invalid value has been provided. |
| -ENOTSUP | If the requested resolution is not supported. |
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Configure an DAC channel from a struct dac_dt_spec.
| spec | DAC specification from Devicetree. |
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Validate that the DAC device is ready.
| spec | DAC specification from devicetree |
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Convert a microvolts value to raw DAC value using information stored in a struct dac_dt_spec.
| [in] | spec | DAC specification from Devicetree. |
| [in,out] | valp | Pointer to the raw measurement value on input, and the corresponding microvolt value on successful conversion. If conversion fails the stored value is left unchanged. |
#include <zephyr/drivers/dac.h>
Convert a millivolts value to a raw DAC value.
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Convert a millivolts value to raw DAC using information stored in a struct dac_dt_spec.
| [in] | spec | DAC specification from Devicetree. |
| [in,out] | valp | Pointer to the raw measurement value on input, and the corresponding millivolt value on successful conversion. If conversion fails the stored value is left unchanged. |
#include <zephyr/drivers/dac.h>
Write a single value to a DAC channel.
| dev | Pointer to the device structure for the driver instance. |
| channel | Number of the channel to be used. |
| value | Data to be written to DAC output registers. |
| 0 | On success. |
| -EINVAL | If a parameter with an invalid value has been provided. |
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Write a single value to a DAC channel from a struct dac_dt_spec.
| spec | DAC specification from Devicetree. |
| value | Data to be written to DAC output registers. |
|
inlinestatic |
#include <zephyr/drivers/dac.h>
Convert a raw DAC value to an arbitrary output unit.
| [in] | conv_func | Function that converts to the final output unit. |
| [in] | spec | DAC specification from Devicetree. |
| [in,out] | valp | pointer to the physical voltage value on input, and the corresponding raw output value on successful conversion. If conversion fails the stored value is left unchanged. |