2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> and contributors.
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2019-09-20 06:47:41 +00:00
|
|
|
#pragma once
|
2019-12-08 14:51:52 +00:00
|
|
|
#include "controller.h"
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-12-08 14:46:04 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2019-12-08 14:51:52 +00:00
|
|
|
class DigitalController final : public Controller
|
2019-09-20 06:47:41 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Button : u8
|
|
|
|
{
|
|
|
|
Select = 0,
|
|
|
|
L3 = 1,
|
|
|
|
R3 = 2,
|
|
|
|
Start = 3,
|
|
|
|
Up = 4,
|
|
|
|
Right = 5,
|
|
|
|
Down = 6,
|
|
|
|
Left = 7,
|
|
|
|
L2 = 8,
|
|
|
|
R2 = 9,
|
|
|
|
L1 = 10,
|
|
|
|
R1 = 11,
|
|
|
|
Triangle = 12,
|
|
|
|
Circle = 13,
|
|
|
|
Cross = 14,
|
2019-12-08 15:06:58 +00:00
|
|
|
Square = 15,
|
|
|
|
Count
|
2019-09-20 06:47:41 +00:00
|
|
|
};
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
static const Controller::ControllerInfo INFO;
|
|
|
|
|
|
|
|
DigitalController(u32 index);
|
2019-09-20 06:47:41 +00:00
|
|
|
~DigitalController() override;
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
static std::unique_ptr<DigitalController> Create(u32 index);
|
2019-12-14 14:17:43 +00:00
|
|
|
|
|
|
|
ControllerType GetType() const override;
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2020-04-25 15:18:15 +00:00
|
|
|
void Reset() override;
|
2020-12-16 14:09:32 +00:00
|
|
|
bool DoState(StateWrapper& sw, bool apply_input_state) override;
|
2020-04-25 15:18:15 +00:00
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
float GetBindState(u32 index) const override;
|
|
|
|
void SetBindState(u32 index, float value) override;
|
2020-12-06 05:47:00 +00:00
|
|
|
u32 GetButtonStateBits() const override;
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2019-09-29 15:07:38 +00:00
|
|
|
void ResetTransferState() override;
|
2019-09-20 06:47:41 +00:00
|
|
|
bool Transfer(const u8 data_in, u8* data_out) override;
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
void LoadSettings(SettingsInterface& si, const char* section) override;
|
2020-12-10 07:39:11 +00:00
|
|
|
|
2019-09-20 06:47:41 +00:00
|
|
|
private:
|
2019-10-26 12:33:23 +00:00
|
|
|
enum class TransferState : u8
|
|
|
|
{
|
|
|
|
Idle,
|
2021-02-21 23:20:31 +00:00
|
|
|
Ready,
|
2019-10-26 12:33:23 +00:00
|
|
|
IDMSB,
|
|
|
|
ButtonsLSB,
|
|
|
|
ButtonsMSB
|
|
|
|
};
|
2019-09-20 06:47:41 +00:00
|
|
|
|
|
|
|
// buttons are active low
|
|
|
|
u16 m_button_state = UINT16_C(0xFFFF);
|
|
|
|
|
2019-10-26 12:33:23 +00:00
|
|
|
TransferState m_transfer_state = TransferState::Idle;
|
2020-12-10 07:39:11 +00:00
|
|
|
|
|
|
|
bool m_popn_controller_mode = false;
|
|
|
|
|
|
|
|
u8 GetButtonsLSBMask() const;
|
2019-09-20 06:47:41 +00:00
|
|
|
};
|