Senior Design: Sound Monitor / STM32L4xx_HAL_Driver
Embed: (wiki syntax)

« Back to documentation index

stm32l4xx_hal_comp.c File Reference

stm32l4xx_hal_comp.c File Reference

COMP HAL module driver. This file provides firmware functions to manage the following functionalities of the COMP peripheral: + Initialization and de-initialization functions + Start/Stop operation functions in polling mode. + Start/Stop operation functions in interrupt mode. + Peripheral Control functions + Peripheral State functions. More...

Go to the source code of this file.

Functions

HAL_StatusTypeDef HAL_COMP_Init (COMP_HandleTypeDef *hcomp)
 Initialize the COMP according to the specified parameters in the COMP_InitTypeDef and initialize the associated handle.
HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp)
 DeInitialize the COMP peripheral.
__weak void HAL_COMP_MspInit (COMP_HandleTypeDef *hcomp)
 Initialize the COMP MSP.
__weak void HAL_COMP_MspDeInit (COMP_HandleTypeDef *hcomp)
 DeInitialize the COMP MSP.
HAL_StatusTypeDef HAL_COMP_Start (COMP_HandleTypeDef *hcomp)
 Start the comparator.
HAL_StatusTypeDef HAL_COMP_Stop (COMP_HandleTypeDef *hcomp)
 Stop the comparator.
HAL_StatusTypeDef HAL_COMP_Start_IT (COMP_HandleTypeDef *hcomp)
 Start the comparator in Interrupt mode.
HAL_StatusTypeDef HAL_COMP_Stop_IT (COMP_HandleTypeDef *hcomp)
 Stop the comparator in Interrupt mode.
void HAL_COMP_IRQHandler (COMP_HandleTypeDef *hcomp)
 Comparator IRQ Handler.
HAL_StatusTypeDef HAL_COMP_Lock (COMP_HandleTypeDef *hcomp)
 Lock the selected comparator configuration.
uint32_t HAL_COMP_GetOutputLevel (COMP_HandleTypeDef *hcomp)
 Return the output level (high or low) of the selected comparator.
__weak void HAL_COMP_TriggerCallback (COMP_HandleTypeDef *hcomp)
 Comparator callback.
HAL_COMP_StateTypeDef HAL_COMP_GetState (COMP_HandleTypeDef *hcomp)
 Return the COMP handle state.

Detailed Description

COMP HAL module driver. This file provides firmware functions to manage the following functionalities of the COMP peripheral: + Initialization and de-initialization functions + Start/Stop operation functions in polling mode. + Start/Stop operation functions in interrupt mode. + Peripheral Control functions + Peripheral State functions.

Author:
MCD Application Team
Version:
V1.1.0
Date:
16-September-2015
================================================================================
          ##### COMP Peripheral features #####
================================================================================
           
  [..]       
      The STM32L4xx device family integrates two analog comparators COMP1 and COMP2:
      (#) The non inverting input and inverting input can be set to GPIO pins
          as shown in Table 1. COMP Inputs below.
  
      (#) The COMP output is not configurable by the HAL COMP as on STM32F3 and STM32F0 
          series: redirection to TIMER peripheral is to set with HAL TIM input remapping functions.
  
      (#) The COMP output level is available using HAL_COMP_GetOutputLevel()
          and can be set on GPIO pins. Refer to Table 2. COMP Outputs below.
  
      (#) The comparators COMP1 and COMP2 can be combined in window mode.
  
      (#) The comparators COMP1 and COMP2 have interrupt capability with wake-up
          from Sleep and Stop modes (through the EXTI controller):
          (++) COMP1 is internally connected to EXTI Line 21
          (++) COMP2 is internally connected to EXTI Line 22

          From the corresponding IRQ handler, the right interrupt source can be retrieved with the 
          macros __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().


[..] Table 1. COMP Inputs for the STM32L4xx devices
 (+)  +---------------------------------------------------------+     
 (+)  |                        |                | COMP1 | COMP2 | 
 (+)  |------------------------|----------------|---------------|
 (+)  |                        | 1/4 VREFINT    |  OK   |  OK   |  
 (+)  |                        | 1/2 VREFINT    |  OK   |  OK   |
 (+)  |                        | 3/4 VREFINT    |  OK   |  OK   |
 (+)  | Inverting Input        | VREFINT        |  OK   |  OK   | 
 (+)  | (minus)                | DAC1 OUT       |  OK   |  OK   |  
 (+)  |                        | DAC2 OUT       |  OK   |  OK   |  
 (+)  |                        | IO1            |  PB1  |  PB3  |  
 (+)  |                        | IO2            |  PC4  |  PB7  |  
 (+)  |------------------------|----------------|-------|-------|
 (+)  |  Non Inverting Input   | IO1            |  PC5  |  PB4  |  
 (+)  |  (plus)                | IO2            |  PB2  |  PB6  |
 (+)  +--------------------------------------------------+  
  
 [..] Table 2. COMP Outputs for the STM32L4xx devices
 (+)   +------------------------------------+     
 (+)   |       COMP1      |      COMP2      | 
 (+)   |------------------|-----------------|
 (+)   |      PB0 (AF)    |     PB5 (AF)    | 
 (+)   |      PB10 (AF)   |     PB11 (AF)   | 
 (+)   |------------------|-----------------|
 (+)   |  Embedded TIMERS | Embedded TIMERS | 
 (+)   |  (cf. HAL TIM)   | (cf. HAL TIM)   | 
 (+)   +------------------------------------+

    
            ##### How to use this driver #####
================================================================================
  [..]
      This driver provides functions to configure and program the Comparators of all STM32L4xx devices.

      To use the comparator, perform the following steps:
  
      (#)  Initialize the COMP low level resources by implementing the HAL_COMP_MspInit():
      (++) Configure the inverting and non-inverting comparator inputs in analog mode using HAL_GPIO_Init().
      (++) Configure the comparator output in alternate function mode using HAL_GPIO_Init() to map the comparator 
           output to the GPIO pin.
      (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and 
           selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
           interrupt vector using HAL_NVIC_EnableIRQ() function.
  
      (#) Configure the comparator using HAL_COMP_Init() function:
      (++) Select the inverting input (input minus)
      (++) Select the non-inverting input (input plus)
      (++) Select the hysteresis
      (++) Select the blanking source
      (++) Select the output polarity  
      (++) Select the power mode
      (++) Select the window mode

      -@@- HAL_COMP_Init() calls internally __HAL_RCC_SYSCFG_CLK_ENABLE() in order
          to enable the comparator(s).

      (#) On-the-fly reconfiguration of comparator(s) may be done by calling again HAL_COMP_Init(
          function with new input parameter values; HAL_COMP_MspInit() function shall be adapted 
          to support multi configurations.

      (#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT() functions.
    
      (#) Use HAL_COMP_TriggerCallback() and/or HAL_COMP_GetOutputLevel() functions
          to manage comparator outputs (events and output level).

      (#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT() 
          function.

      (#) De-initialize the comparator using HAL_COMP_DeInit() function.

      (#) For safety purposes comparator(s) can be locked using HAL_COMP_Lock() function.
          Only a MCU reset can reset that protection.
      
  
Attention:

© COPYRIGHT(c) 2015 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file stm32l4xx_hal_comp.c.