Use IO forced ID when re-loading peripherals
MODIFY
src/io/iobase.h
src/io/iobase.h
@@ -188,7 +188,7 @@ protected:
virtual void parameterChanged(unsigned ID) = 0;
std::map<unsigned, IOParam> m_parameters;
- unsigned m_id;
+ unsigned m_id = UINT_MAX;
static std::map<unsigned, std::set<unsigned>> s_peripheralIDs;
static unsigned claimPeripheralId(const unsigned& ioType, int forcedID = -1) {

MODIFY
src/io/iomanager.cpp
src/io/iomanager.cpp
@@ -88,12 +88,15 @@ void IOManager::unregisterPeripheralWithProcessor(IOBase* peripheral) {
}
}
-IOBase* IOManager::createPeripheral(IOType type) {
+IOBase* IOManager::createPeripheral(IOType type, unsigned forcedId) {
auto* peripheral = IOFactories.at(type)(nullptr);
connect(peripheral, &IOBase::sizeChanged, [=] { this->peripheralSizeChanged(peripheral); });
connect(peripheral, &IOBase::aboutToDelete, [=](std::atomic<bool>& ok) { this->removePeripheral(peripheral, ok); });
+ if (forcedId != UINT_MAX) {
+ peripheral->setID(forcedId);
+ }
m_peripherals.insert(peripheral);
assignBaseAddress(peripheral);
refreshMemoryMap();

MODIFY
src/io/iomanager.h
src/io/iomanager.h
@@ -37,7 +37,7 @@ public:
return manager;
}
- IOBase* createPeripheral(IOType type);
+ IOBase* createPeripheral(IOType type, unsigned forcedId = UINT_MAX);
void removePeripheral(IOBase* peripheral, std::atomic<bool>& ok);
const MemoryMap& memoryMap() const { return m_memoryMap; }

MODIFY
src/iotab.cpp
src/iotab.cpp
@@ -77,10 +77,8 @@ IOTab::IOTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent), m_
}
IOBase* IOTab::createPeripheral(IOType type, int forcedID) {
- auto* peripheral = IOManager::get().createPeripheral(type);
- if (forcedID != -1) {
- peripheral->setID(forcedID);
- }
+ auto* peripheral = IOManager::get().createPeripheral(type, forcedID);
+
// Create tab for peripheral
auto* peripheralTab = new IOPeripheralTab(this, peripheral);
m_ui->peripheralsTab->addTab(peripheralTab, peripheral->name());

Use IO forced ID when re-loading peripherals