Subversion Repositories LedShow

Rev

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

Rev 2 Rev 9
Line 4... Line 4...
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   Header file of I2C HAL module.
5
  * @brief   Header file of I2C HAL module.
6
  ******************************************************************************
6
  ******************************************************************************
7
  * @attention
7
  * @attention
8
  *
8
  *
9
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
9
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
-
 
10
  * All rights reserved.</center></h2>
10
  *
11
  *
11
  * Redistribution and use in source and binary forms, with or without modification,
12
  * This software component is licensed by ST under BSD 3-Clause license,
12
  * are permitted provided that the following conditions are met:
13
  * the "License"; You may not use this file except in compliance with the
13
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
14
  *      this list of conditions and the following disclaimer.
-
 
15
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
16
  *      this list of conditions and the following disclaimer in the documentation
-
 
17
  *      and/or other materials provided with the distribution.
14
  * License. You may obtain a copy of the License at:
18
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
19
  *      may be used to endorse or promote products derived from this software
15
  *                        opensource.org/licenses/BSD-3-Clause
20
  *      without specific prior written permission.
-
 
21
  *
-
 
22
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
23
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
24
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
25
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
26
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
27
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
28
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
29
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
30
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
31
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
32
  *
16
  *
33
  ******************************************************************************
17
  ******************************************************************************
34
  */
18
  */
35
 
19
 
36
/* Define to prevent recursive inclusion -------------------------------------*/
20
/* Define to prevent recursive inclusion -------------------------------------*/
37
#ifndef __STM32F1xx_HAL_I2C_H
21
#ifndef __STM32F1xx_HAL_I2C_H
38
#define __STM32F1xx_HAL_I2C_H
22
#define __STM32F1xx_HAL_I2C_H
39
 
23
 
