This are general defs and base class interfaces. ( DACInterface, I2CInterface) to be used with I2C devices
Dependents: MCP23009tst AT30TSE752TST MCP4728setaddrProg mbedSerialInterface_talkback2 ... more
The DevInterfaces class is used for a more general support of a number of I2C devices.
For the moment this is MCP4728 Quad DAC.
The idea is to write a libs for the I2C devices (and perhaps later SPI , ... devices) not restricted to a certain hardware platform.
So there is the I2CInterface. This is a ( not pure) virtual class. A pointer to this class is used for the I2C device lib (like the MCP4728 class https://developer.mbed.org/users/wbeaumont/code/MCP4728/ ) to communicate with the I2C interface. The I2C interface is kept simple as possible. So it has to be applied for "tested environments". I2C Bus timeouts etc. are hard to debug with such a simple interface. This kind of interface is also not suitable for optimal performance. The user has to take care of issues of blocking devices, parallel processes etc. This can be dealt with in the implementation of the I2CInterface class
The aim of this project is to generate code for these devices on different platforms without doing the painstaking work of looking up all the register details.
There is an implementation of the I2CInterface for the MBED , tested with the FRDM-KL05Z platform. https://developer.mbed.org/users/wbeaumont/code/I2Cinterfaces/
A very simple application on a MBED can be found in https://developer.mbed.org/users/wbeaumont/code/MCP4728test/
I2CInterface.h@0:da1fb7dd363f, 2015-10-23 (annotated)
- Committer:
- wbeaumont
- Date:
- Fri Oct 23 19:34:53 2015 +0000
- Revision:
- 0:da1fb7dd363f
- Child:
- 5:b5c9eb2330dc
basics works
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:da1fb7dd363f | 1 | #ifndef __I2CINTERFACE__ |
wbeaumont | 0:da1fb7dd363f | 2 | #define __I2CINTERFACE__ |
wbeaumont | 0:da1fb7dd363f | 3 | |
wbeaumont | 0:da1fb7dd363f | 4 | #include "getVersion.h" |
wbeaumont | 0:da1fb7dd363f | 5 | |
wbeaumont | 0:da1fb7dd363f | 6 | #define I2CINTERFACE_HDR_VER "0.33" |
wbeaumont | 0:da1fb7dd363f | 7 | |
wbeaumont | 0:da1fb7dd363f | 8 | class I2CInterface : public virtual getVersion{ |
wbeaumont | 0:da1fb7dd363f | 9 | private: |
wbeaumont | 0:da1fb7dd363f | 10 | protected : |
wbeaumont | 0:da1fb7dd363f | 11 | void* callback(); |
wbeaumont | 0:da1fb7dd363f | 12 | |
wbeaumont | 0:da1fb7dd363f | 13 | public : |
wbeaumont | 0:da1fb7dd363f | 14 | I2CInterface():getVersion( I2CINTERFACE_HDR_VER ,I2CINTERFACE_HDR_VER , __TIME__, __DATE__){}; //Create an I2C Master interface |
wbeaumont | 0:da1fb7dd363f | 15 | virtual void frequency (int hz){};// Set the frequency of the I2C interface. |
wbeaumont | 0:da1fb7dd363f | 16 | virtual int read (int address, char *data, int length, bool repeated=false){ |
wbeaumont | 0:da1fb7dd363f | 17 | return 0;};//Read from an I2C slave. |
wbeaumont | 0:da1fb7dd363f | 18 | virtual int read (int ack){return 0;};// Read a single byte from the I2C bus. |
wbeaumont | 0:da1fb7dd363f | 19 | virtual int write (int address, const char *data, int length, bool repeated=false){ |
wbeaumont | 0:da1fb7dd363f | 20 | return 0; |
wbeaumont | 0:da1fb7dd363f | 21 | };// Write to an I2C slave. |
wbeaumont | 0:da1fb7dd363f | 22 | virtual int write (int data){return 0;};// Write single byte out on the I2C bus. |
wbeaumont | 0:da1fb7dd363f | 23 | virtual void start (void){};// Creates a start condition on the I2C bus. |
wbeaumont | 0:da1fb7dd363f | 24 | virtual void stop (void){};// Creates a stop condition on the I2C bus. |
wbeaumont | 0:da1fb7dd363f | 25 | virtual int transfer (int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, void* callbackptr, bool repeated=false){ |
wbeaumont | 0:da1fb7dd363f | 26 | return 0; |
wbeaumont | 0:da1fb7dd363f | 27 | }; // Start non-blocking I2C transfer. not yet clear how to deal with the callback |
wbeaumont | 0:da1fb7dd363f | 28 | // proposol here is for the implementation a spefic call back function ,that includes the event type |
wbeaumont | 0:da1fb7dd363f | 29 | |
wbeaumont | 0:da1fb7dd363f | 30 | }; |
wbeaumont | 0:da1fb7dd363f | 31 | |
wbeaumont | 0:da1fb7dd363f | 32 | #endif |