{"id":20989738,"url":"https://github.com/robtillaart/fastshiftin","last_synced_at":"2025-10-05T20:51:28.518Z","repository":{"id":45366526,"uuid":"255623957","full_name":"RobTillaart/FastShiftIn","owner":"RobTillaart","description":"Arduino library for (AVR) optimized shiftIn  - e.g. 74HC165","archived":false,"fork":false,"pushed_at":"2024-09-19T12:11:45.000Z","size":47,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T22:01:44.856Z","etag":null,"topics":["74hc165","arduino","shift"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-04-14T13:57:33.000Z","updated_at":"2025-02-16T18:15:26.000Z","dependencies_parsed_at":"2023-02-12T17:30:26.489Z","dependency_job_id":"bd9f78b1-1fb6-46c0-a6b9-2e06c8d4b303","html_url":"https://github.com/RobTillaart/FastShiftIn","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/RobTillaart/FastShiftIn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FFastShiftIn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FFastShiftIn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FFastShiftIn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FFastShiftIn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/FastShiftIn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FFastShiftIn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278518882,"owners_count":26000177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["74hc165","arduino","shift"],"created_at":"2024-11-19T06:26:00.164Z","updated_at":"2025-10-05T20:51:28.500Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/FastShiftIn/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/FastShiftIn/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/FastShiftIn/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/FastShiftIn/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/FastShiftIn/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/FastShiftIn.svg)](https://github.com/RobTillaart/FastShiftIn/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastShiftIn/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastShiftIn.svg?maxAge=3600)](https://github.com/RobTillaart/FastShiftIn/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/FastShiftIn.svg)](https://registry.platformio.org/libraries/robtillaart/FastShiftIn)\n\n\n# FastShiftIn\n\nArduino library for **AVR** optimized shiftIn - e.g. for 74HC165.\n\n\n## Description\n\nFastShiftIn is a class that has optimized code (AVR only) to shift in data faster \nthan the default provided **shiftIn()** function.\nIt speeds up the shift using low level ports and masks. These are predetermined\nin the constructor of the FastShiftIn object.\n\nIf not an **ARDUINO_ARCH_AVR** or **ARDUINO_ARCH_MEGAAVR** the class falls back \nto the default **shiftIn()** implementation.\n\nThe library allows to set (and get) the bitOrder and apply this to multiple read()\ncalls. It also provide access to **readLSBFIRST()** and **readMSBFIRST()** which \nare the low level workers and most optimized code (so far).\n\nThe library provides wrapper functions to read multi-byte variables. \nThese are read16(), read24(), read32() and read(array, size).\nThe latter is used to shift in any size object.\n\n\n### 0.4.0 breaking changes\n\nThe 0.4.0 version has a flag to unroll the inner loop in **readLSBFIRST()**\nand **readMSBFIRST()**. The AVR optimized code blocks the interrupts per byte.\n\nNote: this optimization is new and thus experimental.\nFeedback, including improvements, is welcome.\n\n\n### Performance\n\nThe performance of **read()** is substantially faster for **AVR** than the default \nArduino **shiftIn()**, but not as fast as HW SPI. \nExact how large the performance gain is can be seen with the example sketch.\nIt does a comparison and shows how the class is to be used.\n\n\n#### Measurements\n\nNumbers may vary depending on bit-order flag.\n\nIndicative time in microseconds, Arduino UNO, IDE 1.8.19, measured over 1000 calls. \n\n|  function            |   0.2.3  |   0.3.2  |   0.4.0  |  0.4.0L  |\n|:---------------------|---------:|---------:|---------:|---------:|\n|  read()              |   19.30  |   20.49  |   12.71  |    9.51  |\n|  read16()            |          |   41.04  |   25.39  |   18.98  |\n|  read24()            |          |   62.91  |   39.10  |   29.48  |\n|  read32()            |          |   83.95  |   51.42  |   38.60  |\n|  readLSBFIRST()      |   19.04  |   19.92  |   11.96  |    8.81  |\n|  readMSBFIRST()      |   19.04  |   19.92  |   11.94  |    8.75  |\n|  reference shiftIn() |  107.82  |  108.20  |  108.05  |  108.05  |\n\n\n- Note: 0.3.2 is a bit slower (incl. reference) than 0.2.3 but still much\nfaster than the reference. (Older IDE?)\n- Note: 0.4.0 improved test sketch, \n- Note: 0.4.0 measured with loop unroll flag disabled.\n- Note: 0.4.0L measured with loop unrolled flag enabled.\n\n\n### Related libraries\n\n- https://github.com/RobTillaart/FastShiftIn\n- https://github.com/RobTillaart/FastShiftInOut\n- https://github.com/RobTillaart/FastShiftOut\n- https://github.com/RobTillaart/ShiftInSlow\n- https://github.com/RobTillaart/ShiftOutSlow\n\n\n## Interface\n\n```cpp\n#include \"FastShiftIn.h\"\n```\n\n### Constructor\n\nbitOrder = { LSBFIRST, MSBFIRST };\n\n- **FastShiftIn(uint8_t dataIn, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** Constructor\n\n### Functions\n\n- **uint16_t read(void)** reads a new value, 8 bit.\n- **uint16_t read16(void)** reads a new value, 16 bit.\n- **uint32_t read24(void)** reads a new value, 24 bit.\n- **uint32_t read32(void)** reads a new value, 32 bit.\n- **uint32_t lastRead()** returns last value read.\n- **uint16_t readLSBFIRST(void)**  optimized LSB read(), 8 bit.\n- **uint16_t readMSBFIRST(void)**  optimized MSB read(), 8 bit.\n\n\n### BitOrder\n\n- **bool setBitOrder(uint8_t bitOrder)** set LSBFIRST or MSBFIRST. \nReturns false for other values ==\u003e no change.\n- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST as set in the constructor\nor latest set from **setBitOrder()**.\n\n\n### Experimental\n\n- **void read(uint8_t \\*array, uint8_t size)** read an array of values.\nThe order in the array follows as BYTE order MSB / LSB, that is why this function\nis made experimental. This might change in the future, and fill the array\nin arrival order.\n\n\n### Byte order\n\nThe functions **read16()**, **read24()** and **read32()** of this library assume\nthat the BIT-order is also the BYTE-order.\nThis is not always the case as an n-byte element can have n! == factorial(n)\ndistinct byte orders.\n\nSo **read16()** can have two, **read24()** can have six and **read32()** can even have \n(in theory) 24 distinct byte orders. Although LSB and MSB are the most common,\nother byte orders exist, and sometimes one explicitly wants to reorder the bytes.\n\nIf the BIT-order is not the BYTE-order, the user has two options\n- call **read()** multiple times and merge the bytes in the order needed.\n- call **read32()** (a.o) and reorder the bytes in a separate function.\n\nThe library will not support such functionality.\n\n\n## Notes\n\n- The optimizations are AVR only for now, other platforms may follow.\n- The 74HC165 needs 0.1uF caps and the data and clock lines may need  \npull up resistors, especially if wires are exceeding 10 cm (4\").\n\n\n## Future\n\n#### Must\n\n- keep in sync with FastShiftOut()\n\n#### Should\n\n- extend unit tests\n\n#### Could\n\n- investigate ESP32 optimization readLSBFIRST readMSBFIRST\n- performance ESP32\n- example schema\n- add invert flag?\n- would it be interesting to make a fastShiftIn16() etc?\n  - squeeze performance but more maintenance.?           \n\n#### Wont\n\n- investigate separate **BYTE**-order, \n  - only MSBFirst and LSBFirst\n  - **void setByteOrder()** + **uint8_t getByteOrder()**\n  - other option is add parameters / overload to make byte order explicit\n    - **read32(1,0,3,2)** performance penalty + invalid combination.\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ffastshiftin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Ffastshiftin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ffastshiftin/lists"}