uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_adc.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_ADC_H_
28 #define LPC17XX_ADC_H_
29 
30 /* Includes ------------------------------------------------------------------- */
31 #include "LPC17xx.h"
32 #include "lpc_types.h"
33 
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 /* Private macros ------------------------------------------------------------- */
45 /* -------------------------- BIT DEFINITIONS ----------------------------------- */
46 /*********************************************************************/
50 #define ADC_CR_CH_SEL(n) ((1UL << n))
51 
53 #define ADC_CR_CLKDIV(n) ((n<<8))
54 
55 #define ADC_CR_BURST ((1UL<<16))
56 
57 #define ADC_CR_PDN ((1UL<<21))
58 
59 #define ADC_CR_START_MASK ((7UL<<24))
60 
61 #define ADC_CR_START_MODE_SEL(SEL) ((SEL<<24))
62 
63 #define ADC_CR_START_NOW ((1UL<<24))
64 
65 #define ADC_CR_START_EINT0 ((2UL<<24))
66 
67 #define ADC_CR_START_CAP01 ((3UL<<24))
68 
69 #define ADC_CR_START_MAT01 ((4UL<<24))
70 
71 #define ADC_CR_START_MAT03 ((5UL<<24))
72 
73 #define ADC_CR_START_MAT10 ((6UL<<24))
74 
75 #define ADC_CR_START_MAT11 ((7UL<<24))
76 
77 #define ADC_CR_EDGE ((1UL<<27))
78 
79 /*********************************************************************/
83 #define ADC_GDR_RESULT(n) (((n>>4)&0xFFF))
84 
85 #define ADC_GDR_CH(n) (((n>>24)&0x7))
86 
88 #define ADC_GDR_OVERRUN_FLAG ((1UL<<30))
89 
90 #define ADC_GDR_DONE_FLAG ((1UL<<31))
91 
93 #define ADC_GDR_CH_MASK ((7UL<<24))
94 /*********************************************************************/
99 #define ADC_INTEN_CH(n) ((1UL<<n))
100 
101 #define ADC_INTEN_GLOBAL ((1UL<<8))
102 
103 /*********************************************************************/
107 #define ADC_DR_RESULT(n) (((n>>4)&0xFFF))
108 
110 #define ADC_DR_OVERRUN_FLAG ((1UL<<30))
111 
113 #define ADC_DR_DONE_FLAG ((1UL<<31))
114 
115 /*********************************************************************/
120 #define ADC_STAT_CH_DONE_FLAG(n) ((n&0xFF))
121 
123 #define ADC_STAT_CH_OVERRUN_FLAG(n) (((n>>8)&0xFF))
124 
125 #define ADC_STAT_INT_FLAG ((1UL<<16))
126 
127 /*********************************************************************/
131 #define ADC_ADCOFFS(n) (((n&0xF)<<4))
132 
133 #define ADC_TRIM(n) (((n&0xF)<<8))
134 
135 /* ------------------- CHECK PARAM DEFINITIONS ------------------------- */
137 #define PARAM_ADCx(n) (((uint32_t *)n)==((uint32_t *)LPC_ADC))
138 
140 #define PARAM_ADC_START_ON_EDGE_OPT(OPT) ((OPT == ADC_START_ON_RISING)||(OPT == ADC_START_ON_FALLING))
141 
143 #define PARAM_ADC_DATA_STATUS(OPT) ((OPT== ADC_DATA_BURST)||(OPT== ADC_DATA_DONE))
144 
146 #define PARAM_ADC_RATE(rate) ((rate>0)&&(rate<=200000))
147 
149 #define PARAM_ADC_CHANNEL_SELECTION(SEL) ((SEL == ADC_CHANNEL_0)||(ADC_CHANNEL_1)\
150 ||(SEL == ADC_CHANNEL_2)|(ADC_CHANNEL_3)\
151 ||(SEL == ADC_CHANNEL_4)||(ADC_CHANNEL_5)\
152 ||(SEL == ADC_CHANNEL_6)||(ADC_CHANNEL_7))
153 
155 #define PARAM_ADC_START_OPT(OPT) ((OPT == ADC_START_CONTINUOUS)||(OPT == ADC_START_NOW)\
156 ||(OPT == ADC_START_ON_EINT0)||(OPT == ADC_START_ON_CAP01)\
157 ||(OPT == ADC_START_ON_MAT01)||(OPT == ADC_START_ON_MAT03)\
158 ||(OPT == ADC_START_ON_MAT10)||(OPT == ADC_START_ON_MAT11))
159 
161 #define PARAM_ADC_TYPE_INT_OPT(OPT) ((OPT == ADC_ADINTEN0)||(OPT == ADC_ADINTEN1)\
162 ||(OPT == ADC_ADINTEN2)||(OPT == ADC_ADINTEN3)\
163 ||(OPT == ADC_ADINTEN4)||(OPT == ADC_ADINTEN5)\
164 ||(OPT == ADC_ADINTEN6)||(OPT == ADC_ADINTEN7)\
165 ||(OPT == ADC_ADGINTEN))
166 
172 /* Public Types --------------------------------------------------------------- */
177 /*********************************************************************/
181 typedef enum
182 {
192 
194 typedef enum
195 {
210 } ADC_START_OPT;
211 
212 
214 typedef enum
215 {
221 
223 typedef enum
224 {
235 
237 typedef enum
238 {
239  ADC_DATA_BURST = 0, /*Burst bit*/
240  ADC_DATA_DONE /*Done bit*/
242 
248 /* Public Functions ----------------------------------------------------------- */
252 /* Init/DeInit ADC peripheral ----------------*/
253 void ADC_Init(LPC_ADC_TypeDef *ADCx, uint32_t rate);
254 void ADC_DeInit(LPC_ADC_TypeDef *ADCx);
255 
256 /* Enable/Disable ADC functions --------------*/
257 void ADC_BurstCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState);
258 void ADC_PowerdownCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState);
259 void ADC_StartCmd(LPC_ADC_TypeDef *ADCx, uint8_t start_mode);
260 void ADC_ChannelCmd (LPC_ADC_TypeDef *ADCx, uint8_t Channel, FunctionalState NewState);
261 
262 /* Configure ADC functions -------------------*/
263 void ADC_EdgeStartConfig(LPC_ADC_TypeDef *ADCx, uint8_t EdgeOption);
264 void ADC_IntConfig (LPC_ADC_TypeDef *ADCx, ADC_TYPE_INT_OPT IntType, FunctionalState NewState);
265 
266 /* Get ADC information functions -------------------*/
267 uint16_t ADC_ChannelGetData(LPC_ADC_TypeDef *ADCx, uint8_t channel);
268 FlagStatus ADC_ChannelGetStatus(LPC_ADC_TypeDef *ADCx, uint8_t channel, uint32_t StatusType);
269 uint32_t ADC_GlobalGetData(LPC_ADC_TypeDef *ADCx);
270 FlagStatus ADC_GlobalGetStatus(LPC_ADC_TypeDef *ADCx, uint32_t StatusType);
271 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 
282 #endif /* LPC17XX_ADC_H_ */
283 
288 /* --------------------------------- End Of File ------------------------------ */