sdmmc: implement driver suitable for fs + bootloader
* sdmmc: begin skeletoning sdmmc driver * sdmmc: add most of SdHostStandardController * sdmmc: implement most of SdmmcController * sdmmc: Sdmmc2Controller * sdmmc: skeleton implementation of Sdmmc1Controller * sdmmc: complete abstract logic for Sdmmc1 power controller * sdmmc: implement gpio handling for sdmmc1-register-control * sdmmc: implement pinmux handling for sdmmc1-register-control * sdmmc: fix building for arm32 and in stratosphere context * sdmmc: implement voltage enable/set for sdmmc1-register-control * util: move T(V)SNPrintf from kernel to util * sdmmc: implement BaseDeviceAccessor * sdmmc: implement MmcDeviceAccessor * sdmmc: implement clock reset controller for register api * sdmmc: fix bug in WaitWhileCommandInhibit, add mmc accessors * exo: add sdmmc test program * sdmmc: fix speed mode extension, add CheckMmcConnection for debug * sdmmc: add DeviceDetector, gpio: implement client api * gpio: modernize client api instead of doing it the lazy way * sdmmc: SdCardDeviceAccessor impl * sdmmc: update test program to read first two sectors of sd card * sdmmc: fix vref sel * sdmmc: finish outward-facing api (untested) * ams: changes for libvapours including tegra register defs * sdmmc: remove hwinit
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include <stratosphere/erpt.hpp>
|
||||
#include <stratosphere/err.hpp>
|
||||
#include <stratosphere/fatal.hpp>
|
||||
#include <stratosphere/gpio.hpp>
|
||||
#include <stratosphere/hid.hpp>
|
||||
#include <stratosphere/hos.hpp>
|
||||
#include <stratosphere/kvdb.hpp>
|
||||
@@ -60,7 +61,6 @@
|
||||
#include <stratosphere/pgl.hpp>
|
||||
#include <stratosphere/psc.hpp>
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/reg.hpp>
|
||||
#include <stratosphere/ro.hpp>
|
||||
#include <stratosphere/settings.hpp>
|
||||
#include <stratosphere/sf.hpp>
|
||||
|
||||
@@ -39,19 +39,21 @@ namespace ams::impl {
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, pm, Main);
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, pm, ProcessTrack);
|
||||
|
||||
|
||||
/* NCM. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, ncm, MainWaitThreads);
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, ncm, ContentManagerServerIpcSession);
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, ncm, LocationResolverServerIpcSession);
|
||||
|
||||
/* FS. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(16, fs, WorkerThreadPool);
|
||||
AMS_DEFINE_SYSTEM_THREAD(17, fs, Main);
|
||||
AMS_DEFINE_SYSTEM_THREAD(17, fs, WorkerRealTimeAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(18, fs, WorkerNormalPriorityAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(19, fs, WorkerLowPriorityAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(30, fs, WorkerBackgroundAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(30, fs, PatrolReader);
|
||||
AMS_DEFINE_SYSTEM_THREAD(11, sdmmc, DeviceDetector);
|
||||
AMS_DEFINE_SYSTEM_THREAD(16, fs, WorkerThreadPool);
|
||||
AMS_DEFINE_SYSTEM_THREAD(17, fs, Main);
|
||||
AMS_DEFINE_SYSTEM_THREAD(17, fs, WorkerRealTimeAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(18, fs, WorkerNormalPriorityAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(19, fs, WorkerLowPriorityAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(30, fs, WorkerBackgroundAccess);
|
||||
AMS_DEFINE_SYSTEM_THREAD(30, fs, PatrolReader);
|
||||
|
||||
/* Boot. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(-1, boot, Main);
|
||||
|
||||
@@ -19,16 +19,13 @@
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
uintptr_t QueryIoMapping(uintptr_t phys_addr, size_t size);
|
||||
|
||||
u32 ReadRegister(uintptr_t phys_addr);
|
||||
void WriteRegister(uintptr_t phys_addr, u32 value);
|
||||
u32 ReadWriteRegister(uintptr_t phys_addr, u32 value, u32 mask);
|
||||
u32 ReadRegister(dd::PhysicalAddress phys_addr);
|
||||
void WriteRegister(dd::PhysicalAddress phys_addr, u32 value);
|
||||
u32 ReadWriteRegister(dd::PhysicalAddress phys_addr, u32 value, u32 mask);
|
||||
|
||||
/* Convenience Helper. */
|
||||
|
||||
inline uintptr_t GetIoMapping(uintptr_t phys_addr, size_t size) {
|
||||
const uintptr_t io_mapping = QueryIoMapping(phys_addr, size);
|
||||
inline uintptr_t GetIoMapping(dd::PhysicalAddress phys_addr, size_t size) {
|
||||
const uintptr_t io_mapping = dd::QueryIoMapping(phys_addr, size);
|
||||
AMS_ABORT_UNLESS(io_mapping);
|
||||
return io_mapping;
|
||||
}
|
||||
|
||||
19
libraries/libstratosphere/include/stratosphere/ddsf.hpp
Normal file
19
libraries/libstratosphere/include/stratosphere/ddsf.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stratosphere/ddsf/ddsf_types.hpp>
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::ddsf {
|
||||
|
||||
enum AccessMode {
|
||||
AccessMode_None = (0u << 0),
|
||||
AccessMode_Read = (1u << 0),
|
||||
AccessMode_Write = (1u << 1),
|
||||
|
||||
AccessMode_ReadWrite = AccessMode_Read | AccessMode_Write,
|
||||
};
|
||||
|
||||
}
|
||||
22
libraries/libstratosphere/include/stratosphere/gpio.hpp
Normal file
22
libraries/libstratosphere/include/stratosphere/gpio.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_manager.hpp>
|
||||
#include <stratosphere/gpio/gpio_api.hpp>
|
||||
#include <stratosphere/gpio/gpio_pad_api.hpp>
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/ddsf/ddsf_types.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/gpio_select_pad_name.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
struct GpioPadSession {
|
||||
void *_session;
|
||||
os::SystemEventType *_event;
|
||||
};
|
||||
|
||||
Result OpenSession(GpioPadSession *out_session, ams::DeviceCode device_code);
|
||||
void CloseSession(GpioPadSession *session);
|
||||
|
||||
Direction GetDirection(GpioPadSession *session);
|
||||
void SetDirection(GpioPadSession *session, Direction direction);
|
||||
|
||||
GpioValue GetValue(GpioPadSession *session);
|
||||
void SetValue(GpioPadSession *session, GpioValue value);
|
||||
|
||||
InterruptMode GetInterruptMode(GpioPadSession *session);
|
||||
void SetInterruptMode(GpioPadSession *session, InterruptMode mode);
|
||||
|
||||
bool GetInterruptEnable(GpioPadSession *session);
|
||||
void SetInterruptEnable(GpioPadSession *session, bool en);
|
||||
|
||||
InterruptStatus GetInterruptStatus(GpioPadSession *session);
|
||||
void ClearInterruptStatus(GpioPadSession *session);
|
||||
|
||||
int GetDebounceTime(GpioPadSession *session);
|
||||
void SetDebounceTime(GpioPadSession *session, int ms);
|
||||
|
||||
bool GetDebounceEnabled(GpioPadSession *session);
|
||||
void SetDebounceEnabled(GpioPadSession *session, bool en);
|
||||
|
||||
Result BindInterrupt(os::SystemEventType *event, GpioPadSession *session);
|
||||
void UnbindInterrupt(GpioPadSession *session);
|
||||
|
||||
Result IsWakeEventActive(bool *out_is_active, ams::DeviceCode device_code);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
enum GpioPadName : u32 {
|
||||
GpioPadName_CodecLdoEnTemp = 1,
|
||||
GpioPadName_ButtonVolUp = 25,
|
||||
GpioPadName_ButtonVolDn = 26,
|
||||
GpioPadName_SdCd = 56,
|
||||
};
|
||||
|
||||
/* TODO: Better place for this? */
|
||||
constexpr inline const DeviceCode DeviceCode_CodecLdoEnTemp = 0x33000002;
|
||||
constexpr inline const DeviceCode DeviceCode_ButtonVolUp = 0x35000002;
|
||||
constexpr inline const DeviceCode DeviceCode_ButtonVolDn = 0x35000003;
|
||||
constexpr inline const DeviceCode DeviceCode_SdCd = 0x3C000002;
|
||||
|
||||
constexpr inline GpioPadName ConvertToGpioPadName(DeviceCode dc) {
|
||||
switch (dc.GetInternalValue()) {
|
||||
case DeviceCode_CodecLdoEnTemp.GetInternalValue(): return GpioPadName_CodecLdoEnTemp;
|
||||
case DeviceCode_ButtonVolUp .GetInternalValue(): return GpioPadName_ButtonVolUp;
|
||||
case DeviceCode_ButtonVolDn .GetInternalValue(): return GpioPadName_ButtonVolDn;
|
||||
case DeviceCode_SdCd .GetInternalValue(): return GpioPadName_SdCd;
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr inline DeviceCode ConvertToDeviceCode(GpioPadName gpn) {
|
||||
switch (gpn) {
|
||||
case GpioPadName_CodecLdoEnTemp: return DeviceCode_CodecLdoEnTemp;
|
||||
case GpioPadName_ButtonVolUp: return DeviceCode_ButtonVolUp;
|
||||
case GpioPadName_ButtonVolDn: return DeviceCode_ButtonVolDn;
|
||||
case GpioPadName_SdCd: return DeviceCode_SdCd;
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
|
||||
#include <stratosphere/gpio/gpio_pad_name.board.nintendo_nx.hpp>
|
||||
#else
|
||||
/* Error? */
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
enum InterruptMode : u32 {
|
||||
InterruptMode_LowLevel = 0,
|
||||
InterruptMode_HighLevel = 1,
|
||||
InterruptMode_RisingEdge = 2,
|
||||
InterruptMode_FallingEdge = 3,
|
||||
InterruptMode_AnyEdge = 4,
|
||||
};
|
||||
|
||||
enum Direction : u32 {
|
||||
Direction_Input = 0,
|
||||
Direction_Output = 1,
|
||||
};
|
||||
|
||||
enum GpioValue : u32 {
|
||||
GpioValue_Low = 0,
|
||||
GpioValue_High = 1,
|
||||
};
|
||||
|
||||
enum InterruptStatus : u32 {
|
||||
InterruptStatus_Inactive = 0,
|
||||
InterruptStatus_Active = 1,
|
||||
};
|
||||
|
||||
using WakeBitFlag = util::BitFlagSet<128>;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/ddsf/ddsf_types.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/gpio_select_pad_name.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp>
|
||||
|
||||
namespace ams::gpio::sf {
|
||||
|
||||
#define AMS_GPIO_I_MANAGER_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSessionForTest, (ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 3, Result, IsWakeEventActive, (ams::sf::Out<bool> out, gpio::GpioPadName pad_name), hos::Version_Min, hos::Version_6_2_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 4, Result, GetWakeEventActiveFlagSet, (ams::sf::Out<gpio::WakeBitFlag> out), hos::Version_Min, hos::Version_6_2_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 5, Result, SetWakeEventActiveFlagSetForDebug, (gpio::GpioPadName pad_name, bool is_enabled), hos::Version_Min, hos::Version_6_2_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 6, Result, SetWakePinDebugMode, (s32 mode) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 7, Result, OpenSession2, (ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode), hos::Version_5_0_0 ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 8, Result, IsWakeEventActive2, (ams::sf::Out<bool> out, DeviceCode device_code), hos::Version_5_0_0 ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 9, Result, SetWakeEventActiveFlagSetForDebug2, (DeviceCode device_code, bool is_enabled), hos::Version_5_0_0 ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 10, Result, SetRetryValues, (u32 arg0, u32 arg1), hos::Version_6_0_0 )
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(IManager, AMS_GPIO_I_MANAGER_INTERFACE_INFO)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
|
||||
namespace ams::gpio::sf {
|
||||
|
||||
#define AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, SetDirection, (gpio::Direction direction) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetDirection, (ams::sf::Out<gpio::Direction> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, SetInterruptMode, (gpio::InterruptMode mode) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 3, Result, GetInterruptMode, (ams::sf::Out<gpio::InterruptMode> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 4, Result, SetInterruptEnable, (bool enable) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 5, Result, GetInterruptEnable, (ams::sf::Out<bool> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 6, Result, GetInterruptStatus, (ams::sf::Out<gpio::InterruptStatus> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 7, Result, ClearInterruptStatus, () ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 8, Result, SetValue, (gpio::GpioValue value) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 9, Result, GetValue, (ams::sf::Out<gpio::GpioValue> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 10, Result, BindInterrupt, (ams::sf::OutCopyHandle out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 11, Result, UnbindInterrupt, () ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 12, Result, SetDebounceEnabled, (bool enable) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 13, Result, GetDebounceEnabled, (ams::sf::Out<bool> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 14, Result, SetDebounceTime, (s32 ms) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 15, Result, GetDebounceTime, (ams::sf::Out<s32> out) ) \
|
||||
AMS_SF_METHOD_INFO(C, H, 16, Result, SetValueForSleepState, (gpio::GpioValue value), hos::Version_4_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 16, Result, GetValueForSleepState, (ams::sf::Out<gpio::GpioValue> out), hos::Version_6_0_0)
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(IPadSession, AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO)
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::reg {
|
||||
|
||||
inline void Write(volatile u32 *reg, u32 val) {
|
||||
*reg = val;
|
||||
}
|
||||
|
||||
inline void Write(uintptr_t reg, u32 val) {
|
||||
Write(reinterpret_cast<volatile u32 *>(reg), val);
|
||||
}
|
||||
|
||||
inline u32 Read(volatile u32 *reg) {
|
||||
return *reg;
|
||||
}
|
||||
|
||||
inline u32 Read(uintptr_t reg) {
|
||||
return Read(reinterpret_cast<volatile u32 *>(reg));
|
||||
}
|
||||
|
||||
inline void SetBits(volatile u32 *reg, u32 mask) {
|
||||
*reg = *reg | mask;
|
||||
}
|
||||
|
||||
inline void SetBits(uintptr_t reg, u32 mask) {
|
||||
SetBits(reinterpret_cast<volatile u32 *>(reg), mask);
|
||||
}
|
||||
|
||||
inline void ClearBits(volatile u32 *reg, u32 mask) {
|
||||
*reg = *reg & ~mask;
|
||||
}
|
||||
|
||||
inline void ClearBits(uintptr_t reg, u32 mask) {
|
||||
ClearBits(reinterpret_cast<volatile u32 *>(reg), mask);
|
||||
}
|
||||
|
||||
inline void MaskBits(volatile u32 *reg, u32 mask) {
|
||||
*reg = *reg & mask;
|
||||
}
|
||||
|
||||
inline void MaskBits(uintptr_t reg, u32 mask) {
|
||||
MaskBits(reinterpret_cast<volatile u32 *>(reg), mask);
|
||||
}
|
||||
|
||||
inline void ReadWrite(volatile u32 *reg, u32 val, u32 mask) {
|
||||
*reg = (*reg & (~mask)) | (val & mask);
|
||||
}
|
||||
|
||||
inline void ReadWrite(uintptr_t reg, u32 val, u32 mask) {
|
||||
ReadWrite(reinterpret_cast<volatile u32 *>(reg), val, mask);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -167,20 +167,19 @@ namespace ams::boot2 {
|
||||
}
|
||||
}
|
||||
|
||||
bool GetGpioPadLow(GpioPadName pad) {
|
||||
GpioPadSession button;
|
||||
if (R_FAILED(gpioOpenSession(&button, pad))) {
|
||||
bool GetGpioPadLow(DeviceCode device_code) {
|
||||
gpio::GpioPadSession button;
|
||||
if (R_FAILED(gpio::OpenSession(std::addressof(button), device_code))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ensure we close even on early return. */
|
||||
ON_SCOPE_EXIT { gpioPadClose(&button); };
|
||||
ON_SCOPE_EXIT { gpio::CloseSession(std::addressof(button)); };
|
||||
|
||||
/* Set direction input. */
|
||||
gpioPadSetDirection(&button, GpioDirection_Input);
|
||||
gpio::SetDirection(std::addressof(button), gpio::Direction_Input);
|
||||
|
||||
GpioValue val;
|
||||
return R_SUCCEEDED(gpioPadGetValue(&button, &val)) && val == GpioValue_Low;
|
||||
return gpio::GetValue(std::addressof(button)) == gpio::GpioValue_Low;
|
||||
}
|
||||
|
||||
bool IsForceMaintenance() {
|
||||
@@ -197,7 +196,7 @@ namespace ams::boot2 {
|
||||
|
||||
/* Contact GPIO, read plus/minus buttons. */
|
||||
{
|
||||
return GetGpioPadLow(GpioPadName_ButtonVolUp) && GetGpioPadLow(GpioPadName_ButtonVolDown);
|
||||
return GetGpioPadLow(gpio::DeviceCode_ButtonVolUp) && GetGpioPadLow(gpio::DeviceCode_ButtonVolDn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
uintptr_t QueryIoMapping(uintptr_t phys_addr, size_t size) {
|
||||
u64 virtual_addr;
|
||||
const u64 aligned_addr = util::AlignDown(phys_addr, os::MemoryPageSize);
|
||||
const size_t offset = phys_addr - aligned_addr;
|
||||
const u64 aligned_size = size + offset;
|
||||
if (hos::GetVersion() >= hos::Version_10_0_0) {
|
||||
u64 region_size;
|
||||
R_TRY_CATCH(svcQueryIoMapping(&virtual_addr, ®ion_size, aligned_addr, aligned_size)) {
|
||||
/* Official software handles this by returning 0. */
|
||||
R_CATCH(svc::ResultNotFound) { return 0; }
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
AMS_ASSERT(region_size >= aligned_size);
|
||||
} else {
|
||||
R_TRY_CATCH(svcLegacyQueryIoMapping(&virtual_addr, aligned_addr, aligned_size)) {
|
||||
/* Official software handles this by returning 0. */
|
||||
R_CATCH(svc::ResultNotFound) { return 0; }
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
}
|
||||
|
||||
return static_cast<uintptr_t>(virtual_addr + offset);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) {
|
||||
u32 out_value;
|
||||
R_ABORT_UNLESS(svcReadWriteRegister(&out_value, phys_addr, mask, value));
|
||||
return out_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u32 ReadRegister(uintptr_t phys_addr) {
|
||||
return ReadWriteRegisterImpl(phys_addr, 0, 0);
|
||||
}
|
||||
|
||||
void WriteRegister(uintptr_t phys_addr, u32 value) {
|
||||
ReadWriteRegisterImpl(phys_addr, value, ~u32());
|
||||
}
|
||||
|
||||
u32 ReadWriteRegister(uintptr_t phys_addr, u32 value, u32 mask) {
|
||||
return ReadWriteRegisterImpl(phys_addr, value, mask);
|
||||
}
|
||||
|
||||
}
|
||||
197
libraries/libstratosphere/source/gpio/gpio_client_api.cpp
Normal file
197
libraries/libstratosphere/source/gpio/gpio_client_api.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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 "gpio_remote_manager_impl.hpp"
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
namespace {
|
||||
|
||||
/* TODO: Manager object. */
|
||||
constinit os::SdkMutex g_init_mutex;
|
||||
constinit int g_initialize_count = 0;
|
||||
std::shared_ptr<sf::IManager> g_manager;
|
||||
|
||||
using InternalSession = std::shared_ptr<gpio::sf::IPadSession>;
|
||||
|
||||
InternalSession &GetInterface(GpioPadSession *session) {
|
||||
AMS_ASSERT(session->_session != nullptr);
|
||||
return *static_cast<InternalSession *>(session->_session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
if ((g_initialize_count++) == 0) {
|
||||
R_ABORT_UNLESS(::gpioInitialize());
|
||||
g_manager = ams::sf::MakeShared<sf::IManager, RemoteManagerImpl>();
|
||||
}
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
AMS_ASSERT(g_initialize_count > 0);
|
||||
|
||||
if ((--g_initialize_count) == 0) {
|
||||
g_manager.reset();
|
||||
::gpioExit();
|
||||
}
|
||||
}
|
||||
|
||||
Result OpenSession(GpioPadSession *out_session, ams::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 the session. */
|
||||
{
|
||||
ams::sf::cmif::ServiceObjectHolder object_holder;
|
||||
if (hos::GetVersion() >= hos::Version_7_0_0) {
|
||||
R_TRY(g_manager->OpenSession2(std::addressof(object_holder), device_code, ddsf::AccessMode_ReadWrite));
|
||||
} else {
|
||||
R_TRY(g_manager->OpenSession(std::addressof(object_holder), ConvertToGpioPadName(device_code)));
|
||||
}
|
||||
*internal_session = object_holder.GetServiceObject<sf::IPadSession>();
|
||||
}
|
||||
|
||||
/* Set output. */
|
||||
out_session->_session = internal_session;
|
||||
out_session->_event = nullptr;
|
||||
|
||||
/* We succeeded. */
|
||||
session_guard.Cancel();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void CloseSession(GpioPadSession *session) {
|
||||
AMS_ASSERT(session != nullptr);
|
||||
|
||||
/* Unbind the interrupt, if it's still bound. */
|
||||
if (session->_event != nullptr) {
|
||||
gpio::UnbindInterrupt(session);
|
||||
}
|
||||
|
||||
/* Close the session. */
|
||||
delete std::addressof(GetInterface(session));
|
||||
session->_session = nullptr;
|
||||
}
|
||||
|
||||
Result IsWakeEventActive(bool *out_is_active, ams::DeviceCode device_code) {
|
||||
if (hos::GetVersion() >= hos::Version_7_0_0) {
|
||||
R_TRY(g_manager->IsWakeEventActive2(out_is_active, device_code));
|
||||
} else {
|
||||
R_TRY(g_manager->IsWakeEventActive(out_is_active, ConvertToGpioPadName(device_code)));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Direction GetDirection(GpioPadSession *session) {
|
||||
Direction out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetDirection(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetDirection(GpioPadSession *session, Direction direction) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetDirection(direction));
|
||||
}
|
||||
|
||||
GpioValue GetValue(GpioPadSession *session) {
|
||||
GpioValue out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetValue(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetValue(GpioPadSession *session, GpioValue value) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetValue(value));
|
||||
}
|
||||
|
||||
InterruptMode GetInterruptMode(GpioPadSession *session) {
|
||||
InterruptMode out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetInterruptMode(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetInterruptMode(GpioPadSession *session, InterruptMode mode) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetInterruptMode(mode));
|
||||
}
|
||||
|
||||
bool GetInterruptEnable(GpioPadSession *session) {
|
||||
bool out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetInterruptEnable(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetInterruptEnable(GpioPadSession *session, bool en) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetInterruptEnable(en));
|
||||
}
|
||||
|
||||
InterruptStatus GetInterruptStatus(GpioPadSession *session) {
|
||||
InterruptStatus out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetInterruptStatus(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void ClearInterruptStatus(GpioPadSession *session) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->ClearInterruptStatus());
|
||||
}
|
||||
|
||||
int GetDebounceTime(GpioPadSession *session) {
|
||||
int out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetDebounceTime(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetDebounceTime(GpioPadSession *session, int ms) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetDebounceTime(ms));
|
||||
}
|
||||
|
||||
bool GetDebounceEnabled(GpioPadSession *session) {
|
||||
bool out;
|
||||
R_ABORT_UNLESS(GetInterface(session)->GetDebounceEnabled(std::addressof(out)));
|
||||
return out;
|
||||
}
|
||||
|
||||
void SetDebounceEnabled(GpioPadSession *session, bool en) {
|
||||
R_ABORT_UNLESS(GetInterface(session)->SetDebounceEnabled(en));
|
||||
}
|
||||
|
||||
Result BindInterrupt(os::SystemEventType *event, GpioPadSession *session) {
|
||||
AMS_ASSERT(session->_event == nullptr);
|
||||
|
||||
ams::sf::CopyHandle handle;
|
||||
R_TRY(GetInterface(session)->BindInterrupt(std::addressof(handle)));
|
||||
|
||||
os::AttachReadableHandleToSystemEvent(event, handle.GetValue(), true, os::EventClearMode_ManualClear);
|
||||
|
||||
session->_event = event;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void UnbindInterrupt(GpioPadSession *session) {
|
||||
AMS_ASSERT(session->_event != nullptr);
|
||||
|
||||
R_ABORT_UNLESS(GetInterface(session)->UnbindInterrupt());
|
||||
|
||||
os::DestroySystemEvent(session->_event);
|
||||
session->_event = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "gpio_remote_pad_session_impl.hpp"
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
class RemoteManagerImpl {
|
||||
public:
|
||||
RemoteManagerImpl() { /* ... */ }
|
||||
|
||||
~RemoteManagerImpl() { /* ... */ }
|
||||
public:
|
||||
/* Actual commands. */
|
||||
Result OpenSessionForDev(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast<u32>(pad_name))));
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenSessionForTest(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result IsWakeEventActive(ams::sf::Out<bool> out, gpio::GpioPadName pad_name) {
|
||||
return ::gpioIsWakeEventActive2(out.GetPointer(), static_cast<::GpioPadName>(static_cast<u32>(pad_name)));
|
||||
}
|
||||
|
||||
Result GetWakeEventActiveFlagSet(ams::sf::Out<gpio::WakeBitFlag> out) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetWakeEventActiveFlagSetForDebug(gpio::GpioPadName pad_name, bool is_enabled) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetWakePinDebugMode(s32 mode) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession2(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode));
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result IsWakeEventActive2(ams::sf::Out<bool> out, DeviceCode device_code) {
|
||||
return ::gpioIsWakeEventActive2(out.GetPointer(), device_code.GetInternalValue());
|
||||
}
|
||||
|
||||
Result SetWakeEventActiveFlagSetForDebug2(DeviceCode device_code, bool is_enabled) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetRetryValues(u32 arg0, u32 arg1) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
};
|
||||
static_assert(gpio::sf::IsIManager<RemoteManagerImpl>);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
class RemotePadSessionImpl {
|
||||
private:
|
||||
::GpioPadSession srv;
|
||||
public:
|
||||
RemotePadSessionImpl(::GpioPadSession &p) : srv(p) { /* ... */ }
|
||||
|
||||
~RemotePadSessionImpl() { ::gpioPadClose(std::addressof(this->srv)); }
|
||||
public:
|
||||
/* Actual commands. */
|
||||
Result SetDirection(gpio::Direction direction) {
|
||||
return ::gpioPadSetDirection(std::addressof(this->srv), static_cast<::GpioDirection>(static_cast<u32>(direction)));
|
||||
}
|
||||
|
||||
Result GetDirection(ams::sf::Out<gpio::Direction> out) {
|
||||
static_assert(sizeof(gpio::Direction) == sizeof(::GpioDirection));
|
||||
return ::gpioPadGetDirection(std::addressof(this->srv), reinterpret_cast<::GpioDirection *>(out.GetPointer()));
|
||||
}
|
||||
|
||||
Result SetInterruptMode(gpio::InterruptMode mode) {
|
||||
return ::gpioPadSetInterruptMode(std::addressof(this->srv), static_cast<::GpioInterruptMode>(static_cast<u32>(mode)));
|
||||
}
|
||||
|
||||
Result GetInterruptMode(ams::sf::Out<gpio::InterruptMode> out) {
|
||||
static_assert(sizeof(gpio::InterruptMode) == sizeof(::GpioInterruptMode));
|
||||
return ::gpioPadGetInterruptMode(std::addressof(this->srv), reinterpret_cast<::GpioInterruptMode *>(out.GetPointer()));
|
||||
}
|
||||
|
||||
Result SetInterruptEnable(bool enable) {
|
||||
return ::gpioPadSetInterruptEnable(std::addressof(this->srv), enable);
|
||||
}
|
||||
|
||||
Result GetInterruptEnable(ams::sf::Out<bool> out) {
|
||||
return ::gpioPadGetInterruptEnable(std::addressof(this->srv), out.GetPointer());
|
||||
}
|
||||
|
||||
Result GetInterruptStatus(ams::sf::Out<gpio::InterruptStatus> out) {
|
||||
static_assert(sizeof(gpio::InterruptStatus) == sizeof(::GpioInterruptStatus));
|
||||
return ::gpioPadGetInterruptStatus(std::addressof(this->srv), reinterpret_cast<::GpioInterruptStatus *>(out.GetPointer()));
|
||||
}
|
||||
|
||||
Result ClearInterruptStatus() {
|
||||
return ::gpioPadClearInterruptStatus(std::addressof(this->srv));
|
||||
}
|
||||
|
||||
Result SetValue(gpio::GpioValue value) {
|
||||
return ::gpioPadSetValue(std::addressof(this->srv), static_cast<::GpioValue>(static_cast<u32>(value)));
|
||||
}
|
||||
|
||||
Result GetValue(ams::sf::Out<gpio::GpioValue> out) {
|
||||
static_assert(sizeof(gpio::GpioValue) == sizeof(::GpioValue));
|
||||
return ::gpioPadGetValue(std::addressof(this->srv), reinterpret_cast<::GpioValue *>(out.GetPointer()));
|
||||
}
|
||||
|
||||
Result BindInterrupt(ams::sf::OutCopyHandle out) {
|
||||
::Event ev;
|
||||
R_TRY(::gpioPadBindInterrupt(std::addressof(this->srv), std::addressof(ev)));
|
||||
out.SetValue(ev.revent);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result UnbindInterrupt() {
|
||||
return ::gpioPadUnbindInterrupt(std::addressof(this->srv));
|
||||
}
|
||||
|
||||
Result SetDebounceEnabled(bool enable) {
|
||||
return ::gpioPadSetDebounceEnabled(std::addressof(this->srv), enable);
|
||||
}
|
||||
|
||||
Result GetDebounceEnabled(ams::sf::Out<bool> out) {
|
||||
return ::gpioPadGetDebounceEnabled(std::addressof(this->srv), out.GetPointer());
|
||||
}
|
||||
|
||||
Result SetDebounceTime(s32 ms) {
|
||||
return ::gpioPadSetDebounceTime(std::addressof(this->srv), ms);
|
||||
}
|
||||
|
||||
Result GetDebounceTime(ams::sf::Out<s32> out) {
|
||||
return ::gpioPadGetDebounceTime(std::addressof(this->srv), out.GetPointer());
|
||||
}
|
||||
|
||||
Result SetValueForSleepState(gpio::GpioValue value) {
|
||||
/* TODO: libnx bindings. */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result GetValueForSleepState(ams::sf::Out<gpio::GpioValue> out) {
|
||||
/* TODO: libnx bindings. */
|
||||
AMS_ABORT();
|
||||
}
|
||||
};
|
||||
static_assert(gpio::sf::IsIPadSession<RemotePadSessionImpl>);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user