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 3c7f9ae commit 530b76f
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 40 deletions.
2 changes: 2 additions & 0 deletions software/usbflashprog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ elseif(NORMAL_BUILD)
ui/qhexeditor.hpp
backend/devices/device.cpp
backend/devices/device.hpp
backend/devices/parallel/dummy.cpp
backend/devices/parallel/dummy.hpp
backend/devices/parallel/sram.cpp
backend/devices/parallel/sram.hpp
main/mainwindow.cpp
Expand Down
2 changes: 1 addition & 1 deletion software/usbflashprog/backend/devices/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Device : public QObject {
virtual bool blankCheck();
virtual bool unprotect();

signals:
Q_SIGNALS:
void onProgress(uint32_t current, uint32_t total, float percent,
bool done = false);
void onFinish(uint32_t address, bool success = true);
Expand Down
157 changes: 157 additions & 0 deletions software/usbflashprog/backend/devices/parallel/dummy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// ---------------------------------------------------------------------------
// USB EPROM/Flash Programmer
//
// Copyright (2023) Robson Martins
//
// This work is licensed under a Creative Commons Attribution-NonCommercial-
// ShareAlike 4.0 International License.
// ---------------------------------------------------------------------------
/**
* @ingroup Software
* @file backend/devices/parallel/dummy.cpp
* @brief Implementation of the Parallel Dummy Device.
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------

#include "backend/devices/parallel/dummy.hpp"

// ---------------------------------------------------------------------------

Dummy::Dummy(QObject *parent) : Device(parent), protected_(true) {
info_.deviceType = kParallelMemory;
info_.name = "Dummy";
info_.capability.hasProgram = true;
info_.capability.hasVerify = true;
info_.capability.hasErase = true;
info_.capability.hasGetId = true;
info_.capability.hasRead = true;
info_.capability.hasBlankCheck = true;
info_.capability.hasUnprotect = 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;
size_ = 2048;
buffer_.resize(size_);
}

Dummy::~Dummy() {}

void Dummy::setSize(uint32_t value) {
Device::setSize(value);
buffer_.resize(size_);
}

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

bool Dummy::read(QByteArray &buffer) {
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);
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) {
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);
Runner::usDelay(twp_);
}
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
Runner::usDelay(twc_);
if (verify) {
return this->verify(buffer);
}
return true;
}

bool Dummy::verify(const QByteArray &buffer) {
int end = qMin(buffer.size(), buffer_.size());
for (int i = 0; i < end; ++i) {
emit onProgress(i, end, i * 100.0f / end);
if (buffer[i] != buffer_[i]) {
emit onFinish(i, 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) {
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);
Runner::usDelay(twp_);
}
emit onProgress(end, end, 100.0f, true);
emit onFinish(0);
Runner::usDelay(twc_);
if (check) {
return blankCheck();
}
return true;
}

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

bool Dummy::unprotect() {
if (!protected_) {
emit onProgress(0, 0, 0.0f, false);
emit onFinish(0, false);
return false;
}
protected_ = false;
Runner::usDelay(twc_);
emit onProgress(1, 1, 100.0f, true);
emit onFinish(0);
return true;
}
64 changes: 64 additions & 0 deletions software/usbflashprog/backend/devices/parallel/dummy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ---------------------------------------------------------------------------
// USB EPROM/Flash Programmer
//
// Copyright (2023) Robson Martins
//
// This work is licensed under a Creative Commons Attribution-NonCommercial-
// ShareAlike 4.0 International License.
// ---------------------------------------------------------------------------
/**
* @ingroup Software
* @file backend/devices/parallel/dummy.hpp
* @brief Class of a Parallel Dummy Device.
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------

#ifndef BACKEND_DEVICES_PARALLEL_DUMMY_HPP_
#define BACKEND_DEVICES_PARALLEL_DUMMY_HPP_

// ---------------------------------------------------------------------------

#include <QObject>
#include <QString>
#include <QByteArray>

#include "backend/devices/device.hpp"

// ---------------------------------------------------------------------------

/**
* @ingroup Software
* @brief Parallel Dummy Device Class
* @details The purpose of this class is to simulate a parallel device.
* @nosubgrouping
*/
class Dummy : public Device {
Q_OBJECT

public:
/**
* @brief Constructor.
* @param parent Pointer to parent object. Default is nullptr.
*/
explicit Dummy(QObject *parent = nullptr);
/** @brief Destructor. */
virtual ~Dummy();

virtual void setSize(uint32_t value);

virtual bool getId(TDeviceID &result);
virtual bool read(QByteArray &buffer);
virtual bool program(const QByteArray &buffer, bool verify = false);
virtual bool verify(const QByteArray &buffer);
virtual bool erase(bool check = false);
virtual bool blankCheck();
virtual bool unprotect();

protected:
QByteArray buffer_;
bool protected_;
};

#endif // BACKEND_DEVICES_PARALLEL_DUMMY_HPP_
3 changes: 2 additions & 1 deletion software/usbflashprog/backend/devices/parallel/sram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ bool SRAM::program(const QByteArray &buffer, bool verify) {
(void)buffer;
(void)verify;
uint32_t current = 0, total = size_ * 4;
bool error = false;
bool error = true;
uint32_t addr = 0;
if (runner_.open(port_)) {
error = false;
resetBus_();
runner_.vddSet(info_.voltage.vddProgram);
runner_.vddCtrl();
Expand Down
Loading

0 comments on commit 530b76f

Please sign in to comment.