mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Diff: targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_smbus.c
- Revision:
- 630:825f75ca301e
- Parent:
- 441:d2c15dda23c1
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_smbus.c Mon Sep 28 10:30:09 2015 +0100 +++ b/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_smbus.c Mon Sep 28 10:45:10 2015 +0100 @@ -2,16 +2,16 @@ ****************************************************************************** * @file stm32f0xx_hal_smbus.c * @author MCD Application Team - * @version V1.2.0 - * @date 11-December-2014 + * @version V1.3.0 + * @date 26-June-2015 * @brief SMBUS HAL module driver. - * * This file provides firmware functions to manage the following * functionalities of the System Management Bus (SMBus) peripheral, - * based on I2C principales of operation : + * based on I2C principles of operation : * + Initialization and de-initialization functions * + IO operation functions * + Peripheral State and Errors functions + * @verbatim ============================================================================== ##### How to use this driver ##### @@ -22,22 +22,22 @@ (#) Declare a SMBUS_HandleTypeDef handle structure, for example: SMBUS_HandleTypeDef hsmbus; - (#)Initialize the SMBUS low level resources by implement the HAL_SMBUS_MspInit ()API: - (##) Enable the SMBUSx interface clock - (##) SMBUS pins configuration + (#)Initialize the SMBUS low level resources by implementing the HAL_SMBUS_MspInit() API: + (++) Enable the SMBUSx interface clock with __HAL_RCC_I2Cx_CLK_ENABLE() + (++) SMBUS pins configuration (+++) Enable the clock for the SMBUS GPIOs (+++) Configure SMBUS pins as alternate function open-drain - (##) NVIC configuration if you need to use interrupt process + (++) NVIC configuration if you need to use interrupt process (+++) Configure the SMBUSx interrupt priority (+++) Enable the NVIC SMBUS IRQ Channel - (#) Configure the Communication Clock Timing, Bus Timeout, Own Address1, Master Adressing Mode, + (#) Configure the Communication Clock Timing, Bus Timeout, Own Address1, Master Addressing Mode, Dual Addressing mode, Own Address2, Own Address2 Mask, General call, Nostretch mode, Peripheral mode and Packet Error Check mode in the hsmbus Init structure. (#) Initialize the SMBUS registers by calling the HAL_SMBUS_Init() API: - (++) These API s configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) - by calling the customed HAL_SMBUS_MspInit(&hsmbus) API. + (++) These API's configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) + by calling the customized HAL_SMBUS_MspInit(&hsmbus) API. (#) To check if target device is ready for communication, use the function HAL_SMBUS_IsDeviceReady() @@ -46,35 +46,35 @@ *** Interrupt mode IO operation *** =================================== [..] - (+) Transmit in master/host SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Master_Transmit_IT() - (++) At transmission end of transfer HAL_SMBUS_MasterTxCpltCallback is executed and user can - add his own code by customization of function pointer HAL_SMBUS_MasterTxCpltCallback - (+) Receive in master/host SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Master_Receive_IT() - (++) At reception end of transfer HAL_SMBUS_MasterRxCpltCallback is executed and user can - add his own code by customization of function pointer HAL_SMBUS_MasterRxCpltCallback - (+) Abort a master/host SMBUS process commnunication with Interrupt using HAL_SMBUS_Master_Abort_IT() + (+) Transmit in master/host SMBUS mode an amount of data in non-blocking mode using HAL_SMBUS_Master_Transmit_IT() + (++) At transmission end of transfer HAL_SMBUS_MasterTxCpltCallback() is executed and user can + add his own code by customization of function pointer HAL_SMBUS_MasterTxCpltCallback() + (+) Receive in master/host SMBUS mode an amount of data in non-blocking mode using HAL_SMBUS_Master_Receive_IT() + (++) At reception end of transfer HAL_SMBUS_MasterRxCpltCallback() is executed and user can + add his own code by customization of function pointer HAL_SMBUS_MasterRxCpltCallback() + (+) Abort a master/host SMBUS process communication with Interrupt using HAL_SMBUS_Master_Abort_IT() (++) The associated previous transfer callback is called at the end of abort process - (++) mean HAL_SMBUS_MasterTxCpltCallback in case of previous state was master transmit - (++) mean HAL_SMBUS_MasterRxCpltCallback in case of previous state was master receive + (++) mean HAL_SMBUS_MasterTxCpltCallback() in case of previous state was master transmit + (++) mean HAL_SMBUS_MasterRxCpltCallback() in case of previous state was master receive (+) Enable/disable the Address listen mode in slave/device or host/slave SMBUS mode - using HAL_SMBUS_Slave_Listen_IT() HAL_SMBUS_DisableListen_IT() - (++) When address slave/device SMBUS match, HAL_SMBUS_SlaveAddrCallback is executed and user can + using HAL_SMBUS_EnableListen_IT() HAL_SMBUS_DisableListen_IT() + (++) When address slave/device SMBUS match, HAL_SMBUS_AddrCallback() is executed and user can add his own code to check the Address Match Code and the transmission direction request by master/host (Write/Read). - (++) At Listen mode end HAL_SMBUS_SlaveListenCpltCallback is executed and user can - add his own code by customization of function pointer HAL_SMBUS_SlaveListenCpltCallback - (+) Transmit in slave/device SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Slave_Transmit_IT() - (++) At transmission end of transfer HAL_SMBUS_SlaveTxCpltCallback is executed and user can - add his own code by customization of function pointer HAL_SMBUS_SlaveTxCpltCallback - (+) Receive in slave/device SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Slave_Receive_IT() - (++) At reception end of transfer HAL_SMBUS_SlaveRxCpltCallback is executed and user can - add his own code by customization of function pointer HAL_SMBUS_SlaveRxCpltCallback + (++) At Listen mode end HAL_SMBUS_ListenCpltCallback() is executed and user can + add his own code by customization of function pointer HAL_SMBUS_ListenCpltCallback() + (+) Transmit in slave/device SMBUS mode an amount of data in non-blocking mode using HAL_SMBUS_Slave_Transmit_IT() + (++) At transmission end of transfer HAL_SMBUS_SlaveTxCpltCallback() is executed and user can + add his own code by customization of function pointer HAL_SMBUS_SlaveTxCpltCallback() + (+) Receive in slave/device SMBUS mode an amount of data in non-blocking mode using HAL_SMBUS_Slave_Receive_IT() + (++) At reception end of transfer HAL_SMBUS_SlaveRxCpltCallback() is executed and user can + add his own code by customization of function pointer HAL_SMBUS_SlaveRxCpltCallback() (+) Enable/Disable the SMBUS alert mode using HAL_SMBUS_EnableAlert_IT() HAL_SMBUS_DisableAlert_IT() (++) When SMBUS Alert is generated HAL_SMBUS_ErrorCallback() is executed and user can - add his own code by customization of function pointer HAL_SMBUS_ErrorCallback + add his own code by customization of function pointer HAL_SMBUS_ErrorCallback() to check the Alert Error Code using function HAL_SMBUS_GetError() (+) Get HAL state machine or error values using HAL_SMBUS_GetState() or HAL_SMBUS_GetError() (+) In case of transfer Error, HAL_SMBUS_ErrorCallback() function is executed and user can - add his own code by customization of function pointer HAL_SMBUS_ErrorCallback + add his own code by customization of function pointer HAL_SMBUS_ErrorCallback() to check the Error Code using function HAL_SMBUS_GetError() *** SMBUS HAL driver macros list *** @@ -97,7 +97,7 @@ ****************************************************************************** * @attention * - * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -131,7 +131,7 @@ * @{ */ -/** @defgroup SMBUS SMBUS HAL module driver +/** @defgroup SMBUS SMBUS * @brief SMBUS HAL module driver * @{ */ @@ -139,8 +139,8 @@ #ifdef HAL_SMBUS_MODULE_ENABLED /* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/** @defgroup SMBUS_Private_Define SMBUS Private Define +/* Private constants ---------------------------------------------------------*/ +/** @defgroup SMBUS_Private_Define SMBUS Private Constants * @{ */ #define TIMING_CLEAR_MASK ((uint32_t)0xF0FFFFFF) /*<! SMBUS TIMING clear register Mask */ @@ -158,18 +158,9 @@ */ /* Private macro -------------------------------------------------------------*/ -/** @defgroup SMBUS_Private_Macros SMBUS Private Macros - * @{ - */ -#define __SMBUS_GET_ISR_REG(__HANDLE__) ((__HANDLE__)->Instance->ISR) -#define __SMBUS_CHECK_FLAG(__ISR__, __FLAG__) ((((__ISR__) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK))) -/** - * @} - */ - /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -/** @defgroup SMBUS_Private_Functions SMBUS Private Functions +/** @addtogroup SMBUS_Private_Functions SMBUS Private Functions * @{ */ static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout(SMBUS_HandleTypeDef *hsmbus, uint32_t Flag, FlagStatus Status, uint32_t Timeout); @@ -184,7 +175,7 @@ * @} */ -/* Exported functions ---------------------------------------------------------*/ +/* Exported functions --------------------------------------------------------*/ /** @defgroup SMBUS_Exported_Functions SMBUS Exported Functions * @{ @@ -198,7 +189,7 @@ ##### Initialization and de-initialization functions ##### =============================================================================== [..] This subsection provides a set of functions allowing to initialize and - de-initialiaze the SMBUSx peripheral: + de-initialize the SMBUSx peripheral: (+) User must Implement HAL_SMBUS_MspInit() function in which he configures all related peripherals resources (CLOCK, GPIO, IT and NVIC ). @@ -220,15 +211,15 @@ (+) Call the function HAL_SMBUS_DeInit() to restore the default configuration - of the selected SMBUSx periperal. + of the selected SMBUSx peripheral. @endverbatim * @{ */ /** - * @brief Initializes the SMBUS according to the specified parameters - * in the SMBUS_InitTypeDef and create the associated handle. + * @brief Initialize the SMBUS according to the specified parameters + * in the SMBUS_InitTypeDef and initialize the associated handle. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status @@ -256,6 +247,9 @@ if(hsmbus->State == HAL_SMBUS_STATE_RESET) { + /* Allocate lock resource and initialize it */ + hsmbus->Lock = HAL_UNLOCKED; + /* Init the low level hardware : GPIO, CLOCK, NVIC */ HAL_SMBUS_MspInit(hsmbus); } @@ -310,7 +304,7 @@ hsmbus->Instance->CR1 = (hsmbus->Init.GeneralCallMode | hsmbus->Init.NoStretchMode | hsmbus->Init.PacketErrorCheckMode | hsmbus->Init.PeripheralMode | hsmbus->Init.AnalogFilter); /* Enable Slave Byte Control only in case of Packet Error Check is enabled and SMBUS Peripheral is set in Slave mode */ - if( (hsmbus->Init.PacketErrorCheckMode == SMBUS_PEC_ENABLED) + if( (hsmbus->Init.PacketErrorCheckMode == SMBUS_PEC_ENABLE) && ( (hsmbus->Init.PeripheralMode == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || (hsmbus->Init.PeripheralMode == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP) ) ) { hsmbus->Instance->CR1 |= I2C_CR1_SBC; @@ -327,7 +321,7 @@ } /** - * @brief DeInitializes the SMBUS peripheral. + * @brief DeInitialize the SMBUS peripheral. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status @@ -362,27 +356,27 @@ } /** - * @brief SMBUS MSP Init. + * @brief Initialize the SMBUS MSP. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_MspInit(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, + /* NOTE : This function should not be modified, when the callback is needed, the HAL_SMBUS_MspInit could be implemented in the user file */ } /** - * @brief SMBUS MSP DeInit + * @brief DeInitialize the SMBUS MSP. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_MspDeInit(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, + /* NOTE : This function should not be modified, when the callback is needed, the HAL_SMBUS_MspDeInit could be implemented in the user file */ } @@ -416,7 +410,7 @@ (++) HAL_SMBUS_Master_Receive_IT() (++) HAL_SMBUS_Slave_Transmit_IT() (++) HAL_SMBUS_Slave_Receive_IT() - (++) HAL_SMBUS_Slave_Listen_IT() or alias HAL_SMBUS_EnableListen_IT() + (++) HAL_SMBUS_EnableListen_IT() or alias HAL_SMBUS_EnableListen_IT() (++) HAL_SMBUS_DisableListen_IT() (++) HAL_SMBUS_EnableAlert_IT() (++) HAL_SMBUS_DisableAlert_IT() @@ -426,8 +420,8 @@ (++) HAL_SMBUS_MasterRxCpltCallback() (++) HAL_SMBUS_SlaveTxCpltCallback() (++) HAL_SMBUS_SlaveRxCpltCallback() - (++) HAL_SMBUS_SlaveAddrCallback() or alias HAL_SMBUS_AddrCallback() - (++) HAL_SMBUS_SlaveListenCpltCallback() or alias HAL_SMBUS_ListenCpltCallback() + (++) HAL_SMBUS_AddrCallback() + (++) HAL_SMBUS_ListenCpltCallback() (++) HAL_SMBUS_ErrorCallback() @endverbatim @@ -435,7 +429,7 @@ */ /** - * @brief Transmit in master/host SMBUS mode an amount of data in no-blocking mode with Interrupt + * @brief Transmit in master/host SMBUS mode an amount of data in non-blocking mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param DevAddress: Target device address @@ -499,7 +493,7 @@ /* If PEC mode is enable, size to transmit manage by SW part should be Size-1 byte, corresponding to PEC byte */ /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ - if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) + if(SMBUS_GET_PEC_MODE(hsmbus) != RESET) { hsmbus->XferSize--; hsmbus->XferCount--; @@ -523,7 +517,7 @@ } /** - * @brief Receive in master/host SMBUS mode an amount of data in no-blocking mode with Interrupt + * @brief Receive in master/host SMBUS mode an amount of data in non-blocking mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param DevAddress: Target device address @@ -604,8 +598,8 @@ } /** - * @brief Abort a master/host SMBUS process commnunication with Interrupt - * @note : This abort can be called only if state is ready + * @brief Abort a master/host SMBUS process communication with Interrupt. + * @note This abort can be called only if state is ready * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param DevAddress: Target device address @@ -664,7 +658,7 @@ } /** - * @brief Transmit in slave/device SMBUS mode an amount of data in no-blocking mode with Interrupt + * @brief Transmit in slave/device SMBUS mode an amount of data in non-blocking mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param pData: Pointer to data buffer @@ -726,7 +720,7 @@ /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ - if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) + if(SMBUS_GET_PEC_MODE(hsmbus) != RESET) { hsmbus->XferSize--; hsmbus->XferCount--; @@ -755,7 +749,7 @@ } /** - * @brief Receive in slave/device SMBUS mode an amount of data in no-blocking mode with Interrupt + * @brief Receive in slave/device SMBUS mode an amount of data in non-blocking mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param pData: Pointer to data buffer @@ -801,7 +795,7 @@ /* no need to set RELOAD bit mode, a ACK will be automatically generated in that case */ /* else need to set RELOAD bit mode to generate an automatic ACK at each byte Received */ /* This RELOAD bit will be reset for last BYTE to be receive in SMBUS_Slave_ISR */ - if((hsmbus->XferSize == 1) || ((hsmbus->XferSize == 2) && (__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET))) + if((hsmbus->XferSize == 1) || ((hsmbus->XferSize == 2) && (SMBUS_GET_PEC_MODE(hsmbus) != RESET))) { SMBUS_TransferConfig(hsmbus,0,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); } @@ -832,12 +826,12 @@ } /** - * @brief This function enable the Address listen mode + * @brief Enable the Address listen mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status */ -HAL_StatusTypeDef HAL_SMBUS_Slave_Listen_IT(SMBUS_HandleTypeDef *hsmbus) +HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT(SMBUS_HandleTypeDef *hsmbus) { hsmbus->State = HAL_SMBUS_STATE_LISTEN; @@ -848,7 +842,7 @@ } /** - * @brief This function disable the Address listen mode + * @brief Disable the Address listen mode with Interrupt. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status @@ -872,7 +866,7 @@ } /** - * @brief This function enable the SMBUS alert mode. + * @brief Enable the SMBUS alert mode with Interrupt. * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUSx peripheral. * @retval HAL status @@ -891,7 +885,7 @@ return HAL_OK; } /** - * @brief This function disable the SMBUS alert mode. + * @brief Disable the SMBUS alert mode with Interrupt. * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUSx peripheral. * @retval HAL status @@ -908,7 +902,7 @@ } /** - * @brief Checks if target device is ready for communication. + * @brief Check if target device is ready for communication. * @note This function is used with Memory devices * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. @@ -939,7 +933,7 @@ do { /* Generate Start */ - hsmbus->Instance->CR2 = __HAL_SMBUS_GENERATE_START(hsmbus->Init.AddressingMode,DevAddress); + hsmbus->Instance->CR2 = SMBUS_GENERATE_START(hsmbus->Init.AddressingMode,DevAddress); /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */ /* Wait until STOPF flag is set or a NACK flag is set*/ @@ -1024,9 +1018,16 @@ return HAL_BUSY; } } +/** + * @} + */ + +/** @defgroup SMBUS_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks + * @{ + */ /** - * @brief This function handles SMBUS event interrupt request. + * @brief Handle SMBUS event interrupt request. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None @@ -1037,10 +1038,10 @@ /* Use a local variable to store the current ISR flags */ /* This action will avoid a wrong treatment due to ISR flags change during interrupt handler */ - tmpisrvalue = __SMBUS_GET_ISR_REG(hsmbus); + tmpisrvalue = SMBUS_GET_ISR_REG(hsmbus); /* SMBUS in mode Transmitter ---------------------------------------------------*/ - if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TXIS) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_TXI)) != RESET)) + if (((SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TXIS) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_TXI)) != RESET)) { /* Slave mode selected */ if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX) @@ -1055,7 +1056,7 @@ } /* SMBUS in mode Receiver ----------------------------------------------------*/ - if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_RXNE) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_RXI)) != RESET)) + if (((SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_RXNE) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_RXI)) != RESET)) { /* Slave mode selected */ if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX) @@ -1070,7 +1071,7 @@ } /* SMBUS in mode Listener Only --------------------------------------------------*/ - if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_ADDR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) + if (((SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_ADDR) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && ((__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ADDRI) != RESET) || (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_STOPI) != RESET) || (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_NACKI) != RESET))) { if (hsmbus->State == HAL_SMBUS_STATE_LISTEN) @@ -1081,7 +1082,7 @@ } /** - * @brief This function handles SMBUS error interrupt request. + * @brief Handle SMBUS error interrupt request. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None @@ -1142,10 +1143,10 @@ __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_PECERR); } - /* Call the Error Callback in case of Error detected */ + /* Call the Error Callback() in case of Error detected */ if((hsmbus->ErrorCode != HAL_SMBUS_ERROR_NONE)&&(hsmbus->ErrorCode != HAL_SMBUS_ERROR_ACKF)) { - /* Do not Reset the the HAL state in case of ALERT error */ + /* Do not Reset the HAL state in case of ALERT error */ if((hsmbus->ErrorCode & HAL_SMBUS_ERROR_ALERT) != HAL_SMBUS_ERROR_ALERT) { if(((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX) @@ -1164,94 +1165,94 @@ } /** - * @brief Master Tx Transfer completed callbacks. + * @brief Master Tx Transfer completed callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_TxCpltCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_TxCpltCallback() could be implemented in the user file */ } /** - * @brief Master Rx Transfer completed callbacks. + * @brief Master Rx Transfer completed callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_TxCpltCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_TxCpltCallback() could be implemented in the user file */ } -/** @brief Slave Tx Transfer completed callbacks. +/** @brief Slave Tx Transfer completed callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_TxCpltCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_TxCpltCallback() could be implemented in the user file */ } /** - * @brief Slave Rx Transfer completed callbacks. + * @brief Slave Rx Transfer completed callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_TxCpltCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_TxCpltCallback() could be implemented in the user file */ } /** - * @brief Slave Address Match callbacks. + * @brief Slave Address Match callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param TransferDirection: Master request Transfer Direction (Write/Read) * @param AddrMatchCode: Address Match Code * @retval None */ -__weak void HAL_SMBUS_SlaveAddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode) +__weak void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_SlaveAddrCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_AddrCallback() could be implemented in the user file */ } /** - * @brief Listen Complete callbacks. + * @brief Listen Complete callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ -__weak void HAL_SMBUS_SlaveListenCpltCallback(SMBUS_HandleTypeDef *hsmbus) +__weak void HAL_SMBUS_ListenCpltCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_SlaveListenCpltCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_ListenCpltCallback() could be implemented in the user file */ } /** - * @brief SMBUS error callbacks. + * @brief SMBUS error callback. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval None */ __weak void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus) { - /* NOTE : This function Should not be modified, when the callback is needed, - the HAL_SMBUS_ErrorCallback could be implemented in the user file + /* NOTE : This function should not be modified, when the callback is needed, + the HAL_SMBUS_ErrorCallback() could be implemented in the user file */ } @@ -1267,7 +1268,7 @@ ##### Peripheral State and Errors functions ##### =============================================================================== [..] - This subsection permit to get in run-time the status of the peripheral + This subsection permits to get in run-time the status of the peripheral and the data flow. @endverbatim @@ -1275,17 +1276,19 @@ */ /** - * @brief Returns the SMBUS state. - * @param hsmbus : SMBUS handle + * @brief Return the SMBUS handle state. + * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains + * the configuration information for the specified SMBUS. * @retval HAL state */ uint32_t HAL_SMBUS_GetState(SMBUS_HandleTypeDef *hsmbus) { + /* Return SMBUS handle state */ return hsmbus->State; } /** -* @brief Return the SMBUS error code +* @brief Return the SMBUS error code. * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval SMBUS Error Code @@ -1309,7 +1312,7 @@ */ /** - * @brief Interrupt Sub-Routine which handle the Interrupt Flags Master Mode + * @brief Interrupt Sub-Routine which handle the Interrupt Flags Master Mode. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status @@ -1349,7 +1352,7 @@ __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); /* Clear Configuration Register 2 */ - __HAL_SMBUS_RESET_CR2(hsmbus); + SMBUS_RESET_CR2(hsmbus); /* Flush remaining data in Fifo register in case of error occurs before TXEmpty */ /* Disable the selected SMBUS peripheral */ @@ -1375,7 +1378,7 @@ __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); /* Clear Configuration Register 2 */ - __HAL_SMBUS_RESET_CR2(hsmbus); + SMBUS_RESET_CR2(hsmbus); hsmbus->PreviousState = HAL_SMBUS_STATE_READY; hsmbus->State = HAL_SMBUS_STATE_READY; @@ -1417,7 +1420,7 @@ SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ - if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) + if(SMBUS_GET_PEC_MODE(hsmbus) != RESET) { hsmbus->XferSize--; hsmbus->XferCount--; @@ -1426,8 +1429,8 @@ } else if((hsmbus->XferSize == 0)&&(hsmbus->XferCount==0)) { - /* Call TxCpltCallback if no stop mode is set */ - if(__HAL_SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) + /* Call TxCpltCallback() if no stop mode is set */ + if(SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) { /* Call the corresponding callback to inform upper layer of End of Transfer */ if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX) @@ -1466,8 +1469,8 @@ /* Generate a Stop command */ hsmbus->Instance->CR2 |= I2C_CR2_STOP; } - /* Call TxCpltCallback if no stop mode is set */ - else if(__HAL_SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) + /* Call TxCpltCallback() if no stop mode is set */ + else if(SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) { /* No Generate Stop, to permit restart mode */ /* The stop will be done at the end of transfer, when SMBUS_AUTOEND_MODE enable */ @@ -1506,7 +1509,7 @@ return HAL_OK; } /** - * @brief Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode + * @brief Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @retval HAL status @@ -1560,8 +1563,8 @@ } else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_ADDR) != RESET) { - TransferDirection = __HAL_SMBUS_GET_DIR(hsmbus); - SlaveAddrCode = __HAL_SMBUS_GET_ADDR_MATCH(hsmbus); + TransferDirection = SMBUS_GET_DIR(hsmbus); + SlaveAddrCode = SMBUS_GET_ADDR_MATCH(hsmbus); /* Disable ADDR interrupt to prevent multiple ADDRInterrupt*/ /* Other ADDRInterrupt will be treat in next Listen usecase */ @@ -1571,7 +1574,7 @@ __HAL_UNLOCK(hsmbus); /* Call Slave Addr callback */ - HAL_SMBUS_SlaveAddrCallback(hsmbus, TransferDirection, SlaveAddrCode); + HAL_SMBUS_AddrCallback(hsmbus, TransferDirection, SlaveAddrCode); } else if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_RXNE) != RESET) || (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TCR) != RESET)) { @@ -1629,7 +1632,7 @@ SMBUS_TransferConfig(hsmbus, 0, hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ - if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) + if(SMBUS_GET_PEC_MODE(hsmbus) != RESET) { hsmbus->XferSize--; hsmbus->XferCount--; @@ -1642,7 +1645,7 @@ { /* Write data to TXDR only if XferCount not reach "0" */ /* A TXIS flag can be set, during STOP treatment */ - /* Check if all Datas have already been sent */ + /* Check if all Data have already been sent */ /* If it is the case, this last write in TXDR is not sent, correspond to a dummy TXIS event */ if(hsmbus->XferCount > 0) { @@ -1683,7 +1686,7 @@ hsmbus->Instance->CR2 |= I2C_CR2_NACK; /* Clear Configuration Register 2 */ - __HAL_SMBUS_RESET_CR2(hsmbus); + SMBUS_RESET_CR2(hsmbus); /* Clear STOP Flag */ __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); @@ -1699,7 +1702,7 @@ __HAL_UNLOCK(hsmbus); /* Call the Listen Complete callback, to prevent upper layer of the end of Listen usecase */ - HAL_SMBUS_SlaveListenCpltCallback(hsmbus); + HAL_SMBUS_ListenCpltCallback(hsmbus); } } @@ -1709,7 +1712,7 @@ return HAL_OK; } /** - * @brief Manage the enabling of Interrupts + * @brief Manage the enabling of Interrupts. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param InterruptRequest : Value of @ref SMBUS_Interrupt_configuration_definition. @@ -1751,7 +1754,7 @@ return HAL_OK; } /** - * @brief Manage the disabling of Interrupts + * @brief Manage the disabling of Interrupts. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param InterruptRequest : Value of @ref SMBUS_Interrupt_configuration_definition. @@ -1772,7 +1775,7 @@ /* Disable TC, STOP, NACK, TXI interrupt */ tmpisr |= SMBUS_IT_TCI | SMBUS_IT_TXI; - if((__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) + if((SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) && ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)) { /* Disable ERR interrupt */ @@ -1791,7 +1794,7 @@ /* Disable TC, STOP, NACK, RXI interrupt */ tmpisr |= SMBUS_IT_TCI | SMBUS_IT_RXI; - if((__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) + if((SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) && ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)) { /* Disable ERR interrupt */ @@ -1810,7 +1813,7 @@ /* Enable ADDR, STOP interrupt */ tmpisr |= SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI; - if(__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) + if(SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) { /* Disable ERR interrupt */ tmpisr |= SMBUS_IT_ERRI; @@ -1825,7 +1828,7 @@ return HAL_OK; } /** - * @brief This function handles SMBUS Communication Timeout. + * @brief Handle SMBUS Communication Timeout. * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains * the configuration information for the specified SMBUS. * @param Flag: specifies the SMBUS flag to check. @@ -1882,7 +1885,7 @@ } /** - * @brief Handles SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set). + * @brief Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set). * @param hsmbus: SMBUS handle. * @param DevAddress: specifies the slave address to be programmed. * @param Size: specifies the number of bytes to be programmed.