Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-usb.h
Go to the documentation of this file.
1
37#ifndef _HDW_USB_
38#define _HDW_USB_
39
40//==============================================================================
41// Includes
42//==============================================================================
43
44#include <class/hid/hid.h>
45#include <class/midi/midi.h>
46#include "tinyusb.h"
47
48//==============================================================================
49// Enums
50//==============================================================================
51
71
85
86//==============================================================================
87// Structs
88//==============================================================================
89
91typedef struct TU_ATTR_PACKED
92{
93 uint16_t buttons;
94 uint8_t hat;
95 int8_t x;
96 int8_t y;
97 int8_t rx;
98 int8_t ry;
99 int8_t z;
100 int8_t rz;
102
103//==============================================================================
104// Function typedefs
105//==============================================================================
106
115typedef int16_t (*fnAdvancedUsbHandler)(uint8_t* buffer, uint16_t length, uint8_t isGet);
116
121typedef void (*fnSetSwadgeMode)(void* mode);
122
123//==============================================================================
124// Function Prototypes
125//==============================================================================
126
127void initUsb(fnSetSwadgeMode _setSwadgeMode, fnAdvancedUsbHandler _advancedUsbHandler, bool redirectPrintf);
128void deinitUsb(void);
129void sendUsbGamepadReport(hid_gamepad_report_t* report);
130void usbSetSwadgeMode(void* newMode);
131void initTusb(const tinyusb_config_t* tusb_cfg, const uint8_t* descriptor);
132bool tud_hid_gamepad_report_ns(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry,
133 uint8_t hat, uint16_t buttons);
134
135#endif
struct TU_ATTR_PACKED hid_gamepad_ns_report_t
HID Switch Gamepad Protocol Report.
uint8_t hat
Buttons mask for currently pressed buttons in the DPad/hat.
Definition hdw-usb.h:94
void initUsb(fnSetSwadgeMode _setSwadgeMode, fnAdvancedUsbHandler _advancedUsbHandler, bool redirectPrintf)
Initialize USB HID device.
Definition hdw-usb.c:152
int8_t x
Delta x movement of left analog-stick.
Definition hdw-usb.h:95
uint16_t buttons
Buttons mask for currently pressed buttons.
Definition hdw-usb.h:93
void usbSetSwadgeMode(void *newMode)
Set the Swadge mode to the given pointer.
Definition hdw-usb.c:353
void deinitUsb(void)
Deinitialize USB HID device Note, this does nothing as tinyusb_driver_uninstall() doesn't exist.
Definition hdw-usb.c:204
hid_gamepad_ns_hat_t
Switch Gamepad HAT/DPAD Buttons (from Linux input event codes)
Definition hdw-usb.h:74
@ GAMEPAD_NS_HAT_UP
DPAD_UP.
Definition hdw-usb.h:76
@ GAMEPAD_NS_HAT_UP_LEFT
DPAD_UP_LEFT.
Definition hdw-usb.h:83
@ GAMEPAD_NS_HAT_UP_RIGHT
DPAD_UP_RIGHT.
Definition hdw-usb.h:77
@ GAMEPAD_NS_HAT_DOWN
DPAD_DOWN.
Definition hdw-usb.h:80
@ GAMEPAD_NS_HAT_CENTERED
DPAD_CENTERED.
Definition hdw-usb.h:75
@ GAMEPAD_NS_HAT_DOWN_LEFT
DPAD_DOWN_LEFT.
Definition hdw-usb.h:81
@ GAMEPAD_NS_HAT_DOWN_RIGHT
DPAD_DOWN_RIGHT.
Definition hdw-usb.h:79
@ GAMEPAD_NS_HAT_RIGHT
DPAD_RIGHT.
Definition hdw-usb.h:78
@ GAMEPAD_NS_HAT_LEFT
DPAD_LEFT.
Definition hdw-usb.h:82
bool tud_hid_gamepad_report_ns(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons)
Send a USB gamepad report to a Switch.
Definition hdw-usb.c:269
hid_gamepad_ns_button_bm_t
Switch Gamepad Buttons Bitmap.
Definition hdw-usb.h:54
@ GAMEPAD_NS_BUTTON_X
Definition hdw-usb.h:58
@ GAMEPAD_NS_BUTTON_TL2
Definition hdw-usb.h:61
@ GAMEPAD_NS_BUTTON_HOME
Definition hdw-usb.h:67
@ GAMEPAD_NS_BUTTON_PLUS
Definition hdw-usb.h:64
@ GAMEPAD_NS_BUTTON_B
Definition hdw-usb.h:56
@ GAMEPAD_NS_BUTTON_TR2
Definition hdw-usb.h:62
@ GAMEPAD_NS_BUTTON_TL
Definition hdw-usb.h:59
@ GAMEPAD_NS_BUTTON_A
Definition hdw-usb.h:57
@ GAMEPAD_NS_BUTTON_CAPTURE
Definition hdw-usb.h:68
@ GAMEPAD_NS_BUTTON_TR
Definition hdw-usb.h:60
@ GAMEPAD_NS_BUTTON_THUMBR
Definition hdw-usb.h:66
@ GAMEPAD_NS_BUTTON_MINUS
Definition hdw-usb.h:63
@ GAMEPAD_NS_BUTTON_Z
Definition hdw-usb.h:69
@ GAMEPAD_NS_BUTTON_Y
Definition hdw-usb.h:55
@ GAMEPAD_NS_BUTTON_THUMBL
Definition hdw-usb.h:65
int8_t rx
Delta Rx movement of analog left trigger.
Definition hdw-usb.h:97
int8_t ry
Delta Ry movement of analog right trigger.
Definition hdw-usb.h:98
int8_t y
Delta y movement of left analog-stick.
Definition hdw-usb.h:96
void(* fnSetSwadgeMode)(void *mode)
Function typedef for a function which will switch the Swadge mode.
Definition hdw-usb.h:121
void sendUsbGamepadReport(hid_gamepad_report_t *report)
Send a USB gamepad report to the system.
Definition hdw-usb.c:214
int8_t rz
Delta Rz movement of right analog-joystick.
Definition hdw-usb.h:100
void initTusb(const tinyusb_config_t *tusb_cfg, const uint8_t *descriptor)
Initialize TinyUSB.
Definition hdw-usb.c:194
int8_t z
Delta z movement of right analog-joystick.
Definition hdw-usb.h:99
int16_t(* fnAdvancedUsbHandler)(uint8_t *buffer, uint16_t length, uint8_t isGet)
Function typedef for a callback which will send USB SET_REPORT and GET_REPORT messages to a Swadge mo...
Definition hdw-usb.h:115
HID Switch Gamepad Protocol Report.
Definition hdw-usb.h:92