HAL COMP Functions

Initialization and de-initialization functions

group COMP_Exported_Functions_Group1

Set of functions to initialize and deinitialize the COMPx peripheral:

  • HAL_COMP_Init(): associate HAL COMP handle with selected COMP instance,

  • HAL_COMP_DeInit(): restore the default configuration of the HAL COMP handle,

  • HAL_COMP_WINDOW_SetHandle(): link HAL COMP handles sharing common features (window mode).

Functions

hal_status_t HAL_COMP_Init ( hal_comp_handle_t * hcomp , hal_comp_t instance )

Initialize HAL COMP handle and associate it to the selected COMP instance.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – HAL COMP handle is already initialized and cannot be modified.

  • HAL_OK – HAL COMP handle has been correctly initialized.

void HAL_COMP_DeInit ( hal_comp_handle_t * hcomp )

Deinitialize the COMP peripheral.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Configuration functions

group COMP_Exported_Functions_Group2

Set of functions to configure COMPx peripheral:

  • HAL_COMP_SetConfig(): Configure comparator.

  • HAL_COMP_GetConfig(): Get comparator configuration.

  • HAL_COMP_SetInputPlus(): Unitary configuration: Set comparator input plus configuration.

  • HAL_COMP_GetInputPlus(): Unitary configuration: Get comparator input plus configuration.

  • HAL_COMP_SetInputMinus(): Unitary configuration: Set comparator input minus configuration.

  • HAL_COMP_GetInputMinus(): Unitary configuration: Get comparator input minus configuration.

  • HAL_COMP_SetOutputBlanking(): Unitary configuration: Set comparator output blanking (optional).

  • HAL_COMP_GetOutputBlanking(): Unitary configuration: Get comparator output blanking (optional).

  • HAL_COMP_WINDOW_SetConfig(): Configure comparators in window mode.

  • HAL_COMP_WINDOW_GetConfig(): Get window comparators configuration.

  • HAL_COMP_WINDOW_SetInput(): Unitary configuration: Set window comparators input plus configuration (common to both comparator instances)

  • HAL_COMP_WINDOW_GetInput(): Unitary configuration: Get window comparators input plus configuration (common to both comparator instances)

  • HAL_COMP_WINDOW_SetUpperThreshold(): Unitary configuration: Set window comparators input minus configuration (for comparator instance assigned to upper threshold)

  • HAL_COMP_WINDOW_GetUpperThreshold(): Unitary configuration: Set window comparators input minus configuration (for comparator instance assigned to upper threshold)

  • HAL_COMP_WINDOW_SetLowerThreshold(): Unitary configuration: Set window comparators input minus configuration (for comparator instance assigned to lower threshold)

  • HAL_COMP_WINDOW_GetLowerThreshold(): Unitary configuration: Set window comparators input minus configuration (for comparator instance assigned to lower threshold)

  • HAL_COMP_WINDOW_SetOutputBlanking(): Unitary configuration: Set window comparators output blanking (optional).

  • HAL_COMP_WINDOW_GetOutputBlanking(): Unitary configuration: Get window comparators output blanking (optional).

Functions

hal_status_t HAL_COMP_SetConfig ( hal_comp_handle_t * hcomp , const hal_comp_config_t * p_config )

Configure comparator.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

void HAL_COMP_GetConfig ( const hal_comp_handle_t * hcomp , hal_comp_config_t * p_config )

Get comparator configuration.

Parameters :
hal_status_t HAL_COMP_SetInputPlus ( hal_comp_handle_t * hcomp , hal_comp_input_plus_t input_plus )

Set comparator input plus configuration.

Parameters :
Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_comp_input_plus_t HAL_COMP_GetInputPlus ( const hal_comp_handle_t * hcomp )

Get comparator input plus configuration.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_input_plus_t – Comparator input plus value.

hal_status_t HAL_COMP_SetInputMinus ( hal_comp_handle_t * hcomp , hal_comp_input_minus_t input_minus )

Set comparator input minus configuration.

Parameters :
Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_comp_input_minus_t HAL_COMP_GetInputMinus ( const hal_comp_handle_t * hcomp )

Get comparator input minus configuration.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_input_minus_t – Comparator input minus value.

hal_status_t HAL_COMP_SetOutputBlanking ( hal_comp_handle_t * hcomp , hal_comp_output_blank_t output_blank )

Set comparator output blanking.

Parameters :
Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_comp_output_blank_t HAL_COMP_GetOutputBlanking ( hal_comp_handle_t * hcomp )

