2022-10-24 19:21:40 -05:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2023-10-22 17:29:26 +02:00
|
|
|
// SCSI Target Emulator PiSCSI
|
|
|
|
// for Raspberry Pi
|
2022-10-24 19:21:40 -05:00
|
|
|
//
|
2023-10-22 17:29:26 +02:00
|
|
|
// Copyright (C) 2022 akuker
|
|
|
|
// Copyright (C) 2023 Uwe Seimet
|
2022-10-24 19:21:40 -05:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-12-02 22:20:27 -06:00
|
|
|
#include <memory>
|
|
|
|
|
2022-10-24 19:21:40 -05:00
|
|
|
#include "hal/gpiobus_factory.h"
|
2022-12-02 22:20:27 -06:00
|
|
|
#include "hal/gpiobus_raspberry.h"
|
|
|
|
#include "hal/gpiobus_virtual.h"
|
|
|
|
#include "hal/sbc_version.h"
|
2023-10-22 17:29:26 +02:00
|
|
|
#include <unistd.h>
|
2023-10-15 08:38:15 +02:00
|
|
|
#include <spdlog/spdlog.h>
|
2022-10-24 19:21:40 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-11-09 08:40:26 +01:00
|
|
|
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
|
2022-10-24 19:21:40 -05:00
|
|
|
{
|
2023-10-22 17:29:26 +02:00
|
|
|
unique_ptr<BUS> bus;
|
2022-12-09 09:50:45 -06:00
|
|
|
|
|
|
|
try {
|
|
|
|
SBC_Version::Init();
|
2023-10-22 17:29:26 +02:00
|
|
|
if (SBC_Version::IsRaspberryPi()) {
|
|
|
|
if (getuid()) {
|
|
|
|
spdlog::error("GPIO bus access requires root permissions. Are you running as root?");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus = make_unique<GPIOBUS_Raspberry>();
|
2022-12-09 09:50:45 -06:00
|
|
|
} else {
|
2023-10-22 17:29:26 +02:00
|
|
|
bus = make_unique<GPIOBUS_Virtual>();
|
2022-12-09 09:50:45 -06:00
|
|
|
}
|
2023-10-22 17:29:26 +02:00
|
|
|
|
|
|
|
if (bus->Init(mode)) {
|
|
|
|
bus->Reset();
|
2022-12-09 09:50:45 -06:00
|
|
|
}
|
2023-10-22 17:29:26 +02:00
|
|
|
} catch (const invalid_argument& e) {
|
|
|
|
spdlog::error(string("Exception while trying to initialize GPIO bus: ") + e.what());
|
|
|
|
return nullptr;
|
2022-12-02 22:20:27 -06:00
|
|
|
}
|
2022-12-09 09:50:45 -06:00
|
|
|
|
2023-10-22 17:29:26 +02:00
|
|
|
return bus;
|
2022-10-24 19:21:40 -05:00
|
|
|
}
|