-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c7f9ae
commit 530b76f
Showing
10 changed files
with
484 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
software/usbflashprog/backend/devices/parallel/dummy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.