]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_i2c.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_i2c.h
1 /**
2   ******************************************************************************
3   * @file    stm32f30x_i2c.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    27-February-2014
7   * @brief   This file contains all the functions prototypes for the I2C firmware
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13   *
14   * Redistribution and use in source and binary forms, with or without modification,
15   * are permitted provided that the following conditions are met:
16   *   1. Redistributions of source code must retain the above copyright notice,
17   *      this list of conditions and the following disclaimer.
18   *   2. Redistributions in binary form must reproduce the above copyright notice,
19   *      this list of conditions and the following disclaimer in the documentation
20   *      and/or other materials provided with the distribution.
21   *   3. Neither the name of STMicroelectronics nor the names of its contributors
22   *      may be used to endorse or promote products derived from this software
23   *      without specific prior written permission.
24   *
25   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   *
36   ******************************************************************************
37   */
38
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32F30x_I2C_H
41 #define __STM32F30x_I2C_H
42
43 #ifdef __cplusplus
44  extern "C" {
45 #endif
46
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32f30x.h"
49
50 /** @addtogroup STM32F30x_StdPeriph_Driver
51   * @{
52   */
53
54 /** @addtogroup I2C
55   * @{
56   */
57
58 /* Exported types ------------------------------------------------------------*/
59
60 /**
61   * @brief  I2C Init structure definition
62   */
63
64 typedef struct
65 {
66   uint32_t I2C_Timing;              /*!< Specifies the I2C_TIMINGR_register value.
67                                          This parameter calculated by referring to I2C initialization 
68                                          section in Reference manual*/
69
70   uint32_t I2C_AnalogFilter;        /*!< Enables or disables analog noise filter.
71                                          This parameter can be a value of @ref I2C_Analog_Filter */
72
73   uint32_t I2C_DigitalFilter;       /*!< Configures the digital noise filter.
74                                          This parameter can be a number between 0x00 and 0x0F */
75
76   uint32_t I2C_Mode;                /*!< Specifies the I2C mode.
77                                          This parameter can be a value of @ref I2C_mode */
78
79   uint32_t I2C_OwnAddress1;         /*!< Specifies the device own address 1.
80                                          This parameter can be a 7-bit or 10-bit address */
81
82   uint32_t I2C_Ack;                 /*!< Enables or disables the acknowledgement.
83                                          This parameter can be a value of @ref I2C_acknowledgement */
84
85   uint32_t I2C_AcknowledgedAddress; /*!< Specifies if 7-bit or 10-bit address is acknowledged.
86                                          This parameter can be a value of @ref I2C_acknowledged_address */
87 }I2C_InitTypeDef;
88
89 /* Exported constants --------------------------------------------------------*/
90
91
92 /** @defgroup I2C_Exported_Constants
93   * @{
94   */
95
96 #define IS_I2C_ALL_PERIPH(PERIPH)       (((PERIPH) == I2C1) || \
97                                          ((PERIPH) == I2C2))
98
99 /** @defgroup I2C_Analog_Filter 
100   * @{
101   */
102
103 #define I2C_AnalogFilter_Enable         ((uint32_t)0x00000000)
104 #define I2C_AnalogFilter_Disable        I2C_CR1_ANFOFF
105
106 #define IS_I2C_ANALOG_FILTER(FILTER)    (((FILTER) == I2C_AnalogFilter_Enable) || \
107                                          ((FILTER) == I2C_AnalogFilter_Disable))
108 /**
109   * @}
110   */
111      
112 /** @defgroup I2C_Digital_Filter
113   * @{
114   */
115
116 #define IS_I2C_DIGITAL_FILTER(FILTER)   ((FILTER) <= 0x0000000F)
117 /**
118   * @}
119   */
120
121 /** @defgroup I2C_mode 
122   * @{
123   */
124
125 #define I2C_Mode_I2C                    ((uint32_t)0x00000000)
126 #define I2C_Mode_SMBusDevice            I2C_CR1_SMBDEN
127 #define I2C_Mode_SMBusHost              I2C_CR1_SMBHEN
128
129 #define IS_I2C_MODE(MODE)               (((MODE) == I2C_Mode_I2C) || \
130                                          ((MODE) == I2C_Mode_SMBusDevice) || \
131                                          ((MODE) == I2C_Mode_SMBusHost))
132 /**
133   * @}
134   */
135
136 /** @defgroup I2C_acknowledgement
137   * @{
138   */
139
140 #define I2C_Ack_Enable                  ((uint32_t)0x00000000)
141 #define I2C_Ack_Disable                 I2C_CR2_NACK
142
143 #define IS_I2C_ACK(ACK)                 (((ACK) == I2C_Ack_Enable) || \
144                                          ((ACK) == I2C_Ack_Disable))
145 /**
146   * @}
147   */
148
149 /** @defgroup I2C_acknowledged_address
150   * @{
151   */
152
153 #define I2C_AcknowledgedAddress_7bit    ((uint32_t)0x00000000)
154 #define I2C_AcknowledgedAddress_10bit   I2C_OAR1_OA1MODE
155
156 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
157                                              ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
158 /**
159   * @}
160   */ 
161
162 /** @defgroup I2C_own_address1
163   * @{
164   */
165
166 #define IS_I2C_OWN_ADDRESS1(ADDRESS1)   ((ADDRESS1) <= (uint32_t)0x000003FF)
167 /**
168   * @}
169   */
170
171 /** @defgroup I2C_transfer_direction 
172   * @{
173   */
174
175 #define I2C_Direction_Transmitter       ((uint16_t)0x0000)
176 #define I2C_Direction_Receiver          ((uint16_t)0x0400)
177
178 #define IS_I2C_DIRECTION(DIRECTION)     (((DIRECTION) == I2C_Direction_Transmitter) || \
179                                          ((DIRECTION) == I2C_Direction_Receiver))
180 /**
181   * @}
182   */
183
184 /** @defgroup I2C_DMA_transfer_requests 
185   * @{
186   */
187
188 #define I2C_DMAReq_Tx                   I2C_CR1_TXDMAEN
189 #define I2C_DMAReq_Rx                   I2C_CR1_RXDMAEN
190
191 #define IS_I2C_DMA_REQ(REQ)             ((((REQ) & (uint32_t)0xFFFF3FFF) == 0x00) && ((REQ) != 0x00))
192 /**
193   * @}
194   */
195
196 /** @defgroup I2C_slave_address
197   * @{
198   */
199
200 #define IS_I2C_SLAVE_ADDRESS(ADDRESS)   ((ADDRESS) <= (uint16_t)0x03FF)
201 /**
202   * @}
203   */
204
205
206 /** @defgroup I2C_own_address2
207   * @{
208   */
209
210 #define IS_I2C_OWN_ADDRESS2(ADDRESS2)   ((ADDRESS2) <= (uint16_t)0x00FF)
211
212 /**
213   * @}
214   */
215
216 /** @defgroup I2C_own_address2_mask
217   * @{
218   */
219
220 #define I2C_OA2_NoMask                  ((uint8_t)0x00)
221 #define I2C_OA2_Mask01                  ((uint8_t)0x01)
222 #define I2C_OA2_Mask02                  ((uint8_t)0x02)
223 #define I2C_OA2_Mask03                  ((uint8_t)0x03)
224 #define I2C_OA2_Mask04                  ((uint8_t)0x04)
225 #define I2C_OA2_Mask05                  ((uint8_t)0x05)
226 #define I2C_OA2_Mask06                  ((uint8_t)0x06)
227 #define I2C_OA2_Mask07                  ((uint8_t)0x07)
228
229 #define IS_I2C_OWN_ADDRESS2_MASK(MASK)  (((MASK) == I2C_OA2_NoMask) || \
230                                          ((MASK) == I2C_OA2_Mask01) || \
231                                          ((MASK) == I2C_OA2_Mask02) || \
232                                          ((MASK) == I2C_OA2_Mask03) || \
233                                          ((MASK) == I2C_OA2_Mask04) || \
234                                          ((MASK) == I2C_OA2_Mask05) || \
235                                          ((MASK) == I2C_OA2_Mask06) || \
236                                          ((MASK) == I2C_OA2_Mask07))  
237
238 /**
239   * @}
240   */
241
242 /** @defgroup I2C_timeout
243   * @{
244   */
245
246 #define IS_I2C_TIMEOUT(TIMEOUT)   ((TIMEOUT) <= (uint16_t)0x0FFF)
247
248 /**
249   * @}
250   */
251
252 /** @defgroup I2C_registers 
253   * @{
254   */
255
256 #define I2C_Register_CR1                ((uint8_t)0x00)
257 #define I2C_Register_CR2                ((uint8_t)0x04)
258 #define I2C_Register_OAR1               ((uint8_t)0x08)
259 #define I2C_Register_OAR2               ((uint8_t)0x0C)
260 #define I2C_Register_TIMINGR            ((uint8_t)0x10)
261 #define I2C_Register_TIMEOUTR           ((uint8_t)0x14)
262 #define I2C_Register_ISR                ((uint8_t)0x18)
263 #define I2C_Register_ICR                ((uint8_t)0x1C)
264 #define I2C_Register_PECR               ((uint8_t)0x20)
265 #define I2C_Register_RXDR               ((uint8_t)0x24)
266 #define I2C_Register_TXDR               ((uint8_t)0x28)
267
268 #define IS_I2C_REGISTER(REGISTER)       (((REGISTER) == I2C_Register_CR1) || \
269                                          ((REGISTER) == I2C_Register_CR2) || \
270                                          ((REGISTER) == I2C_Register_OAR1) || \
271                                          ((REGISTER) == I2C_Register_OAR2) || \
272                                          ((REGISTER) == I2C_Register_TIMINGR) || \
273                                          ((REGISTER) == I2C_Register_TIMEOUTR) || \
274                                          ((REGISTER) == I2C_Register_ISR) || \
275                                          ((REGISTER) == I2C_Register_ICR) || \
276                                          ((REGISTER) == I2C_Register_PECR) || \
277                                          ((REGISTER) == I2C_Register_RXDR) || \
278                                          ((REGISTER) == I2C_Register_TXDR))
279 /**
280   * @}
281   */
282
283 /** @defgroup I2C_interrupts_definition 
284   * @{
285   */
286
287 #define I2C_IT_ERRI                     I2C_CR1_ERRIE
288 #define I2C_IT_TCI                      I2C_CR1_TCIE
289 #define I2C_IT_STOPI                    I2C_CR1_STOPIE
290 #define I2C_IT_NACKI                    I2C_CR1_NACKIE
291 #define I2C_IT_ADDRI                    I2C_CR1_ADDRIE
292 #define I2C_IT_RXI                      I2C_CR1_RXIE
293 #define I2C_IT_TXI                      I2C_CR1_TXIE
294
295 #define IS_I2C_CONFIG_IT(IT)            ((((IT) & (uint32_t)0xFFFFFF01) == 0x00) && ((IT) != 0x00))
296
297 /**
298   * @}
299   */
300
301 /** @defgroup I2C_flags_definition 
302   * @{
303   */
304
305 #define  I2C_FLAG_TXE                   I2C_ISR_TXE
306 #define  I2C_FLAG_TXIS                  I2C_ISR_TXIS
307 #define  I2C_FLAG_RXNE                  I2C_ISR_RXNE
308 #define  I2C_FLAG_ADDR                  I2C_ISR_ADDR
309 #define  I2C_FLAG_NACKF                 I2C_ISR_NACKF
310 #define  I2C_FLAG_STOPF                 I2C_ISR_STOPF
311 #define  I2C_FLAG_TC                    I2C_ISR_TC
312 #define  I2C_FLAG_TCR                   I2C_ISR_TCR
313 #define  I2C_FLAG_BERR                  I2C_ISR_BERR
314 #define  I2C_FLAG_ARLO                  I2C_ISR_ARLO
315 #define  I2C_FLAG_OVR                   I2C_ISR_OVR
316 #define  I2C_FLAG_PECERR                I2C_ISR_PECERR
317 #define  I2C_FLAG_TIMEOUT               I2C_ISR_TIMEOUT
318 #define  I2C_FLAG_ALERT                 I2C_ISR_ALERT
319 #define  I2C_FLAG_BUSY                  I2C_ISR_BUSY
320
321 #define IS_I2C_CLEAR_FLAG(FLAG)         ((((FLAG) & (uint32_t)0xFFFF4000) == 0x00) && ((FLAG) != 0x00))
322
323 #define IS_I2C_GET_FLAG(FLAG)           (((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_TXIS) || \
324                                          ((FLAG) == I2C_FLAG_RXNE) || ((FLAG) == I2C_FLAG_ADDR) || \
325                                          ((FLAG) == I2C_FLAG_NACKF) || ((FLAG) == I2C_FLAG_STOPF) || \
326                                          ((FLAG) == I2C_FLAG_TC) || ((FLAG) == I2C_FLAG_TCR) || \
327                                          ((FLAG) == I2C_FLAG_BERR) || ((FLAG) == I2C_FLAG_ARLO) || \
328                                          ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_PECERR) || \
329                                          ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_ALERT) || \
330                                          ((FLAG) == I2C_FLAG_BUSY))
331
332 /**
333   * @}
334   */
335
336
337 /** @defgroup I2C_interrupts_definition 
338   * @{
339   */
340
341 #define  I2C_IT_TXIS                    I2C_ISR_TXIS
342 #define  I2C_IT_RXNE                    I2C_ISR_RXNE
343 #define  I2C_IT_ADDR                    I2C_ISR_ADDR
344 #define  I2C_IT_NACKF                   I2C_ISR_NACKF
345 #define  I2C_IT_STOPF                   I2C_ISR_STOPF
346 #define  I2C_IT_TC                      I2C_ISR_TC
347 #define  I2C_IT_TCR                     I2C_ISR_TCR
348 #define  I2C_IT_BERR                    I2C_ISR_BERR
349 #define  I2C_IT_ARLO                    I2C_ISR_ARLO
350 #define  I2C_IT_OVR                     I2C_ISR_OVR
351 #define  I2C_IT_PECERR                  I2C_ISR_PECERR
352 #define  I2C_IT_TIMEOUT                 I2C_ISR_TIMEOUT
353 #define  I2C_IT_ALERT                   I2C_ISR_ALERT
354
355 #define IS_I2C_CLEAR_IT(IT)             ((((IT) & (uint32_t)0xFFFFC001) == 0x00) && ((IT) != 0x00))
356                                
357 #define IS_I2C_GET_IT(IT)               (((IT) == I2C_IT_TXIS) || ((IT) == I2C_IT_RXNE) || \
358                                          ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_NACKF) || \
359                                          ((IT) == I2C_IT_STOPF) || ((IT) == I2C_IT_TC) || \
360                                          ((IT) == I2C_IT_TCR) || ((IT) == I2C_IT_BERR) || \
361                                          ((IT) == I2C_IT_ARLO) || ((IT) == I2C_IT_OVR) || \
362                                          ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_TIMEOUT) || \
363                                          ((IT) == I2C_IT_ALERT))
364                                
365
366 /**
367   * @}
368   */
369
370 /** @defgroup I2C_ReloadEndMode_definition 
371   * @{
372   */
373
374 #define  I2C_Reload_Mode                I2C_CR2_RELOAD
375 #define  I2C_AutoEnd_Mode               I2C_CR2_AUTOEND
376 #define  I2C_SoftEnd_Mode               ((uint32_t)0x00000000)
377
378                               
379 #define IS_RELOAD_END_MODE(MODE)        (((MODE) == I2C_Reload_Mode) || \
380                                          ((MODE) == I2C_AutoEnd_Mode) || \
381                                          ((MODE) == I2C_SoftEnd_Mode))
382                                
383
384 /**
385   * @}
386   */
387
388 /** @defgroup I2C_StartStopMode_definition 
389   * @{
390   */
391
392 #define  I2C_No_StartStop                 ((uint32_t)0x00000000)
393 #define  I2C_Generate_Stop                I2C_CR2_STOP
394 #define  I2C_Generate_Start_Read          (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
395 #define  I2C_Generate_Start_Write         I2C_CR2_START
396
397                               
398 #define IS_START_STOP_MODE(MODE)        (((MODE) == I2C_Generate_Stop) || \
399                                          ((MODE) == I2C_Generate_Start_Read) || \
400                                          ((MODE) == I2C_Generate_Start_Write) || \
401                                          ((MODE) == I2C_No_StartStop))
402                                
403
404 /**
405   * @}
406   */
407
408 /**
409   * @}
410   */
411
412 /* Exported macro ------------------------------------------------------------*/
413 /* Exported functions ------------------------------------------------------- */
414
415
416 /* Initialization and Configuration functions *********************************/
417 void I2C_DeInit(I2C_TypeDef* I2Cx);
418 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
419 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
420 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
421 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx);
422 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint32_t I2C_IT, FunctionalState NewState);
423 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
424 void I2C_StopModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
425 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
426 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Mask);
427 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
428 void I2C_SlaveByteControlCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
429 void I2C_SlaveAddressConfig(I2C_TypeDef* I2Cx, uint16_t Address);
430 void I2C_10BitAddressingModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
431
432 /* Communications handling functions ******************************************/
433 void I2C_AutoEndCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
434 void I2C_ReloadCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
435 void I2C_NumberOfBytesConfig(I2C_TypeDef* I2Cx, uint8_t Number_Bytes);
436 void I2C_MasterRequestConfig(I2C_TypeDef* I2Cx, uint16_t I2C_Direction);
437 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
438 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
439 void I2C_10BitAddressHeaderCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
440 void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
441 uint8_t I2C_GetAddressMatched(I2C_TypeDef* I2Cx);
442 uint16_t I2C_GetTransferDirection(I2C_TypeDef* I2Cx);
443 void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode);
444
445 /*  SMBUS management functions ************************************************/
446 void I2C_SMBusAlertCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
447 void I2C_ClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
448 void I2C_ExtendedClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
449 void I2C_IdleClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
450 void I2C_TimeoutAConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
451 void I2C_TimeoutBConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
452 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
453 void I2C_PECRequestCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
454 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
455
456 /* I2C registers management functions *****************************************/
457 uint32_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register);
458
459 /* Data transfers management functions ****************************************/
460 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
461 uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
462
463 /* DMA transfers management functions *****************************************/
464 void I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState);
465
466 /* Interrupts and flags management functions **********************************/
467 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
468 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
469 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
470 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
471
472
473 #ifdef __cplusplus
474 }
475 #endif
476
477 #endif /*__STM32F30x_I2C_H */
478
479 /**
480   * @}
481   */
482
483 /**
484   * @}
485   */
486
487 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/