Skip to content

Commit

Permalink
0.1.0 shiftOutSLow
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed May 30, 2021
1 parent d2ce294 commit 4f22980
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/shiftOutSlow/.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/shiftOutSlow/.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/shiftOutSlow/.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/shiftOutSlow/.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/shiftOutSlow/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.
51 changes: 51 additions & 0 deletions libraries/shiftOutSlow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

[![Arduino CI](https://github.com/RobTillaart/ShiftOutSlow/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/ShiftOutSlow/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftOutSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftOutSlow/releases)

# ShiftOutSlow

Arduino library for shiftOut with build-in delay - e.g. for 74HC595

A library for shiftInSlow also exist.

## Description


ShiftOutSlow 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.

ShiftOutSlow implements the print interface.


## Performance

The performance of **write()** with a delay of 0 microseconds is slower than the default Arduino
**shiftOut()** 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:
- **ShiftOutSlow(datapin, clockpin, bitorder = LSBFIRST)** constructor.
- **size_t write(uint8_t data)** writes a new value
- **uint8_t lastWritten()** returns last value written
- **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

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


#include "ShiftOutSlow.h"


ShiftOutSlow::ShiftOutSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder)
{
_clockPin = clockPin;
_dataPin = dataPin;
_bitOrder = bitOrder;
_value = 0;
pinMode(_dataPin, OUTPUT);
pinMode(_clockPin, OUTPUT);
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
digitalWrite(_clockPin, LOW); // assume rising pulses from clock
}


size_t ShiftOutSlow::write(const uint8_t data)
{
uint8_t val = data;
for (uint8_t i = 0; i < 8; ++i)
{
if (_delay > 0) delayMicroseconds(_delay/2);
if (_bitOrder == LSBFIRST) {
digitalWrite(_dataPin, val & 0x01);
val >>= 1;
} else {
digitalWrite(_dataPin, (val & 0x80) != 0);
val <<= 1;
}
digitalWrite(_clockPin, HIGH);
if (_delay > 0) delayMicroseconds(_delay/2);
yield();
digitalWrite(_clockPin, LOW);
}
_value = data;
return 1;
}


bool ShiftOutSlow::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/shiftOutSlow/ShiftOutSlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
//
// FILE: ShiftOutSlow.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Arduino library for shiftOut with build-in delay
// DATE: 2021-05-11
// URL: https://github.com/RobTillaart/ShiftOutSlow
//


#include "Arduino.h"


#define SHIFTOUTSLOW_LIB_VERSION (F("0.1.0"))


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

size_t write(const uint8_t data);
uint8_t lastWritten(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: shiftOutSlow_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/ShiftOutSlow
//


#include "ShiftOutSlow.h"


ShiftOutSlow SOS(12, 13, LSBFIRST);

volatile int x = 0;

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

for (uint16_t d = 0; d < 1000; d += 10)
{
SOS.setDelay(d);
uint32_t start = micros();
x = SOS.write(0x55);
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/shiftOutSlow/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Syntax Coloring Map For ShiftOutSlow

# Datatypes (KEYWORD1)
ShiftOutSlow KEYWORD1


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


# Constants (LITERAL1)
SHIFTOUTSLOW_LIB_VERSION LITERAL1

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

0 comments on commit 4f22980

Please sign in to comment.