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/pickit2_bootloader | |
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/pickit2_bootloader')
16 files changed, 366 insertions, 0 deletions
diff --git a/src/progs/pickit2_bootloader/Makefile.am b/src/progs/pickit2_bootloader/Makefile.am new file mode 100644 index 0000000..fccf96d --- /dev/null +++ b/src/progs/pickit2_bootloader/Makefile.am @@ -0,0 +1,3 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO +SUBDIRS = xml base gui diff --git a/src/progs/pickit2_bootloader/base/Makefile.am b/src/progs/pickit2_bootloader/base/Makefile.am new file mode 100644 index 0000000..db87222 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_LTLIBRARIES = libpickit2bootloader.la +libpickit2bootloader_la_SOURCES = pickit2_bootloader_data.cpp pickit2_bootloader_prog.cpp pickit2_bootloader.cpp +libpickit2bootloader_la_DEPENDENCIES = pickit2_bootloader_data.cpp + +noinst_DATA = pickit2_bootloader.xml +pickit2_bootloader_data.cpp: ../xml/xml_pickit2_bootloader_parser pickit2_bootloader.xml + ../xml/xml_pickit2_bootloader_parser +CLEANFILES = pickit2_bootloader_data.cpp diff --git a/src/progs/pickit2_bootloader/base/base.pro b/src/progs/pickit2_bootloader/base/base.pro new file mode 100644 index 0000000..9a2fe76 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/base.pro @@ -0,0 +1,6 @@ +STOPDIR = ../../../.. +include($${STOPDIR}/lib.pro) + +TARGET = pickit2_bootloader +HEADERS += pickit2_bootloader.h pickit2_bootloader_prog.h pickit2_bootloader_data.h +SOURCES += pickit2_bootloader.cpp pickit2_bootloader_prog.cpp pickit2_bootloader_data.cpp diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp b/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp new file mode 100644 index 0000000..d080481 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2007 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 "pickit2_bootloader.h" + +//----------------------------------------------------------------------------- +Pickit2Bootloader::Hardware::Hardware(::Programmer::Base &base) + : Bootloader::Hardware(base, new Pickit2::USBPort(base)) +{} + +bool Pickit2Bootloader::Hardware::internalConnectHardware() +{ + if ( !openPort() ) return false; + ::Programmer::Mode mode; + VersionData version; + if ( !port().getMode(version, mode) ) return false; + if ( mode!=::Programmer::BootloadMode ) { + log(Log::LineType::Information, i18n("Trying to enter bootloader mode...")); + if ( !port().resetFirmwareDevice(::Programmer::BootloadMode) ) return false; + for (uint i=0;; i++) { + port().close(); + Port::usleep(500000); // ?? + if ( !openPort() ) continue; + if ( !port().getMode(version, mode) ) continue; + if ( i==4 || mode!=::Programmer::BootloadMode ) { + log(Log::LineType::Error, i18n("Could not detect device in bootloader mode.")); + return false; + } + } + } + log(Log::LineType::Information, i18n("Bootloader version %1 detected.").arg(version.pretty())); + if ( version.majorNum()!=2 ) { + log(Log::LineType::Error, i18n("Only bootloader version 2.x is supported.")); + return false; + } + return true; +} + +bool Pickit2Bootloader::Hardware::write(Pic::MemoryRangeType type, const Device::Array &data) +{ + Q_ASSERT( data.count()==device().nbWords(type) ); + Q_ASSERT( type==Pic::MemoryRangeType::Code ); + // check that there is nothing in bootloader reserved area + for (uint i=0; i<data.count(); i++) { + if ( i>=0x1000 && i<0x3FF0 ) continue; + if ( data[i]==device().mask(Pic::MemoryRangeType::Code) ) continue; + uint address = device().addressIncrement(Pic::MemoryRangeType::Code) * i; + log(Log::LineType::Warning, " " + i18n("Code is present in bootloader reserved area (at address %1). It will be ignored.").arg(toHexLabel(address, device().nbCharsAddress()))); + break; + } + return port().writeFirmwareCodeMemory(data, _base.progressMonitor()); +} + +bool Pickit2Bootloader::Hardware::read(Pic::MemoryRangeType type, Device::Array &data, const ::Programmer::VerifyData *vdata) +{ + Q_ASSERT( type==Pic::MemoryRangeType::Code ); + data.resize(device().nbWords(type)); + Device::Array varray; + if (vdata) varray = static_cast<const Pic::Memory &>(vdata->memory).arrayForWriting(Pic::MemoryRangeType::Code); + return port().readFirmwareCodeMemory(data, vdata ? &varray : 0, _base.progressMonitor()); +} + +//----------------------------------------------------------------------------- +bool Pickit2Bootloader::DeviceSpecific::doEraseRange(Pic::MemoryRangeType type) +{ + Q_ASSERT( type==Pic::MemoryRangeType::Code ); + return static_cast<Hardware &>(hardware()).port().eraseFirmwareCodeMemory(); +} diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader.h new file mode 100644 index 0000000..7af0957 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_H +#define PICKIT2_BOOTLOADER_H + +#include "progs/bootloader/base/bootloader.h" +#include "progs/pickit2/base/pickit2.h" + +namespace Pickit2Bootloader +{ +//----------------------------------------------------------------------------- +class Hardware : public Bootloader::Hardware +{ +public: + Hardware(::Programmer::Base &base); + Pickit2::USBPort &port() { return static_cast<Pickit2::USBPort &>(*_port); } + virtual bool write(Pic::MemoryRangeType type, const Device::Array &data); + virtual bool read(Pic::MemoryRangeType type, Device::Array &data, const ::Programmer::VerifyData *vdata); + virtual bool internalConnectHardware(); +}; + +//----------------------------------------------------------------------------- +class DeviceSpecific : public Bootloader::DeviceSpecific +{ +public: + DeviceSpecific(::Programmer::Base &base) : Bootloader::DeviceSpecific(base) {} + virtual bool canEraseAll() const { return true; } + virtual bool canEraseRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); } + virtual bool canReadRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); } + virtual bool canWriteRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); } + virtual bool doEraseRange(Pic::MemoryRangeType type); + virtual bool doErase(bool) { return doEraseRange(Pic::MemoryRangeType::Code); } +}; + +} // namespace + +#endif diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml b/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml new file mode 100644 index 0000000..2e87949 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml @@ -0,0 +1,16 @@ +<!-- ************************************************************************* --> +<!-- * Copyright (C) 2007 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="pickit2_bootloader"> + <device name="18F2455" family="generic" /> + <device name="18F2550" family="generic" /> + <device name="18F4455" family="generic" /> + <device name="18F4550" family="generic" /> +</type> diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h new file mode 100644 index 0000000..87aead1 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h @@ -0,0 +1,19 @@ +/*************************************************************************** + * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_DATA_H +#define PICKIT2_BOOTLOADER_DATA_H + +namespace Pickit2Bootloader +{ + struct Data {}; + extern bool isSupported(const QString &device); + extern const Data &data(const QString &device); +} // namespace + +#endif diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp new file mode 100644 index 0000000..7f734ba --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp @@ -0,0 +1,14 @@ +/*************************************************************************** + * Copyright (C) 2007 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 "pickit2_bootloader_prog.h" + +//----------------------------------------------------------------------------- +Pickit2Bootloader::ProgrammerBase::ProgrammerBase(const Programmer::Group &group, const Pic::Data *data) + : Bootloader::ProgrammerBase(group, data, "pickit2_bootloader_programmer_base") +{} diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h new file mode 100644 index 0000000..461d734 --- /dev/null +++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_PROG_H +#define PICKIT2_BOOTLOADER_PROG_H + +#include "progs/bootloader/base/bootloader_prog.h" +#include "pickit2_bootloader.h" + +namespace Pickit2Bootloader +{ + +//----------------------------------------------------------------------------- +class ProgrammerBase : public ::Bootloader::ProgrammerBase +{ +Q_OBJECT +public: + ProgrammerBase(const Programmer::Group &group, const Pic::Data *data); + virtual bool verifyDeviceId() { return true; } +}; + +//----------------------------------------------------------------------------- +class Group : public ::Bootloader::Group +{ +public: + virtual QString name() const { return "pickit2_bootloader"; } + virtual QString label() const { return i18n("Pickit2 Bootloader"); } + virtual ::Programmer::Properties properties() const { return ::Programmer::Programmer | ::Programmer::CanReadMemory; } + virtual ::Programmer::TargetPowerMode targetPowerMode() const { return ::Programmer::TargetSelfPowered; } + virtual bool isPortSupported(PortType type) const { return type==PortType::USB; } + virtual bool canReadVoltage(Pic::VoltageType) const { return false; } + +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 &) const { return new Hardware(base); } + virtual ::Programmer::DeviceSpecific *createDeviceSpecific(::Programmer::Base &base) const { return new DeviceSpecific(base); } +}; + +} // namespace + +#endif diff --git a/src/progs/pickit2_bootloader/gui/Makefile.am b/src/progs/pickit2_bootloader/gui/Makefile.am new file mode 100644 index 0000000..b9be2b0 --- /dev/null +++ b/src/progs/pickit2_bootloader/gui/Makefile.am @@ -0,0 +1,6 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_LTLIBRARIES = libpickit2bootloaderui.la +libpickit2bootloaderui_la_LDFLAGS = $(all_libraries) +libpickit2bootloaderui_la_SOURCES = pickit2_bootloader_ui.cpp diff --git a/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.cpp b/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.cpp new file mode 100644 index 0000000..89bf5c7 --- /dev/null +++ b/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.cpp @@ -0,0 +1,20 @@ +/*************************************************************************** + * Copyright (C) 2007 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 "pickit2_bootloader_ui.h" + +//----------------------------------------------------------------------------- +Pickit2Bootloader::ConfigWidget::ConfigWidget(const::Programmer::Group &group, QWidget *parent) + : ::Programmer::ConfigWidget(group, parent) +{} + +//----------------------------------------------------------------------------- +::Programmer::ConfigWidget *Pickit2Bootloader::GroupUI::createConfigWidget(QWidget *parent) const +{ + return new ConfigWidget(static_cast<const ::Programmer::Group &>(group()), parent); +} diff --git a/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.h b/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.h new file mode 100644 index 0000000..d715574 --- /dev/null +++ b/src/progs/pickit2_bootloader/gui/pickit2_bootloader_ui.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_UI_H +#define PICKIT2_BOOTLOADER_UI_H + +#include "progs/bootloader/gui/bootloader_ui.h" + +//----------------------------------------------------------------------------- +namespace Pickit2Bootloader +{ +class ConfigWidget: public ::Programmer::ConfigWidget +{ +Q_OBJECT +public: + ConfigWidget(const::Programmer::Group &group, QWidget *parent); + virtual void loadConfig() {} + virtual void saveConfig() {} +}; + + +//---------------------------------------------------------------------------- +class GroupUI : public ::Bootloader::GroupUI +{ +public: + virtual ::Programmer::ConfigWidget *createConfigWidget(QWidget *parent) const; +}; + +} // namespace + +#endif diff --git a/src/progs/pickit2_bootloader/pickit2_bootloader.pro b/src/progs/pickit2_bootloader/pickit2_bootloader.pro new file mode 100644 index 0000000..60ac0f5 --- /dev/null +++ b/src/progs/pickit2_bootloader/pickit2_bootloader.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = xml base diff --git a/src/progs/pickit2_bootloader/xml/Makefile.am b/src/progs/pickit2_bootloader/xml/Makefile.am new file mode 100644 index 0000000..899aa3b --- /dev/null +++ b/src/progs/pickit2_bootloader/xml/Makefile.am @@ -0,0 +1,14 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_PROGRAMS = xml_pickit2_bootloader_parser +xml_pickit2_bootloader_parser_SOURCES = xml_pickit2_bootloader_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_pickit2_bootloader_parser_DEPENDENCIES = $(OBJECTS) +xml_pickit2_bootloader_parser_LDADD = $(OBJECTS) $(LIB_KDECORE) diff --git a/src/progs/pickit2_bootloader/xml/xml.pro b/src/progs/pickit2_bootloader/xml/xml.pro new file mode 100644 index 0000000..2e2aef1 --- /dev/null +++ b/src/progs/pickit2_bootloader/xml/xml.pro @@ -0,0 +1,17 @@ +STOPDIR = ../../../.. +include($${STOPDIR}/app.pro) + +TARGET = xml_pickit2_bootloader_parser +SOURCES += xml_pickit2_bootloader_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_pickit2_bootloader_parser +unix:QMAKE_CLEAN += ../base/pickit2_bootloader_data.cpp +win32:QMAKE_POST_LINK = cd ..\base && ..\xml\xml_pickit2_bootloader_parser.exe +win32:QMAKE_CLEAN += ..\base\pickit2_bootloader_data.cpp diff --git a/src/progs/pickit2_bootloader/xml/xml_pickit2_bootloader_parser.cpp b/src/progs/pickit2_bootloader/xml/xml_pickit2_bootloader_parser.cpp new file mode 100644 index 0000000..150e814 --- /dev/null +++ b/src/progs/pickit2_bootloader/xml/xml_pickit2_bootloader_parser.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2007 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/pickit2_bootloader/base/pickit2_bootloader_data.h" +#include "devices/base/device_group.h" +#include "devices/pic/base/pic.h" + +//----------------------------------------------------------------------------- +namespace Pickit2Bootloader +{ + +class XmlToData : public Programmer::XmlToData<Data> +{ +public: + XmlToData() : Programmer::XmlToData<Data>("pickit2_bootloader", "Pickit2Bootloader") {} + +private: + virtual void parseData(QDomElement element, Data &data); +}; + +void Pickit2Bootloader::XmlToData::parseData(QDomElement, Data &) +{ + const Device::Data *ddata = Device::lister().data(currentDevice()); + if ( ddata->group().name()!="pic" ) qFatal("non-pic device not supported"); + const Pic::Data *pdata = static_cast<const Pic::Data *>(ddata); + if ( !pdata->hasFeature(Pic::Feature::USB) ) qFatal("device does not have USB"); +} + +} // namespace + +//----------------------------------------------------------------------------- +XML_MAIN(Pickit2Bootloader::XmlToData) |