Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_DAC_H_
14#define ZEPHYR_INCLUDE_DRIVERS_DAC_H_
15
16#include <zephyr/device.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
35
40#define DAC_CHANNEL_BROADCAST 0xFF
41
54 bool buffered: 1;
59 bool internal: 1;
60};
61
67
68/*
69 * Type definition of DAC API function for configuring a channel.
70 * See dac_channel_setup() for argument descriptions.
71 */
72typedef int (*dac_api_channel_setup)(const struct device *dev,
73 const struct dac_channel_cfg *channel_cfg);
74
75/*
76 * Type definition of DAC API function for setting a write request.
77 * See dac_write_value() for argument descriptions.
78 */
79typedef int (*dac_api_write_value)(const struct device *dev,
80 uint8_t channel, uint32_t value);
81
82/*
83 * DAC driver API
84 *
85 * This is the mandatory API any DAC driver needs to expose.
86 */
87__subsystem struct dac_driver_api {
88 dac_api_channel_setup channel_setup;
89 dac_api_write_value write_value;
90};
91
95
109__syscall int dac_channel_setup(const struct device *dev,
110 const struct dac_channel_cfg *channel_cfg);
111
112static inline int z_impl_dac_channel_setup(const struct device *dev,
113 const struct dac_channel_cfg *channel_cfg)
114{
115 const struct dac_driver_api *api =
116 (const struct dac_driver_api *)dev->api;
117
118 return api->channel_setup(dev, channel_cfg);
119}
120
131__syscall int dac_write_value(const struct device *dev, uint8_t channel,
132 uint32_t value);
133
134static inline int z_impl_dac_write_value(const struct device *dev,
135 uint8_t channel, uint32_t value)
136{
137 const struct dac_driver_api *api =
138 (const struct dac_driver_api *)dev->api;
139
140 return api->write_value(dev, channel, value);
141}
142
146
147#ifdef __cplusplus
148}
149#endif
150
151#include <zephyr/syscalls/dac.h>
152
153#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:45
bool buffered
Enable output buffer for this channel.
Definition dac.h:54
uint8_t channel_id
Channel identifier of the DAC that should be configured.
Definition dac.h:47
uint8_t resolution
Desired resolution of the DAC (depends on device capabilities).
Definition dac.h:49
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519