Accel

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaAccel by 智也 大野

hepta_sat/I2cBusDevice.h

Committer:
tomoya123
Date:
2016-12-13
Revision:
1:63c3921c608c
Parent:
0:d721efd58e4e

File content as of revision 1:63c3921c608c:

#ifndef    MBED_I2cBusDevice
#define    MBED_I2cBusDevice

#include    "mbed.h"

class I2cBusDevice {
public:

    I2cBusDevice( I2C *i2c, char dev_address ) {
        bus          = i2c;
        device       = dev_address;
    }

    ~I2cBusDevice() {
    }

    int write( char *data, int length ) {
        return ( bus->write( device, data, length) );
    }

    int read( char *data, int length ) {
        return ( bus->read( device, data, length) );
    }

    int read( char reg_ptr, char *data, int length ) {
        if ( bus->write( device, &reg_ptr, 1 ) )
            return ( 1 );

        if ( bus->read( device, data, length ) )
            return ( 1 );

        return ( 0 );
    }

protected:
    I2C     *bus;
    char    device;

private:
    static char    i2c_error;
}
;

#endif