Skip to content

Commit 331575c

Browse files
authored
Merge pull request #48 from sparkfun/main
Pull develop up to main.
2 parents fa2f46c + 84f7333 commit 331575c

File tree

14 files changed

+1952
-46
lines changed

14 files changed

+1952
-46
lines changed

.github/workflows/compile-sketch.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ on:
44
push:
55
branches:
66
- main
7-
#- pull_request
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
811

912

1013
jobs:
@@ -101,11 +104,10 @@ jobs:
101104
libraries: |
102105
- source-path: ./
103106
sketch-paths: |
104-
- tests
107+
- examples/Example_01_TestCompile
105108
enable-warnings-report: true
106109
enable-deltas-report: true
107110
verbose: true
108111

109112
# outputs:
110113
# report-artifact-name: ${{ steps.report-artifact-name.outputs.report-artifact-name }}
111-

README.md

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,15 @@ The SparkFun Toolkit provides a single implementation of common functionality us
3333

3434
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.
3535

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
36+
![Core Architecture](docs/images/rm_img_01.png)
4437

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-
```
38+
And as additional platforms are added, they also implement/inherit from the SparkFun Toolkit Core.
5939

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.
40+
![Multi-Platform Structure](docs/images/rm_img_02.png)
6141

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
42+
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.
8043

81-
```
44+
![Application Structure](docs/images/rm_img_03.png)
8245

8346
If/when the application is moved to another platform, just the platform specific logic needs implementation.
8447

docs/images/rm_img_01.png

68.3 KB
Loading

docs/images/rm_img_02.png

71.6 KB
Loading

docs/images/rm_img_03.png

95.7 KB
Loading

tests/test_bus01/test_bus01.ino renamed to examples/Example_01_TestCompile/Example_01_TestCompile.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
sfTkArdI2C myI2C;
88
sfTkArdSPI mySPI;
9+
sfTkArdUART myUART;
10+
sfTkArdUARTBus myUARTBus(myUART);
911

