SparkFun Toolkit  v1.0.5-6-g34ffa30
Core Functionality Library
Loading...
Searching...
No Matches
sfTkArdI2C.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <Arduino.h>
17#include <Wire.h>
18
19// Include our platform I2C interface definition.
20#include "sfTkArduino.h"
21#include <sfTk/sfTkII2C.h>
22
27class sfTkArdI2C : public sfTkII2C
28{
29 public:
34 sfTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk}
35 {
36 }
42 sfTkArdI2C(uint8_t addr) : sfTkII2C(addr)
43 {
44 }
45
50 {
51 }
52
60 {
61 _i2cPort = rhs._i2cPort;
62 return *this;
63 }
64
72
78 sfTkError_t init(uint8_t addr);
79
89 sfTkError_t init(TwoWire &wirePort, uint8_t addr, bool bInit = false);
90
98
108 sfTkError_t writeRegister(uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length);
109
121 sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes,
122 uint32_t read_delay = 0);
123 // Buffer size chunk getter/setter
132 void setBufferChunkSize(size_t theChunk)
133 {
134 if (theChunk > 0)
135 _bufferChunkSize = theChunk;
136 }
137
144 size_t bufferChunkSize(void)
145 {
146 return _bufferChunkSize;
147 }
148
149 // For overloaded virtual methods, make sure our subclass methods appear on this object
152
153 protected:
154 // note: The wire port is protected, allowing access if a sub-class is
155 // created to implement a special read/write routine
156 //
158 TwoWire *_i2cPort;
159
160 private:
162 static constexpr size_t kDefaultBufferChunk = 32;
163
165 size_t _bufferChunkSize;
166};
The sfTkArdI2C implements an sfTkII2C interface, defining the Arduino implementation for I2C in the T...
Definition: sfTkArdI2C.h:28
sfTkError_t ping()
A simple ping of the device at the given address.
Definition: sfTkArdI2C.cpp:99
sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes, uint32_t read_delay=0)
Reads data from a specified register of an I2C device.
Definition: sfTkArdI2C.cpp:144
sfTkArdI2C & operator=(const sfTkArdI2C &rhs)
Copy assignment.
Definition: sfTkArdI2C.h:59
TwoWire * _i2cPort
Definition: sfTkArdI2C.h:158
void setBufferChunkSize(size_t theChunk)
set the buffer chunk size
Definition: sfTkArdI2C.h:132
sfTkArdI2C(sfTkArdI2C const &rhs)
copy constructor
Definition: sfTkArdI2C.h:49
sfTkArdI2C(void)
Constructor.
Definition: sfTkArdI2C.h:34
size_t bufferChunkSize(void)
set the buffer chunk size
Definition: sfTkArdI2C.h:144
sfTkArdI2C(uint8_t addr)
Constructor.
Definition: sfTkArdI2C.h:42
sfTkError_t init()
Method sets up the required I2C settings.
Definition: sfTkArdI2C.cpp:81
sfTkError_t writeRegister(uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length)
Writes data to a specified register on an I2C device.
Definition: sfTkArdI2C.cpp:118
virtual sfTkError_t writeRegister(uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length)=0
Writes an array of bytes to a register on the target address. Supports any address size.
virtual sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes, uint32_t read_delay=0)=0
Reads an array of bytes to a register on the target address. Supports any address size.
Definition: sfTkII2C.h:27
header file for the SparkFun Toolkit Arduino layer
int32_t sfTkError_t
Definition: sfTkError.h:35
Header file for the SparkFun Toolkit I2C Interface Definition.