Skip to content

Commit d2ce294

Browse files
committed
0.1.0 shiftInSlow
1 parent 04556d7 commit d2ce294

File tree

13 files changed

+420
-0
lines changed

13 files changed

+420
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/[email protected]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/shiftInSlow/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021-2021 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/shiftInSlow/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ShiftInSlow/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftInSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftInSlow/releases)
5+
6+
# ShiftInSlow
7+
8+
Arduino library for shiftIn with build-in delay - e.g. for 74HC165
9+
10+
A library for shiftOutSlow also exist.
11+
12+
## Description
13+
14+
shiftInSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
15+
This allows one to improve reliability e.g. when using longer lines.
16+
17+
The datapin and clockpin are set in the constructor, the delay is settable per byte send to be able to optimize runtime.
18+
19+
20+
## Performance
21+
22+
The performance of **read()** with a delay of 0 microseconds is slower than the default Arduino
23+
**shiftIn()** due to some overhead.
24+
25+
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
26+
27+
28+
## Interface
29+
30+
The interface exists of the following functions:
31+
- **ShiftInSlow(datapin, clockpin, bitorder = LSBFIRST)** constructor.
32+
- **int read(void)** reads a new value
33+
- **int lastRead()** returns last value read
34+
- **void setDelay(uint16_t microseconds)** set delay per bit from 0 .. 65535 microseconds.
35+
- **uint16_t getDelay()** returns the set delay in microseconds.
36+
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
37+
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST
38+
39+
40+
## Notes
41+
42+
- to be tested
43+
44+
45+
## Operation
46+
47+
See examples
48+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// FILE: ShiftInSlow.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: Arduino library for shiftIn with build-in delay
6+
// DATE: 2021-05-11
7+
// URL: https://github.com/RobTillaart/ShiftInSlow
8+
9+
10+
#include "ShiftInSlow.h"
11+
12+
13+
ShiftInSlow::ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder)
14+
{
15+
_clockPin = clockPin;
16+
_dataPin = dataPin;
17+
_bitOrder = bitOrder;
18+
_value = 0;
19+
pinMode(_dataPin, INPUT);
20+
pinMode(_clockPin, OUTPUT);
21+
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
22+
digitalWrite(_clockPin, LOW); // assume rising pulses from clock
23+
}
24+
25+
26+
int ShiftInSlow::read()
27+
{
28+
_value = 0;
29+
for (uint8_t i = 0; i < 8; ++i)
30+
{
31+
digitalWrite(_clockPin, HIGH);
32+
if (_delay > 0) delayMicroseconds(_delay/2);
33+
yield();
34+
if (_bitOrder == LSBFIRST)
35+
_value |= digitalRead(_dataPin) << i;
36+
else
37+
_value |= digitalRead(_dataPin) << (7 - i);
38+
digitalWrite(_clockPin, LOW);
39+
if (_delay > 0) delayMicroseconds(_delay/2);
40+
}
41+
return _value;
42+
}
43+
44+
45+
bool ShiftInSlow::setBitOrder(const uint8_t bitOrder)
46+
{
47+
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
48+
{
49+
_bitOrder = bitOrder;
50+
return true;
51+
};
52+
return false;
53+
}
54+
55+
// -- END OF FILE --
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
//
3+
// FILE: ShiftInSlow.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for shiftIn with build-in delay
7+
// DATE: 2021-05-11
8+
// URL: https://github.com/RobTillaart/ShiftInSlow
9+
//
10+
11+
12+
#include "Arduino.h"
13+
14+
15+
#define SHIFTINSLOW_LIB_VERSION (F("0.1.0"))
16+
17+
18+
class ShiftInSlow
19+
{
20+
public:
21+
// bitorder = { LSBFIRST, MSBFIRST };
22+
ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
23+
24+
int read(void);
25+
int lastRead(void) { return _value; };
26+
27+
bool setBitOrder(const uint8_t bitOrder);
28+
uint8_t getBitOrder(void) { return _bitOrder; };
29+
30+
void setDelay(uint16_t d) { _delay = d; };
31+
uint16_t getDelay() { return _delay; };
32+
33+
34+
private:
35+
uint8_t _clockPin = 0 ;
36+
uint8_t _dataPin = 0;
37+
uint8_t _bitOrder = LSBFIRST;
38+
uint16_t _delay = 0;
39+
uint8_t _value = 0;
40+
};
41+
42+
// -- END OF FILE --
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// FILE: shiftInSlow_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: test sketch
6+
// URL: https://github.com/RobTillaart/ShiftInSlow
7+
//
8+
9+
10+
#include "ShiftInSlow.h"
11+
12+
13+
ShiftInSlow SIS(12, 13, LSBFIRST);
14+
15+
volatile int x = 0;
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println(__FILE__);
21+
Serial.println(SHIFTINSLOW_LIB_VERSION);
22+
23+
for (uint16_t d = 0; d < 1000; d += 10)
24+
{
25+
SIS.setDelay(d);
26+
uint32_t start = micros();
27+
x = SIS.read();
28+
uint32_t stop = micros();
29+
float duration = stop - start;
30+
Serial.print(stop - start);
31+
Serial.print("\t");
32+
Serial.println(duration / 8, 1);
33+
}
34+
35+
Serial.println("done...");
36+
}
37+
38+
void loop()
39+
{
40+
}
41+
42+
// -- END OF FILE --

libraries/shiftInSlow/keywords.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Syntax Coloring Map For ShiftInSlow
2+
3+
# Datatypes (KEYWORD1)
4+
ShiftInSlow KEYWORD1
5+
6+
7+
# Methods and Functions (KEYWORD2)
8+
read KEYWORD2
9+
lastRead KEYWORD2
10+
setBitOrder KEYWORD2
11+
getBitOrder KEYWORD2
12+
setDelay KEYWORD2
13+
getDelay KEYWORD2
14+
15+
16+
# Constants (LITERAL1)
17+
SHIFTINSLOW_LIB_VERSION LITERAL1
18+

0 commit comments

Comments
 (0)