whiskers 0.4.0
RP2350 BadUSB Tool
Loading...
Searching...
No Matches
wusb.h File Reference

Detailed Description

High-level code for setting up the USB stack.

Author
zane

This code is meant to setup all the USB stack functions in a high-level way. Typically, these are just wrappers for the underlying HAL functions.

Note that with the implementation of Lua being on a seperate core, flags will have to be set so that all of the USB stuff is setup on the same core to prevent memory corruption.

#include "../../hal/usb.h"
#include "../../hal/standard.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define whiskers_usb_task()
 Wrapper for HAL usb_loop().
#define whiskers_send_report(x)
 Wrapper for HAL usb_keyboard_send_report().
#define whiskers_msc_setup(x, y, z)
 Wrapper for HAL usb_setup_msc().

Functions

bool whiskers_usb_started ()
 Checks if USB has been started or not.
bool whiskers_usb_enabled ()
 Checks if USB is enabled or not.
void whiskers_enable_usb (w_usb_mods *mods)
 Enables USB. Called by Lua typically.
void whiskers_start_usb ()
 Starts the USB stack with default values (being the descriptors).
void whiskers_send_reset_report ()
 Sends a HID reset report (all 8 bytes being zero).
void whiskers_send_ascii_string (char *str, size_t len)
 Sends a ascii string via USB.
uint8_t whiskers_char_to_scancode (char key)
 Converts a character into it's corresponding key.
uint8_t whiskers_ascii_to_modbyte (char *mods, size_t len)
 Converts a string of modifier words into a single modbyte.
uint8_t whiskers_ascii_to_special_key (char *key, size_t len)
 Converts a special key string (ie. ENTER, ESCAPE, PRINTSCRN) into it's respective opcode.

Macro Definition Documentation

◆ whiskers_msc_setup

#define whiskers_msc_setup ( x,
y,
z )
Value:
usb_setup_msc(x, y, z)
void usb_setup_msc(char vendor_string[8], char product_string[16], _DISK_INFO *di)
Sets up the MSC Class USB interface.

Wrapper for HAL usb_setup_msc().

◆ whiskers_send_report

#define whiskers_send_report ( x)
Value:
void usb_keyboard_send_report(const uint8_t rep[8])
Sends a standard HID keyboard report.

Wrapper for HAL usb_keyboard_send_report().

◆ whiskers_usb_task

#define whiskers_usb_task ( )
Value:
void usb_loop()
For TinyUSB based systems, this refreshes tud_task(). This must be called at least once every millise...

Wrapper for HAL usb_loop().

Function Documentation

◆ whiskers_ascii_to_modbyte()

uint8_t whiskers_ascii_to_modbyte ( char * mods,
size_t len )

Converts a string of modifier words into a single modbyte.

Parameters
modsString containing modifier words like LSHIFT and LALT.
lenLength of modifier string.
Returns
Modifier byte. Will return zero if no modifier words are valid.

Acceptable modifier words are: LCTRL, LSHIFT, LALT, LWIN, RCTRL, RSHIFT, RALT, RWIN.

For combining multiple into one modifier byte add a '+' between each word like: LALT+LSHIFT.

◆ whiskers_ascii_to_special_key()

uint8_t whiskers_ascii_to_special_key ( char * key,
size_t len )

Converts a special key string (ie. ENTER, ESCAPE, PRINTSCRN) into it's respective opcode.

Parameters
*keyString containing the special key.
lenLength of the key string.
Returns
The scancode for inputted key or zero if none found.

Accepted keys are:

ENTER, ESCAPE, BACKSPACE, TAB, CAPSLOCK, F1-24, NUMLOCK, END, DOWNARROW, PAGEDN, LEFTARROW, RIGHTARROW, HOME, UPARROW, PAGEUP, INSERT, DELETE.

The modifier keys can be used to but instead of the standard modifier bit mask it will return the literal scancode for those keys. The list for those is:

LCTRL, LSHIFT, LALT, LWIN, RCTRL, RSHIFT, RALT, RWIN.

I understand that there are a whole list of other special keys out there. If you want to use them, I recommend sending the raw scancodes instead as the more I add to the list above the longer and worse the resulting code gets.

◆ whiskers_char_to_scancode()

uint8_t whiskers_char_to_scancode ( char key)

Converts a character into it's corresponding key.

Parameters
keyA single character.
Returns
Scancode if applicable.

◆ whiskers_enable_usb()

void whiskers_enable_usb ( w_usb_mods * mods)

Enables USB. Called by Lua typically.

Parameters
*modsUSB mods to be applied. Set to NULL for default configuration.

◆ whiskers_send_ascii_string()

void whiskers_send_ascii_string ( char * str,
size_t len )

Sends a ascii string via USB.

Parameters
strString to an ascii string.
lenLength of the ascii string.

Note that this will only send over standard letters, numbers, and symbols in the ascii table. It will not parse things such as F-keys or keys like escape or enter. However, it treats newlines or carriage returns as sending the enter key. It will recognize capitalized characters and send them accordingly.

Once finished a null report is sent to cap off the series of reports.

◆ whiskers_usb_enabled()

bool whiskers_usb_enabled ( )

Checks if USB is enabled or not.

Returns
True on USB being enabled, false on it not.

◆ whiskers_usb_started()

bool whiskers_usb_started ( )

Checks if USB has been started or not.

Returns
True on USB having been started, false on it hasn't been.