40
#ifdef __cplusplus
24
#ifdef __cplusplus
41
 extern "C" {
25
extern "C" {
42
#endif
26
#endif
43
 
27
 
44
/* Includes ------------------------------------------------------------------*/
28
/* Includes ------------------------------------------------------------------*/
45
#include "stm32f1xx_hal_def.h"
29
#include "stm32f1xx_hal_def.h"
46
 
30
 
Line 54... Line 38...
54
 
38
 
55
/* Exported types ------------------------------------------------------------*/
39
/* Exported types ------------------------------------------------------------*/
56
/** @defgroup I2C_Exported_Types I2C Exported Types
40
/** @defgroup I2C_Exported_Types I2C Exported Types
57
  * @{
41
  * @{
58
  */
42
  */
59
   
-
 
60
/**
43
 
-
 
44
/** @defgroup I2C_Configuration_Structure_definition I2C Configuration Structure definition
61
  * @brief  I2C Configuration Structure definition
45
  * @brief  I2C Configuration Structure definition
-
 
46
  * @{
62
  */
47
  */
63
typedef struct
48
typedef struct
64
{
49
{
65
  uint32_t ClockSpeed;       /*!< Specifies the clock frequency.
50
  uint32_t ClockSpeed;       /*!< Specifies the clock frequency.
66
                                  This parameter must be set to a value lower than 400kHz */
51
                                  This parameter must be set to a value lower than 400kHz */
Line 84... Line 69...
84
                                  This parameter can be a value of @ref I2C_general_call_addressing_mode */
69
                                  This parameter can be a value of @ref I2C_general_call_addressing_mode */
85
 
70
 
86
  uint32_t NoStretchMode;    /*!< Specifies if nostretch mode is selected.
71
  uint32_t NoStretchMode;    /*!< Specifies if nostretch mode is selected.
87
                                  This parameter can be a value of @ref I2C_nostretch_mode */
72
                                  This parameter can be a value of @ref I2C_nostretch_mode */
88
 
73
 
89
}I2C_InitTypeDef;
74
} I2C_InitTypeDef;
90
 
75
 
91
/**
76
/**
-
 
77
  * @}
-
 
78
  */
-
 
79
 
-
 
80
/** @defgroup HAL_state_structure_definition HAL state structure definition
92
  * @brief  HAL State structure definition
81
  * @brief  HAL State structure definition
93
  * @note  HAL I2C State value coding follow below described bitmap :
82
  * @note  HAL I2C State value coding follow below described bitmap :
94
  *          b7-b6  Error information
83
  *          b7-b6  Error information
95
  *             00 : No Error
84
  *             00 : No Error
96
  *             01 : Abort (Abort user request on going)
85
  *             01 : Abort (Abort user request on going)
97
  *             10 : Timeout
86
  *             10 : Timeout
98
  *             11 : Error
87
  *             11 : Error
99
  *          b5     IP initilisation status
88
  *          b5     Peripheral initilisation status
100
  *             0  : Reset (IP not initialized)
89
  *             0  : Reset (Peripheral not initialized)
101
  *             1  : Init done (IP initialized and ready to use. HAL I2C Init function called)
90
  *             1  : Init done (Peripheral initialized and ready to use. HAL I2C Init function called)
102
  *          b4     (not used)
91
  *          b4     (not used)
103
  *             x  : Should be set to 0
92
  *             x  : Should be set to 0
104
  *          b3
93
  *          b3
105
  *             0  : Ready or Busy (No Listen mode ongoing)
94
  *             0  : Ready or Busy (No Listen mode ongoing)
106
  *             1  : Listen (IP in Address Listen Mode)
95
  *             1  : Listen (Peripheral in Address Listen Mode)
107
  *          b2     Intrinsic process state
96
  *          b2     Intrinsic process state
108
  *             0  : Ready
97
  *             0  : Ready
109
  *             1  : Busy (IP busy with some configuration or internal operations)
98
  *             1  : Busy (Peripheral busy with some configuration or internal operations)
110
  *          b1     Rx state
99
  *          b1     Rx state
111
  *             0  : Ready (no Rx operation ongoing)
100
  *             0  : Ready (no Rx operation ongoing)
112
  *             1  : Busy (Rx operation ongoing)
101
  *             1  : Busy (Rx operation ongoing)
113
  *          b0     Tx state
102
  *          b0     Tx state
114
  *             0  : Ready (no Tx operation ongoing)
103
  *             0  : Ready (no Tx operation ongoing)
115
  *             1  : Busy (Tx operation ongoing)
104
  *             1  : Busy (Tx operation ongoing)
-
 
105
  * @{
116
  */
106
  */
117
typedef enum
107
typedef enum
118
{
108
{
119
  HAL_I2C_STATE_RESET             = 0x00U,   /*!< Peripheral is not yet Initialized         */
109
  HAL_I2C_STATE_RESET             = 0x00U,   /*!< Peripheral is not yet Initialized         */
120
  HAL_I2C_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use  */
110
  HAL_I2C_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use  */
Line 128... Line 118...
128
                                                 process is ongoing                         */
118
                                                 process is ongoing                         */
129
  HAL_I2C_STATE_ABORT             = 0x60U,   /*!< Abort user request ongoing                */
119
  HAL_I2C_STATE_ABORT             = 0x60U,   /*!< Abort user request ongoing                */
130
  HAL_I2C_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state                             */
120
  HAL_I2C_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state                             */
131
  HAL_I2C_STATE_ERROR             = 0xE0U    /*!< Error                                     */
121
  HAL_I2C_STATE_ERROR             = 0xE0U    /*!< Error                                     */
132
 
122
 
133
}HAL_I2C_StateTypeDef;
123
} HAL_I2C_StateTypeDef;
134
 
124
 
135
/**
125
/**
-
 
126
  * @}
-
 
127
  */
-
 
128
 
-
 
129
/** @defgroup HAL_mode_structure_definition HAL mode structure definition
136
  * @brief  HAL Mode structure definition
130
  * @brief  HAL Mode structure definition
137
  * @note  HAL I2C Mode value coding follow below described bitmap :
131
  * @note  HAL I2C Mode value coding follow below described bitmap :\n
138
  *          b7     (not used)
132
  *          b7     (not used)\n
139
  *             x  : Should be set to 0
133
  *             x  : Should be set to 0\n
140
  *          b6
134
  *          b6\n
141
  *             0  : None
135
  *             0  : None\n
142
  *             1  : Memory (HAL I2C communication is in Memory Mode)
136
  *             1  : Memory (HAL I2C communication is in Memory Mode)\n
143
  *          b5
137
  *          b5\n
144
  *             0  : None
138
  *             0  : None\n
145
  *             1  : Slave (HAL I2C communication is in Slave Mode)
139
  *             1  : Slave (HAL I2C communication is in Slave Mode)\n
146
  *          b4
140
  *          b4\n
147
  *             0  : None
141
  *             0  : None\n
148
  *             1  : Master (HAL I2C communication is in Master Mode)
142
  *             1  : Master (HAL I2C communication is in Master Mode)\n
149
  *          b3-b2-b1-b0  (not used)
143
  *          b3-b2-b1-b0  (not used)\n
150
  *             xxxx : Should be set to 0000
144
  *             xxxx : Should be set to 0000
-
 
145
  * @{
151
  */
146
  */
152
typedef enum
147
typedef enum
153
{
148
{
154
  HAL_I2C_MODE_NONE               = 0x00U,   /*!< No I2C communication on going             */
149
  HAL_I2C_MODE_NONE               = 0x00U,   /*!< No I2C communication on going             */
155
  HAL_I2C_MODE_MASTER             = 0x10U,   /*!< I2C communication is in Master Mode       */
150
  HAL_I2C_MODE_MASTER             = 0x10U,   /*!< I2C communication is in Master Mode       */
156
  HAL_I2C_MODE_SLAVE              = 0x20U,   /*!< I2C communication is in Slave Mode        */
151
  HAL_I2C_MODE_SLAVE              = 0x20U,   /*!< I2C communication is in Slave Mode        */
157
  HAL_I2C_MODE_MEM                = 0x40U    /*!< I2C communication is in Memory Mode       */
152
  HAL_I2C_MODE_MEM                = 0x40U    /*!< I2C communication is in Memory Mode       */
158
 
153
 
159
}HAL_I2C_ModeTypeDef;
154
} HAL_I2C_ModeTypeDef;
-
 
155
 
-
 
156
/**
-
 
157
  * @}
-
 
158
  */
160
 
159
 
-
 
160
/** @defgroup I2C_Error_Code_definition I2C Error Code definition
-
 
161
  * @brief  I2C Error Code definition
-
 
162
  * @{
-
 
163
  */
-
 
164
#define HAL_I2C_ERROR_NONE              0x00000000U    /*!< No error              */
-
 
165
#define HAL_I2C_ERROR_BERR              0x00000001U    /*!< BERR error            */
-
 
166
#define HAL_I2C_ERROR_ARLO              0x00000002U    /*!< ARLO error            */
-
 
167
#define HAL_I2C_ERROR_AF                0x00000004U    /*!< AF error              */
-
 
168
#define HAL_I2C_ERROR_OVR               0x00000008U    /*!< OVR error             */
-
 
169
#define HAL_I2C_ERROR_DMA               0x00000010U    /*!< DMA transfer error    */
-
 
170
#define HAL_I2C_ERROR_TIMEOUT           0x00000020U    /*!< Timeout Error         */
-
 
171
#define HAL_I2C_ERROR_SIZE              0x00000040U    /*!< Size Management error */
-
 
172
#define HAL_I2C_ERROR_DMA_PARAM         0x00000080U    /*!< DMA Parameter Error   */
-
 
173
#define HAL_I2C_WRONG_START             0x00000200U    /*!< Wrong start Error     */
-
 
174
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
-
 
175
#define HAL_I2C_ERROR_INVALID_CALLBACK  0x00000100U    /*!< Invalid Callback error */
-
 
176
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
161
/**
177
/**
-
 
178
  * @}
-
 
179
  */
-
 
180
 
-
 
181
/** @defgroup I2C_handle_Structure_definition I2C handle Structure definition
162
  * @brief  I2C handle Structure definition
182
  * @brief  I2C handle Structure definition
-
 
183
  * @{
163
  */
184
  */
-
 
185
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
-
 
186
typedef struct __I2C_HandleTypeDef
-
 
187
#else
164
typedef struct
188
typedef struct
-
 
189
#endif  /* USE_HAL_I2C_REGISTER_CALLBACKS */
165
{
190
{
166
  I2C_TypeDef                *Instance;      /*!< I2C registers base address               */
191
  I2C_TypeDef                *Instance;      /*!< I2C registers base address               */
167
                                             
-
 
-
 
192
 
168
  I2C_InitTypeDef            Init;           /*!< I2C communication parameters             */
193
  I2C_InitTypeDef            Init;           /*!< I2C communication parameters             */
169
                                             
-
 
-
 
194
 
170
  uint8_t                    *pBuffPtr;      /*!< Pointer to I2C transfer buffer           */
195
  uint8_t                    *pBuffPtr;      /*!< Pointer to I2C transfer buffer           */
171
                                             
-
 
-
 
196
 
172
  uint16_t                   XferSize;       /*!< I2C transfer size                        */
197
  uint16_t                   XferSize;       /*!< I2C transfer size                        */
173
                                             
-
 
-
 
198
 
174
  __IO uint16_t              XferCount;      /*!< I2C transfer counter                     */
199
  __IO uint16_t              XferCount;      /*!< I2C transfer counter                     */
175
                                             
-
 
-
 
200
 
176
  __IO uint32_t              XferOptions;    /*!< I2C transfer options                     */
201
  __IO uint32_t              XferOptions;    /*!< I2C transfer options                     */
177
                                             
-
 
-
 
202
 
178
  __IO uint32_t              PreviousState;  /*!< I2C communication Previous state and mode
203
  __IO uint32_t              PreviousState;  /*!< I2C communication Previous state and mode
179
                                                  context for internal usage               */
204
                                                  context for internal usage               */
180
                                             
-
 
-
 
205
 
181
  DMA_HandleTypeDef          *hdmatx;        /*!< I2C Tx DMA handle parameters             */
206
  DMA_HandleTypeDef          *hdmatx;        /*!< I2C Tx DMA handle parameters             */
182
                                             
-
 
-
 
207
 
183
  DMA_HandleTypeDef          *hdmarx;        /*!< I2C Rx DMA handle parameters             */
208
  DMA_HandleTypeDef          *hdmarx;        /*!< I2C Rx DMA handle parameters             */
184
                                             
-
 
-
 
209
 
185
  HAL_LockTypeDef            Lock;           /*!< I2C locking object                       */
210
  HAL_LockTypeDef            Lock;           /*!< I2C locking object                       */
186
                                             
-
 
-
 
211
 
187
  __IO HAL_I2C_StateTypeDef  State;          /*!< I2C communication state                  */
212
  __IO HAL_I2C_StateTypeDef  State;          /*!< I2C communication state                  */
188
                                             
-
 
-
 
213
 
189
  __IO HAL_I2C_ModeTypeDef   Mode;           /*!< I2C communication mode                   */
214
  __IO HAL_I2C_ModeTypeDef   Mode;           /*!< I2C communication mode                   */
190
                                             
-
 
-
 
215
 
191
  __IO uint32_t              ErrorCode;      /*!< I2C Error code                           */
216
  __IO uint32_t              ErrorCode;      /*!< I2C Error code                           */
192
 
217
 
193
  __IO uint32_t              Devaddress;     /*!< I2C Target device address                */
218
  __IO uint32_t              Devaddress;     /*!< I2C Target device address                */
194
 
219
 
195
  __IO uint32_t              Memaddress;     /*!< I2C Target memory address                */
220
  __IO uint32_t              Memaddress;     /*!< I2C Target memory address                */
196
 
221
 
197
  __IO uint32_t              MemaddSize;     /*!< I2C Target memory address  size          */
222
  __IO uint32_t              MemaddSize;     /*!< I2C Target memory address  size          */
198
 
223
 
199
  __IO uint32_t              EventCount;     /*!< I2C Event counter                        */
224
  __IO uint32_t              EventCount;     /*!< I2C Event counter                        */
200
       
-
 
201
}I2C_HandleTypeDef;
-
 
202
 
225
 
-
 
226
 
-
 
227
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
-
 
228
  void (* MasterTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);           /*!< I2C Master Tx Transfer completed callback */
-
 
229
  void (* MasterRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);           /*!< I2C Master Rx Transfer completed callback */
-
 
230
  void (* SlaveTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);            /*!< I2C Slave Tx Transfer completed callback  */
-
 
231
  void (* SlaveRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);            /*!< I2C Slave Rx Transfer completed callback  */
-
 
232
  void (* ListenCpltCallback)(struct __I2C_HandleTypeDef *hi2c);             /*!< I2C Listen Complete callback              */
-
 
233
  void (* MemTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);              /*!< I2C Memory Tx Transfer completed callback */
-
 
234
  void (* MemRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c);              /*!< I2C Memory Rx Transfer completed callback */
-
 
235
  void (* ErrorCallback)(struct __I2C_HandleTypeDef *hi2c);                  /*!< I2C Error callback                        */
-
 
236
  void (* AbortCpltCallback)(struct __I2C_HandleTypeDef *hi2c);              /*!< I2C Abort callback                        */
-
 
237
 
-
 
238
  void (* AddrCallback)(struct __I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode);  /*!< I2C Slave Address Match callback */
-
 
239
 
-
 
240
  void (* MspInitCallback)(struct __I2C_HandleTypeDef *hi2c);                /*!< I2C Msp Init callback                     */
-
 
241
  void (* MspDeInitCallback)(struct __I2C_HandleTypeDef *hi2c);              /*!< I2C Msp DeInit callback                   */
-
 
242
 
-
 
243
#endif  /* USE_HAL_I2C_REGISTER_CALLBACKS */
-
 
244
} I2C_HandleTypeDef;
-
 
245
 
-
 
246
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
203
/**
247
/**
204
  * @}
248
  * @brief  HAL I2C Callback ID enumeration definition
205
  */
249
  */
-
 
250
typedef enum
-
 
251
{
-
 
252
  HAL_I2C_MASTER_TX_COMPLETE_CB_ID      = 0x00U,    /*!< I2C Master Tx Transfer completed callback ID  */
-
 
253
  HAL_I2C_MASTER_RX_COMPLETE_CB_ID      = 0x01U,    /*!< I2C Master Rx Transfer completed callback ID  */
-
 
254
  HAL_I2C_SLAVE_TX_COMPLETE_CB_ID       = 0x02U,    /*!< I2C Slave Tx Transfer completed callback ID   */
-
 
255
  HAL_I2C_SLAVE_RX_COMPLETE_CB_ID       = 0x03U,    /*!< I2C Slave Rx Transfer completed callback ID   */
-
 
256
  HAL_I2C_LISTEN_COMPLETE_CB_ID         = 0x04U,    /*!< I2C Listen Complete callback ID               */
-
 
257
  HAL_I2C_MEM_TX_COMPLETE_CB_ID         = 0x05U,    /*!< I2C Memory Tx Transfer callback ID            */
-
 
258
  HAL_I2C_MEM_RX_COMPLETE_CB_ID         = 0x06U,    /*!< I2C Memory Rx Transfer completed callback ID  */
-
 
259
  HAL_I2C_ERROR_CB_ID                   = 0x07U,    /*!< I2C Error callback ID                         */
-
 
260
  HAL_I2C_ABORT_CB_ID                   = 0x08U,    /*!< I2C Abort callback ID                         */
206
 
261
 
-
 
262
  HAL_I2C_MSPINIT_CB_ID                 = 0x09U,    /*!< I2C Msp Init callback ID                      */
207
/* Exported constants --------------------------------------------------------*/
263
  HAL_I2C_MSPDEINIT_CB_ID               = 0x0AU     /*!< I2C Msp DeInit callback ID                    */
-
 
264
 
-
 
265
} HAL_I2C_CallbackIDTypeDef;
-
 
266
 
-
 
267
/**
208
/** @defgroup I2C_Exported_Constants I2C Exported Constants
268
  * @brief  HAL I2C Callback pointer definition
-
 
269
  */
-
 
270
typedef  void (*pI2C_CallbackTypeDef)(I2C_HandleTypeDef *hi2c); /*!< pointer to an I2C callback function */
-
 
271
typedef  void (*pI2C_AddrCallbackTypeDef)(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< pointer to an I2C Address Match callback function */
-
 
272
 
-
 
273
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
-
 
274
/**
209
  * @{
275
  * @}
210
  */
276
  */
211
 
277
 
212
/** @defgroup I2C_Error_Code I2C Error Code
-
 
213
  * @brief    I2C Error Code
-
 
214
  * @{
-
 
215
  */
-
 
216
#define HAL_I2C_ERROR_NONE       0x00000000U    /*!< No error           */
-
 
217
#define HAL_I2C_ERROR_BERR       0x00000001U    /*!< BERR error         */
-
 
218
#define HAL_I2C_ERROR_ARLO       0x00000002U    /*!< ARLO error         */
-
 
219
#define HAL_I2C_ERROR_AF         0x00000004U    /*!< AF error           */
-
 
220
#define HAL_I2C_ERROR_OVR        0x00000008U    /*!< OVR error          */
-
 
221
#define HAL_I2C_ERROR_DMA        0x00000010U    /*!< DMA transfer error */
-
 
222
#define HAL_I2C_ERROR_TIMEOUT    0x00000020U    /*!< Timeout Error      */
-
 
223
/**
278
/**
224
  * @}
279
  * @}
225
  */
280
  */
-
 
281
/* Exported constants --------------------------------------------------------*/
-
 
282
 
-
 
283
/** @defgroup I2C_Exported_Constants I2C Exported Constants
-
 
284
  * @{
-
 
285
  */
226
 
286
 
227
/** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
287
/** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
228
  * @{
288
  * @{
229
  */
289
  */
230
#define I2C_DUTYCYCLE_2                 0x00000000U
290
#define I2C_DUTYCYCLE_2                 0x00000000U
Line 279... Line 339...
279
  */
339
  */
280
 
340
 
281
/** @defgroup I2C_XferDirection_definition I2C XferDirection definition
341
/** @defgroup I2C_XferDirection_definition I2C XferDirection definition
282
  * @{
342
  * @{
283
  */
343
  */
284
#define I2C_DIRECTION_RECEIVE           0x00000000U 
344
#define I2C_DIRECTION_RECEIVE           0x00000000U
285
#define I2C_DIRECTION_TRANSMIT          0x00000001U
345
#define I2C_DIRECTION_TRANSMIT          0x00000001U
286
/**
346
/**
287
  * @}
347
  * @}
288
  */
348
  */
289
 
349
 
290
/** @defgroup I2C_XferOptions_definition I2C XferOptions definition
350
/** @defgroup I2C_XferOptions_definition I2C XferOptions definition
291
  * @{
351
  * @{
292
  */
352
  */
293
#define  I2C_FIRST_FRAME                0x00000001U
353
#define  I2C_FIRST_FRAME                0x00000001U
-
 
354
#define  I2C_FIRST_AND_NEXT_FRAME       0x00000002U
294
#define  I2C_NEXT_FRAME                 0x00000002U
355
#define  I2C_NEXT_FRAME                 0x00000004U
295
#define  I2C_FIRST_AND_LAST_FRAME       0x00000004U
356
#define  I2C_FIRST_AND_LAST_FRAME       0x00000008U
-
 
357
#define  I2C_LAST_FRAME_NO_STOP         0x00000010U
296
#define  I2C_LAST_FRAME                 0x00000008U
358
#define  I2C_LAST_FRAME                 0x00000020U
-
 
359
 
-
 
360
/* List of XferOptions in usage of :
-
 
361
 * 1- Restart condition in all use cases (direction change or not)
-
 
362
 */
-
 
363
#define  I2C_OTHER_FRAME                (0x00AA0000U)
-
 
364
#define  I2C_OTHER_AND_LAST_FRAME       (0xAA000000U)
297
/**
365
/**
298
  * @}
366
  * @}
299
  */
367
  */
300
 
368
 
301
/** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
369
/** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
-
 
370
  * @brief I2C Interrupt definition
-
 
371
  *        Elements values convention: 0xXXXXXXXX
-
 
372
  *           - XXXXXXXX  : Interrupt control mask
302
  * @{
373
  * @{
303
  */
374
  */
304
#define I2C_IT_BUF                      I2C_CR2_ITBUFEN
375
#define I2C_IT_BUF                      I2C_CR2_ITBUFEN
305
#define I2C_IT_EVT                      I2C_CR2_ITEVTEN
376
#define I2C_IT_EVT                      I2C_CR2_ITEVTEN
306
#define I2C_IT_ERR                      I2C_CR2_ITERREN
377
#define I2C_IT_ERR                      I2C_CR2_ITERREN
Line 309... Line 380...
309
  */
380
  */
310
 
381
 
311
/** @defgroup I2C_Flag_definition I2C Flag definition
382
/** @defgroup I2C_Flag_definition I2C Flag definition
312
  * @{
383
  * @{
313
  */
384
  */
314
#define I2C_FLAG_SMBALERT               0x00018000U
-
 
315
#define I2C_FLAG_TIMEOUT                0x00014000U
-
 
316
#define I2C_FLAG_PECERR                 0x00011000U
-
 
-
 
385
 
317
#define I2C_FLAG_OVR                    0x00010800U
386
#define I2C_FLAG_OVR                    0x00010800U
318
#define I2C_FLAG_AF                     0x00010400U
387
#define I2C_FLAG_AF                     0x00010400U
319
#define I2C_FLAG_ARLO                   0x00010200U
388
#define I2C_FLAG_ARLO                   0x00010200U
320
#define I2C_FLAG_BERR                   0x00010100U
389
#define I2C_FLAG_BERR                   0x00010100U
321
#define I2C_FLAG_TXE                    0x00010080U
390
#define I2C_FLAG_TXE                    0x00010080U
Line 324... Line 393...
324
#define I2C_FLAG_ADD10                  0x00010008U
393
#define I2C_FLAG_ADD10                  0x00010008U
325
#define I2C_FLAG_BTF                    0x00010004U
394
#define I2C_FLAG_BTF                    0x00010004U
326
#define I2C_FLAG_ADDR                   0x00010002U
395
#define I2C_FLAG_ADDR                   0x00010002U
327
#define I2C_FLAG_SB                     0x00010001U
396
#define I2C_FLAG_SB                     0x00010001U
328
#define I2C_FLAG_DUALF                  0x00100080U
397
#define I2C_FLAG_DUALF                  0x00100080U
329
#define I2C_FLAG_SMBHOST                0x00100040U
-
 
330
#define I2C_FLAG_SMBDEFAULT             0x00100020U
-
 
331
#define I2C_FLAG_GENCALL                0x00100010U
398
#define I2C_FLAG_GENCALL                0x00100010U
332
#define I2C_FLAG_TRA                    0x00100004U
399
#define I2C_FLAG_TRA                    0x00100004U
333
#define I2C_FLAG_BUSY                   0x00100002U
400
#define I2C_FLAG_BUSY                   0x00100002U
334
#define I2C_FLAG_MSL                    0x00100001U
401
#define I2C_FLAG_MSL                    0x00100001U
335
/**
402
/**
Line 338... Line 405...
338
 
405
 
339
/**
406
/**
340
  * @}
407
  * @}
341
  */
408
  */
342
 
409
 
343
/* Exported macro ------------------------------------------------------------*/
410
/* Exported macros -----------------------------------------------------------*/
-
 
411
 
344
/** @defgroup I2C_Exported_Macros I2C Exported Macros
412
/** @defgroup I2C_Exported_Macros I2C Exported Macros
345
  * @{
413
  * @{
346
  */
414
  */
347
 
415
 
348
/** @brief Reset I2C handle state
416
/** @brief Reset I2C handle state.
349
  * @param  __HANDLE__: specifies the I2C Handle.
417
  * @param  __HANDLE__ specifies the I2C Handle.
350
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
351
  * @retval None
418
  * @retval None
352
  */
419
  */
-
 
420
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
-
 
421
#define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__)                do{                                                   \
-
 
422
                                                                    (__HANDLE__)->State = HAL_I2C_STATE_RESET;       \
-
 
423
                                                                    (__HANDLE__)->MspInitCallback = NULL;            \
-
 
424
                                                                    (__HANDLE__)->MspDeInitCallback = NULL;          \
-
 
425
                                                                  } while(0)
-
 
426
#else
353
#define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
427
#define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__)                ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
-
 
428
#endif
354
 
429
 
355
/** @brief  Enable or disable the specified I2C interrupts.
430
/** @brief  Enable or disable the specified I2C interrupts.
356
  * @param  __HANDLE__: specifies the I2C Handle.
431
  * @param  __HANDLE__ specifies the I2C Handle.
357
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
358
  * @param  __INTERRUPT__: specifies the interrupt source to enable or disable.
432
  * @param  __INTERRUPT__ specifies the interrupt source to enable or disable.
359
  *         This parameter can be one of the following values:
433
  *         This parameter can be one of the following values:
360
  *            @arg I2C_IT_BUF: Buffer interrupt enable
434
  *            @arg I2C_IT_BUF: Buffer interrupt enable
361
  *            @arg I2C_IT_EVT: Event interrupt enable
435
  *            @arg I2C_IT_EVT: Event interrupt enable
362
  *            @arg I2C_IT_ERR: Error interrupt enable
436
  *            @arg I2C_IT_ERR: Error interrupt enable
363
  * @retval None
437
  * @retval None
364
  */
438
  */
365
#define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
439
#define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__)   SET_BIT((__HANDLE__)->Instance->CR2,(__INTERRUPT__))
366
#define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
440
#define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__)  CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
367
 
441
 
368
/** @brief  Checks if the specified I2C interrupt source is enabled or disabled.
442
/** @brief  Checks if the specified I2C interrupt source is enabled or disabled.
369
  * @param  __HANDLE__: specifies the I2C Handle.
443
  * @param  __HANDLE__ specifies the I2C Handle.
370
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
371
  * @param  __INTERRUPT__: specifies the I2C interrupt source to check.
444
  * @param  __INTERRUPT__ specifies the I2C interrupt source to check.
372
  *          This parameter can be one of the following values:
445
  *          This parameter can be one of the following values:
373
  *            @arg I2C_IT_BUF: Buffer interrupt enable
446
  *            @arg I2C_IT_BUF: Buffer interrupt enable
374
  *            @arg I2C_IT_EVT: Event interrupt enable
447
  *            @arg I2C_IT_EVT: Event interrupt enable
375
  *            @arg I2C_IT_ERR: Error interrupt enable
448
  *            @arg I2C_IT_ERR: Error interrupt enable
376
  * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
449
  * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
377
  */
450
  */
378
#define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
451
#define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
379
 
452
 
380
/** @brief  Checks whether the specified I2C flag is set or not.
453
/** @brief  Checks whether the specified I2C flag is set or not.
381
  * @param  __HANDLE__: specifies the I2C Handle.
454
  * @param  __HANDLE__ specifies the I2C Handle.
382
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
383
  * @param  __FLAG__: specifies the flag to check.
455
  * @param  __FLAG__ specifies the flag to check.
384
  *         This parameter can be one of the following values:
456
  *         This parameter can be one of the following values:
385
  *            @arg I2C_FLAG_SMBALERT: SMBus Alert flag
-
 
386
  *            @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
-
 
387
  *            @arg I2C_FLAG_PECERR: PEC error in reception flag
-
 
388
  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag
457
  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag
389
  *            @arg I2C_FLAG_AF: Acknowledge failure flag
458
  *            @arg I2C_FLAG_AF: Acknowledge failure flag
390
  *            @arg I2C_FLAG_ARLO: Arbitration lost flag
459
  *            @arg I2C_FLAG_ARLO: Arbitration lost flag
391
  *            @arg I2C_FLAG_BERR: Bus error flag
460
  *            @arg I2C_FLAG_BERR: Bus error flag
392
  *            @arg I2C_FLAG_TXE: Data register empty flag
461
  *            @arg I2C_FLAG_TXE: Data register empty flag
Line 396... Line 465...
396
  *            @arg I2C_FLAG_BTF: Byte transfer finished flag
465
  *            @arg I2C_FLAG_BTF: Byte transfer finished flag
397
  *            @arg I2C_FLAG_ADDR: Address sent flag
466
  *            @arg I2C_FLAG_ADDR: Address sent flag
398
  *                                Address matched flag
467
  *                                Address matched flag
399
  *            @arg I2C_FLAG_SB: Start bit flag
468
  *            @arg I2C_FLAG_SB: Start bit flag
400
  *            @arg I2C_FLAG_DUALF: Dual flag
469
  *            @arg I2C_FLAG_DUALF: Dual flag
401
  *            @arg I2C_FLAG_SMBHOST: SMBus host header
-
 
402
  *            @arg I2C_FLAG_SMBDEFAULT: SMBus default header
-
 
403
  *            @arg I2C_FLAG_GENCALL: General call header flag
470
  *            @arg I2C_FLAG_GENCALL: General call header flag
404
  *            @arg I2C_FLAG_TRA: Transmitter/Receiver flag
471
  *            @arg I2C_FLAG_TRA: Transmitter/Receiver flag
405
  *            @arg I2C_FLAG_BUSY: Bus busy flag
472
  *            @arg I2C_FLAG_BUSY: Bus busy flag
406
  *            @arg I2C_FLAG_MSL: Master/Slave flag
473
  *            @arg I2C_FLAG_MSL: Master/Slave flag
407
  * @retval The new state of __FLAG__ (TRUE or FALSE).
474
  * @retval The new state of __FLAG__ (TRUE or FALSE).
408
  */
475
  */
-
 
476
#define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U) ? \
409
#define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \
477
                                                  (((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET) : \
410
                                                 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
478
                                                  (((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET))
411
 
479
 
412
/** @brief  Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
480
/** @brief  Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
413
  * @param  __HANDLE__: specifies the I2C Handle.
481
  * @param  __HANDLE__ specifies the I2C Handle.
414
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
415
  * @param  __FLAG__: specifies the flag to clear.
482
  * @param  __FLAG__ specifies the flag to clear.
416
  *         This parameter can be any combination of the following values:
483
  *         This parameter can be any combination of the following values:
417
  *            @arg I2C_FLAG_SMBALERT: SMBus Alert flag
-
 
418
  *            @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
-
 
419
  *            @arg I2C_FLAG_PECERR: PEC error in reception flag
-
 
420
  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
484
  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
421
  *            @arg I2C_FLAG_AF: Acknowledge failure flag
485
  *            @arg I2C_FLAG_AF: Acknowledge failure flag
422
  *            @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
486
  *            @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
423
  *            @arg I2C_FLAG_BERR: Bus error flag
487
  *            @arg I2C_FLAG_BERR: Bus error flag
424
  * @retval None
488
  * @retval None
425
  */
489
  */
426
#define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
490
#define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
427
 
491
 
428
/** @brief  Clears the I2C ADDR pending flag.
492
/** @brief  Clears the I2C ADDR pending flag.
429
  * @param  __HANDLE__: specifies the I2C Handle.
493
  * @param  __HANDLE__ specifies the I2C Handle.
430
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
494
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
431
  * @retval None
495
  * @retval None
432
  */
496
  */
433
#define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__)    \
497
#define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__)    \
434
  do{                                           \
498
  do{                                           \
435
    __IO uint32_t tmpreg = 0x00U;               \
499
    __IO uint32_t tmpreg = 0x00U;               \
436
    tmpreg = (__HANDLE__)->Instance->SR1;       \
500
    tmpreg = (__HANDLE__)->Instance->SR1;       \
437
    tmpreg = (__HANDLE__)->Instance->SR2;       \
501
    tmpreg = (__HANDLE__)->Instance->SR2;       \
438
    UNUSED(tmpreg);                             \
502
    UNUSED(tmpreg);                             \
439
  } while(0U)
503
  } while(0)
440
 
504
 
441
/** @brief  Clears the I2C STOPF pending flag.
505
/** @brief  Clears the I2C STOPF pending flag.
442
  * @param  __HANDLE__: specifies the I2C Handle.
506
  * @param  __HANDLE__ specifies the I2C Handle.
443
  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
-
 
444
  * @retval None
507
  * @retval None
445
  */
508
  */
446
#define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__)    \
509
#define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__)           \
447
  do{                                           \
510
  do{                                                  \
448
    __IO uint32_t tmpreg = 0x00U;               \
511
    __IO uint32_t tmpreg = 0x00U;                      \
449
    tmpreg = (__HANDLE__)->Instance->SR1;       \
512
    tmpreg = (__HANDLE__)->Instance->SR1;              \
450
    (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE;  \
513
    SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE);  \
451
    UNUSED(tmpreg);                             \
514
    UNUSED(tmpreg);                                    \
452
  } while(0U)
515
  } while(0)
453
   
516
 
454
/** @brief  Enable the I2C peripheral.
517
/** @brief  Enable the specified I2C peripheral.
455
  * @param  __HANDLE__: specifies the I2C Handle.
518
  * @param  __HANDLE__ specifies the I2C Handle.
456
  *         This parameter can be I2Cx where x: 1 or 2  to select the I2C peripheral.
-
 
457
  * @retval None
519
  * @retval None
458
  */
520
  */
459
#define __HAL_I2C_ENABLE(__HANDLE__)                             ((__HANDLE__)->Instance->CR1 |=  I2C_CR1_PE)
521
#define __HAL_I2C_ENABLE(__HANDLE__)                  SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)
460
 
522
 
461
/** @brief  Disable the I2C peripheral.
523
/** @brief  Disable the specified I2C peripheral.
462
  * @param  __HANDLE__: specifies the I2C Handle.
524
  * @param  __HANDLE__ specifies the I2C Handle.
463
  *         This parameter can be I2Cx where x: 1 or 2  to select the I2C peripheral.
-
 
464
  * @retval None
525
  * @retval None
465
  */
526
  */
466
#define __HAL_I2C_DISABLE(__HANDLE__)                            ((__HANDLE__)->Instance->CR1 &=  ~I2C_CR1_PE)
527
#define __HAL_I2C_DISABLE(__HANDLE__)                 CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)
467
 
528
 
468
/**
529
/**
469
  * @}
530
  * @}
470
  */
531
  */
471
 
532
 
472
/* Exported functions --------------------------------------------------------*/
533
/* Exported functions --------------------------------------------------------*/
473
/** @addtogroup I2C_Exported_Functions
534
/** @addtogroup I2C_Exported_Functions
474
  * @{
535
  * @{
475
  */
536
  */
476
 
537
 
477
/** @addtogroup I2C_Exported_Functions_Group1
538
/** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions
478
  * @{
539
  * @{
479
  */
540
  */
480
/* Initialization/de-initialization functions  **********************************/
541
/* Initialization and de-initialization functions******************************/
481
HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
542
HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
482
HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
543
HAL_StatusTypeDef HAL_I2C_DeInit(I2C_HandleTypeDef *hi2c);
483
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
544
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
484
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
545
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
-
 
546
 
-
 
547
/* Callbacks Register/UnRegister functions  ***********************************/
-
 
548
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
-
 
549
HAL_StatusTypeDef HAL_I2C_RegisterCallback(I2C_HandleTypeDef *hi2c, HAL_I2C_CallbackIDTypeDef CallbackID, pI2C_CallbackTypeDef pCallback);
-
 
550
HAL_StatusTypeDef HAL_I2C_UnRegisterCallback(I2C_HandleTypeDef *hi2c, HAL_I2C_CallbackIDTypeDef CallbackID);
-
 
551
 
-
 
552
HAL_StatusTypeDef HAL_I2C_RegisterAddrCallback(I2C_HandleTypeDef *hi2c, pI2C_AddrCallbackTypeDef pCallback);
-
 
553
HAL_StatusTypeDef HAL_I2C_UnRegisterAddrCallback(I2C_HandleTypeDef *hi2c);
-
 
554
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
485
/**
555
/**
486
  * @}
556
  * @}
487
  */
557
  */
488
 
558
 
489
/** @addtogroup I2C_Exported_Functions_Group2
559
/** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions
490
  * @{
560
  * @{
491
  */
561
  */
492
/* I/O operation functions  *****************************************************/
562
/* IO operation functions  ****************************************************/
493
/******* Blocking mode: Polling */
563
/******* Blocking mode: Polling */
494
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
564
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
495
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
565
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
496
HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
566
HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
497
HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
567
HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Line 505... Line 575...
505
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
575
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
506
HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
576
HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
507
HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
577
HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
508
HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
578
HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
509
 
579
 
510
HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
580
HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
511
HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
581
HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
512
HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
582
HAL_StatusTypeDef HAL_I2C_Slave_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
513
HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
583
HAL_StatusTypeDef HAL_I2C_Slave_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
514
HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
-
 
515
HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
584
HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
516
HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
585
HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
-
 
586
HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
517
 
587
 
518
/******* Non-Blocking mode: DMA */
588
/******* Non-Blocking mode: DMA */
519
HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
589
HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
520
HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
590
HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
521
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
591
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
522
HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
592
HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
523
HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
593
HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
524
HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
594
HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
525
 
595
 
-
 
596
HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
-
 
597
HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
-
 
598
HAL_StatusTypeDef HAL_I2C_Slave_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
-
 
599
HAL_StatusTypeDef HAL_I2C_Slave_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
-
 
600
/**
-
 
601
  * @}
-
 
602
  */
-
 
603
 
-
 
604
/** @addtogroup I2C_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
-
 
605
 * @{
-
 
606
 */
526
/******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
607
/******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
527
void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
608
void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
528
void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
609
void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
529
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
610
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
530
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
611
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
Line 538... Line 619...
538
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
619
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
539
/**
620
/**
540
  * @}
621
  * @}
541
  */
622
  */
542
 
623
 
543
/** @addtogroup I2C_Exported_Functions_Group3
624
/** @addtogroup I2C_Exported_Functions_Group3 Peripheral State, Mode and Error functions
544
  * @{
625
  * @{
545
  */
626
  */
546
/* Peripheral State, Mode and Errors functions  *********************************/
627
/* Peripheral State, Mode and Error functions  *********************************/
547
HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
628
HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
548
HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
629
HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
549
uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
630
uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
550
 
631
 
551
/**
632
/**
Line 581... Line 662...
581
#define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 3U) : (I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 25U) | I2C_DUTYCYCLE_16_9))
662
#define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 3U) : (I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 25U) | I2C_DUTYCYCLE_16_9))
582
#define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__)      (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
663
#define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__)      (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
583
                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
664
                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
584
                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
665
                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
585
 
666
 
586
#define I2C_7BIT_ADD_WRITE(__ADDRESS__)                    ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
667
#define I2C_7BIT_ADD_WRITE(__ADDRESS__)                    ((uint8_t)((__ADDRESS__) & (uint8_t)(~I2C_OAR1_ADD0)))
587
#define I2C_7BIT_ADD_READ(__ADDRESS__)                     ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
668
#define I2C_7BIT_ADD_READ(__ADDRESS__)                     ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
588
 
669
 
589
#define I2C_10BIT_ADDRESS(__ADDRESS__)                     ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
670
#define I2C_10BIT_ADDRESS(__ADDRESS__)                     ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
590
#define I2C_10BIT_HEADER_WRITE(__ADDRESS__)                ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F0U))))
671
#define I2C_10BIT_HEADER_WRITE(__ADDRESS__)                ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)0x00F0)))
591
#define I2C_10BIT_HEADER_READ(__ADDRESS__)                 ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F1U))))
672
#define I2C_10BIT_HEADER_READ(__ADDRESS__)                 ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)(0x00F1))))
592
 
673
 
593
#define I2C_MEM_ADD_MSB(__ADDRESS__)                       ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
674
#define I2C_MEM_ADD_MSB(__ADDRESS__)                       ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0xFF00)) >> 8)))
594
#define I2C_MEM_ADD_LSB(__ADDRESS__)                       ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
675
#define I2C_MEM_ADD_LSB(__ADDRESS__)                       ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
595
 
676
 
596
/** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
677
/** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
597
  * @{
678
  * @{
598
  */
679
  */
599
#define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
680
#define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
Line 606... Line 687...
606
                                   ((CALL) == I2C_GENERALCALL_ENABLE))
687
                                   ((CALL) == I2C_GENERALCALL_ENABLE))
607
#define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
688
#define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
608
                                    ((STRETCH) == I2C_NOSTRETCH_ENABLE))
689
                                    ((STRETCH) == I2C_NOSTRETCH_ENABLE))
609
#define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
690
#define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
610
                                  ((SIZE) == I2C_MEMADD_SIZE_16BIT))
