Skip to content

Commit 75cf304

Browse files
committed
0.1.0 SWSPI
1 parent e86374e commit 75cf304

File tree

14 files changed

+661
-0
lines changed

14 files changed

+661
-0
lines changed

libraries/SWSPI/.arduino-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+

libraries/SWSPI/.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: json-syntax-check
16+
uses: limitusus/json-syntax-check@v2
17+
with:
18+
pattern: "\\.json$"

libraries/SWSPI/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log SWSPI
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2024-10-29
10+
- initial version, experimental!
11+
12+
13+

libraries/SWSPI/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-2024 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/SWSPI/README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/SWSPI/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/SWSPI/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SWSPI/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/SWSPI/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SWSPI/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/SWSPI.svg)](https://github.com/RobTillaart/SWSPI/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SWSPI/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SWSPI.svg?maxAge=3600)](https://github.com/RobTillaart/SWSPI/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/SWSPI.svg)](https://registry.platformio.org/libraries/robtillaart/SWSPI)
10+
11+
12+
# SWSPI
13+
14+
Arduino library for SoftWare SPI.
15+
16+
17+
## Description
18+
19+
**Experimental, use with care.**
20+
21+
The SPI protocol is a "standard" for serial communication, however there exists many variants.
22+
This document only describe the four modi typical used in the Arduino context.
23+
24+
The SWSPI library implements a software implementation of SPI with 4 different modi.
25+
26+
The library is written for debugging purposes and might evolve to a real software SPI
27+
implementation. It is shared as it might be useful for others.
28+
29+
- educational and debug purpose for now.
30+
- very limited tested
31+
- master only
32+
- no optimized performance
33+
- MSBFIRST is reversed LSBFIRST (reduces code size).
34+
- does not implement SPIClass (yet),
35+
- goal is to follow the SPI API so it can be done in some future.
36+
37+
**Experimental, use with care.**
38+
39+
40+
### SPI modes
41+
42+
There are 4 SPI MODES which encodes the clock polarity, phase and idle state.
43+
The mode also defines at which edge data out should be present and when
44+
data in can be read.
45+
46+
The mode used is set in the **setTransaction()** call.
47+
48+
| SPI MODE | polarity | phase | idle | data out | data in |
49+
|:----------:|:----------:|:-------:|:------:|:----------:|:----------:|
50+
| 0 | 0 | 0 | 0 | rising | falling |
51+
| 1 | 0 | 1 | 0 | falling | rising |
52+
| 2 | 1 | 0 | 1 | falling | rising |
53+
| 3 | 1 | 1 | 1 | rising | falling |
54+
55+
56+
### Basic SPI transaction
57+
58+
```cpp
59+
// set pins in "start position"
60+
myspi.beginTransaction(bitOrder, spiMode);
61+
62+
// select the device to communicate with
63+
// must be done after beginTransaction() to prevent "false clock edges".
64+
digitalWrite(selectPin, LOW);
65+
// do the IO
66+
data_in = myspi.transfer(data_out);
67+
// unslect the device when ready.
68+
digitalWrite(selectPin, HIGH);
69+
70+
// close the transaction.
71+
myspi.endTransaction();
72+
```
73+
74+
75+
### Related
76+
77+
- https://github.com/RobTillaart/FastShiftIn
78+
- https://github.com/RobTillaart/FastShiftInOut
79+
- https://github.com/RobTillaart/FastShiftOut
80+
- https://github.com/RobTillaart/SWSPI
81+
- https://docs.arduino.cc/learn/communication/spi/
82+
- https://en.wikipedia.org/wiki/Serial_Peripheral_Interface
83+
84+
85+
## Interface
86+
87+
```cpp
88+
#include SWSPI.h
89+
```
90+
91+
92+
### Base
93+
94+
- **SWSPI(uint8_t dataIn, uint8_t dataOut, uint8_t clock))** constructor.
95+
- **void begin()**
96+
- **void end()**
97+
- **void setBitOrder(uint8_t bitOrder)** bitOrder must be MSBFIRST or LSBFIRST
98+
- **void setDataMode(uint8_t dataMode)** dataMode must be in range 0..3
99+
100+
### Transfer
101+
102+
- **void beginTransaction(uint8_t bitOrder, uint8_t dataMode)**
103+
- bitOrder must be MSBFIRST or LSBFIRST
104+
- dataMode must be in range 0..3
105+
- **void endTransaction()**
106+
- **uint8_t transfer(uint8_t data)**
107+
- **uint16_t transfer16(uint16_t data)**
108+
- **void transfer(const void \*buf, size_t count)**
109+
110+
111+
## Future
112+
113+
#### Must
114+
115+
- elaborate documentation
116+
- links to SPI explainers.
117+
- test
118+
- implement SPIclass interface
119+
120+
#### Should
121+
122+
- derived classes, read or write only.
123+
124+
#### Could
125+
126+
- add **void suppressInteruupts(bool flag = false)**
127+
- code to .cpp file?
128+
- add transfer24()
129+
- unit test?
130+
131+
132+
#### Won't (unless requested)
133+
134+
135+
## Support
136+
137+
If you appreciate my libraries, you can support the development and maintenance.
138+
Improve the quality of the libraries by providing issues and Pull Requests, or
139+
donate through PayPal or GitHub sponsors.
140+
141+
Thank you,
142+

0 commit comments

Comments
 (0)