0.1.1 shiftInSlow

This commit is contained in:
rob tillaart 2021-12-28 11:35:20 +01:00
parent 13e8fdf2d5
commit a77e4b2772
11 changed files with 64 additions and 37 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

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

@ -1,20 +1,24 @@
[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/jsoncheck.yml)
[![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
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.
The dataPin and clockPin are set in the constructor, the delay is configurable per byte send to be able to optimize runtime.
## Performance
@ -23,26 +27,35 @@ The performance of **read()** with a delay of 0 microseconds is slower than the
**shiftIn()** due to some overhead.
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
This keeps the duty cycle ~50%.
## Interface
The interface exists of the following functions:
- **ShiftInSlow(datapin, clockpin, bitorder = LSBFIRST)** constructor.
- **ShiftInSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor, bit order is default set to LSBFIRST.
- **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.
- **void setDelay(uint16_t microseconds)** set delay per bit from 0 .. 65535 microseconds. Note that the delay is split in two parts to keep ~ 50% duty cycle.
- **uint16_t getDelay()** returns the set delay in microseconds.
- **bool setBitOrder(bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
- **bool setBitOrder(uint8_t 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
## Future
- Add a select pin to be more SPI alike?
- improve documentation
- add examples
- increase max delay uint32_t ?
- set delay in terms of frequency - delay is 'wave length'
- set delay in terms of max total time the read may cost.
- set default delay = 0, is no delay ?
- adaptive speed example?
- get set dutyCycle(0 .. 99%)
-

View File

@ -1,10 +1,13 @@
//
// FILE: ShiftInSlow.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: Arduino library for shiftIn with build-in delay
// DATE: 2021-05-11
// URL: https://github.com/RobTillaart/ShiftInSlow
//
// 0.1.0 2021-05-11 initial version
// 0.1.1 2021-12-28 update library.json, readme, license
#include "ShiftInSlow.h"
@ -19,7 +22,7 @@ ShiftInSlow::ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const ui
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
digitalWrite(_clockPin, LOW); // assume rising pulses from clock
}
@ -46,10 +49,12 @@ bool ShiftInSlow::setBitOrder(const uint8_t bitOrder)
{
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
{
_bitOrder = bitOrder;
_bitOrder = bitOrder;
return true;
};
return false;
}
// -- END OF FILE --

View File

@ -2,23 +2,22 @@
//
// FILE: ShiftInSlow.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// 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"))
#define SHIFTINSLOW_LIB_VERSION (F("0.1.1"))
class ShiftInSlow
{
public:
// bitorder = { LSBFIRST, MSBFIRST };
// bitOrder = { LSBFIRST, MSBFIRST };
ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
int read(void);
@ -27,7 +26,7 @@ public:
bool setBitOrder(const uint8_t bitOrder);
uint8_t getBitOrder(void) { return _bitOrder; };
void setDelay(uint16_t d) { _delay = d; };
void setDelay(uint16_t microseconds) { _delay = microseconds; };
uint16_t getDelay() { return _delay; };
@ -39,4 +38,6 @@ private:
uint8_t _value = 0;
};
// -- END OF FILE --

View File

@ -1,10 +1,8 @@
//
// FILE: shiftInSlow_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: test sketch
// URL: https://github.com/RobTillaart/ShiftInSlow
//
#include "ShiftInSlow.h"
@ -14,6 +12,7 @@ ShiftInSlow SIS(12, 13, LSBFIRST);
volatile int x = 0;
void setup()
{
Serial.begin(115200);
@ -35,8 +34,11 @@ void setup()
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,6 +1,7 @@
# Syntax Coloring Map For ShiftInSlow
# Syntax Colouring Map For ShiftInSlow
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
ShiftInSlow KEYWORD1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/ShiftInSlow.git"
},
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "ShiftInSlow.h"
}

View File

@ -1,5 +1,5 @@
name=ShiftInSlow
version=0.1.0
version=0.1.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for shiftIn with build-in delay - e.g. for 74HC165

View File

@ -37,6 +37,7 @@
unittest_setup()
{
fprintf(stderr, "SHIFTINSLOW_LIB_VERSION: %s\n", (char *) SHIFTINSLOW_LIB_VERSION);
}
unittest_teardown()
@ -48,7 +49,6 @@ unittest(test_constructor)
{
ShiftInSlow SIS(12, 13);
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
assertEqual(0, SIS.lastRead());
assertEqual(LSBFIRST, SIS.getBitOrder());
@ -61,7 +61,6 @@ unittest(test_constructor_LSB)
{
ShiftInSlow SIS(12, 13, LSBFIRST);
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
assertEqual(0, SIS.lastRead());
assertEqual(LSBFIRST, SIS.getBitOrder());
@ -74,7 +73,6 @@ unittest(test_constructor_MSB)
{
ShiftInSlow SIS(12, 13, MSBFIRST);
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
assertEqual(0, SIS.lastRead());
assertEqual(MSBFIRST, SIS.getBitOrder());
@ -87,7 +85,6 @@ unittest(test_setDelay)
{
ShiftInSlow SIS(12, 13);
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
for (uint16_t d = 0; d < 1000; d += 100)
{
SIS.setDelay(d);
@ -100,7 +97,6 @@ unittest(test_read)
{
ShiftInSlow SIS(12, 13);
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
assertEqual(0, SIS.read());
}