2020-11-01 04:50:21 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-11-01 04:50:21 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "i2c_server_manager_impl.hpp"
|
|
|
|
|
|
|
|
namespace ams::i2c::server {
|
|
|
|
|
2021-01-17 15:55:32 +00:00
|
|
|
ManagerImpl::ManagerImpl() {
|
2020-11-01 04:50:21 +00:00
|
|
|
this->heap_handle = lmem::CreateExpHeap(this->heap_buffer, sizeof(this->heap_buffer), lmem::CreateOption_None);
|
2021-01-17 15:55:32 +00:00
|
|
|
this->allocator.Attach(this->heap_handle);
|
2020-11-01 04:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ManagerImpl::~ManagerImpl() {
|
|
|
|
lmem::DestroyExpHeap(this->heap_handle);
|
|
|
|
}
|
|
|
|
|
2021-01-17 15:55:32 +00:00
|
|
|
Result ManagerImpl::OpenSessionForDev(ams::sf::Out<ams::sf::SharedPointer<i2c::sf::ISession>> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode) {
|
2020-11-01 04:50:21 +00:00
|
|
|
/* TODO */
|
2021-10-06 22:20:48 +00:00
|
|
|
AMS_UNUSED(out, bus_idx, slave_address, addressing_mode, speed_mode);
|
2020-11-01 04:50:21 +00:00
|
|
|
AMS_ABORT();
|
|
|
|
}
|
|
|
|
|
2021-01-17 15:55:32 +00:00
|
|
|
Result ManagerImpl::OpenSession(ams::sf::Out<ams::sf::SharedPointer<i2c::sf::ISession>> out, i2c::I2cDevice device) {
|
2020-11-01 04:50:21 +00:00
|
|
|
return this->OpenSession2(out, ConvertToDeviceCode(device));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::HasDevice(ams::sf::Out<bool> out, i2c::I2cDevice device) {
|
|
|
|
/* TODO */
|
2021-10-06 22:20:48 +00:00
|
|
|
AMS_UNUSED(out, device);
|
2020-11-01 04:50:21 +00:00
|
|
|
AMS_ABORT();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::HasDeviceForDev(ams::sf::Out<bool> out, i2c::I2cDevice device) {
|
|
|
|
/* TODO */
|
2021-10-06 22:20:48 +00:00
|
|
|
AMS_UNUSED(out, device);
|
2020-11-01 04:50:21 +00:00
|
|
|
AMS_ABORT();
|
|
|
|
}
|
|
|
|
|
2021-01-17 15:55:32 +00:00
|
|
|
Result ManagerImpl::OpenSession2(ams::sf::Out<ams::sf::SharedPointer<i2c::sf::ISession>> out, DeviceCode device_code) {
|
2020-11-01 04:50:21 +00:00
|
|
|
/* Allocate a session. */
|
2021-01-17 15:55:32 +00:00
|
|
|
auto session = Factory::CreateSharedEmplaced<i2c::sf::ISession, SessionImpl>(std::addressof(this->allocator), this);
|
2020-11-01 04:50:21 +00:00
|
|
|
|
|
|
|
/* Open the session. */
|
2021-01-17 15:55:32 +00:00
|
|
|
R_TRY(session.GetImpl().OpenSession(device_code));
|
2020-11-01 04:50:21 +00:00
|
|
|
|
|
|
|
/* We succeeded. */
|
2021-01-17 15:55:32 +00:00
|
|
|
*out = std::move(session);
|
2020-11-01 04:50:21 +00:00
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|