Skip to content

Commit 85550b2

Browse files
committed
Completes comments on all function
* Removes unused defines
1 parent a8543e2 commit 85550b2

File tree

2 files changed

+106
-89
lines changed

2 files changed

+106
-89
lines changed

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ uint8_t QwDevKX13X::getUniqueID()
3434
//
3535
// Method to set the bus object that is used to communicate with the device
3636
//
37-
// Parameter Description
38-
// --------- -----------------------------
39-
// theBus The communication bus object
40-
// i2cAddress I2C address for the 6DoF
41-
37+
// Parameter:
38+
// theBus-The communication bus object
39+
// i2cAddress-I2C address for the 6DoF
4240
void QwDevKX13X::setCommunicationBus(QwIDeviceBus &theBus, uint8_t i2cAddress)
4341
{
4442
_sfeBus = &theBus;
@@ -50,11 +48,9 @@ void QwDevKX13X::setCommunicationBus(QwIDeviceBus &theBus, uint8_t i2cAddress)
5048
//
5149
// Overloaded option for setting the data bus (theBus) object to a SPI bus object.
5250
//
53-
// Parameter Description
54-
// --------- -----------------------------
55-
// theBus The communication bus object
51+
// Parameter:
52+
// theBus-The communication bus object
5653
//
57-
5854
void QwDevKX13X::setCommunicationBus(QwIDeviceBus &theBus)
5955
{
6056
_sfeBus = &theBus;
@@ -103,7 +99,6 @@ bool QwDevKX13X::initialize(uint8_t settings)
10399
//
104100
// Resets the accelerometer
105101
//
106-
107102
bool QwDevKX13X::softwareReset()
108103
{
109104

@@ -1162,7 +1157,7 @@ bool QwDevKX13X::runCommandTest()
11621157
// Retrieves the raw register values representing accelerometer data.
11631158
//
11641159
// Paramater:
1165-
// *rawAccelData - This pointer to the
1160+
// *rawAccelData - a pointer to the data struct that holds acceleromter X/Y/Z data.
11661161
//
11671162
bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
11681163

@@ -1196,19 +1191,52 @@ bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
11961191
}
11971192

11981193

1194+
//////////////////////////////////////////////////////////////////////////////////
1195+
// readRegisterRegion()
1196+
//
1197+
// Calls sfebus read function.
1198+
//
1199+
// Parameter:
1200+
// reg- register to read from
1201+
// data- array to store data in
1202+
// length- Size of data in bytes (8 bits): 2 bytes = length of two
1203+
// retval- -1 = error, 0 = success
1204+
//
11991205
int QwDevKX13X::readRegisterRegion(uint8_t reg, uint8_t *data, uint16_t len)
12001206
{
12011207
return (int)_sfeBus->readRegisterRegion(_i2cAddress, reg, data, len);
12021208
}
12031209

1210+
//////////////////////////////////////////////////////////////////////////////////
1211+
// writeRegisterRegion()
1212+
//
1213+
// Calls sfebus write function.
1214+
//
1215+
// Parameter:
1216+
// reg- register to read from
1217+
// data- array to store data in
1218+
// length- Size of data in bytes (8 bits): 2 bytes = length of two
1219+
// retval- -1 = error, 0 = success
1220+
//
12041221
int QwDevKX13X::writeRegisterRegion(uint8_t reg, uint8_t *data, uint16_t len)
12051222
{
12061223
return (int)_sfeBus->writeRegisterRegion(_i2cAddress, reg, data, len);
12071224
}
12081225

1209-
int QwDevKX13X::writeRegisterByte(uint8_t reg, uint8_t value)
1226+
//////////////////////////////////////////////////////////////////////////////////
1227+
// writeRegisterByte()
1228+
//
1229+
// Calls sfebus write function.
1230+
//
1231+
// Parameter:
1232+
// reg- register to read from
1233+
// data- array to store data in
1234+
// length- Size of data in bytes (8 bits): 2 bytes = length of two
1235+
// retval- -1 = error, 0 = success
1236+
//
1237+
int QwDevKX13X::writeRegisterByte(uint8_t reg, uint8_t data)
12101238
{
1211-
return (int)_sfeBus->writeRegisterByte(_i2cAddress, reg, value);
1239+
return (int)_sfeBus->writeRegisterByte(_i2cAddress, reg, data);
12121240
}
12131241

12141242

@@ -1218,8 +1246,12 @@ int QwDevKX13X::writeRegisterByte(uint8_t reg, uint8_t value)
12181246
//******************************************************************************************
12191247

12201248

1221-
// Uses the beginCore function to check that the part ID from the "who am I"
1222-
// register matches the correct value. Uses I2C for data transfer.
1249+
//////////////////////////////////////////////////////////////////////////////////
1250+
// init()
1251+
//
1252+
// Ensures that communication is established with the accelerometer by pinging its
1253+
// address and retrieving its device ID.
1254+
//
12231255
bool QwDevKX132::init(void)
12241256
{
12251257
if( !_sfeBus->ping(_i2cAddress) )
@@ -1231,8 +1263,15 @@ bool QwDevKX132::init(void)
12311263
return true;
12321264
}
12331265

1234-
// Grabs raw accel data and passes it to the following function to be
1235-
// converted.
1266+
1267+
//////////////////////////////////////////////////////////////////////////////////
1268+
// getAccelData()
1269+
//
1270+
// Retrieves the raw accelerometer data and calls a conversion function to convert the raw values.
1271+
//
1272+
// Paramater:
1273+
// *userData - a pointer to the user's data struct that will hold acceleromter data.
1274+
//
12361275
bool QwDevKX132::getAccelData(outputData *userData){
12371276

12381277
bool retVal;
@@ -1250,7 +1289,15 @@ bool QwDevKX132::getAccelData(outputData *userData){
12501289
return true;
12511290
}
12521291

1253-
// Converts acceleration data according to the set range value.
1292+
//////////////////////////////////////////////////////////////////////////////////
1293+
// convAccelData()
1294+
//
1295+
// Converts raw acceleromter data with the current accelerometer's range settings.
1296+
//
1297+
// Paramater:
1298+
// *userData - a pointer to the user's data struct that will hold acceleromter data.
1299+
// *rawAccelData - a pointer to the data struct that holds acceleromter X/Y/Z data.
1300+
//
12541301
bool QwDevKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelData){
12551302

12561303
uint8_t regVal;
@@ -1266,22 +1313,22 @@ bool QwDevKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelDat
12661313

12671314

12681315
switch( range ) {
1269-
case KX132_RANGE2G:
1316+
case SFE_KX132_RANGE2G:
12701317
userAccel->xData = (float)rawAccelData->xData * convRange2G;
12711318
userAccel->yData = (float)rawAccelData->yData * convRange2G;
12721319
userAccel->zData = (float)rawAccelData->zData * convRange2G;
12731320
break;
1274-
case KX132_RANGE4G:
1321+
case SFE_KX132_RANGE4G:
12751322
userAccel->xData = (float)rawAccelData->xData * convRange4G;
12761323
userAccel->yData = (float)rawAccelData->yData * convRange4G;
12771324
userAccel->zData = (float)rawAccelData->zData * convRange4G;
12781325
break;
1279-
case KX132_RANGE8G:
1326+
case SFE_KX132_RANGE8G:
12801327
userAccel->xData = (float)rawAccelData->xData * convRange8G;
12811328
userAccel->yData = (float)rawAccelData->yData * convRange8G;
12821329
userAccel->zData = (float)rawAccelData->zData * convRange8G;
12831330
break;
1284-
case KX132_RANGE16G:
1331+
case SFE_KX132_RANGE16G:
12851332
userAccel->xData = (float)rawAccelData->xData * convRange16G;
12861333
userAccel->yData = (float)rawAccelData->yData * convRange16G;
12871334
userAccel->zData = (float)rawAccelData->zData * convRange16G;
@@ -1298,9 +1345,13 @@ bool QwDevKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelDat
12981345
//******************************************************************************************
12991346
//******************************************************************************************
13001347

1301-
//Constructor
1302-
13031348

1349+
//////////////////////////////////////////////////////////////////////////////////
1350+
// init()
1351+
//
1352+
// Ensures that communication is established with the accelerometer by pinging its
1353+
// address and retrieving its device ID.
1354+
//
13041355
bool QwDevKX134::init(void)
13051356
{
13061357
if( !_sfeBus->ping(_i2cAddress) )
@@ -1312,6 +1363,15 @@ bool QwDevKX134::init(void)
13121363
return true;
13131364
}
13141365

1366+
1367+
//////////////////////////////////////////////////////////////////////////////////
1368+
// getAccelData()
1369+
//
1370+
// Retrieves the raw accelerometer data and calls a conversion function to convert the raw values.
1371+
//
1372+
// Paramater:
1373+
// *userData - a pointer to the user's data struct that will hold acceleromter data.
1374+
//
13151375
bool QwDevKX134::getAccelData(outputData *userData)
13161376
{
13171377

@@ -1330,6 +1390,15 @@ bool QwDevKX134::getAccelData(outputData *userData)
13301390
return true;
13311391
}
13321392

1393+
//////////////////////////////////////////////////////////////////////////////////
1394+
// convAccelData()
1395+
//
1396+
// Converts raw acceleromter data with the current accelerometer's range settings.
1397+
//
1398+
// Paramater:
1399+
// *userData - a pointer to the user's data struct that will hold acceleromter data.
1400+
// *rawAccelData - a pointer to the data struct that holds acceleromter X/Y/Z data.
1401+
//
13331402
bool QwDevKX134::convAccelData(outputData *userAccel, rawOutputData *rawAccelData)
13341403
{
13351404

@@ -1346,22 +1415,22 @@ bool QwDevKX134::convAccelData(outputData *userAccel, rawOutputData *rawAccelDat
13461415

13471416

13481417
switch( range ) {
1349-
case KX134_RANGE8G:
1418+
case SFE_KX134_RANGE8G:
13501419
userAccel->xData = (float)rawAccelData->xData * convRange8G;
13511420
userAccel->yData = (float)rawAccelData->yData * convRange8G;
13521421
userAccel->zData = (float)rawAccelData->zData * convRange8G;
13531422
break;
1354-
case KX134_RANGE16G:
1423+
case SFE_KX134_RANGE16G:
13551424
userAccel->xData = (float)rawAccelData->xData * convRange16G;
13561425
userAccel->yData = (float)rawAccelData->yData * convRange16G;
13571426
userAccel->zData = (float)rawAccelData->zData * convRange16G;
13581427
break;
1359-
case KX134_RANGE32G:
1428+
case SFE_KX134_RANGE32G:
13601429
userAccel->xData = (float)rawAccelData->xData * convRange32G;
13611430
userAccel->yData = (float)rawAccelData->yData * convRange32G;
13621431
userAccel->zData = (float)rawAccelData->zData * convRange32G;
13631432
break;
1364-
case KX134_RANGE64G:
1433+
case SFE_KX134_RANGE64G:
13651434
userAccel->xData = (float)rawAccelData->xData * convRange64G;
13661435
userAccel->yData = (float)rawAccelData->yData * convRange64G;
13671436
userAccel->zData = (float)rawAccelData->zData * convRange64G;

src/SparkFun_Qwiic_KX13X.h

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ Distributed as-is; no warranty is given.
2222
#define KX132_WHO_AM_I 0x3D
2323
#define KX134_WHO_AM_I 0x46
2424

25-
#define KX132_RANGE2G 0x00
26-
#define KX132_RANGE4G 0x01
27-
#define KX132_RANGE8G 0x02
28-
#define KX132_RANGE16G 0x03
25+
#define SFE_KX132_RANGE2G 0x00
26+
#define SFE_KX132_RANGE4G 0x01
27+
#define SFE_KX132_RANGE8G 0x02
28+
#define SFE_KX132_RANGE16G 0x03
2929

30-
#define KX134_RANGE8G 0x00
31-
#define KX134_RANGE16G 0x01
32-
#define KX134_RANGE32G 0x02
33-
#define KX134_RANGE64G 0x03
30+
#define SFE_KX134_RANGE8G 0x00
31+
#define SFE_KX134_RANGE16G 0x01
32+
#define SFE_KX134_RANGE32G 0x02
33+
#define SFE_KX134_RANGE64G 0x03
3434

3535
#define TOTAL_ACCEL_DATA_8BIT 3
3636

@@ -49,12 +49,6 @@ Distributed as-is; no warranty is given.
4949
#define BUFFER_SETTINGS 0xE2
5050
#define TILT_SETTINGS 0xE3
5151

52-
#define BUFFER_16BIT_SAMPLES 0x01
53-
#define BUFFER_8BIT_SAMPLES 0x00
54-
#define BUFFER_MODE_FIFO 0x00
55-
#define BUFFER_MODE_STREAM 0x01
56-
#define BUFFER_MODE_TRIGGER 0x02
57-
5852
struct outputData {
5953
float xData;
6054
float yData;
@@ -74,59 +68,13 @@ class QwDevKX13X
7468

7569
QwDevKX13X() : _i2cAddress{0}, _cs{0} {};
7670

77-
//////////////////////////////////////////////////////////////////////////////////
78-
// writeRegisterRegion()
79-
//
80-
//
81-
// Parameter Description
82-
// --------- -----------------------------
83-
// reg register to read from
84-
// data Array to store data in
85-
// length Size of data in bytes (8 bits): 2 bytes = length of two
86-
// retval -1 = error, 0 = success
8771
int writeRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length);
88-
89-
//////////////////////////////////////////////////////////////////////////////////
90-
// writeRegisterByte()
91-
//
92-
//
93-
// Parameter Description
94-
// --------- -----------------------------
95-
// reg register to read from
96-
// data Array to store data in
97-
// retval -1 = error, 0 = success
98-
//
9972
int writeRegisterByte(uint8_t reg, uint8_t data);
100-
101-
//////////////////////////////////////////////////////////////////////////////////
102-
// readRegisterRegion()
103-
//
104-
//
105-
// Parameter Description
106-
// --------- -----------------------------
107-
// reg register to read from
108-
// data Array to store data in
109-
// length Length of the data to read
110-
// retval -1 = error, 0 = success
111-
11273
int readRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length);
113-
114-
//////////////////////////////////////////////////////////////////////////////////
115-
// setCommunicationBus()
116-
//
117-
// Called to set the Communication Bus object to use
118-
//
119-
// Parameter Description
120-
// --------- -----------------------------
121-
// theBus The Bus object to use
122-
// idBus The bus ID for the target device.
123-
//
124-
12574
void setCommunicationBus(QwIDeviceBus &theBus, uint8_t i2cAddress);
12675
void setCommunicationBus(QwIDeviceBus &theBus);
12776

12877
uint8_t getUniqueID();
129-
13078
bool initialize(uint8_t settings = DEFAULT_SETTINGS);
13179

13280
// General Settings
@@ -181,7 +129,7 @@ class QwDevKX13X
181129

182130
protected:
183131

184-
QwIDeviceBus *_sfeBus; //The generic connection to user's chosen SPI hardware
132+
QwIDeviceBus *_sfeBus;
185133
uint8_t _i2cAddress;
186134
uint8_t _cs;
187135
};

0 commit comments

Comments
 (0)