Subversion Repositories NaviCtrl

Rev

Rev 196 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
196 killagreg 1
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
1 ingob 2
* File Name          : 91x_i2c.h
3
* Author             : MCD Application Team
196 killagreg 4
* Version            : V2.1
5
* Date               : 12/22/2008
1 ingob 6
* Description        : This file contains all the functions prototypes for the
196 killagreg 7
*                      I2C firmware library.
1 ingob 8
********************************************************************************
9
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15
*******************************************************************************/
16
 
17
/* Define to prevent recursive inclusion ------------------------------------ */
18
#ifndef __91x_I2C_H
19
#define __91x_I2C_H
20
 
21
/* Includes ----------------------------------------------------------------- */
22
#include "91x_map.h"
23
 
24
/* Exported types ----------------------------------------------------------- */
25
/* I2C Init structure definition */
26
typedef struct
27
{
28
   u32 I2C_CLKSpeed;
29
   u16 I2C_OwnAddress;
30
   u8  I2C_GeneralCall;
31
   u8  I2C_Ack;
32
}I2C_InitTypeDef;
33
 
34
/* Exported constants --------------------------------------------------------*/
35
#define  I2C_GeneralCall_Enable      0x10
36
#define  I2C_GeneralCall_Disable     0xEF
37
/* Acknowledgement */
38
#define  I2C_Ack_Enable      0x04
39
#define  I2C_Ack_Disable     0xFB
40
 
41
/* I2C Flags */
42
#define  I2C_FLAG_SB      0x0001
43
#define  I2C_FLAG_M_SL    0x0002
44
#define  I2C_FLAG_ADSL    0x0004
45
#define  I2C_FLAG_BTF     0x0008
46
#define  I2C_FLAG_BUSY    0x0010
47
#define  I2C_FLAG_TRA     0x0020
48
#define  I2C_FLAG_ADD10   0x0040
49
#define  I2C_FLAG_EVF     0x0080
50
#define  I2C_FLAG_GCAL    0x0100
51
#define  I2C_FLAG_BERR    0x0200
52
#define  I2C_FLAG_ARLO    0x0400
53
#define  I2C_FLAG_STOPF   0x0800
54
#define  I2C_FLAG_AF      0x1000
55
#define  I2C_FLAG_ENDAD   0x2000
56
#define  I2C_FLAG_ACK     0x4000
57
 
58
/* I2C Events */
59
#define  I2C_EVENT_SLAVE_ADDRESS_MATCHED   ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_ADSL)
60
#define  I2C_EVENT_SLAVE_BYTE_RECEIVED     ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_BTF )
61
#define  I2C_EVENT_SLAVE_BYTE_TRANSMITTED  ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_BTF  | I2C_FLAG_TRA )
62
#define  I2C_EVENT_MASTER_MODE_SELECT      ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_M_SL | I2C_FLAG_SB )
63
#define  I2C_EVENT_MASTER_MODE_SELECTED    ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_M_SL | I2C_FLAG_ENDAD )
64
#define  I2C_EVENT_MASTER_BYTE_RECEIVED    ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_M_SL | I2C_FLAG_BTF )
65
#define  I2C_EVENT_MASTER_BYTE_TRANSMITTED ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_M_SL | I2C_FLAG_BTF | I2C_FLAG_TRA )
66
#define  I2C_EVENT_MASTER_MODE_ADDRESS10   ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_M_SL |I2C_FLAG_ADD10 )
67
#define  I2C_EVENT_SLAVE_STOP_DETECTED     ( I2C_FLAG_EVF | I2C_FLAG_STOPF )
68
#define  I2C_EV31                          ( I2C_FLAG_EVF | I2C_FLAG_BUSY | I2C_FLAG_BTF  | I2C_FLAG_TRA | I2C_FLAG_AF)
69
#define  I2C_EVENT_SLAVE_ACK_FAILURE       (  I2C_FLAG_EVF | I2C_FLAG_BUSY |I2C_FLAG_AF)
70
#define  I2C_EVENT_ALL                     (  I2C_FLAG_EVF | I2C_FLAG_BUSY |I2C_FLAG_AF |I2C_FLAG_BTF)
71
#define  I2C_BUS_ERROR_DETECTED       I2C_FLAG_BERR
72
#define  I2C_ARBITRATION_LOST         I2C_FLAG_ARLO
73
#define  I2C_SLAVE_GENERAL_CALL       (I2C_FLAG_BUSY | I2C_FLAG_GCAL)
74
 
75
/* Master/Receiver Mode */
76
#define  I2C_MODE_TRANSMITTER          0x00
77
#define  I2C_MODE_RECEIVER             0x01
78
 
79
/* I2C Registers offset */
80
#define  I2C_CR     0x00
81
#define  I2C_SR1    0x04
82
#define  I2C_SR2    0x08
83
#define  I2C_CCR    0x0C
84
#define  I2C_OAR1   0x10
85
#define  I2C_OAR2   0x14
86
#define  I2C_DR     0x18
87
#define  I2C_ECCR   0x1C
88
 
89
/* Exported macro ------------------------------------------------------------*/
90
/* Exported functions ------------------------------------------------------- */
91
void I2C_DeInit(I2C_TypeDef* I2Cx);
92
void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
93
void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
94
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
95
void I2C_GenerateStart(I2C_TypeDef* I2Cx, FunctionalState NewState);
96
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
97
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState);
98
void I2C_ITConfig(I2C_TypeDef *I2Cx, FunctionalState NewState);
99
void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, u8 Address, u8 Direction);
100
u8 I2C_ReadRegister(I2C_TypeDef* I2Cx, u8 I2C_Register);
101
FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, u16 I2C_FLAG);
102
void I2C_ClearFlag(I2C_TypeDef* I2Cx, u16 I2C_FLAG, ...);
103
void I2C_SendData(I2C_TypeDef* I2Cx, u8 bData);
104
u8 I2C_ReceiveData(I2C_TypeDef* I2Cx);
105
u16 I2C_GetLastEvent(I2C_TypeDef* I2Cx);
106
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx,u16 I2C_Event);
107
 
108
#endif /* __91x_I2C_H */
109
 
196 killagreg 110
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/