diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
commit | f508189682b6fba62e08feeb1596f682bad5fff9 (patch) | |
tree | 28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/progs/direct/base/direct_18.cpp | |
download | piklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip |
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/progs/direct/base/direct_18.cpp')
-rw-r--r-- | src/progs/direct/base/direct_18.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/progs/direct/base/direct_18.cpp b/src/progs/direct/base/direct_18.cpp new file mode 100644 index 0000000..d512d32 --- /dev/null +++ b/src/progs/direct/base/direct_18.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (C) 2003-2005 Alain Gibaud <alain.gibaud@free.fr> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "direct_18.h" + +// Commands specific to 18F: +// xhh = send a 8 bits constant (hh must be a 2 digits hex constant) +// Xhhhh = send a 16 bits constant (hhhh must be a 4 digits hex constant) +bool Direct::P18::pulse(const char *&cmd, BitValue value, BitValue &res) +{ + switch (*cmd) { + case 'x': { + uint n; + sscanf(++cmd, "%02X", &n); + ++cmd; + log(Log::DebugLevel::Max, "SEND 1 byte constant : " + toHexLabel(n, 2)); + send_bits(n, 8); + break; + } + case 'X': { + uint n; + sscanf(++cmd,"%04X", &n); + cmd += 3; + log(Log::DebugLevel::Max, "SEND 2 bytes constant : " + toHexLabel(n, 4)); + send_bits(n, 16); + break; + } + default: return Pic8DeviceSpecific::pulse(cmd, value, res); + } + return true; +} + +void Direct::P18::send_word(BitValue d) +{ + hardware().setWrite(); + for (uint x = 0; x<16; x++) { + hardware().setPin(Clock, High); + if ( d.bit(0) ) hardware().setPin(DataOut, High); + else hardware().setPin(DataOut, Low); + Port::usleep(_clockDelay+5); + hardware().setPin(Clock, Low); + Port::usleep(_clockDelay+3); + d >>= 1; // Move the data over 1 bit + } + hardware().setPin(DataOut, High); + hardware().setRead(); +} + +BitValue Direct::P18::get_word() +{ + hardware().setRead(); + BitValue ind = 0; + send_cmd(9); + hardware().setPin(DataOut, High); + for (uint x = 0; x<16; x++) { + hardware().setPin(Clock, High); + Port::usleep(_clockDelay+5); + if ( x>7 && hardware().readBit() ) ind |= (1 << x-8); + hardware().setPin(Clock, Low); + Port::usleep(_clockDelay+3); + } + send_cmd(9); + hardware().setPin(DataOut, High); + for (uint x = 0; x<16; x++) { + hardware().setPin(Clock, High); + Port::usleep(_clockDelay+5); + if ( x>7 && hardware().readBit() ) ind |= (1 << x); + hardware().setPin(Clock, Low); + Port::usleep(_clockDelay+3); + } + return ind; +} + +BitValue Direct::P18::get_byte() +{ + hardware().setRead(); + BitValue ind = 0; + send_cmd(2); + hardware().setPin(DataOut, High); + for (uint x = 0; x<16; x++) { + hardware().setPin(Clock, High); + Port::usleep(_clockDelay+5); + if ( x>7 && hardware().readBit() ) ind |= (1 << x-8); + hardware().setPin(Clock, Low); + Port::usleep(_clockDelay+3); + } + return ind; +} + +void Direct::P18::send_bits(BitValue d, uint nbb) +{ + hardware().setWrite(); + for (int x = nbb; x; --x) { + hardware().setPin(Clock, High); + if ( d.bit(0) ) hardware().setPin(DataOut, High); + else hardware().setPin(DataOut, Low); + Port::usleep(_clockDelay+5); + hardware().setPin(Clock, Low); + Port::usleep(_clockDelay+3); + d >>= 1; // Move the data over 1 bit + } + hardware().setPin(DataOut, High); + hardware().setRead(); +} |