I2C Slave Library  v0.90
Emulate one ore more I2C slave devices, each from their own Propeller processor (cog).
i2cslave.h
Go to the documentation of this file.
1 
15 #include "simpletools.h"
16 
17 #ifndef __I2CSLAVE_H
18 #define __I2CSLAVE_H
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 
27 typedef struct i2cslave_struct
28 {
29  volatile int flags;
30  volatile char address;
31  volatile char pinSCL;
32  volatile char pinSDA;
33  char registers[32];
34  volatile char cog;
35 } i2cslave_t;
36 
37 typedef i2cslave_t i2cslave;
38 
39 #endif // DOXYGEN_SHOULD_SKIP_THIS
40 
41 
54 i2cslave_t *i2cslave_open(int pin_clock, int pin_data, int address);
55 
56 
63 void i2cslave_close(i2cslave_t *device);
64 
65 
73 char *i2cslave_regAddr(i2cslave_t *device);
74 
75 
86 int i2cslave_checkForRegChange(i2cslave_t *device);
87 
88 
98 int i2cslave_checkReg(i2cslave_t *device, int index);
99 
100 
109 int i2cslave_checkFlags(i2cslave_t *device);
110 
111 
122 int i2cslave_checkFlag(i2cslave_t *device, int index);
123 
131 void i2cslave_clearFlag(i2cslave_t *device, int index);
132 
133 
143 char i2cslave_getReg(i2cslave_t *device, int index);
144 
145 
155 void i2cslave_putReg(i2cslave_t *device, int index, int value);
156 
157 
163 void i2cslave_flush(i2cslave_t *device);
164 
165 
172 int bitwiseEncode(int i);
173 
174 
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 /* __cplusplus */
180 #endif
181 /* __I2CSLAVE_H */
182 
183 
void i2cslave_clearFlag(i2cslave_t *device, int index)
Clear a certain register's flag.
Definition: i2cslave.c:81
int i2cslave_checkFlags(i2cslave_t *device)
Check the flags register. Bits 31 to 0 indicate if data has changed in registers 31 to 0...
Definition: i2cslave.c:69
char i2cslave_getReg(i2cslave_t *device, int index)
Get the value stored by a certain register.
Definition: i2cslave.c:87
char * i2cslave_regAddr(i2cslave_t *device)
Provides a pointer to the first of the I2C slave device's 32 byte registers. Applications can use thi...
Definition: i2cslave.c:40
void i2cslave_flush(i2cslave_t *device)
Clear all register values and flags.
Definition: i2cslave.c:101
int i2cslave_checkForRegChange(i2cslave_t *device)
Check if any registers have changed. If a register has changed, return its number. If more than one register has changed, return the highest address that has changed. If no registers have changed, return -1.
Definition: i2cslave.c:46
int i2cslave_checkReg(i2cslave_t *device, int index)
Get the register value if it has changed.
Definition: i2cslave.c:54
int bitwiseEncode(int i)
Find out the highest bit with a 1 in a 32 bit register.
Definition: i2cslave.c:108
i2cslave_t * i2cslave_open(int pin_clock, int pin_data, int address)
Start an I2C slave processor in a new cog.
Definition: i2cslave.c:12
int i2cslave_checkFlag(i2cslave_t *device, int index)
Check a certain register's flag.
Definition: i2cslave.c:75
void i2cslave_close(i2cslave_t *device)
Stop the I2C slave processor and make cog and memory resources available for other uses...
Definition: i2cslave.c:29
void i2cslave_putReg(i2cslave_t *device, int index, int value)
Set the value of a register.
Definition: i2cslave.c:95