Subversion Repositories group.electronics

Rev

Rev 40 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef wire_h
#define wire_h

#define MAX_BUFFER      4

void i2c_master(void);
void i2c_slave(uint8_t address);
void i2c_beginTransmission(uint8_t address);
uint8_t i2c_endTransmission(uint8_t sentStop);
uint8_t i2c_writeByte(uint8_t data);
uint8_t i2c_writeBytes(uint8_t *data, uint8_t bytes);
void i2c_onReceiveService(uint8_t* inBytes, int numBytes);
void i2c_onRequestService(void);
void i2c_onReceive( void(*function)(uint8_t));
void i2c_onRequest( void(*function)(void));


struct {
        uint8_t rxBuffer[MAX_BUFFER];

        // Save 8 bytes. Maximum buffer size is 15
        union {
                uint8_t rxMeta;
                struct {
                        uint8_t rxBufferIndex:4;
                        uint8_t rxBufferLength:4;
                };
        };

        uint8_t txAddress;
        uint8_t txBuffer[MAX_BUFFER];

        union {
                uint8_t txMeta;
                struct {
                        uint8_t txBufferIndex:4;
                        uint8_t txBufferLength:4;
                };
        };

        void    (*user_onRequest)(void);
        void    (*user_onReceive)(uint8_t);

        union {
                uint8_t internal;
                struct {
                        uint8_t transmitting:1;
                        uint8_t reserved:7;
                };
        };
} wire;

#endif