2018-06-07 12:31:53 +00:00
open Ctypes
2018-06-24 10:14:05 +00:00
(* * {1 Types} *)
2018-06-07 12:31:53 +00:00
type error =
| Number of int (* * A positive number *)
| Success (* * Success ( no error ) *)
| Error_io (* * Input/output error *)
| Error_invalid_param (* * Invalid parameter *)
| Error_access (* * Access denied ( insufficient permissions ) *)
| Error_no_device (* * No such device ( it may have been disconnected ) *)
| Error_not_found (* * Entity not found *)
| Error_busy (* * Resource busy *)
| Error_timeout (* * Operation timed out *)
| Error_overflow (* * Overflow *)
| Error_pipe (* * Pipe error *)
| Error_interrupted (* * System call interrupted ( perhaps due to signal ) *)
| Error_no_mem (* * Insufficient memory *)
| Error_not_supported (* * Operation not supported or unimplemented on this platform *)
| Error_other (* * Other error *)
type version = {
major : int ; (* * Library major version *)
minor : int ; (* * Library major version *)
micro : int ; (* * Library micro version *)
nano : int ; (* * Library nano version *)
rc : string ; (* * Library release candidate suffix string, e.g. "-rc4" *)
describe : string ; (* * For ABI compatibility only *)
}
2018-06-24 10:14:05 +00:00
(* * Contains only the fields I needed so far *)
2018-06-07 12:31:53 +00:00
type device_descriptor = {
id_vendor : int ; (* * Vendor ID. *)
id_product : int ; (* * Product ID. *)
i_manufacturer : int ; (* * Index of string descriptor describing manufacturer. *)
i_product : int ; (* * Index of string descriptor describing product. *)
2018-06-15 06:30:45 +00:00
num_configurations : int ;
2018-06-07 12:31:53 +00:00
}
2018-06-24 10:14:05 +00:00
(* * {1 C types} *)
2018-06-07 12:31:53 +00:00
module Types ( T : Cstubs . Types . TYPE ) = struct
let success = T . constant " LIBUSB_SUCCESS " T . int64_t
let error_io = T . constant " LIBUSB_ERROR_IO " T . int64_t
let error_invalid_param = T . constant " LIBUSB_ERROR_INVALID_PARAM " T . int64_t
let error_access = T . constant " LIBUSB_ERROR_ACCESS " T . int64_t
let error_no_device = T . constant " LIBUSB_ERROR_NO_DEVICE " T . int64_t
let error_not_found = T . constant " LIBUSB_ERROR_NOT_FOUND " T . int64_t
let error_busy = T . constant " LIBUSB_ERROR_BUSY " T . int64_t
let error_timeout = T . constant " LIBUSB_ERROR_TIMEOUT " T . int64_t
let error_overflow = T . constant " LIBUSB_ERROR_OVERFLOW " T . int64_t
let error_pipe = T . constant " LIBUSB_ERROR_PIPE " T . int64_t
let error_interrupted = T . constant " LIBUSB_ERROR_INTERRUPTED " T . int64_t
let error_no_mem = T . constant " LIBUSB_ERROR_NO_MEM " T . int64_t
let error_not_supported = T . constant " LIBUSB_ERROR_NOT_SUPPORTED " T . int64_t
let error_other = T . constant " LIBUSB_ERROR_OTHER " T . int64_t
let error = T . enum " libusb_error " [
Success , success ;
Error_io , error_io ;
Error_invalid_param , error_invalid_param ;
Error_access , error_access ;
Error_no_device , error_no_device ;
Error_not_found , error_not_found ;
Error_busy , error_busy ;
Error_timeout , error_timeout ;
Error_overflow , error_overflow ;
Error_pipe , error_pipe ;
Error_interrupted , error_interrupted ;
Error_no_mem , error_no_mem ;
Error_not_supported , error_not_supported ;
Error_other , error_other ;
] ~ unexpected : ( fun x -> Number ( Int64 . to_int x ) )
let request_type_standard = T . constant " LIBUSB_REQUEST_TYPE_STANDARD " T . int64_t
let request_type_class = T . constant " LIBUSB_REQUEST_TYPE_CLASS " T . int64_t
let request_type_vendor = T . constant " LIBUSB_REQUEST_TYPE_VENDOR " T . int64_t
let request_type_reserved = T . constant " LIBUSB_REQUEST_TYPE_RESERVED " T . int64_t
let endpoint_direction_in = T . constant " LIBUSB_ENDPOINT_IN " T . int64_t
let endpoint_direction_out = T . constant " LIBUSB_ENDPOINT_OUT " T . int64_t
let libusb_recipient_device = T . constant " LIBUSB_RECIPIENT_DEVICE " T . int64_t
let libusb_recipient_interface = T . constant " LIBUSB_RECIPIENT_INTERFACE " T . int64_t
let libusb_recipient_endpoint = T . constant " LIBUSB_RECIPIENT_ENDPOINT " T . int64_t
let libusb_recipient_other = T . constant " LIBUSB_RECIPIENT_OTHER " T . int64_t
type version
let version : version structure typ = structure " libusb_version "
let ( | : ) n t = field version n t
let version_major = " major " | : uint16_t
let version_minor = " minor " | : uint16_t
let version_micro = " micro " | : uint16_t
let version_nano = " nano " | : uint16_t
let version_rc = " rc " | : string
let version_describe = " describe " | : string
let () = seal version
type device
let device : device structure typ = structure " libusb_device "
type device_handle
let device_handle : device_handle structure typ = structure " libusb_device_handle "
type device_descriptor
let device_descriptor : device_descriptor structure typ = structure " libusb_device_descriptor "
let ( | : ) n t = field device_descriptor n t
let device_descriptor_blength = " bLength " | : uint8_t (* Size of this descriptor ( in bytes ) *)
let device_descriptor_bdescriptortype = " bDescriptorType " | : uint8_t (* Descriptor type. *)
let device_descriptor_bcdusb = " bcdUSB " | : uint16_t (* USB specification release number in binary-coded decimal. *)
let device_descriptor_bdeviceclass = " bDeviceClass " | : uint8_t (* USB-IF class code for the device. *)
let device_descriptor_bdevicesubclass = " bDeviceSubClass " | : uint8_t (* USB-IF subclass code for the device, qualified by the bDeviceClass value. *)
let device_descriptor_bdeviceprotocol = " bDeviceProtocol " | : uint8_t (* USB-IF protocol code for the device, qualified by the bDeviceClass and bDeviceSubClass values. *)
let device_descriptor_bmaxpacketsize0 = " bMaxPacketSize0 " | : uint8_t (* Maximum packet size for endpoint 0. *)
let device_descriptor_idvendor = " idVendor " | : uint16_t (* USB-IF vendor ID. *)
let device_descriptor_idproduct = " idProduct " | : uint16_t (* USB-IF product ID. *)
let device_descriptor_bcddevice = " bcdDevice " | : uint16_t (* Device release number in binary-coded decimal. *)
let device_descriptor_imanufacturer = " iManufacturer " | : uint8_t (* Index of string descriptor describing manufacturer. *)
let device_descriptor_iproduct = " iProduct " | : uint8_t (* Index of string descriptor describing product. *)
let device_descriptor_iserialnumber = " iSerialNumber " | : uint8_t (* Index of string descriptor containing device serial number. *)
let device_descriptor_bnumconfigurations = " bNumConfigurations " | : uint8_t (* Number of possible configurations. *)
let () = seal device_descriptor
end