Subversion Repositories DashDisplay

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 5
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_irda.c
3
  * @file    stm32f1xx_hal_irda.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.0.1
5
  * @version V1.0.4
6
  * @date    31-July-2015
6
  * @date    29-April-2016
7
  * @brief   IRDA HAL module driver.
7
  * @brief   IRDA HAL module driver.
8
  *          This file provides firmware functions to manage the following
8
  *          This file provides firmware functions to manage the following
9
  *          functionalities of the IrDA SIR ENDEC block (IrDA):
9
  *          functionalities of the IrDA SIR ENDEC block (IrDA):
10
  *           + Initialization and de-initialization functions
10
  *           + Initialization and de-initialization functions
11
  *           + IO operation functions
11
  *           + IO operation functions
Line 101... Line 101...
101
 
101
 
102
  @endverbatim
102
  @endverbatim
103
  ******************************************************************************
103
  ******************************************************************************
104
  * @attention
104
  * @attention
105
  *
105
  *
106
  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
106
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
107
  *
107
  *
108
  * Redistribution and use in source and binary forms, with or without modification,
108
  * Redistribution and use in source and binary forms, with or without modification,
109
  * are permitted provided that the following conditions are met:
109
  * are permitted provided that the following conditions are met:
110
  *   1. Redistributions of source code must retain the above copyright notice,
110
  *   1. Redistributions of source code must retain the above copyright notice,
111
  *      this list of conditions and the following disclaimer.
111
  *      this list of conditions and the following disclaimer.
Line 197... Line 197...
197
  This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
197
  This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
198
  in IrDA mode.
198
  in IrDA mode.
199
  (+) For the asynchronous mode only these parameters can be configured:
199
  (+) For the asynchronous mode only these parameters can be configured:
200
      (++) Baud Rate
200
      (++) Baud Rate
201
      (++) Word Length
201
      (++) Word Length
202
      (++) Parity: If the parity is enabled, then the MSB bit of the data written
202
      (++) Parity
203
           in the data register is transmitted but is changed by the parity bit.
-
 
204
           Depending on the frame length defined by the M bit (8-bits or 9-bits),
-
 
205
           the possible IRDA frame formats are as listed in the following table:
-
 
206
      (+++)    +-------------------------------------------------------------+
-
 
207
      (+++)    |   M bit |  PCE bit  |            IRDA frame                 |
-
 
208
      (+++)    |---------------------|---------------------------------------|
-
 
209
      (+++)    |    0    |    0      |    | SB | 8 bit data | STB |          |
-
 
210
      (+++)    |---------|-----------|---------------------------------------|
-
 
211
      (+++)    |    0    |    1      |    | SB | 7 bit data | PB | STB |     |
-
 
212
      (+++)    |---------|-----------|---------------------------------------|
-
 
213
      (+++)    |    1    |    0      |    | SB | 9 bit data | STB |          |
-
 
214
      (+++)    |---------|-----------|---------------------------------------|
-
 
215
      (+++)    |    1    |    1      |    | SB | 8 bit data | PB | STB |     |
-
 
216
      (+++)    +-------------------------------------------------------------+
-
 
