0.2.3 FastShiftIn

This commit is contained in:
rob tillaart 2021-12-17 15:14:55 +01:00
parent a2228b5686
commit 7b44c5ef5d
14 changed files with 91 additions and 47 deletions

View File

@ -2,6 +2,11 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
- mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,7 +1,7 @@
//
// FILE: FastShiftIn.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
// URL: https://github.com/RobTillaart/FastShiftIn
@ -17,7 +17,7 @@ FastShiftIn::FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const ui
pinMode(datapin, INPUT);
pinMode(clockpin, OUTPUT);
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
digitalWrite(clockpin, LOW); // assume rising pulses from clock
digitalWrite(clockpin, LOW); // assume rising pulses from clock
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -43,6 +43,8 @@ FastShiftIn::FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const ui
#endif
}
int FastShiftIn::read()
{
if (_bitorder == LSBFIRST)
@ -52,6 +54,8 @@ int FastShiftIn::read()
return readMSBFIRST();
}
int FastShiftIn::readLSBFIRST()
{
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -77,14 +81,13 @@ int FastShiftIn::readLSBFIRST()
return _value;
#else
// reference implementation
_value = shiftIn(_databit, _clockbit, LSBFIRST);
return _value;
#endif
}
int FastShiftIn::readMSBFIRST()
{
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -110,22 +113,22 @@ int FastShiftIn::readMSBFIRST()
return _value;
#else
// reference implementation
_value = shiftIn(_databit, _clockbit, MSBFIRST);
return _value;
#endif
}
bool FastShiftIn::setBitOrder(const uint8_t bitOrder)
{
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
{
_bitorder = bitOrder;
_bitorder = bitOrder;
return true;
};
return false;
}
// -- END OF FILE --

View File

@ -2,23 +2,22 @@
//
// FILE: FastShiftIn.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
// URL: https://github.com/RobTillaart/FastShiftIn
//
#include "Arduino.h"
#define FASTSHIFTIN_LIB_VERSION (F("0.2.2"))
#define FASTSHIFTIN_LIB_VERSION (F("0.2.3"))
class FastShiftIn
{
public:
// bitorder = { LSBFIRST, MSBFIRST };
// bitOrder = { LSBFIRST, MSBFIRST };
FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const uint8_t bitOrder = LSBFIRST);
int read(void);
@ -27,7 +26,7 @@ public:
bool setBitOrder(const uint8_t bitOrder);
uint8_t getBitOrder(void) { return _bitorder; };
// overrule bitorder (most optimized).
// overrule bitOrder (most optimized).
int readLSBFIRST(void);
int readMSBFIRST(void);
@ -42,4 +41,5 @@ private:
volatile uint8_t *_clockin;
};
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2013-2021 Rob Tillaart
Copyright (c) 2013-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,10 +1,9 @@
//
// FILE: fastShiftIn.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/FastShiftIn
//
#include "FastShiftIn.h"
@ -12,6 +11,7 @@ FastShiftIn FSI(12, 13, LSBFIRST);
volatile int x = 0;
void setup()
{
Serial.begin(115200);
@ -70,6 +70,11 @@ void setup()
Serial.println("done...");
}
void loop()
{
}
}
// -- END OF FILE --

View File

@ -1,10 +1,9 @@
//
// FILE: fastShiftIn_readLSBFIRST.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/FastShiftIn
//
#include "FastShiftIn.h"
@ -12,6 +11,7 @@ FastShiftIn FSI(12, 13);
volatile int x = 0;
void setup()
{
Serial.begin(115200);
@ -70,8 +70,10 @@ void setup()
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,10 +1,9 @@
//
// FILE: fastShiftIn_readMSBFIRST.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/FastShiftIn
//
#include "FastShiftIn.h"
@ -12,6 +11,7 @@ FastShiftIn FSI(12, 13);
volatile int x = 0;
void setup()
{
Serial.begin(115200);
@ -70,8 +70,11 @@ void setup()
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,10 +1,9 @@
//
// FILE: fastShiftIn_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/FastShiftIn
//
#include "FastShiftIn.h"
@ -14,6 +13,7 @@ volatile int x = 0;
uint32_t start, duration1, duration2;
void setup()
{
Serial.begin(115200);
@ -38,6 +38,7 @@ void setup()
Serial.println("done...");
}
void test_read()
{
start = micros();
@ -64,6 +65,7 @@ void test_read()
delay(100);
}
void test_readLSBFIRST()
{
start = micros();
@ -90,6 +92,7 @@ void test_readLSBFIRST()
delay(100);
}
void test_readMSBFIRST()
{
start = micros();
@ -116,6 +119,7 @@ void test_readMSBFIRST()
delay(100);
}
void test_reference()
{
start = micros();
@ -142,6 +146,11 @@ void test_reference()
delay(100);
}
void loop()
{
}
}
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
# Syntax Coloring Map For FastShiftIn
# Syntax Colouring Map For FastShiftIn
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
FastShiftIn KEYWORD1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/FastShiftIn.git"
},
"version": "0.2.2",
"version": "0.2.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "FastShiftIn.h"
}

