Skip to content

Commit 6e22e04

Browse files
committed
Adds comments to most of the functions
1 parent 2d5e966 commit 6e22e04

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

examples/Ex1_BasicReadings/Ex1_BasicReadings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <Wire.h>
22
#include "SparkFun_Qwiic_KX13X.h"
33

4-
QwiicKX134 kxAccel;
4+
QwiicKX132 kxAccel;
55
outputData myData; // This will hold the accelerometer's output.
66

77
void setup() {

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Original Creation Date: March, 2021
77
This file implements the QwiicKX13XCore, QwiicKX132, and QwiicKX134 class
88
99
Development environment specifics:
10-
IDE: Arduino 1.8.12
10+
IDE: Arduino 1.8.12
1111
1212
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
1313
local, and you've found our code helpful, please buy us a round!
@@ -64,6 +64,9 @@ uint8_t QwiicKX13xCore::beginSPICore(uint8_t CSPin, uint32_t spiPortSpeed, SPICl
6464
return partID;
6565
}
6666

67+
// This function sets various register with regards to these pre-determined
68+
// settings. These settings are set according to "AN092 Getting Started" guide and can easily
69+
// have additional presets added.
6770
bool QwiicKX13xCore::initialize(uint8_t settings)
6871
{
6972

@@ -97,6 +100,9 @@ bool QwiicKX13xCore::initialize(uint8_t settings)
97100
return false;
98101
}
99102

103+
// Address: 0x1B, bit[7]: default value is: 0x00
104+
// This function sets the accelerometer into stand-by mode or
105+
// an active mode depending on the given argument.
100106
bool QwiicKX13xCore::accelControl(bool standby){
101107

102108
if( standby != true && standby != false )
@@ -111,14 +117,20 @@ bool QwiicKX13xCore::accelControl(bool standby){
111117

112118
}
113119

120+
// Address: 0x1B, bit[7]: default value is: 0x00
121+
// This function reads whether the accelerometer is in stand by or an active
122+
// mode.
114123
uint8_t QwiicKX13xCore::readAccelState(){
115124

116125
uint8_t tempRegVal;
117126
readRegister(&tempRegVal, KX13X_CNTL1);
118127
return (tempRegVal & 0x80) >> 7;
119128

120129
}
121-
130+
// Address: 0x1B, bit[1:0]: default value is: 0x00 (2g)
131+
// This function sets the acceleration range of the accelerometer outputs.
132+
// Possible KX132 arguments: 0x00 (2g), 0x01 (4g), 0x02 (8g), 0x03 (16g)
133+
// Possible KX134 arguments: 0x00 (8g), 0x01 (16g), 0x02 (32g), 0x03 (64g)
122134
bool QwiicKX13xCore::setRange(uint8_t range){
123135

124136
if( range < 0 | range > 3)
@@ -139,7 +151,7 @@ bool QwiicKX13xCore::setRange(uint8_t range){
139151
}
140152

141153

142-
//Address: 0x21, bits[3:0] - default value is 50Hz: 0b0110
154+
//Address: 0x21, bits[3:0] - default value is 0x06 (50Hz)
143155
//Sets the refresh rate of the accelerometer's data.
144156
// 0.781 * (2 * (n)) derived from pg. 26 of Techincal Reference Manual
145157
bool QwiicKX13xCore::setOutputDataRate(uint8_t rate){
@@ -151,7 +163,7 @@ bool QwiicKX13xCore::setOutputDataRate(uint8_t rate){
151163
accelControl(false); // Can't adjust without putting to sleep
152164

153165
KX13X_STATUS_t returnError;
154-
returnError = writeRegister(KX13X_ODCNTL, 0x40, rate, 0);
166+
returnError = writeRegister(KX13X_ODCNTL, 0xF0, rate, 0);
155167
if( returnError == KX13X_SUCCESS )
156168
return true;
157169
else
@@ -164,11 +176,13 @@ bool QwiicKX13xCore::setOutputDataRate(uint8_t rate){
164176
return false;
165177
}
166178

179+
// Address:0x21 , bit[3:0]: default value is: 0x06 (50Hz)
180+
// Gets the accelerometer's output data rate.
167181
float QwiicKX13xCore::readOutputDataRate(){
168182

169183
uint8_t tempRegVal;
170184
readRegister(&tempRegVal, KX13X_ODCNTL);
171-
tempRegVal &= 0x40;
185+
tempRegVal &= 0x0F;
172186
tempRegVal = (float)tempRegVal;
173187
return (0.78 * (2 * tempRegVal));
174188

@@ -238,8 +252,9 @@ bool QwiicKX13xCore::routeHardwareInterrupt(uint8_t rdr, uint8_t pin){
238252

239253
}
240254

241-
242-
255+
// Address: 0x1A , bit[7:0]: default value is: 0x00
256+
// This function reads the interrupt latch release register, thus clearing any
257+
// interrupts.
243258
bool QwiicKX13xCore::clearInterrupt(){
244259

245260
uint8_t tempRegVal;
@@ -340,7 +355,10 @@ bool QwiicKX13xCore::enableBuffer(bool enable, bool enableInterrupt){
340355
return false;
341356
}
342357

343-
//Tests functionality of the integrated circuit
358+
// Address: 0x1C, bit[6]: default value is: 0x00
359+
//Tests functionality of the integrated circuit by setting the command test
360+
//control bit, then checks the results in the COTR register (0x12): 0xAA is a
361+
//successful read, 0x55 is the default state.
344362
bool QwiicKX13xCore::runCommandTest()
345363
{
346364

@@ -358,6 +376,9 @@ bool QwiicKX13xCore::runCommandTest()
358376
return false;
359377
}
360378

379+
// Address:0x08 - 0x0D or 0x63 , bit[7:0]
380+
// Reads acceleration data from either the buffer or the output registers
381+
// depending on if the user specified buffer usage.
361382
bool QwiicKX13xCore::getRawAccelData(rawOutputData *rawAccelData){
362383

363384

0 commit comments

Comments
 (0)