]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_idac.h
Add EFM32 Giant Gecko Starter Kit demo - still a work in progress as the low power...
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_idac.h
1 /***************************************************************************//**\r
2  * @file em_idac.h\r
3  * @brief Current Digital to Analog Converter (IDAC) peripheral API\r
4  * @version 4.0.0\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\r
10  * Permission is granted to anyone to use this software for any purpose,\r
11  * including commercial applications, and to alter it and redistribute it\r
12  * freely, subject to the following restrictions:\r
13  *\r
14  * 1. The origin of this software must not be misrepresented; you must not\r
15  *    claim that you wrote the original software.\r
16  * 2. Altered source versions must be plainly marked as such, and must not be\r
17  *    misrepresented as being the original software.\r
18  * 3. This notice may not be removed or altered from any source distribution.\r
19  *\r
20  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no\r
21  * obligation to support this Software. Silicon Labs is providing the\r
22  * Software "AS IS", with no express or implied warranties of any kind,\r
23  * including, but not limited to, any implied warranties of merchantability\r
24  * or fitness for any particular purpose or warranties against infringement\r
25  * of any proprietary rights of a third party.\r
26  *\r
27  * Silicon Labs will not be liable for any consequential, incidental, or\r
28  * special damages, or any other relief, or for any claim by any third party,\r
29  * arising from your use of this Software.\r
30  *\r
31  ******************************************************************************/\r
32 \r
33 \r
34 #ifndef __SILICON_LABS_EM_IDAC_H_\r
35 #define __SILICON_LABS_EM_IDAC_H_\r
36 \r
37 #include "em_device.h"\r
38 \r
39 #if defined(IDAC_COUNT) && (IDAC_COUNT > 0)\r
40 #include <stdbool.h>\r
41 \r
42 #ifdef __cplusplus\r
43 extern "C" {\r
44 #endif\r
45 \r
46 /***************************************************************************//**\r
47  * @addtogroup EM_Library\r
48  * @{\r
49  ******************************************************************************/\r
50 \r
51 /***************************************************************************//**\r
52  * @addtogroup IDAC\r
53  * @{\r
54  ******************************************************************************/\r
55 \r
56 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */\r
57 \r
58 /** Validation of IDAC register block pointer reference for assert statements. */\r
59 #define IDAC_REF_VALID(ref)    ((ref) == IDAC0)\r
60 \r
61 /** @endcond */\r
62 \r
63 /*******************************************************************************\r
64  ********************************   ENUMS   ************************************\r
65  ******************************************************************************/\r
66 \r
67 /** Output mode. */\r
68 typedef enum\r
69 {\r
70   idacOutputPin     = IDAC_CTRL_OUTMODE_PIN,     /**< Output to IDAC OUT pin */\r
71   idacOutputADC     = IDAC_CTRL_OUTMODE_ADC      /**< Output to ADC */\r
72 } IDAC_OutMode_TypeDef;\r
73 \r
74 \r
75 /** Selects which Peripheral Reflex System (PRS) signal to use when\r
76     PRS is set to control the IDAC output. */\r
77 typedef enum\r
78 {\r
79   idacPRSSELCh0 = IDAC_CTRL_PRSSEL_PRSCH0,      /**< PRS channel 0. */\r
80   idacPRSSELCh1 = IDAC_CTRL_PRSSEL_PRSCH1,      /**< PRS channel 1. */\r
81   idacPRSSELCh2 = IDAC_CTRL_PRSSEL_PRSCH2,      /**< PRS channel 2. */\r
82   idacPRSSELCh3 = IDAC_CTRL_PRSSEL_PRSCH3,      /**< PRS channel 3. */\r
83 #if  defined( IDAC_CTRL_PRSSEL_PRSCH4 )\r
84   idacPRSSELCh4 = IDAC_CTRL_PRSSEL_PRSCH4,      /**< PRS channel 4. */\r
85 #endif\r
86 #if  defined( IDAC_CTRL_PRSSEL_PRSCH5 )\r
87   idacPRSSELCh5 = IDAC_CTRL_PRSSEL_PRSCH5,      /**< PRS channel 5. */\r
88 #endif\r
89 #if  defined( IDAC_CTRL_PRSSEL_PRSCH6 )\r
90   idacPRSSELCh6 = IDAC_CTRL_PRSSEL_PRSCH6,      /**< PRS channel 6. */\r
91 #endif\r
92 #if  defined( IDAC_CTRL_PRSSEL_PRSCH7 )\r
93   idacPRSSELCh7 = IDAC_CTRL_PRSSEL_PRSCH7,      /**< PRS channel 7. */\r
94 #endif\r
95 #if  defined( IDAC_CTRL_PRSSEL_PRSCH8 )\r
96   idacPRSSELCh8 = IDAC_CTRL_PRSSEL_PRSCH8,      /**< PRS channel 8. */\r
97 #endif\r
98 #if  defined( IDAC_CTRL_PRSSEL_PRSCH9 )\r
99   idacPRSSELCh9 = IDAC_CTRL_PRSSEL_PRSCH9,      /**< PRS channel 9. */\r
100 #endif\r
101 #if  defined( IDAC_CTRL_PRSSEL_PRSCH10 )\r
102   idacPRSSELCh10 = IDAC_CTRL_PRSSEL_PRSCH10,    /**< PRS channel 10 */\r
103 #endif\r
104 #if  defined( IDAC_CTRL_PRSSEL_PRSCH11 )\r
105   idacPRSSELCh11 = IDAC_CTRL_PRSSEL_PRSCH11,    /**< PRS channel 11 */\r
106 #endif\r
107 } IDAC_PRSSEL_TypeDef;\r
108 \r
109 \r
110 /** Selects which current range to use. */\r
111 typedef enum\r
112 {\r
113   idacCurrentRange0 = IDAC_CURPROG_RANGESEL_RANGE0, /**< current range 0. */\r
114   idacCurrentRange1 = IDAC_CURPROG_RANGESEL_RANGE1, /**< current range 1. */\r
115   idacCurrentRange2 = IDAC_CURPROG_RANGESEL_RANGE2, /**< current range 2. */\r
116   idacCurrentRange3 = IDAC_CURPROG_RANGESEL_RANGE3, /**< current range 3. */\r
117 } IDAC_Range_TypeDef;\r
118 \r
119 /*******************************************************************************\r
120  *******************************   STRUCTS   ***********************************\r
121  ******************************************************************************/\r
122 \r
123 /** IDAC init structure, common for both channels. */\r
124 typedef struct\r
125 {\r
126   /** Enable IDAC. */\r
127   bool                  enable;\r
128 \r
129   /** Output mode */\r
130   IDAC_OutMode_TypeDef  outMode;\r
131 \r
132   /**\r
133    * Enable Peripheral reflex system (PRS) to control IDAC output. If false,\r
134    * the IDAC output is controlled by writing to IDAC_OUTEN in IDAC_CTRL or\r
135    * by calling IDAC_OutEnable().\r
136    */\r
137   bool                  prsEnable;\r
138 \r
139   /**\r
140    * Peripheral reflex system channel selection. Only applicable if @p prsEnable\r
141    * is enabled.\r
142    */\r
143   IDAC_PRSSEL_TypeDef   prsSel;\r
144 \r
145   /** Enable/disable current sink mode. */\r
146   bool                  sinkEnable;\r
147 \r
148 } IDAC_Init_TypeDef;\r
149 \r
150 /** Default config for IDAC init structure. */\r
151 #define IDAC_INIT_DEFAULT                                             \\r
152   { false,          /* Leave IDAC disabled when init done. */         \\r
153     idacOutputPin,   /* Output to IDAC OUT pin. */                     \\r
154     false,          /* Disable PRS triggering. */                     \\r
155     idacPRSSELCh0,  /* Select PRS ch0 (if PRS triggering enabled). */ \\r
156     false           /* Disable current sink mode. */                  \\r
157   }\r
158 \r
159 \r
160 /*******************************************************************************\r
161  *****************************   PROTOTYPES   **********************************\r
162  ******************************************************************************/\r
163 \r
164 /***************************************************************************//**\r
165  * @brief\r
166  *   Initialize IDAC.\r
167  *\r
168  * @details\r
169  *   Initializes IDAC according to the initialization structure parameter, and\r
170  *   sets the default calibration value stored in the DEVINFO structure.\r
171  *\r
172  * @note\r
173  *   This function will disable the IDAC prior to configuration.\r
174  *\r
175  * @param[in] idac\r
176  *   Pointer to IDAC peripheral register block.\r
177  *\r
178  * @param[in] init\r
179  *   Pointer to IDAC initialization structure.\r
180  ******************************************************************************/\r
181 void IDAC_Init(IDAC_TypeDef *idac, const IDAC_Init_TypeDef *init);\r
182 \r
183 \r
184 /***************************************************************************//**\r
185  * @brief\r
186  *   Enable/disable IDAC.\r
187  *\r
188  * @param[in] idac\r
189  *   Pointer to IDAC peripheral register block.\r
190  *\r
191  * @param[in] enable\r
192  *   true to enable IDAC, false to disable.\r
193  ******************************************************************************/\r
194 void IDAC_Enable(IDAC_TypeDef *idac, bool enable);\r
195 \r
196 \r
197 /***************************************************************************//**\r
198  * @brief\r
199  *   Reset IDAC to same state as after a HW reset.\r
200  *\r
201  * @param[in] idac\r
202  *   Pointer to IDAC peripheral register block.\r
203  ******************************************************************************/\r
204 void IDAC_Reset(IDAC_TypeDef *idac);\r
205 \r
206 \r
207 /***************************************************************************//**\r
208  * @brief\r
209  *   Enable/disable Minimal Output Transition mode.\r
210  *\r
211  * @param[in] idac\r
212  *   Pointer to IDAC peripheral register block.\r
213  *\r
214  * @param[in] enable\r
215  *   true to enable Minimal Output Transition mode, false to disable.\r
216  ******************************************************************************/\r
217 void IDAC_MinimalOutputTransitionMode(IDAC_TypeDef *idac, bool enable);\r
218 \r
219 \r
220 /***************************************************************************//**\r
221  * @brief\r
222  *   Set the current range of the IDAC output.\r
223  *\r
224  * @details\r
225  *   This function sets the current range of the IDAC output. The function\r
226  *   also updates the IDAC calibration register (IDAC_CAL) with the default\r
227  *   calibration value (from DEVINFO, factory setting) corresponding to the\r
228  *   specified range.\r
229  *\r
230  * @param[in] idac\r
231  *   Pointer to IDAC peripheral register block.\r
232  *\r
233  * @param[in] range\r
234  *   Current range value.\r
235  ******************************************************************************/\r
236 void IDAC_RangeSet(IDAC_TypeDef *idac, const IDAC_Range_TypeDef range);\r
237 \r
238 \r
239 /***************************************************************************//**\r
240  * @brief\r
241  *   Set the current step of the IDAC output.\r
242  *\r
243  * @param[in] idac\r
244  *   Pointer to IDAC peripheral register block.\r
245  *\r
246  * @param[in] step\r
247  *   Step value for IDAC output. Valid range is 0-31.\r
248  ******************************************************************************/\r
249 void IDAC_StepSet(IDAC_TypeDef *idac, const uint32_t step);\r
250 \r
251 \r
252 /***************************************************************************//**\r
253  * @brief\r
254  *   Enable/disable the IDAC OUT pin.\r
255  *\r
256  * @param[in] idac\r
257  *   Pointer to IDAC peripheral register block.\r
258  *\r
259  * @param[in] enable\r
260  *   true to enable the IDAC OUT pin, false to disable.\r
261  ******************************************************************************/\r
262 void IDAC_OutEnable(IDAC_TypeDef *idac, bool enable);\r
263 \r
264 \r
265 /** @} (end addtogroup IDAC) */\r
266 /** @} (end addtogroup EM_Library) */\r
267 \r
268 #ifdef __cplusplus\r
269 }\r
270 #endif\r
271 \r
272 #endif /* defined(IDAC_COUNT) && (IDAC_COUNT > 0) */\r
273 \r
274 #endif /* __SILICON_LABS_EM_IDAC_H_ */\r