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.
Diff: PixyLinkI2C.h
- Revision:
- 0:a2603d7fa0ac
- Child:
- 2:c3a866b20784
diff -r 000000000000 -r a2603d7fa0ac PixyLinkI2C.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PixyLinkI2C.h Fri May 05 12:03:13 2017 +0000 @@ -0,0 +1,35 @@ +#ifndef TUIASI_PIXYLINKI2C_H +#define TUIASI_PIXYLINKI2C_H + +#include "I2C.h" +#include "PixyLink.h" + +class PixyLinkI2C : public PixyLink, private I2C +{ +public: + PixyLinkI2C(PinName sda, PinName scl) : + PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl) { + }; + + virtual uint16_t getWord() { + uint8_t data[2] = {0, 0}; + I2C::read((int)m_addr, (char *)data, 2); + return ((uint16_t)data[1] << 8) | data[0]; + }; + + virtual uint8_t getByte() { + uint8_t data = 0; + I2C::read((int)m_addr, (char*)&data, 1); + return data; + }; + + virtual int8_t send(uint8_t *data, uint8_t len) { + return I2C::write((int)m_addr, (char*)data, len); + }; + + +private: + static const uint8_t PIXY_DEFAULT_ADDR = 0x54; +}; + +#endif //TUIASI_PIXYLINKI2C_H