Skip to content

Commit 55e3795

Browse files
authored
Merge pull request #57 from sparkfun/releaese/version-1.0.5
Releaese/version 1.0.5
2 parents 286297b + 7a88268 commit 55e3795

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Toolkit
2-
version=1.1.1
2+
version=1.0.5
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=A utility library that other SparkFun libraries can take advantage of.

src/sfTk/sfTkIBus.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ class sfTkIBus
462462
* @param data The data to buffer to read into
463463
* @param numBytes The length of the data buffer
464464
* @param readBytes[out] The number of bytes read
465+
* @param read_delay After sending the address, delay in milliseconds before reading the data
465466
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
466467
*/
467468
virtual sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
468-
size_t &readBytes) = 0;
469+
size_t &readBytes, uint32_t read_delay = 0) = 0;
469470
/**--------------------------------------------------------------------------
470471
* @brief Read a single byte from the given register
471472
*

src/sfTk/sfTkISerialBus.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "sfTkError.h"
1818
#include "sfTkIBus.h"
1919
#include "sfTkISerial.h"
20+
#include "sfToolkit.h"
2021
// clang-format on
2122

2223
const uint8_t ksfTkBusTypeSerialBus = 0x03;
@@ -81,24 +82,30 @@ class sfTkISerialBus : sfTkIBus
8182
* @param data The data to buffer to read into
8283
* @param numBytes The length of the data buffer
8384
* @param readBytes[out] The number of bytes read
85+
* @param read_delay After sending the address, delay in milliseconds before reading the data
8486
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
8587
*/
8688
virtual sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
87-
size_t &readBytes) override
89+
size_t &readBytes, uint32_t read_delay = 0) override
8890
{
8991
// Buffer valid?
9092
if (!data)
9193
return ksfTkErrBusNullBuffer;
9294

95+
if (devReg == nullptr || regLength == 0)
96+
return ksfTkErrInvalidParam;
97+
9398
sfTkError_t retVal = ksfTkErrOk;
9499

95100
// Do we have a register? If so, write it, else skip.
96-
if (devReg != nullptr && regLength > 0)
97-
retVal = write(devReg, regLength);
101+
retVal = write(devReg, regLength);
98102

99103
if (retVal != ksfTkErrOk)
100104
return retVal;
101105

106+
if (read_delay)
107+
sftk_delay_ms(read_delay);
108+
102109
// Read the data.
103110
retVal = read(data, numBytes, readBytes);
104111

src/sfTkArdI2C.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ sfTkError_t sfTkArdI2C::writeRegister(uint8_t *devReg, size_t regLength, const u
138138
* @param data The data to buffer to read into
139139
* @param numBytes The length of the data buffer
140140
* @param readBytes[out] The number of bytes read
141+
* @param read_delay After sending the address, delay in milliseconds before reading the data
141142
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
142143
*/
143144
sfTkError_t sfTkArdI2C::readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
144-
size_t &readBytes)
145+
size_t &readBytes, uint32_t read_delay)
145146
{
146147
// got port
147148
if (!_i2cPort)
@@ -151,6 +152,9 @@ sfTkError_t sfTkArdI2C::readRegister(uint8_t *devReg, size_t regLength, uint8_t
151152
if (!data)
152153
return ksfTkErrBusNullBuffer;
153154

155+
if (devReg == nullptr || regLength == 0)
156+
return ksfTkErrInvalidParam;
157+
154158
readBytes = 0;
155159

156160
uint16_t nOrig = numBytes; // original number of bytes.
@@ -171,6 +175,10 @@ sfTkError_t sfTkArdI2C::readRegister(uint8_t *devReg, size_t regLength, uint8_t
171175
return ksfTkErrFail; // error with the end transmission
172176

173177
bFirstInter = false;
178+
179+
// Was a delay requested between write addr and read bytes
180+
if (read_delay > 0)
181+
delay(read_delay);
174182
}
175183

176184
// We're chunking in data - keeping the max chunk to kMaxI2CBufferLength

src/sfTkArdI2C.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ class sfTkArdI2C : public sfTkII2C
115115
* @param data Pointer to the buffer where the read data will be stored.
116116
* @param numBytes Number of bytes to read from the register.
117117
* @param readBytes Reference to a variable where the number of bytes actually read will be stored.
118+
* @param read_delay After sending the address, delay in milliseconds before reading the data
118119
* @return sfTkError_t Error code indicating the success or failure of the read operation.
119120
*/
120-
sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes);
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);
121123
// Buffer size chunk getter/setter
122124
/**
123125
@brief set the buffer chunk size

src/sfTkArdSPI.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ sfTkError_t sfTkArdSPI::writeRegister(uint16_t devReg, const uint16_t *data, siz
163163
// Returns ksfTkErrOk on success
164164
//
165165
sfTkError_t sfTkArdSPI::readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
166-
size_t &readBytes)
166+
size_t &readBytes, uint32_t read_delay)
167167
{
168168

169169
if (!_spiPort)
@@ -190,6 +190,9 @@ sfTkError_t sfTkArdSPI::readRegister(uint8_t *devReg, size_t regLength, uint8_t
190190
_spiPort->endTransaction();
191191
return ksfTkErrInvalidParam;
192192
}
193+
// Was a delay requested between write addr and read bytes
194+
if (read_delay > 0)
195+
delay(read_delay);
193196

194197
// data now!
195198
for (size_t i = 0; i < numBytes; i++)

src/sfTkArdSPI.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ class sfTkArdSPI : public sfTkISPI
148148
* @param data Pointer to the buffer where the read data will be stored.
149149
* @param numBytes Number of bytes to read from the register.
150150
* @param readBytes Reference to a variable where the number of bytes actually read will be stored.
151+
* @param read_delay After sending the address, delay in milliseconds before reading the data
151152
* @return sfTkError_t Error code indicating the success or failure of the read operation.
152153
*/
153-
sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes);
154+
sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes,
155+
uint32_t read_delay = 0);
154156

155157
/**
156158
@brief Reads a block of data from the given register.

0 commit comments

Comments
 (0)