Skip to content

Commit e83827b

Browse files
authored
Merge pull request #20 from sparkfun/main
Push changes to working branch.
2 parents 5da9146 + e940f13 commit e83827b

File tree

14 files changed

+527
-317
lines changed

14 files changed

+527
-317
lines changed

.github/workflows/compile-sketch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
libraries: |
102102
- source-path: ./
103103
sketch-paths: |
104-
- test/test
104+
- tests
105105
enable-warnings-report: true
106106
enable-deltas-report: true
107107
verbose: true

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Toolkit
2-
version=0.1.0
2+
version=0.8.0
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=A utility library that other SparkFun libraries can take advantage of.

src/SparkFun_Toolkit.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ SparkFun_Toolkit.h
44
55
The MIT License (MIT)
66
7-
Copyright (c) 2022 SparkFun Electronics
7+
Copyright (c) 2023 SparkFun Electronics
8+
89
Permission is hereby granted, free of charge, to any person obtaining a
910
copy of this software and associated documentation files (the "Software"),
1011
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
1415
above copyright notice and this permission notice shall be included in all
1516
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
1617
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
17-
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18-
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19-
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20-
SOFTWARE.
18+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
2124
*/
2225

2326
#pragma once
@@ -29,5 +32,6 @@ SOFTWARE.
2932

3033
// Just include the toolkit headers
3134

35+
#include <sfeTk/sfeToolkit.h>
3236
#include "sfeTkArdI2C.h"
3337
#include "sfeTkArdSPI.h"

src/sfeTk/sfeTkError.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
// sfeTkError.h
3+
//
4+
// General header file for the SparkFun Toolkit
5+
/*
6+
The MIT License (MIT)
7+
8+
Copyright (c) 2023 SparkFun Electronics
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions: The
16+
above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
18+
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
19+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
25+
*/
26+
27+
#pragma once
28+
29+
30+
#include <cstdint>
31+
32+
//
33+
// General Concept
34+
// A SparkFun Toolkit error system. The goal is to keep this simple.
35+
//
36+
// This mimics a vareity of systems, using an int type for error codes,
37+
// where:
38+
// 0 = okay
39+
// -1 = general failure
40+
// >0 = an informative error
41+
//
42+
// Since *subsystems* in the toolkit can have their own errors,
43+
// A start range for these errors are defined. Values > than this value
44+
// define the errors for the set subsystem. These start ranges are set
45+
// in this file, with actual error values defined in the the respective
46+
// subsystem header files.
47+
//
48+
// Define our error codes/type
49+
typedef int32_t sfeTkError_t;
50+
51+
// General errors
52+
53+
const sfeTkError_t kSTkErrFail = -1; // general fail
54+
const sfeTkError_t kSTkErrOk = 0; // success
55+
56+
// Base error number for IBus/Bus operations Bus errors are not less than this.
57+
const sfeTkError_t kSTkErrBaseBus = 0x1000;

src/sfeTk/sfeTkIBus.h

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
77
The MIT License (MIT)
88
9-
Copyright (c) 2022 SparkFun Electronics
9+
Copyright (c) 2023 SparkFun Electronics
10+
1011
Permission is hereby granted, free of charge, to any person obtaining a
1112
copy of this software and associated documentation files (the "Software"),
1213
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
2122
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2223
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2324
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
2426
*/
2527

2628
#pragma once
2729

28-
#include <cstdint>
30+
#include "sfeTkError.h"
31+
32+
33+
// Define our error codes for the bus. Note Errors are negative, warnings/info postive
34+
// BUT keep the same increment on the base
35+
36+
const sfeTkError_t kSTkErrBusNullPtr = kSTkErrFail * (kSTkErrBaseBus + 1);
37+
const sfeTkError_t kSTkErrBusTimeout = kSTkErrFail * (kSTkErrBaseBus + 2);
38+
const sfeTkError_t kSTkErrBusNoReponse = kSTkErrFail * (kSTkErrBaseBus + 3);
39+
const sfeTkError_t kSTkErrBusDataTooLong = kSTkErrFail * (kSTkErrBaseBus + 4);
40+
const sfeTkError_t kSTkErrBusNullSettings = kSTkErrFail * (kSTkErrBaseBus + 5);
41+
const sfeTkError_t kSTkErrBusNullBuffer = kSTkErrFail * (kSTkErrBaseBus + 6);
42+
const sfeTkError_t kSTkErrBusUnderRead = kSTkErrBaseBus + 7;
43+
const sfeTkError_t kSTkErrBusNotEnabled = kSTkErrBaseBus + 8;
44+
45+
// Define the bus interface.
2946

