Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MCP23009tst AT30TSE752TST MCP4728setaddrProg mbedSerialInterface_talkback2 ... more
I2CInterface.h@5:b5c9eb2330dc, 2017-03-15 (annotated)
- Committer:
- wbeaumont
- Date:
- Wed Mar 15 17:16:59 2017 +0000
- Revision:
- 5:b5c9eb2330dc
- Parent:
- 0:da1fb7dd363f
- Child:
- 7:b091a268b726
added general wait function and defined int8_t
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 | 5:b5c9eb2330dc | 6 | #define I2CINTERFACE_HDR_VER "0.40" |
| wbeaumont | 5:b5c9eb2330dc | 7 | /* |
| wbeaumont | 5:b5c9eb2330dc | 8 | * ver 0:40 added wait_for_ms |
| wbeaumont | 5:b5c9eb2330dc | 9 | */ |
| wbeaumont | 0:da1fb7dd363f | 10 | |
| wbeaumont | 0:da1fb7dd363f | 11 | class I2CInterface : public virtual getVersion{ |
| wbeaumont | 0:da1fb7dd363f | 12 | private: |
| wbeaumont | 0:da1fb7dd363f | 13 | protected : |
| wbeaumont | 0:da1fb7dd363f | 14 | void* callback(); |
| wbeaumont | 0:da1fb7dd363f | 15 | |
| wbeaumont | 0:da1fb7dd363f | 16 | public : |
| wbeaumont | 0:da1fb7dd363f | 17 | I2CInterface():getVersion( I2CINTERFACE_HDR_VER ,I2CINTERFACE_HDR_VER , __TIME__, __DATE__){}; //Create an I2C Master interface |
| wbeaumont | 0:da1fb7dd363f | 18 | virtual void frequency (int hz){};// Set the frequency of the I2C interface. |
| wbeaumont | 0:da1fb7dd363f | 19 | virtual int read (int address, char *data, int length, bool repeated=false){ |
| wbeaumont | 0:da1fb7dd363f | 20 | return 0;};//Read from an I2C slave. |
| wbeaumont | 0:da1fb7dd363f | 21 | virtual int read (int ack){return 0;};// Read a single byte from the I2C bus. |
| wbeaumont | 0:da1fb7dd363f | 22 | virtual int write (int address, const char *data, int length, bool repeated=false){ |
| wbeaumont | 0:da1fb7dd363f | 23 | return 0; |
| wbeaumont | 0:da1fb7dd363f | 24 | };// Write to an I2C slave. |
| wbeaumont | 0:da1fb7dd363f | 25 | virtual int write (int data){return 0;};// Write single byte out on the I2C bus. |
| wbeaumont | 0:da1fb7dd363f | 26 | virtual void start (void){};// Creates a start condition on the I2C bus. |
| wbeaumont | 0:da1fb7dd363f | 27 | virtual void stop (void){};// Creates a stop condition on the I2C bus. |
| wbeaumont | 0:da1fb7dd363f | 28 | 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 | 29 | return 0; |
| wbeaumont | 0:da1fb7dd363f | 30 | }; // Start non-blocking I2C transfer. not yet clear how to deal with the callback |
| wbeaumont | 0:da1fb7dd363f | 31 | // proposol here is for the implementation a spefic call back function ,that includes the event type |
| wbeaumont | 5:b5c9eb2330dc | 32 | // wait function that is sometimes needed , not I2C hardware related but different implementation for platforms |
| wbeaumont | 5:b5c9eb2330dc | 33 | virtual void wait_for_ms(int x) { } ; |
| wbeaumont | 0:da1fb7dd363f | 34 | }; |
| wbeaumont | 0:da1fb7dd363f | 35 | |
| wbeaumont | 0:da1fb7dd363f | 36 | #endif |