1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/****************************************************************************
*
* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
****************************************************************************/
/**
*
* @file i2c-io.h
*
* @brief This file defines the interface to the i2c-io program which
* runs on the robostix.
*
*****************************************************************************/
#if !defined( I2C_IO_H )
#define I2C_IO_H /**< Include Guard */
/* ---- Include Files ---------------------------------------------------- */
/* ---- Constants and Types ---------------------------------------------- */
//---------------------------------------------------------------------------
/**
* Defines the version of this API. This includes the layout of the
* various structures, along with the semantics associated with the
* protocol. Any changes require the version number to be incremented.
*
* Version 2 - Introduced READ/WRITE_REG_8/16
*/
#define I2C_IO_API_VERSION 2
//---------------------------------------------------------------------------
/**
* The min version, determines the minimum version that this API is
* compatable with. This allows old host side programs to determine
* that they're not compatible.
*/
#define I2C_IO_API_MIN_VERSION 1
//---------------------------------------------------------------------------
/**
* The I2C_IO_GET_INFO command retrieves information about the i2c-io
* program running on the robostix.
*/
#define I2C_IO_GET_INFO 0x01
typedef struct
{
uint8_t version;
uint8_t minVersion;
uint16_t svnRevision;
} I2C_IO_Info_t;
//---------------------------------------------------------------------------
/**
* The I2C_IO_GET_GPIO command retrieves the values of the pins indicated
* by portNum.
*
* The portNum is set such that 0 = A, 1 = B, etc.
*
* A block-reply with a single 8 bit value is returned.
*/
typedef struct
{
uint8_t portNum;
} I2C_IO_Get_GPIO_t;
#define I2C_IO_GET_GPIO 0x02
//---------------------------------------------------------------------------
/**
* The I2C_IO_SET_GPIO command sets the values of the pins specified
* by pinMask to the correponding bits in ponVal.
*
* Note: Setting a pin that's configured for input will enable a pullup
* resistor.
*
* The portNum is set such that 0 = A, 1 = B, etc.
*/
typedef struct
{
uint8_t portNum;
uint8_t pinMask;
uint8_t pinVal;
} I2C_IO_Set_GPIO_t;
#define I2C_IO_SET_GPIO 0x03
//---------------------------------------------------------------------------
/**
* The I2C_IO_GET_GPIO_DIR command retrieves the data direction
* register (DDR) for the indicated portNum.
*
* The I2C_IO_Get_GPIO_t structure is used for this command.
*
* Note: It's ok to read the values of pins which are set for output.
*
* The portNum is set such that 0 = A, 1 = B, etc.
*
* A block-reply with a single 8 bit value is returned.
* A 1 bit means that the pin is set for output and a 0 bit means that
* the pin is set for input.
*/
#define I2C_IO_GET_GPIO_DIR 0x04
//---------------------------------------------------------------------------
/**
* The I2C_IO_SET_GPIO_DIR command sets the data direction
* register (DDR) for the indicated portNum.
*
* The I2C_IO_Set_GPIO_t structure is used for this command.
*
* The portNum is set such that 0 = A, 1 = B, etc.
*/
#define I2C_IO_SET_GPIO_DIR 0x05
//---------------------------------------------------------------------------
/**
* The I2C_IO_GET_ADC command performs an ADC sample and returns the result.
*
* mux values 0 thru 7 read singled ended ADC values. Values 8 thru 31
* return a variety of values. See the data sheet for specifics.
*
* A block-reply with a 16 bit value is returned, although only the
* lower 10 bits are significant.
*/
typedef struct
{
uint8_t mux;
} I2C_IO_Get_ADC_t;
#define I2C_IO_GET_ADC 0x06
//---------------------------------------------------------------------------
/**
* The I2C_IO_READ_REG_8 command reads a 8-bit register.
*
* A block reply with an 8 bit value is returned.
*/
typedef struct
{
uint8_t reg; ///< Index of the register to be read.
} I2C_IO_ReadReg8_t;
#define I2C_IO_READ_REG_8 0x07
//---------------------------------------------------------------------------
/**
* The I2C_IO_READ_REG_16 command reads a 16-bit register.
*
* A block reply with a 16 bit value is returned.
*/
typedef struct
{
uint8_t reg; ///< Index of the register to be read.
} I2C_IO_ReadReg16_t;
#define I2C_IO_READ_REG_16 0x08
//---------------------------------------------------------------------------
/**
* The I2C_IO_WRITE_REG_8 command writes an 8-bit register.
*/
typedef struct
{
uint8_t reg; ///< Index of the register to be read.
uint8_t val; ///< Value to write into the register
} I2C_IO_WriteReg8_t;
#define I2C_IO_WRITE_REG_8 0x09
//---------------------------------------------------------------------------
/**
* The I2C_IO_WRITE_REG_16 command writes a 16-bit register.
*/
typedef struct
{
uint8_t reg; ///< Index of the register to be read.
uint8_t pad; ///< Pad for alignment on the host.
uint16_t val; ///< Value to write
} I2C_IO_WriteReg16_t;
#define I2C_IO_WRITE_REG_16 0x0A
/* ---- Variable Externs ------------------------------------------------- */
/* ---- Function Prototypes ---------------------------------------------- */
#endif /* I2C_IO_H */
|