Subversion Repositories group.electronics

Rev

Rev 123 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
123 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
uint8_t i2c_requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop);
13
int i2c_available(void);
14
uint8_t i2c_read(void);
15
 
16
void i2c_onReceiveService(uint8_t* inBytes, int numBytes);
17
void i2c_onRequestService(void);
18
void i2c_onReceive( void(*function)(uint8_t));
19
void i2c_onRequest( void(*function)(void));
20
 
21
 
22
struct {
23
	uint8_t rxBuffer[MAX_BUFFER];
24
 
25
	// Save 8 bytes. Maximum buffer size is 15
26
	union {
27
		uint8_t rxMeta;
28
		struct {
29
			uint8_t rxBufferIndex:4;
30
			uint8_t rxBufferLength:4;
31
		};
32
	};
33
 
34
	uint8_t txAddress;
35
	uint8_t txBuffer[MAX_BUFFER];
36
 
37
	union {
38
		uint8_t txMeta;
39
		struct {
40
			uint8_t txBufferIndex:4;
41
			uint8_t txBufferLength:4;
42
		};
43
	};
44
 
45
	void    (*user_onRequest)(void);
46
	void    (*user_onReceive)(uint8_t);
47
 
48
	union {
49
		uint8_t internal;
50
		struct {
51
			uint8_t transmitting:1;
52
			uint8_t reserved:7;
53
		};
54
	};
55
} wire;
56
 
57
#endif