A31R71x F/W Packages  1.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31R71x_hal_adc.h
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 #ifndef _ADC_H_
36 #define _ADC_H_
37 
38 #include "A31R71x.h"
39 #include "A31R71x_hal_aa_types.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 //******************************************************************************
46 // Constant
47 //******************************************************************************
48 
49 // ADC Trigger Signal Selection Control
50 /*
51 #define ADC_ADST (0x0uL << 11)
52 #define ADC_T10M (0x1uL << 11)
53 #define ADC_T11M (0x2uL << 11)
54 #define ADC_T12M (0x3uL << 11)
55 #define ADC_T30 (0x4uL << 11)
56 */
57 #define TRIG_ADST (ADC_CR_TRIG_ADST << ADC_CR_TRIG_Pos) // ADST : Select ADST
58 #define TRIG_TIMER10 (ADC_CR_TRIG_TIMER10 << ADC_CR_TRIG_Pos) // TIMER10 : Select Timer 10 A-Match Signal
59 #define TRIG_TIMER11 (ADC_CR_TRIG_TIMER11 << ADC_CR_TRIG_Pos) // TIMER11 : Select Timer 11 A-Match Signal
60 #define TRIG_TIMER12 (ADC_CR_TRIG_TIMER12 << ADC_CR_TRIG_Pos) // TIMER12 : Select Timer 12 A-Match Signal
61 
62 // ADC Reference Selection Control
63 /*
64 #define ADC_VDD (0x0uL << 10)
65 #define ADC_AVREF (0x1uL << 10)
66 */
67 #define REFSEL_Vdd (ADC_CR_REFSEL_Vdd << ADC_CR_REFSEL_Pos) // Vdd : Select analog power (VDD)
68 #define REFSEL_AVref (ADC_CR_REFSEL_AVref << ADC_CR_REFSEL_Pos) // AVref : Select external reference (AVREF)
69 
70 // ADC Interrupt Enable Control
71 /*
72 #define ADC_INTDIS (0x0uL << 5)
73 #define ADC_INTEN (0x1uL << 5)
74 */
75 #define ADCIEN_Disable (ADC_CR_ADCIEN_Disable << ADC_CR_ADCIEN_Pos) // Disable : Disable ADC interrupt
76 #define ADCIEN_Enable (ADC_CR_ADCIEN_Enable << ADC_CR_ADCIEN_Pos) // Enable : Enable ADC interrupt
77 
78 // A/D Converter Channel Selection Control
79 /*
80 #define ADC_AN0 (0x00uL << 0)
81 #define ADC_AN1 (0x01uL << 0)
82 #define ADC_AN2 (0x02uL << 0)
83 #define ADC_AN3 (0x03uL << 0)
84 #define ADC_AN4 (0x04uL << 0)
85 #define ADC_AN5 (0x05uL << 0)
86 #define ADC_AN6 (0x06uL << 0)
87 #define ADC_AN7 (0x07uL << 0)
88 #define ADC_AN8 (0x08uL << 0)
89 #define ADC_AN9 (0x09uL << 0)
90 #define ADC_AN10 (0x0auL << 0)
91 */
92 #define ADSEL_AN0 (ADC_CR_ADSEL_AN0 << ADC_CR_ADSEL_Pos) // AN0 : Select AN0
93 #define ADSEL_AN1 (ADC_CR_ADSEL_AN1 << ADC_CR_ADSEL_Pos) // AN1 : Select AN1
94 #define ADSEL_AN2 (ADC_CR_ADSEL_AN2 << ADC_CR_ADSEL_Pos) // AN2 : Select AN2
95 #define ADSEL_AN3 (ADC_CR_ADSEL_AN3 << ADC_CR_ADSEL_Pos) // AN3 : Select AN3
96 #define ADSEL_AN4 (ADC_CR_ADSEL_AN4 << ADC_CR_ADSEL_Pos) // AN4 : Select AN4
97 #define ADSEL_AN5 (ADC_CR_ADSEL_AN5 << ADC_CR_ADSEL_Pos) // AN5 : Select AN5
98 #define ADSEL_AN6 (ADC_CR_ADSEL_AN6 << ADC_CR_ADSEL_Pos) // AN6 : Select AN6
99 #define ADSEL_AN7 (ADC_CR_ADSEL_AN7 << ADC_CR_ADSEL_Pos) // AN7 : Select AN7
100 #define ADSEL_AN8 (ADC_CR_ADSEL_AN8 << ADC_CR_ADSEL_Pos) // AN8 : Select AN8
101 #define ADSEL_AN9 (ADC_CR_ADSEL_AN9 << ADC_CR_ADSEL_Pos) // AN9 : Select AN9
102 #define ADSEL_AN10 (ADC_CR_ADSEL_AN10 << ADC_CR_ADSEL_Pos) // AN10 : Select AN10
103 #define ADSEL_AN11 (ADC_CR_ADSEL_AN11 << ADC_CR_ADSEL_Pos) // AN11 : Select AN11
104 #define ADSEL_AN12 (ADC_CR_ADSEL_AN12 << ADC_CR_ADSEL_Pos) // AN12 : Select AN12
105 #define ADSEL_AN13 (ADC_CR_ADSEL_AN13 << ADC_CR_ADSEL_Pos) // AN13 : Select AN13
106 
107 //******************************************************************************
108 // Type
109 //******************************************************************************
110 
111 //==============================================================================
112 // Structure
113 //==============================================================================
114 
115 typedef struct
116 {
117  /* ADC_CR */
118  uint32_t RefSel;
119  uint32_t TrgSel;
120 
121  /* ADC_PREDR */
122  uint32_t InClkDiv;
123 } ADC_CFG_Type;
124 
125 //******************************************************************************
126 // Macro
127 //******************************************************************************
128 
129 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
133 #define ADCEN() (ADC->CR_b.ADCEN = 1)
134 
135 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
139 #define ADCDIS() (ADC->CR_b.ADCEN = 0)
140 
141 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
145 #define ADCADST_Set() (ADC->CR_b.ADST = 1)
146 
147 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
151 #define ADCADST_Get() (ADC->CR_b.ADST)
152 
153 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
157 #define ADCInt_GetFg() (ADC->CR_b.ADCIFLAG)
158 
159 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
163 #define ADCInt_ClrFg() (ADC->CR_b.ADCIFLAG = 1)
164 
165 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
169 #define ADCData_Get() (ADC->DR)
170 
171 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
175 #define ADC_DR_RESULT( n ) ((n) & ADC_DR_ADDATA_Msk)
176 
177 //******************************************************************************
178 // Function
179 //******************************************************************************
180 
181 HAL_Status_Type HAL_ADC_Init( ADC_Type* ADCx, ADC_CFG_Type* ADC_Config );
182 HAL_Status_Type HAL_ADC_DeInit( ADC_Type* ADCx );
183 
184 HAL_Status_Type HAL_ADC_ConfigInterrupt( ADC_Type* ADCx, FunctionalState NewState );
185 HAL_Status_Type HAL_ADC_ChannelSel( ADC_Type* ADCx, uint32_t Channel );
186 HAL_Status_Type HAL_ADC_Start( ADC_Type* ADCx );
187 HAL_Status_Type HAL_ADC_Stop( ADC_Type* ADCx );
188 HAL_Status_Type HAL_ADC_ClearStatus( ADC_Type* ADCx );
189 uint32_t HAL_ADC_GetStatus( ADC_Type* ADCx );
190 
191 uint16_t HAL_ADC_GetData( ADC_Type* ADCx );
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif /* _ADC_H_ */
198 
HAL_Status_Type
uint32_t InClkDiv
FunctionalState
HAL_Status_Type HAL_ADC_Start(ADC_Type *ADCx)
Start A/D conversion.
HAL_Status_Type HAL_ADC_ChannelSel(ADC_Type *ADCx, uint32_t Channel)
Select ADC Channel Number.
HAL_Status_Type HAL_ADC_Stop(ADC_Type *ADCx)
Stop A/D conversion If this function called after a conversion cycle starts, the current conversion i...
HAL_Status_Type HAL_ADC_DeInit(ADC_Type *ADCx)
Close ADC.
HAL_Status_Type HAL_ADC_ClearStatus(ADC_Type *ADCx)
Clear ADC channel status.
uint16_t HAL_ADC_GetData(ADC_Type *ADCx)
Get Result conversion from A/D data register.
Contains the ABOV typedefs for C standard types. It is intended to be used in ISO C conforming develo...
uint32_t HAL_ADC_GetStatus(ADC_Type *ADCx)
Get ADC channel status.
HAL_Status_Type HAL_ADC_ConfigInterrupt(ADC_Type *ADCx, FunctionalState NewState)
ADC interrupt configuration.
HAL_Status_Type HAL_ADC_Init(ADC_Type *ADCx, ADC_CFG_Type *ADC_Config)
Initialize the ADC peripheral with the specified parameters.