1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\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
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\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
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
35 * Interface for configuration the Analog-to-Digital Converter (ADC) peripheral.
\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
51 /*----------------------------------------------------------------------------
\r
53 *----------------------------------------------------------------------------*/
\r
57 /*------------------------------------------------------------------------------
\r
59 *------------------------------------------------------------------------------*/
\r
61 /* Max. ADC Clock Frequency (Hz) */
\r
62 #define ADC_CLOCK_MAX 20000000
\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
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
91 /*------------------------------------------------------------------------------
\r
92 * Macros function of register access
\r
93 *------------------------------------------------------------------------------*/
\r
95 #define ADC_GetModeReg( pAdc ) ((pAdc)->ADC_MR)
\r
97 #define ADC_StartConversion( pAdc ) ((pAdc)->ADC_CR = ADC_CR_START)
\r
99 #define ADC_SetCalibMode(pAdc) ((pAdc)->ADC_CR |= ADC_CR_AUTOCAL)
\r
101 #define ADC_EnableChannel( pAdc, dwChannel ) {\
\r
102 (pAdc)->ADC_CHER = (1 << (dwChannel));\
\r
105 #define ADC_DisableChannel(pAdc, dwChannel) {\
\r
106 (pAdc)->ADC_CHDR = (1 << (dwChannel));\
\r
109 #define ADC_EnableIt(pAdc, dwMode) {\
\r
110 (pAdc)->ADC_IER = (dwMode);\
\r
113 #define ADC_DisableIt(pAdc, dwMode) {\
\r
114 (pAdc)->ADC_IDR = (dwMode);\
\r
117 #define ADC_SetChannelGain(pAdc,dwMode) {\
\r
118 (pAdc)->ADC_CGR = dwMode;\
\r
121 #define ADC_SetChannelOffset(pAdc,dwMode) {\
\r
122 (pAdc)->ADC_COR = dwMode;\
\r
125 #define ADC_EnableDataReadyIt(pAdc) ((pAdc)->ADC_IER = ADC_IER_DRDY)
\r
127 #define ADC_GetStatus(pAdc) ((pAdc)->ADC_ISR)
\r
129 #define ADC_GetCompareMode(pAdc) (((pAdc)->ADC_EMR)& (ADC_EMR_CMPMODE_Msk))
\r
131 #define ADC_GetChannelStatus(pAdc) ((pAdc)->ADC_CHSR)
\r
133 #define ADC_GetInterruptMaskStatus(pAdc) ((pAdc)->ADC_IMR)
\r
135 #define ADC_GetLastConvertedData(pAdc) ((pAdc)->ADC_LCDR)
\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
175 #endif /* #ifndef _ADC_ */
\r