Adafruit_I2CDevice.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include <Wire.h>
  2. #ifndef Adafruit_I2CDevice_h
  3. #define Adafruit_I2CDevice_h
  4. ///< The class which defines how we will talk to this device over I2C
  5. class Adafruit_I2CDevice {
  6. public:
  7. Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
  8. uint8_t address(void);
  9. bool begin(bool addr_detect = true);
  10. bool detected(void);
  11. bool read(uint8_t *buffer, size_t len, bool stop = true);
  12. bool write(const uint8_t *buffer, size_t len, bool stop = true,
  13. const uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
  14. bool write_then_read(const uint8_t *write_buffer, size_t write_len,
  15. uint8_t *read_buffer, size_t read_len,
  16. bool stop = false);
  17. bool setSpeed(uint32_t desiredclk);
  18. /*! @brief How many bytes we can read in a transaction
  19. * @return The size of the Wire receive/transmit buffer */
  20. size_t maxBufferSize() { return _maxBufferSize; }
  21. private:
  22. uint8_t _addr;
  23. TwoWire *_wire;
  24. bool _begun;
  25. size_t _maxBufferSize;
  26. };
  27. #endif // Adafruit_I2CDevice_h