MatrixMiniR4 1.1.5
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4_I2CDevice.h
Go to the documentation of this file.
1
7/*
8The MIT License (MIT)
9
10Copyright (c) 2017 Adafruit Industries
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files (the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions:
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29*/
30
31#ifndef Adafruit_I2CDevice_h
32#define Adafruit_I2CDevice_h
33
34#include <Arduino.h>
35#include <Wire.h>
36
44public:
45 Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
46 uint8_t address(void);
47 bool begin(bool addr_detect = true);
48 void end(void);
49 bool detected(void);
50
51 bool read(uint8_t *buffer, size_t len, bool stop = true);
52 bool write(const uint8_t *buffer, size_t len, bool stop = true,
53 const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
54 bool write_then_read(const uint8_t *write_buffer, size_t write_len,
55 uint8_t *read_buffer, size_t read_len,
56 bool stop = false);
57 bool setSpeed(uint32_t desiredclk);
58
61 size_t maxBufferSize() { return _maxBufferSize; }
62
63private:
64 uint8_t _addr;
65 TwoWire *_wire;
66 bool _begun;
67 size_t _maxBufferSize;
68 bool _read(uint8_t *buffer, size_t len, bool stop);
69};
70
71#endif // Adafruit_I2CDevice_h
Adafruit I2CDevice Class for OLED.
size_t maxBufferSize()
How many bytes we can read in a transaction.
bool setSpeed(uint32_t desiredclk)
Change the I2C clock speed to desired (relies on underlying Wire support!
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.
bool detected(void)
Scans I2C for the address - note will give a false-positive if there's no pullups on I2C.
bool begin(bool addr_detect=true)
Initializes and does basic address detection.
uint8_t address(void)
Returns the 7-bit address of this device.
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(...
void end(void)
De-initialize device, turn off the Wire interface.
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire=&Wire)
Create an I2C device at a given address.
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.