arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

Adafruit_I2CDevice.h (1043B)


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