691
                                  ((SIZE) == I2C_MEMADD_SIZE_16BIT))
611
#define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0) && ((SPEED) <= 400000U))
692
#define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 400000U))
612
#define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00U)) == 0U)
693
#define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & 0xFFFFFC00U) == 0U)
613
#define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01U)) == 0U)
694
#define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & 0xFFFFFF01U) == 0U)
614
#define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST)      (((REQUEST) == I2C_FIRST_FRAME)              || \
695
#define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST)      (((REQUEST) == I2C_FIRST_FRAME)              || \
-
 
696
                                                       ((REQUEST) == I2C_FIRST_AND_NEXT_FRAME)     || \
615
                                                       ((REQUEST) == I2C_NEXT_FRAME)               || \
697
                                                       ((REQUEST) == I2C_NEXT_FRAME)               || \
616
                                                       ((REQUEST) == I2C_FIRST_AND_LAST_FRAME)     || \
698
                                                       ((REQUEST) == I2C_FIRST_AND_LAST_FRAME)     || \
-
 
699
                                                       ((REQUEST) == I2C_LAST_FRAME)               || \
-
 
700
                                                       ((REQUEST) == I2C_LAST_FRAME_NO_STOP)       || \
-
 
701
                                                       IS_I2C_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST))
-
 
702
 
-
 
703
#define IS_I2C_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_OTHER_FRAME)     || \
617
                                                       ((REQUEST) == I2C_LAST_FRAME))
704
                                                        ((REQUEST) == I2C_OTHER_AND_LAST_FRAME))
-
 
705
 
-
 
706
#define I2C_CHECK_FLAG(__ISR__, __FLAG__)         ((((__ISR__) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET)
-
 
707
#define I2C_CHECK_IT_SOURCE(__CR1__, __IT__)      ((((__CR1__) & (__IT__)) == (__IT__)) ? SET : RESET)
618
/**
708
/**
619
  * @}
709
  * @}
620
  */
710
  */
621
 
711
 
622
/**
712
/**