Export # of switches as symbol from switches device
MODIFY
examples/C/switchesAndLeds.c
examples/C/switchesAndLeds.c
@@ -16,9 +16,9 @@ unsigned* switch_base = SWITCHES_0_BASE;
void main() {
unsigned v = 0;
while (1) {
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < SWITCHES_0_N; i++) {
if ((*switch_base >> i) & 0x1) {
- *(led_base + i) = 0xFFFFFF;
+ *(led_base + i) = 0xFF << ((i % 3) * 8);
} else {
*(led_base + i) = 0x0;
}

MODIFY
src/io/ioswitches.cpp
src/io/ioswitches.cpp
@@ -162,6 +162,9 @@ void IOSwitches::updateSwitches() {
}
}
+ m_extraSymbols.clear();
+ m_extraSymbols.push_back(IOSymbol{"N", nSwitches});
+
// Remove extra switches if # of switches was reduced
std::vector<unsigned> idxToDelete;
for (const auto& it : m_switches) {

MODIFY
src/io/ioswitches.h
src/io/ioswitches.h
@@ -71,6 +71,7 @@ public:
virtual QString baseName() const override { return "Switches"; };
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
@@ -88,5 +89,6 @@ private:
std::map<unsigned, std::pair<QLabel*, ToggleButton*>> m_switches;
QGridLayout* m_switchLayout;
std::vector<RegDesc> m_regDescs;
+ std::vector<IOSymbol> m_extraSymbols;
};
} // namespace Ripes

Export # of switches as symbol from switches device