A31R71x F/W Packages  1.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
Functions
A31R71x_hal_adc.c File Reference

Go to the source code of this file.

Functions

HAL_Status_Type HAL_ADC_Init (ADC_Type *ADCx, ADC_CFG_Type *ADC_Config)
 Initialize the ADC peripheral with the specified parameters. More...
 
HAL_Status_Type HAL_ADC_DeInit (ADC_Type *ADCx)
 Close ADC. More...
 
HAL_Status_Type HAL_ADC_ConfigInterrupt (ADC_Type *ADCx, FunctionalState NewState)
 ADC interrupt configuration. More...
 
HAL_Status_Type HAL_ADC_ChannelSel (ADC_Type *ADCx, uint32_t Channel)
 Select ADC Channel Number. More...
 
HAL_Status_Type HAL_ADC_Start (ADC_Type *ADCx)
 Start A/D conversion. More...
 
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 is completed. More...
 
HAL_Status_Type HAL_ADC_ClearStatus (ADC_Type *ADCx)
 Clear ADC channel status. More...
 
uint32_t HAL_ADC_GetStatus (ADC_Type *ADCx)
 Get ADC channel status. More...
 
uint16_t HAL_ADC_GetData (ADC_Type *ADCx)
 Get Result conversion from A/D data register. More...
 

Function Documentation

◆ HAL_ADC_ChannelSel()

HAL_Status_Type HAL_ADC_ChannelSel ( ADC_Type *  ADCx,
uint32_t  Channel 
)

Select ADC Channel Number.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]ChannelChannel Number
  • ADC_CR_ADSEL_AN0 ~ ADC_CR_ADSEL_AN13
Returns
HAL_Status_Type

Definition at line 148 of file A31R71x_hal_adc.c.

149 {
150  uint32_t temp_reg;
151 
152  /* Check ADC handle */
153  if( ADCx == NULL )
154  {
155  return HAL_ERROR;
156  }
157 
158  temp_reg = ADCx->CR & ( uint32_t )( ~ADC_CR_ADSEL_Msk );
159  temp_reg |= ( uint32_t )( Channel & ADC_CR_ADSEL_Msk );
160  ADCx->CR = temp_reg;
161 
162  return HAL_OK;
163 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_ClearStatus()

HAL_Status_Type HAL_ADC_ClearStatus ( ADC_Type *  ADCx)

Clear ADC channel status.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
HAL_Status_Type

Definition at line 214 of file A31R71x_hal_adc.c.

215 {
216  uint32_t tempreg;
217 
218  /* Check ADC handle */
219  if( ADCx == NULL )
220  {
221  return HAL_ERROR;
222  }
223 
224  tempreg = ADCx->CR;
225  tempreg |= ( 1 << ADC_CR_ADCIFLAG_Pos );
226 
227  ADCx->CR = tempreg; // clear flag;
228 
229  return HAL_OK;
230 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_ConfigInterrupt()

HAL_Status_Type HAL_ADC_ConfigInterrupt ( ADC_Type *  ADCx,
FunctionalState  NewState 
)

ADC interrupt configuration.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]NewStateNext State of Interrupt Operation
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 116 of file A31R71x_hal_adc.c.

117 {
118  uint32_t tempreg;
119 
120  /* Check ADC handle */
121  if( ADCx == NULL )
122  {
123  return HAL_ERROR;
124  }
125 
126  tempreg = ADCx->CR;
127  tempreg &= ~( 1 << ADC_CR_ADCIEN_Pos );
128 
129  if( NewState )
130  {
131  tempreg |= ( 1 << ADC_CR_ADCIEN_Pos );
132  }
133  ADCx->CR = tempreg;
134 
135  return HAL_OK;
136 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_DeInit()

HAL_Status_Type HAL_ADC_DeInit ( ADC_Type *  ADCx)

Close ADC.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
HAL_Status_Type

Definition at line 92 of file A31R71x_hal_adc.c.

93 {
94  /* Check ADC handle */
95  if( ADCx == NULL )
96  {
97  return HAL_ERROR;
98  }
99 
100  ADCx->CR = 0;
101  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_ADCLKE, PPxCLKE_Disable );
102 
103  return HAL_OK;
104 }
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.

References HAL_ERROR, HAL_OK, and HAL_SCU_Peripheral_EnableClock2().

Here is the call graph for this function:

◆ HAL_ADC_GetData()

uint16_t HAL_ADC_GetData ( ADC_Type *  ADCx)

Get Result conversion from A/D data register.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
Result of conversion

Definition at line 256 of file A31R71x_hal_adc.c.

257 {
258  uint16_t adc_value;
259 
260  adc_value = ADCx->DR;
261 
262  return ADC_DR_RESULT( adc_value );
263 }

◆ HAL_ADC_GetStatus()

uint32_t HAL_ADC_GetStatus ( ADC_Type *  ADCx)

Get ADC channel status.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
ADC status register

Definition at line 239 of file A31R71x_hal_adc.c.

240 {
241  uint32_t tempreg;
242 
243  tempreg = ADCx->CR;
244  tempreg &= ( 1 << ADC_CR_ADCIFLAG_Pos );
245 
246  return tempreg;
247 }

◆ HAL_ADC_Init()

HAL_Status_Type HAL_ADC_Init ( ADC_Type *  ADCx,
ADC_CFG_Type ADC_Config 
)

Initialize the ADC peripheral with the specified parameters.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]ADC_ConfigPointer to a ADC_CFG_Type structure that contains the configuration information for the specified peripheral.
Returns
HAL_Status_Type

