2020-05-12 20:24:44 +01:00
|
|
|
#ifndef Adafruit_I2CDevice_h
|
|
|
|
#define Adafruit_I2CDevice_h
|
|
|
|
|
2022-02-05 15:56:21 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
|
2020-05-12 20:24:44 +01:00
|
|
|
///< The class which defines how we will talk to this device over I2C
|
|
|
|
class Adafruit_I2CDevice {
|
2022-02-05 15:56:21 +00:00
|
|
|
public:
|
|
|
|
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
|
2020-05-12 20:24:44 +01:00
|
|
|
uint8_t address(void);
|
2022-02-05 15:56:21 +00:00
|
|
|
bool begin(bool addr_detect = true);
|
|
|
|
void end(void);
|
2020-05-12 20:24:44 +01:00
|
|
|
bool detected(void);
|
|
|
|
|
2022-02-05 15:56:21 +00:00
|
|
|
bool read(uint8_t *buffer, size_t len, bool stop = true);
|
|
|
|
bool write(const uint8_t *buffer, size_t len, bool stop = true,
|
|
|
|
const uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
|
|
|
|
bool write_then_read(const uint8_t *write_buffer, size_t write_len,
|
|
|
|
uint8_t *read_buffer, size_t read_len,
|
|
|
|
bool stop = false);
|
|
|
|
bool setSpeed(uint32_t desiredclk);
|
2020-05-12 20:24:44 +01:00
|
|
|
|
|
|
|
/*! @brief How many bytes we can read in a transaction
|
2022-02-05 15:56:21 +00:00
|
|
|
* @return The size of the Wire receive/transmit buffer */
|
|
|
|
size_t maxBufferSize() { return _maxBufferSize; }
|
2020-05-12 20:24:44 +01:00
|
|
|
|
2022-02-05 15:56:21 +00:00
|
|
|
private:
|
2020-05-12 20:24:44 +01:00
|
|
|
uint8_t _addr;
|
|
|
|
TwoWire *_wire;
|
|
|
|
bool _begun;
|
2022-02-05 15:56:21 +00:00
|
|
|
size_t _maxBufferSize;
|
|
|
|
bool _read(uint8_t *buffer, size_t len, bool stop);
|
2020-05-12 20:24:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // Adafruit_I2CDevice_h
|