(MBED) implementation of the I2C interface

Dependents:   MCP23009tst AT30TSE752TST MCP4728setaddrProg mbedSerialInterface_talkback2 ... more

Committer:
wbeaumont
Date:
Wed Mar 15 17:17:46 2017 +0000
Revision:
2:b7ebe53e8fac
Parent:
1:80ebfbf95667
Child:
3:06e9e208a2b0
added a implementation for wait_for_ms

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