mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 06:41:50 +01:00
Refactor HID Shared Memory
This commit refactors and reorders a lot of the HID Shared Memory from the previous commits to be in line with the rest of the codebase.
This commit is contained in:
parent
b167abcdb7
commit
5fec7eefd0
2
.idea/codeStyles/Project.xml
generated
2
.idea/codeStyles/Project.xml
generated
@ -3,6 +3,8 @@
|
||||
<option name="RIGHT_MARGIN" value="400" />
|
||||
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
|
||||
<option name="FORMATTER_TAGS_ENABLED" value="true" />
|
||||
<option name="FORMATTER_ON_TAG" value="@fmt:on" />
|
||||
<option name="FORMATTER_OFF_TAG" value="@fmt:off" />
|
||||
<option name="SOFT_MARGINS" value="80,140" />
|
||||
<JetCodeStyleSettings>
|
||||
<option name="SPACE_BEFORE_TYPE_COLON" value="true" />
|
||||
|
@ -16,7 +16,7 @@ namespace skyline::audio {
|
||||
i32 d; //!< The coefficient for the fourth index
|
||||
};
|
||||
|
||||
// @formatter:off
|
||||
// @fmt:off
|
||||
constexpr std::array<LutEntry, 128> CurveLut0 = {{
|
||||
{6600, 19426, 6722, 3}, {6479, 19424, 6845, 9}, {6359, 19419, 6968, 15}, {6239, 19412, 7093, 22},
|
||||
{6121, 19403, 7219, 28}, {6004, 19391, 7345, 34}, {5888, 19377, 7472, 41}, {5773, 19361, 7600, 48},
|
||||
@ -118,7 +118,7 @@ namespace skyline::audio {
|
||||
{-76, 5004, 25919, 1912}, {-72, 4837, 25980, 2015}, {-67, 4673, 26035, 2120}, {-63, 4512, 26085, 2227},
|
||||
{-58, 4354, 26130, 2338}, {-54, 4199, 26169, 2451}, {-50, 4046, 26202, 2568}, {-46, 3897, 26230, 2688},
|
||||
{-42, 3751, 26253, 2811}, {-38, 3608, 26270, 2936}, {-34, 3467, 26281, 3064}, {-32, 3329, 26287, 3195}}};
|
||||
// @formatter:on
|
||||
// @fmt:on
|
||||
|
||||
std::vector<i16> Resampler::ResampleBuffer(const std::vector<i16> &inputBuffer, double ratio, u8 channelCount) {
|
||||
auto step = static_cast<u32>(ratio * 0x8000);
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "kernel/types/KSharedMemory.h"
|
||||
#include "input/common.h"
|
||||
#include "input/shared_mem.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
|
@ -1,29 +0,0 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "npad.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief Encapsulates hid shared memory
|
||||
*/
|
||||
struct HidSharedMemory {
|
||||
DebugPadSection debugPad; //!< The debug pad section
|
||||
TouchScreenSection touchScreen; //!< The touch screen section
|
||||
MouseSection mouse; //!< The mouse section
|
||||
KeyboardSection keyboard; //!< The keyboard section
|
||||
std::array<BasicXpadSection, 4> xpad; //!< The xpads section
|
||||
HomeButtonSection homeButton; //!< The home button section
|
||||
SleepButtonSection sleepButton; //!< The sleep button section
|
||||
CaptureButtonSection captureButton; //!< The capture button section
|
||||
std::array<InputDetectorSection, 16> inputDetector; //!< The input detectors section
|
||||
u64 _pad0_[0x80 * 0x10]; //!< Unique pad (<5.0.0)
|
||||
std::array<npad::NpadSection, constant::NpadCount> npad; //!< The npads section
|
||||
GestureSection gesture; //!< The gesture section
|
||||
ConsoleSixAxisSensorSection consoleSixAxisSensor; //!< The gyro/accel section
|
||||
u64 _pad1_[0x7BC];
|
||||
};
|
||||
static_assert(sizeof(HidSharedMemory) == 0x40000);
|
||||
}
|
@ -5,392 +5,153 @@
|
||||
|
||||
#include "shared_mem.h"
|
||||
|
||||
namespace skyline {
|
||||
namespace constant {
|
||||
constexpr u32 NpadBatteryFull = 2; //!< The full battery state of an npad
|
||||
constexpr u8 NpadCount = 10; //!< The number of npads in shared memory
|
||||
}
|
||||
namespace skyline::input::npad {
|
||||
enum class NpadAxisId {
|
||||
RX, //!< Right stick X
|
||||
RY, //!< Right stick Y
|
||||
LX, //!< Left stick X
|
||||
LY //!< Left stick Y
|
||||
};
|
||||
|
||||
namespace input::npad {
|
||||
union NpadButton {
|
||||
struct {
|
||||
bool a : 1; //!< The A button
|
||||
bool b : 1; //!< The B button
|
||||
bool x : 1; //!< The X button
|
||||
bool y : 1; //!< The Y button
|
||||
bool l3 : 1; //!< The L3 button
|
||||
bool r3 : 1; //!< The R3 button
|
||||
bool l : 1; //!< The L trigger
|
||||
bool r : 1; //!< The R button
|
||||
bool zl : 1; //!< The ZL trigger
|
||||
bool zr : 1; //!< The ZR trigger
|
||||
bool plus : 1; //!< The + button
|
||||
bool minus : 1; //!< The - button
|
||||
bool dpadLeft : 1; //!< D-Pad left
|
||||
bool dpadUp : 1; //!< D-Pad up
|
||||
bool dpadRight : 1; //!< D-Pad right
|
||||
bool dpadDown : 1; //!< D-Pad down
|
||||
bool leftStickLeft : 1; //!< Left stick left
|
||||
bool leftStickUp : 1; //!< Left stick up
|
||||
bool leftStickRight : 1; //!< Left stick right
|
||||
bool leftStickDown : 1; //!< Left stick down
|
||||
bool rightStickLeft : 1; //!< Right stick left
|
||||
bool rightStickUp : 1; //!< Right stick up
|
||||
bool rightStickRight : 1; //!< Right stick right
|
||||
bool rightStickDown : 1; //!< Right stick down
|
||||
bool leftSL : 1; //!< Left Joy-Con SL button
|
||||
bool leftSr : 1; //!< Left Joy-Con SR button
|
||||
bool rightSl : 1; //!< Right Joy-Con SL button
|
||||
bool rightSr : 1; //!< Right Joy-Con SR button
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadButton) == 0x8);
|
||||
enum class NpadButtonState : bool {
|
||||
Released = false, //!< Released button
|
||||
Pressed = true //!< Pressed button
|
||||
};
|
||||
|
||||
enum class NpadAxisId {
|
||||
RX, //!< Right stick X
|
||||
RY, //!< Right stick Y
|
||||
LX, //!< Left stick X
|
||||
LY //!< Left stick Y
|
||||
};
|
||||
/**
|
||||
* @brief This enumerates all the possible IDs for an NPad (https://switchbrew.org/wiki/HID_services#NpadIdType)
|
||||
*/
|
||||
enum class NpadId : u32 {
|
||||
Player1 = 0x0, //!< 1st Player
|
||||
Player2 = 0x1, //!< 2nd Player
|
||||
Player3 = 0x2, //!< 3rd Player
|
||||
Player4 = 0x3, //!< 4th Player
|
||||
Player5 = 0x4, //!< 5th Player
|
||||
Player6 = 0x5, //!< 6th Player
|
||||
Player7 = 0x6, //!< 7th Player
|
||||
Player8 = 0x7, //!< 8th Player
|
||||
Unknown = 0x10, //!< Unknown
|
||||
Handheld = 0x20 //!< Handheld mode
|
||||
};
|
||||
|
||||
enum class NpadButtonState : bool {
|
||||
Released = false, //!< Released button
|
||||
Pressed = true //!< Pressed button
|
||||
/**
|
||||
* @brief This enumerates all the orientations of the Joy-Con(s)
|
||||
*/
|
||||
enum class NpadJoyOrientation : u64 {
|
||||
Vertical = 0, //!< The Joy-Con is held vertically
|
||||
Horizontal = 1, //!< The Joy-Con is held horizontally
|
||||
};
|
||||
/**
|
||||
* @brief This holds all the NPad styles (https://switchbrew.org/wiki/HID_services#NpadStyleTag)
|
||||
*/
|
||||
union NpadStyleSet {
|
||||
struct {
|
||||
bool proController : 1; //!< The Pro Controller
|
||||
bool joyconHandheld : 1; //!< Joy-Cons in handheld mode
|
||||
bool joyconDual : 1; //!< Joy-Cons in a pair
|
||||
bool joyconLeft : 1; //!< Left Joy-Con only
|
||||
bool joyconRight : 1; //!< Right Joy-Con only
|
||||
bool gamecube : 1; //!< GameCube controller
|
||||
bool palma : 1; //!< Poké Ball Plus controller
|
||||
bool nes : 1; //!< NES controller
|
||||
bool nesHandheld : 1; //!< NES controller in handheld mode
|
||||
bool snes : 1; //!< SNES controller
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadStyleSet) == 0x4);
|
||||
|
||||
/**
|
||||
* @brief Converts the ID of an npad to the index in shared memory
|
||||
* @param id The ID of an npad
|
||||
* @return The index in shared memory
|
||||
*/
|
||||
u32 NpadIdToIndex(NpadId id);
|
||||
|
||||
/**
|
||||
* @brief Converts the index in shared memory to the ID of an npad
|
||||
* @param id The index in shared memory
|
||||
* @return The ID of the npad
|
||||
*/
|
||||
NpadId IndexToNpadId(u32 index);
|
||||
|
||||
class NpadDevice {
|
||||
private:
|
||||
NpadId id; //!< The ID of the npad
|
||||
NpadControllerType controllerType{NpadControllerType::None}; //!< The type of controller
|
||||
uint stateEntryIndex{}; //!< The index of the current state entry
|
||||
|
||||
NpadConnectionState connectionState{}; //!< The state of the connection
|
||||
NpadSection &shmemSection; //!< The section in HID shared memory for this controller
|
||||
|
||||
/**
|
||||
* @brief This holds the controller styles supported
|
||||
* @brief Updates headers for a new shared memory entry
|
||||
* @param controller The controller to operate on
|
||||
* @param lastStateEntryIndex The index of the previous state entry
|
||||
*/
|
||||
union NpadStyleSet {
|
||||
struct {
|
||||
bool proController : 1; //!< The Pro Controller
|
||||
bool joyconHandheld : 1; //!< Joy-Cons in handheld mode
|
||||
bool joyconDual : 1; //!< Joy-Cons in a pair
|
||||
bool joyconLeft : 1; //!< Left Joy-Con only
|
||||
bool joyconRight : 1; //!< Right Joy-Con only
|
||||
bool gamecube : 1; //!< GameCube controller
|
||||
bool palma : 1; //!< Poké Ball Plus controller
|
||||
bool nes : 1; //!< NES controller
|
||||
bool nesHandheld : 1; //!< NES controller in handheld mode
|
||||
bool snes : 1; //!< SNES controller
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadStyleSet) == 0x4);
|
||||
void UpdateHeaders(NpadControllerInfo &controller, uint lastStateEntryIndex);
|
||||
|
||||
/**
|
||||
* @brief This holds a Controller's ID (https://switchbrew.org/wiki/HID_services#NpadIdType)
|
||||
* @return The controller device info appropriate for the controllers type
|
||||
*/
|
||||
enum class NpadId : u32 {
|
||||
Player1 = 0x0, //!< 1st Player
|
||||
Player2 = 0x1, //!< 2nd Player
|
||||
Player3 = 0x2, //!< 3rd Player
|
||||
Player4 = 0x3, //!< 4th Player
|
||||
Player5 = 0x4, //!< 5th Player
|
||||
Player6 = 0x5, //!< 6th Player
|
||||
Player7 = 0x6, //!< 7th Player
|
||||
Player8 = 0x7, //!< 8th Player
|
||||
Unknown = 0x10, //!< Unknown
|
||||
Handheld = 0x20 //!< Handheld mode
|
||||
};
|
||||
NpadControllerInfo &GetControllerDeviceInfo();
|
||||
|
||||
public:
|
||||
bool supported{false}; //!< If the npad marked as supported
|
||||
|
||||
/**
|
||||
* @brief This denotes the orientation of the Joy-Con(s)
|
||||
* @param shmemSection A reference to the controllers shared memory region
|
||||
* @param id The ID of the npad
|
||||
*/
|
||||
enum class NpadJoyOrientation : u64 {
|
||||
Vertical = 0, //!< The Joy-Con is held vertically
|
||||
Horizontal = 1, //!< The Joy-Con is held horizontally
|
||||
Unset = 2 //!< Not set
|
||||
};
|
||||
NpadDevice(NpadSection &shmemSection, NpadId id);
|
||||
|
||||
/**
|
||||
* @brief This denotes the assignment of the Joy-Con(s)
|
||||
* @brief Sets the joycon assignment in shared memory
|
||||
* @param assignment The assignment to set
|
||||
*/
|
||||
enum class NpadJoyAssignment : u32 {
|
||||
Dual = 0, //!< Dual Joy-Cons
|
||||
Single = 1, //!< Single Joy-Con
|
||||
Unset = 2 //!< Not set
|
||||
};
|
||||
inline void SetAssignment(NpadJoyAssignment assignment) {
|
||||
shmemSection.header.assignment = assignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This denotes the colour read status of an npad
|
||||
* @brief Connects a controller to the guest
|
||||
* @param type The type of controller to connect
|
||||
*/
|
||||
enum class NpadColourReadStatus : u32 {
|
||||
Success = 0, //!< Success
|
||||
Invalid = 1, //!< Invalid color
|
||||
Disconnected = 2 //!< Controller not connected
|
||||
};
|
||||
void Connect(NpadControllerType type);
|
||||
|
||||
/**
|
||||
* @brief This denotes the type of an npad
|
||||
* @brief Disconnects the controller from the guest
|
||||
*/
|
||||
enum class NpadControllerType {
|
||||
None, //!< Nothing
|
||||
ProController, //!< A Pro Controller
|
||||
Handheld, //!< Handheld mode
|
||||
JoyconDual, //!< Dual Joy-Cons
|
||||
JoyconLeft, //!< Left Joy-Con
|
||||
JoyconRight, //!< Right Joy-Con
|
||||
Palma, //!< Poké Ball Plus
|
||||
};
|
||||
void Disconnect();
|
||||
|
||||
/**
|
||||
* @brief This denotes the connection state of an npad
|
||||
* @brief Changes a button's state on the virtual controller
|
||||
* @param button The button work on
|
||||
* @param state Whether to release or press the button
|
||||
*/
|
||||
union NpadConnectionState {
|
||||
struct {
|
||||
bool connected : 1; //!< Is connected
|
||||
bool handheld : 1; //!< Is in handheld mode
|
||||
bool leftJoyconConnected : 1; //!< Is the left Joy-Con connected
|
||||
bool leftJoyconHandheld : 1; //!< Is the left Joy-Con handheld
|
||||
bool rightJoyconConnected : 1; //!< Is the right Joy-Con connected
|
||||
bool rightJoyconHandheld : 1; //!< Is the right Joy-Con handheld
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadConnectionState) == 0x8);
|
||||
void SetButtonState(NpadButton button, NpadButtonState state);
|
||||
|
||||
/**
|
||||
* @brief This denotes the device type of an npad
|
||||
* @brief Sets an axis to a value on the virtual controller
|
||||
* @param axis The axis to change
|
||||
* @param value The value to use
|
||||
*/
|
||||
union NpadDeviceType {
|
||||
struct {
|
||||
bool fullKey : 1; //!< Pro/GC controller
|
||||
bool handheld : 1; //!< Handheld mode
|
||||
bool handheldLeft : 1; //!< Joy-Con/Famicom/NES left controller
|
||||
bool handheldRight : 1; //!< Joy-Con/Famicom/NES right controller
|
||||
bool joyconLeft : 1; //!< Left Joy-Con
|
||||
bool joyconRight : 1; //!< Right Joy-Con
|
||||
bool palma : 1; //!< Pokeball Plus controller
|
||||
bool larkLeftFamicom : 1; //!< Famicom left Joy-Con
|
||||
bool larkRightFamicom : 1;//!< Famicom right Joy-Con
|
||||
bool larkLeftNES : 1; //!< NES left Joy-Con
|
||||
bool larkRightNES : 1; //!< NES right Joy-Con
|
||||
u32 _unk1_ : 4;
|
||||
bool systemExt : 1; //!< Generic external controller
|
||||
u32 _unk2_ : 14;
|
||||
bool system : 1; //!< Generic controller
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadDeviceType) == 0x4);
|
||||
void SetAxisValue(NpadAxisId axis, int value);
|
||||
};
|
||||
|
||||
class CommonNpad {
|
||||
private:
|
||||
const DeviceState &state; //!< The state of the device
|
||||
|
||||
public:
|
||||
NpadStyleSet supportedStyles{}; //!< The supported style sets
|
||||
NpadJoyOrientation orientation{NpadJoyOrientation::Unset}; //!< The Joy-Con orientation to use
|
||||
|
||||
CommonNpad(const DeviceState &state);
|
||||
|
||||
/**
|
||||
* @brief This denotes the system properties of the npad
|
||||
* @brief Activates npad support
|
||||
*/
|
||||
union NpadSystemProperties {
|
||||
struct {
|
||||
bool powerInfo0Charging : 1; //!< Info 0 Charging
|
||||
bool powerInfo1Charging : 1; //!< Info 1 Charging
|
||||
bool powerInfo2Charging : 1; //!< Info 2 Charging
|
||||
bool powerInfo0PowerConnected : 1; //!< Info 0 Connected
|
||||
bool powerInfo1PowerConnected : 1; //!< Info 1 Connected
|
||||
bool powerInfo2PowerConnected : 1; //!< Info 2 Connected
|
||||
u64 _unk_ : 3;
|
||||
bool unsupportedButtonPressedSystem : 1; //!< Unsupported buttons are pressed on system controller
|
||||
bool unsupportedButtonPressedSystemExt : 1; //!< Unsupported buttons are pressed on system external controller
|
||||
bool ABXYButtonOriented : 1; //!< Are the ABXY Buttons oriented
|
||||
bool SLSRuttonOriented : 1; //!< Are the SLSR Buttons oriented
|
||||
bool plusButtonCapability : 1; //!< Does the + button exist
|
||||
bool minusButtonCapability : 1; //!< Does the - button exist
|
||||
bool directionalButtonsSupported : 1; //!< Does the controller have a D-Pad
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadSystemProperties) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief This denotes the system button properties of the npad
|
||||
*/
|
||||
union NpadSystemButtonProperties {
|
||||
struct {
|
||||
bool unintendedHomeButtonInputProtectionEnabled : 1; //!< Is unintended home button input protection enabled
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadSystemButtonProperties) == 0x4);
|
||||
|
||||
/**
|
||||
* @brief This denotes the colour of an npad
|
||||
*/
|
||||
struct NpadColour {
|
||||
u32 bodyColour; //!< The body colour
|
||||
u32 buttonColour; //!< The button colour
|
||||
};
|
||||
static_assert(sizeof(NpadColour) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief This is the header of an npad entry
|
||||
*/
|
||||
struct NpadHeader {
|
||||
NpadStyleSet styles; //!< The style set
|
||||
NpadJoyAssignment assignment; //!< The pad assignment
|
||||
|
||||
NpadColourReadStatus singleColourStatus; //!< The single colour status
|
||||
NpadColour singleColour; //!< The colours
|
||||
|
||||
NpadColourReadStatus dualColourStatus; //!< The dual colour status
|
||||
NpadColour rightColour; //!< The right colours
|
||||
NpadColour leftColour; //!< The left colours
|
||||
};
|
||||
static_assert(sizeof(NpadHeader) == 0x28);
|
||||
|
||||
/**
|
||||
* @brief This contains controller input data
|
||||
*/
|
||||
struct NpadController {
|
||||
NpadButton buttons; //!< The pressed buttons
|
||||
|
||||
u32 leftX; //!< The left stick X
|
||||
u32 leftY; //!< The left stick Y
|
||||
|
||||
u32 rightX; //!< The right stick X
|
||||
u32 rightY; //!< The right stick Y
|
||||
};
|
||||
static_assert(sizeof(NpadController) == 0x18);
|
||||
|
||||
/**
|
||||
* @brief This contains info about controller input data
|
||||
*/
|
||||
struct NpadControllerState {
|
||||
u64 globalTimestamp; //!< The global timestamp
|
||||
u64 localTimestamp; //!< The local timestamp
|
||||
NpadController controller; //!< The npad controller
|
||||
NpadConnectionState status; //!< The npad connection status
|
||||
};
|
||||
static_assert(sizeof(NpadControllerState) == 0x30);
|
||||
|
||||
/**
|
||||
* @brief This contains all the input states
|
||||
*/
|
||||
struct NpadControllerInfo {
|
||||
CommonHeader header; //!< The common data header
|
||||
std::array<NpadControllerState, 17> state; //!< The npad state
|
||||
};
|
||||
static_assert(sizeof(NpadControllerInfo) == 0x350);
|
||||
|
||||
/**
|
||||
* @brief An npad section in shared memory
|
||||
*/
|
||||
struct NpadSection {
|
||||
NpadHeader header; //!< The npad header
|
||||
|
||||
NpadControllerInfo fullKeyController; //!< The full key controller
|
||||
NpadControllerInfo handheldController; //!< The handheld controller
|
||||
NpadControllerInfo dualController; //!< The dual Joy-Con controller
|
||||
NpadControllerInfo leftController; //!< The left Joy-Con controller
|
||||
NpadControllerInfo rightController; //!< The right Joy-Con controller
|
||||
NpadControllerInfo pokeballController; //!< The Pokeball Plus controller
|
||||
NpadControllerInfo systemExtController; //!< The system external controller
|
||||
|
||||
u64 _unk_[0xE1 * 6]; //!< Unused sixaxis data
|
||||
|
||||
NpadDeviceType deviceType; //!< The device type
|
||||
|
||||
u32 _pad0_;
|
||||
|
||||
NpadSystemProperties properties; //!< The system properties
|
||||
NpadSystemButtonProperties buttonProperties; //!< The button properties
|
||||
|
||||
u32 batteryLevel[3]; //!< The battery level reported
|
||||
|
||||
u32 _pad1_[0x395];
|
||||
};
|
||||
static_assert(sizeof(NpadSection) == 0x5000);
|
||||
|
||||
/**
|
||||
* @brief Converts the ID of an npad to the index in shared memory
|
||||
* @param id The ID of an npad
|
||||
* @return The index in shared memory
|
||||
*/
|
||||
u32 NpadIdToIndex(NpadId id);
|
||||
|
||||
/**
|
||||
* @brief Converts the index in shared memory to the ID of an npad
|
||||
* @param id The index in shared memory
|
||||
* @return The ID of the npad
|
||||
*/
|
||||
NpadId IndexToNpadId(u32 index);
|
||||
|
||||
class NpadDevice {
|
||||
private:
|
||||
NpadId id; //!< The ID of the npad
|
||||
NpadControllerType controllerType{NpadControllerType::None}; //!< The type of controller
|
||||
uint stateEntryIndex{}; //!< The index of the current state entry
|
||||
|
||||
NpadConnectionState connectionState{}; //!< The state of the connection
|
||||
NpadSection &shmemSection; //!< The section in HID shared memory for this controller
|
||||
|
||||
/**
|
||||
* @brief Updates headers for a new shared memory entry
|
||||
* @param controller The controller to operate on
|
||||
* @param lastStateEntryIndex The index of the previous state entry
|
||||
*/
|
||||
void UpdateHeaders(NpadControllerInfo &controller, uint lastStateEntryIndex);
|
||||
|
||||
/**
|
||||
* @return The controller device info appropriate for the controllers type
|
||||
*/
|
||||
NpadControllerInfo &GetControllerDeviceInfo();
|
||||
|
||||
public:
|
||||
bool supported{false}; //!< If the npad marked as supported
|
||||
|
||||
/**
|
||||
* @param shmemSection A reference to the controllers shared memory region
|
||||
* @param id The ID of the npad
|
||||
*/
|
||||
NpadDevice(NpadSection &shmemSection, NpadId id);
|
||||
|
||||
/**
|
||||
* @brief Sets the joycon assignment in shared memory
|
||||
* @param assignment The assignment to set
|
||||
*/
|
||||
inline void SetAssignment(NpadJoyAssignment assignment) {
|
||||
shmemSection.header.assignment = assignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connects a controller to the guest
|
||||
* @param type The type of controller to connect
|
||||
*/
|
||||
void Connect(NpadControllerType type);
|
||||
|
||||
/**
|
||||
* @brief Disconnects the controller from the guest
|
||||
*/
|
||||
void Disconnect();
|
||||
|
||||
/**
|
||||
* @brief Changes a button's state on the virtual controller
|
||||
* @param button The button work on
|
||||
* @param state Whether to release or press the button
|
||||
*/
|
||||
void SetButtonState(NpadButton button, NpadButtonState state);
|
||||
|
||||
/**
|
||||
* @brief Sets an axis to a value on the virtual controller
|
||||
* @param axis The axis to change
|
||||
* @param value The value to use
|
||||
*/
|
||||
void SetAxisValue(NpadAxisId axis, int value);
|
||||
};
|
||||
|
||||
class CommonNpad {
|
||||
private:
|
||||
const DeviceState &state; //!< The state of the device
|
||||
|
||||
public:
|
||||
NpadStyleSet supportedStyles{}; //!< The supported style sets
|
||||
NpadJoyOrientation orientation{NpadJoyOrientation::Unset}; //!< The Joy-Con orientation to use
|
||||
|
||||
CommonNpad(const DeviceState &state);
|
||||
|
||||
/**
|
||||
* @brief Activates npad support
|
||||
*/
|
||||
void Activate();
|
||||
};
|
||||
}
|
||||
void Activate();
|
||||
};
|
||||
}
|
||||
|
27
app/src/main/cpp/skyline/input/sections/BasicXpad.h
Normal file
27
app/src/main/cpp/skyline/input/sections/BasicXpad.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of an entry for BasicXpad (https://switchbrew.org/wiki/HID_Shared_Memory#BasicXpadState)
|
||||
*/
|
||||
struct BasicXpadState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 _unk_[0x4];
|
||||
};
|
||||
static_assert(sizeof(BasicXpadState) == 0x28);
|
||||
|
||||
/**
|
||||
* @brief The structure of the BasicXpad section (https://switchbrew.org/wiki/HID_Shared_Memory#BasicXpad)
|
||||
*/
|
||||
struct BasicXpadSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<BasicXpadState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x27];
|
||||
};
|
||||
static_assert(sizeof(BasicXpadSection) == 0x400);
|
||||
}
|
27
app/src/main/cpp/skyline/input/sections/Button.h
Normal file
27
app/src/main/cpp/skyline/input/sections/Button.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The state structure for all Button sections (HomeButton, SleepButton, CaptureButton)
|
||||
*/
|
||||
struct ButtonState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 _unk_[0x2];
|
||||
};
|
||||
static_assert(sizeof(ButtonState) == 0x18);
|
||||
|
||||
/**
|
||||
* @brief The section structure for all Button sections (HomeButton, SleepButton, CaptureButton)
|
||||
*/
|
||||
struct ButtonSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<ButtonState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x9];
|
||||
};
|
||||
static_assert(sizeof(ButtonSection) == 0x200);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of the ConsoleSixAxisSensor section (https://switchbrew.org/wiki/HID_Shared_Memory#ConsoleSixAxisSensor)
|
||||
* @note This is seemingly used to calibrate the gyroscope bias values over time
|
||||
*/
|
||||
struct ConsoleSixAxisSensorSection {
|
||||
u64 timestamp; //!< The timestamp in samples
|
||||
bool resting; //!< If the sensors are at rest or not (The calibration is performed when the devices are at rest)
|
||||
u8 _pad0_[0x3];
|
||||
u32 verticalizationError; //!< The error in verticalization ?
|
||||
u32 gyroBias[3]; //!< The gyroscope's sensor bias in all axis
|
||||
u32 _pad1_;
|
||||
};
|
||||
static_assert(sizeof(ConsoleSixAxisSensorSection) == 0x20);
|
||||
}
|
27
app/src/main/cpp/skyline/input/sections/DebugPad.h
Normal file
27
app/src/main/cpp/skyline/input/sections/DebugPad.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of an entry for DebugPad (https://switchbrew.org/wiki/HID_Shared_Memory#DebugPadState)
|
||||
*/
|
||||
struct DebugPadState {
|
||||
u64 timestamp; //!< The total timestamp in ticks
|
||||
u8 _unk_[0x20];
|
||||
};
|
||||
static_assert(sizeof(DebugPadState) == 0x28);
|
||||
|
||||
/**
|
||||
* @brief The structure of the DebugPad section (https://switchbrew.org/wiki/HID_Shared_Memory#DebugPad)
|
||||
*/
|
||||
struct DebugPadSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<DebugPadState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x27];
|
||||
};
|
||||
static_assert(sizeof(DebugPadSection) == 0x400);
|
||||
}
|
27
app/src/main/cpp/skyline/input/sections/Gesture.h
Normal file
27
app/src/main/cpp/skyline/input/sections/Gesture.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of an entry for Gesture (https://switchbrew.org/wiki/HID_Shared_Memory#GestureState)
|
||||
*/
|
||||
struct GestureState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 _unk_[0xC];
|
||||
};
|
||||
static_assert(sizeof(GestureState) == 0x68);
|
||||
|
||||
/**
|
||||
* @brief The structure of the Gesture section (https://switchbrew.org/wiki/HID_Shared_Memory#Gesture)
|
||||
*/
|
||||
struct GestureSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<GestureState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x1F];
|
||||
};
|
||||
static_assert(sizeof(GestureSection) == 0x800);
|
||||
}
|
27
app/src/main/cpp/skyline/input/sections/InputDetector.h
Normal file
27
app/src/main/cpp/skyline/input/sections/InputDetector.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of an entry for InputDetector (https://switchbrew.org/wiki/HID_Shared_Memory#InputDetectorState)
|
||||
*/
|
||||
struct InputDetectorState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 _unk_[0x2];
|
||||
};
|
||||
static_assert(sizeof(InputDetectorState) == 0x18);
|
||||
|
||||
/**
|
||||
* @brief The structure of the InputDetector section (https://switchbrew.org/wiki/HID_Shared_Memory#InputDetector)
|
||||
*/
|
||||
struct InputDetectorSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<InputDetectorState, 2> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x6];
|
||||
};
|
||||
static_assert(sizeof(InputDetectorSection) == 0x80);
|
||||
}
|
50
app/src/main/cpp/skyline/input/sections/Keyboard.h
Normal file
50
app/src/main/cpp/skyline/input/sections/Keyboard.h
Normal file
@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief This enumerates all the modifier keys that can be used
|
||||
*/
|
||||
union ModifierKey {
|
||||
struct {
|
||||
bool LControl : 1; //!< Left Control Key
|
||||
bool LShift : 1; //!< Left Shift Key
|
||||
bool LAlt : 1; //!< Left Alt Key
|
||||
bool LWindows : 1; //!< Left Windows Key
|
||||
bool RControl : 1; //!< Right Control Key
|
||||
bool RShift : 1; //!< Right Shift Key
|
||||
bool RAlt : 1; //!< Right Alt Key
|
||||
bool RWindows : 1; //!< Right Windows Key
|
||||
bool CapsLock : 1; //!< Caps-Lock Key
|
||||
bool ScrLock : 1; //!< Scroll-Lock Key
|
||||
bool NumLock : 1; //!< Num-Lock Key
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The structure of an entry for Keyboard (https://switchbrew.org/wiki/HID_Shared_Memory#KeyboardState)
|
||||
*/
|
||||
struct KeyboardState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 localTimestamp; //!< The local timestamp in samples
|
||||
|
||||
ModifierKey modifers; //!< The state of any modifier keys
|
||||
std::bitset<256> keysDown; //!< A bit-array of the state of all the keys
|
||||
};
|
||||
static_assert(sizeof(KeyboardState) == 0x38);
|
||||
|
||||
/**
|
||||
* @brief The structure of the Keyboard section (https://switchbrew.org/wiki/HID_Shared_Memory#Keyboard)
|
||||
*/
|
||||
struct KeyboardSection {
|
||||
CommonHeader header;
|
||||
std::array<KeyboardState, constant::HidEntryCount> entries;
|
||||
u64 _pad_[0x5];
|
||||
};
|
||||
static_assert(sizeof(KeyboardSection) == 0x400);
|
||||
}
|
38
app/src/main/cpp/skyline/input/sections/Mouse.h
Normal file
38
app/src/main/cpp/skyline/input/sections/Mouse.h
Normal file
@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief The structure of an entry for Mouse (https://switchbrew.org/wiki/HID_Shared_Memory#MouseState)
|
||||
*/
|
||||
struct MouseState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 localTimestamp; //!< The local timestamp in samples
|
||||
|
||||
u32 positionX; //!< The X position of the mouse
|
||||
u32 positionY; //!< The Y position of the mouse
|
||||
|
||||
u32 deltaX; //!< The change in the X-axis value
|
||||
u32 deltaY; //!< The change in the Y-axis value
|
||||
|
||||
u32 scrollChangeY; //!< The amount scrolled in the Y-axis since the last entry
|
||||
u32 scrollChangeX; //!< The amount scrolled in the X-axis since the last entry
|
||||
|
||||
std::bitset<64> buttons; //!< The state of the mouse buttons as a bit-array
|
||||
};
|
||||
static_assert(sizeof(MouseState) == 0x30);
|
||||
|
||||
/**
|
||||
* @brief The structure of the Mouse section (https://switchbrew.org/wiki/HID_Shared_Memory#Mouse)
|
||||
*/
|
||||
struct MouseSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<MouseState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x16];
|
||||
};
|
||||
static_assert(sizeof(MouseSection) == 0x400);
|
||||
}
|
289
app/src/main/cpp/skyline/input/sections/Npad.h
Normal file
289
app/src/main/cpp/skyline/input/sections/Npad.h
Normal file
@ -0,0 +1,289 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
// @fmt:off
|
||||
/**
|
||||
* @brief This enumerates all of the types of an NPad controller
|
||||
*/
|
||||
enum class NpadControllerType : u32 {
|
||||
None = 0, //!< No Controller
|
||||
ProController = 0b1, //!< Pro Controller
|
||||
Handheld = 0b10, //!< Handheld Controllers
|
||||
JoyconDual = 0b100, //!< Dual Joy-Cons Controller
|
||||
JoyconLeft = 0b1000, //!< Left Joy-Con Controller
|
||||
JoyconRight = 0b10000, //!< Right Joy-Con Controller
|
||||
};
|
||||
// @fmt:on
|
||||
|
||||
/**
|
||||
* @brief This enumerates all the possible assignments of the Joy-Con(s)
|
||||
*/
|
||||
enum class NpadJoyAssignment : u32 {
|
||||
Dual = 0, //!< Dual Joy-Cons
|
||||
Single = 1, //!< Single Joy-Con
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This enumerates the status codes for reading NPad colors
|
||||
*/
|
||||
enum class NpadColorReadStatus : u32 {
|
||||
Success = 0, //!< The color was read successfully
|
||||
Invalid = 1, //!< The color read in wasn't valid
|
||||
Disconnected = 2 //!< The controller isn't connected
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This structure stores the color of a controller
|
||||
*/
|
||||
struct NpadColor {
|
||||
u32 bodyColor; //!< The color of the controller's body
|
||||
u32 buttonColor; //!< The color of the controller's buttons
|
||||
};
|
||||
static_assert(sizeof(NpadColor) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief The structure of the NPad headers (https://switchbrew.org/wiki/HID_Shared_Memory#NpadStateHeader)
|
||||
*/
|
||||
struct NpadHeader {
|
||||
NpadControllerType type; //!< The type of this controller
|
||||
NpadJoyAssignment assignment; //!< The Joy-Con assignment of this controller
|
||||
|
||||
NpadColorReadStatus singleColorStatus; //!< The status of reading color from a single controller (Single Joy-Con or Pro Controller)
|
||||
NpadColor singleColor; //!< The color of the single controller
|
||||
|
||||
NpadColorReadStatus dualColorStatus; //!< The status of reading color from dual controllers (Dual Joy-Cons)
|
||||
NpadColor rightColor; //!< The color of the right Joy-Con
|
||||
NpadColor leftColor; //!< The color of the left Joy-Con
|
||||
};
|
||||
static_assert(sizeof(NpadHeader) == 0x28);
|
||||
|
||||
/**
|
||||
* @brief This is a bit-field of all the buttons on an NPad (https://switchbrew.org/wiki/HID_Shared_Memory#NpadButton)
|
||||
*/
|
||||
union NpadButton {
|
||||
struct {
|
||||
bool a : 1; //!< The A button
|
||||
bool b : 1; //!< The B button
|
||||
bool x : 1; //!< The X button
|
||||
bool y : 1; //!< The Y button
|
||||
bool leftStick : 1; //!< The Left-Stick button
|
||||
bool rightStick : 1; //!< The Right-Stick button
|
||||
bool l : 1; //!< The L trigger
|
||||
bool r : 1; //!< The R button
|
||||
bool zl : 1; //!< The ZL trigger
|
||||
bool zr : 1; //!< The ZR trigger
|
||||
bool plus : 1; //!< The + button
|
||||
bool minus : 1; //!< The - button
|
||||
bool dpadLeft : 1; //!< D-Pad left
|
||||
bool dpadUp : 1; //!< D-Pad up
|
||||
bool dpadRight : 1; //!< D-Pad right
|
||||
bool dpadDown : 1; //!< D-Pad down
|
||||
bool leftStickLeft : 1; //!< Left stick left
|
||||
bool leftStickUp : 1; //!< Left stick up
|
||||
bool leftStickRight : 1; //!< Left stick right
|
||||
bool leftStickDown : 1; //!< Left stick down
|
||||
bool rightStickLeft : 1; //!< Right stick left
|
||||
bool rightStickUp : 1; //!< Right stick up
|
||||
bool rightStickRight : 1; //!< Right stick right
|
||||
bool rightStickDown : 1; //!< Right stick down
|
||||
bool leftSL : 1; //!< Left Joy-Con SL button
|
||||
bool leftSr : 1; //!< Left Joy-Con SR button
|
||||
bool rightSl : 1; //!< Right Joy-Con SL button
|
||||
bool rightSr : 1; //!< Right Joy-Con SR button
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadButton) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief This structure holds data about the state of the connection with the controller
|
||||
*/
|
||||
union NpadConnectionState {
|
||||
struct {
|
||||
bool connected : 1; //!< If the controller is connected
|
||||
bool handheld : 1; //!< If the controller is in handheld mode
|
||||
bool leftJoyconConnected : 1; //!< If the left Joy-Con is connected
|
||||
bool leftJoyconHandheld : 1; //!< If the left Joy-Con is handheld
|
||||
bool rightJoyconConnected : 1; //!< If the right Joy-Con is connected
|
||||
bool rightJoyconHandheld : 1; //!< If the right Joy-Con is handheld
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadConnectionState) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief This structure contains data about the controller's current state (https://switchbrew.org/wiki/HID_Shared_Memory#NpadHandheldState)
|
||||
*/
|
||||
struct NpadControllerState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 localTimestamp; //!< The local timestamp in samples
|
||||
|
||||
NpadButton buttons; //!< The state of the buttons
|
||||
|
||||
i32 leftX; //!< The left stick X (32768 to -32768)
|
||||
i32 leftY; //!< The left stick Y (32768 to -32768)
|
||||
|
||||
i32 rightX; //!< The right stick X (32768 to -32768)
|
||||
i32 rightY; //!< The right stick Y (32768 to -32768)
|
||||
|
||||
NpadConnectionState status; //!< The connection status of the controller
|
||||
};
|
||||
static_assert(sizeof(NpadControllerState) == 0x30);
|
||||
|
||||
/**
|
||||
* @brief This structure contains the header and entries for the controller input
|
||||
*/
|
||||
struct NpadControllerInfo {
|
||||
CommonHeader header; //!< The header for this controller
|
||||
std::array<NpadControllerState, constant::HidEntryCount> state; //!< An array of all of the entries
|
||||
};
|
||||
static_assert(sizeof(NpadControllerInfo) == 0x350);
|
||||
|
||||
/**
|
||||
* @brief This structure is used to hold a single sample of 3D data from the IMU
|
||||
*/
|
||||
struct SixaxisVector {
|
||||
float x; //!< The data in the X-axis
|
||||
float y; //!< The data in the Y-axis
|
||||
float z; //!< The data in the Z-axis
|
||||
};
|
||||
static_assert(sizeof(SixaxisVector) == 0xC);
|
||||
|
||||
/**
|
||||
* @brief This structure contains data about the state of the controller's IMU (Sixaxis) (https://switchbrew.org/wiki/HID_Shared_Memory#NpadSixAxisSensorHandheldState)
|
||||
*/
|
||||
struct NpadSixaxisState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 _unk0_;
|
||||
u64 localTimestamp; //!< The local timestamp in samples
|
||||
|
||||
SixaxisVector accelerometer; //!< The data from the accelerometer
|
||||
SixaxisVector gyroscope; //!< The data from the gyroscope
|
||||
SixaxisVector _unk1_; //!< The data from an unknown sensor
|
||||
std::array<SixaxisVector, 3> orientation; //!< The orientation basis data as a matrix
|
||||
|
||||
u64 _unk2_; //!< This is always 1
|
||||
};
|
||||
static_assert(sizeof(NpadSixaxisState) == 0x68);
|
||||
|
||||
/**
|
||||
* @brief This structure contains header and entries for the IMU (Sixaxis) data
|
||||
*/
|
||||
struct NpadSixaxisInfo {
|
||||
CommonHeader header; //!< The header for the controller's IMU data
|
||||
std::array<NpadSixaxisState, constant::HidEntryCount> state; //!< An array of all of the entries
|
||||
};
|
||||
static_assert(sizeof(NpadSixaxisInfo) == 0x708);
|
||||
|
||||
/**
|
||||
* @brief This is a bit-field of all the device types (https://switchbrew.org/wiki/HID_services#DeviceType)
|
||||
*/
|
||||
union NpadDeviceType {
|
||||
struct {
|
||||
bool fullKey : 1; //!< Pro/GC controller
|
||||
bool debugPad : 1; //!< Debug controller
|
||||
bool handheldLeft : 1; //!< Left Joy-Con controller in handheld mode
|
||||
bool handheldRight : 1; //!< Right Joy-Con controller in handheld mode
|
||||
bool joyconLeft : 1; //!< Left Joy-Con controller
|
||||
bool joyconRight : 1; //!< Right Joy-Con controller
|
||||
bool palma : 1; //!< Poké Ball Plus controller
|
||||
bool famicomLeft : 1; //!< Famicom left controller
|
||||
bool famicomRight : 1;//!< Famicom right controller
|
||||
bool nesLeft : 1; //!< NES left controller
|
||||
bool nesRight : 1; //!< NES right controller
|
||||
bool handheldFamicomLeft : 1; //!< Famicom left controller in handheld mode
|
||||
bool handheldFamicomRight : 1;//!< Famicom right controller in handheld mode
|
||||
bool handheldNesLeft : 1; //!< NES left controller in handheld mode
|
||||
bool handheldNesRight : 1; //!< NES right controller in handheld mode
|
||||
bool lucia : 1; //!< SNES controller
|
||||
u32 _unk_ : 15;
|
||||
bool system : 1; //!< Generic controller
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadDeviceType) == 0x4);
|
||||
|
||||
/**
|
||||
* @brief This structure holds the system properties of this NPad (https://switchbrew.org/wiki/HID_Shared_Memory#NpadSystemProperties)
|
||||
*/
|
||||
union NpadSystemProperties {
|
||||
struct {
|
||||
bool singleCharging : 1; //!< Info 0 Charging
|
||||
bool leftCharging : 1; //!< Info 1 Charging
|
||||
bool rightCharging : 1; //!< Info 2 Charging
|
||||
bool singlePowerConnected : 1; //!< Info 0 Connected
|
||||
bool leftPowerConnected : 1; //!< Info 1 Connected
|
||||
bool rightPowerConnected : 1; //!< Info 2 Connected
|
||||
u64 _unk_ : 3;
|
||||
bool unsupportedButtonPressedSystem : 1; //!< Unsupported buttons are pressed on system controller
|
||||
bool unsupportedButtonPressedSystemExt : 1; //!< Unsupported buttons are pressed on system external controller
|
||||
bool ABXYButtonOriented : 1; //!< Are the ABXY Buttons oriented
|
||||
bool SLSRuttonOriented : 1; //!< Are the SLSR Buttons oriented
|
||||
bool plusButtonCapability : 1; //!< Does the + button exist
|
||||
bool minusButtonCapability : 1; //!< Does the - button exist
|
||||
bool directionalButtonsSupported : 1; //!< Does the controller have a D-Pad
|
||||
};
|
||||
u64 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadSystemProperties) == 0x8);
|
||||
|
||||
/**
|
||||
* @brief This structure holds data about the System Buttons (Home, Sleep and Capture) on an NPad (https://switchbrew.org/wiki/HID_Shared_Memory#NpadSystemButtonProperties)
|
||||
*/
|
||||
union NpadSystemButtonProperties {
|
||||
struct {
|
||||
bool unintendedHomeButtonInputProtectionEnabled : 1; //!< If the Unintended Home Button Input Protection is enabled or not
|
||||
};
|
||||
u32 raw;
|
||||
};
|
||||
static_assert(sizeof(NpadSystemButtonProperties) == 0x4);
|
||||
|
||||
/**
|
||||
* @brief This enumerates all the possible values for the NPad's battery level
|
||||
*/
|
||||
enum class NpadBatteryLevel : u32 {
|
||||
Empty = 0, //!< The battery is empty
|
||||
Low = 1, //!< The battery is nearly empty
|
||||
Medium = 2, //!< The battery is fairly full
|
||||
High = 3, //!< The battery is almost full
|
||||
Full = 4, //!< The battery is 100% full
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The structure of the Npad section (https://switchbrew.org/wiki/HID_Shared_Memory#NpadState)
|
||||
*/
|
||||
struct NpadSection {
|
||||
NpadHeader header; //!< The header for this section
|
||||
|
||||
NpadControllerInfo fullKeyController; //!< The Pro/GC controller data
|
||||
NpadControllerInfo handheldController; //!< The Handheld controller data
|
||||
NpadControllerInfo dualController; //!< The Dual Joy-Con controller data
|
||||
NpadControllerInfo leftController; //!< The Left Joy-Con controller data
|
||||
NpadControllerInfo rightController; //!< The Right Joy-Con controller data
|
||||
NpadControllerInfo palmaController; //!< The Poké Ball Plus controller data
|
||||
NpadControllerInfo systemExtController; //!< The System External controller data
|
||||
|
||||
NpadSixaxisInfo fullKeySixaxis; //!< The Pro/GC IMU data
|
||||
NpadSixaxisInfo handheldSixaxis; //!< The Handheld IMU data
|
||||
NpadSixaxisInfo dualLeftSixaxis; //!< The Left Joy-Con in dual mode IMU data
|
||||
NpadSixaxisInfo dualRightSixaxis; //!< The Left Joy-Con in dual mode IMU data
|
||||
NpadSixaxisInfo leftSixaxis; //!< The Left Joy-Con IMU data
|
||||
NpadSixaxisInfo rightSixaxis; //!< The Right Joy-Con IMU data
|
||||
|
||||
NpadDeviceType deviceType; //!< The device type of this controller
|
||||
|
||||
u32 _pad0_;
|
||||
|
||||
NpadSystemProperties systemProperties; //!< The system properties of this controller
|
||||
NpadSystemButtonProperties buttonProperties; //!< The system button properties of this controller
|
||||
NpadBatteryLevel batteryLevel[3]; //!< The battery level of this controller
|
||||
|
||||
u32 _pad1_[0x395];
|
||||
};
|
||||
static_assert(sizeof(NpadSection) == 0x5000);
|
||||
}
|
50
app/src/main/cpp/skyline/input/sections/TouchScreen.h
Normal file
50
app/src/main/cpp/skyline/input/sections/TouchScreen.h
Normal file
@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace skyline::input {
|
||||
/**
|
||||
* @brief This structure holds information about a single touch point
|
||||
*/
|
||||
struct TouchScreenStateData {
|
||||
u64 timestamp; //!< The timestamp in samples
|
||||
u32 _pad0_;
|
||||
|
||||
u32 index; //!< The index of this touch
|
||||
|
||||
u32 positionX; //!< The X position of this touch
|
||||
u32 positionY; //!< The Y position of this touch
|
||||
|
||||
u32 diameterX; //!< The diameter of the touch on the X-axis
|
||||
u32 diameterY; //!< The diameter of the touch on the Y-axis
|
||||
|
||||
u32 angle; //!< The angle of the touch
|
||||
u32 _pad1_;
|
||||
};
|
||||
static_assert(sizeof(TouchScreenStateData) == 0x28);
|
||||
|
||||
/**
|
||||
* @brief The structure of an entry for TouchScreen (https://switchbrew.org/wiki/HID_Shared_Memory#TouchScreenState)
|
||||
*/
|
||||
struct TouchScreenState {
|
||||
u64 globalTimestamp; //!< The global timestamp in samples
|
||||
u64 localTimestamp; //!< The local timestamp in samples
|
||||
|
||||
u64 touchCount; //!< The amount of active touch instances
|
||||
std::array<TouchScreenStateData, 16> data;
|
||||
};
|
||||
static_assert(sizeof(TouchScreenState) == 0x298);
|
||||
|
||||
/**
|
||||
* @brief The structure of the TouchScreen section (https://switchbrew.org/wiki/HID_Shared_Memory#TouchScreen)
|
||||
*/
|
||||
struct TouchScreenSection {
|
||||
CommonHeader header; //!< The header for this section
|
||||
std::array<TouchScreenState, constant::HidEntryCount> entries; //!< An array of all of the entries
|
||||
u64 _pad_[0x79];
|
||||
};
|
||||
static_assert(sizeof(TouchScreenSection) == 0x3000);
|
||||
}
|
28
app/src/main/cpp/skyline/input/sections/common.h
Normal file
28
app/src/main/cpp/skyline/input/sections/common.h
Normal file
@ -0,0 +1,28 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <common.h>
|
||||
|
||||
namespace skyline {
|
||||
namespace constant {
|
||||
constexpr u8 HidEntryCount = 17; //!< The amount of entries in each HID device
|
||||
constexpr u8 NpadCount = 10; //!< The number of npads in shared memory
|
||||
constexpr u32 NpadBatteryFull = 2; //!< The full battery state of an npad
|
||||
}
|
||||
|
||||
namespace input {
|
||||
/**
|
||||
* @brief This is the common part of the header for all sections
|
||||
*/
|
||||
struct CommonHeader {
|
||||
u64 timestamp; //!< The timestamp of the latest entry in ticks
|
||||
u64 entryCount; //!< The number of entries (17)
|
||||
u64 currentEntry; //!< The index of the latest entry
|
||||
u64 maxEntry; //!< The maximum entry index (16)
|
||||
};
|
||||
static_assert(sizeof(CommonHeader) == 0x20);
|
||||
}
|
||||
}
|
@ -3,214 +3,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <common.h>
|
||||
#include "sections/DebugPad.h"
|
||||
#include "sections/TouchScreen.h"
|
||||
#include "sections/Mouse.h"
|
||||
#include "sections/Keyboard.h"
|
||||
#include "sections/BasicXpad.h"
|
||||
#include "sections/Button.h"
|
||||
#include "sections/InputDetector.h"
|
||||
#include "sections/Npad.h"
|
||||
#include "sections/Gesture.h"
|
||||
#include "sections/ConsoleSixAxisSensor.h"
|
||||
|
||||
namespace skyline {
|
||||
namespace constant {
|
||||
constexpr u8 HidEntryCount = 17; //!< The amount of state entries in each hid device
|
||||
}
|
||||
|
||||
namespace input {
|
||||
struct CommonHeader {
|
||||
u64 timestamp;
|
||||
u64 entryCount;
|
||||
u64 currentEntry;
|
||||
u64 maxEntry;
|
||||
/**
|
||||
* @brief This encapsulates HID Shared Memory (https://switchbrew.org/wiki/HID_Shared_Memory)
|
||||
*/
|
||||
struct HidSharedMemory {
|
||||
DebugPadSection debugPad; //!< The DebugPad section (https://switchbrew.org/wiki/HID_Shared_Memory#DebugPad)
|
||||
TouchScreenSection touchScreen; //!< The TouchScreen section (https://switchbrew.org/wiki/HID_Shared_Memory#TouchScreen)
|
||||
MouseSection mouse; //!< The Mouse section (https://switchbrew.org/wiki/HID_Shared_Memory#Mouse)
|
||||
KeyboardSection keyboard; //!< The Keyboard section (https://switchbrew.org/wiki/HID_Shared_Memory#Keyboard)
|
||||
std::array<BasicXpadSection, 4> xpad; //!< The XPad (XBOX Pad) section (https://switchbrew.org/wiki/HID_Shared_Memory#BasicXpad)
|
||||
ButtonSection homeButton; //!< The HomeButton section (https://switchbrew.org/wiki/HID_Shared_Memory#HomeButton)
|
||||
ButtonSection sleepButton; //!< The SleepButton section (https://switchbrew.org/wiki/HID_Shared_Memory#SleepButton)
|
||||
ButtonSection captureButton; //!< The CaptureButton section (https://switchbrew.org/wiki/HID_Shared_Memory#CaptureButton)
|
||||
std::array<InputDetectorSection, 16> inputDetector; //!< The InputDetector section (https://switchbrew.org/wiki/HID_Shared_Memory#InputDetector)
|
||||
u64 _pad0_[0x80 * 0x10]; //!< This was UniquePad in FW 5.0.0 and below but has been removed (https://switchbrew.org/wiki/HID_Shared_Memory#UniquePad)
|
||||
std::array<NpadSection, constant::NpadCount> npad; //!< The NPad (Nintendo Pad) section (https://switchbrew.org/wiki/HID_Shared_Memory#Npad)
|
||||
GestureSection gesture; //!< The Gesture section (https://switchbrew.org/wiki/HID_Shared_Memory#Gesture)
|
||||
ConsoleSixAxisSensorSection consoleSixAxisSensor; //!< The SixAxis (Gyroscope/Accelerometer) section on FW 5.0.0 and above (https://switchbrew.org/wiki/HID_Shared_Memory#ConsoleSixAxisSensor)
|
||||
u64 _pad1_[0x7BC];
|
||||
};
|
||||
static_assert(sizeof(CommonHeader) == 0x20);
|
||||
|
||||
|
||||
|
||||
struct DebugPadState {
|
||||
u64 timestamp;
|
||||
u8 _unk_[0x20];
|
||||
};
|
||||
static_assert(sizeof(DebugPadState) == 0x28);
|
||||
|
||||
struct DebugPadSection {
|
||||
CommonHeader header;
|
||||
std::array<DebugPadState, constant::HidEntryCount> state;
|
||||
u64 _pad_[0x27];
|
||||
};
|
||||
static_assert(sizeof(DebugPadSection) == 0x400);
|
||||
|
||||
|
||||
|
||||
struct TouchScreenStateData {
|
||||
u64 timestamp;
|
||||
u32 _pad0_;
|
||||
|
||||
u32 index;
|
||||
|
||||
u32 positionX;
|
||||
u32 positionY;
|
||||
|
||||
u32 diameterX;
|
||||
u32 diameterY;
|
||||
|
||||
u32 angle;
|
||||
u32 _pad1_;
|
||||
};
|
||||
static_assert(sizeof(TouchScreenStateData) == 0x28);
|
||||
|
||||
struct TouchScreenState {
|
||||
u64 globalTimestamp;
|
||||
u64 localTimestamp;
|
||||
|
||||
u64 touchCount;
|
||||
std::array<TouchScreenStateData, 16> data;
|
||||
};
|
||||
static_assert(sizeof(TouchScreenState) == 0x298);
|
||||
|
||||
struct TouchScreenSection {
|
||||
CommonHeader header;
|
||||
std::array<TouchScreenState, constant::HidEntryCount> state;
|
||||
u64 _pad_[0x79];
|
||||
|
||||
};
|
||||
static_assert(sizeof(TouchScreenSection) == 0x3000);
|
||||
|
||||
|
||||
|
||||
struct MouseState {
|
||||
u64 globalTimestamp;
|
||||
u64 localTimestamp;
|
||||
|
||||
u32 positionX;
|
||||
u32 positionY;
|
||||
|
||||
u32 changeX;
|
||||
u32 changeY;
|
||||
|
||||
u32 scrollChangeY;
|
||||
u32 scrollChangeX;
|
||||
|
||||
u64 buttons;
|
||||
};
|
||||
static_assert(sizeof(MouseState) == 0x30);
|
||||
|
||||
struct MouseSection {
|
||||
CommonHeader header;
|
||||
std::array<MouseState, constant::HidEntryCount> state;
|
||||
u64 _pad_[22];
|
||||
};
|
||||
static_assert(sizeof(MouseSection) == 0x400);
|
||||
|
||||
|
||||
|
||||
struct KeyboardState {
|
||||
u64 globalTimestamp;
|
||||
u64 localTimestamp;
|
||||
|
||||
u64 modifers;
|
||||
u64 keysDown[4];
|
||||
};
|
||||
static_assert(sizeof(KeyboardState) == 0x38);
|
||||
|
||||
struct KeyboardSection {
|
||||
CommonHeader header;
|
||||
std::array<KeyboardState, constant::HidEntryCount> state;
|
||||
u64 _pad_[5];
|
||||
};
|
||||
static_assert(sizeof(KeyboardSection) == 0x400);
|
||||
|
||||
|
||||
|
||||
struct BasicXpadState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[4];
|
||||
};
|
||||
static_assert(sizeof(BasicXpadState) == 0x28);
|
||||
|
||||
struct BasicXpadSection {
|
||||
CommonHeader header;
|
||||
std::array<BasicXpadState, constant::HidEntryCount> state;
|
||||
u64 _pad_[39];
|
||||
};
|
||||
static_assert(sizeof(BasicXpadSection) == 0x400);
|
||||
|
||||
|
||||
|
||||
struct HomeButtonState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[2];
|
||||
};
|
||||
static_assert(sizeof(HomeButtonState) == 0x18);
|
||||
|
||||
struct HomeButtonSection {
|
||||
CommonHeader header;
|
||||
std::array<HomeButtonState, constant::HidEntryCount> state;
|
||||
u64 _pad_[9];
|
||||
};
|
||||
static_assert(sizeof(HomeButtonSection) == 0x200);
|
||||
|
||||
|
||||
|
||||
struct SleepButtonState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[2];
|
||||
};
|
||||
static_assert(sizeof(SleepButtonState) == 0x18);
|
||||
|
||||
struct SleepButtonSection {
|
||||
CommonHeader header;
|
||||
std::array<SleepButtonState, constant::HidEntryCount> state;
|
||||
u64 _pad_[9];
|
||||
};
|
||||
static_assert(sizeof(SleepButtonSection) == 0x200);
|
||||
|
||||
|
||||
|
||||
struct CaptureButtonState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[2];
|
||||
};
|
||||
static_assert(sizeof(CaptureButtonState) == 0x18);
|
||||
|
||||
struct CaptureButtonSection {
|
||||
CommonHeader header;
|
||||
std::array<CaptureButtonState, constant::HidEntryCount> state;
|
||||
u64 _pad_[9];
|
||||
};
|
||||
static_assert(sizeof(CaptureButtonSection) == 0x200);
|
||||
|
||||
|
||||
struct InputDetectorState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[2];
|
||||
};
|
||||
static_assert(sizeof(InputDetectorState) == 0x18);
|
||||
|
||||
struct InputDetectorSection {
|
||||
CommonHeader header;
|
||||
std::array<InputDetectorState, 2> state;
|
||||
u64 _pad_[6];
|
||||
};
|
||||
static_assert(sizeof(InputDetectorSection) == 0x80);
|
||||
|
||||
|
||||
struct GestureState {
|
||||
u64 globalTimestamp;
|
||||
u64 _unk_[12];
|
||||
};
|
||||
static_assert(sizeof(GestureState) == 0x68);
|
||||
|
||||
struct GestureSection {
|
||||
CommonHeader header;
|
||||
std::array<GestureState, constant::HidEntryCount> state;
|
||||
u64 _pad_[31];
|
||||
};
|
||||
static_assert(sizeof(GestureSection) == 0x800);
|
||||
|
||||
struct ConsoleSixAxisSensorSection {
|
||||
u64 timestamp;
|
||||
bool resting : 1;
|
||||
u32 _pad0_ : 3;
|
||||
u32 verticalizationError;
|
||||
u32 gyroBias[3];
|
||||
u32 _pad1_;
|
||||
};
|
||||
static_assert(sizeof(ConsoleSixAxisSensorSection) == 0x20);
|
||||
static_assert(sizeof(HidSharedMemory) == 0x40000);
|
||||
}
|
||||
}
|
||||
|
@ -236,8 +236,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {
|
||||
KeyEvent.KEYCODE_BUTTON_B to NpadButton.B,
|
||||
KeyEvent.KEYCODE_BUTTON_X to NpadButton.X,
|
||||
KeyEvent.KEYCODE_BUTTON_Y to NpadButton.Y,
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBL to NpadButton.L3,
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBR to NpadButton.R3,
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBL to NpadButton.LeftStick,
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBR to NpadButton.RightStick,
|
||||
KeyEvent.KEYCODE_BUTTON_L1 to NpadButton.L,
|
||||
KeyEvent.KEYCODE_BUTTON_R1 to NpadButton.R,
|
||||
KeyEvent.KEYCODE_BUTTON_L2 to NpadButton.ZL,
|
||||
|
@ -13,8 +13,8 @@ enum class NpadButton : ButtonId {
|
||||
B,
|
||||
X,
|
||||
Y,
|
||||
L3,
|
||||
R3,
|
||||
LeftStick,
|
||||
RightStick,
|
||||
L,
|
||||
R,
|
||||
ZL,
|
||||
|
Loading…
Reference in New Issue
Block a user