A31L12x F/W Packages  1.4.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
Functions
A31L12x_hal_adc.c File Reference

Contains all functions support for adc firmware library on A31L12x. More...

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, ADC_INT_Type ADCIntCfg, FunctionalState NewState)
 ADC interrupt configuration. More...
 
HAL_Status_Type HAL_ADC_OvSamplingConfig (ADC_Type *ADCx, ADC_OV_SAMPLING_RATIO OvSampRatio, ADC_OVSCR_OVSHT_Enum DataShiftRight)
 ADC oversampling configuration. More...
 
HAL_Status_Type HAL_ADC_ChannelSel (ADC_Type *ADCx, uint32_t Channels)
 Select ADC Channels to conversion (Ex: ADC_AN0 | ADC_AN5 | ADC_AN14 | ADC_AVDD) More...
 
HAL_Status_Type HAL_ADC_Start (ADC_Type *ADCx)
 Start A/D conversion. More...
 
HAL_Status_Type HAL_ADC_RdyCmd (ADC_Type *ADCx)
 Ready procedure for ADC conversion. More...
 
HAL_Status_Type HAL_ADC_ClearStatus (ADC_Type *ADCx, ADC_INT_STATUS_Type ADCInt_status)
 Clear ADC interrupt status. More...
 
uint8_t HAL_ADC_GetStatus (ADC_Type *ADCx)
 Get ADC interrupt status. More...
 
uint16_t HAL_ADC_GetData (ADC_Type *ADCx)
 Get Result conversion from A/D data register. More...
 

Detailed Description

Contains all functions support for adc firmware library on A31L12x.

Version
1.00
Date
2020-05-29
Author
ABOV Application Team

Copyright(C) 2019, ABOV Semiconductor All rights reserved.

ABOV Disclaimer

IMPORTANT NOTICE ? PLEASE READ CAREFULLY ABOV Semiconductor ("ABOV") reserves the right to make changes, corrections, enhancements, modifications, and improvements to ABOV products and/or to this document at any time without notice. ABOV does not give warranties as to the accuracy or completeness of the information included herein. Purchasers should obtain the latest relevant information of ABOV products before placing orders. Purchasers are entirely responsible for the choice, selection, and use of ABOV products and ABOV assumes no liability for application assistance or the design of purchasers' products. No license, express or implied, to any intellectual property rights is granted by ABOV herein. ABOV disclaims all express and implied warranties and shall not be responsible or liable for any injuries or damages related to use of ABOV products in such unauthorized applications. ABOV and the ABOV logo are trademarks of ABOV. All other product or service names are the property of their respective owners. Information in this document supersedes and replaces the information previously supplied in any former versions of this document. 2020 ABOV Semiconductor All rights reserved

Definition in file A31L12x_hal_adc.c.

Function Documentation

◆ HAL_ADC_ChannelSel()

HAL_Status_Type HAL_ADC_ChannelSel ( ADC_Type *  ADCx,
uint32_t  Channels 
)

Select ADC Channels to conversion (Ex: ADC_AN0 | ADC_AN5 | ADC_AN14 | ADC_AVDD)

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]ChannelsChannel Numbers
  • ADC_CHSELR_AN0_Msk | ... | ADC_CHSELR_AN16_Msk | ADC_CHSELR_AN18_Msk | ADC_CHSELR_AN19_Msk
Returns
HAL_Status_Type

Definition at line 207 of file A31L12x_hal_adc.c.

208 {
209  /* Check ADC handle */
210  if( ADCx == NULL )
211  {
212  return HAL_ERROR;
213  }
214 
215  ADCx->CHSELR = Channels;
216 
217  return HAL_OK;
218 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_ClearStatus()

HAL_Status_Type HAL_ADC_ClearStatus ( ADC_Type *  ADCx,
ADC_INT_STATUS_Type  ADCInt_status 
)

Clear ADC interrupt status.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]ADCInt_statusBit position to be cleared
Returns
HAL_Status_Type

Definition at line 272 of file A31L12x_hal_adc.c.

