duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

digital_controller.h (1507B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors.
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "controller.h"
      7 
      8 #include <memory>
      9 
     10 class DigitalController final : public Controller
     11 {
     12 public:
     13   enum class Button : u8
     14   {
     15     Select = 0,
     16     L3 = 1,
     17     R3 = 2,
     18     Start = 3,
     19     Up = 4,
     20     Right = 5,
     21     Down = 6,
     22     Left = 7,
     23     L2 = 8,
     24     R2 = 9,
     25     L1 = 10,
     26     R1 = 11,
     27     Triangle = 12,
     28     Circle = 13,
     29     Cross = 14,
     30     Square = 15,
     31     Count
     32   };
     33 
     34   static const Controller::ControllerInfo INFO;
     35 
     36   DigitalController(u32 index);
     37   ~DigitalController() override;
     38 
     39   static std::unique_ptr<DigitalController> Create(u32 index);
     40 
     41   ControllerType GetType() const override;
     42 
     43   void Reset() override;
     44   bool DoState(StateWrapper& sw, bool apply_input_state) override;
     45 
     46   float GetBindState(u32 index) const override;
     47   void SetBindState(u32 index, float value) override;
     48   u32 GetButtonStateBits() const override;
     49 
     50   void ResetTransferState() override;
     51   bool Transfer(const u8 data_in, u8* data_out) override;
     52 
     53   void LoadSettings(SettingsInterface& si, const char* section, bool initial) override;
     54 
     55 private:
     56   enum class TransferState : u8
     57   {
     58     Idle,
     59     Ready,
     60     IDMSB,
     61     ButtonsLSB,
     62     ButtonsMSB
     63   };
     64 
     65   // buttons are active low
     66   u16 m_button_state = UINT16_C(0xFFFF);
     67 
     68   TransferState m_transfer_state = TransferState::Idle;
     69 
     70   bool m_popn_controller_mode = false;
     71 
     72   u8 GetButtonsLSBMask() const;
     73 };