3047
class sfeTkIBus
3148
{
3249
public:
33-
/// @brief Write a single byte to the given register
34-
///
35-
/// @param devReg The device's register's address.
36-
/// @param data Data to write.
37-
///
38-
/// @retval bool - true on successful execution.
39-
///
40-
virtual bool writeRegisterByte(uint8_t devReg, uint8_t data) = 0;
41-
42-
/// @brief Write a single word (16 bit) to the given register
43-
///
44-
/// @param devReg The device's register's address.
45-
/// @param data Data to write.
46-
///
47-
/// @retval bool - true on successful execution.
48-
///
49-
virtual bool writeRegisterWord(uint8_t devReg, uint16_t data) = 0;
50-
51-
/// @brief Writes a number of bytes starting at the given register's address.
52-
///
53-
/// @param devAddr The device's address/pin
54-
/// @param devReg The device's register's address.
55-
/// @param data Data to write.
56-
///
57-
/// @retval int returns the number of bytes written, < 0 on error
58-
///
59-
virtual int writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) = 0;
60-
61-
/// @brief Read a single byte from the given register
62-
///
63-
/// @param devReg The device's register's address.
64-
/// @param data Data to read.
65-
///
66-
/// @retval bool - true on successful execution.
67-
///
68-
virtual bool readRegisterByte(uint8_t devReg, uint8_t &data) = 0;
69-
70-
/// @brief Read a single word (16 bit) from the given register
71-
///
72-
/// @param devReg The device's register's address.
73-
/// @param data Data to read.
74-
///
75-
/// @retval bool - true on successful execution.
76-
///
77-
virtual bool readRegisterWord(uint8_t devReg, uint16_t &data) = 0;
78-
79-
/// @brief Reads a block of data from the given register.
80-
///
81-
/// @param devAddr The device's I2C address.
82-
/// @param devReg The device's register's address.
83-
/// @param data Data to write.
84-
///
85-
/// @retval int returns 0 on success, or error code
86-
///
87-
virtual int readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes) = 0;
50+
/*--------------------------------------------------------------------------
51+
@brief Write a single byte to the given register
52+
53+
@param devReg The device's register's address.
54+
@param data Data to write.
55+
56+
@retval sfeTkError_t - kSTkErrOk on successful execution.
57+
58+
*/
59+
virtual sfeTkError_t writeRegisterByte(uint8_t devReg, uint8_t data) = 0;
60+
61+
/*--------------------------------------------------------------------------
62+
@brief Write a single word (16 bit) to the given register
63+
64+
@param devReg The device's register's address.
65+
@param data Data to write.
66+
67+
@retval sfeTkError_t - kSTkErrOk on successful execution.
68+
69+
*/
70+
virtual sfeTkError_t writeRegisterWord(uint8_t devReg, uint16_t data) = 0;
71+
72+
/*--------------------------------------------------------------------------
73+
@brief Writes a number of bytes starting at the given register's address.
74+
75+
@param devAddr The device's address/pin
76+
param devReg The device's register's address.
77+
@param data Data to write.
78+
79+
@retval int returns the number of bytes written, or kSTkErrFail on error
80+
81+
*/
82+
virtual int32_t writeRegisterRegion(uint8_t devReg, const uint8_t *data, size_t length) = 0;
83+
84+
/*--------------------------------------------------------------------------
85+
@brief Read a single byte from the given register
86+
87+
@param devReg The device's register's address.
88+
@param data Data to read.
89+
90+
@retval sfeTkError_t - kSTkErrOk on successful execution.
91+
92+
*/
93+
virtual sfeTkError_t readRegisterByte(uint8_t devReg, uint8_t &data) = 0;
94+
95+
/*--------------------------------------------------------------------------
96+
@brief Read a single word (16 bit) from the given register
97+
98+
@param devReg The device's register's address.
99+
@param data Data to read.
100+
101+
@retval sfeTkError_t - kSTkErrOk on successful execution.
102+
*/
103+
virtual sfeTkError_t readRegisterWord(uint8_t devReg, uint16_t &data) = 0;
104+
105+
/*--------------------------------------------------------------------------
106+
@brief Reads a block of data from the given register.
107+
108+
@param devAddr The device's I2C address.
109+
@param devReg The device's register's address.
110+
@param data Data to write.
111+
112+
@retval int returns kSTkErrOk on success, or kSTkErrFail code
113+
114+
*/
115+
virtual sfeTkError_t readRegisterRegion(uint8_t reg, uint8_t *data, size_t numBytes) = 0;
88116
};
89117

