blob: 8c57095d3a77215d5da188df270dc0f569fe7079 (
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
|
/**************************************************************************//**
* @file adc.c
* @version V1.00
* $Revision: 13 $
* $Date: 14/05/29 1:13p $
* @brief NUC472/NUC442 ADC driver source file
*
* @note
* Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/
#include "NUC472_442.h"
/** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
@{
*/
/** @addtogroup NUC472_442_ADC_Driver ADC Driver
@{
*/
/** @addtogroup NUC472_442_ADC_EXPORTED_FUNCTIONS ADC Exported Functions
@{
*/
/**
* @brief This API configures ADC module to be ready for convert the input from selected channel
* @param[in] adc Base address of ADC module
* @param[in] u32InputMode Input mode (single-end/differential). Valid values are:
* - \ref ADC_INPUT_MODE_SINGLE_END
* - \ref ADC_INPUT_MODE_DIFFERENTIAL
* @param[in] u32OpMode Operation mode (single/single cycle/continuous). Valid values are:
* - \ref ADC_OPERATION_MODE_SINGLE
* - \ref ADC_OPERATION_MODE_SINGLE_CYCLE
* - \ref ADC_OPERATION_MODE_CONTINUOUS
* @param[in] u32ChMask Channel enable bit. Valid values are:
* - \ref ADC_CH_0_MASK
* - \ref ADC_CH_1_MASK
* - \ref ADC_CH_2_MASK
* - \ref ADC_CH_3_MASK
* - \ref ADC_CH_4_MASK
* - \ref ADC_CH_5_MASK
* - \ref ADC_CH_6_MASK
* - \ref ADC_CH_7_MASK
* - \ref ADC_CH_8_MASK
* - \ref ADC_CH_9_MASK
* - \ref ADC_CH_10_MASK
* - \ref ADC_CH_11_MASK
* - \ref ADC_CH_TS_MASK
* - \ref ADC_CH_BG_MASK
* @return None
* @note This API does not turn on ADC power nor does trigger ADC conversion
*/
void ADC_Open(ADC_T *adc,
uint32_t u32InputMode,
uint32_t u32OpMode,
uint32_t u32ChMask)
{
ADC->CTL |= u32InputMode;
ADC->CTL |= u32OpMode;
ADC->CHEN = (ADC->CHEN & ~(ADC_CHEN_CHEN_Msk | ADC_CHEN_ADBGEN_Msk | ADC_CHEN_ADTSEN_Msk)) | u32ChMask;
return;
}
/**
* @brief Disable ADC module
* @param[in] adc Base address of ADC module
* @return None
*/
void ADC_Close(ADC_T *adc)
{
SYS->IPRST1 |= SYS_IPRST1_ADCRST_Msk;
SYS->IPRST1 &= ~SYS_IPRST1_ADCRST_Msk;
return;
}
/**
* @brief Configure the hardware trigger condition and enable hardware trigger
* @param[in] adc Base address of ADC module
* @param[in] u32Source Decides the hardware trigger source. Valid values are:
* - \ref ADC_TRIGGER_BY_EXT_PIN
* - \ref ADC_TRIGGER_BY_PWM
* @param[in] u32Param While ADC trigger by PWM, this parameter is used to set the delay between PWM
* trigger and ADC conversion. Valid values are from 0 ~ 0xFF, and actual delay
* time is (4 * u32Param * HCLK). While ADC trigger by external pin, this parameter
* is used to set trigger condition. Valid values are:
* - \ref ADC_LOW_LEVEL_TRIGGER
* - \ref ADC_HIGH_LEVEL_TRIGGER
* - \ref ADC_FALLING_EDGE_TRIGGER
* - \ref ADC_RISING_EDGE_TRIGGER
* @return None
*/
void ADC_EnableHWTrigger(ADC_T *adc,
uint32_t u32Source,
uint32_t u32Param)
{
ADC->CTL &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_CTL_HWTRGEN_Msk);
if(u32Source == ADC_TRIGGER_BY_EXT_PIN) {
ADC->CTL &= ~(ADC_CTL_HWTRGSEL_Msk | ADC_CTL_HWTRGCOND_Msk);
ADC->CTL |= u32Source | u32Param | ADC_CTL_HWTRGEN_Msk;
} else {
ADC->CTL &= ~(ADC_CTL_HWTRGSEL_Msk | ADC_CTL_PWMTRGDLY_Msk);
ADC->CTL |= u32Source | (u32Param << ADC_CTL_PWMTRGDLY_Pos) | ADC_CTL_HWTRGEN_Msk;
}
return;
}
/**
* @brief Disable hardware trigger ADC function.
* @param[in] adc Base address of ADC module
* @return None
*/
void ADC_DisableHWTrigger(ADC_T *adc)
{
ADC->CTL &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_CTL_HWTRGEN_Msk);
return;
}
/**
* @brief Enable the interrupt(s) selected by u32Mask parameter.
* @param[in] adc Base address of ADC module
* @param[in] u32Mask The combination of interrupt status bits listed below. Each bit
* corresponds to a interrupt status. This parameter decides which
* interrupts will be enabled.
* - \ref ADC_ADF_INT
* - \ref ADC_CMP0_INT
* - \ref ADC_CMP1_INT
* @return None
*/
void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
{
if(u32Mask & ADC_ADF_INT)
ADC->CTL |= ADC_CTL_ADCIEN_Msk;
if(u32Mask & ADC_CMP0_INT)
ADC->CMP[0] |= ADC_CMP0_ADCMPIE_Msk;
if(u32Mask & ADC_CMP1_INT)
ADC->CMP[1] |= ADC_CMP1_ADCMPIE_Msk;
return;
}
/**
* @brief Disable the interrupt(s) selected by u32Mask parameter.
* @param[in] adc Base address of ADC module
* @param[in] u32Mask The combination of interrupt status bits listed below. Each bit
* corresponds to a interrupt status. This parameter decides which
* interrupts will be disabled.
* - \ref ADC_ADF_INT
* - \ref ADC_CMP0_INT
* - \ref ADC_CMP1_INT
* @return None
*/
void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
{
if(u32Mask & ADC_ADF_INT)
ADC->CTL &= ~ADC_CTL_ADCIEN_Msk;
if(u32Mask & ADC_CMP0_INT)
ADC->CMP[0] &= ~ADC_CMP0_ADCMPIE_Msk;
if(u32Mask & ADC_CMP1_INT)
ADC->CMP[1] &= ~ADC_CMP1_ADCMPIE_Msk;
return;
}
/*@}*/ /* end of group NUC472_442_ADC_EXPORTED_FUNCTIONS */
/*@}*/ /* end of group NUC472_442_ADC_Driver */
/*@}*/ /* end of group NUC472_442_Device_Driver */
/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
|