273 {
274  uint32_t tempreg;
275 
276  /* Check ADC handle */
277  if( ADCx == NULL )
278  {
279  return HAL_ERROR;
280  }
281 
282  switch( ADCInt_status )
283  {
284  case ADC_INT_STATUS_EOS:
285  tempreg = ADC_IESR_EOSIFLAG_Msk;
286  break;
287  case ADC_INT_STATUS_EOC:
288  tempreg = ADC_IESR_EOCIFLAG_Msk;
289  break;
291  tempreg = ADC_IESR_OVRUNIFLAG_Msk;
292  break;
293  case ADC_INT_STATUS_STB:
294  tempreg = ADC_IESR_STBIFLAG_Msk;
295  break;
296  case ADC_INT_STATUS_ALL:
297  tempreg = ADC_IESR_EOSIFLAG_Msk | ADC_IESR_EOCIFLAG_Msk | ADC_IESR_OVRUNIFLAG_Msk | ADC_IESR_STBIFLAG_Msk;
298  break;
299  default:
300  return HAL_ERROR;
301  }
302 
303  ADCx->IESR = ( ADCx->IESR & ADC_INT_STATUS_MSK ) | tempreg;
304 
305  return HAL_OK;
306 }

References ADC_INT_STATUS_ALL, ADC_INT_STATUS_EOC, ADC_INT_STATUS_EOS, ADC_INT_STATUS_OVRUN, ADC_INT_STATUS_STB, HAL_ERROR, and HAL_OK.

◆ HAL_ADC_ConfigInterrupt()

HAL_Status_Type HAL_ADC_ConfigInterrupt ( ADC_Type *  ADCx,
ADC_INT_Type  ADCIntCfg,
FunctionalState  NewState 
)

ADC interrupt configuration.

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

Definition at line 118 of file A31L12x_hal_adc.c.

119 {
120  uint32_t tempreg;
121 
122  /* Check ADC handle */
123  if( ADCx == NULL )
124  {
125  return HAL_ERROR;
126  }
127 
128  // get mask
129  switch( ADCIntCfg )
130  {
131  case ADC_INTCFG_EOS:
132  tempreg = ADC_IESR_EOSIEN_Msk;
133  break;
134  case ADC_INTCFG_EOC:
135  tempreg = ADC_IESR_EOCIEN_Msk;
136  break;
137  case ADC_INTCFG_OVRUN:
138  tempreg = ADC_IESR_OVRUNIEN_Msk;
139  break;
140  case ADC_INTCFG_STB:
141  tempreg = ADC_IESR_STBIEN_Msk;
142  break;
143  default:
144  return HAL_ERROR;
145  }
146 
147  // enable/disable
148  if( NewState == ENABLE )
149  {
150  ADCx->IESR = ( ( ADCx->IESR & ADC_INT_STATUS_MSK ) | tempreg );
151  }
152  else
153  {
154  ADCx->IESR = ( ( ADCx->IESR & ADC_INT_STATUS_MSK ) & ( ~tempreg ) );
155  }
156 
157  return HAL_OK;
158 }

References ADC_INTCFG_EOC, ADC_INTCFG_EOS, ADC_INTCFG_OVRUN, ADC_INTCFG_STB, ENABLE, 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 91 of file A31L12x_hal_adc.c.

