Joshy
short test
Code: Select all
#ifdef __FB_WIN32__
#include once "lusb0_usb.bi"
#else
#include once "usb.bi"
#endif
usb_init()
usb_find_busses()
usb_find_devices()
dim as usb_bus ptr aBus = usb_get_busses()
while (aBus)
? "bus " & aBus->dirname
dim as usb_device ptr aDev = aBus->devices
while aDev
? "vendor 0x" & hex(aDev->descriptor.idVendor,4) & " product: 0x" & hex(aDev->descriptor.idProduct,4)
aDev=aDev->next
wend
aBus = aBus->next
wend
? "done ..." : sleep
Code: Select all
/'
* Prototypes, structure definitions and macros.
*
* Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* This file (and only this file) may alternatively be licensed under the
* BSD license. See the LICENSE file shipped with the libusb-compat-0.1 source
* distribution for details.
'/
#ifndef __USB_BI__
#define __USB_BI__
#inclib "usb"
/'
* USB spec information
*
* This is all stuff grabbed from various USB specs and is pretty much not subject to change
'/
/'
* Device and/or Interface Class codes
'/
#define USB_CLASS_PER_INTERFACE 0 /' for DeviceClass '/
#define USB_CLASS_AUDIO 1
#define USB_CLASS_COMM 2
#define USB_CLASS_HID 3
#define USB_CLASS_PTP 6
#define USB_CLASS_PRINTER 7
#define USB_CLASS_MASS_STORAGE 8
#define USB_CLASS_HUB 9
#define USB_CLASS_DATA 10
#define USB_CLASS_VENDOR_SPEC &Hff
/'
* Descriptor types
'/
#define USB_DT_DEVICE &H01
#define USB_DT_CONFIG &H02
#define USB_DT_STRING &H03
#define USB_DT_INTERFACE &H04
#define USB_DT_ENDPOINT &H05
#define USB_DT_HID &H21
#define USB_DT_REPORT &H22
#define USB_DT_PHYSICAL &H23
#define USB_DT_HUB &H29
/'
* Descriptor sizes per descriptor type
'/
#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 /' Audio extension '/
#define USB_DT_HUB_NONVAR_SIZE 7
/' All standard descriptors have these 2 fields in common '/
type usb_descriptor_header
as ubyte bLength
as ubyte bDescriptorType
end type
/' String descriptor '/
type usb_string_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort wData(0)
end type
/' HID descriptor '/
type usb_hid_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort bcdHID
as ubyte bCountryCode
as ubyte bNumDescriptors
/' as ubyte bReportDescriptorType '/
/' as ushort wDescriptorLength '/
/' ... '/
end type
/' Endpoint descriptor '/
#define USB_MAXENDPOINTS 32
type usb_endpoint_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bEndpointAddress
as ubyte bmAttributes
as ushort wMaxPacketSize
as ubyte bInterval
as ubyte bRefresh
as ubyte bSynchAddress
as ubyte ptr extra /' Extra descriptors '/
as integer extralen
end type
#define USB_ENDPOINT_ADDRESS_MASK &H0f /' in bEndpointAddress '/
#define USB_ENDPOINT_DIR_MASK &H80
#define USB_ENDPOINT_TYPE_MASK &H03 /' in bmAttributes '/
#define USB_ENDPOINT_TYPE_CONTROL 0
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
#define USB_ENDPOINT_TYPE_BULK 2
#define USB_ENDPOINT_TYPE_INTERRUPT 3
/' Interface descriptor '/
#define USB_MAXINTERFACES 32
type usb_interface_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bInterfaceNumber
as ubyte bAlternateSetting
as ubyte bNumEndpoints
as ubyte bInterfaceClass
as ubyte bInterfaceSubClass
as ubyte bInterfaceProtocol
as ubyte iInterface
as usb_endpoint_descriptor ptr endpoint
as ubyte ptr extra /' Extra descriptors '/
as integer extralen
end type
#define USB_MAXALTSETTING 128 /' Hard limit '/
type usb_interface
as usb_interface_descriptor ptr altsetting
as integer num_altsetting
end type
/' Configuration descriptor information.. '/
#define USB_MAXCONFIG 8
type usb_config_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort wTotalLength
as ubyte bNumInterfaces
as ubyte bConfigurationValue
as ubyte iConfiguration
as ubyte bmAttributes
as ubyte MaxPower
as usb_interface ptr interface
as ubyte ptr extra /' Extra descriptors '/
as integer extralen
end type
/' Device descriptor '/
type usb_device_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort bcdUSB
as ubyte bDeviceClass
as ubyte bDeviceSubClass
as ubyte bDeviceProtocol
as ubyte bMaxPacketSize0
as ushort idVendor
as ushort idProduct
as ushort bcdDevice
as ubyte iManufacturer
as ubyte iProduct
as ubyte iSerialNumber
as ubyte bNumConfigurations
end type
type usb_ctrl_setup
as ubyte bRequestType
as ubyte bRequest
as ushort wValue
as ushort wIndex
as ushort wLength
end type
/'
* Standard requests
'/
#define USB_REQ_GET_STATUS &H00
#define USB_REQ_CLEAR_FEATURE &H01
/' &H02 is reserved '/
#define USB_REQ_SET_FEATURE &H03
/' &H04 is reserved '/
#define USB_REQ_SET_ADDRESS &H05
#define USB_REQ_GET_DESCRIPTOR &H06
#define USB_REQ_SET_DESCRIPTOR &H07
#define USB_REQ_GET_CONFIGURATION &H08
#define USB_REQ_SET_CONFIGURATION &H09
#define USB_REQ_GET_INTERFACE &H0A
#define USB_REQ_SET_INTERFACE &H0B
#define USB_REQ_SYNCH_FRAME &H0C
#define USB_TYPE_STANDARD (&H00 shl 5)
#define USB_TYPE_CLASS (&H01 shl 5)
#define USB_TYPE_VENDOR (&H02 shl 5)
#define USB_TYPE_RESERVED (&H03 shl 5)
#define USB_RECIP_DEVICE &H00
#define USB_RECIP_INTERFACE &H01
#define USB_RECIP_ENDPOINT &H02
#define USB_RECIP_OTHER &H03
/'
* Various libusb API related stuff
'/
#define USB_ENDPOINT_IN &H80
#define USB_ENDPOINT_OUT &H00
/' Error codes '/
#define USB_ERROR_BEGIN 500000
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
/' Data types '/
'type usb_device as any
type usb_bus_ as usb_bus
/'
* To maintain compatibility with applications already built with libusb,
* we must only add entries to the end of this structure. NEVER delete or
* move members and only change types if you really know what you're doing.
'/
type usb_device
as usb_device ptr next, prev
as zstring * PATH_MAX + 1 filename
as usb_bus_ ptr bus
as usb_device_descriptor descriptor
as usb_config_descriptor ptr config
as any ptr dev /' Darwin support '/
as ubyte devnum
as ubyte num_children
as usb_device ptr ptr children
end type
type usb_bus
as usb_bus ptr next, prev
as zstring * PATH_MAX + 1 dirname
as usb_device ptr devices
as uinteger location
as usb_device ptr root_dev
end type
type usb_dev_handle as any
#define LIBUSB_HAS_GET_DRIVER_NP 1
#define LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 1
/' Variables '/
extern usb_busses as usb_bus ptr
extern "C"
/' Function prototypes '/
/' usb.c '/
declare function usb_open (dev as usb_device ptr) as usb_dev_handle ptr
declare function usb_close (dev as usb_dev_handle ptr) as integer
declare function usb_get_string (dev as usb_dev_handle ptr, index as integer, langid as integer, buf as ubyte ptr, buflen as integer) as integer
declare function usb_get_string_simple(dev as usb_dev_handle ptr, index as integer, buf as ubyte ptr, buflen as integer) as integer
/' descriptors.c '/
declare function usb_get_descriptor_by_endpoint(udev as usb_dev_handle ptr, ep as integer, typ as ubyte, index as ubyte, buf as any ptr, size as integer) as integer
declare function usb_get_descriptor (udev as usb_dev_handle ptr, typ as ubyte, index as ubyte, buf as any ptr, size as integer) as integer
/' <arch>.c '/
declare function usb_bulk_write (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_bulk_read (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_interrupt_write (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_interrupt_read (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_control_msg (dev as usb_dev_handle ptr, requesttype as integer, request as integer, value as integer, index as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_set_configuration(dev as usb_dev_handle ptr, configuration as integer) as integer
declare function usb_claim_interface (dev as usb_dev_handle ptr, interface as integer) as integer
declare function usb_release_interface(dev as usb_dev_handle ptr, interface as integer) as integer
declare function usb_set_altinterface (dev as usb_dev_handle ptr, alternate as integer) as integer
declare function usb_resetep (dev as usb_dev_handle ptr, ep as uinteger) as integer
declare function usb_clear_halt (dev as usb_dev_handle ptr, ep as uinteger) as integer
declare function usb_reset (dev as usb_dev_handle ptr) as integer
declare function usb_get_driver_np(dev as usb_dev_handle ptr, interface as integer, name_ as zstring ptr, namelen as uinteger) as integer
declare function usb_detach_kernel_driver_np(dev as usb_dev_handle ptr, interface as integer) as integer
declare function usb_strerror() as zstring ptr
declare sub usb_init()
declare sub usb_set_debug(level as integer)
declare function usb_find_busses() as integer
declare function usb_find_devices() as integer
declare function usb_device(dev as usb_dev_handle ptr) as usb_device ptr
declare function usb_get_busses() as usb_bus ptr
end extern
#endif /' __USB_BI__ '/
Code: Select all
#ifndef __USB_BI__
#define __USB_BI__
#include once "crt.bi"
#include once "windows.bi"
#inclib "usb"
' 'interface' is defined somewhere in the Windows header files. This macro is deleted here to avoid conflicts and compile errors.
#ifdef interface
#undef interface
#endif
' PATH_MAX from limits.h can't be used on Windows if the dll and import libraries are build/used by different compilers
#define LIBUSB_PATH_MAX 512
' USB spec information
' This is all stuff grabbed from various USB specs and is pretty much not subject to change
' Device and/or Interface Class codes
#define USB_CLASS_PER_INTERFACE 0 ' for DeviceClass
#define USB_CLASS_AUDIO 1
#define USB_CLASS_COMM 2
#define USB_CLASS_HID 3
#define USB_CLASS_PRINTER 7
#define USB_CLASS_MASS_STORAGE 8
#define USB_CLASS_HUB 9
#define USB_CLASS_DATA 10
#define USB_CLASS_VENDOR_SPEC &Hff
' Descriptor types
#define USB_DT_DEVICE &H01
#define USB_DT_CONFIG &H02
#define USB_DT_STRING &H03
#define USB_DT_INTERFACE &H04
#define USB_DT_ENDPOINT &H05
#define USB_DT_HID &H21
#define USB_DT_REPORT &H22
#define USB_DT_PHYSICAL &H23
#define USB_DT_HUB &H29
' Descriptor sizes per descriptor type
#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 ' Audio extension
#define USB_DT_HUB_NONVAR_SIZE 7
' All standard descriptors have these 2 fields in common
type usb_descriptor_header
as ubyte bLength
as ubyte bDescriptorType
end type
' String descriptor
type usb_string_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort wData(0)
end type
' HID descriptor
type usb_hid_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort bcdHID
as ubyte bCountryCode
as ubyte bNumDescriptors
end type
' Endpoint descriptor
#define USB_MAXENDPOINTS 32
type usb_endpoint_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bEndpointAddress
as ubyte bmAttributes
as ushort wMaxPacketSize
as ubyte bInterval
as ubyte bRefresh
as ubyte bSynchAddress
as ubyte ptr extra
as integer extralen
end type
#define USB_ENDPOINT_ADDRESS_MASK &H0f ' in bEndpointAddress
#define USB_ENDPOINT_DIR_MASK &H80
#define USB_ENDPOINT_TYPE_MASK &H03 ' in bmAttributes
#define USB_ENDPOINT_TYPE_CONTROL 0
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
#define USB_ENDPOINT_TYPE_BULK 2
#define USB_ENDPOINT_TYPE_INTERRUPT 3
' Interface descriptor
#define USB_MAXINTERFACES 32
type usb_interface_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bInterfaceNumber
as ubyte bAlternateSetting
as ubyte bNumEndpoints
as ubyte bInterfaceClass
as ubyte bInterfaceSubClass
as ubyte bInterfaceProtocol
as ubyte iInterface
as usb_endpoint_descriptor ptr endpoint
as ubyte ptr extra ' Extra descriptors
as integer extralen
end type
#define USB_MAXALTSETTING 128 ' Hard limit
type usb_interface
as usb_interface_descriptor ptr altsetting
as integer num_altsetting
end type
' Configuration descriptor information..
#define USB_MAXCONFIG 8
type usb_config_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort wTotalLength
as ubyte bNumInterfaces
as ubyte bConfigurationValue
as ubyte iConfiguration
as ubyte bmAttributes
as ubyte MaxPower
as usb_interface ptr interface
as ubyte ptr extra ' Extra descriptors
as integer extralen
end type
' Device descriptor
type usb_device_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort bcdUSB
as ubyte bDeviceClass
as ubyte bDeviceSubClass
as ubyte bDeviceProtocol
as ubyte bMaxPacketSize0
as ushort idVendor
as ushort idProduct
as ushort bcdDevice
as ubyte iManufacturer
as ubyte iProduct
as ubyte iSerialNumber
as ubyte bNumConfigurations
end type
type usb_ctrl_setup
as ubyte bRequestType
as ubyte bRequest
as ushort wValue
as ushort wIndex
as ushort wLength
end type
' Standard requests
#define USB_REQ_GET_STATUS &H00
#define USB_REQ_CLEAR_FEATURE &H01
' &H02 is reserved
#define USB_REQ_SET_FEATURE &H03
' &H04 is reserved
#define USB_REQ_SET_ADDRESS &H05
#define USB_REQ_GET_DESCRIPTOR &H06
#define USB_REQ_SET_DESCRIPTOR &H07
#define USB_REQ_GET_CONFIGURATION &H08
#define USB_REQ_SET_CONFIGURATION &H09
#define USB_REQ_GET_INTERFACE &H0A
#define USB_REQ_SET_INTERFACE &H0B
#define USB_REQ_SYNCH_FRAME &H0C
#define USB_TYPE_STANDARD (&H00 shl 5)
#define USB_TYPE_CLASS (&H01 shl 5)
#define USB_TYPE_VENDOR (&H02 shl 5)
#define USB_TYPE_RESERVED (&H03 shl 5)
#define USB_RECIP_DEVICE &H00
#define USB_RECIP_INTERFACE &H01
#define USB_RECIP_ENDPOINT &H02
#define USB_RECIP_OTHER &H03
' Various libusb API related stuff
#define USB_ENDPOINT_IN &H80
#define USB_ENDPOINT_OUT &H00
' Error codes
#define USB_ERROR_BEGIN 500000
' This is supposed to look weird. This file is generated from autoconf and I didn't want to make this too complicated.
#define USB_LE16_TO_CPU(x)
' Device reset types for usb_reset_ex.
' http://msdn.microsoft.com/en-us/library/ff537269%28VS.85%29.aspx
' http://msdn.microsoft.com/en-us/library/ff537243%28v=vs.85%29.aspx
#define USB_RESET_TYPE_RESET_PORT (1 shl 0)
#define USB_RESET_TYPE_CYCLE_PORT (1 shl 1)
#define USB_RESET_TYPE_FULL_RESET (USB_RESET_TYPE_CYCLE_PORT or USB_RESET_TYPE_RESET_PORT)
type usb_bus_ as usb_bus
' Data types
type usb_device
as usb_device ptr next, prev
as zstring * LIBUSB_PATH_MAX -1 filename
as usb_bus_ ptr bus
as usb_device_descriptor descriptor
as usb_config_descriptor ptr config
as any ptr dev ' Darwin support '
as ubyte devnum
as ubyte num_children
as usb_device ptr ptr children
end type
type usb_bus
as usb_bus ptr next, prev
as zstring * LIBUSB_PATH_MAX - 1 dirname
as usb_device ptr devices
as ulong location
as usb_device ptr root_dev
end type
' Version information, Windows specific
type dll_
as integer major
as integer minor
as integer micro
as integer nano
end type
type driver_
as integer major
as integer minor
as integer micro
as integer nano
end type
type usb_version
as dll_ dll
as driver_ driver
end type
type usb_dev_handle as any
' Variables
#ifndef __USB_C__
#define usb_busses usb_get_busses()
#endif
#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
#define LIBUSB_HAS_INSTALL_NP 1
#define usb_install_np usb_install_npA
declare sub usb_install_np_rundll (wnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, cmd_show as integer)
declare sub usb_install_driver_np_rundll (wnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, cmd_show as integer)
declare sub usb_touch_inf_file_np_rundll (wnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, cmd_show as integer)
declare sub usb_install_service_np_rundll (wnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, cmd_show as integer)
declare sub usb_uninstall_service_np_rundll(wnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, cmd_show as integer)
extern "C"
' usb.c
declare function usb_open(dev as usb_device ptr) as usb_dev_handle ptr
declare function usb_close(dev as usb_dev_handle ptr) as integer
declare function usb_get_string(dev as usb_dev_handle ptr, index as integer, langid as integer, buf as byte ptr, buflen as integer) as integer
declare function usb_get_string_simple(dev as usb_dev_handle ptr, index as integer, buf as byte ptr, buflen as integer) as integer
' descriptors.c
declare function usb_get_descriptor_by_endpoint(dev as usb_dev_handle ptr,ep as integer, type_ as ubyte, index as ubyte, buf as byte ptr, size as integer) as integer
declare function usb_get_descriptor (dev as usb_dev_handle ptr, type_ as ubyte, index as ubyte, buf as byte ptr, size as integer) as integer
' <arch>.c
declare function usb_bulk_write (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_bulk_read (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_interrupt_write (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_interrupt_read (dev as usb_dev_handle ptr, ep as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_control_msg (dev as usb_dev_handle ptr, requesttype as integer, request as integer, value as integer, index as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
declare function usb_set_configuration(dev as usb_dev_handle ptr, configuration as integer) as integer
declare function usb_claim_interface (dev as usb_dev_handle ptr, interface as integer) as integer
declare function usb_release_interface(dev as usb_dev_handle ptr, interface as integer) as integer
declare function usb_set_altinterface (dev as usb_dev_handle ptr, alternate_ as integer) as integer
declare function usb_resetep (dev as usb_dev_handle ptr, ep as uinteger) as integer
declare function usb_clear_halt (dev as usb_dev_handle ptr, ep as uinteger) as integer
declare function usb_reset (dev as usb_dev_handle ptr) as integer
declare function usb_reset_ex (dev as usb_dev_handle ptr, reset_type as uinteger) as integer
declare function usb_strerror() as byte ptr
declare sub usb_init()
declare sub usb_set_debug(level as integer)
declare function usb_find_busses() as integer
declare function usb_find_devices() as integer
declare function usb_device(dev as usb_dev_handle ptr) as usb_device ptr
declare function usb_get_busses() as usb_bus ptr
' Windows specific functions
declare function usb_install_service_np() as integer
declare function usb_uninstall_service_np() as integer
declare function usb_install_driver_np(inf_file as const zstring ptr) as integer
declare function usb_touch_inf_file_np(inf_file as const zstring ptr) as integer
declare function usb_install_needs_restart_np() as integer
declare function usb_install_npW(hwnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, starg_arg as integer) as integer
declare function usb_install_npA(hwnd as HWND, instance as HINSTANCE, cmd_line as zstring ptr, starg_arg as integer) as integer
declare function usb_get_version() as const usb_version ptr
declare function usb_isochronous_setup_async(dev as usb_dev_handle ptr, context as any ptr ptr, ep as ubyte, pktsize as integer) as integer
declare function usb_bulk_setup_async (dev as usb_dev_handle ptr, context as any ptr ptr, ep as ubyte) as integer
declare function usb_interrupt_setup_async (dev as usb_dev_handle ptr, context as any ptr ptr, ep as ubyte) as integer
declare function usb_submit_async (context as any ptr, bytes as byte ptr, size as integer) as integer
declare function usb_reap_async (context as any ptr, timeout as integer) as integer
declare function usb_reap_async_nocancel(context as any ptr, timeout as integer) as integer
declare function usb_cancel_async (context as any ptr) as integer
declare function usb_free_async (context as any ptr ptr) as integer
end extern
#endif ' __USB_BI__