Git Product home page Git Product logo

fastshiftin's Introduction

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

FastShiftIn

Arduino library for AVR optimized shiftIn - e.g. for 74HC165.

Related libraries

Description

FastShiftIn is a class that has optimized code (AVR only) to shift in data faster than the normal shiftIn() function. It speeds up the shift using low level ports and masks. These are predetermined in the constructor of the FastShiftIn object.

If not an ARDUINO_ARCH_AVR or ARDUINO_ARCH_MEGAAVR the class falls back to the default shiftIn() implementation.

Since 0.3.2 read16(), read24() and read32() are added. These are experimental and not fully tested yet.

Performance

The performance of read() is substantially faster than the default Arduino shiftIn(), but not as fast as HW SPI. 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.

Time in microseconds, Arduino UNO

function 0.2.3 0.3.2
read() 19.30 20.49
read16() 41.04
read24() 62.91
read32() 83.95
readLSBFIRST() 19.04 19.92
readMSBFIRST() 19.04 19.92
reference shiftIn() 107.82 108.20

0.3.2 is a bit slower (incl. reference) than 0.2.3 but still much faster than the reference.

Interface

#include "FastShiftIn.h"

Functions

  • FastShiftIn(uint8_t dataIn, uint8_t clockPin, uint8_t bitOrder = LSBFIRST) Constructor
  • uint16_t read(void) reads a new value, 8 bit.
  • uint16_t read16(void) reads a new value, 16 bit.
  • uint32_t read24(void) reads a new value, 24 bit.
  • uint32_t read32(void) reads a new value, 32 bit.
  • uint32_t lastRead() returns last value read.
  • bool setBitOrder(uint8_t bitOrder) set LSBFIRST or MSBFIRST. Returns false for other values.
  • uint8_t getBitOrder(void) returns LSBFIRST or MSBFIRST.
  • uint16_t readLSBFIRST(void) optimized LSB read(), 8 bit.
  • uint16_t readMSBFIRST(void) optimized MSB read(), 8 bit.

Byte order

It might be that read16/24/32 has bytes not in the right order. Then you should use multiple calls to read() and merge these bytes in the order you want them.

Notes

  • The optimizations are AVR only for now, other platforms may follow.
  • The 74HC165 needs 0.1uF caps and the data and clock lines may need
    pull up resistors, especially if wires are exceeding 10 cm (4").

Future

Must

Should

  • extend unit tests

Could

  • esp32 optimization readLSBFIRST readMSBFIRST
  • read(uint8_t * arr, uint8_t nr) ??
  • example schema
  • would it be interesting to make a fastShiftIn16() etc?
    • squeeze performance but more maintenance.?

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,

fastshiftin's People

Contributors

robtillaart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fastshiftin's Issues

unit test fails for Due and Zero

error msg

/github/home/Arduino/libraries/FastShiftIn/FastShiftIn.cpp:76:12: error: ‘shiftIn’ was not declared in this scope
   _value = shiftIn(_databit, _clockbit, LSBFIRST);

Now disabled in - .arduino-ci.yml in test folder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.