/******************************************************************************* * 函数名称: SPI_I2S_ITConfig * 功能描述: 使能或禁止指定的SPI/I2S中断。 * 输入参数: (1)SPIx: x可以是 : * - 1, 2 或 3 在 SPI 模式 * - 2 或 3 在 I2S 模式 * (2)SPI_I2S_IT: 指定的中断源被使能或禁止. * 这个参数可以是下面的值之一: * - SPI_I2S_IT_TXE: Tx buffer empty interrupt mask * - SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask * - SPI_I2S_IT_ERR: Error interrupt mask * (3)NewState: 指定的 SPI/I2S 中断新状态. * 这个参数可以是: ENABLE or DISABLE. * 输出参数: 无 * 返回参数: 无 *******************************************************************************/ void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, u8 SPI_I2S_IT, FunctionalState NewState) { u16 itpos = 0, itmask = 0 ; /* Check the parameters [检查参数]*/ assert_param(IS_SPI_ALL_PERIPH(SPIx)); assert_param(IS_FUNCTIONAL_STATE(NewState)); assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT)); /* Get the SPI/I2S IT index */ itpos = SPI_I2S_IT >> 4; /* Set the IT mask */ itmask = (u16)((u16)1 << itpos); if (NewState != DISABLE) { /* Enable the selected SPI/I2S interrupt [使能选择的SPI/I2S 中断]*/ SPIx->CR2 |= itmask; } else { /* Disable the selected SPI/I2S interrupt [禁止选择的SPI/I2S 中断]*/ SPIx->CR2 &= (u16)~itmask; } }
/** * @brief Enables or disables the specified SPI/I2S interrupts. * @param SPIx: where x can be 1 or 2 in SPI mode or 1 in I2S mode to select * the SPI peripheral. * @param SPI_I2S_IT: specifies the SPI interrupt source to be enabled or disabled. * This parameter can be one of the following values: * @arg SPI_I2S_IT_TXE: Tx buffer empty interrupt mask * @arg SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask * @arg SPI_I2S_IT_ERR: Error interrupt mask * @param NewState: new state of the specified SPI interrupt. * This parameter can be: ENABLE or DISABLE. * @retval None */ void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState) { uint16_t itpos = 0, itmask = 0 ; /* Check the parameters */ assert_param(IS_SPI_ALL_PERIPH(SPIx)); assert_param(IS_FUNCTIONAL_STATE(NewState)); assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT)); /* Get the SPI IT index */ itpos = SPI_I2S_IT >> 4; /* Set the IT mask */ itmask = (uint16_t)1 << (uint16_t)itpos; if (NewState != DISABLE) { /* Enable the selected SPI interrupt */ SPIx->CR2 |= itmask; } else { /* Disable the selected SPI interrupt */ SPIx->CR2 &= (uint16_t)~itmask; } }