pixy Libari 2
Dependents: PES PES1 PES4 PES3
PixyLinkI2C.h@1:a57585d5e81b, 2017-03-29 (annotated)
- Committer:
- scholfa2
- Date:
- Wed Mar 29 12:34:18 2017 +0000
- Revision:
- 1:a57585d5e81b
- Parent:
- 0:ed8dc4531ac1
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scholfa2 | 1:a57585d5e81b | 1 | #ifndef PIXYLINKI2C_H |
scholfa2 | 1:a57585d5e81b | 2 | #define PIXYLINKI2C_H |
acracan | 0:ed8dc4531ac1 | 3 | |
acracan | 0:ed8dc4531ac1 | 4 | #include "I2C.h" |
acracan | 0:ed8dc4531ac1 | 5 | #include "PixyLink.h" |
acracan | 0:ed8dc4531ac1 | 6 | |
acracan | 0:ed8dc4531ac1 | 7 | class PixyLinkI2C : public PixyLink, private I2C |
acracan | 0:ed8dc4531ac1 | 8 | { |
acracan | 0:ed8dc4531ac1 | 9 | public: |
acracan | 0:ed8dc4531ac1 | 10 | PixyLinkI2C(PinName sda, PinName scl) : |
scholfa2 | 1:a57585d5e81b | 11 | PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl){ |
scholfa2 | 1:a57585d5e81b | 12 | I2C::frequency(100000); |
scholfa2 | 1:a57585d5e81b | 13 | }; |
acracan | 0:ed8dc4531ac1 | 14 | |
acracan | 0:ed8dc4531ac1 | 15 | virtual uint16_t getWord() { |
acracan | 0:ed8dc4531ac1 | 16 | uint8_t data[2] = {0, 0}; |
acracan | 0:ed8dc4531ac1 | 17 | I2C::read((int)m_addr, (char *)data, 2); |
acracan | 0:ed8dc4531ac1 | 18 | return ((uint16_t)data[1] << 8) | data[0]; |
acracan | 0:ed8dc4531ac1 | 19 | }; |
acracan | 0:ed8dc4531ac1 | 20 | |
acracan | 0:ed8dc4531ac1 | 21 | virtual uint8_t getByte() { |
acracan | 0:ed8dc4531ac1 | 22 | uint8_t data = 0; |
acracan | 0:ed8dc4531ac1 | 23 | I2C::read((int)m_addr, (char*)&data, 1); |
acracan | 0:ed8dc4531ac1 | 24 | return data; |
acracan | 0:ed8dc4531ac1 | 25 | }; |
acracan | 0:ed8dc4531ac1 | 26 | |
acracan | 0:ed8dc4531ac1 | 27 | virtual int8_t send(uint8_t *data, uint8_t len) { |
acracan | 0:ed8dc4531ac1 | 28 | return I2C::write((int)m_addr, (char*)data, len); |
acracan | 0:ed8dc4531ac1 | 29 | }; |
acracan | 0:ed8dc4531ac1 | 30 | |
acracan | 0:ed8dc4531ac1 | 31 | |
acracan | 0:ed8dc4531ac1 | 32 | private: |
scholfa2 | 1:a57585d5e81b | 33 | static const uint8_t PIXY_DEFAULT_ADDR = 0xAC; |
acracan | 0:ed8dc4531ac1 | 34 | }; |
acracan | 0:ed8dc4531ac1 | 35 | |
scholfa2 | 1:a57585d5e81b | 36 | #endif //PIXYLINKI2C_H |