+ based upon Print interface

+ less variables (more local)
+ some comments
This commit is contained in:
Rob Tillaart 2013-08-29 11:39:24 +02:00
parent b99f202fac
commit 9593136bda
2 changed files with 31 additions and 28 deletions

View File

@ -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;

View File

@ -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