Adafruit_I2CDevice.h 1.1 KB

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