103 lines
3.5 KiB
Markdown
Raw Normal View History

2021-01-29 12:31:58 +01:00
[![Arduino CI](https://github.com/RobTillaart/FastShiftOut/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-17 15:24:28 +01:00
[![Arduino-lint](https://github.com/RobTillaart/FastShiftOut/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/FastShiftOut/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/FastShiftOut/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/FastShiftOut/actions/workflows/jsoncheck.yml)
2021-01-29 12:31:58 +01:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastShiftOut/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastShiftOut.svg?maxAge=3600)](https://github.com/RobTillaart/FastShiftOut/releases)
2020-11-27 11:16:22 +01:00
# FastShiftOut
2022-11-06 20:23:19 +01:00
Arduino library for **AVR** optimized shiftOut - e.g. 74HC595.
2020-11-27 11:16:22 +01:00
2022-11-06 20:23:19 +01:00
Related libraries
- https://github.com/RobTillaart/FastShiftIn
- https://github.com/RobTillaart/FastShiftInOut
- https://github.com/RobTillaart/ShiftInSlow
- https://github.com/RobTillaart/ShiftOutSlow
2020-11-27 11:16:22 +01:00
2021-05-28 13:26:27 +02:00
2020-11-27 11:16:22 +01:00
## Description
FastShiftOut is a class that has optimized code for AVR to shift out data faster
2021-12-17 15:24:28 +01:00
than the normal **shiftOut()** function.
2020-11-27 11:16:22 +01:00
It speeds up the shift using low level ports and masks. These are predetermined
in the constructor of the FastShiftOut object.
If not an **ARDUINO_ARCH_AVR** or **ARDUINO_ARCH_MEGAAVR** the class falls back
to the default shiftOut() implementation.
2021-05-28 13:26:27 +02:00
2020-11-27 11:16:22 +01:00
## Performance
The performance of **write()** is substantially faster than the default Arduino
2021-01-29 12:31:58 +01:00
**shiftOut()**, but not as fast as HW SPI.
2020-11-27 11:16:22 +01:00
Exact how big the performance gain is can be seen with the example sketch.
It does a comparison and shows how the class is to be used.
2023-02-20 17:37:06 +01:00
Time in microseconds, Arduino UNO
2022-11-05 12:39:40 +01:00
2023-02-20 17:37:06 +01:00
| function | 0.2.4 | 0.3.1 |
|:-------------------------|--------:|---------:|
| write() | 21.66 | 22.48 |
| writeLSBFIRST() | 22.94 | 23.37 |
| writeMSBFIRST() | 20.30 | 21.86 |
| reference shiftOut() | 89.74 | 89.74 |
| println("Hello world") | | 328.92 |
| println(1357) | | 313.56 |
| println(3.14159265, 4) | | 717.36 |
2022-11-05 12:39:40 +01:00
2021-05-28 13:26:27 +02:00
2020-11-27 11:16:22 +01:00
## Interface
2023-02-20 17:37:06 +01:00
```cpp
#include "FastShiftOut.h"
```
2020-11-27 11:16:22 +01:00
2023-02-20 17:37:06 +01:00
#### Functions
- **FastShiftOut(uint8_t dataOut, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** Constructor.
2021-12-17 15:24:28 +01:00
- **size_t write(const uint8_t data)** send a byte, also the workhorse of the **Print** interface.
- **uint8_t lastWritten()** returns last byte written.
- **bool setBitOrder(uint8_t bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST.
- **size_t writeLSBFIRST(const uint8_t data);** most optimized.
- **size_t writeMSBFIRST(const uint8_t data);** most optimized.
2020-11-27 11:16:22 +01:00
2023-02-20 17:37:06 +01:00
2021-01-29 12:31:58 +01:00
As a FastShiftOut object implements the Print interface, one can also call
2023-02-20 17:37:06 +01:00
2020-11-27 11:16:22 +01:00
- **FSO.print(any type);** or
2021-01-29 12:31:58 +01:00
- **FSO.println(any type);**
to send e.g. a float with 4 digits over the line, or some text string.
2021-12-17 15:24:28 +01:00
Note: **FSO.print()** returns the number of characters printed, including an optional \\r or \\n.
2020-11-27 11:16:22 +01:00
## Notes
- The optimizations are AVR only for now, other platforms may follow.
- The 74HC595 needs 0.1uF caps and the data and clock lines may need
pull up resistors, especially if wires are exceeding 10 cm (4").
2021-05-28 13:26:27 +02:00
2023-02-20 17:37:06 +01:00
## Future
2020-11-27 11:16:22 +01:00
2023-02-20 17:37:06 +01:00
#### Must
2020-11-27 11:16:22 +01:00
2023-02-20 17:37:06 +01:00
#### Should
2021-12-17 15:24:28 +01:00
2023-02-20 17:37:06 +01:00
- extend unit tests
#### Could
2021-12-17 15:24:28 +01:00
- performance ESP32
- check optimized ESP32
- add **size_t write(const uint8_t \*buffer, size_t size)**
- example schema
2023-02-20 17:37:06 +01:00
#### Wont