View File

@ -1,5 +1,5 @@
name=FastShiftIn
version=0.2.2
version=0.2.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for (AVR) optimized shiftIn - e.g. for 74HC165

View File

@ -1,24 +1,29 @@
[![Arduino CI](https://github.com/RobTillaart/FastShiftIn/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/FastShiftIn/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/FastShiftIn/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/FastShiftIn/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/FastShiftIn/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastShiftIn/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastShiftIn.svg?maxAge=3600)](https://github.com/RobTillaart/FastShiftIn/releases)
# FastShiftIn
Arduino library for (AVR) optimized shiftIn - e.g. for 74HC165
Arduino library for **AVR** optimized shiftIn - e.g. for 74HC165.
A library for FastShiftOut also exist - https://github.com/RobTillaart/FastShiftOut
A library for FastShiftOut also exist.
## Description
FastShiftIn is a class that has optimized code (AVR only) to shift in data faster
than the normal shiftIn() function.
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.
## Performance
The performance of **read()** is substantially faster than the default Arduino
@ -26,16 +31,18 @@ The performance of **read()** is substantially faster than the default Arduino
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.
## Interface
The interface exists of the following functions:
- **int read(void)** reads a new value
- **int lastRead()** returns last value read
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
- **int read(void)** reads a new value.
- **int 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
- **int readLSBFIRST(void)** optimized LSB read()
- **int readMSBFIRST(void)** optimized MSB read()
- **int readLSBFIRST(void)** optimized LSB read().
- **int readMSBFIRST(void)** optimized MSB read().
## Notes
@ -43,7 +50,16 @@ The interface exists of the following functions:
- 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").
## Operation
See examples
## Future
- esp32 optimization readLSBFIRST readMSBFIRST
- read8() read16(), read24(), read32()
- **read(uint8_t \* arr, uint8_t nr)** ??
- example schema

View File

@ -37,6 +37,7 @@
unittest_setup()
{
fprintf(stderr, "FASTSHIFTIN_LIB_VERSION: %s\n", (char *) FASTSHIFTIN_LIB_VERSION);
}
unittest_teardown()
@ -48,7 +49,6 @@ unittest(test_constructor)
{
FastShiftIn FSI(12, 13);
fprintf(stderr, "VERSION:\t%s\n", FASTSHIFTIN_LIB_VERSION);
assertEqual(0, FSI.lastRead());
assertEqual(LSBFIRST, FSI.getBitOrder());
@ -61,7 +61,6 @@ unittest(test_constructor_LSB)
{
FastShiftIn FSI(12, 13, LSBFIRST);
fprintf(stderr, "VERSION:\t%s\n", FASTSHIFTIN_LIB_VERSION);
assertEqual(0, FSI.lastRead());
assertEqual(LSBFIRST, FSI.getBitOrder());
@ -74,7 +73,6 @@ unittest(test_constructor_MSB)
{
FastShiftIn FSI(12, 13, MSBFIRST);
fprintf(stderr, "VERSION:\t%s\n", FASTSHIFTIN_LIB_VERSION);
assertEqual(0, FSI.lastRead());
assertEqual(MSBFIRST, FSI.getBitOrder());
@ -87,8 +85,6 @@ unittest(test_read)
{
FastShiftIn FSI(12, 13);
fprintf(stderr, "VERSION:\t%s\n", FASTSHIFTIN_LIB_VERSION);
// apparently needed... To be investigated someday ...
#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)