Commit initial
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
let () =
|
||||
Format.fprintf Format.std_formatter "#include <libusb.h>@.";
|
||||
Cstubs.Types.write_c Format.std_formatter (module T.Types)
|
9
lib/generator/stubs/c_types_generator/jbuild
Normal file
9
lib/generator/stubs/c_types_generator/jbuild
Normal file
@ -0,0 +1,9 @@
|
||||
(executable(
|
||||
(name c_types_generator)
|
||||
(libraries (ctypes.stubs))
|
||||
))
|
||||
|
||||
(rule(
|
||||
(targets (t.ml))
|
||||
(action (copy ../t.ml t.ml))
|
||||
))
|
@ -0,0 +1,5 @@
|
||||
Printf.printf "-I%s%!"
|
||||
(
|
||||
Findlib.init ();
|
||||
Findlib.package_directory "ctypes"
|
||||
)
|
4
lib/generator/stubs/ctypes_cflags_generator/jbuild
Normal file
4
lib/generator/stubs/ctypes_cflags_generator/jbuild
Normal file
@ -0,0 +1,4 @@
|
||||
(executable(
|
||||
(name ctypes_cflags_generator)
|
||||
(libraries (findlib))
|
||||
))
|
36
lib/generator/stubs/jbuild
Normal file
36
lib/generator/stubs/jbuild
Normal file
@ -0,0 +1,36 @@
|
||||
(rule(
|
||||
(targets (my_types.ml))
|
||||
(deps (my_types_generator.exe))
|
||||
(action (with-stdout-to ${@} (run ${<})))
|
||||
))
|
||||
|
||||
(rule(
|
||||
(targets (my_types_generator.exe))
|
||||
(deps (my_types_generator.c))
|
||||
(action (run ${CC}
|
||||
-o ${@}
|
||||
${read:libusb_cflags}
|
||||
${read:ctypes_cflags}
|
||||
-I${ocaml-config:standard_library}
|
||||
${<}))
|
||||
))
|
||||
|
||||
(rule(
|
||||
(targets (my_types_generator.c))
|
||||
(action
|
||||
(with-stdout-to ${@}
|
||||
(run c_types_generator/c_types_generator.exe)
|
||||
))
|
||||
))
|
||||
|
||||
(rule(
|
||||
(targets (ctypes_cflags))
|
||||
(action (with-stdout-to ${@}
|
||||
(run ctypes_cflags_generator/ctypes_cflags_generator.exe)))
|
||||
))
|
||||
|
||||
(rule(
|
||||
(targets (libusb_cflags))
|
||||
(action (with-stdout-to ${@}
|
||||
(run libusb_cflags_generator/libusb_cflags_generator.exe)))
|
||||
))
|
4
lib/generator/stubs/libusb_cflags_generator/jbuild
Normal file
4
lib/generator/stubs/libusb_cflags_generator/jbuild
Normal file
@ -0,0 +1,4 @@
|
||||
(executable(
|
||||
(name libusb_cflags_generator)
|
||||
(libraries (configurator))
|
||||
))
|
@ -0,0 +1,14 @@
|
||||
let (>>|) a f = match a with None -> None | Some a -> f a
|
||||
|
||||
let libusb_c_flags =
|
||||
let open Configurator in
|
||||
create "c"
|
||||
|> Pkg_config.get
|
||||
>>| Pkg_config.query ~package:"libusb-1.0"
|
||||
>>| (fun Pkg_config.{cflags} ->
|
||||
Some (String.concat " " cflags))
|
||||
|> (function
|
||||
| None -> "libusb flag not found"
|
||||
| Some f -> f)
|
||||
|
||||
let () = Printf.printf "%s%!" libusb_c_flags
|
117
lib/generator/stubs/t.ml
Normal file
117
lib/generator/stubs/t.ml
Normal file
@ -0,0 +1,117 @@
|
||||
open Ctypes
|
||||
|
||||
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 *)
|
||||
}
|
||||
|
||||
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. *)
|
||||
}
|
||||
|
||||
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
|
Reference in New Issue
Block a user