mirror of
https://github.com/steve-chamberlin/mac-rom-simm-programmer.software.git
synced 2025-01-21 17:32:09 +00:00
Added better error checking to the ROM SIMM flasher for when the
programmer board is unplugged. The UI seems a lot cleaner now too. Removed dead code. Moved to a more consistent function naming style.
This commit is contained in:
parent
4d38eb6d3e
commit
0dfe69cbf8
@ -12,11 +12,9 @@ TEMPLATE = app
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
usbprogrammerfinder_win.cpp \
|
||||
programmer.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
usbprogrammerfinder.h \
|
||||
programmer.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
@ -12,6 +12,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->pages->setCurrentWidget(ui->notConnectedPage);
|
||||
ui->actionUpdate_firmware->setEnabled(false);
|
||||
p = new Programmer();
|
||||
ui->chosenWriteFile->setText("");
|
||||
ui->chosenReadFile->setText("");
|
||||
@ -36,6 +38,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(p, SIGNAL(firmwareFlashStatusChanged(FirmwareFlashStatus)), SLOT(programmerFirmwareFlashStatusChanged(FirmwareFlashStatus)));
|
||||
connect(p, SIGNAL(firmwareFlashTotalLengthChanged(uint32_t)), SLOT(programmerFirmwareFlashTotalLengthChanged(uint32_t)));
|
||||
connect(p, SIGNAL(firmwareFlashCompletionLengthChanged(uint32_t)), SLOT(programmerFirmwareFlashCompletionLengthChanged(uint32_t)));
|
||||
connect(p, SIGNAL(programmerBoardConnected()), SLOT(programmerBoardConnected()));
|
||||
connect(p, SIGNAL(programmerBoardDisconnected()), SLOT(programmerBoardDisconnected()));
|
||||
connect(p, SIGNAL(programmerBoardDisconnectedDuringOperation()), SLOT(programmerBoardDisconnectedDuringOperation()));
|
||||
p->startCheckingPorts();
|
||||
|
||||
/*QList<QextPortInfo> l = QextSerialEnumerator::getPorts();
|
||||
foreach (QextPortInfo p, l)
|
||||
@ -65,11 +71,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
QextSerialEnumerator *p = new QextSerialEnumerator();
|
||||
connect(p, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(portDiscovered(QextPortInfo)));
|
||||
connect(p, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(portRemoved(QextPortInfo)));
|
||||
p->setUpNotifications();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -103,14 +104,14 @@ void MainWindow::on_selectReadFileButton_clicked()
|
||||
void MainWindow::on_readFromSIMMButton_clicked()
|
||||
{
|
||||
resetAndShowStatusPage();
|
||||
p->ReadSIMMToFile(ui->chosenReadFile->text());
|
||||
p->readSIMMToFile(ui->chosenReadFile->text());
|
||||
qDebug() << "Reading from SIMM...";
|
||||
}
|
||||
|
||||
void MainWindow::on_writeToSIMMButton_clicked()
|
||||
{
|
||||
resetAndShowStatusPage();
|
||||
p->WriteFileToSIMM(ui->chosenWriteFile->text());
|
||||
p->writeFileToSIMM(ui->chosenWriteFile->text());
|
||||
qDebug() << "Writing to SIMM...";
|
||||
}
|
||||
|
||||
@ -134,7 +135,7 @@ void MainWindow::programmerWriteStatusChanged(WriteStatus newStatus)
|
||||
switch (newStatus)
|
||||
{
|
||||
case WriteErasing:
|
||||
ui->statusLabel->setText("Erasing SIMM...");
|
||||
ui->statusLabel->setText("Erasing SIMM (this may take a few seconds)...");
|
||||
break;
|
||||
case WriteComplete:
|
||||
ui->pages->setCurrentWidget(ui->controlPage);
|
||||
@ -178,7 +179,7 @@ void MainWindow::on_electricalTestButton_clicked()
|
||||
{
|
||||
resetAndShowStatusPage();
|
||||
electricalTestString = "";
|
||||
p->RunElectricalTest();
|
||||
p->runElectricalTest();
|
||||
}
|
||||
|
||||
void MainWindow::programmerElectricalTestStatusChanged(ElectricalTestStatus newStatus)
|
||||
@ -186,7 +187,7 @@ void MainWindow::programmerElectricalTestStatusChanged(ElectricalTestStatus newS
|
||||
switch (newStatus)
|
||||
{
|
||||
case ElectricalTestStarted:
|
||||
ui->statusLabel->setText("Running electrical test...");
|
||||
ui->statusLabel->setText("Running electrical test (this may take a few seconds)...");
|
||||
qDebug() << "Electrical test started";
|
||||
break;
|
||||
case ElectricalTestPassed:
|
||||
@ -273,7 +274,7 @@ void MainWindow::programmerIdentifyStatusChanged(IdentificationStatus newStatus)
|
||||
QString thisString;
|
||||
uint8_t manufacturer = 0;
|
||||
uint8_t device = 0;
|
||||
p->GetChipIdentity(x, &manufacturer, &device);
|
||||
p->getChipIdentity(x, &manufacturer, &device);
|
||||
thisString.sprintf("\nIC%d: Manufacturer 0x%02X, Device 0x%02X", (x + 1), manufacturer, device);
|
||||
identifyString.append(thisString);
|
||||
}
|
||||
@ -328,29 +329,6 @@ void MainWindow::programmerFirmwareFlashCompletionLengthChanged(uint32_t len)
|
||||
ui->progressBar->setValue((int)len);
|
||||
}
|
||||
|
||||
void MainWindow::startOperation_updateButtons()
|
||||
{
|
||||
ui->writeToSIMMButton->setEnabled(false);
|
||||
ui->readFromSIMMButton->setEnabled(false);
|
||||
ui->identifyButton->setEnabled(false);
|
||||
ui->electricalTestButton->setEnabled(false);
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressBar->setEnabled(true);
|
||||
ui->cancelButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::endOperation_updateButtons()
|
||||
{
|
||||
ui->writeToSIMMButton->setEnabled(writeFileValid);
|
||||
ui->readFromSIMMButton->setEnabled(readFileValid);
|
||||
|
||||
ui->identifyButton->setEnabled(true);
|
||||
ui->electricalTestButton->setEnabled(true);
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressBar->setEnabled(false);
|
||||
ui->cancelButton->setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionUpdate_firmware_triggered()
|
||||
{
|
||||
@ -358,7 +336,7 @@ void MainWindow::on_actionUpdate_firmware_triggered()
|
||||
if (!filename.isNull())
|
||||
{
|
||||
resetAndShowStatusPage();
|
||||
p->FlashFirmware(filename);
|
||||
p->flashFirmware(filename);
|
||||
qDebug() << "Updating firmware...";
|
||||
}
|
||||
}
|
||||
@ -366,46 +344,31 @@ void MainWindow::on_actionUpdate_firmware_triggered()
|
||||
void MainWindow::on_identifyButton_clicked()
|
||||
{
|
||||
resetAndShowStatusPage();
|
||||
p->IdentifySIMMChips();
|
||||
p->identifySIMMChips();
|
||||
}
|
||||
|
||||
void MainWindow::portDiscovered(const QextPortInfo &info)
|
||||
void MainWindow::programmerBoardConnected()
|
||||
{
|
||||
qDebug() << info.portName << "discovered";
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
if (info.portName.startsWith("COM"))
|
||||
#endif
|
||||
{
|
||||
// TODO: Do checking for valid USB ID?
|
||||
|
||||
if ((info.vendorID == 0x03EB) && (info.productID == 0x204B))
|
||||
{
|
||||
ui->portList->addItem(QString("%1 (Programmer)").arg(info.portName), QVariant(info.portName));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->portList->addItem(info.portName, QVariant(info.portName));
|
||||
}
|
||||
}
|
||||
ui->pages->setCurrentWidget(ui->controlPage);
|
||||
ui->actionUpdate_firmware->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::portRemoved(const QextPortInfo &info)
|
||||
void MainWindow::programmerBoardDisconnected()
|
||||
{
|
||||
qDebug() << info.portName << "removed";
|
||||
ui->pages->setCurrentWidget(ui->notConnectedPage);
|
||||
ui->actionUpdate_firmware->setEnabled(false);
|
||||
}
|
||||
|
||||
for (int x = ui->portList->count() - 1; x >= 0; x--)
|
||||
{
|
||||
if (ui->portList->itemData(x) == info.portName)
|
||||
{
|
||||
ui->portList->removeItem(x);
|
||||
}
|
||||
}
|
||||
void MainWindow::programmerBoardDisconnectedDuringOperation()
|
||||
{
|
||||
ui->pages->setCurrentWidget(ui->notConnectedPage);
|
||||
ui->actionUpdate_firmware->setEnabled(false);
|
||||
QMessageBox::warning(this, "Programmer lost connection", "Lost contact with the programmer board. Unplug it, plug it back in, and try again.");
|
||||
}
|
||||
|
||||
void MainWindow::resetAndShowStatusPage()
|
||||
{
|
||||
ui->progressBar->setValue(0);
|
||||
ui->statusLabel->setText("Communicating with programmer...");
|
||||
ui->statusLabel->setText("Communicating with programmer (this may take a few seconds)...");
|
||||
ui->pages->setCurrentWidget(ui->statusPage);
|
||||
}
|
||||
|
11
mainwindow.h
11
mainwindow.h
@ -2,7 +2,7 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qextserialenumerator.h>
|
||||
//#include <qextserialenumerator.h>
|
||||
#include "programmer.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -45,15 +45,14 @@ private slots:
|
||||
|
||||
void on_electricalTestButton_clicked();
|
||||
|
||||
void startOperation_updateButtons();
|
||||
void endOperation_updateButtons();
|
||||
|
||||
void on_actionUpdate_firmware_triggered();
|
||||
|
||||
void on_identifyButton_clicked();
|
||||
|
||||
void portDiscovered(const QextPortInfo &info);
|
||||
void portRemoved(const QextPortInfo &info);
|
||||
// Handlers for when the programmer board has been connected or disconnected
|
||||
void programmerBoardConnected();
|
||||
void programmerBoardDisconnected();
|
||||
void programmerBoardDisconnectedDuringOperation();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
<string>SIMM Programmer</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -28,36 +28,6 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="controlPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="portLabel">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="portList"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="writeGroupBox">
|
||||
<property name="title">
|
||||
@ -259,6 +229,20 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="notConnectedPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Please connect the SIMM programmer board to your computer in order to use this software.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
210
programmer.cpp
210
programmer.cpp
@ -25,6 +25,10 @@ typedef enum ProgrammerCommandState
|
||||
BootloaderStateAwaitingReply,
|
||||
BootloaderStateAwaitingOKReplyToBootloader,
|
||||
BootloaderStateAwaitingReplyToBootloader,
|
||||
BootloaderStateAwaitingUnplug,
|
||||
BootloaderStateAwaitingPlug,
|
||||
BootloaderStateAwaitingUnplugToBootloader,
|
||||
BootloaderStateAwaitingPlugToBootloader,
|
||||
|
||||
IdentificationAwaitingOKReply,
|
||||
IdentificationWaitingData,
|
||||
@ -36,6 +40,12 @@ typedef enum ProgrammerCommandState
|
||||
BootloaderEraseProgramWaitingWriteReply
|
||||
} ProgrammerCommandState;
|
||||
|
||||
typedef enum ProgrammerBoardFoundState
|
||||
{
|
||||
ProgrammerBoardNotFound,
|
||||
ProgrammerBoardFound
|
||||
} ProgrammerBoardFoundState;
|
||||
|
||||
typedef enum ProgrammerCommand
|
||||
{
|
||||
EnterWaitingMode = 0,
|
||||
@ -118,8 +128,8 @@ typedef enum ComputerBootloaderEraseWriteRequest
|
||||
ComputerBootloaderCancel
|
||||
} ComputerBootloaderEraseWriteRequest;
|
||||
|
||||
|
||||
|
||||
#define PROGRAMMER_USB_VENDOR_ID 0x03EB
|
||||
#define PROGRAMMER_USB_DEVICE_ID 0x204B
|
||||
|
||||
|
||||
#define WRITE_CHUNK_SIZE 1024
|
||||
@ -133,23 +143,23 @@ static ProgrammerCommandState curState = WaitingForNextCommand;
|
||||
static ProgrammerCommandState nextState = WaitingForNextCommand;
|
||||
static uint8_t nextSendByte = 0;
|
||||
|
||||
static ProgrammerBoardFoundState foundState = ProgrammerBoardNotFound;
|
||||
static QString programmerBoardPortName;
|
||||
|
||||
Programmer::Programmer(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
serialPort = new QextSerialPort("\\\\.\\COM13", QextSerialPort::EventDriven);
|
||||
serialPort = new QextSerialPort(QextSerialPort::EventDriven);
|
||||
connect(serialPort, SIGNAL(readyRead()), SLOT(dataReady()));
|
||||
}
|
||||
|
||||
Programmer::~Programmer()
|
||||
{
|
||||
if (serialPort->isOpen())
|
||||
{
|
||||
serialPort->close();
|
||||
}
|
||||
closePort();
|
||||
delete serialPort;
|
||||
}
|
||||
|
||||
void Programmer::ReadSIMMToFile(QString filename)
|
||||
void Programmer::readSIMMToFile(QString filename)
|
||||
{
|
||||
readFile = new QFile(filename);
|
||||
readFile->open(QFile::WriteOnly);
|
||||
@ -161,7 +171,7 @@ void Programmer::ReadSIMMToFile(QString filename)
|
||||
startProgrammerCommand(ReadChips, ReadSIMMWaitingStartReply);
|
||||
}
|
||||
|
||||
void Programmer::WriteFileToSIMM(QString filename)
|
||||
void Programmer::writeFileToSIMM(QString filename)
|
||||
{
|
||||
writeFile = new QFile(filename);
|
||||
if (!writeFile->open(QFile::ReadOnly))
|
||||
@ -221,7 +231,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
writeFile->close();
|
||||
curState = WaitingForNextCommand;
|
||||
emit writeStatusChanged(WriteEraseFailed);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -249,7 +259,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
writeFile->close();
|
||||
curState = WaitingForNextCommand;
|
||||
emit writeStatusChanged(WriteError);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -296,7 +306,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
writeFile->close();
|
||||
curState = WaitingForNextCommand;
|
||||
emit writeStatusChanged(WriteError);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -309,7 +319,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
curState = WaitingForNextCommand;
|
||||
qDebug() << "Write success at end";
|
||||
emit writeStatusChanged(WriteComplete);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
case ProgrammerWriteError:
|
||||
default:
|
||||
@ -317,7 +327,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
curState = WaitingForNextCommand;
|
||||
writeFile->close();
|
||||
emit writeStatusChanged(WriteError);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -338,7 +348,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
default:
|
||||
curState = WaitingForNextCommand;
|
||||
emit electricalTestStatusChanged(ElectricalTestCouldntStart);
|
||||
serialPort->close();
|
||||
closePort();
|
||||
}
|
||||
break;
|
||||
case ElectricalTestWaitingNextStatus:
|
||||
@ -354,7 +364,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
emit electricalTestStatusChanged(ElectricalTestPassed);
|
||||
}
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
break;
|
||||
case ProgrammerElectricalTestFail:
|
||||
electricalTestErrorCounter++;
|
||||
@ -393,13 +403,13 @@ void Programmer::handleChar(uint8_t c)
|
||||
{
|
||||
case ProgrammerReadFinished:
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
readFile->close();
|
||||
emit readStatusChanged(ReadComplete);
|
||||
break;
|
||||
case ProgrammerReadConfirmCancel:
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
readFile->close();
|
||||
emit readStatusChanged(ReadCancelled);
|
||||
break;
|
||||
@ -439,24 +449,10 @@ void Programmer::handleChar(uint8_t c)
|
||||
qDebug() << "We're in the bootloader, so sending an \"enter programmer\" request.";
|
||||
emit startStatusChanged(ProgrammerInitializing);
|
||||
sendByte(EnterProgrammer);
|
||||
serialPort->close();
|
||||
{
|
||||
QMutex mutex;
|
||||
mutex.lock();
|
||||
closePort();
|
||||
|
||||
QWaitCondition waitCondition;
|
||||
waitCondition.wait(&mutex, 5000);
|
||||
mutex.unlock();
|
||||
}
|
||||
serialPort->open(QextSerialPort::ReadWrite);
|
||||
curState = nextState;
|
||||
sendByte(nextSendByte);
|
||||
// Special case: Send out notification we are starting an erase command.
|
||||
// I don't have any hooks into the process between now and the erase reply.
|
||||
if (nextSendByte == EraseChips)
|
||||
{
|
||||
emit writeStatusChanged(WriteErasing);
|
||||
}
|
||||
// Now wait for it to reconnect
|
||||
curState = BootloaderStateAwaitingUnplug;
|
||||
break;
|
||||
case BootloaderStateInProgrammer:
|
||||
// Good to go...
|
||||
@ -504,18 +500,10 @@ void Programmer::handleChar(uint8_t c)
|
||||
qDebug() << "We're in the programmer, so sending an \"enter bootloader\" request.";
|
||||
emit startStatusChanged(ProgrammerInitializing);
|
||||
sendByte(EnterBootloader);
|
||||
serialPort->close();
|
||||
{
|
||||
QMutex mutex;
|
||||
mutex.lock();
|
||||
closePort();
|
||||
|
||||
QWaitCondition waitCondition;
|
||||
waitCondition.wait(&mutex, 5000);
|
||||
mutex.unlock();
|
||||
}
|
||||
serialPort->open(QextSerialPort::ReadWrite);
|
||||
curState = nextState;
|
||||
sendByte(nextSendByte);
|
||||
// Now wait for it to reconnect
|
||||
curState = BootloaderStateAwaitingUnplugToBootloader;
|
||||
break;
|
||||
case BootloaderStateInBootloader:
|
||||
// Good to go...
|
||||
@ -585,7 +573,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
{
|
||||
emit firmwareFlashStatusChanged(FirmwareFlashError);
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
firmwareFile->close();
|
||||
}
|
||||
break;
|
||||
@ -594,14 +582,14 @@ void Programmer::handleChar(uint8_t c)
|
||||
{
|
||||
emit firmwareFlashStatusChanged(FirmwareFlashComplete);
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
firmwareFile->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit firmwareFlashStatusChanged(FirmwareFlashError);
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
firmwareFile->close();
|
||||
}
|
||||
break;
|
||||
@ -640,7 +628,7 @@ void Programmer::handleChar(uint8_t c)
|
||||
{
|
||||
emit firmwareFlashStatusChanged(FirmwareFlashError);
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
firmwareFile->close();
|
||||
}
|
||||
break;
|
||||
@ -663,14 +651,21 @@ void Programmer::handleChar(uint8_t c)
|
||||
{
|
||||
emit firmwareFlashStatusChanged(FirmwareFlashError);
|
||||
curState = WaitingForNextCommand;
|
||||
serialPort->close();
|
||||
closePort();
|
||||
firmwareFile->close();
|
||||
}
|
||||
break;
|
||||
|
||||
// UNUSED STATE HANDLERS (They are handled elsewhere)
|
||||
case BootloaderStateAwaitingPlug:
|
||||
case BootloaderStateAwaitingUnplug:
|
||||
case BootloaderStateAwaitingPlugToBootloader:
|
||||
case BootloaderStateAwaitingUnplugToBootloader:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Programmer::RunElectricalTest()
|
||||
void Programmer::runElectricalTest()
|
||||
{
|
||||
startProgrammerCommand(DoElectricalTest, ElectricalTestWaitingStartReply);
|
||||
}
|
||||
@ -727,12 +722,12 @@ QString Programmer::electricalTestPinName(uint8_t index)
|
||||
}
|
||||
}
|
||||
|
||||
void Programmer::IdentifySIMMChips()
|
||||
void Programmer::identifySIMMChips()
|
||||
{
|
||||
startProgrammerCommand(IdentifyChips, IdentificationAwaitingOKReply);
|
||||
}
|
||||
|
||||
void Programmer::GetChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *device)
|
||||
void Programmer::getChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *device)
|
||||
{
|
||||
if ((chipIndex >= 0) && (chipIndex < 4))
|
||||
{
|
||||
@ -746,7 +741,7 @@ void Programmer::GetChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *
|
||||
}
|
||||
}
|
||||
|
||||
void Programmer::FlashFirmware(QString filename)
|
||||
void Programmer::flashFirmware(QString filename)
|
||||
{
|
||||
firmwareFile = new QFile(filename);
|
||||
if (!firmwareFile->open(QFile::ReadOnly))
|
||||
@ -775,7 +770,7 @@ void Programmer::startProgrammerCommand(uint8_t commandByte, uint32_t newState)
|
||||
nextSendByte = commandByte;
|
||||
|
||||
curState = BootloaderStateAwaitingOKReply;
|
||||
serialPort->open(QextSerialPort::ReadWrite);
|
||||
openPort();
|
||||
sendByte(GetBootloaderState);
|
||||
}
|
||||
|
||||
@ -790,6 +785,107 @@ void Programmer::startBootloaderCommand(uint8_t commandByte, uint32_t newState)
|
||||
nextSendByte = commandByte;
|
||||
|
||||
curState = BootloaderStateAwaitingOKReplyToBootloader;
|
||||
serialPort->open(QextSerialPort::ReadWrite);
|
||||
openPort();
|
||||
sendByte(GetBootloaderState);
|
||||
}
|
||||
|
||||
|
||||
void Programmer::portDiscovered(const QextPortInfo &info)
|
||||
{
|
||||
if ((foundState == ProgrammerBoardNotFound) &&
|
||||
(info.vendorID == PROGRAMMER_USB_VENDOR_ID) &&
|
||||
(info.productID == PROGRAMMER_USB_DEVICE_ID))
|
||||
{
|
||||
#ifdef Q_WS_WIN
|
||||
programmerBoardPortName = "\\\\.\\" + info.portName;
|
||||
#else
|
||||
programmerBoardPortName = info.portName;
|
||||
#endif
|
||||
foundState = ProgrammerBoardFound;
|
||||
|
||||
closePort();
|
||||
serialPort->setPortName(programmerBoardPortName);
|
||||
|
||||
// Don't show the "control" screen if we intentionally
|
||||
// reconnected the USB port because we are changing from bootloader
|
||||
// to programmer mode or vice-versa.
|
||||
if (curState == BootloaderStateAwaitingPlug)
|
||||
{
|
||||
openPort();
|
||||
curState = nextState;
|
||||
sendByte(nextSendByte);
|
||||
// Special case: Send out notification we are starting an erase command.
|
||||
// I don't have any hooks into the process between now and the erase reply.
|
||||
if (nextSendByte == EraseChips)
|
||||
{
|
||||
emit writeStatusChanged(WriteErasing);
|
||||
}
|
||||
}
|
||||
else if (curState == BootloaderStateAwaitingPlugToBootloader)
|
||||
{
|
||||
openPort();
|
||||
curState = nextState;
|
||||
sendByte(nextSendByte);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit programmerBoardConnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Programmer::portRemoved(const QextPortInfo &info)
|
||||
{
|
||||
if ((info.vendorID == PROGRAMMER_USB_VENDOR_ID) &&
|
||||
(info.productID == PROGRAMMER_USB_DEVICE_ID))
|
||||
{
|
||||
programmerBoardPortName = "";
|
||||
foundState = ProgrammerBoardNotFound;
|
||||
|
||||
// Don't show the "no programmer connected" screen if we intentionally
|
||||
// disconnected the USB port because we are changing from bootloader
|
||||
// to programmer mode or vice-versa.
|
||||
if (curState == BootloaderStateAwaitingUnplug)
|
||||
{
|
||||
curState = BootloaderStateAwaitingPlug;
|
||||
}
|
||||
else if (curState == BootloaderStateAwaitingUnplugToBootloader)
|
||||
{
|
||||
curState = BootloaderStateAwaitingPlugToBootloader;
|
||||
}
|
||||
else
|
||||
{
|
||||
closePort();
|
||||
|
||||
if (curState != WaitingForNextCommand)
|
||||
{
|
||||
// This means they unplugged while we were in the middle
|
||||
// of an operation. Reset state, and let them know.
|
||||
curState = WaitingForNextCommand;
|
||||
emit programmerBoardDisconnectedDuringOperation();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit programmerBoardDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Programmer::startCheckingPorts()
|
||||
{
|
||||
QextSerialEnumerator *p = new QextSerialEnumerator();
|
||||
connect(p, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(portDiscovered(QextPortInfo)));
|
||||
connect(p, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(portRemoved(QextPortInfo)));
|
||||
p->setUpNotifications();
|
||||
}
|
||||
|
||||
void Programmer::openPort()
|
||||
{
|
||||
serialPort->open(QextSerialPort::ReadWrite);
|
||||
}
|
||||
|
||||
void Programmer::closePort()
|
||||
{
|
||||
serialPort->close();
|
||||
}
|
||||
|
24
programmer.h
24
programmer.h
@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <qextserialport.h>
|
||||
#include <qextserialenumerator.h>
|
||||
|
||||
typedef enum StartStatus
|
||||
{
|
||||
@ -74,13 +75,14 @@ class Programmer : public QObject
|
||||
public:
|
||||
explicit Programmer(QObject *parent = 0);
|
||||
virtual ~Programmer();
|
||||
void ReadSIMMToFile(QString filename);
|
||||
void WriteFileToSIMM(QString filename);
|
||||
void RunElectricalTest();
|
||||
void readSIMMToFile(QString filename);
|
||||
void writeFileToSIMM(QString filename);
|
||||
void runElectricalTest();
|
||||
QString electricalTestPinName(uint8_t index);
|
||||
void IdentifySIMMChips();
|
||||
void GetChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *device);
|
||||
void FlashFirmware(QString filename);
|
||||
void identifySIMMChips();
|
||||
void getChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *device);
|
||||
void flashFirmware(QString filename);
|
||||
void startCheckingPorts();
|
||||
signals:
|
||||
void startStatusChanged(StartStatus status);
|
||||
|
||||
@ -100,6 +102,10 @@ signals:
|
||||
void firmwareFlashStatusChanged(FirmwareFlashStatus status);
|
||||
void firmwareFlashTotalLengthChanged(uint32_t total);
|
||||
void firmwareFlashCompletionLengthChanged(uint32_t total);
|
||||
|
||||
void programmerBoardConnected();
|
||||
void programmerBoardDisconnected();
|
||||
void programmerBoardDisconnectedDuringOperation();
|
||||
public slots:
|
||||
|
||||
private:
|
||||
@ -127,11 +133,17 @@ private:
|
||||
uint32_t firmwareLenRemaining;
|
||||
uint32_t firmwareLenWritten;
|
||||
|
||||
void openPort();
|
||||
void closePort();
|
||||
|
||||
void startProgrammerCommand(uint8_t commandByte, uint32_t newState);
|
||||
void startBootloaderCommand(uint8_t commandByte, uint32_t newState);
|
||||
|
||||
private slots:
|
||||
void dataReady();
|
||||
|
||||
void portDiscovered(const QextPortInfo &info);
|
||||
void portRemoved(const QextPortInfo &info);
|
||||
};
|
||||
|
||||
#endif // PROGRAMMER_H
|
||||
|
@ -1,21 +0,0 @@
|
||||
#ifndef USBPROGRAMMERFINDER_H
|
||||
#define USBPROGRAMMERFINDER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#define USB_PROGRAMMER_VID 0x03EB
|
||||
#define USB_PROGRAMMER_PID 0x204B
|
||||
|
||||
class USBProgrammerFinder : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit USBProgrammerFinder(QObject *parent = 0);
|
||||
QString getSerialPortName();
|
||||
signals:
|
||||
void programmerPresenceChanged(bool);
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // USBPROGRAMMERFINDER_H
|
@ -1,32 +0,0 @@
|
||||
//#ifdef Q_WS_WIN
|
||||
|
||||
#include "usbprogrammerfinder.h"
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
//#include <tchar.h>
|
||||
|
||||
USBProgrammerFinder::USBProgrammerFinder(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString USBProgrammerFinder::getSerialPortName()
|
||||
{
|
||||
/*//GUID_
|
||||
HDEVINFO result = SetupDiGetClassDevs(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
|
||||
|
||||
if (result != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
return QString();*/
|
||||
|
||||
return "COM13";
|
||||
}
|
||||
|
||||
//#endif
|
Loading…
x
Reference in New Issue
Block a user