Allow peripherals to export additional symbols
MODIFY
src/io/iobase.h
src/io/iobase.h
@@ -30,6 +30,11 @@ struct IOParam {
QVariant max;
};
+struct IOSymbol {
+ QString name;
+ uint32_t value;
+};
+
struct RegDesc {
enum class RW { R, W, RW };
QString name;
@@ -74,6 +79,13 @@ public:
*/
virtual const std::vector<RegDesc>& registers() const = 0;
+ /**
+ * @brief extraSymbols
+ * @returns the set of extra symbols defined by this peripheral. Useful if some symbols aren't directly translated
+ * from the register descriptions of this peripheral.
+ */
+ virtual const std::vector<IOSymbol>* extraSymbols() const { return nullptr; };
+
/**
* @brief setParameter
* Attempt to set the parameter @p ID to @p value. Returns true if the value was set successfully.

MODIFY
src/io/ioledmatrix.cpp
src/io/ioledmatrix.cpp
@@ -57,11 +57,15 @@ inline QColor regToColor(uint32_t regVal) {
}
void IOLedMatrix::updateLEDRegs() {
- const int width = m_parameters[WIDTH].value.toInt();
- const int height = m_parameters[HEIGHT].value.toInt();
+ const unsigned width = m_parameters[WIDTH].value.toInt();
+ const unsigned height = m_parameters[HEIGHT].value.toInt();
const int nLEDs = width * height;
m_ledRegs.resize(nLEDs);
+ m_extraSymbols.clear();
+ m_extraSymbols.push_back(IOSymbol{"WIDTH", width});
+ m_extraSymbols.push_back(IOSymbol{"HEIGHT", width});
+
m_regDescs.clear();
m_regDescs.resize(nLEDs);
for (unsigned i = 0; i < m_regDescs.size(); i++) {

MODIFY
src/io/ioledmatrix.h
src/io/ioledmatrix.h
@@ -22,6 +22,7 @@ public:
virtual QString baseName() const override { return "LED Matrix"; }
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
@@ -45,6 +46,7 @@ private:
unsigned m_maxSideWidth = 256;
std::vector<uint32_t> m_ledRegs;
std::vector<RegDesc> m_regDescs;
+ std::vector<IOSymbol> m_extraSymbols;
QPen m_pen;
};

MODIFY
src/io/iomanager.cpp
src/io/iomanager.cpp
@@ -128,6 +128,12 @@ std::map<QString, uint32_t> IOManager::assemblerSymbolsForPeriph(IOBase* periphe
}
}
+ if (auto* extraSymbols = peripheral->extraSymbols()) {
+ for (const auto& extraSymbol : *extraSymbols) {
+ symbols[periphName + "_" + cName(extraSymbol.name)] = extraSymbol.value;
+ }
+ }
+
return symbols;
}

Allow peripherals to export additional symbols