/** * @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_MINUS(COMPx, COMP_InitStruct->InputMinus)); assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus)); assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis)); assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity)); assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource)); /* Note: Hardware constraint (refer to description of this function) */ /* COMP instance must not be locked. */ if(LL_COMP_IsLocked(COMPx) == 0) { /* Configuration of comparator instance : */ /* - PowerMode */ /* - InputPlus */ /* - InputMinus */ /* - InputHysteresis */ /* - OutputPolarity */ /* - OutputBlankingSource */ MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN | COMP_CSR_INMSEL | COMP_CSR_HYST | COMP_CSR_POLARITY | COMP_CSR_BLANKING , COMP_InitStruct->PowerMode | COMP_InitStruct->InputPlus | COMP_InitStruct->InputMinus | COMP_InitStruct->InputHysteresis | COMP_InitStruct->OutputPolarity | COMP_InitStruct->OutputBlankingSource ); } else { /* Initialization error: COMP instance is locked. */ 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; }