1012
void setup()
1113
{

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=1.0.0
2+
version=1.1.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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
// Just include the toolkit headers
2222
#include "sfTkArdI2C.h"
2323
#include "sfTkArdSPI.h"
24+
#include "sfTkArdUART.h"
2425
#include "sfTkArduino.h"

src/sfTk/sfTkISerial.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @file sfTkISerial.h
3+
* @brief Header file for the SparkFun Toolkit Base Serial Interface Definition.
4+
*
5+
* This file contains the interface declaration for basic serial read/write.
6+
*
7+
* @author SparkFun Electronics
8+
* @date 2025
9+
* @copyright Copyright (c) 2025, SparkFun Electronics Inc. This project is released under the MIT License.
10+
*
11+
* SPDX-License-Identifier: MIT
12+
*/
13+
14+
#pragma once
15+
16+
// clang-format off
17+
#include "sfTkError.h"
18+
// clang-format on
19+
20+
/**
21+
* @brief A base value for serial errors. All serial errors are greater than this value, in the 2000 range
22+
*
23+
*/
24+
const sfTkError_t ksfTkErrBaseSerial = 0x2000;
25+
26+
/**
27+
* @brief Error code for when a serial system is not initalized.
28+
*/
29+
const sfTkError_t ksfTkErrSerialNotInit = ksfTkErrFail * (ksfTkErrBaseSerial + 1);
30+
31+
/**
32+
* @brief Returned when a serial interface times out.
33+
*
34+
*/
35+
const sfTkError_t ksfTkErrSerialTimeout = ksfTkErrFail * (ksfTkErrBaseSerial + 2);
36+
37+
/**
38+
* @brief Returned when a serial interface does not respond.
39+
*
40+
*/
41+
const sfTkError_t ksfTkErrSerialNoResponse = ksfTkErrFail * (ksfTkErrBaseSerial + 3);
42+
43+
/**
44+
* @brief Returned when the data to be sent is too long or received is too short.
45+
*
46+
*/
47+
const sfTkError_t ksfTkErrSerialDataTooLong = ksfTkErrFail * (ksfTkErrBaseSerial + 4);
48+
49+
/**
50+
* @brief Returned when the serial settings are null, invalid, or on set/initialized.
51+
*
52+
*/
53+
const sfTkError_t ksfTkErrSerialNullSettings = ksfTkErrFail * (ksfTkErrBaseSerial + 5);
54+
55+
/**
56+
* @brief Returned when the buffer is null or invalid.
57+
*
58+
*/
59+
const sfTkError_t ksfTkErrSerialNullBuffer = ksfTkErrFail * (ksfTkErrBaseSerial + 6);
60+
61+
/**
62+
* @brief Returned when the bus is under read. Warning.
63+
*
64+
*/
65+
const sfTkError_t ksfTkErrSerialUnderRead = ksfTkErrBaseSerial + 7;
66+
67+
class sfTkISerial
68+
{
69+
public:
70+
sfTkISerial() = default;
71+
virtual ~sfTkISerial() = default;
72+
73+
/**
74+
* @brief Writes an array of bytes to the serial interface.
75+
*
76+
* @param data The data to write
77+
* @param length The length of the data buffer
78+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
79+
*/
80+
virtual sfTkError_t write(const uint8_t *data, size_t length) = 0;
81+
82+
/**
83+
* @brief Writes a single byte to the serial interface.
84+
*
85+
* @param data The data to write
86+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
87+
*/
88+
virtual sfTkError_t write(const uint8_t data)
89+
{
90+
return write(&data, sizeof(data));
91+
}
92+
93+
/**
94+
* @brief Reads an array of bytes from the serial interface
95+
*
96+
* @param data The data buffer to read into
97+
* @param length The length of the data buffer
98+
* @param readBytes[out] The number of bytes read
99+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
100+
*/
101+
virtual sfTkError_t read(uint8_t *data, size_t length, size_t &readBytes) = 0;
102+
103+
/**
104+
* @brief Read a single byte from the serial interface
105+
*
106+
* @param data Byte to be read
107+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
108+
*/
109+
virtual sfTkError_t read(uint8_t &data)
110+
{
111+
size_t nRead;
112+
113+
return read(&data, sizeof(data), nRead);
114+
}
115+
};

src/sfTk/sfTkISerialBus.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @file sfTkISerialBus.h
3+
* @brief Header file for the SparkFun Toolkit Base Serial Bus Interface Definition.
4+
*
5+
* This file contains the interface declaration for connecting sfTkISerial to the sfTkIBus.
6+
*
7+
* @author SparkFun Electronics
8+
* @date 2025
9+
* @copyright Copyright (c) 2025, SparkFun Electronics Inc. This project is released under the MIT License.
10+
*
11+
* SPDX-License-Identifier: MIT
12+
*/
13+
14+
#pragma once
15+
16+
// clang-format off
17+
#include "sfTkError.h"
18+
#include "sfTkIBus.h"
19+
#include "sfTkISerial.h"
20+
// clang-format on
21+
22+
const uint8_t ksfTkBusTypeSerialBus = 0x03;
23+
24+
class sfTkISerialBus : sfTkIBus
25+
{
26+
public:
27+
/**
28+
* @brief Constructor for the serial bus
29+
*
30+
*/
31+
sfTkISerialBus()
32+
{
33+
}
34+
35+
virtual ~sfTkISerialBus() = default;
36+
37+
/**
38+
* @brief Writes an array of bytes to the serial interface.
39+
*
40+
* @param data The data to write
41+
* @param length The length of the data buffer
42+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
43+
*/
44+
virtual sfTkError_t write(const uint8_t *data, size_t length) = 0;
45+
46+
/**
47+
* @brief Writes an array of bytes to a register on the target address. Supports any address size
48+
*
49+
* @param devReg The device's register's address - can be any size, If nullptr, address is not sent
50+
* @param regLength The length of the register address. If 0, address is not sent
51+
* @param data The data to write
52+
* @param length The length of the data buffer
53+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
54+
*/
55+
virtual sfTkError_t writeRegister(uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length) override
56+
{
57+
58+
// Do we have a register? If so write it, else skip.
59+
if (devReg != nullptr && regLength > 0)
60+
write(devReg, regLength);
61+
62+
// Write the data.
63+
return write(data, length);
64+
}
65+
66+
/**
67+
* @brief Read an array of bytes from the serial interface
68+
*
69+
* @param data The data buffer to read into
70+
* @param length The length of the data buffer
71+
* @param readBytes[out] The number of bytes read
72+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
73+
*/
74+
virtual sfTkError_t read(uint8_t *data, size_t length, size_t &readBytes) = 0;
75+
76+
/**
77+
* @brief Reads an array of bytes to a register on the target address. Supports any address size
78+
*
79+
* @param devReg The device's register's address - can be any size
80+
* @param regLength The length of the register address
81+
* @param data The data to buffer to read into
82+
* @param numBytes The length of the data buffer
83+
* @param readBytes[out] The number of bytes read
84+
* @return sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code
85+
*/
86+
virtual sfTkError_t readRegister(uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
87+
size_t &readBytes) override
88+
{
89+
// Buffer valid?
90+
if (!data)
91+
return ksfTkErrBusNullBuffer;
92+
93+
sfTkError_t retVal = ksfTkErrOk;
94+
95+
// Do we have a register? If so, write it, else skip.
96+
if (devReg != nullptr && regLength > 0)
97+
retVal = write(devReg, regLength);
98+
99+
if (retVal != ksfTkErrOk)
100+
return retVal;
101+
102+
// Read the data.
103+
retVal = read(data, numBytes, readBytes);
104+
105+
return retVal;
106+
}
107+
108+
/**
109+
* @brief Get the type of the object
110+
*
111+
* @return uint8_t The type of the object
112+
*/
113+
virtual uint8_t type(void) override
114+
{
115+
return ksfTkBusTypeSerialBus;
116+
}
117+
};

0 commit comments

Comments
 (0)