I2CRTOS Driver by Helmut Schmücker. Removed included mbed-rtos library to prevent multiple definition. Make sure to include mbed-rtos library in your program!
Fork of I2cRtosDriver by
I2CMasterRtos.h
- Committer:
- humlet
- Date:
- 2013-04-19
- Revision:
- 3:967dde37e712
- Child:
- 5:8a418c89e515
File content as of revision 3:967dde37e712:
#ifndef I2CMASTERRTOS_H #define I2CMASTERRTOS_H #include "I2CDriver.h" namespace mbed { /// I2C master interface to the RTOS-I2CDriver. /// The interface is compatible to the original mbed I2C class. /// Provides an additonal read from register function. class I2CMasterRtos { I2CDriver m_drv; public: /** Create an I2C Master interface, connected to the specified pins * * @param sda I2C data line pin * @param scl I2C clock line pin */ I2CMasterRtos(PinName sda, PinName scl, int freq=100000):m_drv(sda,scl,freq) {} /** Set the frequency of the I2C interface * * @param hz The bus frequency in hertz */ void frequency(int hz) { m_drv.frequency(hz); } /** Read from an I2C slave * * Performs a complete read transaction. The bottom bit of * the address is forced to 1 to indicate a read. * * @param address 8-bit I2C slave address [ addr | 1 ] * @param data Pointer to the byte-array to read data in to * @param length Number of bytes to read * @param repeated Repeated start, true - don't send stop at end * * @returns * 0 on success (ack), * non-0 on failure (nack) */ int read(int address, char *data, int length, bool repeated = false) { return m_drv.readMaster( address, data, length, repeated); } /** Read from a given I2C slave register * * Performs a complete write-register-read-data-transaction. The bottom bit of * the address is forced to 1 to indicate a read. * * @param address 8-bit I2C slave address [ addr | 1 ] * @param _register 8-bit regster address * @param data Pointer to the byte-array to read data in to * @param length Number of bytes to read * @param repeated Repeated start, true - don't send stop at end * * @returns * 0 on success (ack), * non-0 on failure (nack) */ int read(int address, uint8_t _register, char *data, int length, bool repeated = false) { return m_drv.readMaster( address, _register, data, length, repeated); } /** Read a single byte from the I2C bus * * @param ack indicates if the byte is to be acknowledged (1 = acknowledge) * * @returns * the byte read */ int read(int ack) { return m_drv.readMaster(ack); } /** Write to an I2C slave * * Performs a complete write transaction. The bottom bit of * the address is forced to 0 to indicate a write. * * @param address 8-bit I2C slave address [ addr | 0 ] * @param data Pointer to the byte-array data to send * @param length Number of bytes to send * @param repeated Repeated start, true - do not send stop at end * * @returns * 0 on success (ack), * non-0 on failure (nack) */ int write(int address, const char *data, int length, bool repeated = false) { return m_drv.writeMaster(address, data, length, repeated); } /** Write single byte out on the I2C bus * * @param data data to write out on bus * * @returns * '1' if an ACK was received, * '0' otherwise */ int write(int data) { return m_drv.writeMaster(data); } /** Creates a start condition on the I2C bus */ void startMaster(void) { m_drv.startMaster(); } /** Creates a stop condition on the I2C bus */ void stop(void) { m_drv.stopMaster(); } }; } #endif