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