aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/inc/fsl_dac_driver.h
blob: 65ce73ed02a1c868cb22300010ef27030d70013b (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_DAC_DRIVER_H__
#define __FSL_DAC_DRIVER_H__

#include <stdint.h>
#include <stdbool.h>
#include "fsl_dac_hal.h"

#if FSL_FEATURE_SOC_DAC_COUNT

/*!
 * @addtogroup dac_driver
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*!
 * @brief Defines the type of event flags.
 */
typedef enum _dac_flag_t
{
#if FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
    kDacBuffIndexWatermarkFlag = 0U, /*!< Event for the buffer index hit the watermark. */
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
    kDacBuffIndexStartFlag = 1U, /*!< Event for the buffer index hit the start (0). */
    kDacBuffIndexUpperFlag = 2U /*!< Event for the buffer index hit the upper. */
} dac_flag_t;

/*! @brief Table of base addresses for DAC instances. */
extern DAC_Type * const g_dacBase[];

/*! @brief Table to save DAC IRQ enumeration numbers defined in the CMSIS header file. */
extern const IRQn_Type g_dacIrqId[DAC_INSTANCE_COUNT];

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Populates the initial user configuration for the DAC module without interrupt and buffer features. 
 *
 * This function  populates the initial user configuration 
 * without interrupt and buffer features. Calling the initialization
 * function with the populated parameter configures the DAC module to operate as
 * a simple converter. The settings are:\n
 *
 * \li.refVoltSrcMode = kDacRefVoltSrcOfVref2; // Vdda
 * \li.triggerMode = kDacTriggerBySoftware;
 * \li.lowPowerEnable = false;
 *
 * @param userConfigPtr Pointer to the user configuration structure. See the "dac_user_config_t".
 * @return Execution status.
 */
dac_status_t DAC_DRV_StructInitUserConfigNormal(dac_converter_config_t *userConfigPtr);

/*!
 * @brief Initializes the converter. 
 *
 * This function initializes the converter. 
 *
 * @param instance DAC instance ID.
 * @param userConfigPtr Pointer to the initialization structure. See the "dac_user_config_t".
 * @return Execution status.
 */
dac_status_t DAC_DRV_Init(uint32_t instance, const dac_converter_config_t *userConfigPtr);

/*!
 * @brief De-initializes the DAC module converter.
 *
 * This function de-initializes the converter. It disables the
 * DAC module and shuts down the clock to reduce the power consumption. 
 *
 * @param instance DAC instance ID.
 * @return Execution status.
 */
dac_status_t DAC_DRV_Deinit(uint32_t instance);

/*!
 * @brief Drives the converter to output the DAC value.
 *
 * This function drives the converter to output the DAC value. It forces
 * the buffer index to be the first one and load the setting value to this item. 
 * Then, the converter outputs the voltage indicated by the indicated value
 * immediately. 
 *
 * @param instance DAC instance ID.
 * @param value Setting value for DAC.
 */
void DAC_DRV_Output(uint32_t instance, uint16_t value);

/*!
 * @brief Configures the internal buffer.
 *
 * This function configures the feature of the internal buffer for the DAC module.
 * By default, the buffer feature  is disabled. Calling this API enables
 * the buffer and configures it.
 *
 * @param instance DAC instance ID.
 * @param configPtr Pointer to the configuration structure. See the "dac_buff_config_t".
 * @return Execution status.
 */
dac_status_t DAC_DRV_ConfigBuffer(uint32_t instance, const dac_buffer_config_t *configPtr);

/*!
 * @brief Sets values into the DAC internal buffer.
 *
 * This function  sets values into the DAC internal buffer. Note that the buffer
 * size is defined by the  "FSL_FEATURE_DAC_BUFFER_SIZE" macro and the available
 * value is 12 bit.
 *
 * @param instance DAC instance ID.
 * @param start Start index of setting values.
 * @param offset Length of setting values' array.
 * @param arr Setting values' array.
 * @return Execution status.
 */
dac_status_t DAC_DRV_SetBuffValue(uint32_t instance, uint8_t start, uint8_t offset, uint16_t arr[]);

/*!
 * @brief Triggers the buffer by software and returns the current value.
 *
 * This function triggers the buffer by software and returns the current
 * value. After it is triggered, the buffer index  updates according to work mode.
 * Then, the value kept inside the pointed item  is immediately output.
 *
 * @param instance DAC instance ID.
 */
void DAC_DRV_SoftTriggerBuffCmd(uint32_t instance);

/*!
 * @brief Clears the flag for an indicated event causing an interrupt.
 *
 * This function clears the flag for an indicated event causing an interrupt.
 *
 * @param instance DAC instance ID.
 * @param flag Indicated flag. See "dac_flag_t".
 */
void DAC_DRV_ClearBuffFlag(uint32_t instance, dac_flag_t flag);

/*!
 * @brief Gets the flag for an indicated event causing an interrupt.
 *
 * This function gets the flag for an indicated event causing an interrupt.
 * If the event occurs, the return value is asserted.
 *
 * @param instance DAC instance ID.
 * @param flag Indicated flag. See "dac_flag_t".
 * @return Assertion of indicated event.
 */
bool DAC_DRV_GetBuffFlag(uint32_t instance, dac_flag_t flag);

/*!
 * @brief Sets the current read pointer in DAC buffer.
 *
 * This function sets the current read pointer in DAC buffer.
 *
 * @param instance DAC instance ID.
 * @param idx Index for read pointer in buffer.
 */
void DAC_DRV_SetBuffCurIdx(uint32_t instance, uint8_t idx);

/*!
 * @brief Gets the current read pointer in the DAC buffer.
 *
 * This function gets the current read pointer in DAC buffer.
 *
 * @param instance DAC instance ID.
 * @return Index for current read pointer in buffer.
 */
uint8_t DAC_DRV_GetBuffCurIdx(uint32_t instance);

#if defined(__cplusplus)
}
#endif

/*!
 *@}
 */

#endif /* __FSL_DAC_DRIVER_H__ */

/******************************************************************************
 * EOF
 *****************************************************************************/

#endif