summaryrefslogtreecommitdiffstats
path: root/src/progs/icd1
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/progs/icd1
downloadpiklab-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/icd1')
-rw-r--r--src/progs/icd1/Makefile.am3
-rw-r--r--src/progs/icd1/base/Makefile.am11
-rw-r--r--src/progs/icd1/base/base.pro6
-rw-r--r--src/progs/icd1/base/icd1.cpp197
-rw-r--r--src/progs/icd1/base/icd1.h58
-rw-r--r--src/progs/icd1/base/icd1.xml25
-rw-r--r--src/progs/icd1/base/icd1_data.h22
-rw-r--r--src/progs/icd1/base/icd1_prog.cpp51
-rw-r--r--src/progs/icd1/base/icd1_prog.h60
-rw-r--r--src/progs/icd1/base/icd1_serial.cpp76
-rw-r--r--src/progs/icd1/base/icd1_serial.h31
-rw-r--r--src/progs/icd1/gui/Makefile.am6
-rw-r--r--src/progs/icd1/gui/icd1_group_ui.cpp41
-rw-r--r--src/progs/icd1/gui/icd1_group_ui.h43
-rw-r--r--src/progs/icd1/icd1.pro2
-rw-r--r--src/progs/icd1/xml/Makefile.am14
-rw-r--r--src/progs/icd1/xml/xml.pro18
-rw-r--r--src/progs/icd1/xml/xml_icd1_parser.cpp41
18 files changed, 705 insertions, 0 deletions
diff --git a/src/progs/icd1/Makefile.am b/src/progs/icd1/Makefile.am
new file mode 100644
index 0000000..fccf96d
--- /dev/null
+++ b/src/progs/icd1/Makefile.am
@@ -0,0 +1,3 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+SUBDIRS = xml base gui
diff --git a/src/progs/icd1/base/Makefile.am b/src/progs/icd1/base/Makefile.am
new file mode 100644
index 0000000..3795dc5
--- /dev/null
+++ b/src/progs/icd1/base/Makefile.am
@@ -0,0 +1,11 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libicd1.la
+libicd1_la_SOURCES = icd1.cpp icd1_prog.cpp icd1_serial.cpp icd1_data.cpp
+libicd1_la_DEPENDENCIES = icd1_data.cpp
+
+noinst_DATA = icd1.xml
+icd1_data.cpp: ../xml/xml_icd1_parser icd1.xml
+ ../xml/xml_icd1_parser
+CLEANFILES = icd1_data.cpp
diff --git a/src/progs/icd1/base/base.pro b/src/progs/icd1/base/base.pro
new file mode 100644
index 0000000..8ff4081
--- /dev/null
+++ b/src/progs/icd1/base/base.pro
@@ -0,0 +1,6 @@
+STOPDIR = ../../../..
+include($${STOPDIR}/lib.pro)
+
+TARGET = icd1
+HEADERS += icd1.h icd1_data.h icd1_prog.h icd1_serial.h
+SOURCES += icd1.cpp icd1_data.cpp icd1_prog.cpp icd1_serial.cpp
diff --git a/src/progs/icd1/base/icd1.cpp b/src/progs/icd1/base/icd1.cpp
new file mode 100644
index 0000000..8c2704a
--- /dev/null
+++ b/src/progs/icd1/base/icd1.cpp
@@ -0,0 +1,197 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2002-2003 Stephen Landamore <stephen@landamore.com> *
+ * *
+ * 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 "icd1.h"
+
+#include "common/global/global.h"
+#include "common/common/misc.h"
+#include "common/port/port_base.h"
+
+//-----------------------------------------------------------------------------
+Icd1::Hardware::Hardware(::Programmer::Base &base, const QString &portDevice)
+ : Icd::Hardware(base, new SerialPort(portDevice, base))
+{}
+
+bool Icd1::Hardware::internalConnect(const QString &mode)
+{
+ if ( !port()->open() ) return false;
+ if ( !port()->reset() ) return false;
+ if ( hasError() ) return false;
+ QByteArray a = toAscii(mode);
+ if ( !port()->send(a.data(), a.count()) ) return false;
+ QString s;
+ if ( !port()->receive(1, s) ) return false;
+ port()->setPinOn(Port::Serial::RTS, false, Port::PositiveLogic);
+ Port::msleep(1);
+ port()->setPinOn(Port::Serial::RTS, true, Port::PositiveLogic);
+ if ( s.upper()!=mode ) {
+ log(Log::LineType::Error, i18n("Failed to set port mode to '%1'.").arg(mode));
+ return false;
+ }
+ return true;
+}
+
+bool Icd1::Hardware::sendCommand(uint cmd, BitValue *res, uint timeout)
+{
+ if ( !port()->sendCommand(cmd) ) return false;
+ uchar byte;
+ if ( !port()->receiveByte((char &)byte, false, timeout) ) return false;
+ if (res) *res = byte << 8;
+ if ( !port()->receiveByte((char &)byte, true, timeout) ) return false;
+ if (res) *res += byte;
+ return true;
+}
+
+bool Icd1::Hardware::readBlockCommand(uint nbBytes)
+{
+ Q_ASSERT( nbBytes<=0xFF );
+ if ( !port()->sendCommand(0x7D00 + nbBytes) ) return false;
+ QByteArray a(nbBytes);
+ for (uint i=0; i<nbBytes; i++)
+ if ( !port()->receiveByte(*(a.data()+i), i!=0) ) return false;
+ _rx = QString(a);
+ return true;
+}
+
+bool Icd1::Hardware::setTarget()
+{
+ return sendCommand(0x6300 + data(_base.device()->name()).part);
+}
+
+bool Icd1::Hardware::getFirmwareVersion(VersionData &version)
+{
+ BitValue v1, v2;
+ if ( !sendCommand(0x7F00, &v1) || !sendCommand(0x7021, &v2) ) return false;
+ version = VersionData(v1.byte(1), v1.byte(0), v2.toUInt());
+ return true;
+}
+
+bool Icd1::Hardware::readVoltages(VoltagesData &voltages)
+{
+ if ( !sendCommand(0x7000) ) return false;
+ BitValue res;
+ if ( !sendCommand(0x701C, &res) ) return false;
+ voltages[Pic::TargetVdd].value = (2.050 / 256) * res.toUInt(); // voltage at AN0 pin
+ voltages[Pic::TargetVdd].value /= (4.7 / 14.7); // voltage at Vcc
+ log(Log::DebugLevel::Max, QString("Vdd: %1 %2").arg(toHexLabel(res, 4)).arg(voltages[Pic::TargetVdd].value));
+ voltages[Pic::TargetVdd].error = false;
+ if ( !sendCommand(0x701D, &res) ) return false;
+ voltages[Pic::TargetVpp].value = (2.050 / 256) * res.byte(0); // voltage at AN1 pin
+ voltages[Pic::TargetVpp].value /= (10.0 / 110.0); // voltage at Vpp
+ log(Log::DebugLevel::Max, QString("Vpp: %1 %2").arg(toHexLabel(res, 4)).arg(voltages[Pic::TargetVpp].value));
+ voltages[Pic::TargetVpp].error = false;
+ return sendCommand(0x7001);
+}
+
+bool Icd1::Hardware::uploadFirmware(const Pic::Memory &memory)
+{
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::setTargetReset(Pic::ResetMode mode)
+{
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::selfTest()
+{
+ BitValue res;
+ if ( !sendCommand(0x700B, &res, 5000) ) return false;
+ if ( res!=0 ) {
+ log(Log::LineType::Warning, i18n("Self-test failed (returned value is %1)").arg(toLabel(res)));
+ return false;
+ }
+ return true;
+}
+
+bool Icd1::Hardware::gotoMemory(Pic::MemoryRangeType type, uint offset)
+{
+ if ( !sendCommand(0x7000) ) return false; // start sequence
+ uint cmd = (type==Pic::MemoryRangeType::Eeprom ? 0x7006 : 0x7005);
+ if ( !sendCommand(cmd) ) return false;
+ if ( type==Pic::MemoryRangeType::Config || type==Pic::MemoryRangeType::UserId || type==Pic::MemoryRangeType::DeviceId ) {
+ Q_ASSERT( offset==0 );
+ offset = device().range(type).start - Address(0x2000);
+ if ( !sendCommand(0xC000 + offset) ) return false;
+ } else if ( !sendCommand(0x2000 + offset) ) return false;
+ return true;
+}
+
+bool Icd1::Hardware::readMemory(Pic::MemoryRangeType type, uint wordOffset, Device::Array &data, const ::Programmer::VerifyData *vdata)
+{
+ if ( !gotoMemory(type, wordOffset) ) return false;
+ for (uint i=0; i<data.count(); i++) if ( !sendCommand(0x7002, &data[i]) ) return false;
+ if ( !sendCommand(0x7001) ) return false; // end sequence
+ if (vdata) {
+ for (uint i=0; i<data.count(); i++)
+ if ( !verifyWord(wordOffset+i, data[i], type, *vdata) ) return false;
+ }
+ return true;
+}
+
+bool Icd1::Hardware::writeMemory(Pic::MemoryRangeType type, uint wordOffset, const Device::Array &data)
+{
+ if ( !gotoMemory(type, wordOffset) ) return false;
+ for (uint i=0; i<data.count(); i++) if ( !sendCommand(0x8000 | data[i].toUInt()) ) return false;
+ if ( !sendCommand(0x7001) ) return false; // end sequence
+ return true;
+}
+
+bool Icd1::Hardware::eraseAll()
+{
+ BitValue res;
+ if ( !sendCommand(0x7000) ) return false; // enable Vpp
+ if ( !sendCommand(0x7007, &res) ) return false;
+ if ( !sendCommand(0x7001) ) return false; // disable Vpp
+ if ( res!=0x3FFF ) {
+ log(Log::LineType::Error, i18n("Erase failed (returned value is %1)").arg(toHexLabel(res, 4)));
+ return false;
+ }
+ return true;
+}
+
+bool Icd1::Hardware::haltRun()
+{
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::step()
+{
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::resumeRun()
+{
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::writeRegister(Address address, BitValue value, uint nbBytes)
+{
+ Q_ASSERT( nbBytes==1 || nbBytes==2 );
+ // #### TODO
+ return false;
+}
+
+bool Icd1::Hardware::readRegister(Address address, BitValue &value, uint nbBytes)
+{
+ Q_ASSERT( nbBytes==1 || nbBytes==2 );
+ // #### TODO
+ return false;
+}
+
+BitValue Icd1::Hardware::getProgramCounter()
+{
+ // #### TODO
+ return 0;
+}
diff --git a/src/progs/icd1/base/icd1.h b/src/progs/icd1/base/icd1.h
new file mode 100644
index 0000000..d1ae1d0
--- /dev/null
+++ b/src/progs/icd1/base/icd1.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2002-2003 Stephen Landamore <stephen@landamore.com> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ICD1_H
+#define ICD1_H
+
+#include "progs/icd2/base/icd.h"
+#include "icd1_data.h"
+#include "icd1_serial.h"
+
+namespace Icd1
+{
+//-----------------------------------------------------------------------------
+class Hardware : public Icd::Hardware
+{
+public:
+ Hardware(::Programmer::Base &base, const QString &portDevice);
+ SerialPort *port() { return static_cast<SerialPort *>(_port); }
+ // initialization
+ virtual bool uploadFirmware(const Pic::Memory &memory);
+ virtual bool setTarget();
+
+// status
+ virtual bool getFirmwareVersion(VersionData &version);
+ virtual bool readVoltages(VoltagesData &voltages);
+ virtual bool setTargetReset(Pic::ResetMode mode);
+ bool selfTest();
+
+// programming
+ virtual bool readMemory(Pic::MemoryRangeType type, uint wordOffset, Device::Array &data, const ::Programmer::VerifyData *vdata);
+ virtual bool writeMemory(Pic::MemoryRangeType type, uint wordOffset, const Device::Array &data);
+ virtual bool eraseAll();
+
+// debugging
+ virtual bool readRegister(Address address, BitValue &value, uint nbBytes);
+ virtual bool writeRegister(Address address, BitValue value, uint nbBytes);
+ virtual bool resumeRun();
+ virtual bool step();
+ virtual bool haltRun();
+ virtual BitValue getProgramCounter();
+
+private:
+ virtual bool internalConnect(const QString &mode);
+ virtual QString receivedData() const { return _rx; }
+ bool sendCommand(uint cmd, BitValue *res = 0, uint timeout = Port::Serial::DEFAULT_TIMEOUT);
+ bool readBlockCommand(uint nbBytes);
+ bool gotoMemory(Pic::MemoryRangeType type, uint offset);
+};
+
+} // namespace
+
+#endif
diff --git a/src/progs/icd1/base/icd1.xml b/src/progs/icd1/base/icd1.xml
new file mode 100644
index 0000000..4be7e3e
--- /dev/null
+++ b/src/progs/icd1/base/icd1.xml
@@ -0,0 +1,25 @@
+<!-- ************************************************************************* -->
+<!-- * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> * -->
+<!-- * * -->
+<!-- * 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. * -->
+<!-- *************************************************************************/-->
+<!DOCTYPE piklab>
+
+<type name="icd1">
+ <device name="16F870" family="0x02" />
+ <device name="16F871" family="0x02" />
+ <device name="16F872" family="0x02" />
+ <device name="16F873" family="0x01" />
+ <device name="16F874" family="0x01" />
+ <device name="16F876" family="0x00" />
+ <device name="16F877" family="0x00" />
+
+ <!-- not sure about these: only with newer firmware -->
+ <device name="16F873A" family="0x01" />
+ <device name="16F874A" family="0x01" />
+ <device name="16F876A" family="0x00" />
+ <device name="16F877A" family="0x00" />
+</type>
diff --git a/src/progs/icd1/base/icd1_data.h b/src/progs/icd1/base/icd1_data.h
new file mode 100644
index 0000000..4200578
--- /dev/null
+++ b/src/progs/icd1/base/icd1_data.h
@@ -0,0 +1,22 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ICD1_DATA_H
+#define ICD1_DATA_H
+
+#include <qstring.h>
+
+namespace Icd1
+{
+ struct Data {
+ uchar part;
+ };
+ extern const Data &data(const QString &device);
+} // namespace
+
+#endif
diff --git a/src/progs/icd1/base/icd1_prog.cpp b/src/progs/icd1/base/icd1_prog.cpp
new file mode 100644
index 0000000..13d0d4c
--- /dev/null
+++ b/src/progs/icd1/base/icd1_prog.cpp
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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 "icd1_prog.h"
+
+#include <qdir.h>
+
+#include "progs/base/prog_config.h"
+#include "devices/list/device_list.h"
+#include "icd1_serial.h"
+
+//-----------------------------------------------------------------------------
+void Icd1::ProgrammerBase::clear()
+{
+ Icd::ProgrammerBase::clear();
+ _selfTestResult = ::Programmer::Nb_ResultTypes;
+}
+
+bool Icd1::ProgrammerBase::selfTest(bool ask)
+{
+ log(Log::DebugLevel::Normal, " Self-test");
+ _selfTestResult = (hardware().selfTest() ? ::Programmer::Pass : ::Programmer::Fail);
+ if ( _selfTestResult==::Programmer::Fail ) {
+ if ( ask && !askContinue(i18n("Self-test failed. Do you want to continue anyway?")) ) {
+ logUserAbort();
+ return false;
+ }
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+Programmer::Properties Icd1::Group::properties() const
+{
+ return ::Programmer::Programmer | ::Programmer::HasFirmware | ::Programmer::CanUploadFirmware | ::Programmer::HasSelfTest | ::Programmer::CanReadMemory | ::Programmer::HasConnectedState;
+}
+
+Programmer::Hardware *Icd1::Group::createHardware(::Programmer::Base &base, const ::Programmer::HardwareDescription &hd) const
+{
+ return new Hardware(base, hd.port.device);
+}
+
+Programmer::DeviceSpecific *Icd1::Group::createDeviceSpecific(::Programmer::Base &base) const
+{
+ return new Icd::DeviceSpecific(base);
+}
diff --git a/src/progs/icd1/base/icd1_prog.h b/src/progs/icd1/base/icd1_prog.h
new file mode 100644
index 0000000..721be49
--- /dev/null
+++ b/src/progs/icd1/base/icd1_prog.h
@@ -0,0 +1,60 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ICD1_PROG_H
+#define ICD1_PROG_H
+
+#include "common/global/global.h"
+#include "progs/icd2/base/icd_prog.h"
+#include "icd1.h"
+#include "progs/base/prog_group.h"
+
+namespace Icd1
+{
+class Hardware;
+
+//-----------------------------------------------------------------------------
+class ProgrammerBase : public Icd::ProgrammerBase
+{
+Q_OBJECT
+public:
+ ProgrammerBase(const Programmer::Group &group, const Pic::Data *data)
+ : Icd::ProgrammerBase(group, data, "icd1_programmer_base") {}
+ virtual bool selfTest(bool ask);
+ ::Programmer::ResultType selfTestResult() const { return _selfTestResult; }
+
+protected:
+ Hardware &hardware() { return static_cast<Hardware &>(*_hardware); }
+ virtual void clear();
+
+private:
+ ::Programmer::ResultType _selfTestResult;
+};
+
+//-----------------------------------------------------------------------------
+class Group : public Icd::Group
+{
+public:
+ virtual QString name() const { return "icd1"; }
+ virtual QString label() const { return i18n("ICD1 Programmer"); }
+ virtual QString xmlName() const { return "icd1"; }
+ virtual ::Programmer::Properties properties() const;
+ virtual ::Programmer::TargetPowerMode targetPowerMode() const { return ::Programmer::TargetExternallyPowered; }
+ virtual bool isPortSupported(PortType type) const { return ( type==PortType::Serial ); }
+ virtual bool canReadVoltage(Pic::VoltageType type) const { return ( type==Pic::TargetVdd || type==Pic::TargetVpp ); }
+
+protected:
+ virtual void initSupported();
+ virtual ::Programmer::Base *createBase(const Device::Data *data) const { return new ProgrammerBase(*this, static_cast<const Pic::Data *>(data)); }
+ virtual ::Programmer::Hardware *createHardware(::Programmer::Base &base, const ::Programmer::HardwareDescription &hd) const;
+ virtual ::Programmer::DeviceSpecific *createDeviceSpecific(::Programmer::Base &base) const;
+};
+
+} // namespace
+
+#endif
diff --git a/src/progs/icd1/base/icd1_serial.cpp b/src/progs/icd1/base/icd1_serial.cpp
new file mode 100644
index 0000000..a506fdb
--- /dev/null
+++ b/src/progs/icd1/base/icd1_serial.cpp
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2002-2003 Stephen Landamore <stephen@landamore.com> *
+ * *
+ * 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 "icd1_serial.h"
+
+#include <qdatetime.h>
+#include "common/global/global.h"
+#include "common/common/misc.h"
+#include "common/common/number.h"
+
+//-----------------------------------------------------------------------------
+Icd1::SerialPort::SerialPort(const QString &device, Log::Base &log)
+ : Port::Serial(device, NeedDrain | NeedFlush, log)
+{}
+
+bool Icd1::SerialPort::open()
+{
+ if ( !Port::Serial::open() ) return false;
+ return setMode(NoInputFlag, ByteSize8 | IgnoreControlLines | EnableReceiver, S57600, 0);
+}
+
+bool Icd1::SerialPort::reset()
+{
+ // reset
+ setPinOn(RTS, false, Port::PositiveLogic);
+ setPinOn(DTR, false, Port::PositiveLogic);
+ Port::msleep(10);
+ // remove reset
+ setPinOn(RTS, true, Port::PositiveLogic);
+ setPinOn(DTR, true, Port::PositiveLogic);
+ Port::msleep(10);
+ return true;
+}
+
+bool Icd1::SerialPort::synchronize()
+{
+ if ( !setPinOn(RTS, false, Port::PositiveLogic) ) return false;
+ QTime time;
+ time.start();
+ for (;;) {
+ bool bit;
+ if ( !readPin(CTS, Port::PositiveLogic, bit) ) return false;
+ if ( !bit) break;
+ if ( uint(time.elapsed())>3000 ) { // 3 seconds
+ log(Log::LineType::Error, i18n("Timeout synchronizing."));
+ return false;
+ }
+ }
+ return setPinOn(RTS, true, Port::PositiveLogic);
+}
+
+bool Icd1::SerialPort::sendCommand(uint cmd)
+{
+ Q_ASSERT( cmd<=0xFFFF );
+ synchronize();
+ char c[7] = "$XXXX\r";
+ QString cs = toHex(cmd, 4);
+ log(Log::DebugLevel::Extra, QString("Send command: %1").arg(toPrintable(cs, PrintAlphaNum)));
+ c[1] = cs[0].latin1();
+ c[2] = cs[1].latin1();
+ c[3] = cs[2].latin1();
+ c[4] = cs[3].latin1();
+ return send(c, 7);
+}
+
+bool Icd1::SerialPort::receiveByte(char &byte, bool synchronizeBefore, uint timeout)
+{
+ if ( synchronizeBefore && !synchronize() ) return false;
+ return receiveChar(byte, timeout);
+}
diff --git a/src/progs/icd1/base/icd1_serial.h b/src/progs/icd1/base/icd1_serial.h
new file mode 100644
index 0000000..e8d03da
--- /dev/null
+++ b/src/progs/icd1/base/icd1_serial.h
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2002-2003 Stephen Landamore <stephen@landamore.com> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ICD1_SERIAL_H
+#define ICD1_SERIAL_H
+
+#include "common/port/serial.h"
+
+namespace Icd1
+{
+
+class SerialPort : public Port::Serial
+{
+public:
+ SerialPort(const QString &portDevice, Log::Base &log);
+ bool open();
+ bool reset();
+ bool synchronize();
+ bool sendCommand(uint cmd);
+ bool receiveByte(char &byte, bool synchronizeBefore, uint timeout = DEFAULT_TIMEOUT);
+};
+
+} // namespace
+
+#endif
diff --git a/src/progs/icd1/gui/Makefile.am b/src/progs/icd1/gui/Makefile.am
new file mode 100644
index 0000000..183aab9
--- /dev/null
+++ b/src/progs/icd1/gui/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+libicd1ui_la_LDFLAGS = $(all_libraries)
+noinst_LTLIBRARIES = libicd1ui.la
+
+libicd1ui_la_SOURCES = icd1_group_ui.cpp
diff --git a/src/progs/icd1/gui/icd1_group_ui.cpp b/src/progs/icd1/gui/icd1_group_ui.cpp
new file mode 100644
index 0000000..34f28d5
--- /dev/null
+++ b/src/progs/icd1/gui/icd1_group_ui.cpp
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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 "icd1_group_ui.h"
+
+#include "progs/gui/prog_config_widget.h"
+#include "progs/base/prog_group.h"
+#include "progs/icd1/base/icd1_prog.h"
+
+//----------------------------------------------------------------------------
+Icd1::AdvancedDialog::AdvancedDialog(ProgrammerBase &base, QWidget *parent)
+ : ::Programmer::PicAdvancedDialog(base, parent, "icd1_advanced_dialog")
+{
+ uint row = _selfTestContainer->numRows();
+ QLabel *label = new QLabel(i18n("Result:"), _selfTestContainer);
+ _selfTestContainer->addWidget(label, row,row, 0,0);
+ _selfTestLabel = new QLabel(_selfTestContainer);
+ _selfTestContainer->addWidget(_selfTestLabel, row,row, 1,1);
+}
+
+void Icd1::AdvancedDialog::updateDisplay()
+{
+ ::Programmer::PicAdvancedDialog::updateDisplay();
+ _selfTestLabel->setText(i18n(::Programmer::RESULT_TYPE_LABELS[base().selfTestResult()]));
+}
+
+//----------------------------------------------------------------------------
+::Programmer::ConfigWidget *Icd1::GroupUI::createConfigWidget(QWidget *parent) const
+{
+ return new ::Programmer::ConfigWidget(static_cast<const Group &>(group()), parent);
+}
+
+::Programmer::AdvancedDialog *Icd1::GroupUI::createAdvancedDialog(::Programmer::Base &base, QWidget *parent) const
+{
+ return new AdvancedDialog(static_cast<ProgrammerBase &>(base), parent);
+}
diff --git a/src/progs/icd1/gui/icd1_group_ui.h b/src/progs/icd1/gui/icd1_group_ui.h
new file mode 100644
index 0000000..f60562a
--- /dev/null
+++ b/src/progs/icd1/gui/icd1_group_ui.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ICD1_GROUP_UI_H
+#define ICD1_GROUP_UI_H
+
+#include "devices/pic/gui/pic_prog_group_ui.h"
+#include "progs/icd1/base/icd1_prog.h"
+
+namespace Icd1
+{
+class Group;
+
+//----------------------------------------------------------------------------
+class AdvancedDialog : public ::Programmer::PicAdvancedDialog
+{
+Q_OBJECT
+public:
+ AdvancedDialog(ProgrammerBase &base, QWidget *parent);
+ virtual void updateDisplay();
+
+private:
+ QLabel *_selfTestLabel;
+ ProgrammerBase &base() { return static_cast<ProgrammerBase &>(_base); }
+};
+
+//----------------------------------------------------------------------------
+class GroupUI : public ::Programmer::GroupUI
+{
+public:
+ virtual ::Programmer::ConfigWidget *createConfigWidget(QWidget *parent) const;
+ virtual bool hasAdvancedDialog() const { return true; }
+ virtual ::Programmer::AdvancedDialog *createAdvancedDialog(::Programmer::Base &base, QWidget *parent) const;
+};
+
+} // namespace
+
+#endif
diff --git a/src/progs/icd1/icd1.pro b/src/progs/icd1/icd1.pro
new file mode 100644
index 0000000..60ac0f5
--- /dev/null
+++ b/src/progs/icd1/icd1.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS = xml base
diff --git a/src/progs/icd1/xml/Makefile.am b/src/progs/icd1/xml/Makefile.am
new file mode 100644
index 0000000..dab961c
--- /dev/null
+++ b/src/progs/icd1/xml/Makefile.am
@@ -0,0 +1,14 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_PROGRAMS = xml_icd1_parser
+xml_icd1_parser_SOURCES = xml_icd1_parser.cpp
+OBJECTS = $(top_builddir)/src/devices/list/libdevicelistnoui.la \
+ $(top_builddir)/src/devices/pic/pic/libpic.la $(top_builddir)/src/devices/pic/base/libpicbase.la \
+ $(top_builddir)/src/devices/pic/xml_data/libpicxml.la \
+ $(top_builddir)/src/devices/mem24/mem24/libmem24.la $(top_builddir)/src/devices/mem24/base/libmem24base.la \
+ $(top_builddir)/src/devices/mem24/xml_data/libmem24xml.la \
+ $(top_builddir)/src/xml_to_data/libxmltodata.la $(top_builddir)/src/devices/base/libdevicebase.la \
+ $(top_builddir)/src/common/common/libcommon.la
+xml_icd1_parser_DEPENDENCIES = $(OBJECTS)
+xml_icd1_parser_LDADD = $(OBJECTS) $(LIB_KDECORE)
diff --git a/src/progs/icd1/xml/xml.pro b/src/progs/icd1/xml/xml.pro
new file mode 100644
index 0000000..ebbde6c
--- /dev/null
+++ b/src/progs/icd1/xml/xml.pro
@@ -0,0 +1,18 @@
+STOPDIR = ../../../..
+include($${STOPDIR}/app.pro)
+
+TARGET = xml_icd1_parser
+SOURCES += xml_icd1_parser.cpp
+LIBS += ../../../devices/list/libdevicelist.a \
+ ../../../devices/mem24/mem24/libmem24.a ../../../devices/mem24/xml_data/libmem24xml.a \
+ ../../../devices/mem24/base/libmem24base.a \
+ ../../../devices/pic/pic/libpic.a ../../../devices/pic/xml_data/libpicxml.a \
+ ../../../devices/pic/base/libpicbase.a ../../../xml_to_data/libxmltodata.a \
+ ../../../devices/base/libdevicebase.a ../../../common/global/libglobal.a \
+ ../../../common/nokde/libnokde.a ../../../common/common/libcommon.a
+
+unix:QMAKE_POST_LINK = cd ../base && ../xml/xml_icd1_parser
+unix:QMAKE_CLEAN += ../base/icd1_data.cpp
+win32:QMAKE_POST_LINK = cd ..\base && ..\xml\xml_icd1_parser.exe
+win32:QMAKE_CLEAN += ..\base\icd1_data.cpp
+
diff --git a/src/progs/icd1/xml/xml_icd1_parser.cpp b/src/progs/icd1/xml/xml_icd1_parser.cpp
new file mode 100644
index 0000000..e09f51c
--- /dev/null
+++ b/src/progs/icd1/xml/xml_icd1_parser.cpp
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * 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 "xml_to_data/prog_xml_to_data.h"
+#include "progs/icd1/base/icd1_data.h"
+
+//-----------------------------------------------------------------------------
+namespace Icd1
+{
+
+class XmlToData : public Programmer::XmlToData<Data>
+{
+public:
+ XmlToData() : Programmer::XmlToData<Data>("icd1", "Icd1") {}
+
+private:
+ virtual void parseData(QDomElement element, Data &data);
+ virtual void outputData(const Data &data, QTextStream &s) const;
+};
+
+void Icd1::XmlToData::parseData(QDomElement element, Data &data)
+{
+ bool ok;
+ data.part = fromHexLabel(element.attribute("family"), 2, &ok);
+ if ( !ok ) qFatal("Missing or malformed family attribute");
+}
+
+void Icd1::XmlToData::outputData(const Data &data, QTextStream &s) const
+{
+ s << toHexLabel(data.part, 2);
+}
+
+} // namespace
+
+//-----------------------------------------------------------------------------
+XML_MAIN(Icd1::XmlToData)