Skip to content

Commit fcbfc39

Browse files
committed
Initializes the _spiPort pointer, was previously not given anything
* Fixes incorrect use of bitwise OR where logical operator was expected * Removes some unused variables * Removes incorrect statements checking if unsigned integers were less than zero * Rolls version for release
1 parent e143210 commit fcbfc39

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun KX13X Arduino Library
2-
version=1.0.6
2+
version=1.0.7
33
author=SparkFun Electronics <[email protected]>
44
maintainer=Elias Santistevan @ SparkFun Electronics
55
sentence=Communicates and configures the SparkFun KX132/KX134 Accelerometer.

src/SparkFun_Qwiic_KX13X.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uint8_t QwiicKX13xCore::beginSPICore(uint8_t CSPin, uint32_t spiPortSpeed, SPICl
3535
{
3636
_i2cPort = NULL;
3737
_spiPortSpeed = spiPortSpeed;
38+
_spiPort = &spiPort;
3839

3940
if( _spiPortSpeed > 10000000 )
4041
_spiPortSpeed = 10000000;
@@ -70,7 +71,7 @@ uint8_t QwiicKX13xCore::beginSPICore(uint8_t CSPin, uint32_t spiPortSpeed, SPICl
7071
bool QwiicKX13xCore::initialize(uint8_t settings)
7172
{
7273

73-
KX13X_STATUS_t returnError;
74+
KX13X_STATUS_t returnError = KX13X_GENERAL_ERROR;
7475
if( !accelControl(false) ){
7576
return false;
7677
}
@@ -133,7 +134,7 @@ uint8_t QwiicKX13xCore::readAccelState(){
133134
// Possible KX134 arguments: 0x00 (8g), 0x01 (16g), 0x02 (32g), 0x03 (64g)
134135
bool QwiicKX13xCore::setRange(uint8_t range){
135136

136-
if( range < 0 | range > 3)
137+
if( range > 3)
137138
return false;
138139

139140
uint8_t accelState = readAccelState();
@@ -156,7 +157,7 @@ bool QwiicKX13xCore::setRange(uint8_t range){
156157
// 0.781 * (2 * (n)) derived from pg. 26 of Techincal Reference Manual
157158
bool QwiicKX13xCore::setOutputDataRate(uint8_t rate){
158159

159-
if( rate < 0 | rate > 15 )
160+
if( rate > 15 )
160161
return false;
161162

162163
uint8_t accelState = readAccelState(); // Put it back where we found it.
@@ -197,8 +198,6 @@ bool QwiicKX13xCore::setInterruptPin(bool enable, uint8_t polarity, uint8_t puls
197198
return false;
198199
else if( pulseWidth != 1 && pulseWidth != 0 )
199200
return false;
200-
else if( latchControl < 0 | latchControl > 4 )
201-
return false;
202201

203202
uint8_t accelState = readAccelState(); // Put it back where we found it.
204203
accelControl(false); // Can't adjust without putting to sleep
@@ -220,7 +219,7 @@ bool QwiicKX13xCore::setInterruptPin(bool enable, uint8_t polarity, uint8_t puls
220219
// interrupt pin one or pin two.
221220
bool QwiicKX13xCore::routeHardwareInterrupt(uint8_t rdr, uint8_t pin){
222221

223-
if( rdr < 0 | rdr > 128 )
222+
if( rdr > 128 )
224223
return false;
225224
if( pin != 1 && pin != 2)
226225
return false;
@@ -287,7 +286,7 @@ bool QwiicKX13xCore::dataTrigger(){
287286
// set in the BUF_CNTL2 (0x5F) register (see "setBufferOperation" below).
288287
bool QwiicKX13xCore::setBufferThreshold(uint8_t threshold){
289288

290-
if( threshold < 2 | threshold > 171 )
289+
if( threshold < 2 || threshold > 171 )
291290
return false;
292291

293292

@@ -300,7 +299,7 @@ bool QwiicKX13xCore::setBufferThreshold(uint8_t threshold){
300299
return false;
301300

302301
if( threshold > 86 && resolution == 1 ) // 1 = 16bit resolution, max samples: 86
303-
threshold == 86;
302+
threshold = 86;
304303

305304
returnError = writeRegister(KX13X_BUF_CNTL1, 0x00, threshold, 0);
306305
if( returnError == KX13X_SUCCESS )
@@ -316,9 +315,9 @@ bool QwiicKX13xCore::setBufferThreshold(uint8_t threshold){
316315
// to be powered own to adjust settings.
317316
bool QwiicKX13xCore::setBufferOperation(uint8_t operationMode, uint8_t resolution){
318317

319-
if( resolution < 0 | resolution > 1 )
318+
if( resolution > 1 )
320319
return false;
321-
if( operationMode < 0 | operationMode > 2 )
320+
if( operationMode > 2 )
322321
return false;
323322

324323

@@ -438,7 +437,7 @@ KX13X_STATUS_t QwiicKX13xCore::readRegister(uint8_t *dataPointer, uint8_t reg)
438437
}
439438

440439
//Sends a request to read a number of registers
441-
KX13X_STATUS_t QwiicKX13xCore::readMultipleRegisters(uint8_t reg, uint8_t dataBuffer[], int16_t numBytes)
440+
KX13X_STATUS_t QwiicKX13xCore::readMultipleRegisters(uint8_t reg, uint8_t dataBuffer[], uint16_t numBytes)
442441
{
443442

444443
if( _i2cPort == NULL ) {
@@ -590,8 +589,6 @@ bool QwiicKX132::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPor
590589
// converted.
591590
outputData QwiicKX132::getAccelData(){
592591

593-
uint8_t tempRegVal;
594-
KX13X_STATUS_t returnError;
595592
if( getRawAccelData(&rawAccelData) &&
596593
convAccelData(&userAccel, &rawAccelData) )
597594
return userAccel;
@@ -679,8 +676,6 @@ bool QwiicKX134::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPor
679676
// converted.
680677
outputData QwiicKX134::getAccelData(){
681678

682-
uint8_t tempRegVal;
683-
KX13X_STATUS_t returnError;
684679
if( getRawAccelData(&rawAccelData) &&
685680
convAccelData(&userAccel, &rawAccelData) )
686681
return userAccel;

src/SparkFun_Qwiic_KX13X.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class QwiicKX13xCore
212212

213213
KX13X_STATUS_t readRegister(uint8_t*, uint8_t);
214214
KX13X_STATUS_t writeRegister(uint8_t, uint8_t, uint8_t, uint8_t);
215-
KX13X_STATUS_t readMultipleRegisters(uint8_t, uint8_t dataBuffer[] , int16_t);
215+
KX13X_STATUS_t readMultipleRegisters(uint8_t, uint8_t dataBuffer[] , uint16_t);
216216
KX13X_STATUS_t overBufLenI2CRead(uint8_t, uint8_t dataBuffer[] , int16_t);
217217

218218
// CPOL and CPHA are demonstrated on pg 25 of Specification Data sheet

0 commit comments

Comments
 (0)