Remove start address info from IOBase
This information should be managed by the IOManager. The peripheral itself should not be concerned with where it resides in the address space.
MODIFY
src/io/iobase.h
src/io/iobase.h
@@ -35,7 +35,7 @@ class IOBase : public QWidget {
Q_OBJECT
public:
- IOBase(QWidget* parent, uint32_t startAddr) : QWidget(parent) { registerPeripheral(this); }
+ IOBase(QWidget* parent) : QWidget(parent) { registerPeripheral(this); }
virtual ~IOBase() { deregisterPeripheral(this); };
const std::map<unsigned, IOParam>& parameters() const { return m_parameters; }
@@ -53,11 +53,7 @@ public:
* Attempt to set the parameter @p ID to @p value. Returns true if the value was set successfully.
*/
virtual bool setParameter(unsigned ID, const QVariant& value);
-
- void setStartAddr(uint32_t addr) { m_startAddr = addr; }
- uint32_t startAddr() const { return m_startAddr; }
virtual uint32_t size() const = 0;
- uint32_t endAddr() const { return startAddr() + size(); }
/**
* Hardware read/write functions
@@ -79,7 +75,6 @@ signals:
protected:
virtual void parameterChanged(unsigned ID) = 0;
- ::uint32_t m_startAddr;
std::map<unsigned, IOParam> m_parameters;
static std::map<std::type_index, int> s_peripheralCount;

MODIFY
src/io/ioledmatrix.cpp
src/io/ioledmatrix.cpp
namespace Ripes {
-IOLedMatrix::IOLedMatrix(QWidget* parent, uint32_t startAddr) : IOBase(parent, startAddr) {
+IOLedMatrix::IOLedMatrix(QWidget* parent) : IOBase(parent) {
constexpr unsigned defaultWidth = 25;
// Parameters
- m_parameters[HEIGHT] = IOParam(WIDTH, "Matrix height", defaultWidth, true, 0, m_maxSideWidth);
- m_parameters[WIDTH] = IOParam(WIDTH, "Matrix width", defaultWidth + 10, true, 0, m_maxSideWidth);
+ m_parameters[HEIGHT] = IOParam(WIDTH, "Height", defaultWidth, true, 0, m_maxSideWidth);
+ m_parameters[WIDTH] = IOParam(WIDTH, "Width", defaultWidth + 10, true, 0, m_maxSideWidth);
m_parameters[SIZE] = IOParam(SIZE, "LED size", 8, true, 1, 100);
m_pen.setWidth(1);

MODIFY
src/io/ioledmatrix.h
src/io/ioledmatrix.h
@@ -14,12 +14,10 @@ class IOLedMatrix : public IOBase {
enum Parameters { HEIGHT, WIDTH, SIZE };
public:
- IOLedMatrix(QWidget* parent, uint32_t startAddr);
+ IOLedMatrix(QWidget* parent);
~IOLedMatrix(){};
- uint32_t startAddr() const { return m_startAddr; }
virtual uint32_t size() const override { return (m_maxSideWidth * m_maxSideWidth) * 4; }
- uint32_t endAddr() const { return startAddr() + size(); }
virtual QString description() const override;
virtual QString name() const override;

ADD
src/io/iomanager.cpp
+#include "iomanager.h"
+
+namespace Ripes {
+
+IOManager::IOManager() {}
+
+IOBase* IOManager::createPeripheral(IOType type) {
+ auto* peripheral = IOFactories.at(type)(nullptr);
+
+ // Assign base address to peripheral
+
+ return peripheral;
+}
+
+} // namespace Ripes

ADD
src/io/iomanager.h
+#pragma once
+
+#include "iobase.h"
+#include "ioregistry.h"
+
+namespace Ripes {
+
+struct MemoryMapEntry {
+ unsigned size;
+ QString name;
+};
+
+using MemoryMap = std::map<uint32_t, MemoryMapEntry>;
+
+class IOManager {
+public:
+ IOManager();
+ IOBase* createPeripheral(IOType type);
+ const MemoryMap& memoryMap() const { return m_memoryMap; }
+
+private:
+ MemoryMap m_memoryMap;
+};
+
+} // namespace Ripes

MODIFY
src/io/ioregistry.h
src/io/ioregistry.h
@@ -20,12 +20,12 @@ namespace Ripes {
enum class IOType { LED_MATRIX, SWITCHES };
template <typename T>
-IOBase* createIO(QWidget* parent, uint32_t startAddr) {
+IOBase* createIO(QWidget* parent) {
static_assert(std::is_base_of<IOBase, T>::value);
- return new T(parent, startAddr);
+ return new T(parent);
}
-using IOFactory = std::function<IOBase*(QWidget* parent, uint32_t)>;
+using IOFactory = std::function<IOBase*(QWidget* parent)>;
const static std::map<IOType, QString> IOTypeTitles = {{IOType::LED_MATRIX, "LED Matrix"},
{IOType::SWITCHES, "Switches"}};

MODIFY
src/io/ioswitches.cpp
src/io/ioswitches.cpp
@@ -135,7 +135,7 @@ void ToggleButton::enterEvent(QEvent* event) {
* IO Switches
*/
-IOSwitches::IOSwitches(QWidget* parent, uint32_t startAddr) : IOBase(parent, startAddr) {
+IOSwitches::IOSwitches(QWidget* parent) : IOBase(parent) {
constexpr unsigned defaultWidth = 25;
// Parameters

MODIFY
src/io/ioswitches.h
src/io/ioswitches.h
@@ -60,12 +60,10 @@ class IOSwitches : public IOBase {
enum Parameters { SWITCHES };
public:
- IOSwitches(QWidget* parent, uint32_t startAddr);
+ IOSwitches(QWidget* parent);
~IOSwitches(){};
- uint32_t startAddr() const { return m_startAddr; }
virtual uint32_t size() const override { return 4; }
- uint32_t endAddr() const { return startAddr() + size(); }
virtual QString description() const override;
virtual QString name() const override;

MODIFY
src/iotab.cpp
src/iotab.cpp
@@ -71,7 +71,7 @@ uint32_t nextAddress() {
}
void IOTab::createPeripheral(IOType type) {
- auto* peripheral = IOFactories.at(type)(this, nextAddress());
+ auto* peripheral = m_iomanager.createPeripheral(type);
// Create tab for peripheral
auto* peripheralTab = new IOPeripheralTab(this, peripheral);
m_ui->peripheralsTab->addTab(peripheralTab, peripheral->name());

MODIFY
src/iotab.h
src/iotab.h
#include "processorhandler.h"
#include "ripestab.h"
+#include "io/iomanager.h"
#include "io/ioregistry.h"
namespace Ripes {
@@ -53,5 +54,6 @@ private:
* Pointer from the tab associated with a peripheral to its corresponding MDI subwindow.
*/
std::unordered_map<QWidget*, QMdiSubWindow*> m_subWindows;
+ IOManager m_iomanager;
};
} // namespace Ripes

Remove start address info from IOBase

This information should be managed by the IOManager. The peripheral itself should not be concerned with where it resides in the address space.