```html
|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_smbus.h 00004 * @author MCD Application Team 00005 * @brief Header file of SMBUS HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2019 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32G4xx_HAL_SMBUS_H 00021 #define STM32G4xx_HAL_SMBUS_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32g4xx_hal_def.h" 00029 00030 /** @addtogroup STM32G4xx_HAL_Driver 00031 * @{ 00032 */ 00033 00034 /** @addtogroup SMBUS 00035 * @{ 00036 */ 00037 00038 /* Exported types ------------------------------------------------------------*/ 00039 /** @defgroup SMBUS_Exported_Types SMBUS Exported Types 00040 * @{ 00041 */ 00042 00043 /** @defgroup SMBUS_Configuration_Structure_definition SMBUS Configuration Structure definition 00044 * @brief SMBUS Configuration Structure definition 00045 * @{ 00046 */ 00047 typedef struct 00048 { 00049 uint32_t Timing; /*!< Specifies the SMBUS_TIMINGR_register value. 00050 This parameter calculated by referring to SMBUS initialization section 00051 in Reference manual */ 00052 uint32_t AnalogFilter; /*!< Specifies if Analog Filter is enable or not. 00053 This parameter can be a value of @ref SMBUS_Analog_Filter */ 00054 00055 uint32_t OwnAddress1; /*!< Specifies the first device own address. 00056 This parameter can be a 7-bit or 10-bit address. */ 00057 00058 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode for master is selected. 00059 This parameter can be a value of @ref SMBUS_addressing_mode */ 00060 00061 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected. 00062 This parameter can be a value of @ref SMBUS_dual_addressing_mode */ 00063 00064 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected 00065 This parameter can be a 7-bit address. */ 00066 00067 uint32_t OwnAddress2Masks; /*!< Specifies the acknowledge mask address second device own address 00068 if dual addressing mode is selected 00069 This parameter can be a value of @ref SMBUS_own_address2_masks. */ 00070 00071 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected. 00072 This parameter can be a value of @ref SMBUS_general_call_addressing_mode. */ 00073 00074 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected. 00075 This parameter can be a value of @ref SMBUS_nostretch_mode */ 00076 00077 uint32_t PacketErrorCheckMode; /*!< Specifies if Packet Error Check mode is selected. 00078 This parameter can be a value of @ref SMBUS_packet_error_check_mode */ 00079 00080 uint32_t PeripheralMode; /*!< Specifies which mode of Periphal is selected. 00081 This parameter can be a value of @ref SMBUS_peripheral_mode */ 00082 00083 uint32_t SMBusTimeout; /*!< Specifies the content of the 32 Bits SMBUS_TIMEOUT_register value. 00084 (Enable bits and different timeout values) 00085 This parameter calculated by referring to SMBUS initialization section 00086 in Reference manual */ 00087 } SMBUS_InitTypeDef; 00088 /** 00089 * @} 00090 */ 00091 00092 /** @defgroup HAL_state_definition HAL state definition 00093 * @brief HAL State definition 00094 * @{ 00095 */ 00096 #define HAL_SMBUS_STATE_RESET (0x00000000U) /*!< SMBUS not yet initialized or disabled */ 00097 #define HAL_SMBUS_STATE_READY (0x00000001U) /*!< SMBUS initialized and ready for use */ 00098 #define HAL_SMBUS_STATE_BUSY (0x00000002U) /*!< SMBUS internal process is ongoing */ 00099 #define HAL_SMBUS_STATE_MASTER_BUSY_TX (0x00000012U) /*!< Master Data Transmission process is ongoing */ 00100 #define HAL_SMBUS_STATE_MASTER_BUSY_RX (0x00000022U) /*!< Master Data Reception process is ongoing */ 00101 #define HAL_SMBUS_STATE_SLAVE_BUSY_TX (0x00000032U) /*!< Slave Data Transmission process is ongoing */ 00102 #define HAL_SMBUS_STATE_SLAVE_BUSY_RX (0x00000042U) /*!< Slave Data Reception process is ongoing */ 00103 #define HAL_SMBUS_STATE_LISTEN (0x00000008U) /*!< Address Listen Mode is ongoing */ 00104 /** 00105 * @} 00106 */ 00107 00108 /** @defgroup SMBUS_Error_Code_definition SMBUS Error Code definition 00109 * @brief SMBUS Error Code definition 00110 * @{ 00111 */ 00112 #define HAL_SMBUS_ERROR_NONE (0x00000000U) /*!< No error */ 00113 #define HAL_SMBUS_ERROR_BERR (0x00000001U) /*!< BERR error */ 00114 #define HAL_SMBUS_ERROR_ARLO (0x00000002U) /*!< ARLO error */ 00115 #define HAL_SMBUS_ERROR_ACKF (0x00000004U) /*!< ACKF error */ 00116 #define HAL_SMBUS_ERROR_OVR (0x00000008U) /*!< OVR error */ 00117 #define HAL_SMBUS_ERROR_HALTIMEOUT (0x00000010U) /*!< Timeout error */ 00118 #define HAL_SMBUS_ERROR_BUSTIMEOUT (0x00000020U) /*!< Bus Timeout error */ 00119 #define HAL_SMBUS_ERROR_ALERT (0x00000040U) /*!< Alert error */ 00120 #define HAL_SMBUS_ERROR_PECERR (0x00000080U) /*!< PEC error */ 00121 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1) 00122 #define HAL_SMBUS_ERROR_INVALID_CALLBACK (0x00000100U) /*!< Invalid Callback error */ 00123 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */ 00124 #define HAL_SMBUS_ERROR_INVALID_PARAM (0x00000200U) /*!< Invalid Parameters error */ 00125 /** 00126 * @} 00127 */ 00128 00129 /** @defgroup SMBUS_handle_Structure_definition SMBUS handle Structure definition 00130 * @brief SMBUS handle Structure definition 00131 * @{ 00132 */ 00133 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1) 00134 typedef struct __SMBUS_HandleTypeDef 00135 #else 00136 typedef struct 00137 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */ 00138 { 00139 I2C_TypeDef *Instance; /*!< SMBUS registers base address */ 00140 00141 SMBUS_InitTypeDef Init; /*!< SMBUS communication parameters */ 00142 00143 uint8_t *pBuffPtr; /*!< Pointer to SMBUS transfer buffer */ 00144 00145 uint16_t XferSize; /*!< SMBUS transfer size */ 00146 00147 __IO uint16_t XferCount; /*!< SMBUS transfer counter */ 00148 00149 __IO uint32_t XferOptions; /*!< SMBUS transfer options */ 00150 00151 __IO uint32_t PreviousState; /*!< SMBUS communication Previous state */ 00152