mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-20 00:55:58 -04:00
0.1.1 shiftInSlow
This commit is contained in:
parent
13e8fdf2d5
commit
a77e4b2772
@ -2,6 +2,10 @@ compile:
|
|||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
platforms:
|
platforms:
|
||||||
- uno
|
- uno
|
||||||
- leonardo
|
# - due
|
||||||
- due
|
# - zero
|
||||||
- zero
|
# - leonardo
|
||||||
|
- m4
|
||||||
|
- esp32
|
||||||
|
# - esp8266
|
||||||
|
# - mega2560
|
||||||
|
@ -4,10 +4,14 @@ name: Arduino CI
|
|||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
arduino_ci:
|
runTest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: Arduino-CI/action@master
|
- uses: ruby/setup-ruby@v1
|
||||||
# Arduino-CI/action@v0.1.1
|
with:
|
||||||
|
ruby-version: 2.6
|
||||||
|
- run: |
|
||||||
|
gem install arduino_ci
|
||||||
|
arduino_ci.rb
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
|
|
||||||
[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
[![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)
|
[![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)
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftInSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftInSlow/releases)
|
||||||
|
|
||||||
|
|
||||||
# ShiftInSlow
|
# 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.
|
A library for shiftOutSlow also exist.
|
||||||
|
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
shiftInSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
|
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.
|
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
|
## Performance
|
||||||
@ -23,26 +27,35 @@ The performance of **read()** with a delay of 0 microseconds is slower than the
|
|||||||
**shiftIn()** due to some overhead.
|
**shiftIn()** due to some overhead.
|
||||||
|
|
||||||
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
|
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
|
||||||
|
This keeps the duty cycle ~50%.
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
The interface exists of the following functions:
|
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 read(void)** reads a new value
|
||||||
- **int lastRead()** returns last value read
|
- **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.
|
- **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
|
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST
|
||||||
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- to be tested
|
|
||||||
|
|
||||||
|
|
||||||
## Operation
|
## Operation
|
||||||
|
|
||||||
See examples
|
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%)
|
||||||
|
-
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
//
|
//
|
||||||
// FILE: ShiftInSlow.cpp
|
// FILE: ShiftInSlow.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// PURPOSE: Arduino library for shiftIn with build-in delay
|
// PURPOSE: Arduino library for shiftIn with build-in delay
|
||||||
// DATE: 2021-05-11
|
// DATE: 2021-05-11
|
||||||
// URL: https://github.com/RobTillaart/ShiftInSlow
|
// 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"
|
#include "ShiftInSlow.h"
|
||||||
@ -19,7 +22,7 @@ ShiftInSlow::ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const ui
|
|||||||
pinMode(_dataPin, INPUT);
|
pinMode(_dataPin, INPUT);
|
||||||
pinMode(_clockPin, OUTPUT);
|
pinMode(_clockPin, OUTPUT);
|
||||||
// https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
|
// 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))
|
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
|
||||||
{
|
{
|
||||||
_bitOrder = bitOrder;
|
_bitOrder = bitOrder;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -2,23 +2,22 @@
|
|||||||
//
|
//
|
||||||
// FILE: ShiftInSlow.h
|
// FILE: ShiftInSlow.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// PURPOSE: Arduino library for shiftIn with build-in delay
|
// PURPOSE: Arduino library for shiftIn with build-in delay
|
||||||
// DATE: 2021-05-11
|
// DATE: 2021-05-11
|
||||||
// URL: https://github.com/RobTillaart/ShiftInSlow
|
// URL: https://github.com/RobTillaart/ShiftInSlow
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
#define SHIFTINSLOW_LIB_VERSION (F("0.1.0"))
|
#define SHIFTINSLOW_LIB_VERSION (F("0.1.1"))
|
||||||
|
|
||||||
|
|
||||||
class ShiftInSlow
|
class ShiftInSlow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// bitorder = { LSBFIRST, MSBFIRST };
|
// bitOrder = { LSBFIRST, MSBFIRST };
|
||||||
ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
|
ShiftInSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
|
||||||
|
|
||||||
int read(void);
|
int read(void);
|
||||||
@ -27,7 +26,7 @@ public:
|
|||||||
bool setBitOrder(const uint8_t bitOrder);
|
bool setBitOrder(const uint8_t bitOrder);
|
||||||
uint8_t getBitOrder(void) { return _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; };
|
uint16_t getDelay() { return _delay; };
|
||||||
|
|
||||||
|
|
||||||
@ -39,4 +38,6 @@ private:
|
|||||||
uint8_t _value = 0;
|
uint8_t _value = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
//
|
//
|
||||||
// FILE: shiftInSlow_demo.ino
|
// FILE: shiftInSlow_demo.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: test sketch
|
// PURPOSE: test sketch
|
||||||
// URL: https://github.com/RobTillaart/ShiftInSlow
|
// URL: https://github.com/RobTillaart/ShiftInSlow
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "ShiftInSlow.h"
|
#include "ShiftInSlow.h"
|
||||||
@ -14,6 +12,7 @@ ShiftInSlow SIS(12, 13, LSBFIRST);
|
|||||||
|
|
||||||
volatile int x = 0;
|
volatile int x = 0;
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
@ -35,8 +34,11 @@ void setup()
|
|||||||
Serial.println("done...");
|
Serial.println("done...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# Syntax Coloring Map For ShiftInSlow
|
# Syntax Colouring Map For ShiftInSlow
|
||||||
|
|
||||||
# Datatypes (KEYWORD1)
|
|
||||||
|
# Data types (KEYWORD1)
|
||||||
ShiftInSlow KEYWORD1
|
ShiftInSlow KEYWORD1
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/ShiftInSlow.git"
|
"url": "https://github.com/RobTillaart/ShiftInSlow.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*"
|
"platforms": "*",
|
||||||
|
"headers": "ShiftInSlow.h"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=ShiftInSlow
|
name=ShiftInSlow
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=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
|
sentence=Arduino library for shiftIn with build-in delay - e.g. for 74HC165
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
unittest_setup()
|
unittest_setup()
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "SHIFTINSLOW_LIB_VERSION: %s\n", (char *) SHIFTINSLOW_LIB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest_teardown()
|
unittest_teardown()
|
||||||
@ -48,7 +49,6 @@ unittest(test_constructor)
|
|||||||
{
|
{
|
||||||
ShiftInSlow SIS(12, 13);
|
ShiftInSlow SIS(12, 13);
|
||||||
|
|
||||||
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
|
|
||||||
assertEqual(0, SIS.lastRead());
|
assertEqual(0, SIS.lastRead());
|
||||||
assertEqual(LSBFIRST, SIS.getBitOrder());
|
assertEqual(LSBFIRST, SIS.getBitOrder());
|
||||||
|
|
||||||
@ -61,7 +61,6 @@ unittest(test_constructor_LSB)
|
|||||||
{
|
{
|
||||||
ShiftInSlow SIS(12, 13, LSBFIRST);
|
ShiftInSlow SIS(12, 13, LSBFIRST);
|
||||||
|
|
||||||
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
|
|
||||||
assertEqual(0, SIS.lastRead());
|
assertEqual(0, SIS.lastRead());
|
||||||
assertEqual(LSBFIRST, SIS.getBitOrder());
|
assertEqual(LSBFIRST, SIS.getBitOrder());
|
||||||
|
|
||||||
@ -74,7 +73,6 @@ unittest(test_constructor_MSB)
|
|||||||
{
|
{
|
||||||
ShiftInSlow SIS(12, 13, MSBFIRST);
|
ShiftInSlow SIS(12, 13, MSBFIRST);
|
||||||
|
|
||||||
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
|
|
||||||
assertEqual(0, SIS.lastRead());
|
assertEqual(0, SIS.lastRead());
|
||||||
assertEqual(MSBFIRST, SIS.getBitOrder());
|
assertEqual(MSBFIRST, SIS.getBitOrder());
|
||||||
|
|
||||||
@ -87,7 +85,6 @@ unittest(test_setDelay)
|
|||||||
{
|
{
|
||||||
ShiftInSlow SIS(12, 13);
|
ShiftInSlow SIS(12, 13);
|
||||||
|
|
||||||
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
|
|
||||||
for (uint16_t d = 0; d < 1000; d += 100)
|
for (uint16_t d = 0; d < 1000; d += 100)
|
||||||
{
|
{
|
||||||
SIS.setDelay(d);
|
SIS.setDelay(d);
|
||||||
@ -100,7 +97,6 @@ unittest(test_read)
|
|||||||
{
|
{
|
||||||
ShiftInSlow SIS(12, 13);
|
ShiftInSlow SIS(12, 13);
|
||||||
|
|
||||||
fprintf(stderr, "VERSION:\t%s\n", SHIFTINSLOW_LIB_VERSION);
|
|
||||||
assertEqual(0, SIS.read());
|
assertEqual(0, SIS.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user