#lang scheme/base
(require scheme/foreign)
(define USB_CLASS_PER_INTERFACE 0) (define USB_CLASS_AUDIO 1)
(define USB_CLASS_COMM 2)
(define USB_CLASS_HID 3)
(define USB_CLASS_PRINTER 7)
(define USB_CLASS_PTP 6)
(define USB_CLASS_MASS_STORAGE 8)
(define USB_CLASS_HUB 9)
(define USB_CLASS_DATA 10)
(define USB_CLASS_VENDOR_SPEC #xff)
(define USB_DT_DEVICE #x01)
(define USB_DT_CONFIG #x02)
(define USB_DT_STRING #x03)
(define USB_DT_INTERFACE #x04)
(define USB_DT_ENDPOINT #x05)
(define USB_DT_HID #x21)
(define USB_DT_REPORT #x22)
(define USB_DT_PHYSICAL #x23)
(define USB_DT_HUB #x29)
(define USB_DT_DEVICE_SIZE 18)
(define USB_DT_CONFIG_SIZE 9)
(define USB_DT_INTERFACE_SIZE 9)
(define USB_DT_ENDPOINT_SIZE 7)
(define USB_DT_ENDPOINT_AUDIO_SIZE 9) (define USB_DT_HUB_NONVAR_SIZE 7)
(define-cstruct _usb_descriptor_header
([bLength _int8]
[bDescriptorType _int8]))
(define-cstruct _usb_string_descriptor
([bLength _int8]
[bDescriptorType _int8]
[wData _int16]))
(define-cstruct _usb_hid_descriptor
([bLength _int8]
[bDescriptorType _int8]
[bcdHID _int16]
[bCountryCode _int8]
[bNumDescriptors _int8]))
(define-cstruct _usb_endpoint_descriptor
([bLength _int8]
[bDescriptorType _int8]
[bEndpointAddress _int8]
[bmAttributes _int8]
[wMaxPacketSize _int16]
[bInterval _int8]
[bRefresh _int8]
[bSynchAddress _int8]
))
(define-cstruct _usb_interface_descriptor
([bLength _int8]
[bDescriptorType _int8]
[bInterfaceNumber _int8]
[bAlternateSetting _int8]
[bNumEndpoints _int8]
[bInterfaceClass _int8]
[bInterfaceSubClass _int8]
[bInterfaceProtocol _int8]
[iInterface _int8]
))
(define-cstruct _usb_interface
([alsetting _usb_interface_descriptor-pointer]
[num_altsetting _int]))
(define-cstruct _usb_config_descriptor
([bLength _int8]
[bDescriptorType _int8]
[wTotalLength _int16]
[bNumInterfaces _int8]
[bConfigurationValue _int8]
[iConfiguration _int8]
[bmAttributes _int8]
[MaxPower _int8]
[interface _usb_interface-pointer]
))
(define-cstruct _usb_device_descriptor
([bLength _int8]
[bDescriptorType _int8]
[bcdUSB _int16]
[bDeviceClass _int8]
[bDeviceSubClass _int8]
[bDeviceProtocol _int8]
[bMaxPacketSize0 _int8]
[idVendor _int16]
[idProduct _int16]
[bcdDevice _int16]
[iManufacturer _int8]
[iProduct _int8]
[iSerialNumber _int8]
[bNumConfigurations _int8]))
(define-cstruct _usb_ctrl_setup
([bRequestType _int8]
[bRequest _int8]
[wValue _int16]
[wIndex _int16]
[wLength _int16]))
(define <<< arithmetic-shift)
(define USB_REQ_GET_STATUS #x00)
(define USB_REQ_CLEAR_FEATURE #x01)
(define USB_REQ_SET_FEATURE #x03)
(define USB_REQ_SET_ADDRESS #x05)
(define USB_REQ_GET_DESCRIPTOR #x06)
(define USB_REQ_SET_DESCRIPTOR #x07)
(define USB_REQ_GET_CONFIGURATION #x08)
(define USB_REQ_SET_CONFIGURATION #x09)
(define USB_REQ_GET_INTERFACE #x0A)
(define USB_REQ_SET_INTERFACE #x0B)
(define USB_REQ_SYNCH_FRAME #x0C)
(define USB_TYPE_STANDARD (<<< #x00 5))
(define USB_TYPE_CLASS (<<< #x01 5))
(define USB_TYPE_VENDOR (<<< #x02 5))
(define USB_TYPE_RESERVED (<<< #x03 5))
(define USB_RECIP_DEVICE #x00)
(define USB_RECIP_INTERFACE #x01)
(define USB_RECIP_ENDPOINT #x02)
(define USB_RECIP_OTHER #x03)
(define USB_ENDPOINT_IN #x80)
(define USB_ENDPOINT_OUT #x00)
(define USB_ERROR_BEGIN 500000)
(define-cstruct _usb_device
([next _usb_device-pointer]
[prev _usb_device-pointer]
[bus _usb_bus-pointer]
[descriptor _usb_device_descriptor]
[config _usb_config_descriptor-pointer]
[dev _void] [devnum _int8]
[num_children _int8]
[children _usb_devicep-pointer]))
(define-cstruct _usb_devicep
([devicep _usb_device-pointer]))
(define-cstruct _usb_bus
([next _usb_bus-pointer]
[prev _usb_bus-pointer]
[device _usb_device-pointer]
[location _int32]
[root_dev _usb_device-pointer]))