90118
//};

src/sfeTk/sfeTkII2C.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//
44
// Defines the I2C communication bus interface for the SparkFun Electronics Toolkit
55
/*
6-
76
The MIT License (MIT)
87
9-
Copyright (c) 2022 SparkFun Electronics
8+
Copyright (c) 2023 SparkFun Electronics
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
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
2121
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2222
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2323
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
2425
*/
2526

2627
#pragma once
@@ -37,26 +38,31 @@ class sfeTkII2C : public sfeTkIBus
3738
{
3839
}
3940

40-
///
41-
/// @brief A simple ping of the device at the set address
42-
///
43-
/// @retval bool - true on success, false on failure
44-
///
45-
virtual bool ping() = 0;
46-
47-
/// @brief setter for the I2C address
48-
///
49-
/// @param devAddr The device's address
50-
///
41+
/*--------------------------------------------------------------------------
42+
@brief A simple ping of the device at the set address
43+
44+
@retval sfeTkError_t - ok on success
45+
46+
*/
47+
virtual sfeTkError_t ping() = 0;
48+
49+
/*--------------------------------------------------------------------------
50+
@brief setter for the I2C address
51+
52+
@param devAddr The device's address
53+
54+
*/
5155
virtual void setAddress(uint8_t devAddr)
5256
{
5357
_address = devAddr;
5458
}
5559

56-
/// @brief getter for the I2C address
57-
///
58-
/// @retval uint8_t returns the address for the device
59-
///
60+
/*--------------------------------------------------------------------------
61+
@brief getter for the I2C address
62+
63+
@retval uint8_t returns the address for the device
64+
65+
*/
6066
virtual uint8_t address(void)
6167
{
6268
return _address;

src/sfeTk/sfeTkISPI.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
77
The MIT License (MIT)
88
9-
Copyright (c) 2022 SparkFun Electronics
9+
Copyright (c) 2023 SparkFun Electronics
10+
1011
Permission is hereby granted, free of charge, to any person obtaining a
1112
copy of this software and associated documentation files (the "Software"),
1213
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
2122
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2223
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2324
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
2426
*/
2527

2628
#pragma once
@@ -37,19 +39,24 @@ class sfeTkISPI : public sfeTkIBus
3739
sfeTkISPI(uint8_t csPin) : _cs{csPin}
3840
{
3941
}
40-
/// @brief setter for the CS Pin
41-
///
42-
/// @param devCS The device's CS Pin
43-
///
42+
43+
/*--------------------------------------------------------------------------
44+
@brief setter for the CS Pin
45+
46+
@param devCS The device's CS Pin
47+
48+
*/
4449
virtual void setCS(uint8_t devCS)
4550
{
4651
_cs = devCS;
4752
}
4853

49-
/// @brief getter for the cs pin
50-
///
51-
/// @retval uint8_t returns the CS pin for the device
52-
///
54+
/*--------------------------------------------------------------------------
55+
@brief getter for the cs pin
56+
57+
@retval uint8_t returns the CS pin for the device
58+
59+
*/
5360
virtual uint8_t cs(void)
5461
{
5562
return _cs;

0 commit comments

Comments
 (0)