Skip to content

Commit a8543e2

Browse files
committed
Adds many comments
1 parent 21cefb7 commit a8543e2

File tree

2 files changed

+178
-28
lines changed

2 files changed

+178
-28
lines changed

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 176 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool QwDevKX13X::softwareReset()
123123
}
124124

125125
//////////////////////////////////////////////////
126-
// softwareReset()
126+
// enableAccel()
127127
//
128128
// Enables acceleromter data. In addition
129129
// some settings can only be set when the accelerometer is
@@ -162,15 +162,15 @@ bool QwDevKX13X::enableAccel(bool enable)
162162
// Retrieves the current operating mode - low/high power mode
163163
//
164164

165-
uint8_t QwDevKX13X::getOperatingMode(){
165+
int8_t QwDevKX13X::getOperatingMode(){
166166

167167
uint8_t tempVal;
168168
int retVal;
169169

170170
retVal = readRegisterRegion(SFE_KX13X_CNTL1, &tempVal, 1);
171171

172172
if( retVal != 0 )
173-
return 2; // Not a possible value for the PC1 bit.
173+
return retVal;
174174

175175
return (tempVal >> 7);
176176

@@ -572,9 +572,16 @@ bool QwDevKX13X::setPulseWidth(uint8_t width, uint8_t pin)
572572
}
573573

574574

575-
// Address: 0x25, bits[7:0]: default value is 0: disabled
576-
// Enables anyone of the various interrupt settings to be routed to hardware
577-
// interrupt pin one or pin two.
575+
//////////////////////////////////////////////////
576+
// setPulseWidth()
577+
//
578+
// This determines which interrupt is routed to a particular physical
579+
// interrupt pin.
580+
//
581+
// Parameters:
582+
// rdr - The selected interrupt - watermark, tap/double tap, tilt, data ready etc.
583+
// pin - The physical hardware pin that will receive the interrupt.
584+
//
578585
bool QwDevKX13X::routeHardwareInterrupt(uint8_t rdr, uint8_t pin)
579586
{
580587

@@ -604,9 +611,12 @@ bool QwDevKX13X::routeHardwareInterrupt(uint8_t rdr, uint8_t pin)
604611

605612
}
606613

607-
// Address: 0x1A , bit[7:0]: default value is: 0x00
608-
// This function reads the interrupt latch release register, thus clearing any
609-
// interrupts.
614+
615+
//////////////////////////////////////////////////
616+
// clearInterrupt()
617+
//
618+
// Clears any latched interrupt by reading the INT_REL register.
619+
//
610620
bool QwDevKX13X::clearInterrupt()
611621
{
612622

@@ -621,6 +631,14 @@ bool QwDevKX13X::clearInterrupt()
621631
return true;
622632
}
623633

634+
//////////////////////////////////////////////////
635+
// enableDirecTapInterupt()
636+
//
637+
// Enables reporting on the direction of the latest generated tap.
638+
//
639+
// Parameter:
640+
// enable - enables/disables directional tap reporting.
641+
//
624642
bool QwDevKX13X::enableDirecTapInterupt(bool enable)
625643
{
626644
int retVal;
@@ -641,7 +659,16 @@ bool QwDevKX13X::enableDirecTapInterupt(bool enable)
641659
return true;
642660
}
643661

644-
bool QwDevKX13X::enableDoubleTapInterupt(bool enable)
662+
663+
//////////////////////////////////////////////////
664+
// enableDirecTapInterupt()
665+
//
666+
// Enables the double tap interrupt.
667+
//
668+
// Parameter:
669+
// enable - enables/disables the double tap interrupt
670+
//
671+
bool QwDevKX13X::enableDoubleTapInterrupt(bool enable)
645672
{
646673
int retVal;
647674
uint8_t tempVal;
@@ -661,6 +688,14 @@ bool QwDevKX13X::enableDoubleTapInterupt(bool enable)
661688
return true;
662689
}
663690

691+
//////////////////////////////////////////////////
692+
// dataReady()
693+
//
694+
// Checks the data ready bit indicating new accelerometer data
695+
// is ready in the X/Y/Z Out regsiters. This is cleared automatically
696+
// on read.
697+
//
698+
//
664699
bool QwDevKX13X::dataReady()
665700
{
666701

@@ -678,6 +713,12 @@ bool QwDevKX13X::dataReady()
678713
return false;
679714
}
680715

716+
//////////////////////////////////////////////////
717+
// freeFall()
718+
//
719+
// Checks the free fall interrupt bit indicating free fall
720+
// has been detected.
721+
//
681722
bool QwDevKX13X::freeFall()
682723
{
683724

@@ -695,6 +736,13 @@ bool QwDevKX13X::freeFall()
695736
return false;
696737
}
697738

739+
740+
//////////////////////////////////////////////////
741+
// bufferFull()
742+
//
743+
// Checks the buffer full interrupt bit indicating that the
744+
// buff is full.
745+
//
698746
bool QwDevKX13X::bufferFull()
699747
{
700748

@@ -712,6 +760,13 @@ bool QwDevKX13X::bufferFull()
712760
return false;
713761
}
714762

763+
764+
//////////////////////////////////////////////////
765+
// waterMarkReached()
766+
//
767+
// Checks the watermark interrupt bit indicating it has been reached.
768+
// buff is full.
769+
//
715770
bool QwDevKX13X::waterMarkReached()
716771
{
717772

@@ -729,6 +784,13 @@ bool QwDevKX13X::waterMarkReached()
729784
return false;
730785
}
731786

787+
788+
//////////////////////////////////////////////////
789+
// tapDetected()
790+
//
791+
// Checks the tap interrupt bit indicating that a tap has
792+
// been detected.
793+
//
732794
bool QwDevKX13X::tapDetected()
733795
{
734796

@@ -750,6 +812,12 @@ bool QwDevKX13X::tapDetected()
750812
return false;
751813
}
752814

815+
//////////////////////////////////////////////////
816+
// getDirection()
817+
//
818+
// If the tap direction bit is enabled, this register will report
819+
// the direction of the detected tap.
820+
//
753821
int8_t QwDevKX13X::getDirection()
754822
{
755823

@@ -764,6 +832,14 @@ int8_t QwDevKX13X::getDirection()
764832
return tempVal;
765833
}
766834

835+
836+
//////////////////////////////////////////////////
837+
// unknowntap()
838+
//
839+
// if the accelerometer is unsure whether it has in fact
840+
// detected a tap, it will report an "unknown" state. in that
841+
// case this function will return true. good for error checking.
842+
//
767843
bool QwDevKX13X::unknownTap()
768844
{
769845

@@ -784,6 +860,13 @@ bool QwDevKX13X::unknownTap()
784860
return false;
785861
}
786862

863+
864+
//////////////////////////////////////////////////
865+
// doubleTapDetected()
866+
//
867+
// Checks the double tap interrupt bit indicating that
868+
// a double tap has been detected.
869+
//
787870
bool QwDevKX13X::doubleTapDetected()
788871
{
789872

@@ -804,6 +887,13 @@ bool QwDevKX13X::doubleTapDetected()
804887
return false;
805888
}
806889

890+
891+
//////////////////////////////////////////////////
892+
// tiltChange()
893+
//
894+
// Checks the tilt change interrupt bit indicating that
895+
// the accelerometer has been tipped.
896+
//
807897
bool QwDevKX13X::tiltChange()
808898
{
809899

@@ -821,11 +911,17 @@ bool QwDevKX13X::tiltChange()
821911
return false;
822912
}
823913

824-
// Address: 0x5E , bit[7:0]: default value is: unknown
825-
// This function sets the number of samples (not bytes) that are held in the
826-
// buffer. Each sample is one full word of X,Y,Z data and the minimum that this
827-
// can be set to is two. The maximum is dependent on the resolution: 8 or 16bit,
828-
// set in the BUF_CNTL2 (0x5F) register (see "setBufferOperation" below).
914+
915+
//////////////////////////////////////////////////
916+
// setBufferThreshold()
917+
//
918+
// Sets the number of samples that can be held in the buffer.
919+
//
920+
// Parameter:
921+
// threshold - This value determines the number of samples that
922+
// will be store in the buffer. Can not exceed 171 for 8 bit resolution
923+
// and 86 for 16 bit resolution.
924+
//
829925
bool QwDevKX13X::setBufferThreshold(uint8_t threshold)
830926
{
831927

@@ -855,10 +951,15 @@ bool QwDevKX13X::setBufferThreshold(uint8_t threshold)
855951

856952
}
857953

858-
// Address: 0x5F, bits[6] and bits[1:0]: default value is: 0x00
859-
// This functions sets the resolution and operation mode of the buffer. This does not include
860-
// the threshold - see "setBufferThreshold". This is a "On-the-fly" register, accel does not need
861-
// to be powered own to adjust settings.
954+
955+
//////////////////////////////////////////////////
956+
// setBufferOperationMode()
957+
//
958+
// Sets the opertion mode of the Buffer: Bypass, FIFO, Stream, Trigger
959+
//
960+
// Parameter:
961+
// operationMode - Determines the operation mode to set.
962+
//
862963
bool QwDevKX13X::setBufferOperationMode(uint8_t operationMode)
863964
{
864965

@@ -883,6 +984,15 @@ bool QwDevKX13X::setBufferOperationMode(uint8_t operationMode)
883984
return true;
884985
}
885986

987+
988+
//////////////////////////////////////////////////
989+
// setBufferResolution()
990+
//
991+
// Sets the resoltuion of the data that is stored in the buffer: 8 or 16 bit.
992+
//
993+
// Parameter:
994+
// sixteenBit - Determines whether the resolution is 16 (true) or 8 bit (false).
995+
//
886996
bool QwDevKX13X::setBufferResolution(bool sixteenBit )
887997
{
888998
int retVal;
@@ -904,6 +1014,15 @@ bool QwDevKX13X::setBufferResolution(bool sixteenBit )
9041014
}
9051015

9061016

1017+
1018+
//////////////////////////////////////////////////
1019+
// enableBufferInt()
1020+
//
1021+
// Enables the buffer full interrupt bit.
1022+
//
1023+
// Parameter:
1024+
// enable - enable/disables the buffer full interrupt bit.
1025+
//
9071026
bool QwDevKX13X::enableBufferInt(bool enable)
9081027
{
9091028
int retVal;
@@ -924,6 +1043,15 @@ bool QwDevKX13X::enableBufferInt(bool enable)
9241043
return true;
9251044
}
9261045

1046+
1047+
//////////////////////////////////////////////////
1048+
// enableSampleBuffer()
1049+
//
1050+
// Enables use of the buffer.
1051+
//
1052+
// Parameter:
1053+
// enable - enable/disables the buffer.
1054+
//
9271055
bool QwDevKX13X::enableSampleBuffer(bool enable)
9281056
{
9291057
int retVal;
@@ -944,6 +1072,13 @@ bool QwDevKX13X::enableSampleBuffer(bool enable)
9441072
return true;
9451073
}
9461074

1075+
1076+
1077+
//////////////////////////////////////////////////
1078+
// getSampleLevel()
1079+
//
1080+
// Gets the number of samples in the Buffer.
1081+
//
9471082
uint16_t QwDevKX13X::getSampleLevel()
9481083
{
9491084
int retVal;
@@ -961,6 +1096,12 @@ uint16_t QwDevKX13X::getSampleLevel()
9611096
return numSamples;
9621097
}
9631098

1099+
1100+
//////////////////////////////////////////////////
1101+
// clearBuffer()
1102+
//
1103+
// Clears the samples in the buffer.
1104+
//
9641105
bool QwDevKX13X::clearBuffer()
9651106
{
9661107
int retVal;
@@ -973,10 +1114,13 @@ bool QwDevKX13X::clearBuffer()
9731114

9741115
return true;
9751116
}
976-
// Address: 0x1C, bit[6]: default value is: 0x00
977-
//Tests functionality of the integrated circuit by setting the command test
978-
//control bit, then checks the results in the COTR register (0x12): 0xAA is a
979-
//successful read, 0x55 is the default state.
1117+
1118+
//////////////////////////////////////////////////
1119+
// runCommandTest()
1120+
//
1121+
// Runs the command test which verifies the circuitry connected to
1122+
// the accelerometer.
1123+
//
9801124
bool QwDevKX13X::runCommandTest()
9811125
{
9821126

@@ -1011,9 +1155,15 @@ bool QwDevKX13X::runCommandTest()
10111155
return true;
10121156
}
10131157

1014-
// Address:0x08 - 0x0D or 0x63 , bit[7:0]
1015-
// Reads acceleration data from either the buffer or the output registers
1016-
// depending on if the user specified buffer usage.
1158+
1159+
//////////////////////////////////////////////////
1160+
// getRawAccelData()
1161+
//
1162+
// Retrieves the raw register values representing accelerometer data.
1163+
//
1164+
// Paramater:
1165+
// *rawAccelData - This pointer to the
1166+
//
10171167
bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
10181168

10191169

src/SparkFun_Qwiic_KX13X.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class QwDevKX13X
132132
// General Settings
133133
bool enableAccel(bool enable = true);
134134
bool softwareReset();
135-
uint8_t getOperatingMode();
135+
int8_t getOperatingMode();
136136
bool setRange(uint8_t);
137137
bool setInterruptPin(bool enable, uint8_t polarity = 0, uint8_t pulseWidth = 0, bool latchControl = false);
138138
bool enableDataEngine(bool enable = true);
@@ -155,7 +155,7 @@ class QwDevKX13X
155155
bool setLatchControl(bool latch = true, uint8_t pin = 1);
156156
bool setPulseWidth(uint8_t width, uint8_t pin = 1);
157157
bool enableDirecTapInterupt(bool enable = true);
158-
bool enableDoubleTapInterupt(bool enable = true);
158+
bool enableDoubleTapInterrupt(bool enable = true);
159159
bool clearInterrupt();
160160
bool tapDetected();
161161
int8_t getDirection();

0 commit comments

Comments
 (0)