Files
@ d651f75c8fbc
Branch filter:
Location: HydroBot/protomodule-firmware/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_comp.c - annotation
d651f75c8fbc
13.9 KiB
text/plain
Added ability to read ph meter from analog input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 3970a40efdc5 | /**
******************************************************************************
* @file stm32f0xx_ll_comp.c
* @author MCD Application Team
* @brief COMP LL module driver
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_ll_comp.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32F0xx_LL_Driver
* @{
*/
#if defined (COMP1) || defined (COMP2)
/** @addtogroup COMP_LL COMP
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup COMP_LL_Private_Macros
* @{
*/
/* Check of parameters for configuration of COMP hierarchical scope: */
/* COMP instance. */
#define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
)
/* Note: On this STM32 serie, comparator input plus parameters are */
/* the different depending on COMP instances. */
#define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
(((__COMP_INSTANCE__) == COMP1) \
? ( \
((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1) \
) \
: \
( \
((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
) \
)
/* Note: On this STM32 serie, comparator input minus parameters are */
/* the same on all COMP instances. */
/* However, comparator instance kept as macro parameter for */
/* compatibility with other STM32 families. */
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
)
#define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
)
#define IS_LL_COMP_OUTPUT_SELECTION(__OUTPUT_SELECTION__) \
( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1) \
|| ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR) \
)
#define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
|| ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
)
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup COMP_LL_Exported_Functions
* @{
*/
/** @addtogroup COMP_LL_EF_Init
* @{
*/
/**
* @brief De-initialize registers of the selected COMP instance
* to their default reset values.
* @note If comparator is locked, de-initialization by software is
* not possible.
* The only way to unlock the comparator is a device hardware reset.
* @param COMPx COMP instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: COMP registers are de-initialized
* - ERROR: COMP registers are not de-initialized
*/
ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
/* Note: Hardware constraint (refer to description of this function): */
/* COMP instance must not be locked. */
if(LL_COMP_IsLocked(COMPx) == 0U)
{
/* Note: Connection switch is applicable only to COMP instance COMP1, */
/* therefore is COMP2 is selected the equivalent bit is */
/* kept unmodified. */
if(COMPx == COMP1)
{
CLEAR_BIT(COMP->CSR,
( COMP_CSR_COMP1MODE
| COMP_CSR_COMP1INSEL
| COMP_CSR_COMP1SW1
| COMP_CSR_COMP1OUTSEL
| COMP_CSR_COMP1HYST
| COMP_CSR_COMP1POL
| COMP_CSR_COMP1EN
) << __COMP_BITOFFSET_INSTANCE(COMPx)
);
}
else
{
CLEAR_BIT(COMP->CSR,
( COMP_CSR_COMP1MODE
| COMP_CSR_COMP1INSEL
| COMP_CSR_COMP1OUTSEL
| COMP_CSR_COMP1HYST
| COMP_CSR_COMP1POL
| COMP_CSR_COMP1EN
) << __COMP_BITOFFSET_INSTANCE(COMPx)
);
}
}
else
{
/* Comparator instance is locked: de-initialization by software is */
/* not possible. */
/* The only way to unlock the comparator is a device hardware reset. */
status = ERROR;
}
return status;
}
/**
* @brief Initialize some features of COMP instance.
* @note This function configures features of the selected COMP instance.
* Some features are also available at scope COMP common instance
* (common to several COMP instances).
* Refer to functions having argument "COMPxy_COMMON" as parameter.
* @param COMPx COMP instance
* @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: COMP registers are initialized
* - ERROR: COMP registers are not initialized
*/
ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMP_InitStruct->OutputSelection));
assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
/* Note: Hardware constraint (refer to description of this function) */
/* COMP instance must not be locked. */
if(LL_COMP_IsLocked(COMPx) == 0U)
{
/* Configuration of comparator instance : */
/* - PowerMode */
/* - InputPlus */
/* - InputMinus */
/* - InputHysteresis */
/* - OutputSelection */
/* - OutputPolarity */
/* Note: Connection switch is applicable only to COMP instance COMP1, */
/* therefore is COMP2 is selected the equivalent bit is */
/* kept unmodified. */
if(COMPx == COMP1)
{
MODIFY_REG(COMP->CSR,
( COMP_CSR_COMP1MODE
| COMP_CSR_COMP1INSEL
| COMP_CSR_COMP1SW1
| COMP_CSR_COMP1OUTSEL
| COMP_CSR_COMP1HYST
| COMP_CSR_COMP1POL
) << __COMP_BITOFFSET_INSTANCE(COMPx)
,
( COMP_InitStruct->PowerMode
| COMP_InitStruct->InputPlus
| COMP_InitStruct->InputMinus
| COMP_InitStruct->InputHysteresis
| COMP_InitStruct->OutputSelection
| COMP_InitStruct->OutputPolarity
) << __COMP_BITOFFSET_INSTANCE(COMPx)
);
}
else
{
MODIFY_REG(COMP->CSR,
( COMP_CSR_COMP1MODE
| COMP_CSR_COMP1INSEL
| COMP_CSR_COMP1OUTSEL
| COMP_CSR_COMP1HYST
| COMP_CSR_COMP1POL
) << __COMP_BITOFFSET_INSTANCE(COMPx)
,
( COMP_InitStruct->PowerMode
| COMP_InitStruct->InputPlus
| COMP_InitStruct->InputMinus
| COMP_InitStruct->InputHysteresis
| COMP_InitStruct->OutputSelection
| COMP_InitStruct->OutputPolarity
) << __COMP_BITOFFSET_INSTANCE(COMPx)
);
}
}
else
{
/* Initialization error: COMP instance is locked. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_COMP_InitTypeDef field to default value.
* @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
{
/* Set COMP_InitStruct fields to default values */
COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
COMP_InitStruct->OutputSelection = LL_COMP_OUTPUT_NONE;
COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* COMP1 || COMP2 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|