Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
The USB component uses Espressif's USB Device Driver. It's based on the TinyUSB Human Interface Device Example.
The Swadge primarily functions as a USB gamepad.
The Swadge can also exchange USB data with a host by setting a Swadge mode's swadgeMode_t.fnAdvancedUSB function pointer. If that is set, then USB SET_REPORT
and GET_REPORT
messages with report_id
== 173 will be sent to that function.
For development purposes, the Swadge has advanced USB capabilities to load and execute code from RAM. These capabilites can be read about in advanced_usb_control.h.
You don't need to call initUsb() or deinitUsb(). The system does this the appropriate time.
sendUsbGamepadReport() should be called whenever there is an updated gamepad state to be sent to the host.
usbSetSwadgeMode() should NOT be called, except during development.
Go to the source code of this file.
Data Structures | |
struct | TU_ATTR_PACKED |
HID Switch Gamepad Protocol Report. More... | |
Typedefs | |
typedef struct TU_ATTR_PACKED | hid_gamepad_ns_report_t |
HID Switch Gamepad Protocol Report. | |
typedef 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 mode. | |
typedef void(* | fnSetSwadgeMode) (void *mode) |
Function typedef for a function which will switch the Swadge mode. | |
Enumerations | |
enum | hid_gamepad_ns_button_bm_t { GAMEPAD_NS_BUTTON_Y = 0x01 , GAMEPAD_NS_BUTTON_B = 0x02 , GAMEPAD_NS_BUTTON_A = 0x04 , GAMEPAD_NS_BUTTON_X = 0x08 , GAMEPAD_NS_BUTTON_TL = 0x10 , GAMEPAD_NS_BUTTON_TR = 0x20 , GAMEPAD_NS_BUTTON_TL2 = 0x40 , GAMEPAD_NS_BUTTON_TR2 = 0x80 , GAMEPAD_NS_BUTTON_MINUS = 0x100 , GAMEPAD_NS_BUTTON_PLUS = 0x200 , GAMEPAD_NS_BUTTON_THUMBL = 0x400 , GAMEPAD_NS_BUTTON_THUMBR = 0x800 , GAMEPAD_NS_BUTTON_HOME = 0x1000 , GAMEPAD_NS_BUTTON_CAPTURE = 0x2000 , GAMEPAD_NS_BUTTON_Z = 0x4000 } |
Switch Gamepad Buttons Bitmap. More... | |
enum | hid_gamepad_ns_hat_t { GAMEPAD_NS_HAT_CENTERED = 8 , GAMEPAD_NS_HAT_UP = 0 , GAMEPAD_NS_HAT_UP_RIGHT = 1 , GAMEPAD_NS_HAT_RIGHT = 2 , GAMEPAD_NS_HAT_DOWN_RIGHT = 3 , GAMEPAD_NS_HAT_DOWN = 4 , GAMEPAD_NS_HAT_DOWN_LEFT = 5 , GAMEPAD_NS_HAT_LEFT = 6 , GAMEPAD_NS_HAT_UP_LEFT = 7 } |
Switch Gamepad HAT/DPAD Buttons (from Linux input event codes) More... | |
Functions | |
void | initUsb (fnSetSwadgeMode _setSwadgeMode, fnAdvancedUsbHandler _advancedUsbHandler, bool redirectPrintf) |
Initialize USB HID device. | |
void | deinitUsb (void) |
Deinitialize USB HID device Note, this does nothing as tinyusb_driver_uninstall() doesn't exist. | |
void | sendUsbGamepadReport (hid_gamepad_report_t *report) |
Send a USB gamepad report to the system. | |
void | usbSetSwadgeMode (void *newMode) |
Set the Swadge mode to the given pointer. | |
void | initTusb (const tinyusb_config_t *tusb_cfg, const uint8_t *descriptor) |
Initialize TinyUSB. | |
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. | |
struct TU_ATTR_PACKED |
typedef struct TU_ATTR_PACKED hid_gamepad_ns_report_t |
HID Switch Gamepad Protocol Report.
typedef 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 mode.
buffer | Pointer to full command |
length | Total length of the buffer (command ID included) |
isGet | 0 if this is a SET_REPORT , 1 if this is a GET_REPORT |
typedef void(* fnSetSwadgeMode) (void *mode) |
Function typedef for a function which will switch the Swadge mode.
mode | A pointer to the new Swadge mode. Be very careful with this, it will execute whatever's at this address. |
Switch Gamepad Buttons Bitmap.
enum hid_gamepad_ns_hat_t |
Switch Gamepad HAT/DPAD Buttons (from Linux input event codes)
void initUsb | ( | fnSetSwadgeMode | _setSwadgeMode, |
fnAdvancedUsbHandler | _advancedUsbHandler, | ||
bool | redirectPrintf ) |
Initialize USB HID device.
_setSwadgeMode | A function that can be called from this component to set the Swadge mode |
_advancedUsbHandler | A function that can be called from this component to handle USB commands |
redirectPrintf | true to redirect printf() to USB, false to leave it over UART |
void deinitUsb | ( | void | ) |
Deinitialize USB HID device Note, this does nothing as tinyusb_driver_uninstall() doesn't exist.
void sendUsbGamepadReport | ( | hid_gamepad_report_t * | report | ) |
Send a USB gamepad report to the system.
report | The report to send, the current state of all gamepad inputs |
void usbSetSwadgeMode | ( | void * | newMode | ) |
Set the Swadge mode to the given pointer.
newMode | A pointer to the new mode to set |
void initTusb | ( | const tinyusb_config_t * | tusb_cfg, |
const uint8_t * | descriptor ) |
Initialize TinyUSB.
tusb_cfg | The TinyUSB configuration |
descriptor | The descriptor to use for this configuration |
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.
report_id | Should be HID_ITF_PROTOCOL_NONE |
x | Unsure |
y | Unsure |
z | Unsure |
rz | Unsure |
rx | Unsure |
ry | Unsure |
hat | A bitmask of hid_gamepad_ns_hat_t |
buttons | A bitmask of hid_gamepad_ns_button_bm_t |