Get comparator output blanking.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_output_blank_t – Comparator output blanking value.

IRQHandler and Callbacks functions

group COMP_Exported_Functions_Group3

Set of function to handle the COMP interrupts :

Functions

void HAL_COMP_IRQHandler ( hal_comp_handle_t * hcomp )

Handle the COMP interrupt request.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

void HAL_COMP_OutputTriggerCallback ( hal_comp_handle_t * hcomp )

Event callback.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure

hal_status_t HAL_COMP_RegisterOutputTriggerCallback ( hal_comp_handle_t * hcomp , hal_comp_cb_t p_callback )

Register the COMP output trigger callback to be used instead of the weak HAL_COMP_OutputTriggerCallback() predefined callback.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

Peripheral State, Error functions

group COMP_Exported_Functions_Group4

Set of function to handle the HAL COMP driver state and errors:

Functions

hal_comp_state_t HAL_COMP_GetState ( const hal_comp_handle_t * hcomp )

Retrieve the HAL COMP global state.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_state_t – HAL COMP global state.

Process functions

group COMP_Exported_Functions_Group5

Set of functions to operate COMPx peripheral.

  • HAL_COMP_Start(): Start comparator.

  • HAL_COMP_Stop(): Stop comparator.

  • HAL_COMP_Start_IT(): Start comparator with interrupt.

  • HAL_COMP_Stop_IT(): Stop comparator with interrupt.

  • HAL_COMP_Lock(): Lock comparator.

  • HAL_COMP_IsLocked(): Check whether comparator is locked.

  • HAL_COMP_GetOutputLevel(): Get comparator output logical level.

  • HAL_COMP_WINDOW_Start(): Start window comparators.

  • HAL_COMP_WINDOW_Stop(): Stop window comparators.

  • HAL_COMP_WINDOW_Start_IT(): Start window comparators with interrupt.

  • HAL_COMP_WINDOW_Stop_IT(): Stop window comparators with interrupt.

  • HAL_COMP_WINDOW_Lock(): Lock window comparators.

  • HAL_COMP_WINDOW_IsLocked(): Check whether window comparators is locked.

  • HAL_COMP_WINDOW_GetOutputLevel(): Get window comparators output logical level.

Functions

hal_status_t HAL_COMP_Start ( hal_comp_handle_t * hcomp )

Start comparator.

Note

Depending on configuration of output trigger to system ( hal_comp_output_trigger_t), comparator can generate events to system. Output trigger edge selection is optional (selected parameter can be no trigger).

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure

Return values :
  • HAL_BUSY – HAL COMP state machine not in expected initial state

  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_Stop ( hal_comp_handle_t * hcomp )

Stop comparator.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_Start_IT ( hal_comp_handle_t * hcomp )

Start comparator with interrupt: default interrupts.

Note

Depending on configuration of output trigger to system hal_comp_output_trigger_t, comparator can generate events and interrupt to system. Output trigger edge selection is mandatory (selected parameter must be different of no trigger).

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :
  • HAL_BUSY – HAL COMP state machine not in expected initial state

  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_Stop_IT ( hal_comp_handle_t * hcomp )

Stop comparator in interrupt mode.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_Lock ( hal_comp_handle_t * hcomp )

Lock comparator.

Note

Once locked, comparator configuration cannot be changed (use case: safety purpose).

Note

Comparator can be unlocked with a system reset.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_comp_lock_status_t HAL_COMP_IsLocked ( hal_comp_handle_t * hcomp )

Check whether comparator is locked.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

Value – of hal_comp_lock_status_t.

hal_comp_output_level_t HAL_COMP_GetOutputLevel ( hal_comp_handle_t * hcomp )

Get comparator output logical level.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

Value – of hal_comp_output_level_t.

User data functions

group COMP_Exported_Functions_Group6

This subsection provides functions to:

Note

A typical usage is to set user data pointer before starting a process, then retrieve it within the user process completion callback.

Functions

void HAL_COMP_SetUserData ( hal_comp_handle_t * hcomp , const void * p_user_data )

Store user data pointer into the comp handle.

Parameters :
  • hcomp – Pointer to a hal_comp_handle_t.

  • p_user_data – Pointer to the user data.

const void * HAL_COMP_GetUserData ( const hal_comp_handle_t * hcomp )

Retrieve user data pointer from the comp handle.

Parameters :

hcomp – Pointer to a hal_comp_handle_t.

Return values :
  • (void*) – the pointer to the user data, when previously set by HAL_COMP_SetUserData().

  • NULL – other way.