0.1.3 FastShiftInOut

This commit is contained in:
rob tillaart 2023-02-20 19:36:46 +01:00
parent c1e371adeb
commit d61734c7d2
13 changed files with 94 additions and 47 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,15 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.3] - 2023-02-20
- optimized noInterrupts
- add lastRead()
- update readme.md
- update GitHub actions
- update license 2023
- minor edits
## [0.1.2] - 2022-11-06
- redo clock pulse to match fastShiftOut
(after write and before read)
## [0.1.1] - 2022-11-05
- optimize AVR
## [0.1.0] - 2022-11-04
- initial version - no optimization
- two examples

View File

@ -1,11 +1,9 @@
//
// FILE: FastShiftInOut.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library for (AVR) optimized shiftInOut (simultaneously)
// URL: https://github.com/RobTillaart/FastShiftInOut
//
// HISTORY: see changelog.md
#include "FastShiftInOut.h"
@ -42,17 +40,18 @@ FastShiftInOut::FastShiftInOut(uint8_t dataIn, uint8_t dataOut, uint8_t clockPin
_clockPin = clockPin;
#endif
_lastValue = 0;
_lastRead = 0;
}
uint8_t FastShiftInOut::write(uint8_t data)
{
_value = data;
if (_bitOrder == LSBFIRST)
{
return writeLSBFIRST(_value);
return writeLSBFIRST(data);
}
return writeMSBFIRST(_value);
return writeMSBFIRST(data);
}
@ -60,7 +59,7 @@ uint8_t FastShiftInOut::writeLSBFIRST(uint8_t data)
{
uint8_t rv = 0;
uint8_t value = data;
_value = value;
_lastValue = value;
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -70,10 +69,10 @@ uint8_t FastShiftInOut::writeLSBFIRST(uint8_t data)
uint8_t outmask1 = _dataOutBit;
uint8_t outmask2 = ~_dataOutBit;
uint8_t oldSREG = SREG;
noInterrupts();
for (uint8_t m = 1; m > 0; m <<= 1)
{
uint8_t oldSREG = SREG;
noInterrupts();
// write one bit
if ((value & m) == 0) *_dataOutRegister &= outmask2;
else *_dataOutRegister |= outmask1;
@ -83,10 +82,9 @@ uint8_t FastShiftInOut::writeLSBFIRST(uint8_t data)
if ((*_dataInRegister & inmask1) > 0) rv |= m;
// clock pulse LOW
*_clockRegister &= cbmask2;
SREG = oldSREG;
}
return rv;
SREG = oldSREG;
#else
for (uint8_t i = 0; i < 8; i++)
@ -105,6 +103,7 @@ uint8_t FastShiftInOut::writeLSBFIRST(uint8_t data)
#endif
_lastRead = rv;
return rv;
}
@ -113,7 +112,7 @@ uint8_t FastShiftInOut::writeMSBFIRST(uint8_t data)
{
uint8_t rv = 0;
uint8_t value = data;
_value = value;
_lastValue = value;
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -123,10 +122,10 @@ uint8_t FastShiftInOut::writeMSBFIRST(uint8_t data)
uint8_t outmask1 = _dataOutBit;
uint8_t outmask2 = ~_dataOutBit;
uint8_t oldSREG = SREG;
noInterrupts();
for (uint8_t m = 0x80; m > 0; m >>= 1)
{
uint8_t oldSREG = SREG;
noInterrupts();
// write one bit
if ((value & m) == 0) *_dataOutRegister &= outmask2;
else *_dataOutRegister |= outmask1;
@ -136,9 +135,8 @@ uint8_t FastShiftInOut::writeMSBFIRST(uint8_t data)
if ((*_dataInRegister & inmask1) > 0) rv |= m;
// clock pulse LOW
*_clockRegister &= cbmask2;
SREG = oldSREG;
}
return rv;
SREG = oldSREG;
#else
@ -158,13 +156,20 @@ uint8_t FastShiftInOut::writeMSBFIRST(uint8_t data)
#endif
_lastRead = rv;
return rv;
}
uint8_t FastShiftInOut::lastWritten(void)
{
return _value;
return _lastValue;
};
uint8_t FastShiftInOut::lastRead(void)
{
return _lastRead;
};
@ -185,5 +190,5 @@ uint8_t FastShiftInOut::getBitOrder(void)
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: FastShiftInOut.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library for (AVR) optimized shiftInOut (simultaneously)
// URL: https://github.com/RobTillaart/FastShiftInOut
@ -10,7 +10,7 @@
#include "Arduino.h"
#define FASTSHIFTINOUT_LIB_VERSION (F("0.1.2"))
#define FASTSHIFTINOUT_LIB_VERSION (F("0.1.3"))
class FastShiftInOut
@ -21,7 +21,9 @@ public:
// reads and writes simultaneously
uint8_t write(uint8_t data);
uint8_t lastWritten(void);
uint8_t lastRead(void);
bool setBitOrder(uint8_t bitOrder);
uint8_t getBitOrder(void);
@ -32,7 +34,8 @@ public:
private:
uint8_t _bitOrder;
int _value;
int _lastValue;
int _lastRead;
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
@ -55,5 +58,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022-2022 Rob Tillaart
Copyright (c) 2022-2023 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

