Skip to content

Commit 6d169d2

Browse files
authored
Move version 1.0 in prep of release - go go go
Release/v01.00.00
2 parents 38a1334 + b7c90c4 commit 6d169d2

31 files changed

+2125
-1745
lines changed

.github/workflows/build-deploy-ghpages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Documentation and Deploy
1+
name: Documentation
22

33
on:
44
push:

README.md

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,102 @@
77
![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/sparkfun/SparkFun_Toolkit)
88
![Documentation Build](https://github.com/sparkfun/SparkFun_Toolkit/actions/workflows/build-deploy-ghpages.yml/badge.svg)
99

10-
The SparkFun Toolkit provides a common set of core functionality for use across the SparkFun Arduino Driver library. Instead of each device driver library implementing it's own communication layers, error types and design, the SparkFun Toolkit library is used.
10+
The SparkFun Toolkit provides a common set of core functionality for use across the spectrum of SparkFun developed embedded libraries and applications. It provides a well tested, extensively used, and abstract foundational layer of functionality to use across a wide-range of solutions.
11+
12+
This, the first iteration of the SparkFun Toolkit focuses on device communication - namely the communication between a embedded microprocessor and a peripheral devices. Focusing on the *communication bus* aspect of embedded development, the toolkit simplifies system development by providing a proven bus implementation, as well as a set of abstract interfaces that enable rapid development of multi-bus type implementations.
13+
14+
In addition to providing a set of common device bus communication functionality, the SparkFun Toolkit is structure to provide a *platform independent* solution. While the initial implementation targets Arduino development, the architecture is patterned to define a common core of functionality and interfaces that are platform agnostic. Use of the SparkFun Toolkit within a non-Arduino, c++ environment, requires the implementation of small set of platform specific functionality.
1115

1216
## Motivation
1317

14-
Often, the same core functionality is implemented with a majority of our Arduino libraries, each implementation providing the same functionality, but implemented differently. The result is solutions that have different quirks, and impossible to maintain/support effectively. The SparkFun Toolkit solves this issue.
18+
Often, the same core functionality is implemented within a majority of our Arduino libraries, with each implementation providing the same functionality, but implemented differently. The result of this are different solutions that delivery the same functionality, but each have their unique quirks and behavior oddities. As this implementation patter expands, it becomes impossible to maintain/support effectively.
19+
20+
An example of this is software libraries provided in support of the SparkFun qwiic ecosystem. With over 200 sensors, input devices and accessories, the implementation and maintenance of the driver communication layers are difficult burden that the SparkFun Toolkit addresses.
21+
22+
## The SparkFun Toolkit
1523

1624
The SparkFun Toolkit provides a single implementation of common functionality used in the software developed for SparkFun boards. Initially targeted at the Arduino development environment, the SparkFun Toolkit delivers the following benefits:
1725

1826
* Use a well-tested and validated implementation
1927
* Reduce development effort
2028
* Implement functionality following a common structure
29+
* Designed following a platform independent architectural pattern
2130
* Set the foundation for future enhancements - as the capabilities of the toolkit grow, these features become available with little to any implementation effort.
2231

32+
### General Architecture
33+
34+
Implemented using C++, the SparkFun toolkit follows a simple two layered approach in it's design: A core foundational layer, and a platform specific layer.
35+
36+
```mermaid
37+
---
38+
title: General Architecture Structure
39+
---
40+
classDiagram
41+
class CoreToolkit["Core Toolkit Interfaces"]
42+
class PlatformOne["Platform Implementation"]
43+
CoreToolkit <|-- PlatformOne
44+
45+
```
46+
And as additional plaforms are added, they also implement/inherit from the SparkFun Toolkit Core.
47+
```mermaid
48+
---
49+
title: Multi-Platform Structure
50+
---
51+
classDiagram
52+
class CoreToolkit["Core Toolkit Interfaces"]
53+
class PlatformOne["Platform One"]
54+
class PlatformTwo["Platform Two"]
55+
56+
CoreToolkit <|-- PlatformOne
57+
CoreToolkit <|-- PlatformTwo
58+
```
59+
60+
When using the SparkFun Toolkit, the intent is for the implementation to follow the same pattern: A platform independent layer that works with the SparkFun Toolkit core, and a platform specific layer that utilizes the SparkFun Toolkit platform specific implementation.
61+
62+
```mermaid
63+
---
64+
title: Application Structure
65+
---
66+
classDiagram
67+
direction TD
68+
note for ApplicationCore "Application Logic"
69+
class ApplicationCore["Application Core"]
70+
class CoreToolkit["Core Toolkit Interfaces"]
71+
72+
note for CoreToolkit "SparkFun Toolkit"
73+
class ApplicationPlatform["Application Platform"]
74+
style ApplicationPlatform fill:#909090
75+
class PlatformOne["Platform Implementation"]
76+
style PlatformOne fill:#909090
77+
78+
CoreToolkit <|-- PlatformOne
79+
ApplicationCore <--> Application Platform
80+
81+
```
82+
83+
If/when the application is moved to another platform, just the platform specific logic needs implementation.
84+
2385
## Documentation
2486

25-
The SparkFun Toolkit Development documentation is available [here](https://docs.sparkfun.com/SparkFun_Toolkit)
87+
The SparkFun Toolkit Development documentation is available [here](https://docs.sparkfun.com/SparkFun_Toolkit). This includes doxygen generated class/API documentation, as well as additional architectural details.
88+
89+
## Examples
90+
91+
The best way to understand and use the SparkFun Toolkit is to see it being used on other libraries. For our SparkFun developed libraries and firmware that use the SparkFun Toolkit, their associated github repositories are tagged with [sparkfun-toolkit](https://github.com/topics/sparkfun-toolkit) tag.
92+
2693

2794
## Installation and Use
2895

2996
To use the SparkFun Toolkit directly, or in library development kit is installable via the Arduino Library Manager - search for `SparkFun ToolKit` within the Arduino Library Manager to install.
3097

3198
However, for solutions that use the SparkFun Toolkit, it is installed automatically during the Arduino library installation process, by marking the Toolkit as a dependency when publishing your library.
3299

33-
To mark the `SparkFun Toolkit` as a dependency, add the following line to the `library.properties` file for your library.
100+
To mark the `SparkFun Toolkit` as a dependency, add the following line to the `library.properties` file for your library.
34101

35102
```INI
36-
depends=SparkFun Toolkit
103+
depends=SparkFun Toolkit (>=1.0.0)
37104
```
38105

39-
## Examples
40-
41-
The following Arduino Libraries are making use of the SparkFun Toolkit:
106+
> [!NOTE]
107+
> A version indicator is included to ensure your library uses the correct version of the toolkit.
42108
43-
* [SparkFun Qwiic Pulsed Coherent Radar Sensor XM125](https://github.com/sparkfun/SparkFun_Qwiic_XM125_Arduino_Library)
44-
* [SparkFun Qwiic AS7331 Spectral UV Sensor](https://github.com/sparkfun/SparkFun_AS7331_Arduino_Library)

docs/ar_ibus.md

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,32 @@ The key class to support this pattern are:
3535

3636
| | |
3737
|------|-------|
38-
|**sfeTkIBus** | A virtual C++ class that device the bus ```sfeTkIBus``` interface |
39-
|**sfeTkII2C** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for I2C devices|
40-
|**sfeTkISPI** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for SPI devices |
38+
|**sfTkIBus** | A virtual C++ class that device the bus ```sfeTkIBus``` interface |
39+
|**sfTkII2C** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for I2C devices|
40+
|**sfTkISPI** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for SPI devices |
4141

42-
### The sfeTkIBus Interface
42+
### The sfTkIBus Interface
4343

4444
The key to meeting the goals of the Toolkit is the IBus interface. This interface defines the methods used to communicate with a device. The setup, configuration and implementation of this interface is performed by platform specific implementations of the interface.
4545

46-
The interface methods:
46+
The bus implements methods that perform the following
4747

4848
| Method| Definition |
4949
|------|-------|
50-
|**writeRegisterByte** | Write a byte of data to a particular register of a device |
51-
|**writeRegisterWord** | Write a word of data to a particular register of a device |
52-
|**writeRegisterRegion** | Write an array of data to a particular register of a device|
53-
|**readRegisterByte** | Read a byte of data from a particular register of a device |
54-
|**readRegisterWord** | Read a word of data from a particular register of a device |
55-
|**readRegisterRegion** | Read an array of data from a particular register of a device |
50+
|**writeRegister(...)** | Overloaded set of methods to write data to a specified register|
51+
|**readRegister(...)** | Overloaded set of methods to read data from a specified register|
52+
|**writeData(...)** | An overloaded set of methods to write data directly to the device|
53+
54+
Additionally a set of explicitly named methods for different core types are provided.
5655

5756
> [!NOTE]
5857
> This interface only defines the methods to read and write data on the given bus. Any address, or bus specific settings is provided/implemented by the implementation/specialization of this interface.
5958
60-
The Inteface diagram for the ```sfeTkIBus``` is:
61-
62-
![IIBus Interface](images/tk_uml_ibus.png)
59+
Specific details for this class are detailed [here](https://docs.sparkfun.com/SparkFun_Toolkit/classsf_tk_i_bus.html)
6360

64-
### The sfeTkII2C Implementation
61+
### The sfTkII2C Implementation
6562

66-
This class sub-classes from the ```sfeTkIBus``` interface adding additional functionally focused on supporting an I2C implementation. This class does not implement the IIBus interface, so it's abstract, but the class adds the additional functionality.
63+
This class sub-classes from the ```sfTkIBus``` interface adding additional functionally focused on supporting an I2C implementation. This class does not implement the IIBus interface, so it's abstract, but the class adds the additional functionality.
6764

6865
| Method| Definition |
6966
|------|-------|
@@ -72,15 +69,13 @@ This class sub-classes from the ```sfeTkIBus``` interface adding additional func
7269
|**address** | Returns the address used by this I2C object |
7370

7471
> [!NOTE]
75-
> The ```sfeTkII2C``` class manages the device address for the I2C bus. As such, each I2C device instantiates/uses an instance of the ```sfeTkII2C``` class.
72+
> The ```sfTkII2C``` class manages the device address for the I2C bus. As such, each I2C device instantiates/uses an instance of the ```sfTkII2C``` class.
7673
77-
The class diagram for the ```sfeTkII2C``` interface is the following:
78-
79-
![II2C Class Diagram](images/tk_uml_ii2c.png)
74+
The details for the ```sfeTkII2C``` interface are [here](https://docs.sparkfun.com/SparkFun_Toolkit/classsf_tk_i_i2_c.html)
8075

8176
### The sfeTkISPI Implementation
8277

83-
This class sub-classes from the ```sfeTkIBus``` interface adding additional functionally focused on supporting an SPI implementation. This interface provides the additional functionality.
78+
This class sub-classes from the ```sfTkIBus``` interface adding additional functionally focused on supporting an SPI implementation. This interface provides the additional functionality.
8479

8580
| Method| Definition |
8681
|------|-------|
@@ -90,53 +85,47 @@ This class sub-classes from the ```sfeTkIBus``` interface adding additional func
9085
> [!NOTE]
9186
> The ```sfeTkISPI``` class manages CS Pin for the SPI bus. As such, each SPI device instantiates/uses an instance of the ```sfeTkISPI``` class.
9287
93-
The class diagram of these base class interfaces/implementation:
94-
95-
![ISPI Class Diagram](images/tk_uml_ispi.png)
88+
The details for the ```sfTkII2C``` interface are [here](https://docs.sparkfun.com/SparkFun_Toolkit/classsf_tk_i_s_p_i.html)
9689

97-
## sfeTkIBus - Arduino Implementation
90+
## sfTkIBus - Arduino Implementation
9891

99-
The initial implementation of the toolkit IBus interface is for the Arduino environment. This implementation consists of two classes, ```sfeTkArdI2C``` and ```sfeTkArdSPI```, each of which sub-class from their respective bus type interfaces within the core toolkit.
92+
The initial implementation of the toolkit IBus interface is for the Arduino environment. This implementation consists of two classes, ```sfTkArdI2C``` and ```sfTkArdSPI```, each of which sub-class from their respective bus type interfaces within the core toolkit.
10093

10194
These driver implementations provide the platform specific implementation for the toolkit bus interfaces, supporting the methods defined by the interfaces, as well as contain and manage the platform specific settings and attributes for each bus type.
10295

10396
> [!IMPORTANT]
10497
> The intent is that each user of an particular - a device in most cases - contains an instance of the specific bus class.
10598
106-
### The sfeTkArdI2C Class
99+
### The sfTkArdI2C Class
107100

108-
This class provides the Arduino implementation of I2C in the SparkFun Toolkit. It implements the methods of the ```sfeTkIBus``` and ```sfeTkII2C``` interfaces, as well as manages any Arduino specific state.
101+
This class provides the Arduino implementation of I2C in the SparkFun Toolkit. It implements the methods of the ```sfTkIBus``` and ```sfTkII2C``` interfaces, as well as manages any Arduino specific state.
109102

110-
The class diagram for the sfeTkArdI2C class:
103+
Details for this class are located [here](https://docs.sparkfun.com/SparkFun_Toolkit/classsf_tk_ard_i2_c.html)
111104

112-
![Arduino I2C Class Diagram](images/tk_uml_ardi2c.png)
105+
### The sfTkArdSPI Class
113106

114-
### The sfeTkArdSPI Class
107+
This class provides the Arduino implementation of SPI in the SparkFun Toolkit. It implements the methods of the ```sfTkIBus``` and ```sfTkISPI``` interfaces, as well as manages any Arduino specific state for the SPI bus - namely the SPISettings class.
115108

116-
This class provides the Arduino implementation of SPI in the SparkFun Toolkit. It implements the methods of the ```sfeTkIBus``` and ```sfeTkISPI``` interfaces, as well as manages any Arduino specific state for the SPI bus - namely the SPISettings class.
109+
Before each use of the SPI bus, the methods of the ```sfTkArdSPI``` uses an internal SPISettings class to ensure the SPI bus is operating in the desired mode for the device.
117110

118-
Before each use of the SPI bus, the methods of the ```sfeTkArdSPI``` uses an internal SPISettings class to ensure the SPI bus is operating in the desired mode for the device.
111+
Details for this class are located [here](https://docs.sparkfun.com/SparkFun_Toolkit/classsf_tk_ard_s_p_i.html)
119112

120-
The class diagram for the sfeTkArdSPI class:
113+
## sfTkIBus Use
121114

122-
![Arduino SPI Class Diagram](images/tk_uml_ardspi.png)
123-
124-
## sfeTkIBus Use
125-
126-
The general steps when using the sfeTkIBus in device development are outlined in the following steps. This example uses the Arduino implementation of the bus.
115+
The general steps when using the sfTkIBus in device development are outlined in the following steps. This example uses the Arduino implementation of the bus.
127116

128117
The general pattern for a device driver implementation that uses the SparkFun Toolkit is the following:
129118

130119
### Implement a Platform Independent Driver
131120

132-
The first step is to implement a core, platform independent version of the driver that communicates to the target device using the methods of a ```sfeTkIBus``` interface. By limiting use to the IBus interface, the core implementation can use any bus type or platform that implements the sfeTkIBus interface.
121+
The first step is to implement a core, platform independent version of the driver that communicates to the target device using the methods of a ```sfTkIBus``` interface. By limiting use to the IBus interface, the core implementation can use any bus type or platform that implements the sfeTkIBus interface.
133122

134123
> [!IMPORTANT]
135-
> At this level, the driver is only using a ```sfeTkIBus``` interface, not any specific bus implementation.
124+
> At this level, the driver is only using a ```sfTkIBus``` interface, not any specific bus implementation.
136125
137126
This driver has the following unique functionality:
138127

139-
1) A method to set the object that implements the ```sfeTkIBus``` interface object should use. Since
128+
1) A method to set the object that implements the ```sfTkIBus``` interface object should use or sets the bus in a ```begin()``` method.
140129
1) If the device supports identification capabilities, the driver provides this functionality.
141130

142131
#### Simple Example of an Independent Driver Implementation
@@ -152,36 +141,42 @@ class myDriverClass
152141
{
153142
public:
154143

155-
myDriverClass(uint8_t address) : _addr{address}, _theBus{nullptr}{}
144+
myDriverClass() : _theBus{nullptr}{}
156145

157-
bool begin()
146+
sfTkError_t begin(sfTkBus *theBus = nullptr)
158147
{
159148
// initialize things ...
160149

161-
return true;
162-
}
163-
void setCommunicationBus(sfeTkIBus *theBus)
164-
{
150+
if (_theBus == nullptr)
151+
return ksfTkErrFail;
152+
165153
_theBus = theBus;
154+
return ksfTkErrOk;
166155
}
167156

168-
bool updateDeviceData(uint8_t *data, size_t len)
157+
sfTkError_t updateDeviceData(uint8_t *data, size_t len)
169158
{
170159
if (!_theBus || !data || len == 0)
171-
return false;
160+
return ksfTkErrFail;
172161

173-
sfeTkError_t status = _theBus->writeRegisterRegion(THE_REG, data, len);
162+
return _theBus->writeRegister(THE_REG, data, len);
174163

175164
return (status == kSTkErrOk);
176165
}
177166

178-
bool checkDeviceID()
167+
sfTkError_t checkDeviceID()
179168
{
180169
// do some device ID checks in registers ...etc
181-
return true;
170+
return kSTkErrOk;
182171
}
172+
// and additional methods for the driver ..
173+
sfTkError_t doSomethingA(int32_t);
174+
sfTkError_t getValueA(uint32_t&);
175+
sfTkError_t setPropertyB(double);
176+
177+
183178
private:
184-
uint8_t _addr;
179+
185180
sfeTkIBus *_theBus;
186181
};
187182
```
@@ -213,29 +208,27 @@ class myArduinoDriverI2C : public myDriverClass
213208
myArduinoDriverI2C()
214209
{}
215210
216-
bool begin()
211+
bool begin(const uint8_t address = SF_BMV080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire)
217212
{
218-
if (_theI2CBus.init(MY_DEVICE_ADDRESS) != kSTkErrOk)
213+
if (_theI2CBus.init(wirePOrt, MY_DEVICE_ADDRESS) != ksfTkErrOk)
219214
return false;
220215
221216
// OPTIONAL: If your device supports repeat starts.
222217
_theI2CBus.setStop(false);
223218
224-
setCommunicationBus(&_theI2CBus);
225-
226-
return myDriverClass::begin();
219+
return myDriverClass::begin(&_theI2CBus);
227220
}
228221
229222
bool isConnected()
230223
{
231-
if (_theI2CBus.ping() != kSTkErrOk)
224+
if (_theI2CBus.ping() != ksfTkErrOk)
232225
return false;
233226
234-
return checkDeviceID();
227+
return checkDeviceID() == kstTkErrOk;
235228
}
236229
237230
private:
238-
sfeTkArdI2C _theI2CBus;
231+
sfTkArdI2C _theI2CBus;
239232
};
240233
```
241234

@@ -254,27 +247,30 @@ class myArduinoDriveSPI : public myDriverClass
254247
myArduinoDriverSPI()
255248
{}
256249

257-
bool begin()
250+
bool begin(uint8_t csPin, SPIClass &spiPort = SPI,
251+
SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE0))
252+
258253
{
259-
SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE3);
260254

261-
if (_theSPIBus.init(SPI, spiSettings, MY_DEFAULT_CS, true) != kSTkErrOk)
255+
if (_theSPIBus.init(spiPort, spiSettings, csPin, true) != ksfTkErrOk)
262256
return false;
263-
setCommunicationBus(&_theSPIBus);
264257

265-
return myDriverClass::begin();
258+
return myDriverClass::begin(&_theSPIBus) == ksfTkErrOk;
266259
}
267260

268261
bool isConnected()
269262
{
270-
return checkDeviceID();
263+
return checkDeviceID() == ksfTkErrOk;
271264
}
272265

273266
private:
274-
sfeTkArdSPI _theSPIBus;
267+
sfTkArdSPI _theSPIBus;
275268
};
276269
```
277270

271+
> [!IMPORTANT]
272+
>The I2C and SPI versions of the driver just manage the specific bus setup and initialization - beyond that, the core class, which ***only*** operates using the bus interface class forms the core of both implementations.
273+
278274
## Summary
279275

280276
In summary, the SparkFun Toolkit Bus Interface sets a standard that device drivers can implement against without concern for platform or bus type. Using common interface implementation patterns, the implementation delivers on the goals for this subsystem - namely:

docs/images/tk_uml_ardi2c.png

-298 KB
Binary file not shown.

docs/images/tk_uml_ardspi.png

-276 KB
Binary file not shown.

docs/images/tk_uml_ibus.png

-64 KB
Binary file not shown.

docs/images/tk_uml_ii2c.png

-171 KB
Binary file not shown.

docs/images/tk_uml_ispi.png

-163 KB
Binary file not shown.

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.9.2
2+
version=1.0.0
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=A utility library that other SparkFun libraries can take advantage of.

0 commit comments

Comments
 (0)