Skip to content

Push changes to working branch. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile-sketch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
libraries: |
- source-path: ./
sketch-paths: |
- test/test
- tests
enable-warnings-report: true
enable-deltas-report: true
verbose: true
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun Toolkit
version=0.1.0
version=0.8.0
author=SparkFun Electronics
maintainer=SparkFun Electronics
sentence=A utility library that other SparkFun libraries can take advantage of.
Expand Down
14 changes: 9 additions & 5 deletions src/SparkFun_Toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ SparkFun_Toolkit.h

The MIT License (MIT)

Copyright (c) 2022 SparkFun Electronics
Copyright (c) 2023 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -14,10 +15,12 @@ Software is furnished to do so, subject to the following conditions: The
above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#pragma once
Expand All @@ -29,5 +32,6 @@ SOFTWARE.

// Just include the toolkit headers

#include <sfeTk/sfeToolkit.h>
#include "sfeTkArdI2C.h"
#include "sfeTkArdSPI.h"
57 changes: 57 additions & 0 deletions src/sfeTk/sfeTkError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

// sfeTkError.h
//
// General header file for the SparkFun Toolkit
/*
The MIT License (MIT)

Copyright (c) 2023 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions: The
above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#pragma once


#include <cstdint>

//
// General Concept
// A SparkFun Toolkit error system. The goal is to keep this simple.
//
// This mimics a vareity of systems, using an int type for error codes,
// where:
// 0 = okay
// -1 = general failure
// >0 = an informative error
//
// Since *subsystems* in the toolkit can have their own errors,
// A start range for these errors are defined. Values > than this value
// define the errors for the set subsystem. These start ranges are set
// in this file, with actual error values defined in the the respective
// subsystem header files.
//
// Define our error codes/type
typedef int32_t sfeTkError_t;

// General errors

const sfeTkError_t kSTkErrFail = -1; // general fail
const sfeTkError_t kSTkErrOk = 0; // success

// Base error number for IBus/Bus operations Bus errors are not less than this.
const sfeTkError_t kSTkErrBaseBus = 0x1000;
142 changes: 85 additions & 57 deletions src/sfeTk/sfeTkIBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

The MIT License (MIT)

Copyright (c) 2022 SparkFun Electronics
Copyright (c) 2023 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -21,70 +22,97 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#pragma once

#include <cstdint>
#include "sfeTkError.h"


// Define our error codes for the bus. Note Errors are negative, warnings/info postive
// BUT keep the same increment on the base

const sfeTkError_t kSTkErrBusNullPtr = kSTkErrFail * (kSTkErrBaseBus + 1);
const sfeTkError_t kSTkErrBusTimeout = kSTkErrFail * (kSTkErrBaseBus + 2);
const sfeTkError_t kSTkErrBusNoReponse = kSTkErrFail * (kSTkErrBaseBus + 3);
const sfeTkError_t kSTkErrBusDataTooLong = kSTkErrFail * (kSTkErrBaseBus + 4);
const sfeTkError_t kSTkErrBusNullSettings = kSTkErrFail * (kSTkErrBaseBus + 5);
const sfeTkError_t kSTkErrBusNullBuffer = kSTkErrFail * (kSTkErrBaseBus + 6);
const sfeTkError_t kSTkErrBusUnderRead = kSTkErrBaseBus + 7;
const sfeTkError_t kSTkErrBusNotEnabled = kSTkErrBaseBus + 8;

// Define the bus interface.

class sfeTkIBus
{
public:
/// @brief Write a single byte to the given register
///
/// @param devReg The device's register's address.
/// @param data Data to write.
///
/// @retval bool - true on successful execution.
///
virtual bool writeRegisterByte(uint8_t devReg, uint8_t data) = 0;

/// @brief Write a single word (16 bit) to the given register
///
/// @param devReg The device's register's address.
/// @param data Data to write.
///
/// @retval bool - true on successful execution.
///
virtual bool writeRegisterWord(uint8_t devReg, uint16_t data) = 0;

/// @brief Writes a number of bytes starting at the given register's address.
///
/// @param devAddr The device's address/pin
/// @param devReg The device's register's address.
/// @param data Data to write.
///
/// @retval int returns the number of bytes written, < 0 on error
///
virtual int writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) = 0;

/// @brief Read a single byte from the given register
///
/// @param devReg The device's register's address.
/// @param data Data to read.
///
/// @retval bool - true on successful execution.
///
virtual bool readRegisterByte(uint8_t devReg, uint8_t &data) = 0;

/// @brief Read a single word (16 bit) from the given register
///
/// @param devReg The device's register's address.
/// @param data Data to read.
///
/// @retval bool - true on successful execution.
///
virtual bool readRegisterWord(uint8_t devReg, uint16_t &data) = 0;

/// @brief Reads a block of data from the given register.
///
/// @param devAddr The device's I2C address.
/// @param devReg The device's register's address.
/// @param data Data to write.
///
/// @retval int returns 0 on success, or error code
///
virtual int readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes) = 0;
/*--------------------------------------------------------------------------
@brief Write a single byte to the given register

@param devReg The device's register's address.
@param data Data to write.

@retval sfeTkError_t - kSTkErrOk on successful execution.

*/
virtual sfeTkError_t writeRegisterByte(uint8_t devReg, uint8_t data) = 0;

