fix LPC812 PWM

Dependents:   IR_LED_Send

Fork of mbed-dev by mbed official

Committer:
nameless129
Date:
Mon May 16 16:50:30 2016 +0000
Revision:
129:2e517c56bcfb
Parent:
0:9b334a45a8ff
PWM Fix:Duty 0%??H???????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /**
bogdanm 0:9b334a45a8ff 2 ******************************************************************************
bogdanm 0:9b334a45a8ff 3 * @file stm32f3xx_hal_comp.c
bogdanm 0:9b334a45a8ff 4 * @author MCD Application Team
bogdanm 0:9b334a45a8ff 5 * @version V1.1.0
bogdanm 0:9b334a45a8ff 6 * @date 12-Sept-2014
bogdanm 0:9b334a45a8ff 7 * @brief COMP HAL module driver.
bogdanm 0:9b334a45a8ff 8 *
bogdanm 0:9b334a45a8ff 9 * This file provides firmware functions to manage the following
bogdanm 0:9b334a45a8ff 10 * functionalities of the COMP peripheral:
bogdanm 0:9b334a45a8ff 11 * + Initialization/de-initialization functions
bogdanm 0:9b334a45a8ff 12 * + I/O operation functions
bogdanm 0:9b334a45a8ff 13 * + Peripheral Control functions
bogdanm 0:9b334a45a8ff 14 * + Peripheral State functions
bogdanm 0:9b334a45a8ff 15 *
bogdanm 0:9b334a45a8ff 16 @verbatim
bogdanm 0:9b334a45a8ff 17 ================================================================================
bogdanm 0:9b334a45a8ff 18 ##### COMP Peripheral features #####
bogdanm 0:9b334a45a8ff 19 ================================================================================
bogdanm 0:9b334a45a8ff 20
bogdanm 0:9b334a45a8ff 21 [..]
bogdanm 0:9b334a45a8ff 22 The STM32F3xx device family integrates up to 7 analog comparators COMP1, COMP2...COMP7:
bogdanm 0:9b334a45a8ff 23 (#) The non inverting input and inverting input can be set to GPIO pins
bogdanm 0:9b334a45a8ff 24 as shown in table1. COMP Inputs below for STM32F303xB/STM32F303xC as example.
bogdanm 0:9b334a45a8ff 25 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
bogdanm 0:9b334a45a8ff 26 Reference Manual.
bogdanm 0:9b334a45a8ff 27
bogdanm 0:9b334a45a8ff 28 (#) The COMP output is available using HAL_COMP_GetOutputLevel()
bogdanm 0:9b334a45a8ff 29 and can be set on GPIO pins. Refer to table 2. COMP Outputs below for STM32F303xB/STM32F303xC as example.
bogdanm 0:9b334a45a8ff 30 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
bogdanm 0:9b334a45a8ff 31 Reference Manual.
bogdanm 0:9b334a45a8ff 32
bogdanm 0:9b334a45a8ff 33 (#) The COMP output can be redirected to embedded timers (TIM1, TIM2, TIM3...)
bogdanm 0:9b334a45a8ff 34 Refer to table 3. COMP Outputs redirection to embedded timers below for STM32F303xB/STM32F303xC as example.
bogdanm 0:9b334a45a8ff 35 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
bogdanm 0:9b334a45a8ff 36 Reference Manual.
bogdanm 0:9b334a45a8ff 37
bogdanm 0:9b334a45a8ff 38 (#) The comparators COMP1 and COMP2, COMP3 and COMP4, COMP5 and COMP6 can be combined in window
bogdanm 0:9b334a45a8ff 39 mode and only COMP1, COMP3 and COMP5 non inverting input can be used as non-inverting input.
bogdanm 0:9b334a45a8ff 40
bogdanm 0:9b334a45a8ff 41 (#) The seven comparators have interrupt capability with wake-up
bogdanm 0:9b334a45a8ff 42 from Sleep and Stop modes (through the EXTI controller):
bogdanm 0:9b334a45a8ff 43 (++) COMP1 is internally connected to EXTI Line 21
bogdanm 0:9b334a45a8ff 44 (++) COMP2 is internally connected to EXTI Line 22
bogdanm 0:9b334a45a8ff 45 (++) COMP3 is internally connected to EXTI Line 29
bogdanm 0:9b334a45a8ff 46 (++) COMP4 is internally connected to EXTI Line 30
bogdanm 0:9b334a45a8ff 47 (++) COMP5 is internally connected to EXTI Line 31
bogdanm 0:9b334a45a8ff 48 (++) COMP6 is internally connected to EXTI Line 32
bogdanm 0:9b334a45a8ff 49 (++) COMP7 is internally connected to EXTI Line 33
bogdanm 0:9b334a45a8ff 50 From the corresponding IRQ handler, the right interrupt source can be retrieved with the
bogdanm 0:9b334a45a8ff 51 macro __HAL_COMP_EXTI_GET_FLAG(). Possible values are:
bogdanm 0:9b334a45a8ff 52 (++) COMP_EXTI_LINE_COMP1_EVENT
bogdanm 0:9b334a45a8ff 53 (++) COMP_EXTI_LINE_COMP2_EVENT
bogdanm 0:9b334a45a8ff 54 (++) COMP_EXTI_LINE_COMP3_EVENT
bogdanm 0:9b334a45a8ff 55 (++) COMP_EXTI_LINE_COMP4_EVENT
bogdanm 0:9b334a45a8ff 56 (++) COMP_EXTI_LINE_COMP5_EVENT
bogdanm 0:9b334a45a8ff 57 (++) COMP_EXTI_LINE_COMP6_EVENT
bogdanm 0:9b334a45a8ff 58 (++) COMP_EXTI_LINE_COMP7_EVENT
bogdanm 0:9b334a45a8ff 59
bogdanm 0:9b334a45a8ff 60 [..] Table 1. COMP Inputs for the STM32F303xB/STM32F303xC/STM32F303xE devices
bogdanm 0:9b334a45a8ff 61 +------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 62 | | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
bogdanm 0:9b334a45a8ff 63 |-----------------|----------------|---------------|---------------------------------------|
bogdanm 0:9b334a45a8ff 64 | | 1/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 65 | | 1/2 VREFINT | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 66 | | 3/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 67 | Inverting Input | VREFINT | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 68 | | DAC1 OUT (PA4) | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 69 | | DAC2 OUT (PA5) | OK | OK | OK | OK | OK | OK | OK |
bogdanm 0:9b334a45a8ff 70 | | IO1 | PA0 | PA2 | PD15 | PE8 | PD13 | PD10 | PC0 |
bogdanm 0:9b334a45a8ff 71 | | IO2 | --- | --- | PB12 | PB2 | PB10 | PB15 | --- |
bogdanm 0:9b334a45a8ff 72 |-----------------|----------------|-------|-------|-------|-------|-------|-------|-------|
bogdanm 0:9b334a45a8ff 73 | Non Inverting | IO1 | PA1 | PA7 | PB14 | PB0 | PD12 | PD11 | PA0 |
bogdanm 0:9b334a45a8ff 74 | Input | IO2 | --- | PA3 | PD14 | PE7 | PB13 | PB11 | PC1 |
bogdanm 0:9b334a45a8ff 75 +------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 76
bogdanm 0:9b334a45a8ff 77 [..] Table 2. COMP Outputs for the STM32F303xB/STM32F303xC/STM32F303xE devices
bogdanm 0:9b334a45a8ff 78 +-------------------------------------------------------+
bogdanm 0:9b334a45a8ff 79 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
bogdanm 0:9b334a45a8ff 80 |-------|-------|-------|-------|-------|-------|-------|
bogdanm 0:9b334a45a8ff 81 | PA0 | PA2 | PB1 | PC8 | PC7 | PA10 | PC2 |
bogdanm 0:9b334a45a8ff 82 | PF4 | PA7 | --- | PA8 | PA9 | PC6 | --- |
bogdanm 0:9b334a45a8ff 83 | PA6 | PA12 | --- | --- | --- | --- | --- |
bogdanm 0:9b334a45a8ff 84 | PA11 | PB9 | --- | --- | --- | --- | --- |
bogdanm 0:9b334a45a8ff 85 | PB8 | --- | --- | --- | --- | --- | --- |
bogdanm 0:9b334a45a8ff 86 +-------------------------------------------------------+
bogdanm 0:9b334a45a8ff 87
bogdanm 0:9b334a45a8ff 88 [..] Table 3. COMP Outputs redirection to embedded timers for the STM32F303xB/STM32F303xC devices
bogdanm 0:9b334a45a8ff 89 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 90 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
bogdanm 0:9b334a45a8ff 91 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
bogdanm 0:9b334a45a8ff 92 | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN |
bogdanm 0:9b334a45a8ff 93 | | | | | | | |
bogdanm 0:9b334a45a8ff 94 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
bogdanm 0:9b334a45a8ff 95 | | | | | | | |
bogdanm 0:9b334a45a8ff 96 | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN |
bogdanm 0:9b334a45a8ff 97 | | | | | | | |
bogdanm 0:9b334a45a8ff 98 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
bogdanm 0:9b334a45a8ff 99 | | | | | | | |
bogdanm 0:9b334a45a8ff 100 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
bogdanm 0:9b334a45a8ff 101 | + | + | + | + | + | + | + |
bogdanm 0:9b334a45a8ff 102 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 |
bogdanm 0:9b334a45a8ff 103 | | | | | | | |
bogdanm 0:9b334a45a8ff 104 | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR |
bogdanm 0:9b334a45a8ff 105 | | | | | | | |
bogdanm 0:9b334a45a8ff 106 | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR |
bogdanm 0:9b334a45a8ff 107 | | | | | | | |
bogdanm 0:9b334a45a8ff 108 | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 |
bogdanm 0:9b334a45a8ff 109 | | | | | | | |
bogdanm 0:9b334a45a8ff 110 | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 |
bogdanm 0:9b334a45a8ff 111 | | | | | | | |
bogdanm 0:9b334a45a8ff 112 | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR|
bogdanm 0:9b334a45a8ff 113 | | | | | | | |
bogdanm 0:9b334a45a8ff 114 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN |
bogdanm 0:9b334a45a8ff 115 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 116
bogdanm 0:9b334a45a8ff 117 [..] Table 4. COMP Outputs redirection to embedded timers for the STM32F303xE devices
bogdanm 0:9b334a45a8ff 118 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 119 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
bogdanm 0:9b334a45a8ff 120 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
bogdanm 0:9b334a45a8ff 121 | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) |
bogdanm 0:9b334a45a8ff 122 | | | | | | | |
bogdanm 0:9b334a45a8ff 123 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
bogdanm 0:9b334a45a8ff 124 | | | | | | | |
bogdanm 0:9b334a45a8ff 125 | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) |
bogdanm 0:9b334a45a8ff 126 | | | | | | | |
bogdanm 0:9b334a45a8ff 127 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
bogdanm 0:9b334a45a8ff 128 | | | | | | | |
bogdanm 0:9b334a45a8ff 129 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
bogdanm 0:9b334a45a8ff 130 | + | + | + | + | + | + | + |
bogdanm 0:9b334a45a8ff 131 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 |
bogdanm 0:9b334a45a8ff 132 | | | | | | | |
bogdanm 0:9b334a45a8ff 133 | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR |
bogdanm 0:9b334a45a8ff 134 | | | | | | | |
bogdanm 0:9b334a45a8ff 135 | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR |
bogdanm 0:9b334a45a8ff 136 | | | | | | | |
bogdanm 0:9b334a45a8ff 137 | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 |
bogdanm 0:9b334a45a8ff 138 | | | | | | | |
bogdanm 0:9b334a45a8ff 139 | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 |
bogdanm 0:9b334a45a8ff 140 | | | | | | | |
bogdanm 0:9b334a45a8ff 141 | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR|
bogdanm 0:9b334a45a8ff 142 | | | | | | | |
bogdanm 0:9b334a45a8ff 143 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN |
bogdanm 0:9b334a45a8ff 144 | | | | | | | |
bogdanm 0:9b334a45a8ff 145 | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)| TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)|
bogdanm 0:9b334a45a8ff 146 | | | | | | | |
bogdanm 0:9b334a45a8ff 147 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 |
bogdanm 0:9b334a45a8ff 148 | | | | | | | |
bogdanm 0:9b334a45a8ff 149 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
bogdanm 0:9b334a45a8ff 150 | + | + | + | + | + | + | + |
bogdanm 0:9b334a45a8ff 151 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
bogdanm 0:9b334a45a8ff 152 | + | + | + | + | + | + | + |
bogdanm 0:9b334a45a8ff 153 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 |
bogdanm 0:9b334a45a8ff 154 | | | | | | | |
bogdanm 0:9b334a45a8ff 155 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 156 (1):This connection consists of connecting both GPIO and COMP output to TIM1/8/20 BRK input through an OR gate, instead
bogdanm 0:9b334a45a8ff 157 of connecting the GPIO to the TIM1/8/20 BRK input and the COMP output to the TIM1/8/20 BRK_ACTH input. The aim is to
bogdanm 0:9b334a45a8ff 158 add a digital filter (3 bits) on the COMP output.
bogdanm 0:9b334a45a8ff 159
bogdanm 0:9b334a45a8ff 160 [..] Table 5. COMP Outputs blanking sources for the STM32F303xB/STM32F303xC/STM32F303xE devices
bogdanm 0:9b334a45a8ff 161 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 162 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
bogdanm 0:9b334a45a8ff 163 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
bogdanm 0:9b334a45a8ff 164 | TIM1 OC5 | TIM1 OC5 | TIM1 OC5 | TIM3 OC4 | -------- | TIM8 OC5 | TIM1 OC5 |
bogdanm 0:9b334a45a8ff 165 | | | | | | | |
bogdanm 0:9b334a45a8ff 166 | TIM2 OC3 | TIM2 OC3 | -------- | TIM8 OC5 | TIM3 OC3 | TIM2 OC4 | TIM8 OC5 |
bogdanm 0:9b334a45a8ff 167 | | | | | | | |
bogdanm 0:9b334a45a8ff 168 | TIM3 OC3 | TIM3 OC3 | TIM2 OC4 | TIM15 OC1 | TIM8 OC5 | TIM15 OC2 | TIM15 OC2 |
bogdanm 0:9b334a45a8ff 169 | | | | | | | |
bogdanm 0:9b334a45a8ff 170 +----------------------------------------------------------------------------------------------------------------------+
bogdanm 0:9b334a45a8ff 171
bogdanm 0:9b334a45a8ff 172 ##### How to use this driver #####
bogdanm 0:9b334a45a8ff 173 ================================================================================
bogdanm 0:9b334a45a8ff 174 [..]
bogdanm 0:9b334a45a8ff 175 This driver provides functions to configure and program the Comparators of all STM32F3xx devices.
bogdanm 0:9b334a45a8ff 176
bogdanm 0:9b334a45a8ff 177 To use the comparator, perform the following steps:
bogdanm 0:9b334a45a8ff 178
bogdanm 0:9b334a45a8ff 179 (#) Fill in the HAL_COMP_MspInit() to
bogdanm 0:9b334a45a8ff 180 (++) Configure the comparator input in analog mode using HAL_GPIO_Init()
bogdanm 0:9b334a45a8ff 181 (++) Configure the comparator output in alternate function mode using HAL_GPIO_Init() to map the comparator
bogdanm 0:9b334a45a8ff 182 output to the GPIO pin
bogdanm 0:9b334a45a8ff 183 (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and
bogdanm 0:9b334a45a8ff 184 selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
bogdanm 0:9b334a45a8ff 185 interrupt vector using HAL_NVIC_EnableIRQ() function.
bogdanm 0:9b334a45a8ff 186
bogdanm 0:9b334a45a8ff 187 (#) Configure the comparator using HAL_COMP_Init() function:
bogdanm 0:9b334a45a8ff 188 (++) Select the inverting input
bogdanm 0:9b334a45a8ff 189 (++) Select the non-inverting input
bogdanm 0:9b334a45a8ff 190 (++) Select the output polarity
bogdanm 0:9b334a45a8ff 191 (++) Select the output redirection
bogdanm 0:9b334a45a8ff 192 (++) Select the hysteresis level
bogdanm 0:9b334a45a8ff 193 (++) Select the power mode
bogdanm 0:9b334a45a8ff 194 (++) Select the event/interrupt mode
bogdanm 0:9b334a45a8ff 195
bogdanm 0:9b334a45a8ff 196 (#) Enable the comparator using HAL_COMP_Start() function or HAL_COMP_Start_IT() function for interrupt mode
bogdanm 0:9b334a45a8ff 197
bogdanm 0:9b334a45a8ff 198 (#) Read the comparator output level with HAL_COMP_GetOutputLevel()
bogdanm 0:9b334a45a8ff 199
bogdanm 0:9b334a45a8ff 200 @endverbatim
bogdanm 0:9b334a45a8ff 201 ******************************************************************************
bogdanm 0:9b334a45a8ff 202 * @attention
bogdanm 0:9b334a45a8ff 203 *
bogdanm 0:9b334a45a8ff 204 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
bogdanm 0:9b334a45a8ff 205 *
bogdanm 0:9b334a45a8ff 206 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 0:9b334a45a8ff 207 * are permitted provided that the following conditions are met:
bogdanm 0:9b334a45a8ff 208 * 1. Redistributions of source code must retain the above copyright notice,
bogdanm 0:9b334a45a8ff 209 * this list of conditions and the following disclaimer.
bogdanm 0:9b334a45a8ff 210 * 2. Redistributions in binary form must reproduce the above copyright notice,
bogdanm 0:9b334a45a8ff 211 * this list of conditions and the following disclaimer in the documentation
bogdanm 0:9b334a45a8ff 212 * and/or other materials provided with the distribution.
bogdanm 0:9b334a45a8ff 213 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bogdanm 0:9b334a45a8ff 214 * may be used to endorse or promote products derived from this software
bogdanm 0:9b334a45a8ff 215 * without specific prior written permission.
bogdanm 0:9b334a45a8ff 216 *
bogdanm 0:9b334a45a8ff 217 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bogdanm 0:9b334a45a8ff 218 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bogdanm 0:9b334a45a8ff 219 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 0:9b334a45a8ff 220 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bogdanm 0:9b334a45a8ff 221 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bogdanm 0:9b334a45a8ff 222 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bogdanm 0:9b334a45a8ff 223 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bogdanm 0:9b334a45a8ff 224 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bogdanm 0:9b334a45a8ff 225 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bogdanm 0:9b334a45a8ff 226 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 0:9b334a45a8ff 227 *
bogdanm 0:9b334a45a8ff 228 ******************************************************************************
bogdanm 0:9b334a45a8ff 229 */
bogdanm 0:9b334a45a8ff 230
bogdanm 0:9b334a45a8ff 231 /* Includes ------------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 232 #include "stm32f3xx_hal.h"
bogdanm 0:9b334a45a8ff 233
bogdanm 0:9b334a45a8ff 234 /** @addtogroup STM32F3xx_HAL_Driver
bogdanm 0:9b334a45a8ff 235 * @{
bogdanm 0:9b334a45a8ff 236 */
bogdanm 0:9b334a45a8ff 237
bogdanm 0:9b334a45a8ff 238 /** @defgroup COMP COMP HAL module driver
bogdanm 0:9b334a45a8ff 239 * @brief COMP HAL module driver
bogdanm 0:9b334a45a8ff 240 * @{
bogdanm 0:9b334a45a8ff 241 */
bogdanm 0:9b334a45a8ff 242
bogdanm 0:9b334a45a8ff 243 #ifdef HAL_COMP_MODULE_ENABLED
bogdanm 0:9b334a45a8ff 244
bogdanm 0:9b334a45a8ff 245 /* Private typedef -----------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 246 /* Private define ------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 247 /* Private macro -------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 248 /* Private variables ---------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 249 /* Private function prototypes -----------------------------------------------*/
bogdanm 0:9b334a45a8ff 250 /* Exported functions --------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 251
bogdanm 0:9b334a45a8ff 252 /** @defgroup COMP_Exported_Functions COMP Exported Functions
bogdanm 0:9b334a45a8ff 253 * @{
bogdanm 0:9b334a45a8ff 254 */
bogdanm 0:9b334a45a8ff 255
bogdanm 0:9b334a45a8ff 256 /** @defgroup COMP_Exported_Functions_Group1 Initialization and de-initialization functions
bogdanm 0:9b334a45a8ff 257 * @brief Initialization and Configuration functions
bogdanm 0:9b334a45a8ff 258 *
bogdanm 0:9b334a45a8ff 259 @verbatim
bogdanm 0:9b334a45a8ff 260 ===============================================================================
bogdanm 0:9b334a45a8ff 261 ##### Initialization/de-initialization functions #####
bogdanm 0:9b334a45a8ff 262 ===============================================================================
bogdanm 0:9b334a45a8ff 263 [..] This section provides functions to initialize and de-initialize comparators
bogdanm 0:9b334a45a8ff 264
bogdanm 0:9b334a45a8ff 265 @endverbatim
bogdanm 0:9b334a45a8ff 266 * @{
bogdanm 0:9b334a45a8ff 267 */
bogdanm 0:9b334a45a8ff 268
bogdanm 0:9b334a45a8ff 269 /**
bogdanm 0:9b334a45a8ff 270 * @brief Initializes the COMP according to the specified
bogdanm 0:9b334a45a8ff 271 * parameters in the COMP_InitTypeDef and create the associated handle.
bogdanm 0:9b334a45a8ff 272 * @note If the selected comparator is locked, initialization can't be performed.
bogdanm 0:9b334a45a8ff 273 * To unlock the configuration, perform a system reset.
bogdanm 0:9b334a45a8ff 274 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 275 * @retval HAL status
bogdanm 0:9b334a45a8ff 276 */
bogdanm 0:9b334a45a8ff 277 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 278 {
bogdanm 0:9b334a45a8ff 279 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 280
bogdanm 0:9b334a45a8ff 281 /* Check the COMP handle allocation and lock status */
bogdanm 0:9b334a45a8ff 282 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
bogdanm 0:9b334a45a8ff 283 {
bogdanm 0:9b334a45a8ff 284 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 285 }
bogdanm 0:9b334a45a8ff 286 else
bogdanm 0:9b334a45a8ff 287 {
bogdanm 0:9b334a45a8ff 288 /* Check the parameter */
bogdanm 0:9b334a45a8ff 289 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 290 assert_param(IS_COMP_INVERTINGINPUT(hcomp->Init.InvertingInput));
bogdanm 0:9b334a45a8ff 291 assert_param(IS_COMP_NONINVERTINGINPUT(hcomp->Init.NonInvertingInput));
bogdanm 0:9b334a45a8ff 292 assert_param(IS_COMP_NONINVERTINGINPUT_INSTANCE(hcomp->Instance, hcomp->Init.NonInvertingInput));
bogdanm 0:9b334a45a8ff 293 assert_param(IS_COMP_OUTPUT(hcomp->Init.Output));
bogdanm 0:9b334a45a8ff 294 assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
bogdanm 0:9b334a45a8ff 295 assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
bogdanm 0:9b334a45a8ff 296 assert_param(IS_COMP_MODE(hcomp->Init.Mode));
bogdanm 0:9b334a45a8ff 297 assert_param(IS_COMP_BLANKINGSRCE(hcomp->Init.BlankingSrce));
bogdanm 0:9b334a45a8ff 298 assert_param(IS_COMP_BLANKINGSRCE_INSTANCE(hcomp->Instance, hcomp->Init.BlankingSrce));
bogdanm 0:9b334a45a8ff 299
bogdanm 0:9b334a45a8ff 300 if(hcomp->Init.WindowMode != COMP_WINDOWMODE_DISABLED)
bogdanm 0:9b334a45a8ff 301 {
bogdanm 0:9b334a45a8ff 302 assert_param(IS_COMP_WINDOWMODE_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 303 }
bogdanm 0:9b334a45a8ff 304
bogdanm 0:9b334a45a8ff 305 if(hcomp->State == HAL_COMP_STATE_RESET)
bogdanm 0:9b334a45a8ff 306 {
bogdanm 0:9b334a45a8ff 307 /* Init SYSCFG and the low level hardware to access comparators */
bogdanm 0:9b334a45a8ff 308 __SYSCFG_CLK_ENABLE();
bogdanm 0:9b334a45a8ff 309
bogdanm 0:9b334a45a8ff 310 HAL_COMP_MspInit(hcomp);
bogdanm 0:9b334a45a8ff 311 }
bogdanm 0:9b334a45a8ff 312
bogdanm 0:9b334a45a8ff 313 /* Set COMP parameters */
bogdanm 0:9b334a45a8ff 314 /* Set COMPxINSEL bits according to hcomp->Init.InvertingInput value */
bogdanm 0:9b334a45a8ff 315 /* Set COMPxNONINSEL bits according to hcomp->Init.NonInvertingInput value */
bogdanm 0:9b334a45a8ff 316 /* Set COMPxBLANKING bits according to hcomp->Init.BlankingSrce value */
bogdanm 0:9b334a45a8ff 317 /* Set COMPxOUTSEL bits according to hcomp->Init.Output value */
bogdanm 0:9b334a45a8ff 318 /* Set COMPxPOL bit according to hcomp->Init.OutputPol value */
bogdanm 0:9b334a45a8ff 319 /* Set COMPxHYST bits according to hcomp->Init.Hysteresis value */
bogdanm 0:9b334a45a8ff 320 /* Set COMPxMODE bits according to hcomp->Init.Mode value */
bogdanm 0:9b334a45a8ff 321 COMP_INIT(hcomp);
bogdanm 0:9b334a45a8ff 322
bogdanm 0:9b334a45a8ff 323 /* Initialize the COMP state*/
bogdanm 0:9b334a45a8ff 324 if(hcomp->State == HAL_COMP_STATE_RESET)
bogdanm 0:9b334a45a8ff 325 {
bogdanm 0:9b334a45a8ff 326 hcomp->State = HAL_COMP_STATE_READY;
bogdanm 0:9b334a45a8ff 327 }
bogdanm 0:9b334a45a8ff 328 }
bogdanm 0:9b334a45a8ff 329
bogdanm 0:9b334a45a8ff 330 return status;
bogdanm 0:9b334a45a8ff 331 }
bogdanm 0:9b334a45a8ff 332
bogdanm 0:9b334a45a8ff 333 /**
bogdanm 0:9b334a45a8ff 334 * @brief DeInitializes the COMP peripheral
bogdanm 0:9b334a45a8ff 335 * @note Deinitialization can't be performed if the COMP configuration is locked.
bogdanm 0:9b334a45a8ff 336 * To unlock the configuration, perform a system reset.
bogdanm 0:9b334a45a8ff 337 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 338 * @retval HAL status
bogdanm 0:9b334a45a8ff 339 */
bogdanm 0:9b334a45a8ff 340 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 341 {
bogdanm 0:9b334a45a8ff 342 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 343
bogdanm 0:9b334a45a8ff 344 /* Check the COMP handle allocation and lock status */
bogdanm 0:9b334a45a8ff 345 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
bogdanm 0:9b334a45a8ff 346 {
bogdanm 0:9b334a45a8ff 347 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 348 }
bogdanm 0:9b334a45a8ff 349 else
bogdanm 0:9b334a45a8ff 350 {
bogdanm 0:9b334a45a8ff 351 /* Check the parameter */
bogdanm 0:9b334a45a8ff 352 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 353
bogdanm 0:9b334a45a8ff 354 /* Set COMP_CSR register to reset value */
bogdanm 0:9b334a45a8ff 355 COMP_DEINIT(hcomp);
bogdanm 0:9b334a45a8ff 356
bogdanm 0:9b334a45a8ff 357 /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
bogdanm 0:9b334a45a8ff 358 HAL_COMP_MspDeInit(hcomp);
bogdanm 0:9b334a45a8ff 359
bogdanm 0:9b334a45a8ff 360 hcomp->State = HAL_COMP_STATE_RESET;
bogdanm 0:9b334a45a8ff 361 }
bogdanm 0:9b334a45a8ff 362
bogdanm 0:9b334a45a8ff 363 return status;
bogdanm 0:9b334a45a8ff 364 }
bogdanm 0:9b334a45a8ff 365
bogdanm 0:9b334a45a8ff 366 /**
bogdanm 0:9b334a45a8ff 367 * @brief Initializes the COMP MSP.
bogdanm 0:9b334a45a8ff 368 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 369 * @retval None
bogdanm 0:9b334a45a8ff 370 */
bogdanm 0:9b334a45a8ff 371 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 372 {
bogdanm 0:9b334a45a8ff 373 /* NOTE : This function Should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 374 the HAL_COMP_MspInit could be implemented in the user file
bogdanm 0:9b334a45a8ff 375 */
bogdanm 0:9b334a45a8ff 376 }
bogdanm 0:9b334a45a8ff 377
bogdanm 0:9b334a45a8ff 378 /**
bogdanm 0:9b334a45a8ff 379 * @brief DeInitializes COMP MSP.
bogdanm 0:9b334a45a8ff 380 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 381 * @retval None
bogdanm 0:9b334a45a8ff 382 */
bogdanm 0:9b334a45a8ff 383 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 384 {
bogdanm 0:9b334a45a8ff 385 /* NOTE : This function Should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 386 the HAL_COMP_MspDeInit could be implenetd in the user file
bogdanm 0:9b334a45a8ff 387 */
bogdanm 0:9b334a45a8ff 388 }
bogdanm 0:9b334a45a8ff 389
bogdanm 0:9b334a45a8ff 390 /**
bogdanm 0:9b334a45a8ff 391 * @}
bogdanm 0:9b334a45a8ff 392 */
bogdanm 0:9b334a45a8ff 393
bogdanm 0:9b334a45a8ff 394 /** @defgroup COMP_Exported_Functions_Group2 Input and Output operation functions
bogdanm 0:9b334a45a8ff 395 * @brief Data transfers functions
bogdanm 0:9b334a45a8ff 396 *
bogdanm 0:9b334a45a8ff 397 @verbatim
bogdanm 0:9b334a45a8ff 398 ===============================================================================
bogdanm 0:9b334a45a8ff 399 ##### IO operation functions #####
bogdanm 0:9b334a45a8ff 400 ===============================================================================
bogdanm 0:9b334a45a8ff 401 [..]
bogdanm 0:9b334a45a8ff 402 This subsection provides a set of functions allowing to manage the COMP data
bogdanm 0:9b334a45a8ff 403 transfers.
bogdanm 0:9b334a45a8ff 404
bogdanm 0:9b334a45a8ff 405 @endverbatim
bogdanm 0:9b334a45a8ff 406 * @{
bogdanm 0:9b334a45a8ff 407 */
bogdanm 0:9b334a45a8ff 408
bogdanm 0:9b334a45a8ff 409 /**
bogdanm 0:9b334a45a8ff 410 * @brief Start the comparator
bogdanm 0:9b334a45a8ff 411 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 412 * @retval HAL status
bogdanm 0:9b334a45a8ff 413 */
bogdanm 0:9b334a45a8ff 414 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 415 {
bogdanm 0:9b334a45a8ff 416 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 417
bogdanm 0:9b334a45a8ff 418 /* Check the COMP handle allocation and lock status */
bogdanm 0:9b334a45a8ff 419 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
bogdanm 0:9b334a45a8ff 420 {
bogdanm 0:9b334a45a8ff 421 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 422 }
bogdanm 0:9b334a45a8ff 423 else
bogdanm 0:9b334a45a8ff 424 {
bogdanm 0:9b334a45a8ff 425 /* Check the parameter */
bogdanm 0:9b334a45a8ff 426 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 427
bogdanm 0:9b334a45a8ff 428 if(hcomp->State == HAL_COMP_STATE_READY)
bogdanm 0:9b334a45a8ff 429 {
bogdanm 0:9b334a45a8ff 430 /* Enable the selected comparator */
bogdanm 0:9b334a45a8ff 431 COMP_START(hcomp);
bogdanm 0:9b334a45a8ff 432
bogdanm 0:9b334a45a8ff 433 hcomp->State = HAL_COMP_STATE_BUSY;
bogdanm 0:9b334a45a8ff 434 }
bogdanm 0:9b334a45a8ff 435 else
bogdanm 0:9b334a45a8ff 436 {
bogdanm 0:9b334a45a8ff 437 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 438 }
bogdanm 0:9b334a45a8ff 439 }
bogdanm 0:9b334a45a8ff 440
bogdanm 0:9b334a45a8ff 441 return status;
bogdanm 0:9b334a45a8ff 442 }
bogdanm 0:9b334a45a8ff 443
bogdanm 0:9b334a45a8ff 444 /**
bogdanm 0:9b334a45a8ff 445 * @brief Stop the comparator
bogdanm 0:9b334a45a8ff 446 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 447 * @retval HAL status
bogdanm 0:9b334a45a8ff 448 */
bogdanm 0:9b334a45a8ff 449 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 450 {
bogdanm 0:9b334a45a8ff 451 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 452
bogdanm 0:9b334a45a8ff 453 /* Check the COMP handle allocation and lock status */
bogdanm 0:9b334a45a8ff 454 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
bogdanm 0:9b334a45a8ff 455 {
bogdanm 0:9b334a45a8ff 456 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 457 }
bogdanm 0:9b334a45a8ff 458 else
bogdanm 0:9b334a45a8ff 459 {
bogdanm 0:9b334a45a8ff 460 /* Check the parameter */
bogdanm 0:9b334a45a8ff 461 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 462
bogdanm 0:9b334a45a8ff 463 if(hcomp->State == HAL_COMP_STATE_BUSY)
bogdanm 0:9b334a45a8ff 464 {
bogdanm 0:9b334a45a8ff 465 /* Disable the selected comparator */
bogdanm 0:9b334a45a8ff 466 COMP_STOP(hcomp);
bogdanm 0:9b334a45a8ff 467
bogdanm 0:9b334a45a8ff 468 hcomp->State = HAL_COMP_STATE_READY;
bogdanm 0:9b334a45a8ff 469 }
bogdanm 0:9b334a45a8ff 470 else
bogdanm 0:9b334a45a8ff 471 {
bogdanm 0:9b334a45a8ff 472 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 473 }
bogdanm 0:9b334a45a8ff 474 }
bogdanm 0:9b334a45a8ff 475
bogdanm 0:9b334a45a8ff 476 return status;
bogdanm 0:9b334a45a8ff 477 }
bogdanm 0:9b334a45a8ff 478
bogdanm 0:9b334a45a8ff 479 /**
bogdanm 0:9b334a45a8ff 480 * @brief Enables the interrupt and starts the comparator
bogdanm 0:9b334a45a8ff 481 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 482 * @retval HAL status.
bogdanm 0:9b334a45a8ff 483 */
bogdanm 0:9b334a45a8ff 484 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 485 {
bogdanm 0:9b334a45a8ff 486 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 487 uint32_t extiline = 0;
bogdanm 0:9b334a45a8ff 488
bogdanm 0:9b334a45a8ff 489 /* Check the parameter */
bogdanm 0:9b334a45a8ff 490 assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
bogdanm 0:9b334a45a8ff 491
bogdanm 0:9b334a45a8ff 492 status = HAL_COMP_Start(hcomp);
bogdanm 0:9b334a45a8ff 493 if(status == HAL_OK)
bogdanm 0:9b334a45a8ff 494 {
bogdanm 0:9b334a45a8ff 495 /* Check the Exti Line output configuration */
bogdanm 0:9b334a45a8ff 496 extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
bogdanm 0:9b334a45a8ff 497 /* Configure the rising edge */
bogdanm 0:9b334a45a8ff 498 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET)
bogdanm 0:9b334a45a8ff 499 {
bogdanm 0:9b334a45a8ff 500 __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline);
bogdanm 0:9b334a45a8ff 501 }
bogdanm 0:9b334a45a8ff 502 else
bogdanm 0:9b334a45a8ff 503 {
bogdanm 0:9b334a45a8ff 504 __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline);
bogdanm 0:9b334a45a8ff 505 }
bogdanm 0:9b334a45a8ff 506 /* Configure the falling edge */
bogdanm 0:9b334a45a8ff 507 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET)
bogdanm 0:9b334a45a8ff 508 {
bogdanm 0:9b334a45a8ff 509 __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline);
bogdanm 0:9b334a45a8ff 510 }
bogdanm 0:9b334a45a8ff 511 else
bogdanm 0:9b334a45a8ff 512 {
bogdanm 0:9b334a45a8ff 513 __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline);
bogdanm 0:9b334a45a8ff 514 }
bogdanm 0:9b334a45a8ff 515 /* Enable Exti interrupt mode */
bogdanm 0:9b334a45a8ff 516 __HAL_COMP_EXTI_ENABLE_IT(extiline);
bogdanm 0:9b334a45a8ff 517 /* Clear COMP Exti pending bit */
bogdanm 0:9b334a45a8ff 518 __HAL_COMP_EXTI_CLEAR_FLAG(extiline);
bogdanm 0:9b334a45a8ff 519 }
bogdanm 0:9b334a45a8ff 520
bogdanm 0:9b334a45a8ff 521 return status;
bogdanm 0:9b334a45a8ff 522 }
bogdanm 0:9b334a45a8ff 523
bogdanm 0:9b334a45a8ff 524 /**
bogdanm 0:9b334a45a8ff 525 * @brief Disable the interrupt and Stop the comparator
bogdanm 0:9b334a45a8ff 526 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 527 * @retval HAL status
bogdanm 0:9b334a45a8ff 528 */
bogdanm 0:9b334a45a8ff 529 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 530 {
bogdanm 0:9b334a45a8ff 531 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 532
bogdanm 0:9b334a45a8ff 533 /* Disable the Exti Line interrupt mode */
bogdanm 0:9b334a45a8ff 534 __HAL_COMP_EXTI_DISABLE_IT(__HAL_COMP_GET_EXTI_LINE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 535
bogdanm 0:9b334a45a8ff 536 status = HAL_COMP_Stop(hcomp);
bogdanm 0:9b334a45a8ff 537
bogdanm 0:9b334a45a8ff 538 return status;
bogdanm 0:9b334a45a8ff 539 }
bogdanm 0:9b334a45a8ff 540
bogdanm 0:9b334a45a8ff 541 /**
bogdanm 0:9b334a45a8ff 542 * @brief Comparator IRQ Handler
bogdanm 0:9b334a45a8ff 543 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 544 * @retval HAL status
bogdanm 0:9b334a45a8ff 545 */
bogdanm 0:9b334a45a8ff 546 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 547 {
bogdanm 0:9b334a45a8ff 548 uint32_t extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
bogdanm 0:9b334a45a8ff 549
bogdanm 0:9b334a45a8ff 550 /* Check COMP Exti flag */
bogdanm 0:9b334a45a8ff 551 if(__HAL_COMP_EXTI_GET_FLAG(extiline) != RESET)
bogdanm 0:9b334a45a8ff 552 {
bogdanm 0:9b334a45a8ff 553 /* Clear COMP Exti pending bit */
bogdanm 0:9b334a45a8ff 554 __HAL_COMP_EXTI_CLEAR_FLAG(extiline);
bogdanm 0:9b334a45a8ff 555
bogdanm 0:9b334a45a8ff 556 /* COMP trigger user callback */
bogdanm 0:9b334a45a8ff 557 HAL_COMP_TriggerCallback(hcomp);
bogdanm 0:9b334a45a8ff 558 }
bogdanm 0:9b334a45a8ff 559 }
bogdanm 0:9b334a45a8ff 560
bogdanm 0:9b334a45a8ff 561 /**
bogdanm 0:9b334a45a8ff 562 * @}
bogdanm 0:9b334a45a8ff 563 */
bogdanm 0:9b334a45a8ff 564
bogdanm 0:9b334a45a8ff 565 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
bogdanm 0:9b334a45a8ff 566 * @brief management functions
bogdanm 0:9b334a45a8ff 567 *
bogdanm 0:9b334a45a8ff 568 @verbatim
bogdanm 0:9b334a45a8ff 569 ===============================================================================
bogdanm 0:9b334a45a8ff 570 ##### Peripheral Control functions #####
bogdanm 0:9b334a45a8ff 571 ===============================================================================
bogdanm 0:9b334a45a8ff 572 [..]
bogdanm 0:9b334a45a8ff 573 This subsection provides a set of functions allowing to control the COMP data
bogdanm 0:9b334a45a8ff 574 transfers.
bogdanm 0:9b334a45a8ff 575
bogdanm 0:9b334a45a8ff 576 @endverbatim
bogdanm 0:9b334a45a8ff 577 * @{
bogdanm 0:9b334a45a8ff 578 */
bogdanm 0:9b334a45a8ff 579
bogdanm 0:9b334a45a8ff 580 /**
bogdanm 0:9b334a45a8ff 581 * @brief Lock the selected comparator configuration.
bogdanm 0:9b334a45a8ff 582 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 583 * @retval HAL status
bogdanm 0:9b334a45a8ff 584 */
bogdanm 0:9b334a45a8ff 585 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 586 {
bogdanm 0:9b334a45a8ff 587 HAL_StatusTypeDef status = HAL_OK;
bogdanm 0:9b334a45a8ff 588
bogdanm 0:9b334a45a8ff 589 /* Check the COMP handle allocation and lock status */
bogdanm 0:9b334a45a8ff 590 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
bogdanm 0:9b334a45a8ff 591 {
bogdanm 0:9b334a45a8ff 592 status = HAL_ERROR;
bogdanm 0:9b334a45a8ff 593 }
bogdanm 0:9b334a45a8ff 594 else
bogdanm 0:9b334a45a8ff 595 {
bogdanm 0:9b334a45a8ff 596 /* Check the parameter */
bogdanm 0:9b334a45a8ff 597 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 598
bogdanm 0:9b334a45a8ff 599 /* Set lock flag */
bogdanm 0:9b334a45a8ff 600 hcomp->State |= COMP_STATE_BIT_LOCK;
bogdanm 0:9b334a45a8ff 601
bogdanm 0:9b334a45a8ff 602 /* Set the lock bit corresponding to selected comparator */
bogdanm 0:9b334a45a8ff 603 COMP_LOCK(hcomp);
bogdanm 0:9b334a45a8ff 604 }
bogdanm 0:9b334a45a8ff 605
bogdanm 0:9b334a45a8ff 606 return status;
bogdanm 0:9b334a45a8ff 607 }
bogdanm 0:9b334a45a8ff 608
bogdanm 0:9b334a45a8ff 609 /**
bogdanm 0:9b334a45a8ff 610 * @brief Return the output level (high or low) of the selected comparator.
bogdanm 0:9b334a45a8ff 611 * The output level depends on the selected polarity.
bogdanm 0:9b334a45a8ff 612 * If the polarity is not inverted:
bogdanm 0:9b334a45a8ff 613 * - Comparator output is low when the non-inverting input is at a lower
bogdanm 0:9b334a45a8ff 614 * voltage than the inverting input
bogdanm 0:9b334a45a8ff 615 * - Comparator output is high when the non-inverting input is at a higher
bogdanm 0:9b334a45a8ff 616 * voltage than the inverting input
bogdanm 0:9b334a45a8ff 617 * If the polarity is inverted:
bogdanm 0:9b334a45a8ff 618 * - Comparator output is high when the non-inverting input is at a lower
bogdanm 0:9b334a45a8ff 619 * voltage than the inverting input
bogdanm 0:9b334a45a8ff 620 * - Comparator output is low when the non-inverting input is at a higher
bogdanm 0:9b334a45a8ff 621 * voltage than the inverting input
bogdanm 0:9b334a45a8ff 622 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 623 * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH.
bogdanm 0:9b334a45a8ff 624 *
bogdanm 0:9b334a45a8ff 625 */
bogdanm 0:9b334a45a8ff 626 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 627 {
bogdanm 0:9b334a45a8ff 628 uint32_t level=0;
bogdanm 0:9b334a45a8ff 629
bogdanm 0:9b334a45a8ff 630 /* Check the parameter */
bogdanm 0:9b334a45a8ff 631 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 632
bogdanm 0:9b334a45a8ff 633 level = READ_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxOUT);
bogdanm 0:9b334a45a8ff 634
bogdanm 0:9b334a45a8ff 635 if(level != 0)
bogdanm 0:9b334a45a8ff 636 {
bogdanm 0:9b334a45a8ff 637 return(COMP_OUTPUTLEVEL_HIGH);
bogdanm 0:9b334a45a8ff 638 }
bogdanm 0:9b334a45a8ff 639 return(COMP_OUTPUTLEVEL_LOW);
bogdanm 0:9b334a45a8ff 640 }
bogdanm 0:9b334a45a8ff 641
bogdanm 0:9b334a45a8ff 642 /**
bogdanm 0:9b334a45a8ff 643 * @brief Comparator callback.
bogdanm 0:9b334a45a8ff 644 * @param hcomp: COMP handle
bogdanm 0:9b334a45a8ff 645 * @retval None
bogdanm 0:9b334a45a8ff 646 */
bogdanm 0:9b334a45a8ff 647 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 648 {
bogdanm 0:9b334a45a8ff 649 /* NOTE : This function should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 650 the HAL_COMP_TriggerCallback should be implemented in the user file
bogdanm 0:9b334a45a8ff 651 */
bogdanm 0:9b334a45a8ff 652 }
bogdanm 0:9b334a45a8ff 653
bogdanm 0:9b334a45a8ff 654
bogdanm 0:9b334a45a8ff 655 /**
bogdanm 0:9b334a45a8ff 656 * @}
bogdanm 0:9b334a45a8ff 657 */
bogdanm 0:9b334a45a8ff 658
bogdanm 0:9b334a45a8ff 659 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
bogdanm 0:9b334a45a8ff 660 * @brief Peripheral State functions
bogdanm 0:9b334a45a8ff 661 *
bogdanm 0:9b334a45a8ff 662 @verbatim
bogdanm 0:9b334a45a8ff 663 ===============================================================================
bogdanm 0:9b334a45a8ff 664 ##### Peripheral State functions #####
bogdanm 0:9b334a45a8ff 665 ===============================================================================
bogdanm 0:9b334a45a8ff 666 [..]
bogdanm 0:9b334a45a8ff 667 This subsection permit to get in run-time the status of the peripheral
bogdanm 0:9b334a45a8ff 668 and the data flow.
bogdanm 0:9b334a45a8ff 669
bogdanm 0:9b334a45a8ff 670 @endverbatim
bogdanm 0:9b334a45a8ff 671 * @{
bogdanm 0:9b334a45a8ff 672 */
bogdanm 0:9b334a45a8ff 673
bogdanm 0:9b334a45a8ff 674 /**
bogdanm 0:9b334a45a8ff 675 * @brief Return the COMP state
bogdanm 0:9b334a45a8ff 676 * @param hcomp : COMP handle
bogdanm 0:9b334a45a8ff 677 * @retval HAL state
bogdanm 0:9b334a45a8ff 678 */
bogdanm 0:9b334a45a8ff 679 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
bogdanm 0:9b334a45a8ff 680 {
bogdanm 0:9b334a45a8ff 681 /* Check the COMP handle allocation */
bogdanm 0:9b334a45a8ff 682 if(hcomp == HAL_NULL)
bogdanm 0:9b334a45a8ff 683 {
bogdanm 0:9b334a45a8ff 684 return HAL_COMP_STATE_RESET;
bogdanm 0:9b334a45a8ff 685 }
bogdanm 0:9b334a45a8ff 686
bogdanm 0:9b334a45a8ff 687 /* Check the parameter */
bogdanm 0:9b334a45a8ff 688 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
bogdanm 0:9b334a45a8ff 689
bogdanm 0:9b334a45a8ff 690 return hcomp->State;
bogdanm 0:9b334a45a8ff 691 }
bogdanm 0:9b334a45a8ff 692 /**
bogdanm 0:9b334a45a8ff 693 * @}
bogdanm 0:9b334a45a8ff 694 */
bogdanm 0:9b334a45a8ff 695
bogdanm 0:9b334a45a8ff 696 /**
bogdanm 0:9b334a45a8ff 697 * @}
bogdanm 0:9b334a45a8ff 698 */
bogdanm 0:9b334a45a8ff 699
bogdanm 0:9b334a45a8ff 700 #endif /* HAL_COMP_MODULE_ENABLED */
bogdanm 0:9b334a45a8ff 701 /**
bogdanm 0:9b334a45a8ff 702 * @}
bogdanm 0:9b334a45a8ff 703 */
bogdanm 0:9b334a45a8ff 704
bogdanm 0:9b334a45a8ff 705 /**
bogdanm 0:9b334a45a8ff 706 * @}
bogdanm 0:9b334a45a8ff 707 */
bogdanm 0:9b334a45a8ff 708
bogdanm 0:9b334a45a8ff 709 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/