-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
#pragma once | ||
|
||
template <class Device, uint8_t totalChipCount> | ||
class ShiftIn { | ||
private: | ||
uint8_t _buffer[totalChipCount]; | ||
class ShiftIn | ||
{ | ||
private: | ||
uint8_t _buffer[totalChipCount]; | ||
bool invert = true; | ||
|
||
public: | ||
ShiftIn(Device& device) | ||
: _device(device) | ||
{ | ||
} | ||
public: | ||
ShiftIn(Device &device) | ||
: _device(device) | ||
{ | ||
} | ||
|
||
uint8_t* read(uint8_t chipCount = totalChipCount) { | ||
uint8_t *read(uint8_t chipCount = totalChipCount) | ||
{ | ||
_device.beginRead(); | ||
|
||
_device.beginRead(); | ||
for (auto i = 0; i < chipCount; i++) | ||
_buffer[i] = _device.read(); | ||
|
||
for (auto i = 0; i < chipCount; i++) | ||
_buffer[i] = _device.read(); | ||
_device.endRead(); | ||
|
||
_device.endRead(); | ||
if (invert) | ||
for (auto i = 0; i < chipCount; i++) | ||
_buffer[i] = ~_buffer[i]; | ||
|
||
return _buffer; | ||
} | ||
return _buffer; | ||
} | ||
|
||
private: | ||
Device& _device; | ||
private: | ||
Device &_device; | ||
}; | ||
|
||
#include <hardware/IC74HC165.h> | ||
|
||
#define CREATE_NATIVE_74HC165(Name, LatchPin, DataPin, ClockPin, MaxChipCount) \ | ||
NativeDigitalIO<LatchPin, OUTPUT> latch##Name; \ | ||
NativeDigitalIO<DataPin, INPUT> data##Name; \ | ||
NativeDigitalIO<ClockPin, OUTPUT> clock##Name; \ | ||
#define CREATE_NATIVE_74HC165(Name, LatchPin, DataPin, ClockPin, MaxChipCount) \ | ||
NativeDigitalIO<LatchPin, OUTPUT> latch##Name; \ | ||
NativeDigitalIO<DataPin, INPUT> data##Name; \ | ||
NativeDigitalIO<ClockPin, OUTPUT> clock##Name; \ | ||
IC74HC165<NativeDigitalIO<LatchPin, OUTPUT>, NativeDigitalIO<DataPin, INPUT>, NativeDigitalIO<ClockPin, OUTPUT>> chip##Name(latch##Name, data##Name, clock##Name); \ | ||
ShiftIn<IC74HC165<NativeDigitalIO<LatchPin, OUTPUT>, NativeDigitalIO<DataPin, INPUT>, NativeDigitalIO<ClockPin, OUTPUT>>, MaxChipCount> Name(chip##Name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ | |
|
||
#include <NativeDigitalIO.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,55 @@ | ||
#pragma once | ||
|
||
template <class Device, uint8_t totalChipCount> | ||
class ShiftOut { | ||
public: | ||
ShiftOut(Device& device) | ||
: _device(device) | ||
{ | ||
} | ||
class ShiftOut | ||
{ | ||
private: | ||
uint8_t _buffer[totalChipCount]; | ||
bool _autoCommit; | ||
|
||
void write(uint8_t* buffer, uint8_t chipCount = totalChipCount) { | ||
_device.beginWrite(); | ||
public: | ||
ShiftOut(Device &device) | ||
: _device(device) | ||
{ | ||
} | ||
|
||
for (int i = chipCount - 1; i >= 0; i--) | ||
_device.write(buffer[i]); | ||
void write(uint8_t *buffer, uint8_t chipCount = totalChipCount) | ||
{ | ||
_device.beginWrite(); | ||
|
||
_device.endWrite(); | ||
} | ||
for (int i = chipCount - 1; i >= 0; i--) | ||
_device.write(buffer[i]); | ||
|
||
private: | ||
Device& _device; | ||
_device.endWrite(); | ||
} | ||
|
||
ShiftOut& setAll(bool onOff) | ||
{ | ||
for (int i = totalChipCount - 1; i >= 0; i--) | ||
_buffer[i] = (onOff) ? 0xFF : 0x00; | ||
return static_cast<ShiftOut &>(*this); | ||
} | ||
|
||
ShiftOut& set(uint8_t bit, bool onOff) | ||
{ | ||
bitWrite(_buffer[bit / 8], bit - (8 * (bit / 8)), onOff); | ||
return static_cast<ShiftOut &>(*this); | ||
} | ||
|
||
void commit() | ||
{ | ||
write(_buffer, totalChipCount); | ||
} | ||
|
||
private: | ||
Device &_device; | ||
}; | ||
|
||
#include <hardware/IC74HC595.h> | ||
|
||
#define CREATE_NATIVE_74HC595(Name, LatchPin, DataPin, ClockPin, MaxChipCount) \ | ||
NativeDigitalIO<LatchPin, OUTPUT> latch##Name; \ | ||
NativeDigitalIO<DataPin, OUTPUT> data##Name; \ | ||
NativeDigitalIO<ClockPin, OUTPUT> clock##Name; \ | ||
#define CREATE_NATIVE_74HC595(Name, LatchPin, DataPin, ClockPin, MaxChipCount) \ | ||
NativeDigitalIO<LatchPin, OUTPUT> latch##Name; \ | ||
NativeDigitalIO<DataPin, OUTPUT> data##Name; \ | ||
NativeDigitalIO<ClockPin, OUTPUT> clock##Name; \ | ||
IC74HC595<NativeDigitalIO<LatchPin, OUTPUT>, NativeDigitalIO<DataPin, OUTPUT>, NativeDigitalIO<ClockPin, OUTPUT>> chip##Name(latch##Name, data##Name, clock##Name); \ | ||
ShiftOut<IC74HC595<NativeDigitalIO<LatchPin, OUTPUT>, NativeDigitalIO<DataPin, OUTPUT>, NativeDigitalIO<ClockPin, OUTPUT>>, MaxChipCount> Name(chip##Name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters