2020-11-02 07:04:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* 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 "impl/pwm_driver_core.hpp"
|
|
|
|
#include "impl/pwm_channel_session_impl.hpp"
|
|
|
|
|
|
|
|
namespace ams::pwm::driver {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
Result OpenSessionImpl(ChannelSession *out, IPwmDevice *device) {
|
|
|
|
/* Construct the session. */
|
2021-03-22 03:30:40 +00:00
|
|
|
auto *session = std::construct_at(std::addressof(impl::GetChannelSessionImpl(*out)));
|
|
|
|
auto session_guard = SCOPE_GUARD { std::destroy_at(session); };
|
2020-11-02 07:04:19 +00:00
|
|
|
|
|
|
|
/* Open the session. */
|
|
|
|
R_TRY(session->Open(device, ddsf::AccessMode_ReadWrite));
|
|
|
|
|
|
|
|
/* We succeeded. */
|
|
|
|
session_guard.Cancel();
|
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Result OpenSession(ChannelSession *out, DeviceCode device_code) {
|
|
|
|
AMS_ASSERT(out != nullptr);
|
|
|
|
|
|
|
|
/* Find the device. */
|
|
|
|
IPwmDevice *device = nullptr;
|
|
|
|
R_TRY(impl::FindDevice(std::addressof(device), device_code));
|
|
|
|
AMS_ASSERT(device != nullptr);
|
|
|
|
|
|
|
|
/* Open the session. */
|
|
|
|
R_TRY(OpenSessionImpl(out, device));
|
|
|
|
|
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloseSession(ChannelSession &session) {
|
2021-03-22 03:30:40 +00:00
|
|
|
std::destroy_at(std::addressof(impl::GetOpenChannelSessionImpl(session)));
|
2020-11-02 07:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetPeriod(ChannelSession &session, TimeSpan period) {
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).SetPeriod(period));
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeSpan GetPeriod(ChannelSession &session) {
|
|
|
|
TimeSpan out_val;
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).GetPeriod(std::addressof(out_val)));
|
|
|
|
return out_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDuty(ChannelSession &session, int duty) {
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).SetDuty(duty));
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetDuty(ChannelSession &session) {
|
|
|
|
int out_val;
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).GetDuty(std::addressof(out_val)));
|
|
|
|
return out_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetEnabled(ChannelSession &session, bool en) {
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).SetEnabled(en));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetEnabled(ChannelSession &session) {
|
|
|
|
bool out_val;
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).GetEnabled(std::addressof(out_val)));
|
|
|
|
return out_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetScale(ChannelSession &session, double scale) {
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).SetScale(scale));
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetScale(ChannelSession &session) {
|
|
|
|
double out_val;
|
|
|
|
R_ABORT_UNLESS(impl::GetOpenChannelSessionImpl(session).GetScale(std::addressof(out_val)));
|
|
|
|
return out_val;
|
|
|
|
}
|
|
|
|
}
|