0.2.4 FastShiftIn

This commit is contained in:
rob tillaart 2022-11-05 12:41:07 +01:00
parent 7a400f004b
commit e8a4a2fdfe
8 changed files with 107 additions and 17 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,5 +23,6 @@ compile:
- m4
- esp32
# - esp8266
- mega2560
# - mega2560
- rpipico

View File

@ -0,0 +1,28 @@
# Change Log FastShiftIn
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.4] - 2022-11-05
- add changelog.md
- add rp2040 to build-CI
- update readme.md
## [0.2.3] - 2021-17-12
- update license
- update readme - some badges
- clean up unit test
## [0.2.2] - 2020-12-22
## No history ...
## [0.1.0 - 2013-09-29
- initial version

View File

@ -1,10 +1,12 @@
//
// FILE: FastShiftIn.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.3
// VERSION: 0.2.4
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
// URL: https://github.com/RobTillaart/FastShiftIn
//
// HISTORY: see changelog.md
#include "FastShiftIn.h"
@ -16,27 +18,27 @@ FastShiftIn::FastShiftIn(const uint8_t datapin, const uint8_t clockpin, const ui
_value = 0;
pinMode(datapin, INPUT);
pinMode(clockpin, OUTPUT);
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
digitalWrite(clockpin, LOW); // assume rising pulses from clock
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// uint8_t _datatimer = digitalPinToTimer(datapin);
// if (_datatimer != NOT_ON_TIMER) turnOffPWM(_datatimer); TODO
// uint8_t _datatimer = digitalPinToTimer(datapin);
// if (_datatimer != NOT_ON_TIMER) turnOffPWM(_datatimer); TODO
uint8_t _dataport = digitalPinToPort(datapin);
_datain = portOutputRegister(_dataport);
_databit = digitalPinToBitMask(datapin);
// uint8_t _clocktimer = digitalPinToTimer(clockpin);
// if (_clocktimer != NOT_ON_TIMER) turnOffPWM(_clocktimer);
// uint8_t _clocktimer = digitalPinToTimer(clockpin);
// if (_clocktimer != NOT_ON_TIMER) turnOffPWM(_clocktimer);
uint8_t _clockport = digitalPinToPort(clockpin);
_clockin = portOutputRegister(_clockport);
_clockbit = digitalPinToBitMask(clockpin);
#else
// reference implementation
// reuse these local vars as pin to save some space
// reference implementation
// reuse these local variables as pin to save some space
_databit = datapin;
_clockbit = clockpin;
@ -113,7 +115,7 @@ int FastShiftIn::readMSBFIRST()
return _value;
#else
// reference implementation
// reference implementation
_value = shiftIn(_databit, _clockbit, MSBFIRST);
return _value;
#endif

View File

@ -2,7 +2,7 @@
//
// FILE: FastShiftIn.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.3
// VERSION: 0.2.4
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
// URL: https://github.com/RobTillaart/FastShiftIn
@ -11,13 +11,13 @@
#include "Arduino.h"
#define FASTSHIFTIN_LIB_VERSION (F("0.2.3"))
#define FASTSHIFTIN_LIB_VERSION (F("0.2.4"))
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);
@ -26,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);

View File

@ -0,0 +1,34 @@
Arduino UNO
IDE 1.8.19
fastShiftIn_test.ino
0.2.3
8 bits HIGH
Performance - time in us : read()
FastShiftIn1: 20.42
FastShiftIn2: 39.72
Delta: 19.30
Performance - time in us : readLSBFIRST()
FastShiftIn1: 19.80
FastShiftIn2: 38.84
Delta: 19.04
Performance - time in us : readMSBFIRST()
FastShiftIn1: 19.80
FastShiftIn2: 38.84
Delta: 19.04
Performance - time in us : reference shiftIn()
Standard shiftIn1: 108.61
Standard shiftIn2: 216.43
Delta: 107.82
done...

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/FastShiftIn.git"
},
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=FastShiftIn
version=0.2.3
version=0.2.4
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

@ -10,7 +10,8 @@
Arduino library for **AVR** optimized shiftIn - e.g. for 74HC165.
A library for FastShiftOut also exist - https://github.com/RobTillaart/FastShiftOut
- library for FastShiftOut - https://github.com/RobTillaart/FastShiftOut
- library for FastShiftInOut - https://github.com/RobTillaart/FastShiftInOut
## Description
@ -31,6 +32,15 @@ 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.
test 0.2.3 Arduino UNO
| function | time (us) |
|:---------------------|----------:|
| read() | 19.30 |
| readLSBFIRST() | 19.04 |
| readMSBFIRST() | 19.04 |
| reference shiftIn() | 107.82 |
## Interface