+++ /dev/null
-/**\r
- ******************************************************************************\r
- * @file stm32l1xx_comp.c\r
- * @author MCD Application Team\r
- * @version V1.0.0\r
- * @date 31-December-2010\r
- * @brief This file provides firmware functions to manage the following \r
- * functionalities of the comparators (COMP1 and COMP2) peripheral: \r
- * - Comparators configuration\r
- * - Window mode control\r
- * - Internal Reference Voltage (VREFINT) output\r
- *\r
- * @verbatim\r
- *\r
- * ===================================================================\r
- * How to use this driver\r
- * ===================================================================\r
- * \r
- * The device integrates two analog comparators COMP1 and COMP2: \r
- * - COMP1 is a fixed threshold (VREFINT) that shares the non inverting\r
- * input with the ADC channels.\r
- *\r
- * - COMP2 is a rail-to-rail comparator whose the inverting input \r
- * can be selected among: DAC_OUT1, DAC_OUT2, 1/4 VREFINT,\r
- * 1/2 VERFINT, 3/4 VREFINT, VREFINT, PB3 and whose the output\r
- * can be redirected to embedded timers: TIM2, TIM3, TIM4, TIM10\r
- *\r
- * - The two comparators COMP1 and COMP2 can be combined in window\r
- * mode.\r
- *\r
- * @note\r
- * 1- Comparator APB clock must be enabled to get write access\r
- * to comparator register using\r
- * RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE);\r
- *\r
- * 2- COMP1 comparator and ADC can't be used at the same time since\r
- * they share the same ADC switch matrix (analog switches).\r
- *\r
- * 3- When an I/O is used as comparator input, the corresponding GPIO \r
- * registers should be configured in analog mode.\r
- *\r
- * 4- Comparators outputs (CMP1OUT and CMP2OUT) are not mapped on\r
- * GPIO pin. They are only internal.\r
- * To get the comparator output level, use COMP_GetOutputLevel()\r
- *\r
- * 5- COMP1 and COMP2 outputs are internally connected to EXTI Line 21\r
- * and EXTI Line 22 respectively.\r
- * Interrupts can be used by configuring the EXTI Line using the \r
- * EXTI peripheral driver.\r
- *\r
- * 6- After enabling the comparator (COMP1 or COMP2), user should wait\r
- * for start-up time (tSTART) to get right output levels.\r
- * Please refer to product datasheet for more information on tSTART. \r
- *\r
- * 7- Comparators cannot be used to exit the device from Sleep or Stop \r
- * mode when the internal reference voltage is switched off using \r
- * the PWR_UltraLowPowerCmd() function (ULP bit in the PWR_CR register).\r
- *\r
- * @endverbatim\r
- * \r
- ******************************************************************************\r
- * @attention\r
- *\r
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
- *\r
- * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>\r
- ****************************************************************************** \r
- */ \r
-\r
-/* Includes ------------------------------------------------------------------*/\r
-#include "stm32l1xx_comp.h"\r
-\r
-/** @addtogroup STM32L1xx_StdPeriph_Driver\r
- * @{\r
- */\r
-\r
-/** @defgroup COMP \r
- * @brief COMP driver modules\r
- * @{\r
- */ \r
-\r
-/* Private typedef -----------------------------------------------------------*/\r
-/* Private define ------------------------------------------------------------*/\r
-/* Private macro -------------------------------------------------------------*/\r
-/* Private variables ---------------------------------------------------------*/\r
-/* Private function prototypes -----------------------------------------------*/\r
-/* Private functions ---------------------------------------------------------*/\r
-\r
-/** @defgroup COMP_Private_Functions\r
- * @{\r
- */\r
-\r
-/** @defgroup COMP_Group1 Initialization and Configuration functions\r
- * @brief Initialization and Configuration functions \r
- *\r
-@verbatim \r
- ===============================================================================\r
- Initialization and Configuration functions\r
- =============================================================================== \r
-\r
-@endverbatim\r
- * @{\r
- */\r
- \r
-/**\r
- * @brief Deinitializes COMP peripheral registers to their default reset values.\r
- * @param None\r
- * @retval None\r
- */\r
-void COMP_DeInit(void)\r
-{\r
- COMP->CSR = ((uint32_t)0x00000000); /*!< Set COMP->CSR to reset value */\r
-}\r
-\r
-/**\r
- * @brief Initializes the COMP2 peripheral according to the specified parameters\r
- * in the COMP_InitStruct:\r
- * - COMP_InvertingInput specify the inverting input of COMP2\r
- * - COMP_OutputSelect connect the output of COMP2 to selected timer\r
- * input (Input capture / Output Compare Reference Clear)\r
- * - COMP_Speed configures COMP2 speed for optimum speed/consumption ratio\r
- * @note This function configures only COMP2.\r
- * @note COMP2 comparator is enabled as soon as the INSEL[2:0] bits are \r
- * different from "000".\r
- * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains \r
- * the configuration information for the specified COMP peripheral.\r
- * @retval None\r
- */\r
-void COMP_Init(COMP_InitTypeDef* COMP_InitStruct)\r
-{\r
- uint32_t tmpreg = 0;\r
- \r
- /* Check the parameters */\r
- assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput));\r
- assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_OutputSelect));\r
- assert_param(IS_COMP_SPEED(COMP_InitStruct->COMP_Speed));\r
-\r
- /*!< Get the COMP CSR value */\r
- tmpreg = COMP->CSR;\r
-\r
- /*!< Clear the INSEL[2:0], OUTSEL[1:0] and SPEED bits */ \r
- tmpreg &= (uint32_t) (~(uint32_t) (COMP_CSR_OUTSEL | COMP_CSR_INSEL | COMP_CSR_SPEED));\r
- \r
- /*!< Configure COMP: speed, inversion input selection and output redirection */\r
- /*!< Set SPEED bit according to COMP_InitStruct->COMP_Speed value */\r
- /*!< Set INSEL bits according to COMP_InitStruct->COMP_InvertingInput value */ \r
- /*!< Set OUTSEL bits according to COMP_InitStruct->COMP_OutputSelect value */ \r
- tmpreg |= (uint32_t)((COMP_InitStruct->COMP_Speed | COMP_InitStruct->COMP_InvertingInput \r
- | COMP_InitStruct->COMP_OutputSelect));\r
-\r
- /*!< The COMP2 comparator is enabled as soon as the INSEL[2:0] bits value are \r
- different from "000" */\r
- /*!< Write to COMP_CSR register */\r
- COMP->CSR = tmpreg; \r
-}\r
-\r
-/**\r
- * @brief Enable or disable the COMP1 peripheral.\r
- * After enabling COMP1, the following functions should be called to \r
- * connect the selected GPIO input to COMP1 non inverting input:\r
- * - Enable switch control mode using SYSCFG_RISwitchControlModeCmd()\r
- * - Close VCOMP switch using SYSCFG_RIIOSwitchConfig()\r
- * - Close the I/O switch number n corresponding to the I/O \r
- * using SYSCFG_RIIOSwitchConfig()\r
- * @param NewState: new state of the COMP1 peripheral.\r
- * This parameter can be: ENABLE or DISABLE.\r
- * @note This function enables/disables only the COMP1.\r
- * @retval None\r
- */\r
-void COMP_Cmd(FunctionalState NewState)\r
-{\r
- /* Check the parameter */\r
- assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-\r
- if (NewState != DISABLE)\r
- {\r
- /* Enable the COMP1 */\r
- COMP->CSR |= (uint32_t) COMP_CSR_CMP1EN;\r
- }\r
- else\r
- {\r
- /* Disable the COMP1 */\r
- COMP->CSR &= (uint32_t)(~COMP_CSR_CMP1EN);\r
- }\r
-}\r
-\r
-/**\r
- * @brief Return the output level (high or low) of the selected comparator:\r
- * - Comparator output is low when the non-inverting input is at a lower\r
- * voltage than the inverting input\r
- * - Comparator output is high when the non-inverting input is at a higher\r
- * voltage than the inverting input\r
- * @note Comparators outputs aren't available on GPIO (outputs levels are \r
- * only internal). The COMP1 and COMP2 outputs are connected internally \r
- * to the EXTI Line 21 and Line 22 respectively. \r
- * @param COMP_Selection: the selected comparator. \r
- * This parameter can be one of the following values:\r
- * @arg COMP_Selection_COMP1: COMP1 selected\r
- * @arg COMP_Selection_COMP2: COMP2 selected \r
- * @retval Returns the selected comparator output level.\r
- */\r
-uint8_t COMP_GetOutputLevel(uint32_t COMP_Selection)\r
-{\r
- uint8_t compout = 0x0;\r
-\r
- /* Check the parameters */\r
- assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));\r
-\r
- /* Check if Comparator 1 is selected */\r
- if(COMP_Selection == COMP_Selection_COMP1)\r
- {\r
- /* Check if comparator 1 output level is high */\r
- if((COMP->CSR & COMP_CSR_CMP1OUT) != (uint8_t) RESET)\r
- {\r
- /* Get Comparator 1 output level */\r
- compout = (uint8_t) COMP_OutputLevel_High;\r
- }\r
- /* comparator 1 output level is low */\r
- else\r
- {\r
- /* Get Comparator 1 output level */\r
- compout = (uint8_t) COMP_OutputLevel_Low;\r
- }\r
- }\r
- /* Comparator 2 is selected */\r
- else\r
- {\r
- /* Check if comparator 2 output level is high */\r
- if((COMP->CSR & COMP_CSR_CMP2OUT) != (uint8_t) RESET)\r
- {\r
- /* Get Comparator output level */\r
- compout = (uint8_t) COMP_OutputLevel_High;\r
- }\r
- /* comparator 2 output level is low */\r
- else\r
- {\r
- /* Get Comparator 2 output level */\r
- compout = (uint8_t) COMP_OutputLevel_Low;\r
- }\r
- }\r
- /* Return the comparator output level */\r
- return (uint8_t)(compout);\r
-}\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/** @defgroup COMP_Group2 Window mode control function\r
- * @brief Window mode control function \r
- *\r
-@verbatim \r
- ===============================================================================\r
- Window mode control function\r
- =============================================================================== \r
-\r
-@endverbatim\r
- * @{\r
- */\r
-\r
-/**\r
- * @brief Enables or disables the window mode.\r
- * In window mode:\r
- * - COMP1 inverting input is fixed to VREFINT defining the first\r
- * threshold\r
- * - COMP2 inverting input is configurable (DAC_OUT1, DAC_OUT2, VREFINT\r
- * sub-multiples, PB3) defining the second threshold\r
- * - COMP1 and COMP2 non inverting inputs are connected together.\r
- * @note In window mode, only the Group 6 (PB4 or PB5) can be used as\r
- * non-inverting inputs.\r
- * param NewState: new state of the window mode. \r
- * This parameter can be ENABLE or DISABLE.\r
- * @retval None\r
- */\r
-void COMP_WindowCmd(FunctionalState NewState)\r
-{\r
- /* Check the parameters */\r
- assert_param(IS_FUNCTIONAL_STATE(NewState));\r
- \r
- if (NewState != DISABLE)\r
- {\r
- /* Enable the window mode */\r
- COMP->CSR |= (uint32_t) COMP_CSR_WNDWE;\r
- }\r
- else\r
- {\r
- /* Disable the window mode */\r
- COMP->CSR &= (uint32_t)(~COMP_CSR_WNDWE);\r
- }\r
-}\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/** @defgroup COMP_Group3 Internal Reference Voltage output function\r
- * @brief Internal Reference Voltage (VREFINT) output function \r
- *\r
-@verbatim \r
- ===============================================================================\r
- Internal Reference Voltage (VREFINT) output function\r
- =============================================================================== \r
-\r
-@endverbatim\r
- * @{\r
- */\r
-\r
-/**\r
- * @brief Enables or disables the output of internal reference voltage (VREFINT).\r
- * The VREFINT output can be routed to any I/O in group 3: CH8 (PB0) or\r
- * CH9 (PB1).\r
- * To correctly use this function, the SYSCFG_RIIOSwitchConfig() function\r
- * should be called after.\r
- * @param NewState: new state of the Vrefint output.\r
- * This parameter can be: ENABLE or DISABLE.\r
- * @retval None\r
- */\r
-void COMP_VrefintOutputCmd(FunctionalState NewState)\r
-{\r
- /* Check the parameters */\r
- assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-\r
- if (NewState != DISABLE)\r
- {\r
- /* Enable the output of internal reference voltage */\r
- COMP->CSR |= (uint32_t) COMP_CSR_VREFOUTEN;\r
- }\r
- else\r
- {\r
- /* Disable the output of internal reference voltage */\r
- COMP->CSR &= (uint32_t) (~COMP_CSR_VREFOUTEN);\r
- }\r
-}\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/**\r
- * @}\r
- */\r
-\r
-/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r