Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
196 | killagreg | 1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
1 | ingob | 2 | * File Name : 91x_adc.c |
3 | * Author : MCD Application Team |
||
196 | killagreg | 4 | * Version : V2.1 |
5 | * Date : 12/22/2008 |
||
6 | * Description : This file provides all the ADC firmware functions. |
||
1 | ingob | 7 | ******************************************************************************** |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
||
9 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
||
10 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
||
11 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
||
12 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
||
13 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
14 | *******************************************************************************/ |
||
15 | |||
16 | |||
17 | /* Standard include ----------------------------------------------------------*/ |
||
18 | #include "91x_adc.h" |
||
19 | #include "91x_scu.h" |
||
20 | /* Include of other module interface headers ---------------------------------*/ |
||
21 | /* Local includes ------------------------------------------------------------*/ |
||
22 | /* Private typedef -----------------------------------------------------------*/ |
||
23 | /* Private define ------------------------------------------------------------*/ |
||
24 | |||
25 | /* ADC mask */ |
||
26 | #define ADC_FLAG_MASK 0x001F /* ADC Flag Mask */ |
||
27 | #define ADC_RESULT_MASK 0x03FF /* ADC Result Mask */ |
||
28 | #define ADC_SCAN_MODE_MASK 0x0020 /* ADC Sacn Mode Mask */ |
||
29 | #define ADC_STANDBY_MODE_MASK 0x0008 /* ADC Standby Mode Mask */ |
||
30 | #define ADC_CMD_MASK 0x0002 /* ADC Command Mask */ |
||
31 | #define ADC_CHANNEL_MASK 0xFE3F /* ADC Channel Select Mask */ |
||
32 | /* Private macro -------------------------------------------------------------*/ |
||
33 | /* Private variables ---------------------------------------------------------*/ |
||
34 | /* Private function prototypes -----------------------------------------------*/ |
||
35 | /* Interface functions -------------------------------------------------------*/ |
||
36 | /* Private functions ---------------------------------------------------------*/ |
||
37 | |||
38 | /******************************************************************************* |
||
39 | * Function Name : ADC_DeInit |
||
40 | * Description : Deinitialize the ADC module registers to their default reset |
||
41 | * values |
||
42 | * Input : None |
||
43 | * Output : None |
||
44 | * Return : None |
||
45 | *******************************************************************************/ |
||
46 | void ADC_DeInit(void) |
||
47 | { |
||
48 | /* Reset the ADC registers values */ |
||
49 | SCU_APBPeriphReset(__ADC,ENABLE); |
||
50 | SCU_APBPeriphReset(__ADC,DISABLE); |
||
51 | } |
||
52 | |||
53 | /******************************************************************************* |
||
54 | * Function Name : ADC_Init |
||
55 | * Description : Initializes ADC peripheral according to the specified |
||
56 | * parameters in the ADC_InitTypeDef structure. |
||
57 | * Input : ADC_InitStruct: pointer to a ADC_InitTypeDef structure that |
||
58 | * contains the configuration information for the specified |
||
59 | * ADC peripheral. |
||
60 | * Output : None |
||
61 | * Return : None |
||
62 | *******************************************************************************/ |
||
63 | void ADC_Init(ADC_InitTypeDef* ADC_InitStruct) |
||
64 | { |
||
65 | /* Set the low threshold of the watchdog */ |
||
66 | ADC->LTR = ADC_InitStruct->ADC_WDG_Low_Threshold; |
||
67 | |||
68 | /* Set the high threshold of the watchdog */ |
||
69 | ADC->HTR = ADC_InitStruct->ADC_WDG_High_Threshold; |
||
70 | |||
71 | |||
72 | /* Channel 0 conversion mode */ |
||
73 | ADC->CCR &= 0xFFFC; |
||
74 | ADC->CCR |= ADC_InitStruct->ADC_Channel_0_Mode; |
||
75 | |||
76 | /* Channel 1 conversion mode */ |
||
77 | ADC->CCR &= 0xFFF3; |
||
78 | ADC->CCR |= ADC_InitStruct->ADC_Channel_1_Mode << 0x2; |
||
79 | |||
80 | /* Channel 2 conversion mode */ |
||
81 | ADC->CCR &= 0xFFCF; |
||
82 | ADC->CCR |= ADC_InitStruct->ADC_Channel_2_Mode << 0x4; |
||
83 | |||
84 | /* Channel 3 conversion mode */ |
||
85 | ADC->CCR &= 0xFF3F; |
||
86 | ADC->CCR |= ADC_InitStruct->ADC_Channel_3_Mode << 0x6; |
||
87 | |||
88 | /* Channel 4 conversion mode */ |
||
89 | ADC->CCR &= 0xFCFF; |
||
90 | ADC->CCR |= ADC_InitStruct->ADC_Channel_4_Mode << 0x8; |
||
91 | |||
92 | /* Channel 5 conversion mode */ |
||
93 | ADC->CCR &= 0xF3FF; |
||
94 | ADC->CCR |= ADC_InitStruct->ADC_Channel_5_Mode << 0xA; |
||
95 | |||
96 | /* Channel 6 conversion mode */ |
||
97 | ADC->CCR &= 0xCFFF; |
||
98 | ADC->CCR |= ADC_InitStruct->ADC_Channel_6_Mode << 0xC; |
||
99 | |||
100 | /* Channel 7 conversion mode */ |
||
101 | ADC->CCR &= 0x3FFF; |
||
102 | ADC->CCR |= ADC_InitStruct->ADC_Channel_7_Mode << 0xE; |
||
103 | |||
104 | /* Select the channel to be converted */ |
||
105 | ADC->CR &= ADC_CHANNEL_MASK; |
||
106 | ADC->CR |= ADC_InitStruct->ADC_Select_Channel << 0x6; |
||
107 | |||
108 | /* Enable/disable the scan mode */ |
||
109 | if (ADC_InitStruct->ADC_Scan_Mode == ENABLE) |
||
110 | { |
||
111 | /* Enable the scan mode */ |
||
112 | ADC->CR |= ADC_SCAN_MODE_MASK; |
||
113 | } |
||
114 | else |
||
115 | { |
||
116 | /* Disable the scan mode */ |
||
117 | ADC->CR &= ~ADC_SCAN_MODE_MASK; |
||
118 | } |
||
119 | |||
120 | /* Configure the conversion mode */ |
||
121 | if (ADC_InitStruct->ADC_Conversion_Mode == ADC_Continuous_Mode) |
||
122 | { |
||
123 | /* ADC continuous mode */ |
||
124 | ADC->CR |= ADC_Continuous_Mode; |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | /* ADC single mode */ |
||
129 | ADC->CR &= ADC_Single_Mode; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | /******************************************************************************* |
||
134 | * Function Name : ADC_StructInit |
||
135 | * Description : Fills each ADC_InitStruct member with its reset value. |
||
136 | * Input : ADC_InitStruct : pointer to a ADC_InitTypeDef structure |
||
137 | * which will be initialized. |
||
138 | * Output : None |
||
139 | * Return : None. |
||
140 | *******************************************************************************/ |
||
141 | void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct) |
||
142 | { |
||
143 | ADC_InitStruct->ADC_WDG_High_Threshold = 0x0000; |
||
144 | ADC_InitStruct->ADC_WDG_Low_Threshold = 0x0000; |
||
145 | ADC_InitStruct->ADC_Channel_0_Mode = ADC_No_Conversion; |
||
146 | ADC_InitStruct->ADC_Channel_1_Mode = ADC_No_Conversion; |
||
147 | ADC_InitStruct->ADC_Channel_2_Mode = ADC_No_Conversion; |
||
148 | ADC_InitStruct->ADC_Channel_3_Mode = ADC_No_Conversion; |
||
149 | ADC_InitStruct->ADC_Channel_4_Mode = ADC_No_Conversion; |
||
150 | ADC_InitStruct->ADC_Channel_5_Mode = ADC_No_Conversion; |
||
151 | ADC_InitStruct->ADC_Channel_6_Mode = ADC_No_Conversion; |
||
152 | ADC_InitStruct->ADC_Channel_7_Mode = ADC_No_Conversion; |
||
153 | ADC_InitStruct->ADC_Select_Channel = ADC_Channel_0; |
||
154 | ADC_InitStruct->ADC_Scan_Mode = DISABLE; |
||
155 | ADC_InitStruct->ADC_Conversion_Mode = ADC_Single_Mode; |
||
156 | } |
||
157 | |||
158 | /******************************************************************************* |
||
159 | * Function Name : ADC_PrescalerConfig |
||
160 | * Description : This routine is used to configure the ADC prescaler value. |
||
161 | * Input : ADC_Prescaler: specifies the prescaler value. This parameter |
||
162 | * can be a value from 0x0 to 0xFF. |
||
163 | * Output : None |
||
164 | * Return : None |
||
165 | *******************************************************************************/ |
||
166 | void ADC_PrescalerConfig(u8 ADC_Prescaler) |
||
167 | { |
||
168 | ADC->PRS &= 0xFF00; |
||
169 | ADC->PRS |= ADC_Prescaler; |
||
170 | |||
171 | } |
||
172 | /******************************************************************************* |
||
173 | * Function Name : ADC_GetPrescalerValue |
||
174 | * Description : This routine is used to get the ADC prescaler value. |
||
175 | * Input : None |
||
176 | * Output : None |
||
177 | * Return : The prescaler value. |
||
178 | *******************************************************************************/ |
||
179 | u8 ADC_GetPrescalerValue(void) |
||
180 | { |
||
181 | return ADC->PRS & 0x00FF; |
||
182 | } |
||
183 | /******************************************************************************* |
||
184 | * Function Name : ADC_GetFlagStatus |
||
185 | * Description : Checks whether the specified ADC flag is set or not. |
||
186 | * Input : ADC_Flag: flag to check. |
||
187 | * This parameter can be one of the following values: |
||
188 | * - ADC_FLAG_OV_CH_0: Conversion overflow status for |
||
189 | * channel 0. |
||
190 | * - ADC_FLAG_OV_CH_1: Conversion overflow status for |
||
191 | * channel 1. |
||
192 | * - ADC_FLAG_OV_CH_2: Conversion overflow status for |
||
193 | * channel 2. |
||
194 | * - ADC_FLAG_OV_CH_3: Conversion overflow status for |
||
195 | * channel 3. |
||
196 | * - ADC_FLAG_OV_CH_4: Conversion overflow status for |
||
197 | * channel 4. |
||
198 | * - ADC_FLAG_OV_CH_5: Conversion overflow status for |
||
199 | * channel 5. |
||
200 | * - ADC_FLAG_OV_CH_6: Conversion overflow status for |
||
201 | * channel 6. |
||
202 | * - ADC_FLAG_OV_CH_7: Conversion overflow status for |
||
203 | * channel 7. |
||
204 | * - ADC_FLAG_ECV: End of conversion status. |
||
205 | * - ADC_FLAG_AWD: Analog watchdog status. |
||
206 | * Output : None |
||
207 | * Return : The NewState of the ADC_Flag (SET or RESET). |
||
208 | *******************************************************************************/ |
||
209 | FlagStatus ADC_GetFlagStatus(u16 ADC_Flag) |
||
210 | { |
||
211 | u8 AdcReg = 0, FlagPos = 0; |
||
212 | |||
213 | /* Get the ADC register index */ |
||
214 | AdcReg = ADC_Flag >> 5; |
||
215 | |||
216 | /* Get the flag position */ |
||
217 | FlagPos = ADC_Flag & ADC_FLAG_MASK; |
||
218 | |||
219 | if(AdcReg == 1) /* The flag to check is in CR register */ |
||
220 | { |
||
221 | if((ADC->CR & (1<<FlagPos))!= RESET) |
||
222 | { |
||
223 | return SET; |
||
224 | } |
||
225 | else |
||
226 | { |
||
227 | return RESET; |
||
228 | } |
||
229 | } |
||
230 | else if(AdcReg == 6) /* The flag to check is in DR0 register */ |
||
231 | { |
||
232 | if((ADC->DR0 & (1<<FlagPos))!= RESET) |
||
233 | { |
||
234 | return SET; |
||
235 | } |
||
236 | else |
||
237 | { |
||
238 | return RESET; |
||
239 | } |
||
240 | } |
||
241 | else if(AdcReg == 7) /* The flag to check is in DR1 register */ |
||
242 | { |
||
243 | if((ADC->DR1 & (1<<FlagPos))!= RESET) |
||
244 | { |
||
245 | return SET; |
||
246 | } |
||
247 | else |
||
248 | { |
||
249 | return RESET; |
||
250 | } |
||
251 | } |
||
252 | else if(AdcReg == 8) /* The flag to check is in DR2 register */ |
||
253 | { |
||
254 | if((ADC->DR2 & (1<<FlagPos))!= RESET) |
||
255 | { |
||
256 | return SET; |
||
257 | } |
||
258 | else |
||
259 | { |
||
260 | return RESET; |
||
261 | } |
||
262 | } |
||
263 | else if(AdcReg == 9) /* The flag to check is in DR3 register */ |
||
264 | { |
||
265 | if((ADC->DR3 & (1<<FlagPos))!= RESET) |
||
266 | { |
||
267 | return SET; |
||
268 | } |
||
269 | else |
||
270 | { |
||
271 | return RESET; |
||
272 | } |
||
273 | } |
||
274 | |||
275 | else if(AdcReg == 0xA) /* The flag to check is in DR4 register */ |
||
276 | { |
||
277 | if((ADC->DR4 & (1<<FlagPos))!= RESET) |
||
278 | { |
||
279 | return SET; |
||
280 | } |
||
281 | else |
||
282 | { |
||
283 | return RESET; |
||
284 | } |
||
285 | } |
||
286 | else if(AdcReg == 0xB) /* The flag to check is in DR5 register */ |
||
287 | { |
||
288 | if((ADC->DR5 & (1<<FlagPos))!= RESET) |
||
289 | { |
||
290 | return SET; |
||
291 | } |
||
292 | else |
||
293 | { |
||
294 | return RESET; |
||
295 | } |
||
296 | } |
||
297 | else if(AdcReg == 0xC) /* The flag to check is in DR6 register */ |
||
298 | { |
||
299 | if((ADC->DR6 & (1<<FlagPos))!= RESET) |
||
300 | { |
||
301 | return SET; |
||
302 | } |
||
303 | else |
||
304 | { |
||
305 | return RESET; |
||
306 | } |
||
307 | } |
||
308 | else /* (AdcReg == 0xD), The flag to check is in DR7 register */ |
||
309 | { |
||
310 | if((ADC->DR7 & (1<<FlagPos))!= RESET) |
||
311 | { |
||
312 | return SET; |
||
313 | } |
||
314 | else |
||
315 | { |
||
316 | return RESET; |
||
317 | } |
||
318 | } |
||
319 | } |
||
320 | |||
321 | /******************************************************************************* |
||
322 | * Function Name : ADC_ClearFlag |
||
323 | * Description : Clears the ADC Flag passed as a parameter. |
||
324 | * Input : ADC_Flag: flag to clear. |
||
325 | * This parameter can be one of the following values: |
||
326 | * - ADC_FLAG_ECV: End of conversion status. |
||
327 | * - ADC_FLAG_AWD: Analog watchdog status. |
||
328 | * Output : None |
||
329 | * Return : None |
||
330 | *******************************************************************************/ |
||
331 | void ADC_ClearFlag(u16 ADC_Flag) |
||
332 | { |
||
196 | killagreg | 333 | vu16 tmp=0; |
1 | ingob | 334 | /* Clear the correspondent flag */ |
196 | killagreg | 335 | if (ADC_Flag==ADC_FLAG_ORD) |
336 | tmp = ADC->DDR; |
||
337 | else |
||
338 | ADC->CR |= (1<<(ADC_Flag & ADC_FLAG_MASK)); |
||
1 | ingob | 339 | } |
340 | |||
341 | /******************************************************************************* |
||
342 | * Function Name : ADC_GetConversionValue |
||
343 | * Description : Read the result of conversion from the appropriate data |
||
344 | * register. |
||
345 | * Input : ADC_Channel: the correspondent channel of the ADC peripheral. |
||
346 | * This parameter can be one of the following values: |
||
347 | * - ADC_Channel_0: ADC channel 0. |
||
348 | * - ADC_Channel_1: ADC channel 1. |
||
349 | * - ADC_Channel_2: ADC channel 2. |
||
350 | * - ADC_Channel_3: ADC channel 3. |
||
351 | * - ADC_Channel_4: ADC channel 4. |
||
352 | * - ADC_Channel_5: ADC channel 5. |
||
353 | * - ADC_Channel_6: ADC channel 6. |
||
354 | * - ADC_Channel_7: ADC channel 7. |
||
355 | * Output : None |
||
356 | * Return : The result of the conversion for the specific channel. |
||
357 | *******************************************************************************/ |
||
358 | u16 ADC_GetConversionValue(u16 ADC_Channel) |
||
359 | { |
||
360 | u16 ADC_Conversion_Value = 0; |
||
361 | |||
362 | switch (ADC_Channel) |
||
363 | { |
||
364 | case (ADC_Channel_0): |
||
365 | /* Get the conversion value of the channel 0 */ |
||
366 | ADC_Conversion_Value = ADC->DR0 & ADC_RESULT_MASK; |
||
367 | break; |
||
368 | |||
369 | case (ADC_Channel_1): |
||
370 | /* Get the conversion value of the channel 1 */ |
||
371 | ADC_Conversion_Value = ADC->DR1 & ADC_RESULT_MASK; |
||
372 | break; |
||
373 | |||
374 | case (ADC_Channel_2): |
||
375 | /* Get the conversion value of the channel 2 */ |
||
376 | ADC_Conversion_Value = ADC->DR2 & ADC_RESULT_MASK; |
||
377 | break; |
||
378 | |||
379 | case (ADC_Channel_3): |
||
380 | /* Get the conversion value of the channel 3 */ |
||
381 | ADC_Conversion_Value = ADC->DR3 & ADC_RESULT_MASK; |
||
382 | break; |
||
383 | |||
384 | case (ADC_Channel_4): |
||
385 | /* Get the conversion value of the channel 4 */ |
||
386 | ADC_Conversion_Value = ADC->DR4 & ADC_RESULT_MASK; |
||
387 | break; |
||
388 | |||
389 | case (ADC_Channel_5): |
||
390 | /* Get the conversion value of the channel 5 */ |
||
391 | ADC_Conversion_Value = ADC->DR5 & ADC_RESULT_MASK; |
||
392 | break; |
||
393 | |||
394 | case (ADC_Channel_6): |
||
395 | /* Get the conversion value of the channel 6 */ |
||
396 | ADC_Conversion_Value = ADC->DR6 & ADC_RESULT_MASK; |
||
397 | break; |
||
398 | |||
399 | case (ADC_Channel_7): |
||
400 | /* Get the conversion value of the channel 7 */ |
||
401 | ADC_Conversion_Value = ADC->DR7 & ADC_RESULT_MASK; |
||
402 | break; |
||
403 | |||
404 | default: |
||
405 | break; |
||
406 | } |
||
407 | |||
408 | return(ADC_Conversion_Value); |
||
409 | } |
||
410 | |||
411 | /******************************************************************************* |
||
412 | * Function Name : ADC_GetAnalogWatchdogResult |
||
413 | * Description : Return the result of the comparaison on the selected Analog |
||
414 | * Watchdog. |
||
415 | * Input : ADC_Channel: the correspondent channel of the ADC peripheral. |
||
416 | * This parameter can be one of the following values: |
||
417 | * - ADC_Channel_0: ADC channel 0. |
||
418 | * - ADC_Channel_1: ADC channel 1. |
||
419 | * - ADC_Channel_2: ADC channel 2. |
||
420 | * - ADC_Channel_3: ADC channel 3. |
||
421 | * - ADC_Channel_4: ADC channel 4. |
||
422 | * - ADC_Channel_5: ADC channel 5. |
||
423 | * - ADC_Channel_6: ADC channel 6. |
||
424 | * - ADC_Channel_7: ADC channel 7. |
||
425 | * Output : None |
||
426 | * Return : The state of the comparision (SET or RESET). |
||
427 | *******************************************************************************/ |
||
428 | FlagStatus ADC_GetAnalogWatchdogResult(u16 ADC_Channel) |
||
429 | { |
||
196 | killagreg | 430 | if ((ADC->CRR & (1<<ADC_Channel)) != RESET) |
1 | ingob | 431 | { |
432 | return SET; |
||
433 | } |
||
434 | else |
||
435 | { |
||
436 | return RESET; |
||
437 | } |
||
438 | } |
||
439 | |||
440 | /******************************************************************************* |
||
441 | * Function Name : ADC_ClearAnalogWatchdogResult |
||
442 | * Description : Clear the result of the comparaison on the selected Analog |
||
443 | * Watchdog. |
||
444 | * Input : ADC_Channel: the correspondent channel of the ADC peripheral. |
||
445 | * This parameter can be one of the following values: |
||
446 | * - ADC_Channel_0: ADC channel 0. |
||
447 | * - ADC_Channel_1: ADC channel 1. |
||
448 | * - ADC_Channel_2: ADC channel 2. |
||
449 | * - ADC_Channel_3: ADC channel 3. |
||
450 | * - ADC_Channel_4: ADC channel 4. |
||
451 | * - ADC_Channel_5: ADC channel 5. |
||
452 | * - ADC_Channel_6: ADC channel 6. |
||
453 | * - ADC_Channel_7: ADC channel 7. |
||
454 | * Output : None |
||
455 | * Return : None |
||
456 | *******************************************************************************/ |
||
457 | void ADC_ClearAnalogWatchdogResult(u16 ADC_Channel) |
||
458 | { |
||
459 | /* Clear the correspondent watchdog result */ |
||
460 | ADC->CRR = 1<<ADC_Channel; |
||
461 | } |
||
462 | |||
463 | /******************************************************************************* |
||
464 | * Function Name : ADC_GetWatchdogThreshold |
||
465 | * Description : Get the higher/lower thresholds values of the watchdog. |
||
466 | * Input : ADC_Threshold: the lower or the higher threshold. |
||
467 | * This parameter can be one of the following values: |
||
468 | * - ADC_HigherThreshold: The higher threshold. |
||
469 | * - ADC_LowerThreshold: The lower threshold. |
||
470 | * Output : None |
||
471 | * Return : The selected threshold value. |
||
472 | *******************************************************************************/ |
||
473 | u16 ADC_GetWatchdogThreshold(ADC_ThresholdType ADC_Threshold) |
||
474 | { |
||
475 | u16 ADC_Threshold_Value = 0; |
||
476 | |||
477 | switch (ADC_Threshold) |
||
478 | { |
||
479 | case ADC_LowThreshold: |
||
480 | /* Get the low threshold of the watchdog */ |
||
481 | ADC_Threshold_Value = ADC->LTR; |
||
482 | break; |
||
483 | |||
484 | case ADC_HighThreshold: |
||
485 | /* Get the high threshol of the watchdog */ |
||
486 | ADC_Threshold_Value = ADC->HTR; |
||
487 | break; |
||
488 | |||
489 | default: |
||
490 | break; |
||
491 | } |
||
492 | |||
493 | return(ADC_Threshold_Value); |
||
494 | } |
||
495 | |||
496 | /******************************************************************************* |
||
497 | * Function Name : ADC_ITConfig |
||
498 | * Description : Enables or disables the specified ADC interrupts. |
||
499 | * Input : - ADC_IT: specifies the ADC interrupts sources to be enabled |
||
500 | * or disabled. |
||
501 | * This parameter can be one of the following values: |
||
502 | * - ADC_IT_EndOfConversion: End of conversion interrupt. |
||
503 | * - ADC_IT_AnalogWDG: Analog watchdog interrupt. |
||
504 | * - ADC_NewState: new state of the specified ADC interrupts. |
||
505 | * (ADC_Newstate can be ENABLE or DISABLE). |
||
506 | * Output : None |
||
507 | * Return : None |
||
508 | *******************************************************************************/ |
||
509 | void ADC_ITConfig(u16 ADC_IT, FunctionalState ADC_NewState) |
||
510 | { |
||
196 | killagreg | 511 | if (ADC_IT==ADC_IT_ORD) |
1 | ingob | 512 | { |
196 | killagreg | 513 | if (ADC_NewState == ENABLE) |
514 | |||
1 | ingob | 515 | /* Enable the interrupt */ |
196 | killagreg | 516 | ADC->CR2 |= ADC_IT; |
517 | |||
518 | else |
||
519 | |||
520 | /* Disable the interrupt */ |
||
521 | ADC->CR2 &= ~ADC_IT; |
||
522 | |||
523 | } |
||
524 | else{ |
||
525 | |||
526 | if (ADC_NewState == ENABLE) |
||
527 | |||
528 | /* Enable the interrupt */ |
||
1 | ingob | 529 | ADC->CR |= ADC_IT; |
196 | killagreg | 530 | |
1 | ingob | 531 | else |
196 | killagreg | 532 | |
1 | ingob | 533 | /* Disable the interrupt */ |
534 | ADC->CR &= ~ADC_IT; |
||
196 | killagreg | 535 | |
1 | ingob | 536 | } |
196 | killagreg | 537 | } |
1 | ingob | 538 | |
539 | /******************************************************************************* |
||
540 | * Function Name : ADC_StandbyModeCmd |
||
541 | * Description : Enable or disable the standby mode. |
||
542 | * Input : ADC_NewState: new state of the ADC standby mode. |
||
543 | * (ADC_Newstate can be ENABLE or DISABLE). |
||
544 | * Output : None |
||
545 | * Return : None |
||
546 | *******************************************************************************/ |
||
547 | void ADC_StandbyModeCmd(FunctionalState ADC_NewState) |
||
548 | { |
||
549 | if (ADC_NewState == ENABLE) |
||
550 | { |
||
551 | /* Enable the standby mode */ |
||
552 | ADC->CR |= ADC_STANDBY_MODE_MASK; |
||
553 | } |
||
554 | else |
||
555 | { |
||
556 | /* Disable the standby mode */ |
||
557 | ADC->CR &= ~ADC_STANDBY_MODE_MASK; |
||
558 | } |
||
559 | } |
||
560 | |||
561 | /******************************************************************************* |
||
562 | * Function Name : ADC_Cmd |
||
563 | * Description : Power on or put in reset mode the ADC peripheral. |
||
564 | * Input : ADC_NewState: new state of the ADC peripheral. |
||
565 | * (ADC_Newstate can be ENABLE or DISABLE). |
||
566 | * Output : None |
||
567 | * Return : None |
||
568 | *******************************************************************************/ |
||
569 | void ADC_Cmd(FunctionalState ADC_NewState) |
||
570 | { |
||
571 | if (ADC_NewState == ENABLE) |
||
572 | { |
||
573 | /* Enable the ADC */ |
||
574 | ADC->CR |= ADC_CMD_MASK; |
||
575 | } |
||
576 | else |
||
577 | { |
||
578 | /* Disable the ADC */ |
||
579 | ADC->CR &= ~ADC_CMD_MASK; |
||
580 | } |
||
581 | } |
||
582 | |||
583 | /******************************************************************************* |
||
584 | * Function Name : ADC_ConversionCmd |
||
585 | * Description : Start or stop the ADC conversion in the selected mode. |
||
586 | * Input : ADC_Conversion: the conversion command. |
||
587 | * This parameter can be one of the following values: |
||
588 | * - ADC_Conversion_Start: Start the conversion. |
||
589 | * - ADC_Conversion_Stop: Stop the Conversion. |
||
590 | * Output : None |
||
591 | * Return : None |
||
592 | *******************************************************************************/ |
||
593 | void ADC_ConversionCmd(u16 ADC_Conversion) |
||
594 | { |
||
595 | if (ADC_Conversion == ADC_Conversion_Start) |
||
596 | { |
||
597 | /* Start the ADC conversion */ |
||
598 | ADC->CR |= ADC_Conversion_Start; |
||
599 | } |
||
600 | else |
||
601 | { |
||
602 | /* Stop the ADC conversion */ |
||
603 | ADC->CR &= ADC_Conversion_Stop; |
||
604 | } |
||
605 | } |
||
196 | killagreg | 606 | /******************************************************************************* |
607 | * Function Name : ADC_ExternalTrigConfig |
||
608 | * Description : source and edge selection of external trigg |
||
609 | * Input : -ADC_ExtTrig_Src |
||
610 | * This parameter can be one of the following values: |
||
611 | * ADC_PWM_Trig : PWM Trigger |
||
612 | * ADC_TIM_Trig : Timer Trigger |
||
613 | * ADC_PIN_Trig : External Trigger Pin |
||
614 | * |
||
615 | * -ADC_ExtTrig_Edge |
||
616 | * This parameter can be one of the following values: |
||
617 | * Falling_ETE :Falling edge |
||
618 | * Rising_ETE :Rising edge |
||
619 | * Output : None |
||
620 | * Return : None |
||
621 | *******************************************************************************/ |
||
1 | ingob | 622 | |
196 | killagreg | 623 | void ADC_ExternalTrigConfig(u16 ADC_ExtTrig_Src , u16 ADC_ExtTrig_Edge) |
624 | { |
||
625 | ADC->CR2 &= 0x3C; |
||
626 | ADC->CR2 |= ADC_ExtTrig_Src; |
||
627 | |||
628 | if (ADC_ExtTrig_Edge== Falling_ETE) |
||
629 | ADC->CR2 |= 0x20; |
||
630 | else |
||
631 | ADC->CR2 &=~0x20; ; |
||
632 | |||
633 | } |
||
634 | /******************************************************************************* |
||
635 | * Function Name : ADC_ExternalTrigCmd |
||
636 | * Description : Enable or disable the external trigg feature. |
||
637 | * Input : ADC_NewState: Can be ENABLE or DISABLE |
||
638 | * Output : None |
||
639 | * Return : None |
||
640 | *******************************************************************************/ |
||
641 | |||
642 | void ADC_ExternalTrigCmd(FunctionalState ADC_NewState) |
||
643 | { |
||
644 | if (ADC_NewState==ENABLE) |
||
645 | ADC->CR2 |= 0x04; |
||
646 | else |
||
647 | ADC->CR2 &=~0x04; |
||
648 | |||
649 | } |
||
650 | /******************************************************************************* |
||
651 | * Function Name : ADC_DMACmd |
||
652 | * Description : Enable or disable the DMA request for ADC |
||
653 | * Input : ADC_NewState: Can be ENABLE or DISABLE |
||
654 | * Output : None |
||
655 | * Return : None |
||
656 | *******************************************************************************/ |
||
657 | |||
658 | void ADC_DMACmd(FunctionalState ADC_NewState) |
||
659 | { |
||
660 | if (ADC_NewState==ENABLE) |
||
661 | ADC->CR2 |= 0x08; |
||
662 | else |
||
663 | ADC->CR2 &=~0x08; |
||
664 | } |
||
665 | |||
666 | /******************************************************************************* |
||
667 | * Function Name : ADC_AutomaticClockGatedCmd |
||
668 | * Description : Enables or disables the Automatic clock gated mode for Fast |
||
669 | * Trigger mode (only in Rev H). |
||
670 | * Input : ADC_NewState: Can be ENABLE or DISABLE |
||
671 | * Output : None |
||
672 | * Return : None |
||
673 | *******************************************************************************/ |
||
674 | |||
675 | void ADC_AutomaticClockGatedCmd(FunctionalState ADC_NewState) |
||
676 | { |
||
677 | if (ADC_NewState==ENABLE) |
||
678 | SCU->GPIOANA |= 0x100; |
||
679 | else |
||
680 | SCU->GPIOANA &=~0x100; |
||
681 | } |
||
682 | |||
683 | |||
684 | /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ |