2022-10-25 00:21:40 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-25 00:21:40 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 akuker
|
2022-12-03 04:20:27 +00:00
|
|
|
// [ GPIO bus factory ]
|
2022-10-25 00:21:40 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "hal/gpiobus_bananam2p.h"
|
2022-10-25 00:21:40 +00:00
|
|
|
#include "hal/gpiobus_factory.h"
|
2022-12-03 04:20:27 +00:00
|
|
|
#include "hal/gpiobus_raspberry.h"
|
|
|
|
#include "hal/gpiobus_virtual.h"
|
|
|
|
#include "hal/sbc_version.h"
|
|
|
|
#include "shared/log.h"
|
2022-10-25 00:21:40 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-11-09 07:40:26 +00:00
|
|
|
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
|
2022-10-25 00:21:40 +00:00
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
// TODO Make the factory a friend of GPIOBUS and make the GPIOBUS constructor private
|
|
|
|
// so that clients cannot use it anymore but have to use the factory.
|
|
|
|
// Also make Init() private.
|
|
|
|
unique_ptr<BUS> return_ptr;
|
|
|
|
SBC_Version::Init();
|
|
|
|
if (SBC_Version::IsBananaPi()) {
|
|
|
|
LOGTRACE("Creating GPIOBUS_BananaM2p")
|
|
|
|
return_ptr = make_unique<GPIOBUS_BananaM2p>();
|
|
|
|
} else if (SBC_Version::IsRaspberryPi()) {
|
|
|
|
LOGTRACE("Creating GPIOBUS_Raspberry")
|
|
|
|
return_ptr = make_unique<GPIOBUS_Raspberry>();
|
|
|
|
} else {
|
|
|
|
LOGINFO("Creating Virtual GPIOBUS")
|
|
|
|
return_ptr = make_unique<GPIOBUS_Virtual>();
|
|
|
|
}
|
|
|
|
if (!return_ptr->Init(mode)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return_ptr->Reset();
|
|
|
|
return return_ptr;
|
2022-10-25 00:21:40 +00:00
|
|
|
}
|