Skip to content

Commit

Permalink
0.1.0 shiftInSlow
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed May 30, 2021
1 parent 04556d7 commit d2ce294
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/shiftInSlow/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions libraries/shiftInSlow/.github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

name: Arduino-lint

on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict
13 changes: 13 additions & 0 deletions libraries/shiftInSlow/.github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
arduino_ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/[email protected]
18 changes: 18 additions & 0 deletions libraries/shiftInSlow/.github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: JSON check

on:
push:
paths:
- '**.json'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

21 changes: 21 additions & 0 deletions libraries/shiftInSlow/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2021 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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions libraries/shiftInSlow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ShiftInSlow/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftInSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftInSlow/releases)

# ShiftInSlow

Arduino library for shiftIn with build-in delay - e.g. for 74HC165

A library for shiftOutSlow also exist.

## Description

shiftInSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
This allows one to improve reliability e.g. when using longer lines.

The datapin and clockpin are set in the constructor, the delay is settable per byte send to be able to optimize runtime.


## Performance

The performance of **read()** with a delay of 0 microseconds is slower than the default Arduino
**shiftIn()** due to some overhead.

The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.


## Interface

The interface exists of the following functions:
- **ShiftInSlow(datapin, clockpin, bitorder = LSBFIRST)** constructor.
- **int read(void)** reads a new value
- **int lastRead()** returns last value read
- **void setDelay(uint16_t microseconds)** set delay per bit from 0 .. 65535 microseconds.
- **uint16_t getDelay()** returns the set delay in microseconds.
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST


## Notes

- to be tested


## Operation

See examples

55 changes: 55 additions & 0 deletions libraries/shiftInSlow/ShiftInSlow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// FILE: ShiftInSlow.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Arduino library for shiftIn with build-in delay
// DATE: 2021-05-11
// URL: https://github.com/RobTillaart/ShiftInSlow


#include "ShiftInSlow.h"


ShiftInSlow::ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder)
{
_clockPin = clockPin;
_dataPin = dataPin;
_bitOrder = bitOrder;
_value = 0;
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
}


int ShiftInSlow::read()
{
_value = 0;
for (uint8_t i = 0; i < 8; ++i)
{
digitalWrite(_clockPin, HIGH);
if (_delay > 0) delayMicroseconds(_delay/2);
yield();
if (_bitOrder == LSBFIRST)
_value |= digitalRead(_dataPin) << i;
else
_value |= digitalRead(_dataPin) << (7 - i);
digitalWrite(_clockPin, LOW);
if (_delay > 0) delayMicroseconds(_delay/2);
}
return _value;
}


bool ShiftInSlow::setBitOrder(const uint8_t bitOrder)
{
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
{
_bitOrder = bitOrder;
return true;
};
return false;
}

// -- END OF FILE --
42 changes: 42 additions & 0 deletions libraries/shiftInSlow/ShiftInSlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
//
// FILE: ShiftInSlow.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Arduino library for shiftIn with build-in delay
// DATE: 2021-05-11
// URL: https://github.com/RobTillaart/ShiftInSlow
//


#include "Arduino.h"


#define SHIFTINSLOW_LIB_VERSION (F("0.1.0"))


class ShiftInSlow
{
public:
// bitorder = { LSBFIRST, MSBFIRST };
ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);

int read(void);
int lastRead(void) { return _value; };

bool setBitOrder(const uint8_t bitOrder);
uint8_t getBitOrder(void) { return _bitOrder; };

void setDelay(uint16_t d) { _delay = d; };
uint16_t getDelay() { return _delay; };


private:
uint8_t _clockPin = 0 ;
uint8_t _dataPin = 0;
uint8_t _bitOrder = LSBFIRST;
uint16_t _delay = 0;
uint8_t _value = 0;
};

// -- END OF FILE --
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// FILE: shiftInSlow_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/ShiftInSlow
//


#include "ShiftInSlow.h"


ShiftInSlow SIS(12, 13, LSBFIRST);

volatile int x = 0;

void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println(SHIFTINSLOW_LIB_VERSION);

for (uint16_t d = 0; d < 1000; d += 10)
{
SIS.setDelay(d);
uint32_t start = micros();
x = SIS.read();
uint32_t stop = micros();
float duration = stop - start;
Serial.print(stop - start);
Serial.print("\t");
Serial.println(duration / 8, 1);
}

Serial.println("done...");
}

void loop()
{
}

// -- END OF FILE --
18 changes: 18 additions & 0 deletions libraries/shiftInSlow/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Syntax Coloring Map For ShiftInSlow

# Datatypes (KEYWORD1)
ShiftInSlow KEYWORD1


# Methods and Functions (KEYWORD2)
read KEYWORD2
lastRead KEYWORD2
setBitOrder KEYWORD2
getBitOrder KEYWORD2
setDelay KEYWORD2
getDelay KEYWORD2


# Constants (LITERAL1)
SHIFTINSLOW_LIB_VERSION LITERAL1

22 changes: 22 additions & 0 deletions libraries/shiftInSlow/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ShiftInSlow",
"keywords": "Shift, shiftIn, in, serial, slow, 74HC165",
"description": "Arduino library for shiftIn with build-in delay - e.g. for 74HC165",
"authors":
[
{
"name": "Rob Tillaart",
"email": "[email protected]",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/ShiftInSlow.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
}
11 changes: 11 additions & 0 deletions libraries/shiftInSlow/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=ShiftInSlow
version=0.1.0
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for shiftIn with build-in delay - e.g. for 74HC165
paragraph=
category=Signal Input/Output
url=https://github.com/RobTillaart/ShiftInSlow
architectures=*
includes=ShiftInSlow.h
depends=
Loading

0 comments on commit d2ce294

Please sign in to comment.