Skip to content

Commit

Permalink
Initial commit for external bus peripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Dec 13, 2021
1 parent 913d0d0 commit 09b8475
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 3 deletions.
37 changes: 37 additions & 0 deletions src/io/ioexternalbus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "ioexternalbus.h"
#include "ui_ioexternalbus.h"

#include <QPainter>
#include <QPen>

#include "STLExtras.h"
#include "ioregistry.h"

namespace Ripes {

IOExternalBus::IOExternalBus(QWidget* parent) : IOBase(IOType::EXTERNALBUS, parent), m_ui(new Ui::IOExternalBus) {
m_ui->setupUi(this);
}

IOExternalBus::~IOExternalBus() {
unregister();
delete m_ui;
};

unsigned IOExternalBus::byteSize() const {
return 1024;
}

QString IOExternalBus::description() const {
return "An external bus is a memory mapped bus handled through network transactions. The peripheral connects to an "
"IP address denoting a peripheral server - for more details, refer to the Ripes wiki.";
}

VInt IOExternalBus::ioRead(AInt offset, unsigned size) {
return 0;
}
void IOExternalBus::ioWrite(AInt offset, VInt value, unsigned size) {}

void IOExternalBus::parameterChanged(unsigned paramId) {}

} // namespace Ripes
49 changes: 49 additions & 0 deletions src/io/ioexternalbus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <QPen>
#include <QVariant>
#include <QWidget>

#include "iobase.h"

namespace Ripes {

namespace Ui {
class IOExternalBus;
}

/// @todo: should the bus be discoverable? i.e. implement a protocol for external bus to provide info on symbols and
/// registers exposed by its peripherals, which will be made available in Ripes. This will also dynamically adjust the
/// "byteSize" return value.

class IOExternalBus : public IOBase {
Q_OBJECT

public:
IOExternalBus(QWidget* parent);
~IOExternalBus() override;

virtual unsigned byteSize() const override;
virtual QString description() const override;
virtual QString baseName() const override { return "External bus"; }

virtual const std::vector<RegDesc>& registers() const override { return m_regDescs; };
virtual const std::vector<IOSymbol>* extraSymbols() const override { return &m_extraSymbols; }

/**
* Hardware read/write functions
*/
virtual VInt ioRead(AInt offset, unsigned size) override;
virtual void ioWrite(AInt offset, VInt value, unsigned size) override;

protected:
virtual void parameterChanged(unsigned) override;

private:
void updateAddress();
Ui::IOExternalBus* m_ui = nullptr;

std::vector<RegDesc> m_regDescs;
std::vector<IOSymbol> m_extraSymbols;
};
} // namespace Ripes
91 changes: 91 additions & 0 deletions src/io/ioexternalbus.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Ripes::IOExternalBus</class>
<widget class="QWidget" name="Ripes::IOExternalBus">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>149</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="address"/>
</item>
<item>
<widget class="QPushButton" name="connectButton">
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Server:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Status:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="status">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="server">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
9 changes: 6 additions & 3 deletions src/io/ioregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "iobase.h"

#include "iodpad.h"
#include "ioexternalbus.h"
#include "ioledmatrix.h"
#include "ioswitches.h"

Expand All @@ -18,7 +19,7 @@

namespace Ripes {

enum IOType { LED_MATRIX, SWITCHES, DPAD, NPERIPHERALS };
enum IOType { LED_MATRIX, SWITCHES, DPAD, EXTERNALBUS, NPERIPHERALS };

template <typename T>
IOBase* createIO(QWidget* parent) {
Expand All @@ -30,10 +31,12 @@ using IOFactory = std::function<IOBase*(QWidget* parent)>;

const static std::map<IOType, QString> IOTypeTitles = {{IOType::LED_MATRIX, "LED Matrix"},
{IOType::SWITCHES, "Switches"},
{IOType::DPAD, "D-Pad"}};
{IOType::DPAD, "D-Pad"},
{IOType::EXTERNALBUS, "External bus"}};
const static std::map<IOType, IOFactory> IOFactories = {{IOType::LED_MATRIX, createIO<IOLedMatrix>},
{IOType::SWITCHES, createIO<IOSwitches>},
{IOType::DPAD, createIO<IODPad>}};
{IOType::DPAD, createIO<IODPad>},
{IOType::EXTERNALBUS, createIO<IOExternalBus>}};

} // namespace Ripes

Expand Down

0 comments on commit 09b8475

Please sign in to comment.