Definition at line 58 of file A31R71x_hal_adc.c.

59 {
60  uint32_t tempreg;
61 
62  /* Check ADC handle */
63  if( ADCx == NULL )
64  {
65  return HAL_ERROR;
66  }
67 
68  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_ADCLKE, PPxCLKE_Enable );
69 
70  ADCx->CR = ( 1 << ADC_CR_ADCEN_Pos ); // ADCEN;
71 
72  tempreg = 0
73  | ( 1 << ADC_CR_ADCEN_Pos ) // ADCEN
74  | ( ( ( ADC_Config->TrgSel ) & 7 ) << ADC_CR_TRIG_Pos ) // TRGSRC
75  | ( ( ( ADC_Config->RefSel ) & 1 ) << ADC_CR_REFSEL_Pos )
76  | ( 1 << ADC_CR_ADCIFLAG_Pos ) // clear flag
77  ;
78  ADCx->CR = tempreg;
79 
80  ADCx->PREDR = ( ADC_Config->InClkDiv & ADC_PREDR_PRED_Msk );
81 
82  return HAL_OK;
83 }
uint32_t InClkDiv
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.

References HAL_ERROR, HAL_OK, HAL_SCU_Peripheral_EnableClock2(), ADC_CFG_Type::InClkDiv, ADC_CFG_Type::RefSel, and ADC_CFG_Type::TrgSel.

Here is the call graph for this function:

◆ HAL_ADC_Start()

HAL_Status_Type HAL_ADC_Start ( ADC_Type *  ADCx)

Start A/D conversion.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
HAL_Status_Type

Definition at line 172 of file A31R71x_hal_adc.c.

173 {
174  /* Check ADC handle */
175  if( ADCx == NULL )
176  {
177  return HAL_ERROR;
178  }
179 
180  ADCx->CR |= ( 1 << ADC_CR_ADST_Pos );
181 
182  return HAL_OK;
183 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_Stop()

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 is completed.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
Returns
HAL_Status_Type

Definition at line 194 of file A31R71x_hal_adc.c.

195 {
196  /* Check ADC handle */
197  if( ADCx == NULL )
198  {
199  return HAL_ERROR;
200  }
201 
202  ADCx->CR &= ~( 1 << ADC_CR_ADST_Pos );
203 
204  return HAL_OK;
205 }

References HAL_ERROR, and HAL_OK.