217
      (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
203
      (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
218
           not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
204
           not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
219
           specification specifies a minimum of 10 ms delay between transmission and
205
           specification specifies a minimum of 10 ms delay between transmission and
220
           reception (IrDA is a half duplex protocol).
206
           reception (IrDA is a half duplex protocol).
221
      (++) Mode: Receiver/transmitter modes
207
      (++) Mode: Receiver/transmitter modes
Line 227... Line 213...
227
 
213
 
228
@endverbatim
214
@endverbatim
229
  * @{
215
  * @{
230
  */
216
  */
231
 
217
 
-
 
218
 
-
 
219
/*
-
 
220
  Additionnal remark: If the parity is enabled, then the MSB bit of the data written
-
 
221
                      in the data register is transmitted but is changed by the parity bit.
-
 
222
                      Depending on the frame length defined by the M bit (8-bits or 9-bits),
-
 
223
                      the possible IRDA frame formats are as listed in the following table:
-
 
224
    +-------------------------------------------------------------+
-
 
225
    |   M bit |  PCE bit  |            IRDA frame                 |
-
 
226
    |---------------------|---------------------------------------|
-
 
227
    |    0    |    0      |    | SB | 8 bit data | STB |          |
-
 
228
    |---------|-----------|---------------------------------------|
-
 
229
    |    0    |    1      |    | SB | 7 bit data | PB | STB |     |
-
 
230
    |---------|-----------|---------------------------------------|
-
 
231
    |    1    |    0      |    | SB | 9 bit data | STB |          |
-
 
232
    |---------|-----------|---------------------------------------|
-
 
233
    |    1    |    1      |    | SB | 8 bit data | PB | STB |     |
-
 
234
    +-------------------------------------------------------------+
-
 
235
*/
-
 
236
 
232
/**
237
/**
233
  * @brief  Initializes the IRDA mode according to the specified
238
  * @brief  Initializes the IRDA mode according to the specified
234
  *         parameters in the IRDA_InitTypeDef and create the associated handle.
239
  *         parameters in the IRDA_InitTypeDef and create the associated handle.
235
  * @param  hirda: Pointer to a IRDA_HandleTypeDef structure that contains
240
  * @param  hirda: Pointer to a IRDA_HandleTypeDef structure that contains
236
  *                the configuration information for the specified IRDA module.
241
  *                the configuration information for the specified IRDA module.
Line 331... Line 336...
331
  *                the configuration information for the specified IRDA module.
336
  *                the configuration information for the specified IRDA module.
332
  * @retval None
337
  * @retval None
333
  */
338
  */
334
 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
339
 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
335
{
340
{
-
 
341
  /* Prevent unused argument(s) compilation warning */
-
 
342
  UNUSED(hirda);
336
  /* NOTE: This function should not be modified, when the callback is needed,
343
  /* NOTE: This function should not be modified, when the callback is needed,
337
           the HAL_IRDA_MspInit can be implemented in the user file
344
           the HAL_IRDA_MspInit can be implemented in the user file
338
   */
345
   */
339
}
346
}
340
 
347
 
Line 344... Line 351...
344
  *                the configuration information for the specified IRDA module.
351
  *                the configuration information for the specified IRDA module.
345
  * @retval None
352
  * @retval None
346
  */
353
  */
347
 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
354
 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
348
{
355
{
-
 
356
  /* Prevent unused argument(s) compilation warning */
-
 
357
  UNUSED(hirda);
349
  /* NOTE: This function should not be modified, when the callback is needed,
358
  /* NOTE: This function should not be modified, when the callback is needed,
350
           the HAL_IRDA_MspDeInit can be implemented in the user file
359
           the HAL_IRDA_MspDeInit can be implemented in the user file
351
   */
360
   */
352
}
361
}
353
 
362
 
Line 636... Line 645...
636
    }
645
    }
637
 
646
 
638
    /* Process Unlocked */
647
    /* Process Unlocked */
639
    __HAL_UNLOCK(hirda);
648
    __HAL_UNLOCK(hirda);
640
 
649
 
641
    /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
-
 
642
    __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
-
 
643
 
-
 
644
    /* Enable the IRDA Transmit Data Register Empty Interrupt */
650
    /* Enable the IRDA Transmit Data Register Empty Interrupt */
645
    __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
651
    __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
646
   
652
   
647
    return HAL_OK;
653
    return HAL_OK;
648
  }
654
  }
Line 974... Line 980...
974
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
980
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
975
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
981
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
976
  /* IRDA parity error interrupt occurred -----------------------------------*/
982
  /* IRDA parity error interrupt occurred -----------------------------------*/
977
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
983
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
978
  {
984
  {
979
    __HAL_IRDA_CLEAR_PEFLAG(hirda);
-
 
980
    hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
985
    hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
981
  }
986
  }
982
 
987
 
983
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
988
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
984
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
989
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
985
  /* IRDA frame error interrupt occurred ------------------------------------*/
990
  /* IRDA frame error interrupt occurred ------------------------------------*/
986
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
991
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
987
  {
992
  {
988
    __HAL_IRDA_CLEAR_FEFLAG(hirda);
-
 
989
    hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
993
    hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
990
  }
994
  }
991
 
995
 
992
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
996
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
993
  /* IRDA noise error interrupt occurred ------------------------------------*/
997
  /* IRDA noise error interrupt occurred ------------------------------------*/
994
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
998
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
995
  {
999
  {
996
    __HAL_IRDA_CLEAR_NEFLAG(hirda);
-
 
997
    hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
1000
    hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
998
  }
1001
  }
999
 
1002
 
1000
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
1003
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
1001
  /* IRDA Over-Run interrupt occurred ---------------------------------------*/
1004
  /* IRDA Over-Run interrupt occurred ---------------------------------------*/
1002
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
1005
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
1003
  {
1006
  {
1004
    __HAL_IRDA_CLEAR_OREFLAG(hirda);
-
 
1005
    hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
1007
    hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
1006
  }
1008
  }
1007
 
1009
 
1008
  /* Call the Error call Back in case of Errors */
1010
  /* Call the Error call Back in case of Errors */
1009
  if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
1011
  if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
Line 1011... Line 1013...
1011
    /* Disable PE and ERR interrupt */
1013
    /* Disable PE and ERR interrupt */
1012
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1014
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1013
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1015
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1014
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
1016
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
1015
   
1017
   
-
 
1018
    /* Clear all the error flag at once */
-
 
1019
    __HAL_IRDA_CLEAR_PEFLAG(hirda);
-
 
1020
 
1016
    /* Set the IRDA state ready to be able to start again the process */
1021
    /* Set the IRDA state ready to be able to start again the process */
1017
    hirda->State = HAL_IRDA_STATE_READY;
1022
    hirda->State = HAL_IRDA_STATE_READY;
1018
    HAL_IRDA_ErrorCallback(hirda);
1023
    HAL_IRDA_ErrorCallback(hirda);
