Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /*
* Copyright (c) 2020 Libre Solar Technologies GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief DAC public API header file.
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_DAC_H_
#define ZEPHYR_INCLUDE_DRIVERS_DAC_H_
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief DAC driver APIs
* @defgroup dac_interface DAC driver APIs
* @ingroup io_interfaces
* @{
*/
/**
* @struct dac_channel_cfg
* @brief Structure for specifying the configuration of a DAC channel.
*
* @param channel_id Channel identifier of the DAC that should be configured.
* @param resolution Desired resolution of the DAC (depends on device
* capabilities).
*/
struct dac_channel_cfg {
uint8_t channel_id;
uint8_t resolution;
};
/**
* @cond INTERNAL_HIDDEN
*
* For internal use only, skip these in public documentation.
*/
/*
* Type definition of DAC API function for configuring a channel.
* See dac_channel_setup() for argument descriptions.
*/
typedef int (*dac_api_channel_setup)(const struct device *dev,
const struct dac_channel_cfg *channel_cfg);
/*
* Type definition of DAC API function for setting a write request.
* See dac_write_value() for argument descriptions.
*/
typedef int (*dac_api_write_value)(const struct device *dev,
uint8_t channel, uint32_t value);
/*
* DAC driver API
*
* This is the mandatory API any DAC driver needs to expose.
*/
__subsystem struct dac_driver_api {
dac_api_channel_setup channel_setup;
dac_api_write_value write_value;
};
/**
* @endcond
*/
/**
* @brief Configure a DAC channel.
*
* It is required to call this function and configure each channel before it is
* selected for a write request.
*
* @param dev Pointer to the device structure for the driver instance.
* @param channel_cfg Channel configuration.
*
* @retval 0 On success.
* @retval -EINVAL If a parameter with an invalid value has been provided.
* @retval -ENOTSUP If the requested resolution is not supported.
*/
__syscall int dac_channel_setup(const struct device *dev,
const struct dac_channel_cfg *channel_cfg);
static inline int z_impl_dac_channel_setup(const struct device *dev,
const struct dac_channel_cfg *channel_cfg)
{
const struct dac_driver_api *api =
(const struct dac_driver_api *)dev->api;
return api->channel_setup(dev, channel_cfg);
}
/**
* @brief Write a single value to a DAC channel
*
* @param dev Pointer to the device structure for the driver instance.
* @param channel Number of the channel to be used.
* @param value Data to be written to DAC output registers.
*
* @retval 0 On success.
* @retval -EINVAL If a parameter with an invalid value has been provided.
*/
__syscall int dac_write_value(const struct device *dev, uint8_t channel,
uint32_t value);
static inline int z_impl_dac_write_value(const struct device *dev,
uint8_t channel, uint32_t value)
{
const struct dac_driver_api *api =
(const struct dac_driver_api *)dev->api;
return api->write_value(dev, channel, value);
}
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#include <syscalls/dac.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_DAC_H_ */
|