21 #ifndef __STM32F4xx_HAL_IRDA_H
22 #define __STM32F4xx_HAL_IRDA_H
138 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
139 typedef struct __IRDA_HandleTypeDef
175 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
176 void (* TxHalfCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
178 void (* TxCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
180 void (* RxHalfCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
182 void (* RxCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
184 void (* ErrorCallback)(
struct __IRDA_HandleTypeDef *hirda);
186 void (* AbortCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
188 void (* AbortTransmitCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
190 void (* AbortReceiveCpltCallback)(
struct __IRDA_HandleTypeDef *hirda);
193 void (* MspInitCallback)(
struct __IRDA_HandleTypeDef *hirda);
195 void (* MspDeInitCallback)(
struct __IRDA_HandleTypeDef *hirda);
200 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
206 HAL_IRDA_TX_HALFCOMPLETE_CB_ID = 0x00U,
207 HAL_IRDA_TX_COMPLETE_CB_ID = 0x01U,
208 HAL_IRDA_RX_HALFCOMPLETE_CB_ID = 0x02U,
209 HAL_IRDA_RX_COMPLETE_CB_ID = 0x03U,
210 HAL_IRDA_ERROR_CB_ID = 0x04U,
211 HAL_IRDA_ABORT_COMPLETE_CB_ID = 0x05U,
212 HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U,
213 HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U,
215 HAL_IRDA_MSPINIT_CB_ID = 0x08U,
216 HAL_IRDA_MSPDEINIT_CB_ID = 0x09U
218 } HAL_IRDA_CallbackIDTypeDef;
238 #define HAL_IRDA_ERROR_NONE 0x00000000U
239 #define HAL_IRDA_ERROR_PE 0x00000001U
240 #define HAL_IRDA_ERROR_NE 0x00000002U
241 #define HAL_IRDA_ERROR_FE 0x00000004U
242 #define HAL_IRDA_ERROR_ORE 0x00000008U
243 #define HAL_IRDA_ERROR_DMA 0x00000010U
244 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
245 #define HAL_IRDA_ERROR_INVALID_CALLBACK ((uint32_t)0x00000020U)
254 #define IRDA_WORDLENGTH_8B 0x00000000U
255 #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
263 #define IRDA_PARITY_NONE 0x00000000U
264 #define IRDA_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
265 #define IRDA_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
273 #define IRDA_MODE_RX ((uint32_t)USART_CR1_RE)
274 #define IRDA_MODE_TX ((uint32_t)USART_CR1_TE)
275 #define IRDA_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
283 #define IRDA_POWERMODE_LOWPOWER ((uint32_t)USART_CR3_IRLP)
284 #define IRDA_POWERMODE_NORMAL 0x00000000U
294 #define IRDA_FLAG_TXE ((uint32_t)USART_SR_TXE)
295 #define IRDA_FLAG_TC ((uint32_t)USART_SR_TC)
296 #define IRDA_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
297 #define IRDA_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
298 #define IRDA_FLAG_ORE ((uint32_t)USART_SR_ORE)
299 #define IRDA_FLAG_NE ((uint32_t)USART_SR_NE)
300 #define IRDA_FLAG_FE ((uint32_t)USART_SR_FE)
301 #define IRDA_FLAG_PE ((uint32_t)USART_SR_PE)
315 #define IRDA_IT_PE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
316 #define IRDA_IT_TXE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
317 #define IRDA_IT_TC ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
318 #define IRDA_IT_RXNE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
319 #define IRDA_IT_IDLE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
321 #define IRDA_IT_LBD ((uint32_t)(IRDA_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
323 #define IRDA_IT_CTS ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
324 #define IRDA_IT_ERR ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_EIE))
344 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
345 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) do{ \
346 (__HANDLE__)->gState = HAL_IRDA_STATE_RESET; \
347 (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET; \
348 (__HANDLE__)->MspInitCallback = NULL; \
349 (__HANDLE__)->MspDeInitCallback = NULL; \
352 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) do{ \
353 (__HANDLE__)->gState = HAL_IRDA_STATE_RESET; \
354 (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET; \
364 #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
382 #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
403 #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
411 #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__) \
413 __IO uint32_t tmpreg = 0x00U; \
414 tmpreg = (__HANDLE__)->Instance->SR; \
415 tmpreg = (__HANDLE__)->Instance->DR; \
425 #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
433 #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
441 #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
449 #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
465 #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
466 (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
467 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & IRDA_IT_MASK)))
482 #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
483 (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
484 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & IRDA_IT_MASK)))
500 #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == IRDA_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == IRDA_CR2_REG_INDEX)? \
501 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & IRDA_IT_MASK))
507 #define __HAL_IRDA_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 |= USART_CR3_ONEBIT)
513 #define __HAL_IRDA_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
521 #define __HAL_IRDA_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
529 #define __HAL_IRDA_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
549 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
617 #define IRDA_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
618 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
620 #define IRDA_CR1_REG_INDEX 1U
621 #define IRDA_CR2_REG_INDEX 2U
622 #define IRDA_CR3_REG_INDEX 3U
631 #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_8B) || \
632 ((LENGTH) == IRDA_WORDLENGTH_9B))
634 #define IS_IRDA_PARITY(PARITY) (((PARITY) == IRDA_PARITY_NONE) || \
635 ((PARITY) == IRDA_PARITY_EVEN) || \
636 ((PARITY) == IRDA_PARITY_ODD))
638 #define IS_IRDA_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00000000U))
640 #define IS_IRDA_POWERMODE(MODE) (((MODE) == IRDA_POWERMODE_LOWPOWER) || \
641 ((MODE) == IRDA_POWERMODE_NORMAL))
643 #define IS_IRDA_BAUDRATE(BAUDRATE) ((BAUDRATE) < 115201U)
645 #define IRDA_DIV(_PCLK_, _BAUD_) ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(4U*(((uint64_t)(_BAUD_))))))
647 #define IRDA_DIVMANT(_PCLK_, _BAUD_) (IRDA_DIV((_PCLK_), (_BAUD_))/100U)
649 #define IRDA_DIVFRAQ(_PCLK_, _BAUD_) ((((IRDA_DIV((_PCLK_), (_BAUD_)) - (IRDA_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U)
653 #define IRDA_BRR(_PCLK_, _BAUD_) (((IRDA_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
654 (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
655 (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))