/*--------------------------------------------------------------------------
@brief Write a single word (16 bit) to the given register

@param devReg The device's register's address.
@param data Data to write.

@retval sfeTkError_t - kSTkErrOk on successful execution.

*/
virtual sfeTkError_t writeRegisterWord(uint8_t devReg, uint16_t data) = 0;

/*--------------------------------------------------------------------------
@brief Writes a number of bytes starting at the given register's address.

@param devAddr The device's address/pin
param devReg The device's register's address.
@param data Data to write.

@retval int returns the number of bytes written, or kSTkErrFail on error

*/
virtual int32_t writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) = 0;

/*--------------------------------------------------------------------------
@brief Read a single byte from the given register

@param devReg The device's register's address.
@param data Data to read.

@retval sfeTkError_t - kSTkErrOk on successful execution.

*/
virtual sfeTkError_t readRegisterByte(uint8_t devReg, uint8_t &data) = 0;

/*--------------------------------------------------------------------------
@brief Read a single word (16 bit) from the given register

@param devReg The device's register's address.
@param data Data to read.

@retval sfeTkError_t - kSTkErrOk on successful execution.
*/
virtual sfeTkError_t readRegisterWord(uint8_t devReg, uint16_t &data) = 0;

/*--------------------------------------------------------------------------
@brief Reads a block of data from the given register.

@param devAddr The device's I2C address.
@param devReg The device's register's address.
@param data Data to write.

@retval int returns kSTkErrOk on success, or kSTkErrFail code

*/
virtual sfeTkError_t readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes) = 0;
};

//};
40 changes: 23 additions & 17 deletions src/sfeTk/sfeTkII2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//
// Defines the I2C communication bus interface for the SparkFun Electronics Toolkit
/*

The MIT License (MIT)

Copyright (c) 2022 SparkFun Electronics
Copyright (c) 2023 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -21,6 +21,7 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#pragma once
Expand All @@ -37,26 +38,31 @@ class sfeTkII2C : public sfeTkIBus
{
}

///
/// @brief A simple ping of the device at the set address
///
/// @retval bool - true on success, false on failure
///
virtual bool ping() = 0;

/// @brief setter for the I2C address
///
/// @param devAddr The device's address
///
/*--------------------------------------------------------------------------
@brief A simple ping of the device at the set address

@retval sfeTkError_t - ok on success

*/
virtual sfeTkError_t ping() = 0;

/*--------------------------------------------------------------------------
@brief setter for the I2C address

@param devAddr The device's address

*/
virtual void setAddress(uint8_t devAddr)
{
_address = devAddr;
}

/// @brief getter for the I2C address
///
/// @retval uint8_t returns the address for the device
///
/*--------------------------------------------------------------------------
@brief getter for the I2C address

@retval uint8_t returns the address for the device

*/
virtual uint8_t address(void)
{
return _address;
Expand Down
25 changes: 16 additions & 9 deletions src/sfeTk/sfeTkISPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

The MIT License (MIT)

Copyright (c) 2022 SparkFun Electronics
Copyright (c) 2023 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -21,6 +22,7 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#pragma once
Expand All @@ -37,19 +39,24 @@ class sfeTkISPI : public sfeTkIBus
sfeTkISPI(uint8_t csPin) : _cs{csPin}
{
}
/// @brief setter for the CS Pin
///
/// @param devCS The device's CS Pin
///

/*--------------------------------------------------------------------------
@brief setter for the CS Pin

@param devCS The device's CS Pin

*/
virtual void setCS(uint8_t devCS)
{
_cs = devCS;
}

/// @brief getter for the cs pin
///
/// @retval uint8_t returns the CS pin for the device
///
/*--------------------------------------------------------------------------
@brief getter for the cs pin

@retval uint8_t returns the CS pin for the device

*/
virtual uint8_t cs(void)
{
return _cs;
Expand Down
Loading