Skip to content

Commit 89652af

Browse files
committed
moved the byte order logic to the core bus interface; #include cleanup
1 parent 9d0f0f7 commit 89652af

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/sfeTk/sfeTkIBus.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const sfeTkError_t kSTkErrBusTimeout = kSTkErrFail * (kSTkErrBaseBus + 2);
5252
const sfeTkError_t kSTkErrBusNoResponse = kSTkErrFail * (kSTkErrBaseBus + 3);
5353

5454
/**
55-
* @brief Returned when the data to be sent is too long or recieved is too short.
55+
* @brief Returned when the data to be sent is too long or received is too short.
5656
*/
5757
const sfeTkError_t kSTkErrBusDataTooLong = kSTkErrFail * (kSTkErrBaseBus + 4);
5858

@@ -86,6 +86,12 @@ const sfeTkError_t kSTkErrBusNotEnabled = kSTkErrBaseBus + 8;
8686
class sfeTkIBus
8787
{
8888
public:
89+
/**
90+
* @brief Constructor
91+
*/
92+
sfeTkIBus() {
93+
_byteOrder = sftk_system_byteorder();
94+
}
8995
/**--------------------------------------------------------------------------
9096
* @brief Send a single byte to the device*
9197
* @param data Data to write.
@@ -294,6 +300,29 @@ class sfeTkIBus
294300
{
295301
return 0;
296302
}
303+
/**
304+
* @brief Set the byte order for multi-byte data transfers
305+
*
306+
* @param order The byte order to set - set to either SFTK_MSBFIRST or SFTK_LSBFIRST. The default is SFTK_LSBFIRST
307+
*
308+
*/
309+
void setByteOrder(sfeTKByteOrder order)
310+
{
311+
_byteOrder = order;
312+
}
313+
314+
/**
315+
* @brief Get the current byte order
316+
*
317+
* @retval The current byte order
318+
*/
319+
sfeTKByteOrder byteOrder(void)
320+
{
321+
return _byteOrder;
322+
}
323+
324+
protected:
325+
/** flag to manage byte swapping */
326+
sfeTKByteOrder _byteOrder;
297327
};
298328

299-
//};

src/sfeTk/sfeToolkit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3232
@brief Common include file for the core of the SparkFun Electronics Toolkit
3333
*/
3434
#include "sfeTkError.h"
35-
#include "sfeTkIBus.h"
35+
3636

3737
// byte order types/enum
3838
enum class sfeTKByteOrder : uint8_t

src/sfeTkArdI2C.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class sfeTkArdI2C : public sfeTkII2C
4545
@brief Constructor
4646
*/
4747

48-
sfeTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk}, _byteOrder{SFTK_LSBFIRST}
48+
sfeTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk}
4949
{
5050
}
5151
/**
@@ -293,26 +293,7 @@ class sfeTkArdI2C : public sfeTkII2C
293293
return _bufferChunkSize;
294294
}
295295

296-
/**
297-
* @brief Set the byte order for multi-byte data transfers
298-
*
299-
* @param order The byte order to set - set to either SFTK_MSBFIRST or SFTK_LSBFIRST. The default is SFTK_LSBFIRST
300-
*
301-
*/
302-
void setByteOrder(sfeTKByteOrder order)
303-
{
304-
_byteOrder = order;
305-
}
306-
307-
/**
308-
* @brief Get the current byte order
309-
*
310-
* @retval The current byte order
311-
*/
312-
sfeTKByteOrder byteOrder(void)
313-
{
314-
return _byteOrder;
315-
}
296+
316297

317298
protected:
318299
// note: The wire port is protected, allowing access if a sub-class is
@@ -333,6 +314,4 @@ class sfeTkArdI2C : public sfeTkII2C
333314
/** The I2C buffer chunker - chunk size*/
334315
size_t _bufferChunkSize;
335316

336-
/** flag to manage byte swapping */
337-
sfeTKByteOrder _byteOrder;
338317
};

0 commit comments

Comments
 (0)