I2C interface for our mbed.

Fork of I2Cinterfaces by wimbeaumont Project

Committer:
wbeaumont
Date:
Tue Jan 12 15:04:03 2016 +0000
Revision:
0:c65947f64a8b
Child:
1:80ebfbf95667
implementations of the I2C classes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 0:c65947f64a8b 1 #ifndef __MBEDI2CINTERFACE_H
wbeaumont 0:c65947f64a8b 2 #define __MBEDI2CINTERFACE_H
wbeaumont 0:c65947f64a8b 3
wbeaumont 0:c65947f64a8b 4 #define VERSION_MBEDI2CInterface_HDR "1.00"
wbeaumont 0:c65947f64a8b 5
wbeaumont 0:c65947f64a8b 6
wbeaumont 0:c65947f64a8b 7 class MBEDI2CInterface :public I2CInterface {
wbeaumont 0:c65947f64a8b 8
wbeaumont 0:c65947f64a8b 9 I2C i2cdev;
wbeaumont 0:c65947f64a8b 10 public :
wbeaumont 0:c65947f64a8b 11
wbeaumont 0:c65947f64a8b 12 MBEDI2CInterface(PinName sda, PinName scl): i2cdev(sda,scl),
wbeaumont 0:c65947f64a8b 13 getVersion( VERSION_MBEDI2CInterface_HDR,VERSION_MBEDI2CInterface_HDR, __TIME__, __DATE__){
wbeaumont 0:c65947f64a8b 14 // no init code yet
wbeaumont 0:c65947f64a8b 15 } ;
wbeaumont 0:c65947f64a8b 16 // next could perhaps more efficient but not yet investigated
wbeaumont 0:c65947f64a8b 17 virtual void frequency (int hz){return i2cdev.frequency(hz) ;};
wbeaumont 0:c65947f64a8b 18 virtual int read (int address, char *data, int length, bool repeated=false){
wbeaumont 0:c65947f64a8b 19 return i2cdev.read ( address, data, length, repeated);};
wbeaumont 0:c65947f64a8b 20 virtual int read (int ack){return i2cdev.read ( ack);};// Read a single byte from the I2C bus.
wbeaumont 0:c65947f64a8b 21 virtual int write (int address, const char *data, int length, bool repeated=false){
wbeaumont 0:c65947f64a8b 22 return i2cdev.write ( address, data, length, repeated);
wbeaumont 0:c65947f64a8b 23 }
wbeaumont 0:c65947f64a8b 24 virtual int write (int data){return i2cdev.write (data);};// Write single byte out on the I2C bus.
wbeaumont 0:c65947f64a8b 25 virtual void start (void){i2cdev.start ();};// Creates a start condition on the I2C bus.
wbeaumont 0:c65947f64a8b 26 virtual void stop (void){i2cdev.stop();};// Creates a stop condition on the I2C bus.
wbeaumont 0:c65947f64a8b 27 virtual int transfer (int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, void* callbackfunction, bool repeated=false){
wbeaumont 0:c65947f64a8b 28 return -1; // seems transfer not supported in mbed or not correctly called below
wbeaumont 0:c65947f64a8b 29 // return i2cdev.transfer (address, tx_buffer, tx_length, rx_buffer, rx_length, callback, event, repeated);
wbeaumont 0:c65947f64a8b 30 };
wbeaumont 0:c65947f64a8b 31
wbeaumont 0:c65947f64a8b 32
wbeaumont 0:c65947f64a8b 33 } ;
wbeaumont 0:c65947f64a8b 34
wbeaumont 0:c65947f64a8b 35
wbeaumont 0:c65947f64a8b 36
wbeaumont 0:c65947f64a8b 37
wbeaumont 0:c65947f64a8b 38
wbeaumont 0:c65947f64a8b 39 #endif