MatrixMiniR4 1.1.4
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4I2CDevice.h
Go to the documentation of this file.
1
5#ifndef MiniR4I2CDevice_H
6#define MiniR4I2CDevice_H
7
8#include <Arduino.h>
9#include <Wire.h>
10
11#ifndef ADDR_PCA954X
12# define ADDR_PCA954X 0x70
13#endif
14
20{
21public:
22 MiniR4_I2CDevice(uint8_t addr, TwoWire* theWire = &Wire, uint8_t mux_ch = -1);
23 uint8_t address(void);
24 bool begin(bool addr_detect = true);
25 void end(void);
26 bool detected(void);
27
28 bool read(uint8_t* buffer, size_t len, bool stop = true);
29 bool write(
30 const uint8_t* buffer, size_t len, bool stop = true, const uint8_t* prefix_buffer = nullptr,
31 size_t prefix_len = 0);
32 bool write_then_read(
33 const uint8_t* write_buffer, size_t write_len, uint8_t* read_buffer, size_t read_len,
34 bool stop = false);
35 bool setSpeed(uint32_t desiredclk);
36
39 size_t maxBufferSize() { return _maxBufferSize; }
40
41 uint8_t _ch = 0;
42
43private:
44 uint8_t _addr;
45 TwoWire* _wire;
46 bool _begun;
47 size_t _maxBufferSize;
48 bool _read(uint8_t* buffer, size_t len, bool stop);
49 void i2cMUXSelect(void);
50};
51
52#endif // MiniR4I2CDevice_H
The class which defines how we will talk to this device over I2C.
MiniR4_I2CDevice(uint8_t addr, TwoWire *theWire=&Wire, uint8_t mux_ch=-1)
Create an I2C device at a given address.
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.
uint8_t address(void)
Returns the 7-bit address of this device.
bool setSpeed(uint32_t desiredclk)
Change the I2C clock speed to desired (relies on underlying Wire support!
void end(void)
De-initialize device, turn off the Wire interface.
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(...
size_t maxBufferSize()
How many bytes we can read in a transaction.
bool detected(void)
Scans I2C for the address - note will give a false-positive if there's no pullups on I2C.
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.
bool begin(bool addr_detect=true)
Initializes and does basic address detection.