Skip to content

Commit 361fa6d

Browse files
committed
finish up initial documentation
1 parent 055d478 commit 361fa6d

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
# SparkFun Toolkit Arduino Library
22

33
![Toolkit Tests Builds](https://github.com/sparkfun/SparkFun_Toolkit/actions/workflows/compile-sketch.yml/badge.svg)
4+
5+
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.
6+
7+
By using the SparkFun Toolkit, Arduino drivers achieve the following benefits:
8+
9+
* Use a well-tested and validated implementation
10+
* Reduce development effort
11+
* Implement functionality following a common structure
12+
* Set the foundation for future enhancements - as the capabilities of the toolkit grow, these features become available with little to any implementation effort.
13+
14+
## Current Status
15+
16+
### December 2023
17+
18+
The SparkFun Toolkit is available as a *Beta* release, with the intent of testing and validation by SparkFun. The community are free to use this toolkit with the understanding that interfaces, types and class structures could change.
19+
20+
### Documentation
21+
22+
|||
23+
|---|---|
24+
|[Bus Implementation](docs/ar_ibus.md) | The architecture and use of the Tookkit Communication Bus Interface

docs/ar_ibus.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,33 @@ The class diagram of these base class interfaces/implementation:
9494

9595
![ISPI Class Diagram](images/tk_uml_ispi.png)
9696

97-
## sfeTkIIBus - Arduino Implementation
97+
## sfeTkIBus - Arduino Implementation
9898

9999
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.
100100

101101
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.
102102

103103
> [!IMPORTANT]
104-
> The intent is that each user of an particular bus - a device in most cases - contains an instance of the specific bus object.
104+
> The intent is that each user of an particular - a device in most cases - contains an instance of the specific bus class.
105105
106-
The class diagram for the Arduino implementation is as follows:
106+
### The sfeTkArdI2C Class
107107

108-
![Arduino IBus Implementation](images/tk_ibus_ard.png)
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.
109109

110-
### The sfeTkArdI2C Class
110+
The class diagram for the sfeTkArdI2C class:
111111

112-
This class provides the Arduino implementation of I2C in the SparkFun Toolkit. It implements the methods of the ```sfeTkIIBus``` and ```sfeTkII2C``` interfaces, as well as manages any Arduino specific state.
112+
![Arduino I2C Class Diagram](images/tk_uml_ardi2c.png)
113113

114114
### The sfeTkArdSPI Class
115115

116-
This class provides the Arduino implementation of SPI in the SparkFun Toolkit. It implements the methods of the ```sfeTkIIBus``` and ```sfeTkISPI``` interfaces, as well as manages any Arduino specific state for the SPI bus - namely the SPISettings class.
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.
117117

118118
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.
119119

120+
The class diagram for the sfeTkArdSPI class:
121+
122+
![Arduino SPI Class Diagram](images/tk_uml_ardspi.png)
123+
120124
## sfeTkIBus Use
121125

122126
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.
@@ -125,7 +129,7 @@ The general pattern for a device driver implementation that uses the SparkFun To
125129

126130
### Implement a Platform Independent Driver
127131

128-
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 ```sfeTkIIBus``` interface.
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.
129133

130134
>[!IMPORTANT]
131135
> At this level, the driver is only using a ```sfeTkIBus``` interface, not any specific bus implementation.
@@ -135,7 +139,10 @@ This driver has the following unique functionality:
135139
1) A method to set the object that implements the ```sfeTkIBus``` interface object should use. Since
136140
1) If the device supports identification capabilities, the driver provides this functionality.
137141

138-
#### SImple Example of an Independent Driver Implementation
142+
#### Simple Example of an Independent Driver Implementation
143+
144+
>[!NOTE]
145+
> This code is **pseudo-code**, used to demonstrate the key concepts of the implementation pattern.
139146
140147
This implementation would take the following form:
141148

@@ -145,7 +152,7 @@ class myDriverClass
145152
{
146153
public:
147154

148-
myDriverClass(uint8_t address) : _addr{address}{}
155+
myDriverClass(uint8_t address) : _addr{address}, _theBus{nullptr}{}
149156

150157
bool begin()
151158
{
@@ -163,9 +170,9 @@ public:
163170
if (!_theBus || !data || len == 0)
164171
return false;
165172

166-
int status = _theBus->writeRegisterRegion(THE_REG, data, len);
173+
sfeTkError_t status = _theBus->writeRegisterRegion(THE_REG, data, len);
167174

168-
return (status == 0);
175+
return (status == kSTkErrOk);
169176
}
170177

171178
bool checkDeviceID()
@@ -174,6 +181,7 @@ public:
174181
return true;
175182
}
176183
private:
184+
uint8_t _addr;
177185
sfeTkIBus *_theBus;
178186
};
179187
```
@@ -204,7 +212,7 @@ class myArduinoDriverI2C : public myDriverClass
204212
205213
bool begin()
206214
{
207-
if (!_theI2CBus.init(MY_DEVICE_ADDRESS))
215+
if (_theI2CBus.init(MY_DEVICE_ADDRESS) != kSTkErrOk)
208216
return false;
209217
setCommunicationBus(&_theI2CBus);
210218
@@ -213,7 +221,7 @@ class myArduinoDriverI2C : public myDriverClass
213221
214222
bool isConnected()
215223
{
216-
if (!_theI2CBus.ping())
224+
if (_theI2CBus.ping() != kSTkErrOk)
217225
return false;
218226
219227
return checkDeviceID();
@@ -243,7 +251,7 @@ class myArduinoDriveSPI : public myDriverClass
243251
{
244252
SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE3);
245253

246-
if (!_theSPIBus.init(SPI, spiSettings, MY_DEFAULT_CS, true))
254+
if (_theSPIBus.init(SPI, spiSettings, MY_DEFAULT_CS, true) != kSTkErrOk)
247255
return false;
248256
setCommunicationBus(&_theSPIBus);
249257

@@ -259,3 +267,12 @@ private:
259267
sfeTkArdSPI _theSPIBus;
260268
};
261269
```
270+
271+
## Summary
272+
273+
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:
274+
275+
* Separate device setup from device communication
276+
* Define a common bus interface for use across a variety of common device bus types
277+
* Deliver support for both SPI and I2C bus types initially, focusing on Arduino
278+
* Structure the bus/toolkit implementation such that it's platform independent

docs/images/tk_ibus_ard.png

-198 KB
Binary file not shown.

docs/images/tk_uml_ardi2c.png

298 KB
Loading

docs/images/tk_uml_ardspi.png

276 KB
Loading

0 commit comments

Comments
 (0)