1313
1414Arduino library for ** AVR** optimized shiftIn - e.g. for 74HC165.
1515
16- Related libraries
17- - https://github.com/RobTillaart/FastShiftOut
18- - https://github.com/RobTillaart/FastShiftInOut
19- - https://github.com/RobTillaart/ShiftInSlow
20- - https://github.com/RobTillaart/ShiftOutSlow
21-
2216
2317## Description
2418
@@ -28,17 +22,22 @@ It speeds up the shift using low level ports and masks. These are predetermined
2822in the constructor of the FastShiftIn object.
2923
3024If not an ** ARDUINO_ARCH_AVR** or ** ARDUINO_ARCH_MEGAAVR** the class falls back
31- to the default shiftIn() implementation.
25+ to the default ** shiftIn()** implementation.
26+
27+ The library allows to set (and get) the bitOrder and apply this to multiple read()
28+ calls. It also provide access to ** readLSBFIRST()** and ** readMSBFIRST()** which
29+ are the low level workers and most optimized code (so far).
3230
33- Since 0.3.2 read16(), read24() and read32() are added.
34- These are experimental and not fully tested yet.
31+ The library provides wrapper functions to read multi-byte variables.
32+ These are read16(), read24(), read32() and read(array, size).
33+ The latter is used to shift in any size object.
3534
3635
37- ## Performance
36+ ### Performance
3837
39- The performance of ** read()** is substantially faster than the default Arduino
40- ** shiftIn()** , but not as fast as HW SPI.
41- Exact how big the performance gain is can be seen with the example sketch.
38+ The performance of ** read()** is substantially faster for ** AVR ** than the default
39+ Arduino ** shiftIn()** , but not as fast as HW SPI.
40+ Exact how large the performance gain is can be seen with the example sketch.
4241It does a comparison and shows how the class is to be used.
4342
4443Time in microseconds, Arduino UNO
@@ -58,33 +57,64 @@ Time in microseconds, Arduino UNO
5857faster than the reference.
5958
6059
60+ ### Related libraries
61+
62+ - https://github.com/RobTillaart/FastShiftIn
63+ - https://github.com/RobTillaart/FastShiftOut
64+ - https://github.com/RobTillaart/FastShiftInOut
65+ - https://github.com/RobTillaart/ShiftInSlow
66+ - https://github.com/RobTillaart/ShiftOutSlow
67+
6168
6269## Interface
6370
6471``` cpp
6572#include " FastShiftIn.h"
6673```
6774
68- #### Functions
75+ ### Constructor
6976
7077- ** FastShiftIn(uint8_t dataIn, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** Constructor
78+
79+ ### Functions
80+
7181- ** uint16_t read(void)** reads a new value, 8 bit.
7282- ** uint16_t read16(void)** reads a new value, 16 bit.
7383- ** uint32_t read24(void)** reads a new value, 24 bit.
7484- ** uint32_t read32(void)** reads a new value, 32 bit.
7585- ** uint32_t lastRead()** returns last value read.
86+
87+ ### Meta
88+
7689- ** bool setBitOrder(uint8_t bitOrder)** set LSBFIRST or MSBFIRST.
7790Returns false for other values.
7891- ** uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST.
7992- ** uint16_t readLSBFIRST(void)** optimized LSB read(), 8 bit.
8093- ** uint16_t readMSBFIRST(void)** optimized MSB read(), 8 bit.
8194
8295
83- #### Byte order
96+ ### Experimental
97+
98+ - ** void read(uint8_t \* array, uint8_t size)** read an array of values.
99+ The order in the array follows as BYTE order MSB / LSB, that is why this function
100+ is made experimental. This might change in the future, and fill the array
101+ in arrival order.
84102
85- It might be that ** read16/24/32** has bytes not in the right order.
86- Then you should use multiple calls to ** read()** and merge these
87- bytes in the order you want them.
103+
104+ ### Byte order
105+
106+ The functions ** read16()** , ** read24()** and ** read32()** of this library assume
107+ that the BIT-order is also the BYTE-order.
108+ This is not always the case as an n-byte element can have n! == factorial(n)
109+ distinct byte orders.
110+
111+ So ** read16()** can have two, ** read24()** can have six and ** read32()** can even have
112+ (in theory) 24 distinct byte orders. Although LSB and MSB are the most common,
113+ other byte orders exist, and sometimes one explicitly wants to reorder the bytes.
114+
115+ If the BIT-order is not the BYTE-order, the user has two options
116+ - call ** read()** multiple times and merge the bytes in the order needed.
117+ - call ** read32()** (a.o) and reorder the bytes in a separate function.
88118
89119
90120## Notes
@@ -98,15 +128,20 @@ pull up resistors, especially if wires are exceeding 10 cm (4").
98128
99129#### Must
100130
131+
101132#### Should
102133
103134- extend unit tests
104135
105136#### Could
106137
107- - esp32 optimization readLSBFIRST readMSBFIRST
108- - ** read(uint8_t \* arr, uint8_t nr)** ??
109- - example schema
138+ - investigate separate ** BYTE** -order,
139+ - only MSBFirst and LSBFirst
140+ - ** void setByteOrder()** + ** uint8_t getByteOrder()**
141+ - other option is add parameters / overload to make byte order explicit
142+ - ** read32(1,0,3,2)** performance penalty + invalid combination.
143+ - investigate ESP32 optimization readLSBFIRST readMSBFIRST
144+ - example schemas
110145- would it be interesting to make a fastShiftIn16() etc?
111146 - squeeze performance but more maintenance.?
112147
0 commit comments