diff --git a/README.md b/README.md index 147b794..64df0b3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +![SparkFun ToolKit](docs/images/gh-banner-2025-banner-toolkit.png "SparkFun Toolkit") # SparkFun Toolkit Arduino Library ![Toolkit Tests Builds](https://github.com/sparkfun/SparkFun_Toolkit/actions/workflows/compile-sketch.yml/badge.svg) diff --git a/docs/images/gh-banner-2025-banner-toolkit.png b/docs/images/gh-banner-2025-banner-toolkit.png new file mode 100644 index 0000000..d0a144f Binary files /dev/null and b/docs/images/gh-banner-2025-banner-toolkit.png differ diff --git a/src/SparkFun_Toolkit.h b/src/SparkFun_Toolkit.h index ffe3da6..aee8e9f 100644 --- a/src/SparkFun_Toolkit.h +++ b/src/SparkFun_Toolkit.h @@ -31,7 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Arduino Libraries. // Just include the toolkit headers - -#include #include "sfeTkArdI2C.h" -#include "sfeTkArdSPI.h" \ No newline at end of file +#include "sfeTkArdSPI.h" +#include "sfeTkArduino.h" diff --git a/src/sfeTk/sfeTkIBus.h b/src/sfeTk/sfeTkIBus.h index c6ca7ab..43479e8 100644 --- a/src/sfeTk/sfeTkIBus.h +++ b/src/sfeTk/sfeTkIBus.h @@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once -#include "sfeTkError.h" +#include "sfeToolkit.h" #include /** @@ -52,7 +52,7 @@ const sfeTkError_t kSTkErrBusTimeout = kSTkErrFail * (kSTkErrBaseBus + 2); const sfeTkError_t kSTkErrBusNoResponse = kSTkErrFail * (kSTkErrBaseBus + 3); /** - * @brief Returned when the data to be sent is too long or recieved is too short. + * @brief Returned when the data to be sent is too long or received is too short. */ const sfeTkError_t kSTkErrBusDataTooLong = kSTkErrFail * (kSTkErrBaseBus + 4); @@ -86,6 +86,12 @@ const sfeTkError_t kSTkErrBusNotEnabled = kSTkErrBaseBus + 8; class sfeTkIBus { public: + /** + * @brief Constructor + */ + sfeTkIBus() { + _byteOrder = sftk_system_byteorder(); + } /**-------------------------------------------------------------------------- * @brief Send a single byte to the device* * @param data Data to write. @@ -96,7 +102,7 @@ class sfeTkIBus virtual sfeTkError_t writeByte(uint8_t data) = 0; /**-------------------------------------------------------------------------- - * @brief Send a word to the device. + * @brief Send a word to the device. * @param data Data to write. * * @retval sfeTkError_t - kSTkErrOk on successful execution. @@ -125,6 +131,12 @@ class sfeTkIBus */ virtual sfeTkError_t writeRegisterByte(uint8_t devReg, uint8_t data) = 0; + // Overload version + sfeTkError_t writeRegister(uint8_t devReg, uint8_t data) + { + return writeRegisterByte(devReg, data); + } + /**-------------------------------------------------------------------------- * @brief Write a single word (16 bit) to the given register * @@ -136,6 +148,12 @@ class sfeTkIBus */ virtual sfeTkError_t writeRegisterWord(uint8_t devReg, uint16_t data) = 0; + // Overload version + sfeTkError_t writeRegister(uint8_t devReg, uint16_t data) + { + return writeRegisterWord(devReg, data); + } + /**-------------------------------------------------------------------------- * @brief Writes a number of bytes starting at the given register's address. * @@ -148,6 +166,12 @@ class sfeTkIBus */ virtual sfeTkError_t writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) = 0; + // Overload version + sfeTkError_t writeRegister(uint8_t devReg, const uint8_t *data, size_t length) + { + return writeRegisterRegion(devReg, data, length); + } + /**-------------------------------------------------------------------------- * @brief Writes a number of bytes starting at the given register's 16-bit address. * @@ -160,6 +184,29 @@ class sfeTkIBus */ virtual sfeTkError_t writeRegister16Region(uint16_t devReg, const uint8_t *data, size_t length) = 0; + // Overload version + sfeTkError_t writeRegister(uint16_t devReg, const uint8_t *data, size_t length) + { + return writeRegister16Region(devReg, data, length); + } + + /**-------------------------------------------------------------------------- + * @brief Writes a number of uint16's starting at the given register's 16-bit address. + * + * @param devReg The device's register's address. + * @param data Data to write. + * @param length - length of data + * + * @retval sfeTkError_t kSTkErrOk on successful execution + * + */ + virtual sfeTkError_t writeRegister16Region16(uint16_t devReg, const uint16_t *data, size_t length) = 0; + + // Overload version + sfeTkError_t writeRegister(uint16_t devReg, const uint16_t *data, size_t length) + { + return writeRegister16Region16(devReg, data, length); + } /**-------------------------------------------------------------------------- * @brief Read a single byte from the given register * @@ -171,6 +218,12 @@ class sfeTkIBus */ virtual sfeTkError_t readRegisterByte(uint8_t devReg, uint8_t &data) = 0; + // Overload version + sfeTkError_t readRegister(uint8_t devReg, uint8_t &data) + { + return readRegisterByte(devReg, data); + } + /**-------------------------------------------------------------------------- * @brief Read a single word (16 bit) from the given register * @@ -181,6 +234,12 @@ class sfeTkIBus */ virtual sfeTkError_t readRegisterWord(uint8_t devReg, uint16_t &data) = 0; + // Overload version + sfeTkError_t readRegister(uint8_t devReg, uint16_t &data) + { + return readRegisterWord(devReg, data); + } + /**-------------------------------------------------------------------------- * @brief Reads a block of data from the given register. * @@ -194,6 +253,12 @@ class sfeTkIBus */ virtual sfeTkError_t readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes, size_t &readBytes) = 0; + // Overload version + sfeTkError_t readRegister(uint8_t reg, uint8_t *data, size_t numBytes, size_t &readBytes) + { + return readRegisterRegion(reg, data, numBytes, readBytes); + } + /**-------------------------------------------------------------------------- * @brief Reads a block of data from the given 16-bit register address. * @@ -206,6 +271,58 @@ class sfeTkIBus * */ virtual sfeTkError_t readRegister16Region(uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes) = 0; + + // Overload version + sfeTkError_t readRegister(uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes) + { + return readRegister16Region(reg, data, numBytes, readBytes); + } + /**-------------------------------------------------------------------------- + * @brief Reads a block of data from the given 16-bit register address. + * + * @param reg The device's 16 bit register's address. + * @param data Data to write. + * @param numBytes - length of data + * @param[out] readBytes - number of bytes read + * + * @retval int returns kSTkErrOk on success, or kSTkErrFail code + * + */ + virtual sfeTkError_t readRegister16Region16(uint16_t reg, uint16_t *data, size_t numBytes, size_t &readBytes) = 0; + + // Overload version + sfeTkError_t readRegister(uint16_t reg, uint16_t *data, size_t numBytes, size_t &readBytes) + { + return readRegister16Region16(reg, data, numBytes, readBytes); + } + + virtual uint8_t type(void) + { + return 0; + } + /** + * @brief Set the byte order for multi-byte data transfers + * + * @param order The byte order to set - set to either SFTK_MSBFIRST or SFTK_LSBFIRST. The default is SFTK_LSBFIRST + * + */ + void setByteOrder(sfeTKByteOrder order) + { + _byteOrder = order; + } + + /** + * @brief Get the current byte order + * + * @retval The current byte order + */ + sfeTKByteOrder byteOrder(void) + { + return _byteOrder; + } + + protected: + /** flag to manage byte swapping */ + sfeTKByteOrder _byteOrder; }; -//}; diff --git a/src/sfeTk/sfeTkII2C.h b/src/sfeTk/sfeTkII2C.h index f9fdf57..264d243 100644 --- a/src/sfeTk/sfeTkII2C.h +++ b/src/sfeTk/sfeTkII2C.h @@ -34,6 +34,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * The I2C bus interface extends the IBus interface and adds the ability to set and get the I2C * address and stop flag. */ +const uint8_t kBusTypeI2C = 0x01; + class sfeTkII2C : public sfeTkIBus { public: @@ -109,6 +111,11 @@ class sfeTkII2C : public sfeTkIBus */ static constexpr uint8_t kNoAddress = 0; + virtual uint8_t type(void) + { + return kBusTypeI2C; + } + private: uint8_t _address; bool _stop; diff --git a/src/sfeTk/sfeTkISPI.h b/src/sfeTk/sfeTkISPI.h index e9df115..b77ea9c 100644 --- a/src/sfeTk/sfeTkISPI.h +++ b/src/sfeTk/sfeTkISPI.h @@ -34,6 +34,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * The SPI bus interface extends the IBus interface and adds the ability to set and get the CS pin. */ + +const uint8_t kBusTypeSPI = 0x02; class sfeTkISPI : public sfeTkIBus { public: @@ -82,6 +84,11 @@ class sfeTkISPI : public sfeTkIBus */ static constexpr uint8_t kNoCSPin = 0; + virtual uint8_t type(void) + { + return kBusTypeSPI; + } + private: /** The internal storage of the _cs value*/ uint8_t _cs; diff --git a/src/sfeTk/sfeToolkit.cpp b/src/sfeTk/sfeToolkit.cpp new file mode 100644 index 0000000..75cb3eb --- /dev/null +++ b/src/sfeTk/sfeToolkit.cpp @@ -0,0 +1,75 @@ +// File: sfeToolkit.cpp +// +// General impl file for the SparkFun Toolkit +/* + +The MIT License (MIT) + +Copyright (c) 2024 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. +*/ +#include "sfeToolkit.h" + +// THIS IS A PLACEHOLDER FILE for now +#ifdef ARDUINO +#include +#endif +//--------------------------------------------------------------------------------- +/** + * @brief C function - Runtime check for system byte order + */ +sfeTKByteOrder sftk_system_byteorder(void) +{ + uint16_t i = 1; + return *((uint8_t *)&i) == 0 ? sfeTKByteOrder::BigEndian : sfeTKByteOrder::LittleEndian; +} + +//--------------------------------------------------------------------------------- +/** + * @brief to catch 8 bit calls for byte swap + * + */ +uint8_t sftk_byte_swap(uint8_t i) +{ + return i; +} +//--------------------------------------------------------------------------------- +/** + * @brief function - Byte swap a 16 bit value + */ +uint16_t sftk_byte_swap(uint16_t i) +{ + // Use the fast intrinsic if available +#if defined(__clang__) || defined(__GNUC__) + return __builtin_bswap16(i); +#else + return (i << 8) | (i >> 8); +#endif +} + +//--------------------------------------------------------------------------------- +/** + * @brief function - Byte swap a 32 bit value + */ +uint32_t sftk_byte_swap(uint32_t i) +{ +#if defined(__clang__) || defined(__GNUC__) + return __builtin_bswap32(i); +#else + return ((i << 24) & 0xff000000) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | ((i >> 24) & 0x000000ff); +#endif +} diff --git a/src/sfeTk/sfeToolkit.h b/src/sfeTk/sfeToolkit.h index da1ec00..e634a24 100644 --- a/src/sfeTk/sfeToolkit.h +++ b/src/sfeTk/sfeToolkit.h @@ -6,7 +6,7 @@ The MIT License (MIT) -Copyright (c) 2023 SparkFun Electronics +Copyright (c) 2024 SparkFun Electronics Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -26,7 +26,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once +#include + /** @brief Common include file for the core of the SparkFun Electronics Toolkit */ #include "sfeTkError.h" + + +// byte order types/enum +enum class sfeTKByteOrder : uint8_t +{ + BigEndian = 0x01, + LittleEndian = 0x02 +}; + +// Note - toolkit *functions* start with sftk_ to avoid name collisions + +// Function to determine the byte order of the system +sfeTKByteOrder sftk_system_byteorder(void); + +uint8_t sftk_byte_swap(uint8_t i); +uint16_t sftk_byte_swap(uint16_t i); +uint32_t sftk_byte_swap(uint32_t i); + + +// Area for platform specific implementations. The interface/functions are +// defined here, with the expectation that the platform provides the implementation. + +// delay in milliseconds +void sftk_delay_ms(uint32_t ms); + +// ticks in milliseconds +uint32_t sftk_ticks_ms(void); \ No newline at end of file diff --git a/src/sfeTkArdI2C.cpp b/src/sfeTkArdI2C.cpp index ab7b20a..3d8dbc3 100644 --- a/src/sfeTkArdI2C.cpp +++ b/src/sfeTkArdI2C.cpp @@ -180,7 +180,7 @@ sfeTkError_t sfeTkArdI2C::writeRegisterRegionAddress(uint8_t *devReg, size_t reg _i2cPort->beginTransmission(address()); - if(devReg != nullptr && regLength > 0) + if (devReg != nullptr && regLength > 0) _i2cPort->write(devReg, regLength); _i2cPort->write(data, (int)length); @@ -209,11 +209,34 @@ sfeTkError_t sfeTkArdI2C::writeRegisterRegion(uint8_t devReg, const uint8_t *dat // sfeTkError_t sfeTkArdI2C::writeRegister16Region(uint16_t devReg, const uint8_t *data, size_t length) { - devReg = ((devReg << 8) & 0xff00) | ((devReg >> 8) & 0x00ff); + // Byteorder check + if (sftk_system_byteorder() != _byteOrder) + devReg = sftk_byte_swap(devReg); return writeRegisterRegionAddress((uint8_t *)&devReg, 2, data, length); } - +//--------------------------------------------------------------------------------- +// write16BitRegisterRegion16() +// +// Writes an array of bytes to a given 16-bit register on the target address +// +// Returns the number of bytes written, < 0 is an error +// +sfeTkError_t sfeTkArdI2C::writeRegister16Region16(uint16_t devReg, const uint16_t *data, size_t length) +{ + // if the system byte order is the same as the desired order, just send the buffer + if (sftk_system_byteorder() == _byteOrder) + return writeRegisterRegionAddress((uint8_t *)&devReg, 2, (uint8_t *)data, length * 2); + + // okay, we need to swap + devReg = sftk_byte_swap(devReg); + + uint16_t data16[length]; + for (size_t i = 0; i < length; i++) + data16[i] = ((data[i] << 8) & 0xff00) | ((data[i] >> 8) & 0x00ff); + + return writeRegisterRegionAddress((uint8_t *)&devReg, 2, (uint8_t *)data16, length * 2); +} /** * @brief Reads an array of bytes to a register on the target address. Supports any address size @@ -359,3 +382,28 @@ sfeTkError_t sfeTkArdI2C::readRegister16Region(uint16_t devReg, uint8_t *data, s devReg = ((devReg << 8) & 0xff00) | ((devReg >> 8) & 0x00ff); return readRegisterRegionAnyAddress((uint8_t *)&devReg, 2, data, numBytes, readBytes); } +//--------------------------------------------------------------------------------- +// read16BitRegisterRegion16() +// +// Reads an array of bytes to a given 16-bit register on the target address +// +// Returns the number of bytes read, < 0 is an error +// +sfeTkError_t sfeTkArdI2C::readRegister16Region16(uint16_t devReg, uint16_t *data, size_t numBytes, size_t &readWords) +{ + // if the system byte order is the same as the desired order, flip the address + if (sftk_system_byteorder() != _byteOrder) + devReg = sftk_byte_swap(devReg); + + + sfeTkError_t status = readRegisterRegionAnyAddress((uint8_t *)&devReg, 2, (uint8_t *)data, numBytes * 2, readWords); + + // Do we need to flip the byte order? + if (status == kSTkErrOk && sftk_system_byteorder() != _byteOrder) + { + for (size_t i = 0; i < numBytes; i++) + data[i] = sftk_byte_swap(data[i]); + } + readWords = readWords / 2; // convert to words + return status; +} \ No newline at end of file diff --git a/src/sfeTkArdI2C.h b/src/sfeTkArdI2C.h index dc73432..ac94991 100644 --- a/src/sfeTkArdI2C.h +++ b/src/sfeTkArdI2C.h @@ -31,6 +31,7 @@ over Inter-Integrated Circuit (I2C) in Arduino #include // Include our platform I2C interface definition. +#include "sfeTkArduino.h" #include /** @@ -41,8 +42,9 @@ class sfeTkArdI2C : public sfeTkII2C { public: /** - @brief Constructor + @brief Constructor */ + sfeTkArdI2C(void) : _i2cPort(nullptr), _bufferChunkSize{kDefaultBufferChunk} { } @@ -187,6 +189,18 @@ class sfeTkArdI2C : public sfeTkII2C */ sfeTkError_t writeRegister16Region(uint16_t devReg, const uint8_t *data, size_t length); + /** + @brief Writes a number of bytes starting at the given register's 16-bit address. + + @param devReg The device's register's address - 16 bit. + @param data Data to write. + @param length - length of data + + @retval sfeTkError_t kSTkErrOk on successful execution + + */ + sfeTkError_t writeRegister16Region16(uint16_t devReg, const uint16_t *data, size_t length); + /** @brief Reads a byte of data from the given register. @@ -240,6 +254,19 @@ class sfeTkArdI2C : public sfeTkII2C */ sfeTkError_t readRegister16Region(uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes); + /** + @brief Reads a block of data from the given 16-bit register address. + + @param reg The device's 16 bit register's address. + @param data Data buffer to read into + @param numBytes - Number of bytes to read/length of data buffer + @param[out] readBytes - number of bytes read + + @retval int returns kSTkErrOk on success, or kSTkErrFail code + + */ + sfeTkError_t readRegister16Region16(uint16_t reg, uint16_t *data, size_t numBytes, size_t &readBytes); + // Buffer size chunk getter/setter /** @brief set the buffer chunk size @@ -266,6 +293,8 @@ class sfeTkArdI2C : public sfeTkII2C return _bufferChunkSize; } + + protected: // note: The wire port is protected, allowing access if a sub-class is // created to implement a special read/write routine @@ -284,4 +313,5 @@ class sfeTkArdI2C : public sfeTkII2C /** The I2C buffer chunker - chunk size*/ size_t _bufferChunkSize; + }; diff --git a/src/sfeTkArdSPI.cpp b/src/sfeTkArdSPI.cpp index 276e3eb..54741be 100644 --- a/src/sfeTkArdSPI.cpp +++ b/src/sfeTkArdSPI.cpp @@ -120,7 +120,6 @@ sfeTkError_t sfeTkArdSPI::writeWord(uint16_t dataToWrite) return writeRegion((uint8_t *)&dataToWrite, sizeof(uint8_t)) > 0; } - //--------------------------------------------------------------------------------- // writeRegion() // @@ -240,6 +239,30 @@ sfeTkError_t sfeTkArdSPI::writeRegister16Region(uint16_t devReg, const uint8_t * return kSTkErrOk; } +//--------------------------------------------------------------------------------- +// 16 bit address and data version ... +sfeTkError_t sfeTkArdSPI::writeRegister16Region16(uint16_t devReg, const uint16_t *data, size_t length) +{ + if (!_spiPort) + return kSTkErrBusNotInit; + + // Apply settings before work + _spiPort->beginTransaction(_sfeSPISettings); + + // Signal communication start + digitalWrite(cs(), LOW); + _spiPort->transfer16(devReg); + + for (size_t i = 0; i < length; i++) + _spiPort->transfer16(*data++); + + // End communication + digitalWrite(cs(), HIGH); + _spiPort->endTransaction(); + + return kSTkErrOk; +} +//--------------------------------------------------------------------------------- sfeTkError_t sfeTkArdSPI::readRegisterByte(uint8_t devReg, uint8_t &data) { size_t nRead; @@ -320,3 +343,36 @@ sfeTkError_t sfeTkArdSPI::readRegister16Region(uint16_t devReg, uint8_t *data, s return kSTkErrOk; } + +//--------------------------------------------------------------------------------- +// readRegister16Region16() +// +// Reads an array of uint16 to a given a 16 bit register on the target address +// +// Returns kSTkErrOk on success +// +sfeTkError_t sfeTkArdSPI::readRegister16Region16(uint16_t devReg, uint16_t *data, size_t numBytes, size_t &readWords) +{ + if (!_spiPort) + return kSTkErrBusNotInit; + + // Apply settings + _spiPort->beginTransaction(_sfeSPISettings); + + // Signal communication start + digitalWrite(cs(), LOW); + + // A leading "1" must be added to transfer with devRegister to indicate a "read" + _spiPort->transfer16(devReg); + + for (size_t i = 0; i < numBytes; i++) + *data++ = _spiPort->transfer16(0x00); + + // End transaction + digitalWrite(cs(), HIGH); + _spiPort->endTransaction(); + + readWords = numBytes; + + return kSTkErrOk; +} \ No newline at end of file diff --git a/src/sfeTkArdSPI.h b/src/sfeTkArdSPI.h index 113853e..8ab0ce4 100644 --- a/src/sfeTkArdSPI.h +++ b/src/sfeTkArdSPI.h @@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once +#include "sfeTkArduino.h" #include #include @@ -178,6 +179,18 @@ class sfeTkArdSPI : public sfeTkISPI */ sfeTkError_t writeRegister16Region(uint16_t devReg, const uint8_t *data, size_t length); + /** + @brief Writes a number of uint16s 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. + @param length - length of data + + @retval sfeTkError_t - kSTkErrOk on success + */ + sfeTkError_t writeRegister16Region16(uint16_t devReg, const uint16_t *data, size_t length); + /** @brief Read a single byte from the given register @@ -224,6 +237,19 @@ class sfeTkArdSPI : public sfeTkISPI */ virtual sfeTkError_t readRegister16Region(uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes); + /** + @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 reg The device's register's 16 bit address. + @param[out] data Data buffer to read into + @param numBytes - Length of data to read/size of data buffer + @param[out] readBytes - Number of bytes read + + @retval sfeTkError_t - true on success + */ + virtual sfeTkError_t readRegister16Region16(uint16_t reg, uint16_t *data, size_t numBytes, size_t &readBytes); + protected: // note: The instance data is protected, allowing access if a sub-class is // created to implement a special read/write routine diff --git a/src/sfeTkArduino.cpp b/src/sfeTkArduino.cpp new file mode 100644 index 0000000..fd5cca2 --- /dev/null +++ b/src/sfeTkArduino.cpp @@ -0,0 +1,37 @@ +/* +@brief sfeTkArduino.cpp + +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. + +*/ + +#include + +// Implements the sfeToolkit functions for the Arduino platform + +void sftk_delay_ms(uint32_t ms) +{ + delay(ms); +} + +uint32_t sftk_ticks_ms(void) +{ + return millis(); +} \ No newline at end of file diff --git a/src/sfeTkArduino.h b/src/sfeTkArduino.h new file mode 100644 index 0000000..5ebb017 --- /dev/null +++ b/src/sfeTkArduino.h @@ -0,0 +1,39 @@ + +/* +@brief sfeTkArduino.h + +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 + +// Purpose: +// +// "Arduino-ized" value of toolkit values constants" + +// Just include the toolkit headers + +#include + +// Arduino-ize our byte order types + +const sfeTKByteOrder SFTK_MSBFIRST = sfeTKByteOrder::BigEndian; +const sfeTKByteOrder SFTK_LSBFIRST = sfeTKByteOrder::LittleEndian; \ No newline at end of file