Adafruit Bus IO Library
Adafruit_I2CDevice.h
1 #ifndef Adafruit_I2CDevice_h
2 #define Adafruit_I2CDevice_h
3 
4 #include <Arduino.h>
5 #include <Wire.h>
6 
9 public:
10  Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
11  uint8_t address(void);
12  bool begin(bool addr_detect = true);
13  void end(void);
14  bool detected(void);
15 
16  bool read(uint8_t *buffer, size_t len, bool stop = true);
17  bool write(const uint8_t *buffer, size_t len, bool stop = true,
18  const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
19  bool write_then_read(const uint8_t *write_buffer, size_t write_len,
20  uint8_t *read_buffer, size_t read_len,
21  bool stop = false);
22  bool setSpeed(uint32_t desiredclk);
23 
26  size_t maxBufferSize() { return _maxBufferSize; }
27 
28 private:
29  uint8_t _addr;
30  TwoWire *_wire;
31  bool _begun;
32  size_t _maxBufferSize;
33  bool _read(uint8_t *buffer, size_t len, bool stop);
34 };
35 
36 #endif // Adafruit_I2CDevice_h
bool setSpeed(uint32_t desiredclk)
Change the I2C clock speed to desired (relies on underlying Wire support!
Definition: Adafruit_I2CDevice.cpp:267
void end(void)
De-initialize device, turn off the Wire interface.
Definition: Adafruit_I2CDevice.cpp:43
bool write(const uint8_t *buffer, size_t len, bool stop=true, const uint8_t *prefix_buffer=nullptr, size_t prefix_len=0)
Write a buffer or two to the I2C device. Cannot be more than maxBufferSize() bytes.
Definition: Adafruit_I2CDevice.cpp:99
bool read(uint8_t *buffer, size_t len, bool stop=true)
Read from I2C into a buffer from the I2C device. Cannot be more than maxBufferSize() bytes...
Definition: Adafruit_I2CDevice.cpp:180
< The class which defines how we will talk to this device over I2C
Definition: Adafruit_I2CDevice.h:8
bool write_then_read(const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop=false)
Write some data, then read some data from I2C into another buffer. Cannot be more than maxBufferSize(...
Definition: Adafruit_I2CDevice.cpp:244
bool detected(void)
Scans I2C for the address - note will give a false-positive if there&#39;s no pullups on I2C...
Definition: Adafruit_I2CDevice.cpp:62
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire=&Wire)
Create an I2C device at a given address.
Definition: Adafruit_I2CDevice.cpp:10
uint8_t address(void)
Returns the 7-bit address of this device.
Definition: Adafruit_I2CDevice.cpp:258
size_t maxBufferSize()
How many bytes we can read in a transaction.
Definition: Adafruit_I2CDevice.h:26
bool begin(bool addr_detect=true)
Initializes and does basic address detection.
Definition: Adafruit_I2CDevice.cpp:30