//--------------------------------------------------------------------------- // // SCSI Target Emulator PiSCSI // for Raspberry Pi // // Copyright (C) 2022 akuker // Copyright (C) 2023 Uwe Seimet // //--------------------------------------------------------------------------- #include #include "hal/gpiobus_factory.h" #include "hal/gpiobus_raspberry.h" #include "hal/gpiobus_virtual.h" #include "hal/sbc_version.h" #include #include using namespace std; unique_ptr GPIOBUS_Factory::Create(BUS::mode_e mode) { unique_ptr bus; try { SBC_Version::Init(); if (SBC_Version::IsRaspberryPi()) { if (getuid()) { spdlog::error("GPIO bus access requires root permissions. Are you running as root?"); return nullptr; } bus = make_unique(); } else { bus = make_unique(); } if (bus->Init(mode)) { bus->Reset(); } } catch (const invalid_argument& e) { spdlog::error(string("Exception while trying to initialize GPIO bus: ") + e.what()); return nullptr; } return bus; }