214 #ifdef HAL_IRDA_MODULE_ENABLED
225 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
242 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(
IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
302 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
304 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
309 hirda->Lock = HAL_UNLOCKED;
311 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
314 if (hirda->MspInitCallback == NULL)
320 hirda->MspInitCallback(hirda);
330 __HAL_IRDA_DISABLE(hirda);
333 IRDA_SetConfig(hirda);
338 CLEAR_BIT(hirda->Instance->CR2, (USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN));
339 CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
342 __HAL_IRDA_ENABLE(hirda);
345 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
348 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
351 SET_BIT(hirda->Instance->CR3, USART_CR3_IREN);
354 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
376 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
381 __HAL_IRDA_DISABLE(hirda);
384 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
385 if (hirda->MspDeInitCallback == NULL)
390 hirda->MspDeInitCallback(hirda);
395 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
438 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
462 HAL_StatusTypeDef status = HAL_OK;
464 if (pCallback == NULL)
467 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
477 hirda->TxHalfCpltCallback = pCallback;
481 hirda->TxCpltCallback = pCallback;
485 hirda->RxHalfCpltCallback = pCallback;
489 hirda->RxCpltCallback = pCallback;
493 hirda->ErrorCallback = pCallback;
497 hirda->AbortCpltCallback = pCallback;
501 hirda->AbortTransmitCpltCallback = pCallback;
505 hirda->AbortReceiveCpltCallback = pCallback;
509 hirda->MspInitCallback = pCallback;
513 hirda->MspDeInitCallback = pCallback;
518 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
530 hirda->MspInitCallback = pCallback;
534 hirda->MspDeInitCallback = pCallback;
539 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
549 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
580 HAL_StatusTypeDef status = HAL_OK;
628 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
649 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
659 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
767 uint32_t tickstart = 0U;
772 if ((pData == NULL) || (Size == 0U))
780 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
786 hirda->TxXferSize = Size;
787 hirda->TxXferCount = Size;
788 while (hirda->TxXferCount > 0U)
790 hirda->TxXferCount--;
791 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
793 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
797 tmp = (
const uint16_t *) pData;
798 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
799 if (hirda->Init.Parity == IRDA_PARITY_NONE)
810 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
814 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
818 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
852 uint32_t tickstart = 0U;
857 if ((pData == NULL) || (Size == 0U))
865 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
871 hirda->RxXferSize = Size;
872 hirda->RxXferCount = Size;
875 while (hirda->RxXferCount > 0U)
877 hirda->RxXferCount--;
879 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
881 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
885 tmp = (uint16_t *) pData ;
886 if (hirda->Init.Parity == IRDA_PARITY_NONE)
888 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
893 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
899 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
903 if (hirda->Init.Parity == IRDA_PARITY_NONE)
905 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
909 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
944 if ((pData == NULL) || (Size == 0U))
952 hirda->pTxBuffPtr = pData;
953 hirda->TxXferSize = Size;
954 hirda->TxXferCount = Size;
956 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
963 SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
989 if ((pData == NULL) || (Size == 0U))
997 hirda->pRxBuffPtr = pData;
998 hirda->RxXferSize = Size;
999 hirda->RxXferCount = Size;
1001 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1005 __HAL_UNLOCK(hirda);
1007 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1010 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
1015 SET_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
1019 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1042 const uint32_t *tmp;
1047 if ((pData == NULL) || (Size == 0U))
1055 hirda->pTxBuffPtr = pData;
1056 hirda->TxXferSize = Size;
1057 hirda->TxXferCount = Size;
1059 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1063 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
1066 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
1069 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
1072 hirda->hdmatx->XferAbortCallback = NULL;
1075 tmp = (
const uint32_t *)&pData;
1076 HAL_DMA_Start_IT(hirda->hdmatx, *(
const uint32_t *)tmp, (uint32_t)&hirda->Instance->DR, Size);
1079 __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);
1082 __HAL_UNLOCK(hirda);
1086 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1115 if ((pData == NULL) || (Size == 0U))
1123 hirda->pRxBuffPtr = pData;
1124 hirda->RxXferSize = Size;
1126 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1130 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
1133 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
1136 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
1139 hirda->hdmarx->XferAbortCallback = NULL;
1142 tmp = (uint32_t *)&pData;
1143 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t *)tmp, Size);
1146 __HAL_IRDA_CLEAR_OREFLAG(hirda);
1149 __HAL_UNLOCK(hirda);
1151 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1154 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1158 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1162 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1180 uint32_t dmarequest = 0x00U;
1185 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
1189 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1192 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1196 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1197 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1200 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1204 __HAL_UNLOCK(hirda);
1223 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1229 __HAL_IRDA_CLEAR_OREFLAG(hirda);
1232 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1234 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1236 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1239 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1243 __HAL_UNLOCK(hirda);
1256 uint32_t dmarequest = 0x00U;
1264 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
1267 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1270 if (hirda->hdmatx != NULL)
1274 IRDA_EndTxTransfer(hirda);
1278 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1281 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1284 if (hirda->hdmarx != NULL)
1288 IRDA_EndRxTransfer(hirda);
1309 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1310 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1313 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1315 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1318 if (hirda->hdmatx != NULL)
1322 hirda->hdmatx->XferAbortCallback = NULL;
1329 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1331 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1334 if (hirda->hdmarx != NULL)
1338 hirda->hdmarx->XferAbortCallback = NULL;
1345 hirda->TxXferCount = 0x00U;
1346 hirda->RxXferCount = 0x00U;
1349 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1373 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1376 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1378 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1381 if (hirda->hdmatx != NULL)
1385 hirda->hdmatx->XferAbortCallback = NULL;
1392 hirda->TxXferCount = 0x00U;
1415 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1416 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1419 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1421 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1424 if (hirda->hdmarx != NULL)
1428 hirda->hdmarx->XferAbortCallback = NULL;
1435 hirda->RxXferCount = 0x00U;
1459 uint32_t AbortCplt = 0x01U;
1462 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1463 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1468 if (hirda->hdmatx != NULL)
1472 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1474 hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
1478 hirda->hdmatx->XferAbortCallback = NULL;
1482 if (hirda->hdmarx != NULL)
1486 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1488 hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
1492 hirda->hdmarx->XferAbortCallback = NULL;
1497 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1500 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1503 if (hirda->hdmatx != NULL)
1511 hirda->hdmatx->XferAbortCallback = NULL;
1521 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1523 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1526 if (hirda->hdmarx != NULL)
1534 hirda->hdmarx->XferAbortCallback = NULL;
1545 if (AbortCplt == 0x01U)
1548 hirda->TxXferCount = 0x00U;
1549 hirda->RxXferCount = 0x00U;
1552 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1559 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1561 hirda->AbortCpltCallback(hirda);
1588 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1591 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1593 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1596 if (hirda->hdmatx != NULL)
1600 hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
1606 hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
1612 hirda->TxXferCount = 0x00U;
1618 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1620 hirda->AbortTransmitCpltCallback(hirda);
1630 hirda->TxXferCount = 0x00U;
1636 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1638 hirda->AbortTransmitCpltCallback(hirda);
1665 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1666 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1669 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1671 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1674 if (hirda->hdmarx != NULL)
1678 hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
1684 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
1690 hirda->RxXferCount = 0x00U;
1696 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1698 hirda->AbortReceiveCpltCallback(hirda);
1708 hirda->RxXferCount = 0x00U;
1714 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1716 hirda->AbortReceiveCpltCallback(hirda);
1734 uint32_t isrflags = READ_REG(hirda->Instance->SR);
1735 uint32_t cr1its = READ_REG(hirda->Instance->CR1);
1736 uint32_t cr3its = READ_REG(hirda->Instance->CR3);
1737 uint32_t errorflags = 0x00U;
1738 uint32_t dmarequest = 0x00U;
1741 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
1742 if (errorflags == RESET)
1745 if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
1747 IRDA_Receive_IT(hirda);
1753 if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
1756 if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
1758 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
1762 if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
1764 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
1768 if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
1770 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
1774 if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
1776 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
1779 if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
1782 if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
1784 IRDA_Receive_IT(hirda);
1789 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1790 if (((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
1795 IRDA_EndRxTransfer(hirda);
1798 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1800 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1803 if (hirda->hdmarx != NULL)
1807 hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
1813 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
1818 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1820 hirda->ErrorCallback(hirda);
1829 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1831 hirda->ErrorCallback(hirda);
1842 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1844 hirda->ErrorCallback(hirda);
1850 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
1857 if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
1859 IRDA_Transmit_IT(hirda);
1864 if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
1866 IRDA_EndTransmit_IT(hirda);
2028 uint32_t temp1 = 0x00U, temp2 = 0x00U;
2029 temp1 = hirda->gState;
2030 temp2 = hirda->RxState;
2043 return hirda->ErrorCode;
2058 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2089 if ((hdma->
Instance->CR & DMA_SxCR_CIRC) == 0U)
2091 hirda->TxXferCount = 0U;
2095 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
2098 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2103 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2105 hirda->TxCpltCallback(hirda);
2123 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2125 hirda->TxHalfCpltCallback(hirda);
2143 if ((hdma->
Instance->CR & DMA_SxCR_CIRC) == 0U)
2145 hirda->RxXferCount = 0U;
2148 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
2149 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2153 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
2159 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2161 hirda->RxCpltCallback(hirda);
2178 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2180 hirda->RxHalfCpltCallback(hirda);
2195 uint32_t dmarequest = 0x00U;
2199 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
2202 hirda->TxXferCount = 0U;
2203 IRDA_EndTxTransfer(hirda);
2207 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
2210 hirda->RxXferCount = 0U;
2211 IRDA_EndRxTransfer(hirda);
2214 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
2216 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2218 hirda->ErrorCallback(hirda);
2236 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(
IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
2239 while ((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
2242 if (Timeout != HAL_MAX_DELAY)
2244 if ((Timeout == 0U) || ((
HAL_GetTick() - Tickstart) > Timeout))
2247 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2248 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2254 __HAL_UNLOCK(hirda);
2271 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
2285 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2286 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2301 hirda->RxXferCount = 0x00U;
2302 hirda->TxXferCount = 0x00U;
2304 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2306 hirda->ErrorCallback(hirda);
2325 hirda->hdmatx->XferAbortCallback = NULL;
2328 if (hirda->hdmarx != NULL)
2330 if (hirda->hdmarx->XferAbortCallback != NULL)
2337 hirda->TxXferCount = 0x00U;
2338 hirda->RxXferCount = 0x00U;
2341 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
2348 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2350 hirda->AbortCpltCallback(hirda);
2369 hirda->hdmarx->XferAbortCallback = NULL;
2372 if (hirda->hdmatx != NULL)
2374 if (hirda->hdmatx->XferAbortCallback != NULL)
2381 hirda->TxXferCount = 0x00U;
2382 hirda->RxXferCount = 0x00U;
2385 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
2392 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2394 hirda->AbortCpltCallback(hirda);
2413 hirda->TxXferCount = 0x00U;
2419 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2421 hirda->AbortTransmitCpltCallback(hirda);
2440 hirda->RxXferCount = 0x00U;
2446 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2448 hirda->AbortReceiveCpltCallback(hirda);
2463 const uint16_t *tmp;
2468 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
2470 tmp = (
const uint16_t *) hirda->pTxBuffPtr;
2471 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
2472 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2474 hirda->pTxBuffPtr += 2U;
2478 hirda->pTxBuffPtr += 1U;
2483 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
2486 if (--hirda->TxXferCount == 0U)
2489 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
2492 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2512 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2515 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2520 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2522 hirda->TxCpltCallback(hirda);
2545 uhdata = (uint16_t) READ_REG(hirda->Instance->DR);
2546 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
2548 tmp = (uint16_t *) hirda->pRxBuffPtr;
2549 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2551 *tmp = (uint16_t)(uhdata & (uint16_t)0x01FF);
2552 hirda->pRxBuffPtr += 2U;
2556 *tmp = (uint16_t)(uhdata & (uint16_t)0x00FF);
2557 hirda->pRxBuffPtr += 1U;
2562 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2564 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x00FF);
2568 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x007F);
2572 if (--hirda->RxXferCount == 0U)
2575 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
2578 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
2581 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2586 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2588 hirda->RxCpltCallback(hirda);
2615 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
2616 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
2617 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
2618 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
2619 assert_param(IS_IRDA_MODE(hirda->Init.Mode));
2620 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
2624 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
2628 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE));
2635 SET_BIT(hirda->Instance->CR1, (hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode));
2639 CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
2642 #if defined(USART6) && defined(UART9) && defined(UART10)
2643 if ((hirda->Instance == USART1) || (hirda->Instance == USART6) || (hirda->Instance == UART9) || (hirda->Instance == UART10))
2646 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2648 #elif defined(USART6)
2649 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
2652 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2655 if(hirda->Instance == USART1)
2658 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2664 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer.
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
DeInitializes the IRDA peripheral.
void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
IRDA MSP Init.
HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
Initializes the IRDA mode according to the specified parameters in the IRDA_InitTypeDef and create th...
void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
IRDA MSP DeInit.
HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback)
Register a User IRDA Callback To be used instead of the weak predefined callback.
HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID)
Unregister an IRDA callback IRDA callback is redirected to the weak predefined callback.
HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
Receive an amount of data in non blocking mode.
void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Receive Complete callback.
void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Transmit Complete callback.
HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
Sends an amount of data in blocking mode.
HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
Stops the DMA Transfer.
HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
Receive an amount of data in blocking mode.
void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
Tx Transfer complete callback.
HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
Pauses the DMA Transfer.
void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
Tx Half Transfer completed callback.
HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
Abort ongoing Transmit transfer (Interrupt mode).
void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
Rx Transfer complete callback.
void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
Rx Half Transfer complete callback.
void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
This function handles IRDA interrupt request.
HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
Abort ongoing Receive transfer (Interrupt mode).
HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
Send an amount of data in non blocking mode.
HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
Abort ongoing Transmit transfer (blocking mode).
HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
Receives an amount of data in DMA mode.
HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
Abort ongoing Receive transfer (blocking mode).
HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
Send an amount of data in DMA mode.
HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
Abort ongoing transfers (blocking mode).
void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
IRDA error callback.
HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
Resumes the DMA Transfer.
HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
Abort ongoing transfers (Interrupt mode).
void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Complete callback.
uint32_t HAL_IRDA_GetError(const IRDA_HandleTypeDef *hirda)
Return the IRDA error code.
HAL_IRDA_StateTypeDef HAL_IRDA_GetState(const IRDA_HandleTypeDef *hirda)
Return the IRDA state.
void(* pIRDA_CallbackTypeDef)(IRDA_HandleTypeDef *hirda)
HAL IRDA Callback pointer definition.
HAL_IRDA_CallbackIDTypeDef
HAL IRDA Callback ID enumeration definition.
struct __IRDA_HandleTypeDef else typedef struct endif IRDA_HandleTypeDef
IRDA handle Structure definition.
HAL_IRDA_StateTypeDef
HAL IRDA State structures definition.
@ HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID
@ HAL_IRDA_RX_HALFCOMPLETE_CB_ID
@ HAL_IRDA_MSPDEINIT_CB_ID
@ HAL_IRDA_RX_COMPLETE_CB_ID
@ HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID
@ HAL_IRDA_TX_COMPLETE_CB_ID
@ HAL_IRDA_TX_HALFCOMPLETE_CB_ID
@ HAL_IRDA_ABORT_COMPLETE_CB_ID
void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda)
Initialize the callbacks to their default values.
uint32_t HAL_RCC_GetPCLK1Freq(void)
Returns the PCLK1 frequency.
uint32_t HAL_RCC_GetPCLK2Freq(void)
Returns the PCLK2 frequency.
This file contains all the functions prototypes for the HAL module driver.
DMA handle Structure definition.
DMA_Stream_TypeDef * Instance