fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

Jonathan HaylettNintendo Switch USB support (#20)38b67d3

v0.1.2
1.3 KiB60 linesraw
1#ifndef _COMMS_NINTENDOSWITCHBACKEND_HPP
2#define _COMMS_NINTENDOSWITCHBACKEND_HPP
3
4#include "core/CommunicationBackend.hpp"
5
6typedef enum {
7    SWITCH_HAT_UP,
8    SWITCH_HAT_UP_RIGHT,
9    SWITCH_HAT_RIGHT,
10    SWITCH_HAT_DOWN_RIGHT,
11    SWITCH_HAT_DOWN,
12    SWITCH_HAT_DOWN_LEFT,
13    SWITCH_HAT_LEFT,
14    SWITCH_HAT_UP_LEFT,
15    SWITCH_HAT_CENTERED,
16} switch_gamepad_hat_t;
17
18typedef struct __attribute__((packed, aligned(1))) {
19    bool y : 1;
20    bool b : 1;
21    bool a : 1;
22    bool x : 1;
23    bool l : 1;
24    bool r : 1;
25    bool zl : 1;
26    bool zr : 1;
27    bool minus : 1;
28    bool plus : 1;
29    bool l3 : 1;
30    bool r3 : 1;
31    bool home : 1;
32    bool capture : 1;
33    uint8_t reserved0 : 2;
34    switch_gamepad_hat_t hat;
35    uint8_t lx;
36    uint8_t ly;
37    uint8_t rx;
38    uint8_t ry;
39    uint8_t reserved1;
40} switch_gamepad_report_t;
41
42class NintendoSwitchBackend : public CommunicationBackend {
43  public:
44    NintendoSwitchBackend(InputSource **input_sources, size_t input_source_count);
45    ~NintendoSwitchBackend();
46
47    static void RegisterDescriptor();
48
49    void SendReport();
50
51  protected:
52    static const uint8_t _report_id = 0;
53    static uint8_t _descriptor[];
54
55    switch_gamepad_report_t _report;
56
57    static switch_gamepad_hat_t GetHatPosition(bool left, bool right, bool down, bool up);
58};
59
60#endif