Subversion Repositories group.electronics

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
117 pfowler 1
#ifndef wire_h
2
#define wire_h
3
 
4
#define	MAX_BUFFER	4
5
 
6
void i2c_master(void);
7
void i2c_slave(uint8_t address);
8
void i2c_beginTransmission(uint8_t address);
9
uint8_t i2c_endTransmission(uint8_t sentStop);
10
uint8_t i2c_writeByte(uint8_t data);
11
uint8_t i2c_writeBytes(uint8_t *data, uint8_t bytes);
12
void i2c_onReceiveService(uint8_t* inBytes, int numBytes);
13
void i2c_onRequestService(void);
14
void i2c_onReceive( void(*function)(uint8_t));
15
void i2c_onRequest( void(*function)(void));
16
 
17
 
18
struct {
19
	uint8_t rxBuffer[MAX_BUFFER];
20
 
21
	// Save 8 bytes. Maximum buffer size is 15
22
	union {
23
		uint8_t rxMeta;
24
		struct {
25
			uint8_t rxBufferIndex:4;
26
			uint8_t rxBufferLength:4;
27
		};
28
	};
29
 
30
	uint8_t txAddress;
31
	uint8_t txBuffer[MAX_BUFFER];
32
 
33
	union {
34
		uint8_t txMeta;
35
		struct {
36
			uint8_t txBufferIndex:4;
37
			uint8_t txBufferLength:4;
38
		};
39
	};
40
 
41
	void    (*user_onRequest)(void);
42
	void    (*user_onReceive)(uint8_t);
43
 
44
	union {
45
		uint8_t internal;
46
		struct {
47
			uint8_t transmitting:1;
48
			uint8_t reserved:7;
49
		};
50
	};
51
} wire;
52
 
53
#endif