mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-17 16:44:22 -04:00
i2c/gpio: hook up open session for sf interface
This commit is contained in:
parent
b74b309a77
commit
42caa4ffd1
15 changed files with 571 additions and 16 deletions
|
@ -30,6 +30,21 @@ namespace ams::i2c {
|
|||
std::shared_ptr<sf::IManager> g_i2c_pcv_manager;
|
||||
constinit int g_i2c_pcv_count = 0;
|
||||
|
||||
using InternalSession = std::shared_ptr<i2c::sf::ISession>;
|
||||
|
||||
InternalSession &GetInterface(const I2cSession &session) {
|
||||
AMS_ASSERT(session._session != nullptr);
|
||||
return *static_cast<InternalSession *>(session._session);
|
||||
}
|
||||
|
||||
std::shared_ptr<sf::IManager> GetManager(DeviceCode device_code) {
|
||||
if (IsPowerBusDeviceCode(device_code)) {
|
||||
return g_i2c_pcv_manager;
|
||||
} else {
|
||||
return g_i2c_manager;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InitializeWith(std::shared_ptr<i2c::sf::IManager> &&sp, std::shared_ptr<i2c::sf::IManager> &&sp_pcv) {
|
||||
|
@ -83,4 +98,64 @@ namespace ams::i2c {
|
|||
}
|
||||
}
|
||||
|
||||
Result OpenSession(I2cSession *out, DeviceCode device_code) {
|
||||
/* Allocate the session. */
|
||||
InternalSession *internal_session = new (std::nothrow) InternalSession;
|
||||
AMS_ABORT_UNLESS(internal_session != nullptr);
|
||||
auto session_guard = SCOPE_GUARD { delete internal_session; };
|
||||
|
||||
/* Get manager for the device. */
|
||||
auto manager = GetManager(device_code);
|
||||
|
||||
/* Get the session. */
|
||||
{
|
||||
ams::sf::cmif::ServiceObjectHolder object_holder;
|
||||
if (hos::GetVersion() >= hos::Version_6_0_0) {
|
||||
R_TRY(manager->OpenSession2(std::addressof(object_holder), device_code));
|
||||
} else {
|
||||
R_TRY(manager->OpenSession(std::addressof(object_holder), ConvertToI2cDevice(device_code)));
|
||||
}
|
||||
*internal_session = object_holder.GetServiceObject<sf::ISession>();
|
||||
}
|
||||
|
||||
/* Set output. */
|
||||
out->_session = internal_session;
|
||||
|
||||
/* We succeeded. */
|
||||
session_guard.Cancel();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void CloseSession(I2cSession &session) {
|
||||
/* Close the session. */
|
||||
delete std::addressof(GetInterface(session));
|
||||
session._session = nullptr;
|
||||
}
|
||||
|
||||
Result Send(const I2cSession &session, const void *src, size_t src_size, TransactionOption option) {
|
||||
const ams::sf::InAutoSelectBuffer buf(src, src_size);
|
||||
|
||||
return GetInterface(session)->Send(buf, option);
|
||||
}
|
||||
|
||||
Result Receive(void *dst, size_t dst_size, const I2cSession &session, TransactionOption option) {
|
||||
const ams::sf::OutAutoSelectBuffer buf(dst, dst_size);
|
||||
|
||||
return GetInterface(session)->Receive(buf, option);
|
||||
}
|
||||
|
||||
Result ExecuteCommandList(void *dst, size_t dst_size, const I2cSession &session, const void *src, size_t src_size) {
|
||||
const ams::sf::OutAutoSelectBuffer buf(dst, dst_size);
|
||||
const ams::sf::InPointerArray<i2c::I2cCommand> arr(static_cast<const i2c::I2cCommand *>(src), src_size);
|
||||
|
||||
return GetInterface(session)->ExecuteCommandList(buf, arr);
|
||||
}
|
||||
|
||||
void SetRetryPolicy(const I2cSession &session, int max_retry_count, int retry_interval_ms) {
|
||||
AMS_ASSERT(max_retry_count >= 0);
|
||||
AMS_ASSERT(retry_interval_ms >= 0);
|
||||
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetRetryPolicy(max_retry_count, retry_interval_ms));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue