1 |
610 |
jeremybenn |
//*****************************************************************************
|
2 |
|
|
//
|
3 |
|
|
// i2c.h - Prototypes for the I2C Driver.
|
4 |
|
|
//
|
5 |
|
|
// Copyright (c) 2005-2008 Luminary Micro, Inc. All rights reserved.
|
6 |
|
|
//
|
7 |
|
|
// Software License Agreement
|
8 |
|
|
//
|
9 |
|
|
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
|
10 |
|
|
// exclusively on LMI's microcontroller products.
|
11 |
|
|
//
|
12 |
|
|
// The software is owned by LMI and/or its suppliers, and is protected under
|
13 |
|
|
// applicable copyright laws. All rights are reserved. You may not combine
|
14 |
|
|
// this software with "viral" open-source software in order to form a larger
|
15 |
|
|
// program. Any use in violation of the foregoing restrictions may subject
|
16 |
|
|
// the user to criminal sanctions under applicable laws, as well as to civil
|
17 |
|
|
// liability for the breach of the terms and conditions of this license.
|
18 |
|
|
//
|
19 |
|
|
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
20 |
|
|
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
21 |
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
22 |
|
|
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
23 |
|
|
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
24 |
|
|
//
|
25 |
|
|
// This is part of revision 2523 of the Stellaris Peripheral Driver Library.
|
26 |
|
|
//
|
27 |
|
|
//*****************************************************************************
|
28 |
|
|
|
29 |
|
|
#ifndef __I2C_H__
|
30 |
|
|
#define __I2C_H__
|
31 |
|
|
|
32 |
|
|
//*****************************************************************************
|
33 |
|
|
//
|
34 |
|
|
// If building with a C++ compiler, make all of the definitions in this header
|
35 |
|
|
// have a C binding.
|
36 |
|
|
//
|
37 |
|
|
//*****************************************************************************
|
38 |
|
|
#ifdef __cplusplus
|
39 |
|
|
extern "C"
|
40 |
|
|
{
|
41 |
|
|
#endif
|
42 |
|
|
|
43 |
|
|
//*****************************************************************************
|
44 |
|
|
//
|
45 |
|
|
// Defines for the API.
|
46 |
|
|
//
|
47 |
|
|
//*****************************************************************************
|
48 |
|
|
|
49 |
|
|
//*****************************************************************************
|
50 |
|
|
//
|
51 |
|
|
// Interrupt defines.
|
52 |
|
|
//
|
53 |
|
|
//*****************************************************************************
|
54 |
|
|
#define I2C_INT_MASTER 0x00000001
|
55 |
|
|
#define I2C_INT_SLAVE 0x00000002
|
56 |
|
|
|
57 |
|
|
//*****************************************************************************
|
58 |
|
|
//
|
59 |
|
|
// I2C Master commands.
|
60 |
|
|
//
|
61 |
|
|
//*****************************************************************************
|
62 |
|
|
#define I2C_MASTER_CMD_SINGLE_SEND 0x00000007
|
63 |
|
|
#define I2C_MASTER_CMD_SINGLE_RECEIVE 0x00000007
|
64 |
|
|
#define I2C_MASTER_CMD_BURST_SEND_START 0x00000003
|
65 |
|
|
#define I2C_MASTER_CMD_BURST_SEND_CONT 0x00000001
|
66 |
|
|
#define I2C_MASTER_CMD_BURST_SEND_FINISH 0x00000005
|
67 |
|
|
#define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP 0x00000004
|
68 |
|
|
#define I2C_MASTER_CMD_BURST_RECEIVE_START 0x0000000b
|
69 |
|
|
#define I2C_MASTER_CMD_BURST_RECEIVE_CONT 0x00000009
|
70 |
|
|
#define I2C_MASTER_CMD_BURST_RECEIVE_FINISH 0x00000005
|
71 |
|
|
#define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP 0x00000005
|
72 |
|
|
|
73 |
|
|
//*****************************************************************************
|
74 |
|
|
//
|
75 |
|
|
// I2C Master error status.
|
76 |
|
|
//
|
77 |
|
|
//*****************************************************************************
|
78 |
|
|
#define I2C_MASTER_ERR_NONE 0
|
79 |
|
|
#define I2C_MASTER_ERR_ADDR_ACK 0x00000004
|
80 |
|
|
#define I2C_MASTER_ERR_DATA_ACK 0x00000008
|
81 |
|
|
#define I2C_MASTER_ERR_ARB_LOST 0x00000010
|
82 |
|
|
|
83 |
|
|
//*****************************************************************************
|
84 |
|
|
//
|
85 |
|
|
// I2C Slave action requests
|
86 |
|
|
//
|
87 |
|
|
//*****************************************************************************
|
88 |
|
|
#define I2C_SLAVE_ACT_NONE 0
|
89 |
|
|
#define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
|
90 |
|
|
#define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
|
91 |
|
|
#define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
|
92 |
|
|
|
93 |
|
|
//*****************************************************************************
|
94 |
|
|
//
|
95 |
|
|
// Miscellaneous I2C driver definitions.
|
96 |
|
|
//
|
97 |
|
|
//*****************************************************************************
|
98 |
|
|
#define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
|
99 |
|
|
|
100 |
|
|
//*****************************************************************************
|
101 |
|
|
//
|
102 |
|
|
// Prototypes for the APIs.
|
103 |
|
|
//
|
104 |
|
|
//*****************************************************************************
|
105 |
|
|
extern void I2CIntRegister(unsigned long ulBase, void(fnHandler)(void));
|
106 |
|
|
extern void I2CIntUnregister(unsigned long ulBase);
|
107 |
|
|
extern tBoolean I2CMasterBusBusy(unsigned long ulBase);
|
108 |
|
|
extern tBoolean I2CMasterBusy(unsigned long ulBase);
|
109 |
|
|
extern void I2CMasterControl(unsigned long ulBase, unsigned long ulCmd);
|
110 |
|
|
extern unsigned long I2CMasterDataGet(unsigned long ulBase);
|
111 |
|
|
extern void I2CMasterDataPut(unsigned long ulBase, unsigned char ucData);
|
112 |
|
|
extern void I2CMasterDisable(unsigned long ulBase);
|
113 |
|
|
extern void I2CMasterEnable(unsigned long ulBase);
|
114 |
|
|
extern unsigned long I2CMasterErr(unsigned long ulBase);
|
115 |
|
|
extern void I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk,
|
116 |
|
|
tBoolean bFast);
|
117 |
|
|
extern void I2CMasterIntClear(unsigned long ulBase);
|
118 |
|
|
extern void I2CMasterIntDisable(unsigned long ulBase);
|
119 |
|
|
extern void I2CMasterIntEnable(unsigned long ulBase);
|
120 |
|
|
extern tBoolean I2CMasterIntStatus(unsigned long ulBase, tBoolean bMasked);
|
121 |
|
|
extern void I2CMasterSlaveAddrSet(unsigned long ulBase,
|
122 |
|
|
unsigned char ucSlaveAddr,
|
123 |
|
|
tBoolean bReceive);
|
124 |
|
|
extern unsigned long I2CSlaveDataGet(unsigned long ulBase);
|
125 |
|
|
extern void I2CSlaveDataPut(unsigned long ulBase, unsigned char ucData);
|
126 |
|
|
extern void I2CSlaveDisable(unsigned long ulBase);
|
127 |
|
|
extern void I2CSlaveEnable(unsigned long ulBase);
|
128 |
|
|
extern void I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr);
|
129 |
|
|
extern void I2CSlaveIntClear(unsigned long ulBase);
|
130 |
|
|
extern void I2CSlaveIntDisable(unsigned long ulBase);
|
131 |
|
|
extern void I2CSlaveIntEnable(unsigned long ulBase);
|
132 |
|
|
extern tBoolean I2CSlaveIntStatus(unsigned long ulBase, tBoolean bMasked);
|
133 |
|
|
extern unsigned long I2CSlaveStatus(unsigned long ulBase);
|
134 |
|
|
|
135 |
|
|
//*****************************************************************************
|
136 |
|
|
//
|
137 |
|
|
// Several I2C APIs have been renamed, with the original function name being
|
138 |
|
|
// deprecated. These defines provide backward compatibility.
|
139 |
|
|
//
|
140 |
|
|
//*****************************************************************************
|
141 |
|
|
#ifndef DEPRECATED
|
142 |
|
|
#include "sysctl.h"
|
143 |
|
|
#define I2CMasterInit(a, b) \
|
144 |
|
|
I2CMasterInitExpClk(a, SysCtlClockGet(), b)
|
145 |
|
|
#endif
|
146 |
|
|
|
147 |
|
|
//*****************************************************************************
|
148 |
|
|
//
|
149 |
|
|
// Mark the end of the C bindings section for C++ compilers.
|
150 |
|
|
//
|
151 |
|
|
//*****************************************************************************
|
152 |
|
|
#ifdef __cplusplus
|
153 |
|
|
}
|
154 |
|
|
#endif
|
155 |
|
|
|
156 |
|
|
#endif // __I2C_H__
|