HAL COMP Functions

Initialization and de-initialization functions

group COMP_Exported_Functions_Group1

Set of functions allowing to initialize and deinitialize the COMPx peripheral:

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 can not 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.

hal_status_t HAL_COMP_WINDOW_SetHandle ( hal_comp_handle_t * hcomp_upper , hal_comp_handle_t * hcomp_lower )

Link HAL COMP handles sharing common features (window mode).

Note

Link can be performed even if not using the common features. It is recommended to systematically link handles (when compliant instances): this allows functions to perform all cross instances checks possible, for optimal HAL COMP driver usage.

Note

Links are used to access multiple HAL COMP handles (daisy chain: from one to another and circular). Used by functions configuring parameters impacting multiple COMP instances.

Note

A handle can be removed from a chain using function HAL_COMP_DeInit() .

Warning

Requirement: the selected device must have at least 2 COMP instances sharing the same COMP common instance. Refer to device reference manual of COMP LL driver macro “LL_COMP_COMMON_INSTANCE()” returning COMP common instance from COMP instance.

Parameters :
  • hcomp_upper – Pointer to hal_comp_handle_t structure of a COMP instance (not yet linked or already linked to a chain).

  • hcomp_lower – Pointer to hal_comp_handle_t structure of another COMP instance sharing common features (not yet linked: to be added to an existing chain).

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

Configuration functions

group COMP_Exported_Functions_Group2

Set of functions allowing to configure COMPx peripheral:

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.

hal_status_t HAL_COMP_WINDOW_SetConfig ( hal_comp_handle_t * hcomp , const hal_comp_window_config_t * p_config )

Configure comparators in window mode.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

void HAL_COMP_WINDOW_GetConfig ( const hal_comp_handle_t * hcomp , hal_comp_window_config_t * p_config )

Get window comparators configuration.

Parameters :
hal_status_t HAL_COMP_WINDOW_SetInput ( hal_comp_handle_t * hcomp , hal_comp_input_plus_t input )

Set window comparators input plus configuration (common to both comparator instances).

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

  • HAL_OK – Operation completed successfully.

hal_comp_input_plus_t HAL_COMP_WINDOW_GetInput ( const hal_comp_handle_t * hcomp )

Get window comparators input plus configuration (common to both comparator instances).

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_input_plus_t – Window comparators input plus value.

hal_status_t HAL_COMP_WINDOW_SetUpperThreshold ( hal_comp_handle_t * hcomp , hal_comp_input_minus_t upper_threshold )

Set window comparators input minus configuration (for comparator instance assigned to upper threshold).

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

  • HAL_OK – Operation completed successfully.

hal_comp_input_minus_t HAL_COMP_WINDOW_GetUpperThreshold ( const hal_comp_handle_t * hcomp )

Get window comparators input minus configuration (for comparator instance assigned to upper threshold).

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_input_minus_t – Window comparators input minus value.

hal_status_t HAL_COMP_WINDOW_SetLowerThreshold ( hal_comp_handle_t * hcomp , hal_comp_input_minus_t lower_threshold )

Set window comparators input minus configuration (for comparator instance assigned to lower threshold).

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

  • HAL_OK – Operation completed successfully.

hal_comp_input_minus_t HAL_COMP_WINDOW_GetLowerThreshold ( const hal_comp_handle_t * hcomp )

Get window comparators input minus configuration (for comparator instance assigned to lower threshold).

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_input_minus_t – Window comparators input minus value.

hal_status_t HAL_COMP_WINDOW_SetOutputBlanking ( hal_comp_handle_t * hcomp , hal_comp_output_blank_t output_blank )

Set window comparators output blanking.

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

  • HAL_OK – Operation completed successfully.

hal_comp_output_blank_t HAL_COMP_WINDOW_GetOutputBlanking ( const hal_comp_handle_t * hcomp )

Get window comparators output blanking.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

hal_comp_output_blank_t – Window comparators output blanking value.

IRQHandler and Callbacks functions

group COMP_Exported_Functions_Group3

Set of function to handle the COMP interruptions :

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:

  • HAL_COMP_GetState() : Retrieve the HAL COMP global state,

  • HAL_COMP_GetEXTI_Handle(): Retrieve the HAL EXTI handle used by the selected HAL COMP handle.

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 allowing to operate COMPx peripheral.

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 interruption: default interruptions.

Note

Depending on configuration of output trigger to system hal_comp_output_trigger_t , comparator can generate events and interruption 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 interruption 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 .

hal_status_t HAL_COMP_WINDOW_Start ( hal_comp_handle_t * hcomp )

Start window comparators.

Depending on configuration of output trigger to system hal_comp_output_trigger_t , comparator can generate events to system.

Parameters :

hcomp – Pointer to a HAL_COMP_WINDOW_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_WINDOW_Stop ( hal_comp_handle_t * hcomp )

Stop window comparators.

Parameters :

hcomp – Pointer to a HAL_COMP_WINDOW_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_WINDOW_Start_IT ( hal_comp_handle_t * hcomp )

Start window comparators with interruption: default interruptions.

Note

Configuration prerequisite: select comparator output trigger ( hal_comp_output_trigger_t ) with setting 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_WINDOW_Stop_IT ( hal_comp_handle_t * hcomp )

Stop window comparators in interruption mode.

Parameters :

hcomp – Pointer to a HAL_COMP_WINDOW_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_status_t HAL_COMP_WINDOW_Lock ( hal_comp_handle_t * hcomp )

Lock window comparators.

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_WINDOW_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error.

  • HAL_OK – Operation completed successfully.

hal_comp_lock_status_t HAL_COMP_WINDOW_IsLocked ( hal_comp_handle_t * hcomp )

Check whether window comparators are locked.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

Value – of hal_comp_lock_status_t .

hal_comp_window_output_level_t HAL_COMP_WINDOW_GetOutputLevel ( hal_comp_handle_t * hcomp )

Get window comparators output logical level.

Parameters :

hcomp – Pointer to a hal_comp_handle_t structure.

Return values :

Value – of hal_comp_window_output_level_t .

User data functions

group COMP_Exported_Functions_Group6

This subsection provides functions allowing 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 :
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 :