Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
dac.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Libre Solar Technologies GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_DAC_H_
13#define ZEPHYR_INCLUDE_DRIVERS_DAC_H_
14
15#include <zephyr/device.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
41};
42
49/*
50 * Type definition of DAC API function for configuring a channel.
51 * See dac_channel_setup() for argument descriptions.
52 */
53typedef int (*dac_api_channel_setup)(const struct device *dev,
54 const struct dac_channel_cfg *channel_cfg);
55
56/*
57 * Type definition of DAC API function for setting a write request.
58 * See dac_write_value() for argument descriptions.
59 */
60typedef int (*dac_api_write_value)(const struct device *dev,
61 uint8_t channel, uint32_t value);
62
63/*
64 * DAC driver API
65 *
66 * This is the mandatory API any DAC driver needs to expose.
67 */
68__subsystem struct dac_driver_api {
69 dac_api_channel_setup channel_setup;
70 dac_api_write_value write_value;
71};
72
90__syscall int dac_channel_setup(const struct device *dev,
91 const struct dac_channel_cfg *channel_cfg);
92
93static inline int z_impl_dac_channel_setup(const struct device *dev,
94 const struct dac_channel_cfg *channel_cfg)
95{
96 const struct dac_driver_api *api =
97 (const struct dac_driver_api *)dev->api;
98
99 return api->channel_setup(dev, channel_cfg);
100}
101
112__syscall int dac_write_value(const struct device *dev, uint8_t channel,
113 uint32_t value);
114
115static inline int z_impl_dac_write_value(const struct device *dev,
116 uint8_t channel, uint32_t value)
117{
118 const struct dac_driver_api *api =
119 (const struct dac_driver_api *)dev->api;
120
121 return api->write_value(dev, channel, value);
122}
123
128#ifdef __cplusplus
129}
130#endif
131
132#include <syscalls/dac.h>
133
134#endif /* ZEPHYR_INCLUDE_DRIVERS_DAC_H_ */
int dac_write_value(const struct device *dev, uint8_t channel, uint32_t value)
Write a single value to a DAC channel.
int dac_channel_setup(const struct device *dev, const struct dac_channel_cfg *channel_cfg)
Configure a DAC channel.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Structure for specifying the configuration of a DAC channel.
Definition: dac.h:31
bool buffered
Enable output buffer for this channel.
Definition: dac.h:40
uint8_t channel_id
Channel identifier of the DAC that should be configured.
Definition: dac.h:33
uint8_t resolution
Desired resolution of the DAC (depends on device capabilities).
Definition: dac.h:35
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387