Skip to content

Commit 58a3ced

Browse files
committed
Finishes remaining comments on functions and src files, updates properties file
1 parent 6e22e04 commit 58a3ced

File tree

6 files changed

+108
-15
lines changed

6 files changed

+108
-15
lines changed

examples/Ex1_BasicReadings/Ex1_BasicReadings.ino

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*********************************************************
2+
Author: Elias Santistevan @ SparkFun Electronics
3+
Date: 5/2021
4+
Library repository can be found here:
5+
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
6+
7+
Basic example for reading back accelerometer values using I2C.
8+
9+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
10+
11+
Please review the LICENSE.md file included with this example. If you have any questions
12+
or concerns with licensing, please contact [email protected].
13+
14+
Distributed as-is; no warranty is given.
15+
*******************************************************/
16+
117
#include <Wire.h>
218
#include "SparkFun_Qwiic_KX13X.h"
319

420
QwiicKX132 kxAccel;
21+
//QwiicKX134 kxAccel; // Uncomment this if using the KX134 - check your board
22+
//if unsure.
523
outputData myData; // This will hold the accelerometer's output.
624

725
void setup() {
@@ -24,20 +42,21 @@ void setup() {
2442

2543

2644

27-
if( !kxAccel.initialize(DEFAULT_SETTINGS)){
45+
if( !kxAccel.initialize(DEFAULT_SETTINGS)){ // Loading default settings.
2846
Serial.println("Could not initialize the chip.");
2947
while(1);
3048
}
3149
else
3250
Serial.println("Initialized...");
3351

3452
// kxAccel.setRange(KX132_RANGE16G);
53+
// kxAccel.setRange(KX134_RANGE32G); // For a larger range uncomment
3554

3655
}
3756

3857
void loop() {
3958

40-
myData = kxAccel.getAccelData();
59+
myData = kxAccel.getAccelData();
4160
Serial.print("X: ");
4261
Serial.print(myData.xData, 4);
4362
Serial.print("g ");

examples/Ex2_Interrupts/Ex2_Interrupts.ino

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
/*********************************************************
2+
Author: Elias Santistevan @ SparkFun Electronics
3+
Date: 5/2021
4+
Library repository can be found here:
5+
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
6+
7+
This example demonstrates the use of hardware interrupts for synchronizing
8+
acceleromter data using I2C.
9+
10+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
11+
12+
Please review the LICENSE.md file included with this example. If you have any questions
13+
or concerns with licensing, please contact [email protected].
14+
15+
Distributed as-is; no warranty is given.
16+
*******************************************************/
117
#include <Wire.h>
218
#include "SparkFun_Qwiic_KX13X.h"
319

420
QwiicKX132 kxAccel;
21+
//QwiicKX134 kxAccel; // Uncomment this if using the KX134 - check your board
22+
//if unsure.
23+
524
outputData myData; // This will hold the accelerometer's output.
6-
int dataReadyPin = D1;
25+
int dataReadyPin = 3;
726

827
void setup() {
928

@@ -26,15 +45,15 @@ void setup() {
2645

2746

2847

29-
if( !kxAccel.initialize(INT_SETTINGS)){
48+
if( !kxAccel.initialize(INT_SETTINGS)){ // Load preset interrupt settings.
3049
Serial.println("Could not initialize the chip. Freezing.");
3150
while(1);
3251
}
3352
else
3453
Serial.println("Initialized...");
3554

3655
// kxAccel.setRange(KX132_RANGE16G);
37-
56+
// kxAccel.setRange(KX134_RANGE32G); // For a larger range uncomment
3857
}
3958

4059
void loop() {

examples/Ex3_SoftwareInterrupts/Ex3_SoftwareInterrupts.ino

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*********************************************************
2+
Author: Elias Santistevan @ SparkFun Electronics
3+
Date: 5/2021
4+
Library repository can be found here:
5+
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
6+
7+
This example demonstrates the use of software interrupts for synchronizing
8+
acceleromter data using I2C.
9+
10+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
11+
12+
Please review the LICENSE.md file included with this example. If you have any questions
13+
or concerns with licensing, please contact [email protected].
14+
15+
Distributed as-is; no warranty is given.
16+
*******************************************************/
117
#include <Wire.h>
218
#include "SparkFun_Qwiic_KX13X.h"
319

420
QwiicKX132 kxAccel;
21+
//QwiicKX134 kxAccel; // Uncomment this if using the KX134 - check your board
22+
//if unsure.
523
outputData myData; // This will hold the accelerometer's output.
624

725
void setup() {
@@ -23,15 +41,15 @@ void setup() {
2341

2442

2543

26-
if( !kxAccel.initialize(SOFT_INT_SETTINGS)){
44+
if( !kxAccel.initialize(SOFT_INT_SETTINGS)){ //Load preset software interrupt settings.
2745
Serial.println("Could not initialize the chip. Freezing.");
2846
while(1);
2947
}
3048
else
3149
Serial.println("Initialized...");
3250

3351
// kxAccel.setRange(KX132_RANGE16G);
34-
52+
// kxAccel.setRange(KX134_RANGE32G); // For a larger range uncomment
3553
}
3654

3755
void loop() {

examples/Ex4_Buffer/Ex4_Buffer.ino

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*********************************************************
2+
Author: Elias Santistevan @ SparkFun Electronics
3+
Date: 5/2021
4+
Library repository can be found here:
5+
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
6+
7+
This example routes the accelerometer data to the buffer and then reads it when
8+
its full.
9+
10+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
11+
12+
Please review the LICENSE.md file included with this example. If you have any questions
13+
or concerns with licensing, please contact [email protected].
14+
15+
Distributed as-is; no warranty is given.
16+
*******************************************************/
117
#include <Wire.h>
218
#include "SparkFun_Qwiic_KX13X.h"
319

420
QwiicKX132 kxAccel;
21+
//QwiicKX134 kxAccel; // Uncomment this if using the KX134 - check your board
22+
//if unsure.
523
outputData myData; // This will hold the accelerometer's output.
624
int dataReadyPin = D1;
725

@@ -24,16 +42,15 @@ void setup() {
2442
else
2543
Serial.println("Ready.");
2644

27-
28-
29-
if( !kxAccel.initialize(BUFFER_SETTINGS)){
45+
if( !kxAccel.initialize(BUFFER_SETTINGS)){ //Load preset buffer settings.
3046
Serial.println("Could not initialize the chip. Freezing.");
3147
while(1);
3248
}
3349
else
3450
Serial.println("Initialized...");
3551

3652
// kxAccel.setRange(KX132_RANGE16G);
53+
// kxAccel.setRange(KX134_RANGE32G); // For a larger range uncomment
3754

3855
}
3956

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=SparkFun Qwiic KX13X Arduino Library
2-
version=0.0.1
1+
name=SparkFun KX13X Arduino Library
2+
version=v1.0.0
33
author=SparkFun Electronics <[email protected]>
44
maintainer=Elias Santistevan @ SparkFun Electronics
5-
sentence=Communicates and configures the SparkFun Qwiic PIR.
6-
paragraph=This library allows the user to see if there is currently an object detected in front of the SparkFun PIR as well as allows for reading of detection events from a buffer.
5+
sentence=Communicates and configures the SparkFun KX132/KX134 Accelerometer.
6+
paragraph=This library breaks out all the functionality of the Kionix KX132 and KX134.
77
category=Sensors
88
url=
99
architectures=*

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ bool QwiicKX13xCore::getRawAccelData(rawOutputData *rawAccelData){
412412
}
413413

414414

415+
// Reads a single register using the selected bus.
415416
KX13X_STATUS_t QwiicKX13xCore::readRegister(uint8_t *dataPointer, uint8_t reg)
416417
{
417418

@@ -485,6 +486,8 @@ KX13X_STATUS_t QwiicKX13xCore::readMultipleRegisters(uint8_t reg, uint8_t dataBu
485486
}
486487
}
487488

489+
// This function is used when more than 32 bytes (TwoWire maximum buffer
490+
// length) of data are requested.
488491
KX13X_STATUS_t QwiicKX13xCore::overBufLenI2CRead(uint8_t reg, uint8_t dataBuffer[], int16_t numBytes)
489492
{
490493
uint8_t resizedRead;
@@ -519,6 +522,8 @@ KX13X_STATUS_t QwiicKX13xCore::overBufLenI2CRead(uint8_t reg, uint8_t dataBuffer
519522
return KX13X_SUCCESS;
520523
}
521524

525+
// Writes the given value to the given register, using the provided mask and
526+
// bit position.
522527
KX13X_STATUS_t QwiicKX13xCore::writeRegister(uint8_t reg, uint8_t mask, uint8_t data, uint8_t bitPos)
523528
{
524529

@@ -563,8 +568,11 @@ KX13X_STATUS_t QwiicKX13xCore::writeRegister(uint8_t reg, uint8_t mask, uint8_t
563568
//******************************************************************************************
564569
//******************************************************************************************
565570

571+
// Constructor
566572
QwiicKX132::QwiicKX132() { }
567573

574+
// Uses the beginCore function to check that the part ID from the "who am I"
575+
// register matches the correct value. Uses I2C for data transfer.
568576
bool QwiicKX132::begin(uint8_t kxAddress, TwoWire &i2cPort){
569577

570578
if( kxAddress != KX13X_DEFAULT_ADDRESS && kxAddress != KX13X_ALT_ADDRESS )
@@ -578,6 +586,8 @@ bool QwiicKX132::begin(uint8_t kxAddress, TwoWire &i2cPort){
578586

579587
}
580588

589+
// Uses the beginCore function to check that the part ID from the "who am I"
590+
// register matches the correct value. Uses SPI for data transfer.
581591
bool QwiicKX132::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPort){
582592

583593
uint8_t partID = beginSPICore(csPin, spiPortSpeed, spiPort);
@@ -587,8 +597,9 @@ bool QwiicKX132::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPor
587597
return false;
588598
}
589599

600+
// Grabs raw accel data and passes it to the following function to be
601+
// converted.
590602
outputData QwiicKX132::getAccelData(){
591-
592603

593604
uint8_t tempRegVal;
594605
KX13X_STATUS_t returnError;
@@ -603,6 +614,7 @@ outputData QwiicKX132::getAccelData(){
603614
}
604615
}
605616

617+
// Converts acceleration data according to the set range value.
606618
bool QwiicKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelData){
607619

608620
uint8_t regVal;
@@ -646,8 +658,11 @@ bool QwiicKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelDat
646658
//******************************************************************************************
647659
//******************************************************************************************
648660

661+
//Constructor
649662
QwiicKX134::QwiicKX134() { }
650663

664+
// Uses the beginCore function to check that the part ID from the "who am I"
665+
// register matches the correct value. Uses I2C for data transfer.
651666
bool QwiicKX134::begin(uint8_t kxAddress, TwoWire &i2cPort){
652667

653668
if( kxAddress != KX13X_DEFAULT_ADDRESS && kxAddress != KX13X_ALT_ADDRESS )
@@ -661,6 +676,8 @@ bool QwiicKX134::begin(uint8_t kxAddress, TwoWire &i2cPort){
661676
}
662677

663678

679+
// Uses the beginCore function to check that the part ID from the "who am I"
680+
// register matches the correct value. Uses SPI for data transfer.
664681
bool QwiicKX134::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPort){
665682

666683
uint8_t partID = beginSPICore(csPin, spiPortSpeed, spiPort);
@@ -670,6 +687,8 @@ bool QwiicKX134::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, SPIClass &spiPor
670687
return false;
671688
}
672689

690+
// Grabs raw accel data and passes it to the following function to be
691+
// converted.
673692
outputData QwiicKX134::getAccelData(){
674693

675694
uint8_t tempRegVal;
@@ -686,6 +705,7 @@ outputData QwiicKX134::getAccelData(){
686705

687706
}
688707

708+
// Converts acceleration data according to the set range value.
689709
bool QwiicKX134::convAccelData(outputData *userAccel, rawOutputData *rawAccelData){
690710

691711
uint8_t regVal;

0 commit comments

Comments
 (0)