Mbed OS Reference
Loading...
Searching...
No Matches
analogout_api.h
1
2/** \addtogroup hal */
3/** @{*/
4/* mbed Microcontroller Library
5 * Copyright (c) 2006-2013 ARM Limited
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#ifndef MBED_ANALOGOUT_API_H
21#define MBED_ANALOGOUT_API_H
22
23#include "device.h"
24#include "pinmap.h"
25
26#if DEVICE_ANALOGOUT
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/** Analogout hal structure. dac_s is declared in the target's hal
33 */
34typedef struct dac_s dac_t;
35
36/**
37 * \defgroup hal_analogout Analogout hal functions
38 *
39 * # Defined behaviour
40 * * The function ::analogout_init initializes the dac_t control structure
41 * * The function ::analogout_write sets the output voltage, specified as a percentage (float) in range [0.0 (GND), 1.0 (VCC)]
42 * * The function ::analogout_write_u16 sets the output voltage, specified as unsigned 16-bit value [0 (GND), MAX_UINT16 (VCC)]
43 * * The function ::analogout_read reads the current voltage value on the pin and returns a floating-point value representing the current voltage in range [0.0 (GND), 1.0 (VCC)]
44 * * The function ::analogout_read_u16 reads the current voltage value on the pin and returns the output voltage, specified as unsigned 16-bit value [0 (GND), MAX_UINT16 (VCC)]
45 * * The accuracy of the DAC is +/- 10%
46 * * The DAC operations ::analogout_write, ::analogout_write_u16, ::analogout_read, ::analogout_read_u16 take less than 20us to complete
47 * * The function ::analogout_free releases the analogout object
48 *
49 * # Undefined behaviour
50 *
51 * * ::analogout_init is called with invalid pin (which does not support analog output function)
52 * * Calling other functions before ::analogout_init
53 * @{
54 */
55
56/** Initialize the analogout peripheral
57 *
58 * Configures the pin used by analogout.
59 * @param obj The analogout object to initialize
60 * @param pinmap pointer to structure which holds static pinmap
61 */
62void analogout_init_direct(dac_t *obj, const PinMap *pinmap);
63
64/** Initialize the analogout peripheral
65 *
66 * Configures the pin used by analogout.
67 * @param obj The analogout object to initialize
68 * @param pin The analogout pin name
69 */
70void analogout_init(dac_t *obj, PinName pin);
71
72/** Release the analogout object
73 *
74 * @param obj The analogout object
75 */
77
78/** Set the output voltage, specified as a percentage (float)
79 *
80 * @param obj The analogin object
81 * @param value The floating-point output voltage to be set
82 */
83void analogout_write(dac_t *obj, float value);
84
85/** Set the output voltage, specified as unsigned 16-bit
86 *
87 * @param obj The analogin object
88 * @param value The unsigned 16-bit output voltage to be set
89 */
90void analogout_write_u16(dac_t *obj, uint16_t value);
91
92/** Read the current voltage value on the pin
93 *
94 * @param obj The analogin object
95 * @return A floating-point value representing the current voltage on the pin,
96 * measured as a percentage
97 */
99
100/** Read the current voltage value on the pin, as a normalized unsigned 16bit value
101 *
102 * @param obj The analogin object
103 * @return An unsigned 16-bit value representing the current voltage on the pin
104 */
106
107/** Get the pins that support analogout
108 *
109 * Return a PinMap array of pins that support analogout. The
110 * array is terminated with {NC, NC, 0}.
111 *
112 * @return PinMap array
113 */
115
116/**@}*/
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif
123
124#endif
125
126/** @}*/
void analogout_write(dac_t *obj, float value)
Set the output voltage, specified as a percentage (float)
void analogout_init(dac_t *obj, PinName pin)
Initialize the analogout peripheral.
void analogout_init_direct(dac_t *obj, const PinMap *pinmap)
Initialize the analogout peripheral.
uint16_t analogout_read_u16(dac_t *obj)
Read the current voltage value on the pin, as a normalized unsigned 16bit value.
const PinMap * analogout_pinmap(void)
Get the pins that support analogout.
void analogout_write_u16(dac_t *obj, uint16_t value)
Set the output voltage, specified as unsigned 16-bit.
void analogout_free(dac_t *obj)
Release the analogout object.
float analogout_read(dac_t *obj)
Read the current voltage value on the pin.
struct dac_s dac_t
Analogout hal structure.
Definition: analogout_api.h:34
Definition: pinmap.h:31