From 337c84766b41a1d1309696f6c844c4abdf66dcd7 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 6 Dec 2023 13:05:45 -0700 Subject: [PATCH 1/5] first take on a error code impl. compiles --- src/SparkFun_Toolkit.h | 14 +-- src/sfeTk/sfeTkError.h | 57 ++++++++++++ src/sfeTk/sfeTkIBus.h | 142 +++++++++++++++++------------ src/sfeTk/sfeTkII2C.h | 40 +++++---- src/sfeTk/sfeTkISPI.h | 25 ++++-- src/sfeTk/sfeToolkit.h | 31 +++++++ src/sfeTkArdI2C.cpp | 59 ++++++------ src/sfeTkArdI2C.h | 199 +++++++++++++++++++++++------------------ src/sfeTkArdSPI.cpp | 31 +++---- src/sfeTkArdSPI.h | 175 +++++++++++++++++++----------------- 10 files changed, 473 insertions(+), 300 deletions(-) create mode 100644 src/sfeTk/sfeTkError.h create mode 100644 src/sfeTk/sfeToolkit.h diff --git a/src/SparkFun_Toolkit.h b/src/SparkFun_Toolkit.h index c236f72..ffe3da6 100644 --- a/src/SparkFun_Toolkit.h +++ b/src/SparkFun_Toolkit.h @@ -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 @@ -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 @@ -29,5 +32,6 @@ SOFTWARE. // Just include the toolkit headers +#include #include "sfeTkArdI2C.h" #include "sfeTkArdSPI.h" \ No newline at end of file diff --git a/src/sfeTk/sfeTkError.h b/src/sfeTk/sfeTkError.h new file mode 100644 index 0000000..cf78ade --- /dev/null +++ b/src/sfeTk/sfeTkError.h @@ -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 + +// +// 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; diff --git a/src/sfeTk/sfeTkIBus.h b/src/sfeTk/sfeTkIBus.h index 7e06eea..6766d0f 100644 --- a/src/sfeTk/sfeTkIBus.h +++ b/src/sfeTk/sfeTkIBus.h @@ -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 @@ -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 +#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; }; //}; diff --git a/src/sfeTk/sfeTkII2C.h b/src/sfeTk/sfeTkII2C.h index c81a5d8..8ff4d14 100644 --- a/src/sfeTk/sfeTkII2C.h +++ b/src/sfeTk/sfeTkII2C.h @@ -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 @@ -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 @@ -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; diff --git a/src/sfeTk/sfeTkISPI.h b/src/sfeTk/sfeTkISPI.h index e5b34a1..f0721d9 100644 --- a/src/sfeTk/sfeTkISPI.h +++ b/src/sfeTk/sfeTkISPI.h @@ -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 @@ -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 @@ -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; diff --git a/src/sfeTk/sfeToolkit.h b/src/sfeTk/sfeToolkit.h new file mode 100644 index 0000000..c517834 --- /dev/null +++ b/src/sfeTk/sfeToolkit.h @@ -0,0 +1,31 @@ + +// sfeToolkit.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 key things that are core to the toolkit + +#include "sfeTkError.h" diff --git a/src/sfeTkArdI2C.cpp b/src/sfeTkArdI2C.cpp index dafca5e..382b05f 100644 --- a/src/sfeTkArdI2C.cpp +++ b/src/sfeTkArdI2C.cpp @@ -1,9 +1,9 @@ /* sfeTkArdI2C.cpp - 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 @@ -18,6 +18,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. + */ #include "sfeTkArdI2C.h" @@ -29,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Arduino version of init - pass in already setup wire port ... // -bool sfeTkArdI2C::init(TwoWire &wirePort, uint8_t addr, bool bInit) +sfeTkError_t sfeTkArdI2C::init(TwoWire &wirePort, uint8_t addr, bool bInit) { // if we don't have a wire port already if (!_i2cPort) @@ -42,7 +43,7 @@ bool sfeTkArdI2C::init(TwoWire &wirePort, uint8_t addr, bool bInit) } setAddress(addr); - return true; + return kSTkErrOk; } //--------------------------------------------------------------------------------- @@ -50,14 +51,14 @@ bool sfeTkArdI2C::init(TwoWire &wirePort, uint8_t addr, bool bInit) // // no parameters version of init. Setups a a wire port if needed. // -bool sfeTkArdI2C::init(uint8_t addr) +sfeTkError_t sfeTkArdI2C::init(uint8_t addr) { // no port yet, do the default version of it if (!_i2cPort) return init(Wire, addr); // We have a port, so arcady init'd - right? - return true; + return kSTkErrOk; } //--------------------------------------------------------------------------------- @@ -65,7 +66,7 @@ bool sfeTkArdI2C::init(uint8_t addr) // // no parameters version of init. Setups a a wire port if needed. // -bool sfeTkArdI2C::init(void) +sfeTkError_t sfeTkArdI2C::init(void) { // call with our currently set address ... return init(address()); @@ -75,14 +76,14 @@ bool sfeTkArdI2C::init(void) // // Ping an I2C address to see if something is there. // -bool sfeTkArdI2C::ping() +sfeTkError_t sfeTkArdI2C::ping() { // no port, no if (!_i2cPort) - return false; + return kSTkErrBusNullPtr; _i2cPort->beginTransmission(address()); - return _i2cPort->endTransmission() == 0; + return _i2cPort->endTransmission() == 0 ? kSTkErrOk : kSTkErrFail; } //--------------------------------------------------------------------------------- @@ -92,16 +93,16 @@ bool sfeTkArdI2C::ping() // // Returns true on success, false on failure // -bool sfeTkArdI2C::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) +sfeTkError_t sfeTkArdI2C::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) { if (!_i2cPort) - return false; + return kSTkErrBusNullPtr; // do the Arduino I2C work _i2cPort->beginTransmission(address()); _i2cPort->write(devReg); _i2cPort->write(dataToWrite); - return _i2cPort->endTransmission() == 0; + return _i2cPort->endTransmission() == 0 ? kSTkErrOk : kSTkErrFail; } //--------------------------------------------------------------------------------- // writeRegisterWord() @@ -110,12 +111,12 @@ bool sfeTkArdI2C::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) // // Returns true on success, false on failure // -bool sfeTkArdI2C::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) +sfeTkError_t sfeTkArdI2C::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) { if (!_i2cPort) - return false; + return kSTkErrBusNullPtr; - return writeRegisterRegion(devReg, (uint8_t *)&dataToWrite, sizeof(u_int16_t)) == 0; + return writeRegisterRegion(devReg, (uint8_t *)&dataToWrite, sizeof(u_int16_t)); } //--------------------------------------------------------------------------------- @@ -125,16 +126,16 @@ bool sfeTkArdI2C::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) // // Returns the number of bytes written, < 0 is an error // -int sfeTkArdI2C::writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) +sfeTkError_t sfeTkArdI2C::writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) { if (!_i2cPort) - return -1; + return kSTkErrBusNullPtr; _i2cPort->beginTransmission(address()); _i2cPort->write(devReg); _i2cPort->write(data, (int)length); - return _i2cPort->endTransmission() ? -1 : 0; // -1 = error, 0 = success + return _i2cPort->endTransmission() ? kSTkErrFail : kSTkErrOk; } //--------------------------------------------------------------------------------- @@ -144,10 +145,10 @@ int sfeTkArdI2C::writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t // // Returns true on success, false on failure // -bool sfeTkArdI2C::readRegisterByte(uint8_t devReg, uint8_t &dataToRead) +sfeTkError_t sfeTkArdI2C::readRegisterByte(uint8_t devReg, uint8_t &dataToRead) { if (!_i2cPort) - return false; + return kSTkErrBusNullPtr; // Return value uint8_t result = 0; @@ -168,7 +169,7 @@ bool sfeTkArdI2C::readRegisterByte(uint8_t devReg, uint8_t &dataToRead) if (nData == 1) // Only update outputPointer if a single byte was returned dataToRead = result; - return (nData == 1); + return (nData == 1 ? kSTkErrOk : kSTkErrFail); } //--------------------------------------------------------------------------------- // readRegisterWord() @@ -177,12 +178,14 @@ bool sfeTkArdI2C::readRegisterByte(uint8_t devReg, uint8_t &dataToRead) // // Returns true on success, false on failure // -bool sfeTkArdI2C::readRegisterWord(uint8_t devReg, uint16_t &dataToRead) +sfeTkError_t sfeTkArdI2C::readRegisterWord(uint8_t devReg, uint16_t &dataToRead) { if (!_i2cPort) - return false; + return kSTkErrBusNullPtr; + + uint32_t nRead = readRegisterRegion(devReg, (uint8_t *)&dataToRead, sizeof(uint16_t)); - return readRegisterRegion(devReg, (uint8_t *)&dataToRead, sizeof(uint16_t)) == 2; + return (nRead == 2 ? kSTkErrOk : kSTkErrFail); } //--------------------------------------------------------------------------------- @@ -192,11 +195,11 @@ bool sfeTkArdI2C::readRegisterWord(uint8_t devReg, uint16_t &dataToRead) // // Returns the number of bytes read, < 0 is an error // -int sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes) +int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes) { // got port if (!_i2cPort) - return -1; + return kSTkErrBusNullPtr; uint16_t nOrig = numBytes; // original number of bytes. uint8_t nChunk; @@ -215,7 +218,7 @@ int sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numByt } if (_i2cPort->endTransmission() != 0) - return -1; // error with the end transmission + return kSTkErrFail; // error with the end transmission // We're chunking in data - keeping the max chunk to kMaxI2CBufferLength nChunk = numBytes > kMaxI2CBufferLength ? kMaxI2CBufferLength : numBytes; diff --git a/src/sfeTkArdI2C.h b/src/sfeTkArdI2C.h index 39496de..cd9bc6c 100644 --- a/src/sfeTkArdI2C.h +++ b/src/sfeTkArdI2C.h @@ -3,7 +3,8 @@ sfeTkArdI2c.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 @@ -13,10 +14,11 @@ 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. The following classes specify the behavior for communicating over Inter-Integrated Circuit (I2C) in Arduino @@ -30,15 +32,14 @@ over Inter-Integrated Circuit (I2C) in Arduino // Include our platform I2C interface definition. #include -/// @brief -/// The sfeTkArdI2C implements an sfeTkII2C interface, defining the Arduino implementation for I2C in the Toolkit -/// +// @brief The sfeTkArdI2C implements an sfeTkII2C interface, defining the Arduino implementation for I2C in the Toolkit + class sfeTkArdI2C : public sfeTkII2C { public: - /// - /// @brief Constructor - /// + /* + @brief Constructor + */ sfeTkArdI2C(void) : _i2cPort(nullptr) { } @@ -59,84 +60,108 @@ class sfeTkArdI2C : public sfeTkII2C return *this; } - /// @brief Method sets up the required I2C settings. - /// @note This function provides a default I2C Port. - /// - /// @retval True on successful execution. - /// - bool init(); - - // @brief - address version of the init method - bool init(uint8_t addr); - - /// @brief Method sets up the required I2C settings. - /// - /// @param wirePort Port for I2C communication. - /// @param bInit This flag tracks whether the bus has been initialized. - /// - /// @retval True on successful execution. - /// - bool init(TwoWire &wirePort, uint8_t addr, bool bInit = false); - - /// @brief A simple ping of the device at the given address. - /// @note sfeTkIBus interface method - /// - /// @retval bool - true on success, false on error - /// - bool ping(); - - /// @brief Write a single byte to the given register - /// @note sfeTkIBus interface method - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval returns true on successful false on failure. - bool writeRegisterByte(uint8_t devReg, uint8_t data); - - bool writeRegisterWord(uint8_t devReg, uint16_t data); - - /// @brief Writes a number of bytes starting at the given register's address. - /// @note sfeTkIBus interface method - /// @note This method is virtual to allow it to be overridden to support a device that requires a unique impl - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval returns number of bytes written, < 0 is an error code - /// + /*-------------------------------------------------------------------------- + @brief Method sets up the required I2C settings. + @note This function provides a default I2C Port. + + @retval kSTkErrOk on successful execution. + */ + sfeTkError_t init(); + + /*-------------------------------------------------------------------------- + @brief - address version of the init method + */ + sfeTkError_t init(uint8_t addr); + + /*-------------------------------------------------------------------------- + @brief Method sets up the required I2C settings. + + @param wirePort Port for I2C communication. + @param bInit This flag tracks whether the bus has been initialized. + + @retval kSTkErrOk on successful execution. + */ + sfeTkError_t init(TwoWire &wirePort, uint8_t addr, bool bInit = false); + + /*-------------------------------------------------------------------------- + @brief A simple ping of the device at the given address. + @note sfeTkIBus interface method + + @retval kSTkErrOk on success, + */ + sfeTkError_t ping(); + + /*-------------------------------------------------------------------------- + @brief Write a single byte to the given register + @note sfeTkIBus interface method + + @param devReg The device's register's address. + @param data Data to write. + + @retval returns on error on success + */ + sfeTkError_t writeRegisterByte(uint8_t devReg, uint8_t data); + + /*-------------------------------------------------------------------------- + @brief Write a single word to the given register + @note sfeTkIBus interface method + + @param devReg The device's register's address. + @param data Data to write. + + @retval returns on error on success + */ + sfeTkError_t writeRegisterWord(uint8_t devReg, uint16_t data); + + /*-------------------------------------------------------------------------- + @brief Writes a number of bytes starting at the given register's address. + + @note sfeTkIBus interface method + @note This method is virtual to allow it to be overridden to support a device that requires a unique impl + + @param devReg The device's register's address. + @param data Data to write. + + @retval returns number of bytes written, < 0 is an error code + */ virtual int writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length); - /// @brief Reads a byte of data from the given register. - /// @note sfeTkIBus interface method - /// - /// @param devReg The device's register's address. - /// @param data Data to read. - /// - /// @retval true on success, false on error - /// - bool readRegisterByte(uint8_t devReg, uint8_t &data); - - /// @brief Reads a word of data from the given register. - /// @note sfeTkIBus interface method - /// - /// @param devReg The device's register's address. - /// @param data Data to read. - /// - /// @retval true on success, false on error - /// - bool readRegisterWord(uint8_t devReg, uint16_t &data); - - /// @brief Reads a block of data from the given register. - /// @note sfeTkIBus interface method - /// @note This method is virtual to allow it to be overridden to support a device that requires a unique impl - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval 0 on success, < 0 on error - see error code - /// - virtual int readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes); + /*-------------------------------------------------------------------------- + @brief Reads a byte of data from the given register. + + @note sfeTkIBus interface method + + @param devReg The device's register's address. + @param data Data to read. + + @retval on error on success + */ + sfeTkError_t readRegisterByte(uint8_t devReg, uint8_t &data); + + /*-------------------------------------------------------------------------- + @brief Reads a word of data from the given register. + + @note sfeTkIBus interface method + + @param devReg The device's register's address. + @param data Data to read. + + @retval kSTkErrOk on success + */ + sfeTkError_t readRegisterWord(uint8_t devReg, uint16_t &data); + + /*-------------------------------------------------------------------------- + @brief Reads a block of data from the given register. + + @note sfeTkIBus interface method + @note This method is virtual to allow it to be overridden to support a device that requires a unique impl + + @param devReg The device's register's address. + @param data Data to write. + + @retval 0 on success, < 0 on error - see error code + */ + sfeTkError_t readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes); protected: // note: The wire port is protected, allowing access if a sub-class is diff --git a/src/sfeTkArdSPI.cpp b/src/sfeTkArdSPI.cpp index a70ee71..6bf8b28 100644 --- a/src/sfeTkArdSPI.cpp +++ b/src/sfeTkArdSPI.cpp @@ -4,7 +4,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 @@ -37,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Arduino version of init. Will take in a defined SPI port/settings // -bool sfeTkArdSPI::init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t csPin, bool bInit) +sfeTkError_t sfeTkArdSPI::init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t csPin, bool bInit) { // if we don't have a SPI port already if (!_spiPort) @@ -53,7 +54,7 @@ bool sfeTkArdSPI::init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t c // SPI settings are needed for every transaction _sfeSPISettings = busSPISettings; - return true; + return kSTkErrOk; } //--------------------------------------------------------------------------------- @@ -61,7 +62,7 @@ bool sfeTkArdSPI::init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t c // // Arduino version of init. // -bool sfeTkArdSPI::init(uint8_t csPin, bool bInit) +sfeTkError_t sfeTkArdSPI::init(uint8_t csPin, bool bInit) { // If the transaction settings are not provided by the user they are built here. SPISettings spiSettings = SPISettings(3000000, SPI_MSBFIRST, SPI_MODE3); @@ -75,7 +76,7 @@ bool sfeTkArdSPI::init(uint8_t csPin, bool bInit) // // Arduino version of init. // -bool sfeTkArdSPI::init(bool bInit) +sfeTkError_t sfeTkArdSPI::init(bool bInit) { return init(cs(), bInit); } @@ -87,11 +88,11 @@ bool sfeTkArdSPI::init(bool bInit) // // Returns true on success, false on failure // -bool sfeTkArdSPI::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) +sfeTkError_t sfeTkArdSPI::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) { if (!_spiPort) - return false; + return kSTkErrBusNullPtr; // Apply settings _spiPort->beginTransaction(_sfeSPISettings); @@ -105,7 +106,7 @@ bool sfeTkArdSPI::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) digitalWrite(cs(), HIGH); _spiPort->endTransaction(); - return true; + return kSTkErrOk; } //--------------------------------------------------------------------------------- // writeRegisterWord() @@ -114,7 +115,7 @@ bool sfeTkArdSPI::writeRegisterByte(uint8_t devReg, uint8_t dataToWrite) // // Returns true on success, false on failure // -bool sfeTkArdSPI::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) +sfeTkError_t sfeTkArdSPI::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) { return writeRegisterRegion(devReg, (uint8_t *)&dataToWrite, sizeof(uint8_t)) > 0; } @@ -128,7 +129,7 @@ bool sfeTkArdSPI::writeRegisterWord(uint8_t devReg, uint16_t dataToWrite) int sfeTkArdSPI::writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) { if (!_spiPort) - return -1; + return kSTkErrBusNullPtr; // Apply settings _spiPort->beginTransaction(_sfeSPISettings); @@ -147,12 +148,12 @@ int sfeTkArdSPI::writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t return length; } -bool sfeTkArdSPI::readRegisterByte(uint8_t devReg, uint8_t &data) +sfeTkError_t sfeTkArdSPI::readRegisterByte(uint8_t devReg, uint8_t &data) { return readRegisterRegion(devReg, &data, sizeof(data)) == 1; } -bool sfeTkArdSPI::readRegisterWord(uint8_t devReg, uint16_t &data) +sfeTkError_t sfeTkArdSPI::readRegisterWord(uint8_t devReg, uint16_t &data) { return readRegisterRegion(devReg, (uint8_t *)&data, sizeof(data)) == 2; } @@ -163,10 +164,10 @@ bool sfeTkArdSPI::readRegisterWord(uint8_t devReg, uint16_t &data) // // Returns the number of bytes read, < 0 is an error // -int sfeTkArdSPI::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes) +sfeTkError_t sfeTkArdSPI::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes) { if (!_spiPort) - return -1; + return kSTkErrBusNullPtr; // Apply settings _spiPort->beginTransaction(_sfeSPISettings); @@ -184,5 +185,5 @@ int sfeTkArdSPI::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numByt digitalWrite(cs(), HIGH); _spiPort->endTransaction(); - return numBytes; + return kSTkErrOk; } diff --git a/src/sfeTkArdSPI.h b/src/sfeTkArdSPI.h index 40e273e..cf52750 100644 --- a/src/sfeTkArdSPI.h +++ b/src/sfeTkArdSPI.h @@ -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 @@ -29,14 +30,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -/// @brief This class implements the IBus interface for an SPI Implementation on Arduino -/// +/* + @brief This class implements the IBus interface for an SPI Implementation on Arduino + */ class sfeTkArdSPI : public sfeTkISPI { public: - /// - /// @brief Constructor - /// + /* + @brief Constructor + */ sfeTkArdSPI(void) : _spiPort(nullptr){}; // copy constructor @@ -51,82 +53,91 @@ class sfeTkArdSPI : public sfeTkISPI _sfeSPISettings = rhs._sfeSPISettings; return *this; } - /// @brief Method sets up the required SPI settings. - /// @note This function provides a default SPI Port. - /// - /// @param bInit This flag tracks whether the bus has been initialized. - /// - /// @retval bool - True on successful, false on error - /// - bool init(bool bInit = false); - - bool init(uint8_t csPin, bool bInit = false); - - /// @brief Method sets up the required SPI settings. - /// - /// @param spiPort Port for SPI communication. - /// @param busSPISettings Settings for speed, endianness, and spi mode of the SPI bus. - /// @param bInit This flag tracks whether the bus has been initialized. - /// - /// @retval bool - True on successful, false on error - /// - bool init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t csPin, bool bInit = false); - - /// @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 success, false on error - /// - bool writeRegisterByte(uint8_t devReg, uint8_t data); - - /// @brief Write a single word to the given register - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval bool - true on success, false on error - /// - bool writeRegisterWord(uint8_t devReg, uint16_t data); - - /// @brief Writes a number of bytes starting at the given register's address. - /// @note This method is virtual to allow it to be overridden to support a device that requires a unique impl - // - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval int - number of bytes written, < 0 = error value - /// - virtual int writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length); - - /// @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 success, false on error - /// - bool readRegisterByte(uint8_t devReg, uint8_t &data); - - /// @brief read a single word to the given register - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval bool - true on success, false on error - /// - bool readRegisterWord(uint8_t devReg, uint16_t &data); - - /// @brief Reads a block of data from the given register. - /// @note This method is virtual to allow it to be overridden to support a device that requires a unique impl - /// - /// @param devReg The device's register's address. - /// @param data Data to write. - /// - /// @retval int returns the number of bytes read, < 0 on error - /// - virtual int readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes); + + /*-------------------------------------------------------------------------- + @brief Method sets up the required SPI settings. + @note This function provides a default SPI Port. + + @param bInit This flag tracks whether the bus has been initialized. + + @retval sfeTkError_t - kSTkErrOk on success + */ + sfeTkError_t init(bool bInit = false); + + sfeTkError_t init(uint8_t csPin, bool bInit = false); + + /*-------------------------------------------------------------------------- + @brief Method sets up the required SPI settings. + + @param spiPort Port for SPI communication. + @param busSPISettings Settings for speed, endianness, and spi mode of the SPI bus. + @param bInit This flag tracks whether the bus has been initialized. + + @retval sfeTkError_t - kSTkErrOk on success + */ + sfeTkError_t init(SPIClass &spiPort, SPISettings &busSPISettings, uint8_t csPin, bool bInit = false); + + /*-------------------------------------------------------------------------- + @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 success + */ + sfeTkError_t writeRegisterByte(uint8_t devReg, uint8_t data); + + /*-------------------------------------------------------------------------- + @brief Write a single word to the given register + + @param devReg The device's register's address. + @param data Data to write. + + @retval sfeTkError_t - kSTkErrOk on success + */ + sfeTkError_t writeRegisterWord(uint8_t devReg, uint16_t data); + + /*-------------------------------------------------------------------------- + @brief Writes a number of bytes starting at the given register's address. + @note This method is virtual to allow it to be overridden to support a device that requires a unique impl + + @param devReg The device's register's address. + @param data Data to write. + + @retval int32_t - number of bytes written, < 0 = error value + */ + virtual int32_t writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length); + + /*-------------------------------------------------------------------------- + @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 success + */ + sfeTkError_t readRegisterByte(uint8_t devReg, uint8_t &data); + + /*-------------------------------------------------------------------------- + @brief read a single word to the given register + + @param devReg The device's register's address. + @param data Data to write. + + @retval sfeTkError_t - true on success + */ + sfeTkError_t readRegisterWord(uint8_t devReg, uint16_t &data); + + /*-------------------------------------------------------------------------- + @brief Reads a block of data from the given register. + @note This method is virtual to allow it to be overridden to support a device that requires a unique impl + + @param devReg The device's register's address. + @param data Data to write. + + @retval sfeTkError_t - true on success + */ + virtual sfeTkError_t readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes); protected: // note: The instance data is protected, allowing access if a sub-class is From 51d7611d2f754d86860d7f567fb3f27b4fb078ec Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 6 Dec 2023 13:13:22 -0700 Subject: [PATCH 2/5] added settable buffer chunk size --- src/sfeTkArdI2C.cpp | 4 ++-- src/sfeTkArdI2C.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/sfeTkArdI2C.cpp b/src/sfeTkArdI2C.cpp index 382b05f..3374419 100644 --- a/src/sfeTkArdI2C.cpp +++ b/src/sfeTkArdI2C.cpp @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "sfeTkArdI2C.h" -#define kMaxI2CBufferLength 32 + //--------------------------------------------------------------------------------- // init() @@ -221,7 +221,7 @@ int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t nu return kSTkErrFail; // error with the end transmission // We're chunking in data - keeping the max chunk to kMaxI2CBufferLength - nChunk = numBytes > kMaxI2CBufferLength ? kMaxI2CBufferLength : numBytes; + nChunk = numBytes > _bufferChunkSize ? _bufferChunkSize : numBytes; nReturned = _i2cPort->requestFrom((int)address(), (int)nChunk, (int)true); diff --git a/src/sfeTkArdI2C.h b/src/sfeTkArdI2C.h index cd9bc6c..6e729dd 100644 --- a/src/sfeTkArdI2C.h +++ b/src/sfeTkArdI2C.h @@ -40,7 +40,7 @@ class sfeTkArdI2C : public sfeTkII2C /* @brief Constructor */ - sfeTkArdI2C(void) : _i2cPort(nullptr) + sfeTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk} { } @@ -163,10 +163,43 @@ class sfeTkArdI2C : public sfeTkII2C */ sfeTkError_t readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes); + // Buffer size chunk getter/setter + /*-------------------------------------------------------------------------- + @brief set the buffer chunk size + + @note default size is 32 + + @param theChunk the new size - must be > 0 + + */ + void setBufferChunkSize(size_t theChunk) + { + if (theChunk > 0) + _bufferChunkSize = theChunk; + } + + /*-------------------------------------------------------------------------- + @brief set the buffer chunk size + + @retval The current chunk size + + */ + size_t bufferChunkSize(void) + { + return _bufferChunkSize; + } + protected: // note: The wire port is protected, allowing access if a sub-class is // created to implement a special read/write routine // // The actual Arduino i2c port TwoWire *_i2cPort; + + private: + static constexpr size_t kDefaultBufferChunk = 32; + + // the I2C buffer chunker size + + size_t _bufferChunkSize; }; From 763bf3b295bcb780487a3af40673ca644051b0f0 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 6 Dec 2023 13:34:37 -0700 Subject: [PATCH 3/5] proper vesion number --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 4b60d0f..6f971ef 100644 --- a/library.properties +++ b/library.properties @@ -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. From c92962e04f308fb422645ee6416a3577d4cffdc5 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 6 Dec 2023 13:44:22 -0700 Subject: [PATCH 4/5] minor re-org of test area --- test/test.ino | 12 ------------ tests/test_bus01/test_bus01.ino | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 test/test.ino create mode 100644 tests/test_bus01/test_bus01.ino diff --git a/test/test.ino b/test/test.ino deleted file mode 100644 index 07be984..0000000 --- a/test/test.ino +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -void setup() -{ - -} - -void loop() -{ - -} diff --git a/tests/test_bus01/test_bus01.ino b/tests/test_bus01/test_bus01.ino new file mode 100644 index 0000000..217ad37 --- /dev/null +++ b/tests/test_bus01/test_bus01.ino @@ -0,0 +1,16 @@ + + +// Just a simple compile test for the Bus objects + +#include "SparkFun_Toolkit.h" + +sfeTkArdI2C myI2C; +sfeTkArdSPI mySPI; + +void setup() +{ +} + +void loop() +{ +} From e940f1313680877f575dfef5888b4b5b4dc29708 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 6 Dec 2023 13:45:07 -0700 Subject: [PATCH 5/5] make use of the new test folder --- .github/workflows/compile-sketch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-sketch.yml b/.github/workflows/compile-sketch.yml index d9d0d7c..6deb49f 100644 --- a/.github/workflows/compile-sketch.yml +++ b/.github/workflows/compile-sketch.yml @@ -101,7 +101,7 @@ jobs: libraries: | - source-path: ./ sketch-paths: | - - test/test + - tests enable-warnings-report: true enable-deltas-report: true verbose: true