]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/include/adc.h
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / include / adc.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  *  \file\r
32  *\r
33  *  \section Purpose\r
34  *\r
35  *  Interface for configuration the Analog-to-Digital Converter (ADC) peripheral.\r
36  *\r
37  *  \section Usage\r
38  *\r
39  *  -# Configurate the pins for ADC.\r
40  *  -# Initialize the ADC with ADC_Initialize().\r
41  *  -# Set ADC clock and timing with ADC_SetClock() and ADC_SetTiming().\r
42  *  -# Select the active channel using ADC_EnableChannel().\r
43  *  -# Start the conversion with ADC_StartConversion().\r
44  *  -# Wait the end of the conversion by polling status with ADC_GetStatus().\r
45  *  -# Finally, get the converted data using ADC_GetConvertedData() or ADC_GetLastConvertedData().\r
46  *\r
47 */\r
48 #ifndef _ADC_\r
49 #define _ADC_\r
50 \r
51 /*----------------------------------------------------------------------------\r
52  *        Headers\r
53  *----------------------------------------------------------------------------*/\r
54 #include <assert.h>\r
55 #include <stdint.h>\r
56 \r
57 /*------------------------------------------------------------------------------\r
58  *         Definitions\r
59  *------------------------------------------------------------------------------*/\r
60 \r
61 /* Max. ADC Clock Frequency (Hz) */\r
62 #define ADC_CLOCK_MAX   20000000\r
63 \r
64 /* Max. normal ADC startup time (us) */\r
65 #define ADC_STARTUP_NORMAL_MAX     40\r
66 /* Max. fast ADC startup time (us) */\r
67 #define ADC_STARTUP_FAST_MAX       12\r
68 \r
69 /* Definitions for ADC channels */\r
70 #define ADC_CHANNEL_0  0\r
71 #define ADC_CHANNEL_1  1\r
72 #define ADC_CHANNEL_2  2\r
73 #define ADC_CHANNEL_3  3\r
74 #define ADC_CHANNEL_4  4\r
75 #define ADC_CHANNEL_5  5\r
76 #define ADC_CHANNEL_6  6\r
77 #define ADC_CHANNEL_7  7\r
78 #define ADC_CHANNEL_8  8\r
79 #define ADC_CHANNEL_9  9\r
80 #define ADC_CHANNEL_10 10\r
81 #define ADC_CHANNEL_11 11\r
82 #define ADC_CHANNEL_12 12\r
83 #define ADC_CHANNEL_13 13\r
84 #define ADC_CHANNEL_14 14\r
85 #define ADC_CHANNEL_15 15\r
86 \r
87 #ifdef __cplusplus\r
88  extern "C" {\r
89 #endif\r
90 \r
91 /*------------------------------------------------------------------------------\r
92  *         Macros function of register access\r
93  *------------------------------------------------------------------------------*/\r
94 \r
95 #define ADC_GetModeReg( pAdc )                ((pAdc)->ADC_MR)\r
96 \r
97 #define ADC_StartConversion( pAdc )           ((pAdc)->ADC_CR = ADC_CR_START)\r
98 \r
99 #define ADC_SetCalibMode(pAdc)                  ((pAdc)->ADC_CR |= ADC_CR_AUTOCAL)\r
100 \r
101 #define ADC_EnableChannel( pAdc, dwChannel )    {\\r
102             (pAdc)->ADC_CHER = (1 << (dwChannel));\\r
103         }\r
104 \r
105 #define ADC_DisableChannel(pAdc, dwChannel)  {\\r
106             (pAdc)->ADC_CHDR = (1 << (dwChannel));\\r
107         }\r
108 \r
109 #define ADC_EnableIt(pAdc, dwMode)            {\\r
110             (pAdc)->ADC_IER = (dwMode);\\r
111         }\r
112 \r
113 #define ADC_DisableIt(pAdc, dwMode)           {\\r
114             (pAdc)->ADC_IDR = (dwMode);\\r
115         }\r
116 \r
117 #define ADC_SetChannelGain(pAdc,dwMode)       {\\r
118             (pAdc)->ADC_CGR = dwMode;\\r
119         }\r
120 \r
121 #define ADC_SetChannelOffset(pAdc,dwMode)     {\\r
122             (pAdc)->ADC_COR = dwMode;\\r
123         }\r
124 \r
125 #define ADC_EnableDataReadyIt(pAdc)         ((pAdc)->ADC_IER = ADC_IER_DRDY)\r
126 \r
127 #define ADC_GetStatus(pAdc)                 ((pAdc)->ADC_ISR)\r
128 \r
129 #define ADC_GetCompareMode(pAdc)            (((pAdc)->ADC_EMR)& (ADC_EMR_CMPMODE_Msk))\r
130 \r
131 #define ADC_GetChannelStatus(pAdc)          ((pAdc)->ADC_CHSR)\r
132 \r
133 #define ADC_GetInterruptMaskStatus(pAdc)    ((pAdc)->ADC_IMR)\r
134 \r
135 #define ADC_GetLastConvertedData(pAdc)      ((pAdc)->ADC_LCDR)\r
136 \r
137 /*------------------------------------------------------------------------------\r
138  *         Exported functions\r
139  *------------------------------------------------------------------------------*/\r
140 extern void ADC_Initialize( Adc* pAdc, uint32_t dwId );\r
141 extern uint32_t ADC_SetClock( Adc* pAdc, uint32_t dwPres, uint32_t dwMck );\r
142 extern void ADC_SetTiming( Adc* pAdc, uint32_t dwStartup, uint32_t dwTracking, uint32_t dwSettling );\r
143 extern void ADC_SetTrigger( Adc* pAdc, uint32_t dwTrgSel );\r
144 extern void ADC_SetTriggerMode(Adc *pAdc, uint32_t dwMode);\r
145 extern void ADC_SetLowResolution( Adc* pAdc, uint32_t bEnDis );\r
146 extern void ADC_SetSleepMode( Adc *pAdc, uint8_t bEnDis );\r
147 extern void ADC_SetFastWakeup( Adc *pAdc, uint8_t bEnDis );\r
148 extern void ADC_SetSequenceMode( Adc *pAdc, uint8_t bEnDis );\r
149 extern void ADC_SetSequence( Adc *pAdc, uint32_t dwSEQ1, uint32_t dwSEQ2 );\r
150 extern void ADC_SetSequenceByList( Adc *pAdc, uint8_t ucChList[], uint8_t ucNumCh );\r
151 extern void ADC_SetAnalogChange( Adc *pAdc, uint8_t bEnDis );\r
152 extern void ADC_SetTagEnable( Adc *pAdc, uint8_t bEnDis );\r
153 extern void ADC_SetCompareChannel( Adc* pAdc, uint32_t dwChannel ) ;\r
154 extern void ADC_SetCompareMode( Adc* pAdc, uint32_t dwMode ) ;\r
155 extern void ADC_SetComparisonWindow( Adc* pAdc, uint32_t dwHi_Lo ) ;\r
156 extern uint8_t ADC_CheckConfiguration( Adc* pAdc, uint32_t dwMcK ) ;\r
157 extern uint32_t ADC_GetConvertedData( Adc* pAdc, uint32_t dwChannel ) ;\r
158 extern void ADC_SetTsAverage(Adc* pADC, uint32_t dwAvg2Conv);\r
159 extern uint32_t ADC_GetTsXPosition(Adc *pADC);\r
160 extern uint32_t ADC_GetTsYPosition(Adc *pADC);\r
161 extern uint32_t ADC_GetTsPressure(Adc *pADC);\r
162 extern void ADC_SetTsDebounce(Adc *pADC, uint32_t dwTime);\r
163 extern void ADC_SetTsPenDetect(Adc* pADC, uint8_t bEnDis);\r
164 extern void ADC_SetStartupTime( Adc *pAdc, uint32_t dwUs );\r
165 extern void ADC_SetTrackingTime( Adc *pAdc, uint32_t dwNs );\r
166 extern void ADC_SetTriggerPeriod(Adc *pAdc, uint32_t dwPeriod);\r
167 extern void ADC_SetTsMode(Adc* pADC, uint32_t dwMode);\r
168 extern void ADC_TsCalibration( Adc *pAdc );\r
169 \r
170 \r
171 #ifdef __cplusplus\r
172 }\r
173 #endif\r
174 \r
175 #endif /* #ifndef _ADC_ */\r
176 \r