2015-01-19 00:07:48 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-17 02:58:36 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-19 00:07:48 +01:00
|
|
|
#include <array>
|
2015-06-21 14:40:28 +02:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
#include <cstddef>
|
|
|
|
#endif
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/common_types.h"
|
2016-09-18 02:38:01 +02:00
|
|
|
#include "core/settings.h"
|
2015-01-11 06:43:29 +01:00
|
|
|
|
2015-01-19 00:07:48 +01:00
|
|
|
namespace Service {
|
2015-06-21 14:40:28 +02:00
|
|
|
|
|
|
|
class Interface;
|
|
|
|
|
2015-01-19 00:07:48 +01:00
|
|
|
namespace HID {
|
2014-04-17 02:58:36 +02:00
|
|
|
|
2014-11-19 09:49:13 +01:00
|
|
|
/**
|
2014-09-09 06:46:02 +02:00
|
|
|
* Structure of a Pad controller state.
|
|
|
|
*/
|
|
|
|
struct PadState {
|
2014-09-03 07:24:03 +02:00
|
|
|
union {
|
|
|
|
u32 hex;
|
|
|
|
|
2014-09-04 03:12:58 +02:00
|
|
|
BitField<0, 1, u32> a;
|
|
|
|
BitField<1, 1, u32> b;
|
|
|
|
BitField<2, 1, u32> select;
|
|
|
|
BitField<3, 1, u32> start;
|
|
|
|
BitField<4, 1, u32> right;
|
|
|
|
BitField<5, 1, u32> left;
|
|
|
|
BitField<6, 1, u32> up;
|
|
|
|
BitField<7, 1, u32> down;
|
|
|
|
BitField<8, 1, u32> r;
|
|
|
|
BitField<9, 1, u32> l;
|
|
|
|
BitField<10, 1, u32> x;
|
|
|
|
BitField<11, 1, u32> y;
|
|
|
|
|
2015-02-22 00:50:16 +01:00
|
|
|
BitField<14, 1, u32> zl;
|
|
|
|
BitField<15, 1, u32> zr;
|
|
|
|
|
|
|
|
BitField<20, 1, u32> touch;
|
|
|
|
|
|
|
|
BitField<24, 1, u32> c_right;
|
|
|
|
BitField<25, 1, u32> c_left;
|
|
|
|
BitField<26, 1, u32> c_up;
|
|
|
|
BitField<27, 1, u32> c_down;
|
2014-09-04 03:12:58 +02:00
|
|
|
BitField<28, 1, u32> circle_right;
|
|
|
|
BitField<29, 1, u32> circle_left;
|
|
|
|
BitField<30, 1, u32> circle_up;
|
|
|
|
BitField<31, 1, u32> circle_down;
|
2014-09-03 07:24:03 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-09-09 06:46:02 +02:00
|
|
|
/**
|
2015-03-08 06:12:47 +01:00
|
|
|
* Structure of a single entry of Pad state history within HID shared memory
|
2014-09-09 06:46:02 +02:00
|
|
|
*/
|
|
|
|
struct PadDataEntry {
|
|
|
|
PadState current_state;
|
|
|
|
PadState delta_additions;
|
|
|
|
PadState delta_removals;
|
2014-09-04 03:12:58 +02:00
|
|
|
|
|
|
|
s16 circle_pad_x;
|
|
|
|
s16 circle_pad_y;
|
|
|
|
};
|
|
|
|
|
2014-09-09 06:46:02 +02:00
|
|
|
/**
|
2015-03-08 06:12:47 +01:00
|
|
|
* Structure of a single entry of touch state history within HID shared memory
|
2014-09-09 06:46:02 +02:00
|
|
|
*/
|
2015-03-08 06:12:47 +01:00
|
|
|
struct TouchDataEntry {
|
2015-03-10 04:03:24 +01:00
|
|
|
u16 x; ///< Y-coordinate of a touchpad press on the lower screen
|
|
|
|
u16 y; ///< X-coordinate of a touchpad press on the lower screen
|
|
|
|
BitField<0, 7, u32> valid; ///< Set to 1 when this entry contains actual X/Y data, otherwise 0
|
2015-03-08 06:12:47 +01:00
|
|
|
};
|
|
|
|
|
2016-03-18 21:27:36 +01:00
|
|
|
/**
|
|
|
|
* Structure of a single entry of accelerometer state history within HID shared memory
|
|
|
|
*/
|
|
|
|
struct AccelerometerDataEntry {
|
|
|
|
s16 x;
|
|
|
|
s16 y;
|
|
|
|
s16 z;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure of a single entry of gyroscope state history within HID shared memory
|
|
|
|
*/
|
|
|
|
struct GyroscopeDataEntry {
|
|
|
|
s16 x;
|
|
|
|
s16 y;
|
|
|
|
s16 z;
|
|
|
|
};
|
|
|
|
|
2015-03-08 06:12:47 +01:00
|
|
|
/**
|
|
|
|
* Structure of data stored in HID shared memory
|
|
|
|
*/
|
|
|
|
struct SharedMem {
|
2015-03-10 04:03:24 +01:00
|
|
|
/// Pad data, this is used for buttons and the circle pad
|
2015-03-08 06:12:47 +01:00
|
|
|
struct {
|
2015-03-10 04:03:24 +01:00
|
|
|
s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0
|
|
|
|
s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks`
|
2016-09-18 02:38:01 +02:00
|
|
|
u32 index; ///< Index of the last updated pad state entry
|
2015-03-08 06:12:47 +01:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
INSERT_PADDING_WORDS(0x2);
|
2015-03-08 06:12:47 +01:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
PadState current_state; ///< Current state of the pad buttons
|
2015-03-08 06:12:47 +01:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
// TODO(bunnei): Implement `raw_circle_pad_data` field
|
|
|
|
u32 raw_circle_pad_data; ///< Raw (analog) circle pad data, before being converted
|
2014-09-04 03:12:58 +02:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
INSERT_PADDING_WORDS(0x1);
|
|
|
|
|
|
|
|
std::array<PadDataEntry, 8> entries; ///< Last 8 pad entries
|
2015-03-08 06:12:47 +01:00
|
|
|
} pad;
|
2014-09-04 03:12:58 +02:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
/// Touchpad data, this is used for touchpad input
|
2015-03-08 06:12:47 +01:00
|
|
|
struct {
|
2015-03-10 04:03:24 +01:00
|
|
|
s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0
|
|
|
|
s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks`
|
2016-09-18 02:38:01 +02:00
|
|
|
u32 index; ///< Index of the last updated touch entry
|
2015-03-10 04:03:24 +01:00
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x1);
|
2014-09-04 03:12:58 +02:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
// TODO(bunnei): Implement `raw_entry` field
|
|
|
|
TouchDataEntry raw_entry; ///< Raw (analog) touch data, before being converted
|
2014-09-04 03:12:58 +02:00
|
|
|
|
2015-03-10 04:03:24 +01:00
|
|
|
std::array<TouchDataEntry, 8> entries; ///< Last 8 touch entries, in pixel coordinates
|
2015-03-08 06:12:47 +01:00
|
|
|
} touch;
|
2016-03-18 21:27:36 +01:00
|
|
|
|
|
|
|
/// Accelerometer data
|
|
|
|
struct {
|
|
|
|
s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0
|
|
|
|
s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks`
|
2016-09-18 02:38:01 +02:00
|
|
|
u32 index; ///< Index of the last updated accelerometer entry
|
2016-03-18 21:27:36 +01:00
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x1);
|
|
|
|
|
|
|
|
AccelerometerDataEntry raw_entry;
|
|
|
|
INSERT_PADDING_BYTES(2);
|
|
|
|
|
|
|
|
std::array<AccelerometerDataEntry, 8> entries;
|
|
|
|
} accelerometer;
|
|
|
|
|
|
|
|
/// Gyroscope data
|
|
|
|
struct {
|
|
|
|
s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0
|
|
|
|
s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks`
|
2016-09-18 02:38:01 +02:00
|
|
|
u32 index; ///< Index of the last updated accelerometer entry
|
2016-03-18 21:27:36 +01:00
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x1);
|
|
|
|
|
|
|
|
GyroscopeDataEntry raw_entry;
|
|
|
|
INSERT_PADDING_BYTES(2);
|
|
|
|
|
|
|
|
std::array<GyroscopeDataEntry, 32> entries;
|
|
|
|
} gyroscope;
|
2014-09-04 03:12:58 +02:00
|
|
|
};
|
|
|
|
|
2016-03-25 09:39:59 +01:00
|
|
|
/**
|
|
|
|
* Structure of calibrate params that GetGyroscopeLowCalibrateParam returns
|
|
|
|
*/
|
|
|
|
struct GyroscopeCalibrateParam {
|
|
|
|
struct {
|
|
|
|
// TODO (wwylele): figure out the exact meaning of these params
|
|
|
|
s16 zero_point;
|
|
|
|
s16 positive_unit_point;
|
|
|
|
s16 negative_unit_point;
|
|
|
|
} x, y, z;
|
|
|
|
};
|
|
|
|
|
2015-03-09 02:21:25 +01:00
|
|
|
// TODO: MSVC does not support using offsetof() on non-static data members even though this
|
|
|
|
// is technically allowed since C++11. This macro should be enabled once MSVC adds
|
|
|
|
// support for that.
|
|
|
|
#ifndef _MSC_VER
|
2016-09-18 02:38:01 +02:00
|
|
|
#define ASSERT_REG_POSITION(field_name, position) \
|
|
|
|
static_assert(offsetof(SharedMem, field_name) == position * 4, \
|
|
|
|
"Field " #field_name " has invalid position")
|
2015-03-09 02:21:25 +01:00
|
|
|
|
|
|
|
ASSERT_REG_POSITION(pad.index_reset_ticks, 0x0);
|
|
|
|
ASSERT_REG_POSITION(touch.index_reset_ticks, 0x2A);
|
|
|
|
|
|
|
|
#undef ASSERT_REG_POSITION
|
|
|
|
#endif // !defined(_MSC_VER)
|
|
|
|
|
2014-09-09 06:46:02 +02:00
|
|
|
// Pre-defined PadStates for single button presses
|
2016-09-18 02:38:01 +02:00
|
|
|
const PadState PAD_NONE = {{0}};
|
|
|
|
const PadState PAD_A = {{1u << 0}};
|
|
|
|
const PadState PAD_B = {{1u << 1}};
|
|
|
|
const PadState PAD_SELECT = {{1u << 2}};
|
|
|
|
const PadState PAD_START = {{1u << 3}};
|
|
|
|
const PadState PAD_RIGHT = {{1u << 4}};
|
|
|
|
const PadState PAD_LEFT = {{1u << 5}};
|
|
|
|
const PadState PAD_UP = {{1u << 6}};
|
|
|
|
const PadState PAD_DOWN = {{1u << 7}};
|
|
|
|
const PadState PAD_R = {{1u << 8}};
|
|
|
|
const PadState PAD_L = {{1u << 9}};
|
|
|
|
const PadState PAD_X = {{1u << 10}};
|
|
|
|
const PadState PAD_Y = {{1u << 11}};
|
|
|
|
|
|
|
|
const PadState PAD_ZL = {{1u << 14}};
|
|
|
|
const PadState PAD_ZR = {{1u << 15}};
|
|
|
|
|
|
|
|
const PadState PAD_TOUCH = {{1u << 20}};
|
|
|
|
|
|
|
|
const PadState PAD_C_RIGHT = {{1u << 24}};
|
|
|
|
const PadState PAD_C_LEFT = {{1u << 25}};
|
|
|
|
const PadState PAD_C_UP = {{1u << 26}};
|
|
|
|
const PadState PAD_C_DOWN = {{1u << 27}};
|
2014-09-09 06:46:02 +02:00
|
|
|
const PadState PAD_CIRCLE_RIGHT = {{1u << 28}};
|
2016-09-18 02:38:01 +02:00
|
|
|
const PadState PAD_CIRCLE_LEFT = {{1u << 29}};
|
|
|
|
const PadState PAD_CIRCLE_UP = {{1u << 30}};
|
|
|
|
const PadState PAD_CIRCLE_DOWN = {{1u << 31}};
|
2014-09-04 03:12:58 +02:00
|
|
|
|
2015-02-27 03:13:08 +01:00
|
|
|
/**
|
|
|
|
* HID::GetIPCHandles service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
2015-03-13 22:36:19 +01:00
|
|
|
* 2 : IPC Command Structure translate-header
|
2015-05-23 00:55:27 +02:00
|
|
|
* 3 : Handle to HID shared memory
|
|
|
|
* 4 : Event signaled by HID
|
|
|
|
* 5 : Event signaled by HID
|
|
|
|
* 6 : Event signaled by HID
|
2015-02-27 03:13:08 +01:00
|
|
|
* 7 : Gyroscope event
|
2015-05-23 00:55:27 +02:00
|
|
|
* 8 : Event signaled by HID
|
2015-02-27 03:13:08 +01:00
|
|
|
*/
|
|
|
|
void GetIPCHandles(Interface* self);
|
|
|
|
|
2015-03-13 22:36:19 +01:00
|
|
|
/**
|
|
|
|
* HID::EnableAccelerometer service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
|
|
|
void EnableAccelerometer(Interface* self);
|
|
|
|
|
2015-05-23 00:55:27 +02:00
|
|
|
/**
|
|
|
|
* HID::DisableAccelerometer service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
|
|
|
void DisableAccelerometer(Interface* self);
|
|
|
|
|
2015-03-13 22:36:19 +01:00
|
|
|
/**
|
|
|
|
* HID::EnableGyroscopeLow service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
|
|
|
void EnableGyroscopeLow(Interface* self);
|
|
|
|
|
2015-05-23 00:55:27 +02:00
|
|
|
/**
|
|
|
|
* HID::DisableGyroscopeLow service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
|
|
|
void DisableGyroscopeLow(Interface* self);
|
|
|
|
|
2015-03-13 22:36:19 +01:00
|
|
|
/**
|
|
|
|
* HID::GetSoundVolume service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : u8 output value
|
|
|
|
*/
|
|
|
|
void GetSoundVolume(Interface* self);
|
|
|
|
|
2016-03-18 21:27:36 +01:00
|
|
|
/**
|
|
|
|
* HID::GetGyroscopeLowRawToDpsCoefficient service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : float output value
|
|
|
|
*/
|
|
|
|
void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HID::GetGyroscopeLowCalibrateParam service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
2016-03-25 09:39:59 +01:00
|
|
|
* 2~6 (18 bytes) : struct GyroscopeCalibrateParam
|
2016-03-18 21:27:36 +01:00
|
|
|
*/
|
|
|
|
void GetGyroscopeLowCalibrateParam(Service::Interface* self);
|
|
|
|
|
2015-03-09 05:14:59 +01:00
|
|
|
/// Checks for user input updates
|
2015-03-08 02:54:16 +01:00
|
|
|
void Update();
|
2015-03-08 08:05:56 +01:00
|
|
|
|
2015-03-09 05:14:59 +01:00
|
|
|
/// Initialize HID service
|
2015-03-08 02:54:16 +01:00
|
|
|
void Init();
|
2015-03-09 05:14:59 +01:00
|
|
|
|
|
|
|
/// Shutdown HID service
|
2015-03-08 02:54:16 +01:00
|
|
|
void Shutdown();
|
2015-01-19 00:07:48 +01:00
|
|
|
}
|
|
|
|
}
|