Skip to content

Commit

Permalink
Add new software features
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonsmartins committed Dec 13, 2023
1 parent 530b76f commit ab5ca6c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 52 deletions.
6 changes: 6 additions & 0 deletions software/usbflashprog/backend/devices/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

Device::Device(QObject *parent)
: QObject(parent),
canceling_(false),
size_(0),
twp_(1),
twc_(1),
Expand Down Expand Up @@ -127,6 +128,11 @@ uint16_t Device::getSectorSize() const { return sectorSize_; }

TDeviceInformation Device::getInfo() const { return info_; }

void Device::cancel() {
if (canceling_) return;
canceling_ = true;
}

bool Device::getId(TDeviceID &result) {
(void)result;
return false;
Expand Down
9 changes: 6 additions & 3 deletions software/usbflashprog/backend/devices/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Device : public QObject {

virtual TDeviceInformation getInfo() const;

virtual void cancel();

virtual bool getId(TDeviceID &result);
virtual bool read(QByteArray &buffer);
virtual bool program(const QByteArray &buffer, bool verify = false);
Expand All @@ -124,11 +126,12 @@ class Device : public QObject {
virtual bool unprotect();

Q_SIGNALS:
void onProgress(uint32_t current, uint32_t total, float percent,
bool done = false);
void onFinish(uint32_t address, bool success = true);
void onProgress(uint32_t current = 0, uint32_t total = 0,
float percent = 0.0f, bool done = false,
bool success = true, bool canceled = false);

protected:
bool canceling_;
uint32_t size_;
uint32_t twp_;
uint32_t twc_;
Expand Down
71 changes: 41 additions & 30 deletions software/usbflashprog/backend/devices/parallel/dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ Dummy::Dummy(QObject *parent) : Device(parent), protected_(true) {
info_.capability.hasSectorSize = true;
info_.capability.hasFastProg = true;
info_.capability.hasSkipFF = true;
info_.voltage.vddProgram = 5.0f;
info_.voltage.vppProgram = 12.0f;
info_.voltage.vddRead = 5.0f;
info_.voltage.vppRead = 0.0f;
info_.voltage.vddErase = 5.0f;
info_.voltage.vppErase = 12.0f;
info_.voltage.vddGetId = 5.0f;
info_.voltage.vppGetId = 12.0f;
info_.voltage.vddUnprotect = 5.0f;
info_.voltage.vppUnprotect = 12.0f;
twp_ = 2;
twc_ = 4;
twp_ = 20000;
twc_ = 40000;
size_ = 2048;
buffer_.resize(size_);
}
Expand All @@ -56,102 +46,123 @@ void Dummy::setSize(uint32_t value) {
}

bool Dummy::getId(TDeviceID &result) {
canceling_ = false;
result.manufacturer = 0x01;
result.device = 0x01;
emit onProgress(1, 1, 100.0f, true);
emit onFinish(0);
emit onProgress(100, 100, 100.0f, true);
return true;
}

bool Dummy::read(QByteArray &buffer) {
canceling_ = false;
int end = buffer_.size();
buffer.clear();
for (int i = 0; i < end; ++i) {
buffer.append(buffer_[i]);
emit onProgress(i, end, i * 100.0f / end);
if (canceling_) {
emit onProgress(i, end, i * 100.0f / end, true, false, true);
return false;
}
buffer.append(buffer_[i]);
Runner::usDelay(twp_);
}
Runner::usDelay(twc_);
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
return true;
}

bool Dummy::program(const QByteArray &buffer, bool verify) {
canceling_ = false;
if (protected_) return false;
int end = qMin(buffer.size(), buffer_.size());
for (int i = 0; i < end; ++i) {
buffer_[i] = buffer[i];
emit onProgress(i, end, i * 100.0f / end);
if (canceling_) {
emit onProgress(i, end, i * 100.0f / end, true, false, true);
return false;
}
buffer_[i] = buffer[i];
Runner::usDelay(twp_);
}
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
Runner::usDelay(twc_);
if (verify) {
return this->verify(buffer);
} else {
emit onProgress(end, end, 100.0f, true);
}
return true;
}

bool Dummy::verify(const QByteArray &buffer) {
canceling_ = false;
int end = qMin(buffer.size(), buffer_.size());
for (int i = 0; i < end; ++i) {
emit onProgress(i, end, i * 100.0f / end);
if (canceling_) {
emit onProgress(i, end, i * 100.0f / end, true, false, true);
return false;
}
if (buffer[i] != buffer_[i]) {
emit onFinish(i, false);
emit onProgress(i, end, i * 100.0f / end, true, false);
return false;
}
Runner::usDelay(twp_);
}
Runner::usDelay(twc_);
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
return true;
}

bool Dummy::erase(bool check) {
canceling_ = false;
if (protected_) return false;
int end = buffer_.size();
for (int i = 0; i < end; ++i) {
buffer_[i] = 0xFF;
emit onProgress(i, end, i * 100.0f / end);
if (canceling_) {
emit onProgress(i, end, i * 100.0f / end, true, false, true);
return false;
}
buffer_[i] = 0xFF;
Runner::usDelay(twp_);
}
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
Runner::usDelay(twc_);
if (check) {
return blankCheck();
} else {
emit onProgress(end, end, 100.0f, true);
}
return true;
}

bool Dummy::blankCheck() {
canceling_ = false;
int end = buffer_.size();
for (int i = 0; i < end; ++i) {
emit onProgress(i, end, i * 100.0f / end);
if (canceling_) {
emit onProgress(i, end, i * 100.0f / end, true, false, true);
return false;
}
if (buffer_[i] != (char)0xFF) {
emit onFinish(i, false);
emit onProgress(i, end, i * 100.0f / end, true, false);
return false;
}
Runner::usDelay(twp_);
}
Runner::usDelay(twc_);
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
return true;
}

bool Dummy::unprotect() {
canceling_ = false;
if (!protected_) {
emit onProgress(0, 0, 0.0f, false);
emit onFinish(0, false);
emit onProgress(0, 100, 0.0f, true, false);
return false;
}
protected_ = false;
Runner::usDelay(twc_);
emit onProgress(1, 1, 100.0f, true);
emit onFinish(0);
emit onProgress(100, 100, 100.0f, true);
return true;
}
31 changes: 25 additions & 6 deletions software/usbflashprog/backend/devices/parallel/sram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ bool SRAM::program(const QByteArray &buffer, bool verify) {
(void)verify;
uint32_t current = 0, total = size_ * 4;
bool error = true;
uint32_t addr = 0;
if (runner_.open(port_)) {
error = false;
resetBus_();
Expand All @@ -48,16 +47,21 @@ bool SRAM::program(const QByteArray &buffer, bool verify) {
runner_.setCE();
if (!testRAM_(current, total)) {
error = true;
addr = runner_.addrGet();
}
resetBus_();
if (!error) {
error = runner_.hasError();
if (error) {
emit onProgress(total, total, 100.0f, true, false);
}
}
runner_.close();
} else {
emit onProgress(total, total, 100.0f, true, false);
}
if (!error) {
emit onProgress(total, total, 100.0f, true);
}
emit onProgress(total, total, 100.0f, true);
emit onFinish(addr, !error);
return !error;
}

Expand Down Expand Up @@ -120,14 +124,22 @@ bool SRAM::read_(uint8_t &data) {
bool SRAM::program_(const QByteArray &buffer, uint32_t &current,
uint32_t total) {
for (const auto &data : buffer) {
emit onProgress(current, total, current * 100.0f / total);
if (canceling_) {
emit onProgress(current, total, current * 100.0f / total, true,
false, true);
return false;
}
uint8_t read;
write_(data);
read_(read);
runner_.addrInc();
if (runner_.hasError() || read != data) {
emit onProgress(current, total, current * 100.0f / total, true,
false);
return false;
}
emit onProgress(current, total, current * 100.0f / total);

current++;
}
return true;
Expand All @@ -136,13 +148,20 @@ bool SRAM::program_(const QByteArray &buffer, uint32_t &current,
bool SRAM::verify_(const QByteArray &buffer, uint32_t &current,
uint32_t total) {
for (const auto &data : buffer) {
emit onProgress(current, total, current * 100.0f / total);
if (canceling_) {
emit onProgress(current, total, current * 100.0f / total, true,
false, true);
return false;
}
uint8_t read;
read_(read);
runner_.addrInc();
if (runner_.hasError() || read != data) {
emit onProgress(current, total, current * 100.0f / total, true,
false);
return false;
}
emit onProgress(current, total, current * 100.0f / total);
current++;
}
return true;
Expand Down
17 changes: 7 additions & 10 deletions software/usbflashprog/main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,17 @@ void MainWindow::onSelectDeviceTriggered(bool checked) {
device_->setSize(2 * 1024);

connect(device_, &Device::onProgress, this, &MainWindow::onActionProgress);
connect(device_, &Device::onFinish, this, &MainWindow::onActionFinish);
configureProgControls_();
}

void MainWindow::onActionProgress(uint32_t current, uint32_t total,
float percent, bool done) {
if (done) return;
}

void MainWindow::onActionFinish(uint32_t address, bool success) {
if (success) return;
QMessageBox::critical(
this, tr("USB Flash/EPROM Programmer"),
tr("Error at address 0x%1.").arg(address, 4, 16, QChar('0')));
float percent, bool done, bool success,
bool canceled) {
if (done && !success) {
QMessageBox::critical(
this, tr("USB Flash/EPROM Programmer"),
tr("Error at address 0x%1.").arg(current, 4, 16, QChar('0')));
}
}

void MainWindow::on_actionRead_triggered(bool checked) {
Expand Down
6 changes: 3 additions & 3 deletions software/usbflashprog/main/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ class MainWindow : public QMainWindow {
void onDataChanged(bool status = true);
void onBtnSelectDeviceClicked(bool checked = false);
void onSelectDeviceTriggered(bool checked = false);
void onActionProgress(uint32_t current, uint32_t total, float percent,
bool done = false);
void onActionFinish(uint32_t address, bool success = true);
void onActionProgress(uint32_t current = 0, uint32_t total = 0,
float percent = 0.0f, bool done = false,
bool success = true, bool canceled = false);

protected:
/*
Expand Down

0 comments on commit ab5ca6c

Please sign in to comment.