Subversion Repositories group.electronics

Rev

Rev 42 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 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];
56 pfowler 20
        //uint8_t rxBufferIndex;
21
        //uint8_t rxBufferLength;
42 pfowler 22
 
56 pfowler 23
	// Save 8 bytes. Maximum buffer size is 15
24
        union {
25
                uint8_t rxMeta;
26
                struct {
27
                        uint8_t rxBufferIndex:4;
28
                        uint8_t rxBufferLength:4;
29
                };
30
        };
31
 
42 pfowler 32
        uint8_t txAddress;
33
        uint8_t txBuffer[MAX_BUFFER];
56 pfowler 34
        //uint8_t txBufferIndex;
35
        //uint8_t txBufferLength;
42 pfowler 36
 
56 pfowler 37
	union {
38
		uint8_t txMeta;
39
		struct {
40
			uint8_t txBufferIndex:4;
41
			uint8_t txBufferLength:4;
42
		};
43
	};
44
 
42 pfowler 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;
56 pfowler 52
                        uint8_t reserved:7;
42 pfowler 53
                };
54
        };
55
} wire;
56
 
57
#endif