whiskers 0.4.5
RP2350 BadUSB Tool
Loading...
Searching...
No Matches
usb.h
Go to the documentation of this file.
1/* Copyright (c) 2026 Zane A. Maple
2 Licensed under the MIT license. See LICENSE in the main repository for more information. */
3
4#ifndef W_HAL_USB_H
5#define W_HAL_USB_H
6
7#include "shared.h"
8
31#define USB_LANG_CODE { 0x04, 0x09 }
36#define USB_MANUFACTURER_STRING "vllabs"
41#define USB_PRODUCT_STRING "\'whiskers\'"
46/* Turns out you only need custom PIDs and VIDs if your device either follows the USB standard to a tee (it doesn't) or you use the USB trademark (which we aren't) */
47#define USB_PID 0x0400
52#define USB_VID 0xcafe
57
66typedef struct usb_mods
67{
68 char lang[2];
69 /* Note the +1 here is for the string end */
70 char manu_string[32 + 1];
71 char prod_string[32 + 1];
72 char serial_string[32 + 1];
73
74 uint16_t vid;
75 uint16_t pid;
76} w_usb_mods;
77
87typedef struct usb_callbacks
88{
89 void (*mounted_cb)(uint8_t);
90 void (*unmounted_cb)(void);
91 void (*suspend_cb)(bool);
92 void (*unsuspend_cb)(void);
93} w_usb_cbs;
94
95/* The macros below for the OS codes correspond the enumeration order sequencing. It's kinda abstract, but I'll try to explain it here.
96 Before the device mount callback gets called the host will enumerate the device, the sequence of which is unique to each operating system.
97 For example, linux hosts will try to get the device descriptor twice (which is 7 points each) then go through some of the string descriptors, then mount.
98
99 The values of the macro is the sum of the points before the device mounts fully with the host. The device descriptor request is 7 points, then the string
100 requests is the index of the requested string +1, ie. if the host wanted the string index at index 0, you'd gain +1 points. (index 1 = 2, 2 = 3, etc. )
101
102 This is very primitive, and can be reworked to allow for the points AFTER the device is mounted to count also, however I have tested this on a few different
103 operating systems with default settings and it was consistent across the board, at least consistent enough to allow this method to work. */
104
109#define W_USB_OS_UNKNOWN 0
114#define W_USB_OS_WINDOWS 33
119#define W_USB_OS_MACOS 39
124#define W_USB_OS_UNIX 31
125
138void usb_setup_msc(char vendor_string[8], char product_string[16], char revision[4], _DISK_INFO *di);
139
144void usb_initialize_defaults(w_usb_cbs *cbs);
145
151void usb_initialize_custom(w_usb_cbs *cbs, w_usb_mods *mods);
217void usb_keyboard_send_report(const uint8_t rep[8]);
221void usb_loop();
226#endif
Shared structs, error codes, and functions for all HAL files.
Struct holding callback functions for internal USB events.
Definition usb.h:88
void(*) mounted_cb(uint8_t)
Definition usb.h:89
void(*) unmounted_cb(void)
Definition usb.h:90
void(*) suspend_cb(bool)
Definition usb.h:91
void(*) unsuspend_cb(void)
Definition usb.h:92
USB Modifiers.
Definition usb.h:67
char lang[2]
Definition usb.h:68
char manu_string[32+1]
Definition usb.h:70
char serial_string[32+1]
Definition usb.h:72
uint16_t pid
Definition usb.h:75
char prod_string[32+1]
Definition usb.h:71
uint16_t vid
Definition usb.h:74
void usb_remote_wakeup_host()
If the host allows us, this function will wake it up.
void usb_initialize_defaults(w_usb_cbs *cbs)
Starts the internal USB stack with default values.
void usb_keyboard_send_report(const uint8_t rep[8])
Sends a standard HID keyboard report.
void usb_loop()
For TinyUSB based systems, this refreshes tud_task(). This must be called at least once every millise...
void usb_setup_msc(char vendor_string[8], char product_string[16], char revision[4], _DISK_INFO *di)
Sets up the MSC Class USB interface.
void usb_initialize_custom(w_usb_cbs *cbs, w_usb_mods *mods)
Starts the internal USB stack with custom descriptors.