/** * @brief Sets the external interrupt sensitivity of the selected port. * @note * - The modification of external interrupt sensitivity is only possible when * the interrupts are disabled. * - The normal behavior is to disable the interrupts before calling this * function, and re-enable them after. * @param EXTI_Port : The port number to access. * This parameter can be a value of @ref EXTI_Port_TypeDef * @param EXTI_Trigger : The external interrupt sensitivity value to set. * This parameter can be a value of @ref EXTI_Trigger_TypeDef * @retval None * @par Required preconditions: * - Global interrupts must be disabled before calling this function. */ void EXTI_SetPortSensitivity(EXTI_Port_TypeDef EXTI_Port, EXTI_Trigger_TypeDef EXTI_Trigger) { /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); assert_param(IS_EXTI_TRIGGER(EXTI_Trigger)); /* Clear EXTI port sensitivity */ if (EXTI_Port == EXTI_Port_B) { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PBIS); } else if (EXTI_Port == EXTI_Port_D) { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PDIS); } else if (EXTI_Port == EXTI_Port_E) { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PEIS); } else /* EXTI_Port == EXTI_Port_PF */ { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PFIS); } /* Write EXTI port sensitivity */ EXTI->CR3 |= (uint8_t)((uint8_t)(EXTI_Trigger) << EXTI_Port); }
/** * @brief Gets the external interrupt sensitivity of the selected port. * @param EXTI_Port : The port number to access. * This parameter can be a value of @ref EXTI_Port_TypeDef * @retval EXTI_Trigger_TypeDef : The external interrupt sensitivity of the selected port. */ EXTI_Trigger_TypeDef EXTI_GetPortSensitivity(EXTI_Port_TypeDef EXTI_Port) { uint8_t value = 0; uint8_t cr3mask = 0; /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); if (EXTI_Port == EXTI_Port_B) { cr3mask = EXTI_CR3_PBIS; } else if (EXTI_Port == EXTI_Port_D) { cr3mask = EXTI_CR3_PDIS; } else if (EXTI_Port == EXTI_Port_E) { cr3mask = EXTI_CR3_PEIS; } else { cr3mask = EXTI_CR3_PFIS; } value = (uint8_t)((uint8_t)(EXTI->CR3 & cr3mask) >> EXTI_Port); return((EXTI_Trigger_TypeDef)value); }
/** * @brief Get the external interrupt sensitivity of the selected port. * @param EXTI_Port The port number to access. * This parameter can be any combination of the following values: * @arg EXTI_Port_B: GPIO Port B * @arg EXTI_Port_D: GPIO Port D * @retval EXTI_Trigger_TypeDef The external interrupt sensitivity of the selected port. */ EXTI_Trigger_TypeDef EXTI_GetPortSensitivity(EXTI_Port_TypeDef EXTI_Port) { uint8_t value = 0; /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); if (EXTI_Port != EXTI_Port_B) { value = (uint8_t)((EXTI->CR3 & EXTI_CR3_PDIS) >> 2); }
/** * @brief Gets the external interrupt sensitivity of the selected port. * @param EXTI_Port : The port number to access. * This parameter can be a value of @ref EXTI_Port_TypeDef * @retval EXTI_Trigger_TypeDef : The external interrupt sensitivity of the selected port. */ EXTI_Trigger_TypeDef EXTI_GetPortSensitivity(EXTI_Port_TypeDef EXTI_Port) { uint8_t portsensitivity = 0; /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); /* Check if selected port is in EXTI_CR3 */ if ((EXTI_Port & 0xF0) == 0x00) { /* Get port sensitivity */ portsensitivity = (uint8_t)((uint8_t)0x03 & (uint8_t)(EXTI->CR3 >> EXTI_Port)); }
/** * @brief Set the external interrupt sensitivity of the selected port. * @note The modification of external interrupt sensitivity is only possible * when the interrupts are disabled. * @note The normal behavior is to disable the interrupts before calling this * function, and re-enable them after. * @note Global interrupts must be disabled before calling this function. * @param EXTI_Port The port number to access. * This parameter can be any combination of the following values: * @arg EXTI_Port_B: GPIO Port B * @arg EXTI_Port_D: GPIO Port D * @param EXTI_TriggerValue The external interrupt sensitivity value to set. * This parameter can be any combination of the following values: * @arg EXTI_Trigger_Falling_Low: Interrupt on Falling edge and Low level * @arg EXTI_Trigger_Rising: Interrupt on Rising edge * @arg EXTI_Trigger_Falling: Interrupt on Falling edge * @arg EXTI_Trigger_Rising_Falling: Interrupt on Rising and Falling edges * @retval None */ void EXTI_SetPortSensitivity(EXTI_Port_TypeDef EXTI_Port, EXTI_Trigger_TypeDef EXTI_TriggerValue) { /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); assert_param(IS_EXTI_Trigger_VALUE(EXTI_TriggerValue)); /* Clear EXTI port sensitivity */ if (EXTI_Port != EXTI_Port_B) { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PDIS); } else /* PortNum == EXTI_Port_B */ { EXTI->CR3 &= (uint8_t)(~EXTI_CR3_PBIS); } /* Write EXTI port sensitivity */ EXTI->CR3 |= (uint8_t)((uint8_t)(EXTI_TriggerValue) << (uint8_t)EXTI_Port); }
/** * @brief Sets the external interrupt sensitivity of the selected port. * @note - Global interrupts must be disabled before calling this function. * @note - The modification of external interrupt sensitivity is only possible * when the interrupts are disabled. * - The normal behavior is to disable the interrupts before calling this * function, and re-enable them after. * @param EXTI_Port : The port number to access. * This parameter can be a value of @ref EXTI_Port_TypeDef * @param EXTI_Trigger : The external interrupt sensitivity value to set. * This parameter can be a value of @ref EXTI_Trigger_TypeDef * @retval None */ void EXTI_SetPortSensitivity(EXTI_Port_TypeDef EXTI_Port, EXTI_Trigger_TypeDef EXTI_Trigger) { /* Check function parameters */ assert_param(IS_EXTI_PORT(EXTI_Port)); assert_param(IS_EXTI_TRIGGER(EXTI_Trigger)); /* Ceck if selected port is in EXTI_CR3 register */ if ((EXTI_Port & 0xF0) == 0x00) { /* Reset the trigger bits corresponding to EXTI_Port */ EXTI->CR3 &= (uint8_t) (~(uint8_t)((uint8_t)0x03 << EXTI_Port)); /* Write EXTI port trigger */ EXTI->CR3 |= (uint8_t)((uint8_t)(EXTI_Trigger) << EXTI_Port); } else /* selected port is in EXTI_CR4 register */ { /* Reset the trigger bits corresponding to EXTI_Port */ EXTI->CR4 &= (uint8_t) (~(uint8_t)((uint8_t)0x03 << (EXTI_Port & 0x0F))); /* Write EXTI port trigger */ EXTI->CR4 |= (uint8_t)(EXTI_Trigger << (EXTI_Port & 0x0F)); } }
/** * @brief Selects the port interrupt selection. * @param EXTI_Port : The port number to access. * This parameter can be a value of @ref EXTI_Port_TypeDef * @retval None */ void EXTI_SelectPort(EXTI_Port_TypeDef EXTI_Port) { /* Check function parameter */ assert_param(IS_EXTI_PORT(EXTI_Port)); if (EXTI_Port == EXTI_Port_B) { /* Select Port B by resetting PGBS bit in CONF2 register */ EXTI->CONF2 &= (uint8_t) (~EXTI_CONF2_PGBS); } else if (EXTI_Port == EXTI_Port_D) { /* Select Port D by resetting PHDS bit in CONF2 register */ EXTI->CONF2 &= (uint8_t) (~EXTI_CONF2_PHDS); } else if (EXTI_Port == EXTI_Port_E) { /* Select Port E by resetting PFES bit in CONF1 register */ EXTI->CONF1 &= (uint8_t) (~EXTI_CONF1_PFES); } else if (EXTI_Port == EXTI_Port_F) { /* Select Port F by setting PFES bit in CONF1 register */ EXTI->CONF1 |= (uint8_t) (EXTI_CONF1_PFES); } else if (EXTI_Port == EXTI_Port_G) { /* Select Port G by setting PGBS bit in CONF2 register */ EXTI->CONF2 |= (uint8_t) (EXTI_CONF2_PGBS); } else /* EXTI_Port is EXTI_Port_H */ { /* Select Port H by setting PHDS bit in CONF2 register */ EXTI->CONF2 |= (uint8_t) (EXTI_CONF2_PHDS); } }