2015-01-18 18:07:48 -05:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-16 20:58:36 -04:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
2015-02-26 21:13:08 -05:00
|
|
|
#include "core/hle/service/service.h"
|
2014-09-03 01:24:03 -04:00
|
|
|
#include "common/bit_field.h"
|
2014-04-16 20:58:36 -04:00
|
|
|
|
2015-01-11 00:43:29 -05:00
|
|
|
namespace Kernel {
|
|
|
|
class SharedMemory;
|
2015-01-23 00:11:25 -05:00
|
|
|
class Event;
|
2015-01-11 00:43:29 -05:00
|
|
|
}
|
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
namespace Service {
|
|
|
|
namespace HID {
|
2014-04-16 20:58:36 -04:00
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
// Handle to shared memory region designated to HID_User service
|
2015-01-11 00:43:29 -05:00
|
|
|
extern Kernel::SharedPtr<Kernel::SharedMemory> g_shared_mem;
|
2014-04-16 20:58:36 -04:00
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
// Event handles
|
2015-01-23 00:11:25 -05:00
|
|
|
extern Kernel::SharedPtr<Kernel::Event> g_event_pad_or_touch_1;
|
|
|
|
extern Kernel::SharedPtr<Kernel::Event> g_event_pad_or_touch_2;
|
|
|
|
extern Kernel::SharedPtr<Kernel::Event> g_event_accelerometer;
|
|
|
|
extern Kernel::SharedPtr<Kernel::Event> g_event_gyroscope;
|
|
|
|
extern Kernel::SharedPtr<Kernel::Event> g_event_debug_pad;
|
2014-04-16 20:58:36 -04:00
|
|
|
|
2014-11-19 03:49:13 -05:00
|
|
|
/**
|
2014-09-09 00:46:02 -04:00
|
|
|
* Structure of a Pad controller state.
|
|
|
|
*/
|
|
|
|
struct PadState {
|
2014-09-03 01:24:03 -04:00
|
|
|
union {
|
|
|
|
u32 hex;
|
|
|
|
|
2014-09-03 21:12:58 -04: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-21 18:50:16 -05: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-03 21:12:58 -04: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 01:24:03 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-09-09 00:46:02 -04:00
|
|
|
/**
|
2015-03-08 00:12:47 -05:00
|
|
|
* Structure of a single entry of Pad state history within HID shared memory
|
2014-09-09 00:46:02 -04:00
|
|
|
*/
|
|
|
|
struct PadDataEntry {
|
|
|
|
PadState current_state;
|
|
|
|
PadState delta_additions;
|
|
|
|
PadState delta_removals;
|
2014-09-03 21:12:58 -04:00
|
|
|
|
|
|
|
s16 circle_pad_x;
|
|
|
|
s16 circle_pad_y;
|
|
|
|
};
|
|
|
|
|
2014-09-09 00:46:02 -04:00
|
|
|
/**
|
2015-03-08 00:12:47 -05:00
|
|
|
* Structure of a single entry of touch state history within HID shared memory
|
2014-09-09 00:46:02 -04:00
|
|
|
*/
|
2015-03-08 00:12:47 -05:00
|
|
|
struct TouchDataEntry {
|
|
|
|
u16 x;
|
|
|
|
u16 y;
|
|
|
|
u32 data_valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure of data stored in HID shared memory
|
|
|
|
*/
|
|
|
|
struct SharedMem {
|
2015-03-08 21:21:25 -04:00
|
|
|
// "Pad data, this is used for buttons and the circle pad
|
2015-03-08 00:12:47 -05:00
|
|
|
struct {
|
|
|
|
s64 index_reset_ticks;
|
|
|
|
s64 index_reset_ticks_previous;
|
|
|
|
u32 index; // Index of the last updated pad state history element
|
|
|
|
|
|
|
|
INSERT_PADDING_BYTES(0x8);
|
|
|
|
|
|
|
|
PadState current_state; // Same as entries[index].current_state
|
|
|
|
u32 raw_circle_pad_data;
|
|
|
|
|
|
|
|
INSERT_PADDING_BYTES(0x4);
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-03-08 00:12:47 -05:00
|
|
|
std::array<PadDataEntry, 8> entries; // Pad state history
|
|
|
|
} pad;
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-03-08 21:21:25 -04:00
|
|
|
// Touchpad data, this is used for touchpad input
|
2015-03-08 00:12:47 -05:00
|
|
|
struct {
|
|
|
|
s64 index_reset_ticks;
|
|
|
|
s64 index_reset_ticks_previous;
|
|
|
|
u32 index; // Index of the last updated touch state history element
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-03-08 00:12:47 -05:00
|
|
|
INSERT_PADDING_BYTES(0xC);
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-03-08 00:12:47 -05:00
|
|
|
std::array<TouchDataEntry, 8> entries;
|
|
|
|
} touch;
|
2014-09-03 21:12:58 -04:00
|
|
|
};
|
|
|
|
|
2015-03-08 21:21:25 -04: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
|
|
|
|
#define ASSERT_REG_POSITION(field_name, position) \
|
|
|
|
static_assert(offsetof(SharedMem, field_name) == position * 4, \
|
|
|
|
"Field "#field_name" has invalid position")
|
|
|
|
|
|
|
|
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 00:46:02 -04:00
|
|
|
// Pre-defined PadStates for single button presses
|
|
|
|
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}};
|
2015-02-21 18:50:16 -05:00
|
|
|
|
|
|
|
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 00:46:02 -04:00
|
|
|
const PadState PAD_CIRCLE_RIGHT = {{1u << 28}};
|
|
|
|
const PadState PAD_CIRCLE_LEFT = {{1u << 29}};
|
|
|
|
const PadState PAD_CIRCLE_UP = {{1u << 30}};
|
|
|
|
const PadState PAD_CIRCLE_DOWN = {{1u << 31}};
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-02-26 21:13:08 -05:00
|
|
|
/**
|
|
|
|
* HID::GetIPCHandles service function
|
|
|
|
* Inputs:
|
|
|
|
* None
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Unused
|
|
|
|
* 3 : Handle to HID_User shared memory
|
|
|
|
* 4 : Event signaled by HID_User
|
|
|
|
* 5 : Event signaled by HID_User
|
|
|
|
* 6 : Event signaled by HID_User
|
|
|
|
* 7 : Gyroscope event
|
|
|
|
* 8 : Event signaled by HID_User
|
|
|
|
*/
|
|
|
|
void GetIPCHandles(Interface* self);
|
|
|
|
|
2015-03-08 00:13:49 -05:00
|
|
|
/**
|
|
|
|
* Sets a Pad state (button or button combo) as pressed
|
|
|
|
* @param pad_state PadState data indicating which buttons have been pressed
|
|
|
|
*/
|
2014-12-03 19:33:54 -05:00
|
|
|
void PadButtonPress(const PadState& pad_state);
|
2015-03-08 00:13:49 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a Pad state (button or button combo) as released
|
|
|
|
* @param pad_state PadState data indicating which buttons have been released
|
|
|
|
*/
|
2014-12-03 19:33:54 -05:00
|
|
|
void PadButtonRelease(const PadState& pad_state);
|
2015-03-08 00:13:49 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after all Pad changes to be included in this update have been made, including both Pad
|
|
|
|
* key changes and analog circle Pad changes.
|
|
|
|
*/
|
2014-09-09 00:46:02 -04:00
|
|
|
void PadUpdateComplete();
|
2014-09-03 21:12:58 -04:00
|
|
|
|
2015-03-08 03:05:56 -04:00
|
|
|
/**
|
|
|
|
* Signal that the touchpad has been pressed
|
|
|
|
* @param x Touchpad x-coordinate in bottom screen pixels (between 0 and 320)
|
|
|
|
* @param y Touchpad y-coordinate in bottom screen pixels (between 0 and 240)
|
|
|
|
*/
|
|
|
|
void TouchPress(u16 x, u16 y);
|
|
|
|
|
|
|
|
/// Signal that touchpad has been released
|
|
|
|
void TouchRelease();
|
|
|
|
|
|
|
|
/// Signal that touchpad updates have been completed
|
|
|
|
void TouchUpdateComplete();
|
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
void HIDInit();
|
|
|
|
void HIDShutdown();
|
2014-04-16 20:58:36 -04:00
|
|
|
|
2015-01-18 18:07:48 -05:00
|
|
|
}
|
|
|
|
}
|