Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-usb.c File Reference

Macros

#define TUD_HID_REPORT_DESC_GAMEPAD_SWADGE(...)
 HID Gamepad Report Descriptor Template with 32 buttons, 2 joysticks and 1 hat/dpad with following layout | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (4 bytes) |.
 

Functions

void initUsb (fnSetSwadgeMode _setSwadgeMode, fnAdvancedUsbHandler _advancedUsbHandler, bool redirectPrintf)
 Initialize USB HID device.
 
void initTusb (const tinyusb_config_t *tusb_cfg, const uint8_t *descriptor)
 Initialize TinyUSB.
 
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.
 
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.
 
uint8_t const * tud_hid_descriptor_report_cb (uint8_t instance)
 
uint16_t tud_hid_get_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqLen)
 
void tud_hid_set_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
 
void usbSetSwadgeMode (void *newMode)
 Set the Swadge mode to the given pointer.
 

Macro Definition Documentation

◆ TUD_HID_REPORT_DESC_GAMEPAD_SWADGE

#define TUD_HID_REPORT_DESC_GAMEPAD_SWADGE ( ...)

HID Gamepad Report Descriptor Template with 32 buttons, 2 joysticks and 1 hat/dpad with following layout | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (4 bytes) |.

Function Documentation

◆ initUsb()

void initUsb ( fnSetSwadgeMode _setSwadgeMode,
fnAdvancedUsbHandler _advancedUsbHandler,
bool redirectPrintf )

Initialize USB HID device.

Parameters
_setSwadgeModeA function that can be called from this component to set the Swadge mode
_advancedUsbHandlerA function that can be called from this component to handle USB commands
redirectPrintftrue to redirect printf() to USB, false to leave it over UART

◆ initTusb()

void initTusb ( const tinyusb_config_t * tusb_cfg,
const uint8_t * descriptor )

Initialize TinyUSB.

Parameters
tusb_cfgThe TinyUSB configuration
descriptorThe descriptor to use for this configuration

◆ deinitUsb()

void deinitUsb ( void )

Deinitialize USB HID device Note, this does nothing as tinyusb_driver_uninstall() doesn't exist.

◆ sendUsbGamepadReport()

void sendUsbGamepadReport ( hid_gamepad_report_t * report)

Send a USB gamepad report to the system.

Parameters
reportThe report to send, the current state of all gamepad inputs

◆ tud_hid_gamepad_report_ns()

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.

Parameters
report_idShould be HID_ITF_PROTOCOL_NONE
xUnsure
yUnsure
zUnsure
rzUnsure
rxUnsure
ryUnsure
hatA bitmask of hid_gamepad_ns_hat_t
buttonsA bitmask of hid_gamepad_ns_button_bm_t
Returns
Unsure

◆ tud_hid_descriptor_report_cb()

uint8_t const * tud_hid_descriptor_report_cb ( uint8_t instance)

Invoked when received GET HID REPORT DESCRIPTOR request Application return pointer to descriptor, whose contents must exist long enough for transfer to complete

Parameters
instanceThe index to get a descriptor report for
Returns
The descriptor report for the given index

◆ tud_hid_get_report_cb()

uint16_t tud_hid_get_report_cb ( uint8_t instance,
uint8_t report_id,
hid_report_type_t report_type,
uint8_t * buffer,
uint16_t reqLen )

Invoked when received GET_REPORT control request Application must fill buffer report's content and return its length. Return zero will cause the stack to STALL request

Parameters
instanceThe endpoint index to handle a GET_REPORT
report_idThe report ID
report_typeUnused
bufferPointer to a feature get request for the command set.
reqLenNumber of bytes host is requesting from us.
Returns
The number of bytes returned to the host

◆ tud_hid_set_report_cb()

void tud_hid_set_report_cb ( uint8_t instance,
uint8_t report_id,
hid_report_type_t report_type,
uint8_t const * buffer,
uint16_t bufsize )

Invoked when received SET_REPORT control request or received data on OUT endpoint ( Report ID = 0, Type = 0 )

Parameters
instanceThe endpoint index to handle a SET_REPORT request
report_idThe report ID
report_typeunused
bufferPointer to full command
bufsizeTotal length of the buffer (command ID included)

◆ usbSetSwadgeMode()

void usbSetSwadgeMode ( void * newMode)

Set the Swadge mode to the given pointer.

Parameters
newModeA pointer to the new mode to set