PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
dac.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
52 /******************************************************************************/
53 /* Include files */
54 /******************************************************************************/
55 #include "dac.h"
56 
57 #if (defined(PDL_PERIPHERAL_DAC_ACTIVE))
58 
64 
65 /******************************************************************************/
66 /* Local pre-processor symbols/macros ('#define') */
67 /******************************************************************************/
68 
69 /******************************************************************************/
70 /* Global variable definitions (declared in header file with 'extern') */
71 /******************************************************************************/
72 
73 /******************************************************************************/
74 /* Local type definitions ('typedef') */
75 /******************************************************************************/
76 
77 /******************************************************************************/
78 /* Local function prototypes ('static') */
79 /******************************************************************************/
80 
81 /******************************************************************************/
82 /* Local variable definitions ('static') */
83 /******************************************************************************/
84 
85 /******************************************************************************/
86 /* Function implementation - global ('extern') and local ('static') */
87 /******************************************************************************/
88 
100  stc_dac_config_t* pstcConfig
101  )
102 {
103  // Check for NULL pointers
104  if ((pstcDac == NULL) ||
105  (pstcConfig == NULL)
106  )
107  {
108  return ErrorInvalidParameter;
109  }
110 
111  pstcDac->DACR0_f.DAC10 = (TRUE == pstcConfig->bDac12Bit0) ? 0u : 1u ;
112  pstcDac->DACR0_f.DAC10 = (TRUE == pstcConfig->bDac10RightAlign0) ? 1u : 0u ;
113  pstcDac->DACR1_f.DAC10 = (TRUE == pstcConfig->bDac12Bit1) ? 0u : 1u ;
114  pstcDac->DACR1_f.DAC10 = (TRUE == pstcConfig->bDac10RightAlign1) ? 1u : 0u ;
115 
116  return Ok;
117 } // Dac_Init
118 
129 {
130  // Check for NULL pointers
131  if (pstcDac == NULL)
132  {
133  return ErrorInvalidParameter;
134  }
135 
136  pstcDac->DACR0 = 0u;
137  pstcDac->DADR0 = 0u;
138  pstcDac->DACR1 = 0u;
139  pstcDac->DADR1 = 0u;
140 
141  return Ok;
142 } // Dac_DeInit
143 
154  uint16_t u16DacValue
155  )
156 {
157  pstcDac->DADR0_f.DA = u16DacValue;
158 
159  return Ok;
160 } // Dac_SetValue0
161 
162 
173  uint16_t u16DacValue
174  )
175 {
176  pstcDac->DADR1_f.DA = u16DacValue;
177 
178  return Ok;
179 } // Dac_SetValue1
180 
190 {
191  pstcDac->DACR0_f.DAE = 1u;
192 
193  return Ok;
194 } // Dac_Enable0
195 
205 {
206  pstcDac->DACR1_f.DAE = 1u;
207 
208  return Ok;
209 } // Dac_Enable1
210 
211 
221 {
222  pstcDac->DACR0_f.DAE = 0u;
223 
224  return Ok;
225 } // Dac_Disable0
226 
236 {
237  pstcDac->DACR1_f.DAE = 0u;
238 
239  return Ok;
240 } // Dac_Disable1
241 
242 
244 
245 #endif // #if (defined(PDL_PERIPHERAL_DAC_ACTIVE))
246 
247 /******************************************************************************/
248 /* EOF (not truncated) */
249 /******************************************************************************/