mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 ShiftOutSlow
This commit is contained in:
parent
4cbc756466
commit
2564e8e217
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -6,11 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.4] - 2023-02-21
|
||||
- add default **LSBFIRST** for **setBitOrder()**
|
||||
- add default **0** for **setDelay()**
|
||||
- update readme.md
|
||||
- move code from .h to .cpp
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.3] - 2022-11-24
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
||||
|
||||
## [0.1.2] - 2021-12-28
|
||||
- update library.json
|
||||
- update readme
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-2022 Rob Tillaart
|
||||
Copyright (c) 2021-2023 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
|
||||
|
@ -40,19 +40,29 @@ resulting in "better" pulses.
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "ShiftOutSlow.h"
|
||||
```
|
||||
|
||||
#### Functions
|
||||
|
||||
The interface exists of the following functions:
|
||||
|
||||
- **ShiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor.
|
||||
- **size_t write(uint8_t data)** writes a new value. Returns the bytes written.
|
||||
- **size_t write(const uint8_t \*buffer, size_t size)** writes an array of size over shift out. Uses **write(uint8_t)** so expect about equal performance. Returns the bytes written.
|
||||
- **size_t write(uint8_t data)** writes a new value.
|
||||
Returns the bytes written.
|
||||
- **size_t write(const uint8_t \*buffer, size_t size)** writes an array of size over shift out.
|
||||
Uses **write(uint8_t)** so expect about equal performance.
|
||||
Returns the bytes written.
|
||||
- **uint8_t lastWritten()** returns last value written.
|
||||
- **void setDelay(uint16_t microSeconds)** set delay per bit from 0 .. 65535 microseconds.
|
||||
Note that the delay is not the time per bit but an additional time per bit.
|
||||
- **void setDelay(uint16_t microSeconds = 0)** set delay per **bit** from 0 .. 65535 microseconds.
|
||||
Note: the delay is not the time per bit but an additional time per bit.
|
||||
Note: the delay can be set runtime per write / print call.
|
||||
- **uint16_t getDelay()** returns the set delay in microseconds.
|
||||
- **bool setBitOrder(uint8_t bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
|
||||
- **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST.
|
||||
Returns false for other values.
|
||||
Note: bit order can be changed runtime per write / print call.
|
||||
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST (typical 0 and 1).
|
||||
- **uint8_t getBitOrder()** returns LSBFIRST or MSBFIRST (typical 0 and 1).
|
||||
|
||||
|
||||
### Print interface
|
||||
@ -70,19 +80,22 @@ See examples.
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
|
||||
#### should
|
||||
#### Should
|
||||
|
||||
- add examples
|
||||
- adaptive speed example?
|
||||
|
||||
#### could
|
||||
#### Could
|
||||
- Add a select pin to be more SPI alike?
|
||||
- increase max delay uint32_t ?
|
||||
|
||||
#### Wont
|
||||
|
||||
- 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 ?
|
||||
- get set dutyCycle(0 .. 99%)
|
||||
- optimize the place to yield() ?
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: ShiftOutSlow.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Arduino library for shiftOut with build-in delay
|
||||
// DATE: 2021-05-11
|
||||
// URL: https://github.com/RobTillaart/ShiftOutSlow
|
||||
@ -58,6 +58,12 @@ size_t ShiftOutSlow::write(const uint8_t *buffer, size_t size)
|
||||
}
|
||||
|
||||
|
||||
uint8_t ShiftOutSlow::lastWritten()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
bool ShiftOutSlow::setBitOrder(const uint8_t bitOrder)
|
||||
{
|
||||
if ((bitOrder == LSBFIRST) || (bitOrder == MSBFIRST))
|
||||
@ -69,5 +75,23 @@ bool ShiftOutSlow::setBitOrder(const uint8_t bitOrder)
|
||||
}
|
||||
|
||||
|
||||
uint8_t ShiftOutSlow::getBitOrder()
|
||||
{
|
||||
return _bitOrder;
|
||||
}
|
||||
|
||||
|
||||
void ShiftOutSlow::setDelay(uint16_t microSeconds)
|
||||
{
|
||||
_delay = microSeconds;
|
||||
}
|
||||
|
||||
|
||||
uint16_t ShiftOutSlow::getDelay()
|
||||
{
|
||||
return _delay;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,17 +2,16 @@
|
||||
//
|
||||
// FILE: ShiftOutSlow.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// 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.3"))
|
||||
#define SHIFTOUTSLOW_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
|
||||
class ShiftOutSlow : public Print
|
||||
@ -22,17 +21,17 @@ public:
|
||||
ShiftOutSlow(const uint8_t dataPin, const uint8_t clockPin, const uint8_t bitOrder = LSBFIRST);
|
||||
|
||||
// PRINT INTERFACE
|
||||
virtual size_t write(const uint8_t data) override;
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override;
|
||||
virtual size_t write(const uint8_t data) override;
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override;
|
||||
|
||||
uint8_t lastWritten(void) { return _value; };
|
||||
uint8_t lastWritten();
|
||||
|
||||
bool setBitOrder(const uint8_t bitOrder);
|
||||
uint8_t getBitOrder(void) { return _bitOrder; };
|
||||
bool setBitOrder(const uint8_t bitOrder = LSBFIRST);
|
||||
uint8_t getBitOrder();
|
||||
|
||||
// microSeconds = 0..65535
|
||||
void setDelay(uint16_t microSeconds) { _delay = microSeconds; };
|
||||
uint16_t getDelay() { return _delay; };
|
||||
void setDelay(uint16_t microSeconds = 0);
|
||||
uint16_t getDelay();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -16,10 +16,10 @@ volatile int x = 0;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.println(__FILE__);
|
||||
Serial.println(SHIFTOUTSLOW_LIB_VERSION);
|
||||
|
||||
for (uint16_t d = 0; d < 1000; d += 10)
|
||||
for (uint16_t d = 0; d <= 1000; d += 100)
|
||||
{
|
||||
SOS.setDelay(d);
|
||||
uint32_t start = micros();
|
||||
@ -28,7 +28,11 @@ void setup()
|
||||
float duration = stop - start;
|
||||
Serial.print(stop - start);
|
||||
Serial.print("\t");
|
||||
Serial.println(duration / 8, 1);
|
||||
Serial.print(d);
|
||||
Serial.print("\t");
|
||||
Serial.print(duration / 8, 1);
|
||||
Serial.print("\n");
|
||||
delay(20);
|
||||
}
|
||||
|
||||
Serial.println("done...");
|
||||
@ -41,4 +45,3 @@ void loop()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/ShiftOutSlow.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ShiftOutSlow
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for shiftOut with build-in delay - e.g. for 74HC165
|
||||
|
@ -40,6 +40,7 @@ unittest_setup()
|
||||
fprintf(stderr, "SHIFTOUTSLOW_LIB_VERSION:\t%s\n", (char *) SHIFTOUTSLOW_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
@ -55,6 +56,9 @@ unittest(test_constructor)
|
||||
|
||||
SOS.setBitOrder(MSBFIRST);
|
||||
assertEqual(MSBFIRST, SOS.getBitOrder());
|
||||
|
||||
SOS.setBitOrder();
|
||||
assertEqual(LSBFIRST, SOS.getBitOrder());
|
||||
}
|
||||
|
||||
|
||||
@ -93,6 +97,8 @@ unittest(test_setDelay)
|
||||
SOS.setDelay(d);
|
||||
assertEqual(d, SOS.getDelay());
|
||||
}
|
||||
SOS.setDelay();
|
||||
assertEqual(0, SOS.getDelay());
|
||||
}
|
||||
|
||||
|
||||
@ -112,6 +118,9 @@ unittest(test_print_interface)
|
||||
assertEqual(8, z);
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user