92 {
93  /* Check ADC handle */
94  if( ADCx == NULL )
95  {
96  return HAL_ERROR;
97  }
98 
99  ADCRDY_Stop(); // Stop subsequent steps
100  ADCDIS(); // Disable ADC module
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 327 of file A31L12x_hal_adc.c.

328 {
329  uint16_t adc_value;
330 
331  adc_value = ADCx->DR;
332  return ADC_DR_RESULT( adc_value );
333 }

◆ HAL_ADC_GetStatus()

uint8_t HAL_ADC_GetStatus ( ADC_Type *  ADCx)

Get ADC interrupt status.

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

Definition at line 315 of file A31L12x_hal_adc.c.

316 {
317  return ( uint8_t )( ( ADCx->IESR ) & ( ~ADC_INT_STATUS_MSK ) );
318 }

◆ 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 A31L12x_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  tempreg = 0
71  | ( ( ( ADC_Config->TrgSel ) & 7 ) << ADC_CR_TRIG_Pos ) // TRGSRC
72  | ( ( ( ADC_Config->ExtTrgPolSel ) & 3 ) << ADC_CR_ETRGP_Pos ) // Ext Trigger Polarity
73  | ( ( ( ADC_Config->ConvModSel ) & 3 ) << ADC_CR_MDSEL_Pos ) // Conversion Mode
74  ;
75  ADCx->CR = tempreg;
76 
77  ADCx->PREDR = ( ADC_Config->InClkDiv & ADC_PREDR_PRED_Msk );
78 
79  ADCx->SAMR = ( ADC_Config->SamplingClk & ADC_SAMR_SAMCK_Msk ); // Sampling Cycles: SamplingClk + 2
80 
81  return HAL_OK;
82 }
uint32_t SamplingClk
uint32_t InClkDiv
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
uint32_t ExtTrgPolSel
uint32_t ConvModSel

References ADC_CFG_Type::ConvModSel, ADC_CFG_Type::ExtTrgPolSel, HAL_ERROR, HAL_OK, HAL_SCU_Peripheral_EnableClock2(), ADC_CFG_Type::InClkDiv, ADC_CFG_Type::SamplingClk, and ADC_CFG_Type::TrgSel.

Here is the call graph for this function:

◆ HAL_ADC_OvSamplingConfig()

HAL_Status_Type HAL_ADC_OvSamplingConfig ( ADC_Type *  ADCx,
ADC_OV_SAMPLING_RATIO  OvSampRatio,
ADC_OVSCR_OVSHT_Enum  DataShiftRight 
)

ADC oversampling configuration.

Parameters
[in]ADCxPointer to the target ADC
  • ADC
[in]OvSampRatioOverSampling Ratio
  • 0 ~ 7: 2**(in+1)
[in]DataShiftRightOverSampling Data Shift bits
  • 0 ~ 8: result data are shifted right by in bits
Returns
HAL_Status_Type

Definition at line 173 of file A31L12x_hal_adc.c.

174 {
175  uint32_t tempreg;
176 
177  /* Check ADC handle */
178  if( ADCx == NULL )
179  {
180  return HAL_ERROR;
181  }
182 
183  if( DataShiftRight > ADC_OVSCR_OVSHT_ShiftRight8Bit )
184  {
185  DataShiftRight = ADC_OVSCR_OVSHT_NoShift;
186  }
187  tempreg = 0
188  | ( ( ( OvSampRatio ) & 7 ) << ADC_OVSCR_OVSMPR_Pos ) // Oversampling ratio
189  | ( ( DataShiftRight ) << ADC_OVSCR_OVSHT_Pos ) // Shift right bits
190  ;
191  ADCx->OVSCR = tempreg;
192  ADC_OVSMPEN(); // ADC Oversampling Enable
193 
194  return HAL_OK;
195 }

References HAL_ERROR, and HAL_OK.

◆ HAL_ADC_RdyCmd()

HAL_Status_Type HAL_ADC_RdyCmd ( ADC_Type *  ADCx)

Ready procedure for ADC conversion.

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

Definition at line 247 of file A31L12x_hal_adc.c.

248 {
249  /* Check ADC handle */
250  if( ADCx == NULL )
251  {
252  return HAL_ERROR;
253  }
254 
255  ADCEN(); // ADCEN;
256  while( !ADCInt_GetStbFg() ) {} // Check ADC stabiliaztion
257  ADCInt_ClrStbFg(); // Clear the stabiliaztion flag
258  ADCRDY_Conv(); // Ready for conversion
259 
260  return HAL_OK;
261 }

References HAL_ERROR, and HAL_OK.

◆ 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 227 of file A31L12x_hal_adc.c.

228 {
229  /* Check ADC handle */
230  if( ADCx == NULL )
231  {
232  return HAL_ERROR;
233  }
234 
235  ADCADST_Set(); // Start conversion by s/w
236 
237  return HAL_OK;
238 }

References HAL_ERROR, and HAL_OK.