STM32F0 CPAL I2C bibliotheek  1.0
ST Microelectronics CPALv2 bibliotheek documentatie
 All Data Structures Files Functions Variables Enumerations Enumerator Macros
stm32f0xx_i2c_cpal.h
Go to the documentation of this file.
1 
29 /* Includes ------------------------------------------------------------------*/
30 /*========= CPAL library files includes =========*/
31 #include "stm32f0xx_i2c_cpal_hal.h"
32 #include "stm32f0xx_i2c_cpal_conf.h"
33 
34 /* Define to prevent recursive inclusion -------------------------------------*/
35 #ifndef __STM32F0XX_I2C_CPAL_H
36 #define __STM32F0XX_I2C_CPAL_H
37 
38 #ifdef __cplusplus
39  extern "C" {
40 #endif
41 
42 /* Exported types ------------------------------------------------------------*/
43 /*========= CPAL_Dev_TypeDef =========*/
44 /* CPAL devices enumeration contains the device instances */
45 
46 typedef enum
47 {
48  CPAL_I2C1 = 0x00,
50  CPAL_I2C2 = 0x01
53 
54 
55 /*========= CPAL_Direction_TypeDef =========*/
56 /* CPAL transfer directions enumeration is used to configure DMA channels
57  (TX and RX) if CPAL_PROGMODEL_DMA is selected or TX/RX interrupts
58  if CPAL_PROGMODEL_INTERRUPT is selected:
59  - If CPAL_DIRECTION_TX is selected only TX DMA Channel or TX Interrupt is configured
60  - If CPAL_DIRECTION_RX is selected only RX DMA Channel or RX Interrupt is configured
61  - If CPAL_DIRECTION_TXRX is selected both TX and Rx DMA Channels or Interrupts are configured.*/
62 
63 typedef enum
64 {
72 
73 
74 /*========= CPAL_Mode_TypeDef =========*/
75 /* CPAL device Mode enumeration is used to select in which mode the
76  device will proceed : in master mode or slave mode.
77  When an I2C device is used in master mode, it will initiate communication
78  by sending start bit. When it is used in slave mode, it will wait till
79  receiving its own address to start communication.*/
80 
81 typedef enum
82 {
88 
89 
90 /*========= CPAL_ProgModel_TypeDef =========*/
91 /* CPAL Programming Models enumeration is used to define the programming
92  model of device communication.
93  - CPAL_PROGMODEL_DMA : device is programmed to communicate using DMA.
94  - CPAL_PROGMODEL_INTERRUPT : device is programmed to communicate using
95  interruption ( TXE , RXNE ...) handlers.
96  - CPAL_PROGMODEL_POLLING : device is programmed to communicate using
97  application polling routines (interrupts and DMA will not be used).*/
98 
99 typedef enum
100 {
106 
107 
108 /*========= CPAL_Transfer_TypeDef =========*/
109 /* CPAL Transfer structure contains all transfer parameters which are used
110  in every Read or Write operation.*/
111 
112 typedef struct
113 {
114  uint8_t* pbBuffer;
116  __IO uint32_t wNumData;
118  uint32_t wAddr1;
120  uint32_t wAddr2;
123 
124 
125 /*========= CPAL_State_TypeDef =========*/
126 /* CPAL global State enumeration contains the current state of CPAL communication.
127  Before starting each operation this state is tested. After each operation
128  CPAL_State is updated with the new value resulting from the relative operation.*/
129 
130 typedef enum
131 {
158 
159 /*========= CPAL_I2CError_TypeDef =========*/
160 /* I2C Errors TypeDef */
161 
162 typedef enum
163 {
164  CPAL_I2C_ERR_NONE = 0x00000000,
166  CPAL_I2C_ERR_TIMEOUT = 0x000000FF,
169  CPAL_I2C_ERR_BERR = 0x00000100,
178  CPAL_I2C_ERR_ARLO = 0x00000200,
189  CPAL_I2C_ERR_AF = 0x00000010,
194  CPAL_I2C_ERR_OVR = 0x00000400,
205 
206 
207 /*========= CPAL_Dev_TypeDef =========*/
208 /* CPAL Device structure definition */
209 
210 typedef struct
211 {
212  CPAL_DevTypeDef CPAL_Dev;
215  CPAL_DirectionTypeDef CPAL_Direction;
218  CPAL_ModeTypeDef CPAL_Mode;
221  CPAL_ProgModelTypeDef CPAL_ProgModel;
224  CPAL_TransferTypeDef* pCPAL_TransferTx;
229  CPAL_TransferTypeDef* pCPAL_TransferRx;
234  __IO CPAL_StateTypeDef CPAL_State;
238  __IO uint32_t wCPAL_DevError;
242  uint32_t wCPAL_Options;
247  __IO uint32_t wCPAL_Timeout;
249  I2C_InitTypeDef* pCPAL_I2C_Struct;
262 
263 
264 /*========= Table containing all I2C device structures =========*/
265 extern CPAL_InitTypeDef* I2C_DevStructures[];
266 
267 
268 /*========= CPAL_Global_Device_Structures =========*/
269 /* CPAL Global Device Structures are the Global default structures which
270  are used to handle devices configuration and status.*/
271 
272 #ifdef CPAL_USE_I2C1
273 extern CPAL_InitTypeDef I2C1_DevStructure;
274 #endif /* CPAL_USE_I2C1 */
275 
276 #ifdef CPAL_USE_I2C2
277 extern CPAL_InitTypeDef I2C2_DevStructure;
278 #endif /* CPAL_USE_I2C2 */
279 
280 /* Exported constants --------------------------------------------------------*/
281 
282 /*========= CPAL_Options_TypeDef =========*/
283 /* CPAL Options defines contains configuration options which can be affected
284  to wCPAL_Options which is a bit-field argument so any combination of these
285  parameters can be selected. If one option is not selected then the relative
286  feature is disabled.
287  There are common options and device specific options.*/
288 
289 #define CPAL_OPT_I2C_DUALADDR ((uint32_t)0x00000001)
293 #define CPAL_OPT_DMATX_TCIT ((uint32_t)0x00000100)
295 #define CPAL_OPT_DMATX_HTIT ((uint32_t)0x00000200)
297 #define CPAL_OPT_DMATX_TEIT ((uint32_t)0x00000400)
299 #define CPAL_OPT_DMARX_TCIT ((uint32_t)0x00000800)
301 #define CPAL_OPT_DMARX_HTIT ((uint32_t)0x00001000)
303 #define CPAL_OPT_DMARX_TEIT ((uint32_t)0x00002000)
305 #define CPAL_OPT_DMATX_CIRCULAR ((uint32_t)0x00004000)
307 #define CPAL_OPT_DMARX_CIRCULAR ((uint32_t)0x00008000)
309 #define CPAL_OPT_NO_MEM_ADDR ((uint32_t)0x00010000)
312 #define CPAL_OPT_16BIT_REG ((uint32_t)0x00020000)
316 #define CPAL_OPT_I2C_GENCALL ((uint32_t)0x00100000)
319 #define CPAL_OPT_I2C_AUTOMATIC_END ((uint32_t)0x00200000)
321 #define CPAL_OPT_I2C_ERRIT_DISABLE ((uint32_t)0x00400000)
325 #define CPAL_OPT_I2C_NOSTOP ((uint32_t)0x00800000)
328 #define CPAL_OPT_I2C_NOSTOP_MODE ((uint32_t)0x01000000)
331 #define CPAL_OPT_I2C_OA2_MASK ((uint32_t)0x0E000000)
333 #define CPAL_OPT_I2C_10BIT_HEADR ((uint32_t)0x10000000)
336 #define CPAL_OPT_I2C_WAKEUP_STOP ((uint32_t)0x20000000)
338 #define CPAL_OPT_I2C_NACK_ADD ((uint32_t)0x40000000)
341 /*========= CPAL_Interne_Defines =========*/
342 
343 #define CPAL_PASS ((uint32_t)0x00000000)
345 #define CPAL_FAIL ((uint32_t)0x00000001)
347 #define pNULL (void*)0
349 /* Exported macro ------------------------------------------------------------*/
350 
351 /* Exported functions --------------------------------------------------------*/
352 
353 
354 /*========= CPAL_I2C_Exported_Functions =========*/
355 /* These functions constitute the main CPAL API interface. All functions take as argument the
356  CPAL_InitTypeDef structure defined in @ref CPAL_Dev_TypeDef. */
358 uint32_t CPAL_I2C_Init (CPAL_InitTypeDef* pDevInitStruct); /*<!This function Initializes the selected I2C device
359  and all needed resources (GPIOs, clocks, DMA,
360  interrupts …)*/
361 
362 uint32_t CPAL_I2C_DeInit (CPAL_InitTypeDef* pDevInitStruct); /*<!This function free the resources used by the I2C
363  device (GPIOs, clocks, DMA, interrupts …) and
364  deinitialize the device itself */
365 
366 uint32_t CPAL_I2C_StructInit (CPAL_InitTypeDef* pDevInitStruct); /*<!This function Initializes I2C device structure
367  by filling all fields with their default values.
368  Warning: Pointer fields are filled with CPAL local variables
369  pointer. To avoid all risks, it is recommended to declare
370  application local variables and fill these fields with their
371  pointers.*/
372 
373 uint32_t CPAL_I2C_Write (CPAL_InitTypeDef* pDevInitStruct); /*<!This function Writes data to the specified I2C device.
374  All information relative to the write transfer parameters and
375  current status are extracted from pCPAL_TransferTx field defined
376  in @ref CPAL_Transfer_TypeDef */
377 
378 uint32_t CPAL_I2C_Read (CPAL_InitTypeDef* pDevInitStruct); /*<!This function Read data from the specified I2C device
379  All information relative to the read transfer parameters and
380  current status are extracted from pCPAL_TransferTx field defined
381  in @ref CPAL_Transfer_TypeDef */
382 
383 uint32_t CPAL_I2C_IsDeviceReady(CPAL_InitTypeDef* pDevInitStruct); /*<!This function can be used to wait until target device is ready
384  for communication (ie. for memories after write operations) */
385 
386 
387 uint32_t CPAL_I2C_EV_IRQHandler(CPAL_InitTypeDef* pDevInitStruct); /*<!This function manages all I2C device events */
388 
389 uint32_t CPAL_I2C_ER_IRQHandler(CPAL_InitTypeDef* pDevInitStruct); /*<!This function manages all I2C device errors */
390 
391 #ifdef CPAL_I2C_DMA_PROGMODEL
392 uint32_t CPAL_I2C_DMA_TX_IRQHandler(CPAL_InitTypeDef* pDevInitStruct); /*<!This function Handles DMA TX Interrupts */
393 
394 uint32_t CPAL_I2C_DMA_RX_IRQHandler(CPAL_InitTypeDef* pDevInitStruct); /*<!This function Handles DMA RX Interrupts */
395 #endif /* CPAL_I2C_DMA_PROGMODEL */
396 
397 
398 /*========== CPAL_TIMEOUT_Callback ==========*/
399 
400 #ifndef CPAL_TIMEOUT_UserCallback
401  uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when a Timeout
402  occurs during communication with devices */
403 #endif
404 
405 /*========= CPAL_I2C_User_Callbacks =========*/
406 /* These functions prototypes only are declared here. User can (optionally)
407  implement the function body in his own application depending on the application needs.
408  Each callback is called in a particular situation detailed in the callback description.*/
409 
410 #ifndef CPAL_I2C_TX_UserCallback
411 void CPAL_I2C_TX_UserCallback (CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in Interrupt mode)
412  the peripheral is preparing to send data */
413 #endif
414 
415 #ifndef CPAL_I2C_RX_UserCallback
416 void CPAL_I2C_RX_UserCallback (CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in Interrupt mode)
417  the peripheral has received data */
418 #endif
419 
420 #ifndef CPAL_I2C_TXTC_UserCallback
421 void CPAL_I2C_TXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA or Interrupt mode)
422  TX Transfer is complete (to use in DMA mode, Transfer complete
423  interrupt must be enabled) */
424 #endif
425 
426 #ifndef CPAL_I2C_RXTC_UserCallback
427 void CPAL_I2C_RXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA or Interrupt mode)
428  RX Transfer is complete (to use in DMA mode, Transfer complete
429  interrupt must be enabled) */
430 #endif
431 
432 #ifndef CPAL_I2C_DMATXTC_UserCallback
433 void CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called (in DMA mode) when
434  DMA Transmission is finished (If Transfer Complete
435  interrupt is enabled) */
436 #endif
437 
438 #ifndef CPAL_I2C_DMATXHT_UserCallback
439 void CPAL_I2C_DMATXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called (in DMA mode) when the
440  DMA Transmission has reached the half of the
441  buffer (If Half Transfer interrupt is enabled) */
442 #endif
443 
444 #ifndef CPAL_I2C_DMATXTE_UserCallback
445 void CPAL_I2C_DMATXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA mode) a
446  DMA Transmission transfer error has occurred
447  (If Transfer Error interrupt is enabled ) */
448 #endif
449 
450 #ifndef CPAL_I2C_DMARXTC_UserCallback
451 void CPAL_I2C_DMARXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA mode) when
452  DMA Reception is finished (If Transfer Complete
453  interrupt is enabled) */
454 #endif
455 
456 #ifndef CPAL_I2C_DMARXHT_UserCallback
457 void CPAL_I2C_DMARXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA mode) the
458  DMA Reception has reached the half of the
459  buffer (If Half Transfer interrupt is enabled) */
460 #endif
461 
462 #ifndef CPAL_I2C_DMARXTE_UserCallback
463 void CPAL_I2C_DMARXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when (in DMA mode) a
464  DMA Reception transfer error has occurred
465  (If Transfer Error interrupt is enabled ) */
466 #endif
467 
468 #ifndef CPAL_I2C_GENCALL_UserCallback
469 void CPAL_I2C_GENCALL_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when General Call mode
470  is set (used in General Call Mode only ) */
471 #endif
472 
473 #ifndef CPAL_I2C_DUALF_UserCallback
474 void CPAL_I2C_DUALF_UserCallback(CPAL_InitTypeDef* pDevInitStruct); /*<!This function is called when Slave OA2 Address
475  matched (used in Dual Address Mode only ) */
476 #endif
477 
478 /*========= CPAL_User_ErrorCallback_Prototypes =========*/
479 /* User can use two types of Callback:
480  - Single Error Callback : All error are handled by one Callback (CPAL_I2C_ERR_UserCallback()).
481  - Multiple Error Callback : Each error has its own Callback ( CPAL_I2C_ERRTYPE_UserCallback () ,
482  ERRTYPE : can be one of I2C Errors (BERR, ARLO, OVR and NACK)).
483  To select one of this type, user should comment or uncomment adequate defines in stm32f0xx_i2c_cpal_conf.h file. */
484 
485 #ifdef USE_SINGLE_ERROR_CALLBACK
486 
487  #ifndef CPAL_I2C_ERR_UserCallback
488  void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError); /*<!This callback is called when an error
489  occurred on the peripheral while transferring
490  (If I2C Error interrupt is enabled). Device
491  instance and error type (DeviceError) are
492  passed as argument. Device_Error value can be
493  one of CPAL_I2CErrorTypeDef enumeration */
494  #endif
495 #endif /* USE_SINGLE_ERROR_CALLBACK */
496 
497 #ifdef USE_MULTIPLE_ERROR_CALLBACK
498 
499  #ifndef CPAL_I2C_BERR_UserCallback
500  void CPAL_I2C_BERR_UserCallback(CPAL_DevTypeDef pDevInstance); /*<!This callback is called when an Bus ERROR
501  occurred on the peripheral while transferring
502  (If I2C Error interrupt is enabled) */
503  #endif
504 
505  #ifndef CPAL_I2C_ARLO_UserCallback
506  void CPAL_I2C_ARLO_UserCallback(CPAL_DevTypeDef pDevInstance); /*<!This callback is called when an Arbitration Lost
507  ERROR occurred on the peripheral while transferring
508  (If I2C Error interrupt is enabled) */
509  #endif
510 
511  #ifndef CPAL_I2C_OVR_UserCallback
512  void CPAL_I2C_OVR_UserCallback(CPAL_DevTypeDef pDevInstance); /*<!This callback is called when an Overrun/Underrun
513  ERROR occurred on the peripheral while transferring
514  (If I2C Error interrupt is enabled) */
515  #endif
516 
517  #ifndef CPAL_I2C_AF_UserCallback
518  void CPAL_I2C_AF_UserCallback(CPAL_DevTypeDef pDevInstance); /*<!This callback is called when an Not Acknowledge
519  is received (If I2C NACK interrupt is enabled) */
520  #endif
521 
522 #endif /* USE_SINGLE_ERROR_CALLBACK */
523 
524 
525 
526 #ifdef __cplusplus
527 }
528 #endif
529 
530 #endif /*__STM32F0XX_I2C_CPAL_H */
531 
532 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/