A31L12x F/W Packages  1.4.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31L12x_hal_cmpn.c
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 /* Includes ----------------------------------------------------------------- */
36 //******************************************************************************
37 // Include
38 //******************************************************************************
39 
40 #include "A31L12x_hal_cmpn.h"
41 #include "A31L12x_hal_scu.h"
42 
43 /* Public Functions --------------------------------------------------------- */
44 //******************************************************************************
45 // Function
46 //******************************************************************************
47 
48 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
61 HAL_Status_Type HAL_COMP_Init( CMPn_Type* CMPx )
62 {
63  /* Check CMP handle */
64  if( CMPx == NULL )
65  {
66  return HAL_ERROR;
67  }
68 
69 #if 1 // supported
70  if( CMPx == ( CMPn_Type* )CMP0 )
71  {
72  // enable peripheral clock and reset peripheral
73  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_CMP0CLKE, PPxCLKE_Enable );
74  HAL_SCU_Peripheral_SetReset2( PPRST2_CMP0RST );
75  }
76 #endif
77 
78 #if 1 // supported
79  if( CMPx == ( CMPn_Type* )CMP1 )
80  {
81  // enable peripheral clock and reset peripheral
82  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_CMP1CLKE, PPxCLKE_Enable );
83  HAL_SCU_Peripheral_SetReset2( PPRST2_CMP1RST );
84  }
85 #endif
86 
87  return HAL_OK;
88 }
89 
90 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
104 {
105  /* Check CMP handle */
106  if( CMPx == NULL )
107  {
108  return HAL_ERROR;
109  }
110 
111 #if 1 // supported
112  if( CMPx == ( CMPn_Type* )CMP0 )
113  {
114  // reset peripheral and disable peripheral clock
115  HAL_SCU_Peripheral_SetReset2( PPRST2_CMP0RST );
116  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_CMP0CLKE, PPxCLKE_Disable );
117  }
118 #endif
119 
120 #if 1 // supported
121  if( CMPx == ( CMPn_Type* )CMP1 )
122  {
123  // reset peripheral and disable peripheral clock
124  HAL_SCU_Peripheral_SetReset2( PPRST2_CMP1RST );
125  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_CMP1CLKE, PPxCLKE_Disable );
126  }
127 #endif
128 
129  return HAL_OK;
130 }
131 
132 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
152 HAL_Status_Type HAL_COMP_ConfigPositiveInput( CMPn_Type* CMPx, CMPn_CR_CMPnPOS_Enum PositiveInputPin )
153 {
154  /* Check CMP handle */
155  if( CMPx == NULL )
156  {
157  return HAL_ERROR;
158  }
159 
160  CMPx->CR_b.CMPnPOS = PositiveInputPin;
161 
162  return HAL_OK;
163 }
164 
165 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
184 HAL_Status_Type HAL_COMP_ConfigNegativeInput( CMPn_Type* CMPx, CMPn_CR_CMPnNEG_Enum NegativeInputPin )
185 {
186  /* Check CMP handle */
187  if( CMPx == NULL )
188  {
189  return HAL_ERROR;
190  }
191 
192  CMPx->CR_b.CMPnNEG = NegativeInputPin;
193 
194  return HAL_OK;
195 }
196 
197 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
212 HAL_Status_Type HAL_COMP_ConfigHysteresis( CMPn_Type* CMPx, CMPn_CR_HYSnEN_Enum ControlValue )
213 {
214  /* Check CMP handle */
215  if( CMPx == NULL )
216  {
217  return HAL_ERROR;
218  }
219 
220  CMPx->CR_b.HYSnEN = ControlValue;
221 
222  return HAL_OK;
223 }
224 
225 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
240 HAL_Status_Type HAL_COMP_ConfigSpeed( CMPn_Type* CMPx, CMPn_CR_CMPnSPD_Enum Speed )
241 {
242  /* Check CMP handle */
243  if( CMPx == NULL )
244  {
245  return HAL_ERROR;
246  }
247 
248  CMPx->CR_b.CMPnSPD = Speed;
249 
250  return HAL_OK;
251 }
252 
253 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
273 HAL_Status_Type HAL_COMP_ConfigNoiseFilter( CMPn_Type* CMPx, CMPn_CR_NFCKn_Enum SamplingClock )
274 {
275  /* Check CMP handle */
276  if( CMPx == NULL )
277  {
278  return HAL_ERROR;
279  }
280 
281  CMPx->CR_b.NFCKn = SamplingClock;
282 
283  return HAL_OK;
284 }
285 
286 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
303 HAL_Status_Type HAL_COMP_ConfigInterruptPolarity( CMPn_Type* CMPx, CMPn_CR_CMPnPOL_Enum Polarity )
304 {
305  /* Check CMP handle */
306  if( CMPx == NULL )
307  {
308  return HAL_ERROR;
309  }
310 
311  CMPx->CR_b.CMPnPOL = Polarity;
312 
313  return HAL_OK;
314 }
315 
316 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
340 HAL_Status_Type HAL_COMP_ConfigIntRef( CMPn_Type* CMPx, CMPn_RCR_REFnEN_Enum ControlValue, CMPn_RCR_CMPnREF_Enum RefVoltage )
341 {
342  /* Check CMP handle */
343  if( CMPx == NULL )
344  {
345  return HAL_ERROR;
346  }
347 
348  CMPx->RCR_b.REFnEN = ControlValue;
349  CMPx->RCR_b.CMPnREF = RefVoltage;
350 
351  return HAL_OK;
352 }
353 
354 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
367 {
368  /* Check CMP handle */
369  if( CMPx == NULL )
370  {
371  return HAL_ERROR;
372  }
373 
374  CMPx->CR_b.CMPnEN = CMPn_CR_CMPnEN_Enable;
375 
376  return HAL_OK;
377 }
378 
379 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
392 {
393  /* Check CMP handle */
394  if( CMPx == NULL )
395  {
396  return HAL_ERROR;
397  }
398 
399  CMPx->CR_b.CMPnEN = CMPn_CR_CMPnEN_Disable;
400 
401  return HAL_OK;
402 }
403 
404 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
419 HAL_Status_Type HAL_COMP_ClearStatus( CMPn_Type* CMPx, uint32_t mask )
420 {
421  /* Check CMP handle */
422  if( CMPx == NULL )
423  {
424  return HAL_ERROR;
425  }
426 
427  switch( mask )
428  {
429  case CMPn_SR_CMPnIFLAG_Msk:
430  CMPx->SR = 0
431  | CMPn_SR_CMPnIFLAG_Msk
432  ;
433  break;
434  }
435 
436  return HAL_OK;
437 }
438 
439 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
451 uint32_t HAL_COMP_GetStatus( CMPn_Type* CMPx )
452 {
453  return CMPx->SR;
454 }
455 
HAL_Status_Type HAL_COMP_ConfigInterruptPolarity(CMPn_Type *CMPx, CMPn_CR_CMPnPOL_Enum Polarity)
Select the interrupt trigger polarity.
uint32_t HAL_COMP_GetStatus(CMPn_Type *CMPx)
Get the Status Register.
HAL_Status_Type HAL_COMP_ConfigPositiveInput(CMPn_Type *CMPx, CMPn_CR_CMPnPOS_Enum PositiveInputPin)
Select the positive input pin of a comparator.
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
Contains all macro definitions and function prototypes support for cmpn firmware library on A31L12x.
HAL_Status_Type
HAL_Status_Type HAL_COMP_Deinit(CMPn_Type *CMPx)
Deinitialize the target peripheral.
HAL_Status_Type HAL_COMP_ClearStatus(CMPn_Type *CMPx, uint32_t mask)
Clear the Status Register.
HAL_Status_Type HAL_COMP_ConfigIntRef(CMPn_Type *CMPx, CMPn_RCR_REFnEN_Enum ControlValue, CMPn_RCR_CMPnREF_Enum RefVoltage)
Control the reference voltage generator and select the reference voltage.
HAL_Status_Type HAL_COMP_ConfigNegativeInput(CMPn_Type *CMPx, CMPn_CR_CMPnNEG_Enum NegativeInputPin)
Select the negative input pin of a comparator.
HAL_Status_Type HAL_COMP_Disable(CMPn_Type *CMPx)
Disable the comparator function.
HAL_Status_Type HAL_COMP_ConfigHysteresis(CMPn_Type *CMPx, CMPn_CR_HYSnEN_Enum ControlValue)
Control the hysteresis function.
HAL_Status_Type HAL_COMP_Enable(CMPn_Type *CMPx)
Enable the comparator function.
HAL_Status_Type HAL_COMP_ConfigNoiseFilter(CMPn_Type *CMPx, CMPn_CR_NFCKn_Enum SamplingClock)
Select the sampling clock of a noise filter.
void HAL_SCU_Peripheral_SetReset2(uint32_t u32EachPeri2)
Set/Reset Each Peripheral Block Reset of PPRST2 Register.
HAL_Status_Type HAL_COMP_Init(CMPn_Type *CMPx)
Initialize the target peripheral.
Contains all macro definitions and function prototypes support for scu firmware library on A31L12x.
HAL_Status_Type HAL_COMP_ConfigSpeed(CMPn_Type *CMPx, CMPn_CR_CMPnSPD_Enum Speed)
Select the speed of a comparator.