@ -30,39 +30,45 @@ Experimental.
performance of **write()**
| version | UNO (us) | ESP32 (us) |
|:---------:|:----------:|:------------:|
|:---------:|-----------:|-------------:|
| 0.1.0 | 181.08 | 4.32 |
| 0.1.1 | 26.84 | 4.32 |
| 0.1.2 | 26.84 | no data |
| 0.1.3 | 25.52 | 4.32 |
## Interface
```cpp
#include "FastShiftInOut.h"
```
#### Functions
bitOrder = { LSBFIRST, MSBFIRST };
- **FastShiftInOut(uint8_t dataIn, uint8_t dataOut, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)**
- **FastShiftInOut(uint8_t dataIn, uint8_t dataOut, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** Constructor.
- **uint8_t write(uint8_t data)** reads and writes simultaneously.
- **uint8_t lastWritten(void)** returns last written value.
- **bool setBitOrder(uint8_t bitOrder)** idem.
- **uint8_t lastWritten(void)** returns last byte written.
- **uint8_t lastRead(void)** returns last byte read.
- **bool setBitOrder(uint8_t bitOrder)** bitOrder must be LSBFIRST or MSBFIRST.
- **uint8_t getBitOrder(void)** idem.
- **uint8_t writeLSBFIRST(uint8_t data)**
- **uint8_t writeMSBFIRST(uint8_t data)**
## Operation
See examples
- **uint8_t writeLSBFIRST(uint8_t data)** optimized version, in practice almost no difference.
- **uint8_t writeMSBFIRST(uint8_t data)** optimized version, in practice almost no difference.
## Future
#### must
#### Must
- documentation
- follow FastShiftIn and FastShiftOut
#### should
- performance measurements
- optimize for AVR
#### could
- **void ignoreRead()**
- add Print interface?

View File

@ -0,0 +1,20 @@
IDE: 1.8.19
Board: UNO
FASTSHIFTINOUT_LIB_VERSION: 0.1.3
Performance - time in us
write: 26.54
write: 52.06
Delta: 25.52
writeLSBFIRST: 25.66
writeLSBFIRST: 51.17
Delta: 25.52
writeMSBFIRST: 25.65
writeMSBFIRST: 51.18
Delta: 25.52
done ...

View File

@ -6,9 +6,12 @@ FastShiftInOut KEYWORD1
# Methods and Functions (KEYWORD2)
write KEYWORD2
lastWritten KEYWORD2
setBitOrder KEYWORD2
getBitOrder KEYWORD2
writeLSBFIRST KEYWORD2
writeMSBFIRST KEYWORD2

View File

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

View File

@ -1,5 +1,5 @@
name=FastShiftInOut
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for (AVR) optimized shiftInOut (simultaneously)

View File

@ -3,7 +3,7 @@
// AUTHOR: Rob Tillaart
// DATE: 2022-11-04
// PURPOSE: unit tests for the FastShiftIn library
// https://github.com/RobTillaart/FastShiftIn
// https://github.com/RobTillaart/FastShiftInOut
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
@ -94,6 +94,9 @@ unittest(test_print)
}
*/
unittest_main()
// --------
// -- END OF FILE --