From 9593136bdad1785c451a7d91b24cfd5321ec27da Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Thu, 29 Aug 2013 11:39:24 +0200 Subject: [PATCH] + based upon Print interface + less variables (more local) + some comments --- libraries/FastShiftOut/FastShiftOut.cpp | 36 +++++++++++++++---------- libraries/FastShiftOut/FastShiftOut.h | 23 +++++++--------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/libraries/FastShiftOut/FastShiftOut.cpp b/libraries/FastShiftOut/FastShiftOut.cpp index 2bdf8046..b61f0500 100644 --- a/libraries/FastShiftOut/FastShiftOut.cpp +++ b/libraries/FastShiftOut/FastShiftOut.cpp @@ -1,8 +1,8 @@ // // FILE: FastShiftOut.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1 -// PURPOSE: +// VERSION: 0.1.03 +// PURPOSE: shiftout that implements the Print interface // URL: // // Released to the public domain @@ -10,29 +10,33 @@ #include "FastShiftOut.h" +// +// Constructor +// prepares the digitalWrite() FastShiftOut::FastShiftOut(uint8_t datapin, uint8_t clockpin, uint8_t bitOrder) { - _datapin = datapin; - _clockpin = clockpin; _bitorder = bitOrder; _value = -1; - pinMode(_datapin, OUTPUT); - pinMode(_clockpin, OUTPUT); + pinMode(datapin, OUTPUT); + pinMode(clockpin, OUTPUT); - _datatimer = digitalPinToTimer(_datapin); - _databit = digitalPinToBitMask(_datapin); - _dataport = digitalPinToPort(_datapin); - // if (_datatimer != NOT_ON_TIMER) turnOffPWM(_datatimer); + // uint8_t _datatimer = digitalPinToTimer(datapin); + // if (_datatimer != NOT_ON_TIMER) turnOffPWM(_datatimer); TODO + uint8_t _dataport = digitalPinToPort(datapin); _dataout = portOutputRegister(_dataport); + _databit = digitalPinToBitMask(datapin); - _clocktimer = digitalPinToTimer(_clockpin); - _clockbit = digitalPinToBitMask(_clockpin); - _clockport = digitalPinToPort(_clockpin); + // uint8_t _clocktimer = digitalPinToTimer(clockpin); // if (_clocktimer != NOT_ON_TIMER) turnOffPWM(_clocktimer); + uint8_t _clockport = digitalPinToPort(clockpin); _clockout = portOutputRegister(_clockport); + _clockbit = digitalPinToBitMask(clockpin); } -void FastShiftOut::write(uint8_t data) +// +// write() must implement the virtual write of Print class +// +size_t FastShiftOut::write(uint8_t data) { _value = data; for (uint8_t i = 0; i < 8; i++) @@ -49,8 +53,12 @@ void FastShiftOut::write(uint8_t data) *_clockout &= ~_clockbit; SREG = oldSREG; } + return 1; } +// +// reads back the last value written. +// int FastShiftOut::read() { return _value; diff --git a/libraries/FastShiftOut/FastShiftOut.h b/libraries/FastShiftOut/FastShiftOut.h index e46ecb17..5f7a4239 100644 --- a/libraries/FastShiftOut/FastShiftOut.h +++ b/libraries/FastShiftOut/FastShiftOut.h @@ -1,8 +1,8 @@ // // FILE: FastShiftOut.h // AUTHOR: Rob Tillaart -// VERSION: 0.1 -// PURPOSE: +// VERSION: 0.1.03 +// PURPOSE: shiftout that implements the Print interface // URL: // // Released to the public domain @@ -17,31 +17,26 @@ #include "WProgram.h" #endif -#define FASTSHIFTOUT_LIB_VERSION "0.1.00" +#define FASTSHIFTOUT_LIB_VERSION "0.1.03" -class FastShiftOut +#include "Print.h" + +class FastShiftOut : public Print { public: FastShiftOut(uint8_t, uint8_t, uint8_t); - void write(uint8_t); + size_t write(uint8_t); int read(void); private: - uint8_t _datapin; - uint8_t _clockpin; uint8_t _bitorder; int _value; - uint8_t _datatimer; uint8_t _databit; - uint8_t _dataport; volatile uint8_t *_dataout; - - uint8_t _clocktimer; - uint8_t _clockbit; - uint8_t _clockport; - volatile uint8_t *_clockout; + uint8_t _clockbit; + volatile uint8_t *_clockout; }; #endif