fork/GramFirmware

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

Jonathan HaylettNintendo Switch USB support (#20)38b67d3

v0.1.2
2.8 KiB78 linesraw
1/************************************************************************
2MIT License
3
4Copyright (c) 2021 gdsports625@gmail.com
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*************************************************************************/
24#ifndef _TUCOMPOSITE_TUGAMEPAD_HPP
25#define _TUCOMPOSITE_TUGAMEPAD_HPP
26
27#include <Adafruit_TinyUSB.h>
28#include <Arduino.h>
29#include <TUCompositeHID.hpp>
30
31typedef struct TU_ATTR_PACKED {
32    uint16_t x; // X value of left analog stick
33    uint16_t y; // Y value of left analog stick
34    uint16_t z; // Value of analog left trigger
35    uint16_t rz; // Value of analog right trigger
36    uint16_t rx; // X value of right analog stick
37    uint16_t ry; // Y value of right analog stick
38    uint8_t hat; // Position value of the DPad/hat switch
39    uint16_t buttons; // Buttons mask for currently pressed buttons
40} gamepad_report_t;
41
42class TUGamepad {
43  public:
44    TUGamepad();
45
46    static void registerDescriptor();
47
48    void begin();
49    bool ready();
50    void resetInputs();
51    bool sendState();
52
53    void press(uint8_t button);
54    void release(uint8_t button);
55    void setButton(uint8_t button, bool pressed);
56    void releaseAll();
57
58    void buttons(uint16_t buttons);
59    void leftXAxis(uint8_t value);
60    void leftYAxis(uint8_t value);
61    void rightXAxis(uint8_t value);
62    void rightYAxis(uint8_t value);
63    void triggerLAnalog(uint8_t value);
64    void triggerRAnalog(uint8_t value);
65    void hatSwitch(hid_gamepad_hat_t direction);
66    void hatSwitch(bool left, bool right, bool down, bool up);
67
68  protected:
69    static const uint8_t _report_id = 1;
70    static uint8_t _descriptor[];
71
72    gamepad_report_t _report;
73
74  private:
75    static hid_gamepad_hat_t getHatPosition(bool left, bool right, bool down, bool up);
76};
77
78#endif