1019
  }
1024
  }
1020
 
1025
 
Line 1050... Line 1055...
1050
  *                the configuration information for the specified IRDA module.
1055
  *                the configuration information for the specified IRDA module.
1051
  * @retval None
1056
  * @retval None
1052
  */
1057
  */
1053
 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
1058
 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
1054
{
1059
{
-
 
1060
  /* Prevent unused argument(s) compilation warning */
-
 
1061
  UNUSED(hirda);
1055
  /* NOTE: This function should not be modified, when the callback is needed,
1062
  /* NOTE: This function should not be modified, when the callback is needed,
1056
           the HAL_IRDA_TxCpltCallback can be implemented in the user file
1063
           the HAL_IRDA_TxCpltCallback can be implemented in the user file
1057
   */
1064
   */
1058
}
1065
}
1059
 
1066
 
Line 1063... Line 1070...
1063
  *                the configuration information for the specified USART module.
1070
  *                the configuration information for the specified USART module.
1064
  * @retval None
1071
  * @retval None
1065
  */
1072
  */
1066
 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
1073
 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
1067
{
1074
{
-
 
1075
  /* Prevent unused argument(s) compilation warning */
-
 
1076
  UNUSED(hirda);
1068
  /* NOTE: This function should not be modified, when the callback is needed,
1077
  /* NOTE: This function should not be modified, when the callback is needed,
1069
           the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file
1078
           the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file
1070
   */
1079
   */
1071
}
1080
}
1072
 
1081
 
Line 1076... Line 1085...
1076
  *                the configuration information for the specified IRDA module.
1085
  *                the configuration information for the specified IRDA module.
1077
  * @retval None
1086
  * @retval None
1078
  */
1087
  */
1079
__weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
1088
__weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
1080
{
1089
{
-
 
1090
  /* Prevent unused argument(s) compilation warning */
-
 
1091
  UNUSED(hirda);
1081
  /* NOTE: This function should not be modified, when the callback is needed,
1092
  /* NOTE: This function should not be modified, when the callback is needed,
1082
           the HAL_IRDA_RxCpltCallback can be implemented in the user file
1093
           the HAL_IRDA_RxCpltCallback can be implemented in the user file
1083
   */
1094
   */
1084
}
1095
}
1085
 
1096
 
Line 1089... Line 1100...
1089
  *                the configuration information for the specified IRDA module.
1100
  *                the configuration information for the specified IRDA module.
1090
  * @retval None
1101
  * @retval None
1091
  */
1102
  */
1092
__weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
1103
__weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
1093
{
1104
{
-
 
1105
  /* Prevent unused argument(s) compilation warning */
-
 
1106
  UNUSED(hirda);
1094
  /* NOTE : This function should not be modified, when the callback is needed,
1107
  /* NOTE : This function should not be modified, when the callback is needed,
1095
            the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file
1108
            the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file
1096
   */
1109
   */
1097
}
1110
}
1098
 
1111
 
Line 1102... Line 1115...
1102
  *                the configuration information for the specified IRDA module.
1115
  *                the configuration information for the specified IRDA module.
1103
  * @retval None
1116
  * @retval None
1104
  */
1117
  */
1105
 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
1118
 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
1106
{
1119
{
-
 
1120
  /* Prevent unused argument(s) compilation warning */
-
 
1121
  UNUSED(hirda);
1107
  /* NOTE: This function should not be modified, when the callback is needed,
1122
  /* NOTE: This function should not be modified, when the callback is needed,
1108
           the HAL_IRDA_ErrorCallback can be implemented in the user file
1123
           the HAL_IRDA_ErrorCallback can be implemented in the user file
1109
   */
1124
   */
1110
}
1125
}
1111
 
1126
 
Line 1460... Line 1475...
1460
      }
1475
      }
1461
    }
1476
    }
1462
 
1477
 
1463
    if(--hirda->RxXferCount == 0)
1478
    if(--hirda->RxXferCount == 0)
1464
    {
1479
    {
1465
 
-
 
1466
      __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
1480
      __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
1467
     
1481
     
1468
      if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1482
      if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1469
      {
1483
      {
1470
        hirda->State = HAL_IRDA_STATE_BUSY_TX;
1484
        hirda->State = HAL_IRDA_STATE_BUSY_TX;
1471
      }
1485
      }
1472
      else
1486
      else
1473
      {
1487
      {
-
 
1488
        /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
-
 
1489
        __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
-
 
1490
 
1474
        /* Disable the IRDA Parity Error Interrupt */
1491
        /* Disable the IRDA Parity Error Interrupt */
1475
        __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1492
        __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1476
 
1493
 
1477
        /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
-
 
1478
        __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
-
 
1479
 
1494
 
1480
        hirda->State = HAL_IRDA_STATE_READY;
1495
        hirda->State = HAL_IRDA_STATE_READY;
1481
      }
1496
      }
1482
      HAL_IRDA_RxCpltCallback(hirda);
1497
      HAL_IRDA_RxCpltCallback(hirda);
1483
 
1498