2014-04-17 00:58:36 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/hle/service/service.h"
|
2014-09-03 05:24:03 +00:00
|
|
|
#include "common/bit_field.h"
|
2014-04-17 00:58:36 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Namespace HID_User
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
// This service is used for interfacing to physical user controls.
|
|
|
|
// Uses include game pad controls, touchscreen, accelerometers, gyroscopes, and debug pad.
|
2014-04-17 00:58:36 +00:00
|
|
|
|
|
|
|
namespace HID_User {
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
/**
|
|
|
|
* Structure of a Pad controller state.
|
|
|
|
*/
|
|
|
|
struct PadState {
|
2014-09-03 05:24:03 +00:00
|
|
|
union {
|
|
|
|
u32 hex;
|
|
|
|
|
2014-09-04 01:12:58 +00: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;
|
|
|
|
|
|
|
|
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 05:24:03 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
/**
|
|
|
|
* Structure of a single entry in the PadData's Pad state history array.
|
|
|
|
*/
|
|
|
|
struct PadDataEntry {
|
|
|
|
PadState current_state;
|
|
|
|
PadState delta_additions;
|
|
|
|
PadState delta_removals;
|
2014-09-04 01:12:58 +00:00
|
|
|
|
|
|
|
s16 circle_pad_x;
|
|
|
|
s16 circle_pad_y;
|
|
|
|
};
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
/**
|
|
|
|
* Structure of all data related to the 3DS Pad.
|
|
|
|
*/
|
|
|
|
struct PadData {
|
2014-09-04 01:12:58 +00:00
|
|
|
s64 index_reset_ticks;
|
|
|
|
s64 index_reset_ticks_previous;
|
2014-09-09 04:46:02 +00:00
|
|
|
u32 index; // the index of the last updated Pad state history element
|
2014-09-04 01:12:58 +00:00
|
|
|
|
|
|
|
u32 pad1;
|
|
|
|
u32 pad2;
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
PadState current_state; // same as entries[index].current_state
|
2014-09-04 01:12:58 +00:00
|
|
|
u32 raw_circle_pad_data;
|
|
|
|
|
|
|
|
u32 pad3;
|
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
std::array<PadDataEntry, 8> entries; // Pad state history
|
2014-09-04 01:12:58 +00:00
|
|
|
};
|
|
|
|
|
2014-09-09 04:46:02 +00: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}};
|
|
|
|
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-04 01:12:58 +00:00
|
|
|
|
|
|
|
// Methods for updating the HID module's state
|
2014-09-09 04:46:02 +00:00
|
|
|
void PadButtonPress(PadState pad_state);
|
|
|
|
void PadButtonRelease(PadState pad_state);
|
|
|
|
void PadUpdateComplete();
|
2014-09-04 01:12:58 +00:00
|
|
|
|
2014-09-09 04:46:02 +00:00
|
|
|
/**
|
|
|
|
* HID service interface.
|
|
|
|
*/
|
2014-04-17 00:58:36 +00:00
|
|
|
class Interface : public Service::Interface {
|
|
|
|
public:
|
|
|
|
|
|
|
|
Interface();
|
|
|
|
|
|
|
|
~Interface();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string port name used by CTROS for the service
|
|
|
|
* @return Port name of service
|
|
|
|
*/
|
2014-08-18 03:03:22 +00:00
|
|
|
std::string GetPortName() const {
|
2014-04-17 00:58:36 +00:00
|
|
|
return "hid:USER";
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|