diff --git a/.hg_archival.txt b/.hg_archival.txt
--- a/.hg_archival.txt
+++ b/.hg_archival.txt
@@ -1,2 +1,2 @@
 repo: 98941e61c842f8b0ee8011f6a907f7e5f55fe0ac
-node: 64fa5d451fc22872970e333809c1611ada432698
+node: b87cf92e1808c07f761275eb45fd325ea6126549
diff --git a/bindings-libusb.cabal b/bindings-libusb.cabal
--- a/bindings-libusb.cabal
+++ b/bindings-libusb.cabal
@@ -1,9 +1,9 @@
 cabal-version: >= 1.2.3
 name: bindings-libusb
-homepage: http://bitbucket.org/mauricio/bindings
+homepage: http://bitbucket.org/mauricio/bindings-libusb
 synopsis:
-  Check bindings-common package for directions.
-version: 0.0.7
+  Low level bindings to libusb.
+version: 1.0
 license: BSD3
 license-file: LICENSE
 maintainer: Maurício C. Antunes <mauricio.antunes@gmail.com>
@@ -11,28 +11,25 @@
 build-type: Simple
 category: FFI
 bug-reports: http://bitbucket.org/mauricio/bindings-libusb/issues
-stability: Needs users feedback
 library
   hs-source-dirs: src
   extensions:
     ForeignFunctionInterface
-    TypeSynonymInstances
-    ScopedTypeVariables
-    EmptyDataDecls
-    TypeFamilies
   build-depends:
-    base >= 3 && <5, bindings-posix, bindings-common
+    base >= 3 && < 5,
+    bindings-common >= 1 && < 2,
+    bindings-posix >= 1 && < 2
   exposed-modules:
     Bindings.Libusb
-  other-modules:
-    LibusbConstants
-    LibusbFunctions
-    LibusbTypes
--- This has to be commented so hackage won't complain
--- about a missing library.
---  c-sources:
---    src/constants.c
---    src/functions.c
---    src/types.c
---  pkgconfig-depends:
---    libusb-1.0 >= 1.0.0
+    Bindings.Libusb.Asynchronous
+    Bindings.Libusb.Descriptors
+    Bindings.Libusb.HandlingAndEnumeration
+    Bindings.Libusb.InitializationDeinitialization
+    Bindings.Libusb.Miscellaneous
+    Bindings.Libusb.PollingAndTiming
+    Bindings.Libusb.Synchronous
+  include-dirs:
+    src/include
+  extra-libraries:
+    usb-1.0
+  c-sources: src/inlines.c
diff --git a/src/Bindings/Libusb.hs b/src/Bindings/Libusb.hs
deleted file mode 100644
--- a/src/Bindings/Libusb.hs
+++ /dev/null
@@ -1,211 +0,0 @@
-module Bindings.Libusb (
-
-    -- * Library initialization/deinitialization
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__lib.html>
-
-    Libusb_context,
-    libusb_set_debug,
-    libusb_init,
-    libusb_exit,
-    ptr_libusb_exit,
-
-    -- * Device handling and enumeration
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__dev.html>
-
-    Libusb_device,
-    Libusb_device_handle,
-    libusb_get_device_list,
-    libusb_free_device_list,
-    libusb_get_bus_number,
-    libusb_get_device_address,
-    libusb_get_max_packet_size,
-    libusb_ref_device,
-    libusb_unref_device,
-    ptr_libusb_unref_device,
-    libusb_open,
-    libusb_open_device_with_vid_pid,
-    libusb_close,
-    libusb_get_device,
-    libusb_get_configuration,
-    libusb_set_configuration,
-    libusb_claim_interface,
-    libusb_release_interface,
-    libusb_set_interface_alt_setting,
-    libusb_clear_halt,
-    libusb_reset_device,
-    libusb_kernel_driver_active,
-    libusb_attach_kernel_driver,
-    libusb_detach_kernel_driver,
-
-    -- * Miscellaneous
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__misc.html>
-
-    libusb_cpu_to_le16,
-    libusb_le16_to_cpu,
-    Libusb_standard_request,
-    _LIBUSB_REQUEST_GET_STATUS,
-    _LIBUSB_REQUEST_CLEAR_FEATURE,
-    _LIBUSB_REQUEST_SET_FEATURE,
-    _LIBUSB_REQUEST_SET_ADDRESS,
-    _LIBUSB_REQUEST_GET_DESCRIPTOR,
-    _LIBUSB_REQUEST_SET_DESCRIPTOR,
-    _LIBUSB_REQUEST_GET_CONFIGURATION,
-    _LIBUSB_REQUEST_SET_CONFIGURATION,
-    _LIBUSB_REQUEST_GET_INTERFACE,
-    _LIBUSB_REQUEST_SET_INTERFACE,
-    _LIBUSB_REQUEST_SYNCH_FRAME,
-    Libusb_request_type,
-    _LIBUSB_REQUEST_TYPE_STANDARD,
-    _LIBUSB_REQUEST_TYPE_CLASS,
-    _LIBUSB_REQUEST_TYPE_VENDOR,
-    _LIBUSB_REQUEST_TYPE_RESERVED,
-    Libusb_request_recipient,
-    _LIBUSB_RECIPIENT_DEVICE,
-    _LIBUSB_RECIPIENT_INTERFACE,
-    _LIBUSB_RECIPIENT_ENDPOINT,
-    _LIBUSB_RECIPIENT_OTHER,
-    Libusb_error,
-    _LIBUSB_SUCCESS,
-    _LIBUSB_ERROR_IO,
-    _LIBUSB_ERROR_INVALID_PARAM,
-    _LIBUSB_ERROR_ACCESS,
-    _LIBUSB_ERROR_NO_DEVICE,
-    _LIBUSB_ERROR_NOT_FOUND,
-    _LIBUSB_ERROR_BUSY,
-    _LIBUSB_ERROR_TIMEOUT,
-    _LIBUSB_ERROR_OVERFLOW,
-    _LIBUSB_ERROR_PIPE,
-    _LIBUSB_ERROR_INTERRUPTED,
-    _LIBUSB_ERROR_NO_MEM,
-    _LIBUSB_ERROR_NOT_SUPPORTED,
-    _LIBUSB_ERROR_OTHER,
-
-    -- * USB descriptors
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__desc.html>
-
-    Libusb_device_descriptor(..),
-    Libusb_endpoint_descriptor(..),
-    Libusb_interface_descriptor(..),
-    Libusb_interface(..),
-    Libusb_config_descriptor(..),
-    Libusb_class_code,
-    _LIBUSB_CLASS_PER_INTERFACE,
-    _LIBUSB_CLASS_AUDIO,
-    _LIBUSB_CLASS_COMM,
-    _LIBUSB_CLASS_HID,
-    _LIBUSB_CLASS_PRINTER,
-    _LIBUSB_CLASS_PTP,
-    _LIBUSB_CLASS_MASS_STORAGE,
-    _LIBUSB_CLASS_HUB,
-    _LIBUSB_CLASS_DATA,
-    _LIBUSB_CLASS_VENDOR_SPEC,
-    Libusb_descriptor_type,
-    _LIBUSB_DT_DEVICE,
-    _LIBUSB_DT_CONFIG,
-    _LIBUSB_DT_STRING,
-    _LIBUSB_DT_INTERFACE,
-    _LIBUSB_DT_ENDPOINT,
-    _LIBUSB_DT_HID,
-    _LIBUSB_DT_REPORT,
-    _LIBUSB_DT_PHYSICAL,
-    _LIBUSB_DT_HUB,
-    Libusb_endpoint_direction,
-    _LIBUSB_ENDPOINT_IN,
-    _LIBUSB_ENDPOINT_OUT,
-    Libusb_transfer_type,
-    _LIBUSB_TRANSFER_TYPE_CONTROL,
-    _LIBUSB_TRANSFER_TYPE_ISOCHRONOUS,
-    _LIBUSB_TRANSFER_TYPE_BULK,
-    _LIBUSB_TRANSFER_TYPE_INTERRUPT,
-    Libusb_iso_sync_type,
-    _LIBUSB_ISO_SYNC_TYPE_NONE,
-    _LIBUSB_ISO_SYNC_TYPE_ASYNC,
-    _LIBUSB_ISO_SYNC_TYPE_ADAPTIVE,
-    _LIBUSB_ISO_SYNC_TYPE_SYNC,
-    Libusb_iso_usage_type,
-    _LIBUSB_ISO_USAGE_TYPE_DATA,
-    _LIBUSB_ISO_USAGE_TYPE_FEEDBACK,
-    _LIBUSB_ISO_USAGE_TYPE_IMPLICIT,
-    libusb_get_device_descriptor,
-    libusb_get_active_config_descriptor,
-    libusb_get_config_descriptor,
-    libusb_get_config_descriptor_by_value,
-    libusb_free_config_descriptor,
-    libusb_get_string_descriptor_ascii,
-    libusb_get_descriptor,
-    libusb_get_string_descriptor,
-
-    -- * Asynchronous device I/O
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__asyncio.html>
-
-    Libusb_control_setup,
-    Libusb_iso_packet_descriptor,
-    Libusb_transfer,
-    Libusb_transfer_cb_fn,
-    Libusb_transfer_status,
-    _LIBUSB_TRANSFER_COMPLETED,
-    _LIBUSB_TRANSFER_ERROR,
-    _LIBUSB_TRANSFER_TIMED_OUT,
-    _LIBUSB_TRANSFER_CANCELLED,
-    _LIBUSB_TRANSFER_STALL,
-    _LIBUSB_TRANSFER_NO_DEVICE,
-    _LIBUSB_TRANSFER_OVERFLOW,
-    Libusb_transfer_flags,
-    _LIBUSB_TRANSFER_SHORT_NOT_OK,
-    _LIBUSB_TRANSFER_FREE_BUFFER,
-    _LIBUSB_TRANSFER_FREE_TRANSFER,
-    libusb_alloc_transfer,
-    libusb_free_transfer,
-    libusb_submit_transfer,
-    libusb_cancel_transfer,
-    libusb_control_transfer_get_data,
-    libusb_control_transfer_get_setup,
-    libusb_fill_control_setup,
-    libusb_fill_control_transfer,
-    libusb_fill_bulk_transfer,
-    libusb_fill_interrupt_transfer,
-    libusb_fill_iso_transfer,
-    libusb_set_iso_packet_lengths,
-    libusb_get_iso_packet_buffer,
-    libusb_get_iso_packet_buffer_simple,
-
-    -- * Polling and timing
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__poll.html>
-
-    Libusb_pollfd,
-    Libusb_pollfd_added_cb,
-    Libusb_pollfd_removed_cb,
-    libusb_try_lock_events,
-    libusb_lock_events,
-    libusb_unlock_events,
-    libusb_event_handling_ok,
-    libusb_event_handler_active,
-    libusb_lock_event_waiters,
-    libusb_unlock_event_waiters,
-    libusb_wait_for_event,
-    libusb_handle_events_timeout,
-    libusb_handle_events,
-    libusb_handle_events_locked,
-    libusb_get_next_timeout,
-    libusb_set_pollfd_notifiers,
-    libusb_get_pollfds,
-
-    -- * Synchronous device I/O
-
-    -- | <http://libusb.sourceforge.net/api-1.0/group__syncio.html>
-
-    libusb_interrupt_transfer,
-    libusb_bulk_transfer,
-    libusb_control_transfer
-
- ) where
-
-import LibusbTypes
-import LibusbFunctions
-import LibusbConstants
diff --git a/src/Bindings/Libusb.hsc b/src/Bindings/Libusb.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb.hsc
@@ -0,0 +1,18 @@
+-- | <http://libusb.sourceforge.net/api-1.0>
+
+module Bindings.Libusb (
+  module Bindings.Libusb.Asynchronous,
+  module Bindings.Libusb.Descriptors,
+  module Bindings.Libusb.HandlingAndEnumeration,
+  module Bindings.Libusb.InitializationDeinitialization,
+  module Bindings.Libusb.Miscellaneous,
+  module Bindings.Libusb.PollingAndTiming,
+  module Bindings.Libusb.Synchronous,
+ ) where
+import Bindings.Libusb.Asynchronous
+import Bindings.Libusb.Descriptors
+import Bindings.Libusb.HandlingAndEnumeration
+import Bindings.Libusb.InitializationDeinitialization
+import Bindings.Libusb.Miscellaneous
+import Bindings.Libusb.PollingAndTiming
+import Bindings.Libusb.Synchronous
diff --git a/src/Bindings/Libusb/Asynchronous.hsc b/src/Bindings/Libusb/Asynchronous.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/Asynchronous.hsc
@@ -0,0 +1,86 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__asyncio.html>
+
+module Bindings.Libusb.Asynchronous where
+import Foreign
+import Foreign.C
+import Bindings.Libusb.HandlingAndEnumeration
+
+#starttype struct libusb_control_setup
+#field bmRequestType , Word8
+#field bRequest , Word8
+#field wValue , Word16
+#field wIndex , Word16
+#field wLength , Word16
+#stoptype
+
+#starttype struct libusb_iso_packet_descriptor
+#field length , CUInt
+#field actual_length , CUInt
+#field status , <libusb_transfer_status>
+#stoptype
+
+#starttype struct libusb_transfer
+#field dev_handle , Ptr <libusb_device_handle>
+#field flags , Word8
+#field endpoint , CUChar
+#field type , CUChar
+#field timeout , CUInt
+#field status , <libusb_transfer_status>
+#field length , CInt
+#field actual_length , CInt
+#field callback , <libusb_transfer_cb_fn>
+#field user_data , Ptr ()
+#field buffer , Ptr CUChar
+#field num_iso_packets , CInt
+#stoptype
+
+#callback libusb_transfer_cb_fn , Ptr <libusb_transfer> -> IO ()
+
+#integral_t enum libusb_transfer_status
+
+#num LIBUSB_TRANSFER_COMPLETED
+#num LIBUSB_TRANSFER_ERROR
+#num LIBUSB_TRANSFER_TIMED_OUT
+#num LIBUSB_TRANSFER_CANCELLED
+#num LIBUSB_TRANSFER_STALL
+#num LIBUSB_TRANSFER_NO_DEVICE
+#num LIBUSB_TRANSFER_OVERFLOW
+
+#integral_t enum libusb_transfer_flags
+
+#num LIBUSB_TRANSFER_SHORT_NOT_OK
+#num LIBUSB_TRANSFER_FREE_BUFFER
+#num LIBUSB_TRANSFER_FREE_TRANSFER
+
+#ccall libusb_alloc_transfer , CInt -> \
+  IO (Ptr <libusb_transfer>)
+#ccall libusb_free_transfer , Ptr <libusb_transfer> -> IO ()
+#ccall libusb_submit_transfer , Ptr <libusb_transfer> -> IO CInt
+#ccall libusb_cancel_transfer , Ptr <libusb_transfer> -> IO CInt
+#cinline libusb_control_transfer_get_data , Ptr <libusb_transfer> -> \
+  IO (Ptr CUChar)
+#cinline libusb_control_transfer_get_setup , Ptr <libusb_transfer> -> \
+  IO (Ptr <libusb_control_setup>)
+#cinline libusb_fill_control_setup , Ptr CUChar ->  Word8 ->  Word8 -> \
+   Word16 ->  Word16 ->  Word16 -> IO ()
+#cinline libusb_fill_control_transfer , Ptr <libusb_transfer> -> \
+   Ptr <libusb_device_handle> ->  Ptr CUChar -> \
+   <libusb_transfer_cb_fn> ->  Ptr () ->  CUInt -> IO ()
+#cinline libusb_fill_bulk_transfer , Ptr <libusb_transfer> -> \
+   Ptr <libusb_device_handle> ->  CUChar ->  Ptr CUChar ->  CInt -> \
+   <libusb_transfer_cb_fn> ->  Ptr () ->  CUInt -> IO ()
+#cinline libusb_fill_interrupt_transfer , Ptr <libusb_transfer> -> \
+   Ptr <libusb_device_handle> ->  CUChar ->  Ptr CUChar ->  CInt -> \
+   <libusb_transfer_cb_fn> ->  Ptr () ->  CUInt -> IO ()
+#cinline libusb_fill_iso_transfer , Ptr <libusb_transfer> -> \
+   Ptr <libusb_device_handle> ->  CUChar ->  Ptr CUChar ->  CInt -> \
+   CInt ->  <libusb_transfer_cb_fn> ->  Ptr () ->  CUInt -> IO ()
+#cinline libusb_set_iso_packet_lengths , Ptr <libusb_transfer> -> \
+   CUInt -> IO ()
+#cinline libusb_get_iso_packet_buffer , Ptr <libusb_transfer> -> \
+   CUInt -> IO (Ptr CUChar)
+#cinline libusb_get_iso_packet_buffer_simple , Ptr <libusb_transfer> -> \
+   CUInt -> IO (Ptr CUChar)
diff --git a/src/Bindings/Libusb/Descriptors.hsc b/src/Bindings/Libusb/Descriptors.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/Descriptors.hsc
@@ -0,0 +1,150 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__desc.html>
+
+module Bindings.Libusb.Descriptors where
+import Foreign
+import Foreign.C
+import Bindings.Libusb.HandlingAndEnumeration
+
+#starttype struct libusb_device_descriptor
+#field bLength , Word8
+#field bDescriptorType , Word8
+#field bcdUSB , Word16
+#field bDeviceClass , Word8
+#field bDeviceSubClass , Word8
+#field bDeviceProtocol , Word8
+#field bMaxPacketSize0 , Word8
+#field idVendor , Word16
+#field idProduct , Word16
+#field bcdDevice , Word16
+#field iManufacturer , Word8
+#field iProduct , Word8
+#field iSerialNumber , Word8
+#field bNumConfigurations , Word8
+#stoptype
+
+#starttype struct libusb_endpoint_descriptor
+#field bLength , Word8
+#field bDescriptorType , Word8
+#field bEndpointAddress , Word8
+#field bmAttributes , Word8
+#field wMaxPacketSize , Word16
+#field bInterval , Word8
+#field bRefresh , Word8
+#field bSynchAddress , Word8
+#field extra , Ptr CUChar
+#field extra_length , CInt
+#stoptype
+
+#starttype struct libusb_interface_descriptor
+#field bLength , Word8
+#field bDescriptorType , Word8
+#field bInterfaceNumber , Word8
+#field bAlternateSetting , Word8
+#field bNumEndpoints , Word8
+#field bInterfaceClass , Word8
+#field bInterfaceSubClass , Word8
+#field bInterfaceProtocol , Word8
+#field iInterface , Word8
+#field endpoint , Ptr <libusb_endpoint_descriptor>
+#field extra , Ptr CUChar
+#field extra_length , CInt
+#stoptype
+
+#starttype struct libusb_interface
+#field altsetting , Ptr <libusb_interface_descriptor>
+#field num_altsetting , CInt
+#stoptype
+
+#starttype struct libusb_config_descriptor
+#field bLength , Word8
+#field bDescriptorType , Word8
+#field wTotalLength , Word16
+#field bNumInterfaces , Word8
+#field bConfigurationValue , Word8
+#field iConfiguration , Word8
+#field bmAttributes , Word8
+#field MaxPower , Word8
+#field interface , Ptr <libusb_interface>
+#field extra , Ptr CUChar
+#field extra_length , CInt
+#stoptype
+
+#integral_t enum libusb_class_code
+
+#num LIBUSB_CLASS_PER_INTERFACE
+#num LIBUSB_CLASS_AUDIO
+#num LIBUSB_CLASS_COMM
+#num LIBUSB_CLASS_HID
+#num LIBUSB_CLASS_PRINTER
+#num LIBUSB_CLASS_PTP
+#num LIBUSB_CLASS_MASS_STORAGE
+#num LIBUSB_CLASS_HUB
+#num LIBUSB_CLASS_DATA
+#num LIBUSB_CLASS_VENDOR_SPEC
+
+#integral_t enum libusb_descriptor_type
+
+#num LIBUSB_DT_DEVICE
+#num LIBUSB_DT_CONFIG
+#num LIBUSB_DT_STRING
+#num LIBUSB_DT_INTERFACE
+#num LIBUSB_DT_ENDPOINT
+#num LIBUSB_DT_HID
+#num LIBUSB_DT_REPORT
+#num LIBUSB_DT_PHYSICAL
+#num LIBUSB_DT_HUB
+
+#integral_t enum libusb_endpoint_direction
+
+#num LIBUSB_ENDPOINT_IN
+#num LIBUSB_ENDPOINT_OUT
+
+#integral_t enum libusb_transfer_type
+
+#num LIBUSB_TRANSFER_TYPE_CONTROL
+#num LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
+#num LIBUSB_TRANSFER_TYPE_BULK
+#num LIBUSB_TRANSFER_TYPE_INTERRUPT
+
+#integral_t enum libusb_iso_sync_type
+
+#num LIBUSB_ISO_SYNC_TYPE_NONE
+#num LIBUSB_ISO_SYNC_TYPE_ASYNC
+#num LIBUSB_ISO_SYNC_TYPE_ADAPTIVE
+#num LIBUSB_ISO_SYNC_TYPE_SYNC
+
+#integral_t enum libusb_iso_usage_type
+
+#num LIBUSB_ISO_USAGE_TYPE_DATA
+#num LIBUSB_ISO_USAGE_TYPE_FEEDBACK
+#num LIBUSB_ISO_USAGE_TYPE_IMPLICIT
+
+#ccall libusb_get_device_descriptor , Ptr <libusb_device> -> \
+  Ptr <libusb_device_descriptor> -> IO CInt
+
+#ccall libusb_get_active_config_descriptor , Ptr <libusb_device> -> \
+  Ptr (Ptr <libusb_config_descriptor>) -> IO CInt
+
+#ccall libusb_get_config_descriptor , Ptr <libusb_device> -> \
+  Word8 -> Ptr (Ptr <libusb_config_descriptor>) -> IO CInt
+
+#ccall libusb_get_config_descriptor_by_value , Ptr <libusb_device> -> \
+  Word8 -> Ptr (Ptr <libusb_config_descriptor>) -> \
+  IO CInt
+
+#ccall libusb_free_config_descriptor , Ptr <libusb_config_descriptor> -> \
+  IO ()
+
+#ccall libusb_get_string_descriptor_ascii , Ptr <libusb_device_handle> -> \
+  Word8 -> Ptr CUChar -> CInt -> IO CInt
+
+#cinline libusb_get_descriptor , Ptr <libusb_device_handle> -> \
+  Word8 -> Word8 -> Ptr CUChar -> \
+  CInt -> IO CInt
+
+#cinline libusb_get_string_descriptor , Ptr <libusb_device_handle> -> \
+  Word8 -> Word16 -> Ptr CUChar -> \
+  CInt -> IO CInt
diff --git a/src/Bindings/Libusb/HandlingAndEnumeration.hsc b/src/Bindings/Libusb/HandlingAndEnumeration.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/HandlingAndEnumeration.hsc
@@ -0,0 +1,52 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__dev.html>
+
+module Bindings.Libusb.HandlingAndEnumeration where
+import Foreign
+import Foreign.C
+import Bindings.Posix.Sys.Types
+import Bindings.Libusb.InitializationDeinitialization
+
+#opaque_t libusb_device
+#opaque_t libusb_device_handle
+
+#ccall libusb_get_device_list , Ptr <libusb_context> -> \
+  Ptr (Ptr (Ptr <libusb_device>)) -> IO <ssize_t>
+#ccall libusb_free_device_list , Ptr (Ptr <libusb_device>) -> \
+  CInt -> IO ()
+#ccall libusb_get_bus_number , Ptr <libusb_device> -> IO Word8
+#ccall libusb_get_device_address , Ptr <libusb_device> -> IO Word8
+#ccall libusb_get_max_packet_size , Ptr <libusb_device> -> \
+  CUChar -> IO CInt
+#ccall libusb_ref_device , Ptr <libusb_device> -> \
+  IO (Ptr <libusb_device>)
+#ccall libusb_unref_device , Ptr <libusb_device> -> IO ()
+#ccall libusb_open , Ptr <libusb_device> -> \
+  Ptr (Ptr <libusb_device_handle>) -> IO CInt
+#ccall libusb_open_device_with_vid_pid , Ptr <libusb_context> -> \
+  Word16 -> Word16 -> \
+  IO (Ptr <libusb_device_handle>)
+#ccall libusb_close , Ptr <libusb_device_handle> -> IO ()
+#ccall libusb_get_device , Ptr <libusb_device_handle> -> \
+  IO (Ptr <libusb_device>)
+#ccall libusb_get_configuration , Ptr <libusb_device_handle> -> \
+  Ptr int -> IO CInt
+#ccall libusb_set_configuration , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
+#ccall libusb_claim_interface , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
+#ccall libusb_release_interface , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
+#ccall libusb_set_interface_alt_setting , Ptr <libusb_device_handle> -> \
+  CInt -> CInt -> IO CInt
+#ccall libusb_clear_halt , Ptr <libusb_device_handle> -> \
+  CUChar -> IO CInt
+#ccall libusb_reset_device , Ptr <libusb_device_handle> -> IO CInt
+#ccall libusb_kernel_driver_active , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
+#ccall libusb_detach_kernel_driver , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
+#ccall libusb_attach_kernel_driver , Ptr <libusb_device_handle> -> \
+  CInt -> IO CInt
diff --git a/src/Bindings/Libusb/InitializationDeinitialization.hsc b/src/Bindings/Libusb/InitializationDeinitialization.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/InitializationDeinitialization.hsc
@@ -0,0 +1,14 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__lib.html>
+
+module Bindings.Libusb.InitializationDeinitialization where
+import Foreign
+import Foreign.C
+
+#opaque_t libusb_context
+
+#ccall libusb_set_debug , Ptr <libusb_context> -> CInt -> IO ()
+#ccall libusb_init , Ptr (Ptr <libusb_context>) -> IO CInt
+#ccall libusb_exit , Ptr <libusb_context> -> IO ()
diff --git a/src/Bindings/Libusb/Miscellaneous.hsc b/src/Bindings/Libusb/Miscellaneous.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/Miscellaneous.hsc
@@ -0,0 +1,57 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__misc.html>
+
+module Bindings.Libusb.Miscellaneous where
+import Foreign
+import Foreign.C
+
+#cinline libusb_cpu_to_le16 , Word16 -> Word16
+#cinline libusb_le16_to_cpu , Word16 -> Word16
+
+#integral_t enum libusb_standard_request
+
+#num LIBUSB_REQUEST_GET_STATUS
+#num LIBUSB_REQUEST_CLEAR_FEATURE
+#num LIBUSB_REQUEST_SET_FEATURE
+#num LIBUSB_REQUEST_SET_ADDRESS
+#num LIBUSB_REQUEST_GET_DESCRIPTOR
+#num LIBUSB_REQUEST_SET_DESCRIPTOR
+#num LIBUSB_REQUEST_GET_CONFIGURATION
+#num LIBUSB_REQUEST_SET_CONFIGURATION
+#num LIBUSB_REQUEST_GET_INTERFACE
+#num LIBUSB_REQUEST_SET_INTERFACE
+#num LIBUSB_REQUEST_SYNCH_FRAME
+
+#integral_t enum libusb_request_type
+
+#num LIBUSB_REQUEST_TYPE_STANDARD
+#num LIBUSB_REQUEST_TYPE_CLASS
+#num LIBUSB_REQUEST_TYPE_VENDOR
+#num LIBUSB_REQUEST_TYPE_RESERVED
+
+#integral_t enum libusb_request_recipient
+
+#num LIBUSB_RECIPIENT_DEVICE
+#num LIBUSB_RECIPIENT_INTERFACE
+#num LIBUSB_RECIPIENT_ENDPOINT
+#num LIBUSB_RECIPIENT_OTHER
+
+#integral_t enum libusb_error
+
+#num LIBUSB_SUCCESS
+#num LIBUSB_ERROR_IO
+#num LIBUSB_ERROR_INVALID_PARAM
+#num LIBUSB_ERROR_ACCESS
+#num LIBUSB_ERROR_NO_DEVICE
+#num LIBUSB_ERROR_NOT_FOUND
+#num LIBUSB_ERROR_BUSY
+#num LIBUSB_ERROR_TIMEOUT
+#num LIBUSB_ERROR_OVERFLOW
+#num LIBUSB_ERROR_PIPE
+#num LIBUSB_ERROR_INTERRUPTED
+#num LIBUSB_ERROR_NO_MEM
+#num LIBUSB_ERROR_NOT_SUPPORTED
+#num LIBUSB_ERROR_OTHER
+
diff --git a/src/Bindings/Libusb/PollingAndTiming.hsc b/src/Bindings/Libusb/PollingAndTiming.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/PollingAndTiming.hsc
@@ -0,0 +1,40 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__poll.html>
+
+module Bindings.Libusb.PollingAndTiming where
+import Foreign
+import Foreign.C
+import Bindings.Posix.Sys.Select
+import Bindings.Libusb.InitializationDeinitialization
+
+#starttype struct libusb_pollfd
+#field fd , CInt
+#field events , CShort
+#stoptype
+
+#callback libusb_pollfd_added_cb , CInt -> CShort -> Ptr () -> IO ()
+#callback libusb_pollfd_removed_cb , CInt -> Ptr () -> IO ()
+
+#ccall libusb_try_lock_events , Ptr <libusb_context> -> IO CInt
+#ccall libusb_lock_events , Ptr <libusb_context> -> IO ()
+#ccall libusb_unlock_events , Ptr <libusb_context> -> IO ()
+#ccall libusb_event_handling_ok , Ptr <libusb_context> -> IO CInt
+#ccall libusb_event_handler_active , Ptr <libusb_context> -> IO CInt
+#ccall libusb_lock_event_waiters , Ptr <libusb_context> -> IO ()
+#ccall libusb_unlock_event_waiters , Ptr <libusb_context> -> IO ()
+#ccall libusb_wait_for_event , Ptr <libusb_context> ->  \
+  Ptr <timeval> -> IO CInt
+#ccall libusb_handle_events_timeout , Ptr <libusb_context> ->  \
+  Ptr <timeval> -> IO CInt
+#ccall libusb_handle_events , Ptr <libusb_context> -> IO CInt
+#ccall libusb_handle_events_locked , Ptr <libusb_context> ->  \
+  Ptr <timeval> -> IO CInt
+#ccall libusb_get_next_timeout , Ptr <libusb_context> ->  \
+  Ptr <timeval> -> IO CInt
+#ccall libusb_set_pollfd_notifiers , Ptr <libusb_context> ->  \
+  <libusb_pollfd_added_cb> -> <libusb_pollfd_removed_cb> ->  \
+  Ptr () -> IO ()
+#ccall libusb_get_pollfds , Ptr <libusb_context> ->  \
+  IO (Ptr (Ptr <libusb_pollfd>))
diff --git a/src/Bindings/Libusb/Synchronous.hsc b/src/Bindings/Libusb/Synchronous.hsc
new file mode 100644
--- /dev/null
+++ b/src/Bindings/Libusb/Synchronous.hsc
@@ -0,0 +1,18 @@
+#include <bindings.macros.h>
+#include <libusb.h>
+
+-- | <http://libusb.sourceforge.net/api-1.0/group__syncio.html>
+
+module Bindings.Libusb.Synchronous where
+import Foreign
+import Foreign.C
+import Bindings.Libusb.HandlingAndEnumeration
+
+#ccall libusb_control_transfer , Ptr <libusb_device_handle> -> \
+   Word8 ->  Word8 ->  Word16 ->  Word16 ->  Ptr CUChar -> \
+   Word16 ->  CUInt -> IO CInt
+#ccall libusb_bulk_transfer ,  Ptr <libusb_device_handle> -> \
+   CUChar ->  Ptr CUChar ->  CInt ->  Ptr CInt ->  CUInt -> IO CInt
+#ccall libusb_interrupt_transfer ,  Ptr <libusb_device_handle> -> \
+   CUChar ->  Ptr CUChar ->  CInt ->  Ptr CInt ->  CUInt -> IO CInt
+
diff --git a/src/LibusbConstants.hs b/src/LibusbConstants.hs
deleted file mode 100644
--- a/src/LibusbConstants.hs
+++ /dev/null
@@ -1,229 +0,0 @@
-module LibusbConstants where
-import Foreign
-import LibusbTypes
-
-foreign import ccall "_LIBUSB_REQUEST_GET_STATUS"
- _LIBUSB_REQUEST_GET_STATUS :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_CLEAR_FEATURE"
- _LIBUSB_REQUEST_CLEAR_FEATURE :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SET_FEATURE"
- _LIBUSB_REQUEST_SET_FEATURE :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SET_ADDRESS"
- _LIBUSB_REQUEST_SET_ADDRESS :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_GET_DESCRIPTOR"
- _LIBUSB_REQUEST_GET_DESCRIPTOR :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SET_DESCRIPTOR"
- _LIBUSB_REQUEST_SET_DESCRIPTOR :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_GET_CONFIGURATION"
- _LIBUSB_REQUEST_GET_CONFIGURATION :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SET_CONFIGURATION"
- _LIBUSB_REQUEST_SET_CONFIGURATION :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_GET_INTERFACE"
- _LIBUSB_REQUEST_GET_INTERFACE :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SET_INTERFACE"
- _LIBUSB_REQUEST_SET_INTERFACE :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_SYNCH_FRAME"
- _LIBUSB_REQUEST_SYNCH_FRAME :: Libusb_standard_request
-
-foreign import ccall "_LIBUSB_REQUEST_TYPE_STANDARD"
- _LIBUSB_REQUEST_TYPE_STANDARD :: Libusb_request_type
-
-foreign import ccall "_LIBUSB_REQUEST_TYPE_CLASS"
- _LIBUSB_REQUEST_TYPE_CLASS :: Libusb_request_type
-
-foreign import ccall "_LIBUSB_REQUEST_TYPE_VENDOR"
- _LIBUSB_REQUEST_TYPE_VENDOR :: Libusb_request_type
-
-foreign import ccall "_LIBUSB_REQUEST_TYPE_RESERVED"
- _LIBUSB_REQUEST_TYPE_RESERVED :: Libusb_request_type
-
-foreign import ccall "_LIBUSB_RECIPIENT_DEVICE"
- _LIBUSB_RECIPIENT_DEVICE :: Libusb_request_recipient
-
-foreign import ccall "_LIBUSB_RECIPIENT_INTERFACE"
- _LIBUSB_RECIPIENT_INTERFACE :: Libusb_request_recipient
-
-foreign import ccall "_LIBUSB_RECIPIENT_ENDPOINT"
- _LIBUSB_RECIPIENT_ENDPOINT :: Libusb_request_recipient
-
-foreign import ccall "_LIBUSB_RECIPIENT_OTHER"
- _LIBUSB_RECIPIENT_OTHER :: Libusb_request_recipient
-
-foreign import ccall "_LIBUSB_SUCCESS"
- _LIBUSB_SUCCESS :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_IO"
- _LIBUSB_ERROR_IO :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_INVALID_PARAM"
- _LIBUSB_ERROR_INVALID_PARAM :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_ACCESS"
- _LIBUSB_ERROR_ACCESS :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_NO_DEVICE"
- _LIBUSB_ERROR_NO_DEVICE :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_NOT_FOUND"
- _LIBUSB_ERROR_NOT_FOUND :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_BUSY"
- _LIBUSB_ERROR_BUSY :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_TIMEOUT"
- _LIBUSB_ERROR_TIMEOUT :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_OVERFLOW"
- _LIBUSB_ERROR_OVERFLOW :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_PIPE"
- _LIBUSB_ERROR_PIPE :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_INTERRUPTED"
- _LIBUSB_ERROR_INTERRUPTED :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_NO_MEM"
- _LIBUSB_ERROR_NO_MEM :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_NOT_SUPPORTED"
- _LIBUSB_ERROR_NOT_SUPPORTED :: Libusb_error
-
-foreign import ccall "_LIBUSB_ERROR_OTHER"
- _LIBUSB_ERROR_OTHER :: Libusb_error
-
-foreign import ccall "_LIBUSB_CLASS_PER_INTERFACE"
- _LIBUSB_CLASS_PER_INTERFACE :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_AUDIO"
- _LIBUSB_CLASS_AUDIO :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_COMM"
- _LIBUSB_CLASS_COMM :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_HID"
- _LIBUSB_CLASS_HID :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_PRINTER"
- _LIBUSB_CLASS_PRINTER :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_PTP"
- _LIBUSB_CLASS_PTP :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_MASS_STORAGE"
- _LIBUSB_CLASS_MASS_STORAGE :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_HUB"
- _LIBUSB_CLASS_HUB :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_DATA"
- _LIBUSB_CLASS_DATA :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_CLASS_VENDOR_SPEC"
- _LIBUSB_CLASS_VENDOR_SPEC :: Libusb_class_code
-
-foreign import ccall "_LIBUSB_DT_DEVICE"
- _LIBUSB_DT_DEVICE :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_CONFIG"
- _LIBUSB_DT_CONFIG :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_STRING"
- _LIBUSB_DT_STRING :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_INTERFACE"
- _LIBUSB_DT_INTERFACE :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_ENDPOINT"
- _LIBUSB_DT_ENDPOINT :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_HID"
- _LIBUSB_DT_HID :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_REPORT"
- _LIBUSB_DT_REPORT :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_PHYSICAL"
- _LIBUSB_DT_PHYSICAL :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_DT_HUB"
- _LIBUSB_DT_HUB :: Libusb_descriptor_type
-
-foreign import ccall "_LIBUSB_ENDPOINT_IN"
- _LIBUSB_ENDPOINT_IN :: Libusb_endpoint_direction
-
-foreign import ccall "_LIBUSB_ENDPOINT_OUT"
- _LIBUSB_ENDPOINT_OUT :: Libusb_endpoint_direction
-
-foreign import ccall "_LIBUSB_TRANSFER_TYPE_CONTROL"
- _LIBUSB_TRANSFER_TYPE_CONTROL :: Libusb_transfer_type
-
-foreign import ccall "_LIBUSB_TRANSFER_TYPE_ISOCHRONOUS"
- _LIBUSB_TRANSFER_TYPE_ISOCHRONOUS :: Libusb_transfer_type
-
-foreign import ccall "_LIBUSB_TRANSFER_TYPE_BULK"
- _LIBUSB_TRANSFER_TYPE_BULK :: Libusb_transfer_type
-
-foreign import ccall "_LIBUSB_TRANSFER_TYPE_INTERRUPT"
- _LIBUSB_TRANSFER_TYPE_INTERRUPT :: Libusb_transfer_type
-
-foreign import ccall "_LIBUSB_ISO_SYNC_TYPE_NONE"
- _LIBUSB_ISO_SYNC_TYPE_NONE :: Libusb_iso_sync_type
-
-foreign import ccall "_LIBUSB_ISO_SYNC_TYPE_ASYNC"
- _LIBUSB_ISO_SYNC_TYPE_ASYNC :: Libusb_iso_sync_type
-
-foreign import ccall "_LIBUSB_ISO_SYNC_TYPE_ADAPTIVE"
- _LIBUSB_ISO_SYNC_TYPE_ADAPTIVE :: Libusb_iso_sync_type
-
-foreign import ccall "_LIBUSB_ISO_SYNC_TYPE_SYNC"
- _LIBUSB_ISO_SYNC_TYPE_SYNC :: Libusb_iso_sync_type
-
-foreign import ccall "_LIBUSB_ISO_USAGE_TYPE_DATA"
- _LIBUSB_ISO_USAGE_TYPE_DATA :: Libusb_iso_usage_type
-
-foreign import ccall "_LIBUSB_ISO_USAGE_TYPE_FEEDBACK"
- _LIBUSB_ISO_USAGE_TYPE_FEEDBACK :: Libusb_iso_usage_type
-
-foreign import ccall "_LIBUSB_ISO_USAGE_TYPE_IMPLICIT"
- _LIBUSB_ISO_USAGE_TYPE_IMPLICIT :: Libusb_iso_usage_type
-
-foreign import ccall "_LIBUSB_TRANSFER_COMPLETED"
- _LIBUSB_TRANSFER_COMPLETED :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_ERROR"
- _LIBUSB_TRANSFER_ERROR :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_TIMED_OUT"
- _LIBUSB_TRANSFER_TIMED_OUT :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_CANCELLED"
- _LIBUSB_TRANSFER_CANCELLED :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_STALL"
- _LIBUSB_TRANSFER_STALL :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_NO_DEVICE"
- _LIBUSB_TRANSFER_NO_DEVICE :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_OVERFLOW"
- _LIBUSB_TRANSFER_OVERFLOW :: Libusb_transfer_status
-
-foreign import ccall "_LIBUSB_TRANSFER_SHORT_NOT_OK"
- _LIBUSB_TRANSFER_SHORT_NOT_OK :: Libusb_transfer_flags
-
-foreign import ccall "_LIBUSB_TRANSFER_FREE_BUFFER"
- _LIBUSB_TRANSFER_FREE_BUFFER :: Libusb_transfer_flags
-
-foreign import ccall "_LIBUSB_TRANSFER_FREE_TRANSFER"
- _LIBUSB_TRANSFER_FREE_TRANSFER :: Libusb_transfer_flags
-
diff --git a/src/LibusbFunctions.hs b/src/LibusbFunctions.hs
deleted file mode 100644
--- a/src/LibusbFunctions.hs
+++ /dev/null
@@ -1,262 +0,0 @@
-module LibusbFunctions where
-import Bindings.C
-import Bindings.Posix
-import Foreign
-import Foreign.C
-import LibusbTypes
-
-foreign import ccall "libusb_set_debug" libusb_set_debug
-    :: Ptr Libusb_context -> CInt -> IO () ;
-
-foreign import ccall "libusb_init" libusb_init
-    :: Ptr (Ptr Libusb_context) -> IO CInt
-
-foreign import ccall "libusb_exit" libusb_exit
-    :: Ptr Libusb_context -> IO ()
-
-foreign import ccall "&libusb_exit" ptr_libusb_exit
-    :: FunPtr (Ptr Libusb_context -> IO ())
-
-foreign import ccall "libusb_get_device_list" libusb_get_device_list
-    :: Ptr Libusb_context -> Ptr (Ptr (Ptr Libusb_device)) -> IO CInt
-
-foreign import ccall "libusb_free_device_list" libusb_free_device_list
-   :: Ptr (Ptr Libusb_device) -> CInt -> IO ()
-
-foreign import ccall "libusb_get_bus_number" libusb_get_bus_number
-    :: Ptr Libusb_device -> IO Word8
-
-foreign import ccall "libusb_get_device_address"
- libusb_get_device_address
-    :: Ptr Libusb_device -> IO Word8
-
-foreign import ccall "libusb_get_max_packet_size"
- libusb_get_max_packet_size
-    :: Ptr Libusb_device -> CUChar -> IO CInt
-
-foreign import ccall "libusb_ref_device" libusb_ref_device
-    :: Ptr Libusb_device -> IO (Ptr Libusb_device)
-
-foreign import ccall "libusb_unref_device" libusb_unref_device
-    :: Ptr Libusb_device -> IO ()
-
-foreign import ccall "&libusb_unref_device" ptr_libusb_unref_device
-    :: FunPtr (Ptr Libusb_device -> IO ())
-
-foreign import ccall "libusb_open" libusb_open
-    :: Ptr Libusb_device -> Ptr (Ptr Libusb_device_handle) -> IO CInt
-
-foreign import ccall "libusb_open_device_with_vid_pid"
- libusb_open_device_with_vid_pid
-    :: Ptr Libusb_context -> Word16 -> Word16 ->
-       IO (Ptr Libusb_device_handle)
-
-foreign import ccall "libusb_close" libusb_close
-    :: Ptr Libusb_device_handle -> IO ()
-
-foreign import ccall "libusb_get_device" libusb_get_device
-    :: Ptr Libusb_device_handle -> IO (Ptr Libusb_device)
-
-foreign import ccall "libusb_get_configuration"
- libusb_get_configuration
-    :: Ptr Libusb_device_handle -> Ptr CInt -> IO CInt
-
-foreign import ccall "libusb_set_configuration"
- libusb_set_configuration
-    :: Ptr Libusb_device_handle -> CInt -> IO CInt
-
-foreign import ccall "libusb_claim_interface" libusb_claim_interface
-    :: Ptr Libusb_device_handle -> CInt -> IO CInt
-
-foreign import ccall "libusb_release_interface"
- libusb_release_interface
-    :: Ptr Libusb_device_handle -> CInt -> IO CInt
-
-foreign import ccall "libusb_set_interface_alt_setting"
- libusb_set_interface_alt_setting
-    :: Ptr Libusb_device_handle -> CInt -> CInt -> IO CInt
-
-foreign import ccall "libusb_clear_halt" libusb_clear_halt
-    :: Ptr Libusb_device_handle -> CUChar -> IO CInt
-
-foreign import ccall "libusb_reset_device" libusb_reset_device
-    :: Ptr Libusb_device_handle -> IO CInt
-
-foreign import ccall "libusb_kernel_driver_active"
- libusb_kernel_driver_active
-    :: Ptr Libusb_device_handle -> CInt   -> IO CInt
-
-foreign import ccall "libusb_detach_kernel_driver"
- libusb_detach_kernel_driver
-    :: Ptr Libusb_device_handle -> CInt -> IO CInt
-
-foreign import ccall "libusb_attach_kernel_driver"
- libusb_attach_kernel_driver
-    :: Ptr Libusb_device_handle -> CInt -> IO CInt
-
-foreign import ccall "_libusb_cpu_to_le16" libusb_cpu_to_le16
-    :: Word16 -> Word16
-
-foreign import ccall "_libusb_le16_to_cpu" libusb_le16_to_cpu
-    :: Word16 -> Word16
-
-foreign import ccall "libusb_get_device_descriptor"
- libusb_get_device_descriptor
-    :: Ptr Libusb_device -> Ptr Libusb_device_descriptor -> IO CInt
-
-foreign import ccall "libusb_get_active_config_descriptor"
- libusb_get_active_config_descriptor
-    :: Ptr Libusb_device -> Ptr
-       (Ptr Libusb_config_descriptor) -> IO CInt
-
-foreign import ccall "libusb_get_config_descriptor"
- libusb_get_config_descriptor
-    :: Ptr Libusb_device -> Word8 -> Ptr
-       (Ptr Libusb_config_descriptor) -> IO CInt
-
-foreign import ccall "libusb_get_config_descriptor_by_value"
- libusb_get_config_descriptor_by_value
-    :: Ptr Libusb_device -> Word8 -> Ptr (Ptr Libusb_config_descriptor) ->
-       IO CInt
-
-foreign import ccall "libusb_free_config_descriptor"
- libusb_free_config_descriptor
-    :: Ptr Libusb_config_descriptor -> IO ()
-
-foreign import ccall "libusb_get_string_descriptor_ascii"
- libusb_get_string_descriptor_ascii
-    :: Ptr Libusb_device_handle -> Word8 -> Ptr CUChar -> CInt -> IO CInt
-
-foreign import ccall "libusb_get_descriptor2" libusb_get_descriptor
-    :: Ptr Libusb_device_handle -> Word8 -> Word8 -> Ptr CUChar ->
-       CInt -> IO CInt
-
-foreign import ccall "libusb_get_string_descriptor2"
- libusb_get_string_descriptor
-    :: Ptr Libusb_device_handle -> Word8 ->
-       Word16 -> Ptr CUChar -> CInt -> IO CInt
-
-foreign import ccall "libusb_alloc_transfer" libusb_alloc_transfer
-    :: CInt -> IO (Ptr (Libusb_transfer a))
-
-foreign import ccall "libusb_free_transfer" libusb_free_transfer
-    :: Ptr (Libusb_transfer a)
-
-foreign import ccall "libusb_submit_transfer" libusb_submit_transfer
-    :: Ptr (Libusb_transfer a) -> IO CInt
-
-foreign import ccall "libusb_cancel_transfer" libusb_cancel_transfer
-    :: Ptr (Libusb_transfer a) -> IO CInt
-
-foreign import ccall "libusb_control_transfer_get_data2"
- libusb_control_transfer_get_data
-    :: Ptr (Libusb_transfer a) -> IO (Ptr CUChar)
-
-foreign import ccall "libusb_control_transfer_get_setup2"
- libusb_control_transfer_get_setup
-    :: Ptr (Libusb_transfer a) -> IO (Ptr Libusb_control_setup)
-
-foreign import ccall "libusb_fill_control_setup2"
- libusb_fill_control_setup
-    :: Ptr CUChar -> Word8 -> Word8 ->
-       Word16 -> Word16 -> Word16 -> IO ()
-
-foreign import ccall "libusb_fill_control_transfer2"
- libusb_fill_control_transfer
-    :: Ptr (Libusb_transfer a) -> Ptr Libusb_device_handle ->
-       Ptr CUChar -> FunPtr (Libusb_transfer_cb_fn a) ->
-       Ptr a -> CUInt -> IO ()
-
-foreign import ccall "libusb_fill_bulk_transfer2"
- libusb_fill_bulk_transfer
-    :: Ptr (Libusb_transfer a) -> Ptr Libusb_device_handle -> CUChar ->
-       Ptr CUChar -> CInt -> FunPtr (Libusb_transfer_cb_fn a) ->
-       Ptr a -> CUInt -> IO ()
-
-foreign import ccall "libusb_fill_interrupt_transfer2"
- libusb_fill_interrupt_transfer
-    :: Ptr (Libusb_transfer a) -> Ptr Libusb_device_handle -> CUChar ->
-       Ptr CUChar -> CInt -> FunPtr (Libusb_transfer_cb_fn a) ->
-       Ptr a -> CUInt -> IO ()
-
-foreign import ccall "libusb_fill_iso_transfer2"
- libusb_fill_iso_transfer
-    :: Ptr (Libusb_transfer a) -> Ptr Libusb_device_handle -> CUChar ->
-       Ptr CUChar -> CInt -> CInt -> FunPtr (Libusb_transfer_cb_fn a) ->
-       Ptr a -> CUInt -> IO ()
-
-foreign import ccall "libusb_set_iso_packet_lengths2"
- libusb_set_iso_packet_lengths
-    :: Ptr (Libusb_transfer a) -> CUInt -> IO ()
-
-foreign import ccall "libusb_get_iso_packet_buffer2"
- libusb_get_iso_packet_buffer
-    :: Ptr (Libusb_transfer a) -> CUInt -> IO (Ptr CUChar)
-
-foreign import ccall "libusb_get_iso_packet_buffer_simple2"
- libusb_get_iso_packet_buffer_simple
-    :: Ptr (Libusb_transfer a) -> CUInt -> IO (Ptr CUChar)
-
-foreign import ccall "libusb_try_lock_events" libusb_try_lock_events
-    :: Ptr Libusb_context -> IO CInt
-
-foreign import ccall "libusb_lock_events" libusb_lock_events
-    :: Ptr Libusb_context -> IO ()
-
-foreign import ccall "libusb_unlock_events" libusb_unlock_events
-    :: Ptr Libusb_context -> IO ()
-
-foreign import ccall "libusb_event_handling_ok"
- libusb_event_handling_ok
-    :: Ptr Libusb_context -> IO CInt
-
-foreign import ccall "libusb_event_handler_active"
- libusb_event_handler_active
-    :: Ptr Libusb_context -> IO CInt
-
-foreign import ccall "libusb_lock_event_waiters"
- libusb_lock_event_waiters
-    :: Ptr Libusb_context -> IO ()
-
-foreign import ccall "libusb_unlock_event_waiters"
- libusb_unlock_event_waiters
-    :: Ptr Libusb_context -> IO ()
-
-foreign import ccall "libusb_wait_for_event" libusb_wait_for_event
-    :: Ptr Libusb_context -> Ptr Timeval -> IO CInt
-
-foreign import ccall "libusb_handle_events_timeout"
- libusb_handle_events_timeout
-    :: Ptr Libusb_context -> Ptr Timeval -> IO CInt
-
-foreign import ccall "libusb_handle_events" libusb_handle_events
-    :: Ptr Libusb_context -> IO CInt
-
-foreign import ccall "libusb_handle_events_locked"
- libusb_handle_events_locked
-    :: Ptr Libusb_context -> Ptr Timeval -> IO CInt
-
-foreign import ccall "libusb_get_next_timeout" libusb_get_next_timeout
-   :: Ptr Libusb_context -> Ptr Timeval -> IO CInt
-
-foreign import ccall "libusb_set_pollfd_notifiers"
- libusb_set_pollfd_notifiers
-    :: Ptr Libusb_context -> Libusb_pollfd_added_cb a ->
-       Libusb_pollfd_removed_cb a -> Ptr a -> IO ()
-
-foreign import ccall "libusb_get_pollfds" libusb_get_pollfds
-    :: Ptr Libusb_context -> IO (Ptr (Ptr Libusb_pollfd)) ;
-
-foreign import ccall "libusb_interrupt_transfer"
- libusb_interrupt_transfer
-    :: Ptr Libusb_device_handle -> CUChar -> Ptr CUChar ->
-       CInt -> Ptr CInt -> CUInt -> IO CInt
-
-foreign import ccall "libusb_bulk_transfer" libusb_bulk_transfer
-    :: Ptr Libusb_device_handle -> CUChar -> Ptr CUChar -> CInt ->
-       Ptr CInt -> CUInt -> IO CInt
-
-foreign import ccall "libusb_control_transfer" libusb_control_transfer
-   :: Ptr Libusb_device_handle -> Word8 -> Word8 -> Word16 -> Word16 ->
-      Ptr CUChar -> Word16 -> CUInt -> IO CInt
-
diff --git a/src/LibusbTypes.hs b/src/LibusbTypes.hs
deleted file mode 100644
--- a/src/LibusbTypes.hs
+++ /dev/null
@@ -1,651 +0,0 @@
-module LibusbTypes where
-import Bindings.Utilities
-import Foreign
-import Foreign.C
-
-data Libusb_context
-
-data Libusb_device
-
-data Libusb_device_handle
-
-type Libusb_standard_request = Word8
-
-type Libusb_request_type = Word8
-
-type Libusb_request_recipient = Word8
-
-type Libusb_error = CInt
-
-type Libusb_descriptor_type = Word8
-
-data Libusb_device_descriptor = Libusb_device_descriptor {
-    libusb_device_descriptor'bLength,
-    libusb_device_descriptor'bDescriptorType :: Word8,
-    libusb_device_descriptor'bcdUSB :: Word16,
-    libusb_device_descriptor'bDeviceClass,
-    libusb_device_descriptor'bDeviceSubClass,
-    libusb_device_descriptor'bDeviceProtocol,
-    libusb_device_descriptor'bMaxPacketSize0 :: Word8,
-    libusb_device_descriptor'idVendor,
-    libusb_device_descriptor'idProduct,
-    libusb_device_descriptor'bcdDevice :: Word16,
-    libusb_device_descriptor'iManufacturer,
-    libusb_device_descriptor'iProduct,
-    libusb_device_descriptor'iSerialNumber,
-    libusb_device_descriptor'bNumConfigurations :: Word8 }
-
-instance Storable Libusb_device_descriptor where
-    sizeOf _ = fromIntegral size_of_libusb_device_descriptor
-
-    alignment = sizeOf
-
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-        with 0 $ \p6 ->
-        with 0 $ \p7 ->
-        with 0 $ \p8 ->
-        with 0 $ \p9 ->
-        with 0 $ \p10 ->
-        with 0 $ \p11 ->
-        with 0 $ \p12 ->
-        with 0 $ \p13 ->
-        with 0 $ \p14 ->
-
-        c2hs_libusb_device_descriptor p p1 p2 p3 p4 p5 p6 p7 p8
-            p9 p10 p11 p12 p13 p14 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-        peek p6 >>= \v6 ->
-        peek p7 >>= \v7 ->
-        peek p8 >>= \v8 ->
-        peek p9 >>= \v9 ->
-        peek p10 >>= \v10 ->
-        peek p11 >>= \v11 ->
-        peek p12 >>= \v12 ->
-        peek p13 >>= \v13 ->
-        peek p14 >>= \v14 ->
-
-        return $ Libusb_device_descriptor v1 v2 v3 v4 v5 v6 v7 v8
-               v9 v10 v11 v12 v13 v14
-
-    poke p v = hs2c_libusb_device_descriptor p
-        (libusb_device_descriptor'bLength v)
-        (libusb_device_descriptor'bDescriptorType v)
-        (libusb_device_descriptor'bcdUSB v)
-        (libusb_device_descriptor'bDeviceClass v)
-        (libusb_device_descriptor'bDeviceSubClass v)
-        (libusb_device_descriptor'bDeviceProtocol v)
-        (libusb_device_descriptor'bMaxPacketSize0 v)
-        (libusb_device_descriptor'idVendor v)
-        (libusb_device_descriptor'idProduct v)
-        (libusb_device_descriptor'bcdDevice v)
-        (libusb_device_descriptor'iManufacturer v)
-        (libusb_device_descriptor'iProduct v)
-        (libusb_device_descriptor'iSerialNumber v)
-        (libusb_device_descriptor'bNumConfigurations v)
-
-data Libusb_endpoint_descriptor = Libusb_endpoint_descriptor {
-    libusb_endpoint_descriptor'bLength  ,
-    libusb_endpoint_descriptor'bDescriptorType  ,
-    libusb_endpoint_descriptor'bEndpointAddress  ,
-    libusb_endpoint_descriptor'bmAttributes :: Word8 ,
-    libusb_endpoint_descriptor'wMaxPacketSize :: Word16 ,
-    libusb_endpoint_descriptor'bInterval  ,
-    libusb_endpoint_descriptor'bRefresh  ,
-    libusb_endpoint_descriptor'bSynchAddress :: Word8 ,
-    libusb_endpoint_descriptor'extra :: Ptr CUChar ,
-    libusb_endpoint_descriptor'extra_length :: CInt }
-
-instance Storable Libusb_endpoint_descriptor where
-    sizeOf _ = fromIntegral size_of_libusb_endpoint_descriptor
-
-    alignment = sizeOf
-
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-        with 0 $ \p6 ->
-        with 0 $ \p7 ->
-        with 0 $ \p8 ->
-        with nullPtr $ \p9 ->
-        with 0 $ \p10 ->
-
-        c2hs_libusb_endpoint_descriptor p p1 p2 p3 p4 p5 p6
-            p7 p8 p9 p10 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-        peek p6 >>= \v6 ->
-        peek p7 >>= \v7 ->
-        peek p8 >>= \v8 ->
-        peek p9 >>= \v9 ->
-        peek p10 >>= \v10 ->
-
-        return $ Libusb_endpoint_descriptor
-            v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
-
-    poke p v = hs2c_libusb_endpoint_descriptor p
-        (libusb_endpoint_descriptor'bLength v)
-        (libusb_endpoint_descriptor'bDescriptorType v)
-        (libusb_endpoint_descriptor'bEndpointAddress v)
-        (libusb_endpoint_descriptor'bmAttributes v)
-        (libusb_endpoint_descriptor'wMaxPacketSize v)
-        (libusb_endpoint_descriptor'bInterval v)
-        (libusb_endpoint_descriptor'bRefresh v)
-        (libusb_endpoint_descriptor'bSynchAddress v)
-        (libusb_endpoint_descriptor'extra v)
-        (libusb_endpoint_descriptor'extra_length v)
-
-data Libusb_interface_descriptor = Libusb_interface_descriptor {
-    libusb_interface_descriptor'bLength,
-    libusb_interface_descriptor'bDescriptorType,
-    libusb_interface_descriptor'bInterfaceNumber,
-    libusb_interface_descriptor'bAlternateSetting,
-    libusb_interface_descriptor'bNumEndpoints,
-    libusb_interface_descriptor'bInterfaceClass,
-    libusb_interface_descriptor'bInterfaceSubClass,
-    libusb_interface_descriptor'bInterfaceProtocol,
-    libusb_interface_descriptor'iInterface
-        :: Word8,
-    libusb_interface_descriptor'endpoint
-        :: Ptr Libusb_endpoint_descriptor,
-    libusb_interface_descriptor'extra
-        :: Ptr CUChar,
-    libusb_interface_descriptor'extra_length
-        :: CInt }
-
-instance Storable Libusb_interface_descriptor where
-    sizeOf _ = fromIntegral size_of_libusb_interface_descriptor
-
-    alignment = sizeOf
-
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-        with 0 $ \p6 ->
-        with 0 $ \p7 ->
-        with 0 $ \p8 ->
-        with 0 $ \p9 ->
-        with nullPtr $ \p10 ->
-        with nullPtr $ \p11 ->
-        with 0 $ \p12 ->
-
-        c2hs_libusb_interface_descriptor p p1 p2 p3 p4 p5
-            p6 p7 p8 p9 p10 p11 p12 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-        peek p6 >>= \v6 ->
-        peek p7 >>= \v7 ->
-        peek p8 >>= \v8 ->
-        peek p9 >>= \v9 ->
-        peek p10 >>= \v10 ->
-        peek p11 >>= \v11 ->
-        peek p12 >>= \v12 ->
-
-        return $ Libusb_interface_descriptor
-            v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12
-
-    poke p v = hs2c_libusb_interface_descriptor p 
-        (libusb_interface_descriptor'bLength v)
-        (libusb_interface_descriptor'bDescriptorType v)
-        (libusb_interface_descriptor'bInterfaceNumber v)
-        (libusb_interface_descriptor'bAlternateSetting v)
-        (libusb_interface_descriptor'bNumEndpoints v)
-        (libusb_interface_descriptor'bInterfaceClass v)
-        (libusb_interface_descriptor'bInterfaceSubClass v)
-        (libusb_interface_descriptor'bInterfaceProtocol v)
-        (libusb_interface_descriptor'iInterface v)
-        (libusb_interface_descriptor'endpoint v)
-        (libusb_interface_descriptor'extra v)
-        (libusb_interface_descriptor'extra_length v)
-    
-data Libusb_interface = Libusb_interface {
-    libusb_interface'altsetting :: Ptr Libusb_interface_descriptor,
-    libusb_interface'num_altsetting :: CInt }
-
-instance Storable Libusb_interface where
-    sizeOf _ = fromIntegral size_of_libusb_interface
-
-    alignment = sizeOf
-
-    peek p =
-        with nullPtr $ \p1 -> 
-        with 0 $ \p2 ->
-
-        c2hs_libusb_interface p p1 p2 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-
-        return $ Libusb_interface v1 v2
-
-    poke p v = hs2c_libusb_interface p
-        (libusb_interface'altsetting v)
-        (libusb_interface'num_altsetting v)
-
-data Libusb_config_descriptor = Libusb_config_descriptor {
-    libusb_config_descriptor'bLength  ,
-    libusb_config_descriptor'bDescriptorType :: Word8 ,
-    libusb_config_descriptor'wTotalLength :: Word16 ,
-    libusb_config_descriptor'bNumInterfaces  ,
-    libusb_config_descriptor'bConfigurationValue  ,
-    libusb_config_descriptor'iConfiguration  ,
-    libusb_config_descriptor'bmAttributes  ,
-    libusb_config_descriptor'maxPower :: Word8 ,
-    libusb_config_descriptor'interface :: Ptr Libusb_interface ,
-    libusb_config_descriptor'extra :: Ptr CUChar ,
-    libusb_config_descriptor'extra_length :: CInt }
-
-instance Storable Libusb_config_descriptor where
-    sizeOf _ = fromIntegral size_of_libusb_config_descriptor
-
-    alignment = sizeOf
-
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-        with 0 $ \p6 ->
-        with 0 $ \p7 ->
-        with 0 $ \p8 ->
-        with nullPtr $ \p9 ->
-        with nullPtr $ \p10 ->
-        with 0 $ \p11 ->
-
-        c2hs_libusb_config_descriptor p p1 p2 p3 p4 p5 p6 p7
-            p8 p9 p10 p11 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-        peek p6 >>= \v6 ->
-        peek p7 >>= \v7 ->
-        peek p8 >>= \v8 ->
-        peek p9 >>= \v9 ->
-        peek p10 >>= \v10 ->
-        peek p11 >>= \v11 ->
-
-        return $ Libusb_config_descriptor
-            v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11
-
-    poke p v = hs2c_libusb_config_descriptor p
-        (libusb_config_descriptor'bLength v)
-        (libusb_config_descriptor'bDescriptorType v)
-        (libusb_config_descriptor'wTotalLength v)
-        (libusb_config_descriptor'bNumInterfaces v)
-        (libusb_config_descriptor'bConfigurationValue v)
-        (libusb_config_descriptor'iConfiguration v)
-        (libusb_config_descriptor'bmAttributes v)
-        (libusb_config_descriptor'maxPower v)
-        (libusb_config_descriptor'interface v)
-        (libusb_config_descriptor'extra v)
-        (libusb_config_descriptor'extra_length v)
-
-type Libusb_class_code = Word8
-
-type Libusb_endpoint_direction = Word8
-
-type Libusb_transfer_type = Word8
-
-type Libusb_iso_sync_type = Word8
-
-type Libusb_iso_usage_type = Word8
-
-data Libusb_control_setup = Libusb_control_setup {
-    libusb_control_setup'bmRequestType  ,
-    libusb_control_setup'bRequest :: Word8 ,
-    libusb_control_setup'wValue  ,
-    libusb_control_setup'wIndex  ,
-    libusb_control_setup'wLength :: Word16 }
-
-instance Storable Libusb_control_setup where
-    sizeOf _ = fromIntegral size_of_libusb_control_setup
-
-    alignment = sizeOf
-
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-
-        c2hs_libusb_control_setup p p1 p2 p3 p4 p5 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-
-        return $ Libusb_control_setup v1 v2 v3 v4 v5
-
-    poke p v = hs2c_libusb_control_setup p
-        (libusb_control_setup'bmRequestType v)
-        (libusb_control_setup'bRequest v)
-        (libusb_control_setup'wValue v)
-        (libusb_control_setup'wIndex v)
-        (libusb_control_setup'wLength v)
-
-data Libusb_iso_packet_descriptor = Libusb_iso_packet_descriptor {
-    libusb_iso_packet_descriptor'length  ,
-    libusb_iso_packet_descriptor'actual_length :: CUInt ,
-    libusb_iso_packet_descriptor'status :: Libusb_transfer_status }
-
-instance Storable Libusb_iso_packet_descriptor where
-    sizeOf _ = fromIntegral size_of_libusb_iso_packet_descriptor
-    alignment = sizeOf
-    peek p =
-        with 0 $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-
-        c2hs_libusb_iso_packet_descriptor p p1 p2 p3 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-
-        return $ Libusb_iso_packet_descriptor v1 v2 v3
-
-    poke p v = hs2c_libusb_iso_packet_descriptor p
-        (libusb_iso_packet_descriptor'length v)
-        (libusb_iso_packet_descriptor'actual_length v)
-        (libusb_iso_packet_descriptor'status v)
-
-data Libusb_transfer a = Libusb_transfer {
-        libusb_transfer'dev_handle :: Ptr Libusb_device_handle ,
-        libusb_transfer'flags :: Word8 ,
-        libusb_transfer'endpoint  ,
-        libusb_transfer'type :: CUChar ,
-        libusb_transfer'timeout :: CUInt ,
-        libusb_transfer'status :: Libusb_transfer_status ,
-        libusb_transfer'length  ,
-        libusb_transfer'actual_length :: CInt ,
-        libusb_transfer'callback :: Libusb_transfer_cb_fn a,
-        libusb_transfer'user_data :: Ptr a ,
-        libusb_transfer'buffer :: Ptr CUChar ,
-        libusb_transfer'num_iso_packets :: CInt ,
-        libusb_transfer'iso_packet_desc :: () }
-
-instance Storable (Libusb_transfer a) where
-    sizeOf _ = fromIntegral size_of_libusb_transfer
-
-    alignment = sizeOf
-
-    peek p =
-        with nullPtr $ \p1 ->
-        with 0 $ \p2 ->
-        with 0 $ \p3 ->
-        with 0 $ \p4 ->
-        with 0 $ \p5 ->
-        with 0 $ \p6 ->
-        with 0 $ \p7 ->
-        with 0 $ \p8 ->
-        with nullCallback $ \p9 ->
-        with nullPtr $ \p10 ->
-        with nullPtr $ \p11 ->
-        with 0 $ \p12 ->
-
-        c2hs_libusb_transfer p p1 p2 p3 p4 p5 p6 p7 p8 p9
-            p10 p11 p12 >>
-
-        peek p1 >>= \v1 ->
-        peek p2 >>= \v2 ->
-        peek p3 >>= \v3 ->
-        peek p4 >>= \v4 ->
-        peek p5 >>= \v5 ->
-        peek p6 >>= \v6 ->
-        peek p7 >>= \v7 ->
-        peek p8 >>= \v8 ->
-        peek p9 >>= \v9 ->
-        peek p10 >>= \v10 ->
-        peek p11 >>= \v11 ->
-        peek p12 >>= \v12 ->
-
-        return $ Libusb_transfer
-            v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 ()
-
-    poke p v = hs2c_libusb_transfer p
-        (libusb_transfer'dev_handle v)
-        (libusb_transfer'flags v)
-        (libusb_transfer'endpoint v)
-        (libusb_transfer'type v)
-        (libusb_transfer'timeout v)
-        (libusb_transfer'status v)
-        (libusb_transfer'length v)
-        (libusb_transfer'actual_length v)
-        (libusb_transfer'callback v)
-        (libusb_transfer'user_data v)
-        (libusb_transfer'buffer v)
-        (libusb_transfer'num_iso_packets v)
-
-newtype Libusb_transfer_cb_fn a = Libusb_transfer_cb_fn
-    (FunPtr ((Ptr (Libusb_transfer a)) -> IO ()))
-
-instance Storable (Libusb_transfer_cb_fn a) where
-    sizeOf _ = sizeOf (undefined :: FunPtr ())
-    alignment = sizeOf
-    peek p = (peek $ castPtr p) >>= (return . Libusb_transfer_cb_fn)
-    poke p (Libusb_transfer_cb_fn v) = poke (castPtr p) v
-
-instance Callback (Libusb_transfer_cb_fn a) where
-    type F (Libusb_transfer_cb_fn a) = Ptr (Libusb_transfer a) -> IO ()
-    nullCallback = Libusb_transfer_cb_fn nullFunPtr
-    makeCallback f = mkCbTransfer f >>= (return . Libusb_transfer_cb_fn)
-    freeCallback (Libusb_transfer_cb_fn f) = freeHaskellFunPtr f
-
-type Libusb_transfer_status = CInt
-
-type Libusb_transfer_flags = Word8
-
-data Libusb_pollfd = Libusb_pollfd {
-        pollfd'fd :: CInt ,
-        pollfd'events :: CShort }
-
-instance Storable Libusb_pollfd where
-    sizeOf _ = fromIntegral size_of_libusb_pollfd
-    alignment = sizeOf
-
-    peek p = with 0 $ \p1 -> with 0 $ \p2 ->
-        c2hs_libusb_pollfd p p1 p2 >>
-        peek p1 >>= \v1 -> peek p2 >>= \v2 ->
-        return Libusb_pollfd {pollfd'fd = v1, pollfd'events = v2}
-
-    poke p v = hs2c_libusb_pollfd p
-        (pollfd'fd v)
-        (pollfd'events v)
-
-newtype Libusb_pollfd_added_cb a = Libusb_pollfd_added_cb (FunPtr (CInt ->
-    CShort -> Ptr a -> IO ()))
-
-instance Storable (Libusb_pollfd_added_cb a) where
-    sizeOf _ = sizeOf (undefined :: FunPtr ())
-    alignment = sizeOf
-    peek p = (peek $ castPtr p) >>= (return . Libusb_pollfd_added_cb)
-    poke p (Libusb_pollfd_added_cb v) = poke (castPtr p) v
-
-instance Callback (Libusb_pollfd_added_cb a) where
-    type F (Libusb_pollfd_added_cb a) = CInt -> CShort -> Ptr a -> IO ()
-    nullCallback = Libusb_pollfd_added_cb nullFunPtr
-    makeCallback f = mkCbAdded f >>= (return . Libusb_pollfd_added_cb)
-    freeCallback (Libusb_pollfd_added_cb f) = freeHaskellFunPtr f
-
-newtype Libusb_pollfd_removed_cb a = Libusb_pollfd_removed_cb (FunPtr
-    (CInt -> Ptr a -> IO ()))
-
-instance Storable (Libusb_pollfd_removed_cb a) where
-    sizeOf _ = sizeOf (undefined :: FunPtr ())
-    alignment = sizeOf
-    peek p = (peek $ castPtr p) >>= (return . Libusb_pollfd_removed_cb)
-    poke p (Libusb_pollfd_removed_cb v) = poke (castPtr p) v
-
-instance Callback (Libusb_pollfd_removed_cb a) where
-    type F (Libusb_pollfd_removed_cb a) = CInt -> Ptr a -> IO ()
-    nullCallback = Libusb_pollfd_removed_cb nullFunPtr
-    makeCallback f = mkCbRemoved f >>= (return . Libusb_pollfd_removed_cb)
-    freeCallback (Libusb_pollfd_removed_cb f) = freeHaskellFunPtr f
-
-type Cb1 a = Ptr a -> IO ()
-type Cb2 a = CInt -> CShort -> Ptr a -> IO ()
-type Cb3 a = CInt -> Ptr a -> IO ()
-
-foreign import ccall "wrapper" mkCbTransfer
-    :: Cb1 a -> IO (FunPtr (Cb1 a))
-
-foreign import ccall "wrapper" mkCbAdded
-    :: Cb2 a -> IO (FunPtr (Cb2 a))
-
-foreign import ccall "wrapper" mkCbRemoved
-    :: Cb3 a -> IO (FunPtr (Cb3 a))
-
-foreign import ccall "size_of_libusb_device_descriptor"
- size_of_libusb_device_descriptor
-    :: CInt
-
-foreign import ccall "size_of_libusb_endpoint_descriptor"
- size_of_libusb_endpoint_descriptor
-    :: CInt
-
-foreign import ccall "size_of_libusb_interface_descriptor"
- size_of_libusb_interface_descriptor
-    :: CInt
-
-foreign import ccall "size_of_libusb_interface"
- size_of_libusb_interface
-    :: CInt
-
-foreign import ccall "size_of_libusb_config_descriptor"
- size_of_libusb_config_descriptor
-    :: CInt
-
-foreign import ccall "size_of_libusb_control_setup"
- size_of_libusb_control_setup
-    :: CInt
-
-foreign import ccall "size_of_libusb_iso_packet_descriptor"
- size_of_libusb_iso_packet_descriptor
-    :: CInt
-
-foreign import ccall "size_of_libusb_transfer"
- size_of_libusb_transfer
-    :: CInt
-
-foreign import ccall "size_of_libusb_pollfd"
- size_of_libusb_pollfd
-    :: CInt
-
-foreign import ccall "hs2c_libusb_device_descriptor"
- hs2c_libusb_device_descriptor
-    :: Ptr a -> Word8 -> Word8 -> Word16 -> Word8 -> Word8 ->
-       Word8 -> Word8 -> Word16 -> Word16 -> Word16 -> Word8 ->
-       Word8 -> Word8 -> Word8 -> IO ()
-
-foreign import ccall "hs2c_libusb_endpoint_descriptor"
- hs2c_libusb_endpoint_descriptor
-  :: Ptr a -> Word8 -> Word8 -> Word8 -> Word8 -> Word16 -> Word8 ->
-     Word8 -> Word8 -> Ptr CUChar -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_interface_descriptor"
- hs2c_libusb_interface_descriptor
-    :: Ptr a -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 ->
-       Word8 -> Word8 -> Word8 -> Word8 -> Ptr b ->
-       Ptr CUChar -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_interface" hs2c_libusb_interface
-    :: Ptr a -> Ptr b -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_config_descriptor"
- hs2c_libusb_config_descriptor
-    :: Ptr a -> Word8 -> Word8 -> Word16 -> Word8 -> Word8 -> Word8 ->
-       Word8 -> Word8 -> Ptr b -> Ptr CUChar -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_control_setup"
- hs2c_libusb_control_setup
-    :: Ptr a -> Word8 -> Word8 -> Word16 -> Word16 -> Word16 -> IO ()
-
-foreign import ccall "hs2c_libusb_iso_packet_descriptor"
- hs2c_libusb_iso_packet_descriptor
-    :: Ptr a -> CUInt -> CUInt -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_transfer" hs2c_libusb_transfer
-    :: Ptr a -> Ptr b -> Word8 -> CUChar -> CUChar -> CUInt ->
-       CInt -> CInt -> CInt -> Libusb_transfer_cb_fn c ->
-       Ptr d -> Ptr CUChar -> CInt -> IO ()
-
-foreign import ccall "hs2c_libusb_pollfd" hs2c_libusb_pollfd
-    :: Ptr a -> CInt -> CShort -> IO ()
-
-foreign import ccall "c2hs_libusb_device_descriptor"
- c2hs_libusb_device_descriptor
-    :: Ptr a -> Ptr Word8 -> Ptr Word8 -> Ptr Word16 -> Ptr Word8 ->
-       Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word16 ->
-       Ptr Word16 -> Ptr Word16 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr Word8 -> Ptr Word8 -> IO ()
-
-foreign import ccall "c2hs_libusb_endpoint_descriptor"
- c2hs_libusb_endpoint_descriptor
-    :: Ptr a -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr Word16 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr (Ptr CUChar) -> Ptr CInt -> IO ()
-
-foreign import ccall "c2hs_libusb_interface_descriptor"
- c2hs_libusb_interface_descriptor
-    :: Ptr a -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr (Ptr b) -> Ptr (Ptr CUChar) -> Ptr CInt -> IO ()
-
-foreign import ccall "c2hs_libusb_interface" c2hs_libusb_interface
-    ::
- Ptr a -> Ptr (Ptr b) -> Ptr CInt -> IO ()
-
-foreign import ccall "c2hs_libusb_config_descriptor"
- c2hs_libusb_config_descriptor
-    :: Ptr a -> Ptr Word8 -> Ptr Word8 -> Ptr Word16 ->
-       Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 ->
-       Ptr Word8 -> Ptr (Ptr b) -> Ptr (Ptr CUChar) ->
-       Ptr CInt -> IO ()
-
-foreign import ccall "c2hs_libusb_control_setup"
- c2hs_libusb_control_setup
-    :: Ptr a -> Ptr Word8 -> Ptr Word8 -> Ptr Word16 ->
-       Ptr Word16 -> Ptr Word16 -> IO ()
-
-foreign import ccall "c2hs_libusb_iso_packet_descriptor"
- c2hs_libusb_iso_packet_descriptor
-    :: Ptr a -> Ptr CUInt -> Ptr CUInt -> Ptr CInt -> IO ()
-
-foreign import ccall "c2hs_libusb_transfer" c2hs_libusb_transfer
-    :: Ptr a -> Ptr (Ptr b) -> Ptr Word8 -> Ptr CUChar ->
-       Ptr CUChar -> Ptr CUInt -> Ptr CInt -> Ptr CInt -> Ptr CInt ->
-       Ptr (Libusb_transfer_cb_fn c) -> Ptr (Ptr d) ->
-       Ptr (Ptr CUChar) -> Ptr CInt ->   IO ()
-
-foreign import ccall "c2hs_libusb_pollfd" c2hs_libusb_pollfd
-    :: Ptr a -> Ptr CInt -> Ptr CShort -> IO ()
diff --git a/src/constants.c b/src/constants.c
deleted file mode 100644
--- a/src/constants.c
+++ /dev/null
@@ -1,377 +0,0 @@
-#include <libusb.h>
-
-uint8_t _LIBUSB_REQUEST_GET_STATUS (void)
-{
-    return LIBUSB_REQUEST_GET_STATUS;
-}
-
-uint8_t _LIBUSB_REQUEST_CLEAR_FEATURE (void)
-{
-    return LIBUSB_REQUEST_CLEAR_FEATURE;
-}
-
-uint8_t _LIBUSB_REQUEST_SET_FEATURE (void)
-{
-    return LIBUSB_REQUEST_SET_FEATURE;
-}
-
-uint8_t _LIBUSB_REQUEST_SET_ADDRESS (void)
-{
-    return LIBUSB_REQUEST_SET_ADDRESS;
-}
-
-uint8_t _LIBUSB_REQUEST_GET_DESCRIPTOR (void)
-{
-    return LIBUSB_REQUEST_GET_DESCRIPTOR;
-}
-
-uint8_t _LIBUSB_REQUEST_SET_DESCRIPTOR (void)
-{
-    return LIBUSB_REQUEST_SET_DESCRIPTOR;
-}
-
-uint8_t _LIBUSB_REQUEST_GET_CONFIGURATION (void)
-{
-    return LIBUSB_REQUEST_GET_CONFIGURATION;
-}
-
-uint8_t _LIBUSB_REQUEST_SET_CONFIGURATION (void)
-{
-    return LIBUSB_REQUEST_SET_CONFIGURATION;
-}
-
-uint8_t _LIBUSB_REQUEST_GET_INTERFACE (void)
-{
-    return LIBUSB_REQUEST_GET_INTERFACE;
-}
-
-uint8_t _LIBUSB_REQUEST_SET_INTERFACE (void)
-{
-    return LIBUSB_REQUEST_SET_INTERFACE;
-}
-
-uint8_t _LIBUSB_REQUEST_SYNCH_FRAME (void)
-{
-    return LIBUSB_REQUEST_SYNCH_FRAME;
-}
-
-uint8_t _LIBUSB_REQUEST_TYPE_STANDARD (void)
-{
-    return LIBUSB_REQUEST_TYPE_STANDARD;
-}
-
-uint8_t _LIBUSB_REQUEST_TYPE_CLASS (void)
-{
-    return LIBUSB_REQUEST_TYPE_CLASS;
-}
-
-uint8_t _LIBUSB_REQUEST_TYPE_VENDOR (void)
-{
-    return LIBUSB_REQUEST_TYPE_VENDOR;
-}
-
-uint8_t _LIBUSB_REQUEST_TYPE_RESERVED (void)
-{
-    return LIBUSB_REQUEST_TYPE_RESERVED;
-}
-
-uint8_t _LIBUSB_RECIPIENT_DEVICE (void)
-{
-    return LIBUSB_RECIPIENT_DEVICE;
-}
-
-uint8_t _LIBUSB_RECIPIENT_INTERFACE (void)
-{
-    return LIBUSB_RECIPIENT_INTERFACE;
-}
-
-uint8_t _LIBUSB_RECIPIENT_ENDPOINT (void)
-{
-    return LIBUSB_RECIPIENT_ENDPOINT;
-}
-
-uint8_t _LIBUSB_RECIPIENT_OTHER (void)
-{
-    return LIBUSB_RECIPIENT_OTHER;
-}
-
-int _LIBUSB_SUCCESS (void)
-{
-    return LIBUSB_SUCCESS;
-}
-
-int _LIBUSB_ERROR_IO (void)
-{
-    return LIBUSB_ERROR_IO;
-}
-
-int _LIBUSB_ERROR_INVALID_PARAM (void)
-{
-    return LIBUSB_ERROR_INVALID_PARAM;
-}
-
-int _LIBUSB_ERROR_ACCESS (void)
-{
-    return LIBUSB_ERROR_ACCESS;
-}
-
-int _LIBUSB_ERROR_NO_DEVICE (void)
-{
-    return LIBUSB_ERROR_NO_DEVICE;
-}
-
-int _LIBUSB_ERROR_NOT_FOUND (void)
-{
-    return LIBUSB_ERROR_NOT_FOUND;
-}
-
-int _LIBUSB_ERROR_BUSY (void)
-{
-    return LIBUSB_ERROR_BUSY;
-}
-
-int _LIBUSB_ERROR_TIMEOUT (void)
-{
-    return LIBUSB_ERROR_TIMEOUT;
-}
-
-int _LIBUSB_ERROR_OVERFLOW (void)
-{
-    return LIBUSB_ERROR_OVERFLOW;
-}
-
-int _LIBUSB_ERROR_PIPE (void)
-{
-    return LIBUSB_ERROR_PIPE;
-}
-
-int _LIBUSB_ERROR_INTERRUPTED (void)
-{
-    return LIBUSB_ERROR_INTERRUPTED;
-}
-
-int _LIBUSB_ERROR_NO_MEM (void)
-{
-    return LIBUSB_ERROR_NO_MEM;
-}
-
-int _LIBUSB_ERROR_NOT_SUPPORTED (void)
-{
-    return LIBUSB_ERROR_NOT_SUPPORTED;
-}
-
-int _LIBUSB_ERROR_OTHER (void)
-{
-    return LIBUSB_ERROR_OTHER;
-}
-
-uint8_t _LIBUSB_CLASS_PER_INTERFACE (void)
-{
-    return LIBUSB_CLASS_PER_INTERFACE;
-}
-
-uint8_t _LIBUSB_CLASS_AUDIO (void)
-{
-    return LIBUSB_CLASS_AUDIO;
-}
-
-uint8_t _LIBUSB_CLASS_COMM (void)
-{
-    return LIBUSB_CLASS_COMM;
-}
-
-uint8_t _LIBUSB_CLASS_HID (void)
-{
-    return LIBUSB_CLASS_HID;
-}
-
-uint8_t _LIBUSB_CLASS_PRINTER (void)
-{
-    return LIBUSB_CLASS_PRINTER;
-}
-
-uint8_t _LIBUSB_CLASS_PTP (void)
-{
-    return LIBUSB_CLASS_PTP;
-}
-
-uint8_t _LIBUSB_CLASS_MASS_STORAGE (void)
-{
-    return LIBUSB_CLASS_MASS_STORAGE;
-}
-
-uint8_t _LIBUSB_CLASS_HUB (void)
-{
-    return LIBUSB_CLASS_HUB;
-}
-
-uint8_t _LIBUSB_CLASS_DATA (void)
-{
-    return LIBUSB_CLASS_DATA;
-}
-
-uint8_t _LIBUSB_CLASS_VENDOR_SPEC (void)
-{
-    return LIBUSB_CLASS_VENDOR_SPEC;
-}
-
-uint8_t _LIBUSB_DT_DEVICE (void)
-{
-    return LIBUSB_DT_DEVICE;
-}
-
-uint8_t _LIBUSB_DT_CONFIG (void)
-{
-    return LIBUSB_DT_CONFIG;
-}
-
-uint8_t _LIBUSB_DT_STRING (void)
-{
-    return LIBUSB_DT_STRING;
-}
-
-uint8_t _LIBUSB_DT_INTERFACE (void)
-{
-    return LIBUSB_DT_INTERFACE;
-}
-
-uint8_t _LIBUSB_DT_ENDPOINT (void)
-{
-    return LIBUSB_DT_ENDPOINT;
-}
-
-uint8_t _LIBUSB_DT_HID (void)
-{
-    return LIBUSB_DT_HID;
-}
-
-uint8_t _LIBUSB_DT_REPORT (void)
-{
-    return LIBUSB_DT_REPORT;
-}
-
-uint8_t _LIBUSB_DT_PHYSICAL (void)
-{
-    return LIBUSB_DT_PHYSICAL;
-}
-
-uint8_t _LIBUSB_DT_HUB (void)
-{
-    return LIBUSB_DT_HUB;
-}
-
-uint8_t _LIBUSB_ENDPOINT_IN (void)
-{
-    return LIBUSB_ENDPOINT_IN;
-}
-
-uint8_t _LIBUSB_ENDPOINT_OUT (void)
-{
-    return LIBUSB_ENDPOINT_OUT;
-}
-
-uint8_t _LIBUSB_TRANSFER_TYPE_CONTROL (void)
-{
-    return LIBUSB_TRANSFER_TYPE_CONTROL;
-}
-
-uint8_t _LIBUSB_TRANSFER_TYPE_ISOCHRONOUS (void)
-{
-    return LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
-}
-
-uint8_t _LIBUSB_TRANSFER_TYPE_BULK (void)
-{
-    return LIBUSB_TRANSFER_TYPE_BULK;
-}
-
-uint8_t _LIBUSB_TRANSFER_TYPE_INTERRUPT (void)
-{
-    return LIBUSB_TRANSFER_TYPE_INTERRUPT;
-}
-
-uint8_t _LIBUSB_ISO_SYNC_TYPE_NONE (void)
-{
-    return LIBUSB_ISO_SYNC_TYPE_NONE;
-}
-
-uint8_t _LIBUSB_ISO_SYNC_TYPE_ASYNC (void)
-{
-    return LIBUSB_ISO_SYNC_TYPE_ASYNC;
-}
-
-uint8_t _LIBUSB_ISO_SYNC_TYPE_ADAPTIVE (void)
-{
-    return LIBUSB_ISO_SYNC_TYPE_ADAPTIVE;
-}
-
-uint8_t _LIBUSB_ISO_SYNC_TYPE_SYNC (void)
-{
-    return LIBUSB_ISO_SYNC_TYPE_SYNC;
-}
-
-uint8_t _LIBUSB_ISO_USAGE_TYPE_DATA (void)
-{
-    return LIBUSB_ISO_USAGE_TYPE_DATA;
-}
-
-uint8_t _LIBUSB_ISO_USAGE_TYPE_FEEDBACK (void)
-{
-    return LIBUSB_ISO_USAGE_TYPE_FEEDBACK;
-}
-
-uint8_t _LIBUSB_ISO_USAGE_TYPE_IMPLICIT (void)
-{
-    return LIBUSB_ISO_USAGE_TYPE_IMPLICIT;
-}
-
-int _LIBUSB_TRANSFER_COMPLETED (void)
-{
-    return LIBUSB_TRANSFER_COMPLETED;
-}
-
-int _LIBUSB_TRANSFER_ERROR (void)
-{
-    return LIBUSB_TRANSFER_ERROR;
-}
-
-int _LIBUSB_TRANSFER_TIMED_OUT (void)
-{
-    return LIBUSB_TRANSFER_TIMED_OUT;
-}
-
-int _LIBUSB_TRANSFER_CANCELLED (void)
-{
-    return LIBUSB_TRANSFER_CANCELLED;
-}
-
-int _LIBUSB_TRANSFER_STALL (void)
-{
-    return LIBUSB_TRANSFER_STALL;
-}
-
-int _LIBUSB_TRANSFER_NO_DEVICE (void)
-{
-    return LIBUSB_TRANSFER_NO_DEVICE;
-}
-
-int _LIBUSB_TRANSFER_OVERFLOW (void)
-{
-    return LIBUSB_TRANSFER_OVERFLOW;
-}
-
-uint8_t _LIBUSB_TRANSFER_SHORT_NOT_OK (void)
-{
-    return LIBUSB_TRANSFER_SHORT_NOT_OK;
-}
-
-uint8_t _LIBUSB_TRANSFER_FREE_BUFFER (void)
-{
-    return LIBUSB_TRANSFER_FREE_BUFFER;
-}
-
-uint8_t _LIBUSB_TRANSFER_FREE_TRANSFER (void)
-{
-    return LIBUSB_TRANSFER_FREE_TRANSFER;
-}
-
diff --git a/src/functions.c b/src/functions.c
deleted file mode 100644
--- a/src/functions.c
+++ /dev/null
@@ -1,129 +0,0 @@
-#include <libusb.h>
-
-uint16_t _libusb_cpu_to_le16 (uint16_t x)
-{
-    return libusb_cpu_to_le16 (x);
-}
-
-uint16_t _libusb_le16_to_cpu (uint16_t x)
-{
-    return libusb_le16_to_cpu (x);
-}
-
-
-int libusb_get_descriptor2 ( libusb_device_handle * dev,
- uint8_t desc_type,
- uint8_t desc_index,
- unsigned char * data,
- int length 
- )
-{
- libusb_get_descriptor (dev,desc_type,desc_index,data,length);
-}
- 
-
-int libusb_get_string_descriptor2 ( libusb_device_handle * dev,
- uint8_t desc_index,
- uint16_t langid,
- unsigned char * data,
- int length 
- )
-{
- libusb_get_string_descriptor(dev,desc_index,langid,data,length);
-}
-
-unsigned char* libusb_control_transfer_get_data2 ( struct libusb_transfer * transfer )
-{
-  libusb_control_transfer_get_data(transfer);
-}
-
-struct libusb_control_setup* libusb_control_transfer_get_setup2 ( struct libusb_transfer * transfer )
-{
- libusb_control_transfer_get_setup (transfer);
-}
-
-void libusb_fill_control_setup2 ( unsigned char * buffer,
- uint8_t bmRequestType,
- uint8_t bRequest,
- uint16_t wValue,
- uint16_t wIndex,
- uint16_t wLength 
- )
-{
- libusb_fill_control_setup(buffer,bmRequestType,bRequest,wValue,wIndex,wLength);
-}
-
-void libusb_fill_control_transfer2 ( struct libusb_transfer * transfer,
- libusb_device_handle * dev_handle,
- unsigned char * buffer,
- libusb_transfer_cb_fn callback,
- void * user_data,
- unsigned int timeout 
- )
-{
-  libusb_fill_control_transfer(transfer,dev_handle,buffer,callback,user_data,timeout);
-}
-
-void libusb_fill_bulk_transfer2 ( struct libusb_transfer * transfer,
- libusb_device_handle * dev_handle,
- unsigned char endpoint,
- unsigned char * buffer,
- int length,
- libusb_transfer_cb_fn callback,
- void * user_data,
- unsigned int timeout 
- )
-{
- libusb_fill_bulk_transfer(transfer,dev_handle,endpoint,buffer,length,callback,user_data,timeout);
-}
- 
-void libusb_fill_interrupt_transfer2 ( struct libusb_transfer * transfer,
- libusb_device_handle * dev_handle,
- unsigned char endpoint,
- unsigned char * buffer,
- int length,
- libusb_transfer_cb_fn callback,
- void * user_data,
- unsigned int timeout 
- )
-{
-  libusb_fill_interrupt_transfer(transfer,dev_handle,endpoint,buffer,length,callback,user_data,timeout);
-}
- 
-void libusb_fill_iso_transfer2 ( struct libusb_transfer * transfer,
- libusb_device_handle * dev_handle,
- unsigned char endpoint,
- unsigned char * buffer,
- int length,
- int num_iso_packets,
- libusb_transfer_cb_fn callback,
- void * user_data,
- unsigned int timeout 
- )
-{
- libusb_fill_iso_transfer(transfer,dev_handle,endpoint,buffer,length,num_iso_packets,callback,user_data,timeout);
-}
- 
-void libusb_set_iso_packet_lengths2 ( struct libusb_transfer * transfer,
- unsigned int length 
- )
-{
- libusb_set_iso_packet_lengths(transfer,length);
-}
- 
-unsigned char* libusb_get_iso_packet_buffer2 ( struct libusb_transfer * transfer,
- unsigned int packet 
- ) 
-{
- libusb_get_iso_packet_buffer(transfer,packet);
-}
-
-unsigned char* libusb_get_iso_packet_buffer_simple2 ( struct libusb_transfer * transfer,
-
- unsigned int packet 
- )
-{
- libusb_get_iso_packet_buffer_simple(transfer,packet);
-}
-
-
diff --git a/src/include/libusb.h b/src/include/libusb.h
new file mode 100644
--- /dev/null
+++ b/src/include/libusb.h
@@ -0,0 +1,1201 @@
+/*
+ * Public libusb header file
+ * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
+ * Copyright (c) 2001 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
+ */
+
+#ifndef __LIBUSB_H__
+#define __LIBUSB_H__
+
+#include <endian.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+
+#define bswap16(x) (((x & 0xff) << 8) | (x >> 8))
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define libusb_cpu_to_le16(x) (x)
+#define libusb_le16_to_cpu(x) (x)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define libusb_le16_to_cpu(x) bswap16(x)
+#define libusb_cpu_to_le16(x) bswap16(x)
+#else
+#error "Unrecognized endianness"
+#endif
+
+/** \def libusb_cpu_to_le16
+ * \ingroup misc
+ * Convert a 16-bit value from host-endian to little-endian format. On
+ * little endian systems, this function does nothing. On big endian systems,
+ * the bytes are swapped.
+ * \param x the host-endian value to convert
+ * \returns the value in little-endian byte order
+ */
+
+/** \def libusb_le16_to_cpu
+ * \ingroup misc
+ * Convert a 16-bit value from little-endian to host-endian format. On
+ * little endian systems, this function does nothing. On big endian systems,
+ * the bytes are swapped.
+ * \param x the little-endian value to convert
+ * \returns the value in host-endian byte order
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* standard USB stuff */
+
+/** \ingroup desc
+ * Device and/or Interface Class codes */
+enum libusb_class_code {
+	/** In the context of a \ref libusb_device_descriptor "device descriptor",
+	 * this bDeviceClass value indicates that each interface specifies its
+	 * own class information and all interfaces operate independently.
+	 */
+	LIBUSB_CLASS_PER_INTERFACE = 0,
+
+	/** Audio class */
+	LIBUSB_CLASS_AUDIO = 1,
+
+	/** Communications class */
+	LIBUSB_CLASS_COMM = 2,
+
+	/** Human Interface Device class */
+	LIBUSB_CLASS_HID = 3,
+
+	/** Printer dclass */
+	LIBUSB_CLASS_PRINTER = 7,
+
+	/** Picture transfer protocol class */
+	LIBUSB_CLASS_PTP = 6,
+
+	/** Mass storage class */
+	LIBUSB_CLASS_MASS_STORAGE = 8,
+
+	/** Hub class */
+	LIBUSB_CLASS_HUB = 9,
+
+	/** Data class */
+	LIBUSB_CLASS_DATA = 10,
+
+	/** Class is vendor-specific */
+	LIBUSB_CLASS_VENDOR_SPEC = 0xff,
+};
+
+/** \ingroup desc
+ * Descriptor types as defined by the USB specification. */
+enum libusb_descriptor_type {
+	/** Device descriptor. See libusb_device_descriptor. */
+	LIBUSB_DT_DEVICE = 0x01,
+
+	/** Configuration descriptor. See libusb_config_descriptor. */
+	LIBUSB_DT_CONFIG = 0x02,
+
+	/** String descriptor */
+	LIBUSB_DT_STRING = 0x03,
+
+	/** Interface descriptor. See libusb_interface_descriptor. */
+	LIBUSB_DT_INTERFACE = 0x04,
+
+	/** Endpoint descriptor. See libusb_endpoint_descriptor. */
+	LIBUSB_DT_ENDPOINT = 0x05,
+
+	/** HID descriptor */
+	LIBUSB_DT_HID = 0x21,
+
+	/** HID report descriptor */
+	LIBUSB_DT_REPORT = 0x22,
+
+	/** Physical descriptor */
+	LIBUSB_DT_PHYSICAL = 0x23,
+
+	/** Hub descriptor */
+	LIBUSB_DT_HUB = 0x29,
+};
+
+/* Descriptor sizes per descriptor type */
+#define LIBUSB_DT_DEVICE_SIZE			18
+#define LIBUSB_DT_CONFIG_SIZE			9
+#define LIBUSB_DT_INTERFACE_SIZE		9
+#define LIBUSB_DT_ENDPOINT_SIZE		7
+#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE	9	/* Audio extension */
+#define LIBUSB_DT_HUB_NONVAR_SIZE		7
+
+#define LIBUSB_ENDPOINT_ADDRESS_MASK	0x0f    /* in bEndpointAddress */
+#define LIBUSB_ENDPOINT_DIR_MASK		0x80
+
+/** \ingroup desc
+ * Endpoint direction. Values for bit 7 of the
+ * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
+ */
+enum libusb_endpoint_direction {
+	/** In: device-to-host */
+	LIBUSB_ENDPOINT_IN = 0x80,
+
+	/** Out: host-to-device */
+	LIBUSB_ENDPOINT_OUT = 0x00,
+};
+
+#define LIBUSB_TRANSFER_TYPE_MASK			0x03    /* in bmAttributes */
+
+/** \ingroup desc
+ * Endpoint transfer type. Values for bits 0:1 of the
+ * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
+ */
+enum libusb_transfer_type {
+	/** Control endpoint */
+	LIBUSB_TRANSFER_TYPE_CONTROL = 0,
+
+	/** Isochronous endpoint */
+	LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
+
+	/** Bulk endpoint */
+	LIBUSB_TRANSFER_TYPE_BULK = 2,
+
+	/** Interrupt endpoint */
+	LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
+};
+
+/** \ingroup misc
+ * Standard requests, as defined in table 9-3 of the USB2 specifications */
+enum libusb_standard_request {
+	/** Request status of the specific recipient */
+	LIBUSB_REQUEST_GET_STATUS = 0x00,
+
+	/** Clear or disable a specific feature */
+	LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
+
+	/* 0x02 is reserved */
+
+	/** Set or enable a specific feature */
+	LIBUSB_REQUEST_SET_FEATURE = 0x03,
+
+	/* 0x04 is reserved */
+
+	/** Set device address for all future accesses */
+	LIBUSB_REQUEST_SET_ADDRESS = 0x05,
+
+	/** Get the specified descriptor */
+	LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
+
+	/** Used to update existing descriptors or add new descriptors */
+	LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
+
+	/** Get the current device configuration value */
+	LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
+
+	/** Set device configuration */
+	LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
+
+	/** Return the selected alternate setting for the specified interface */
+	LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
+
+	/** Select an alternate interface for the specified interface */
+	LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
+
+	/** Set then report an endpoint's synchronization frame */
+	LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
+};
+
+/** \ingroup misc
+ * Request type bits of the
+ * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
+ * transfers. */
+enum libusb_request_type {
+	/** Standard */
+	LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
+
+	/** Class */
+	LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
+
+	/** Vendor */
+	LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
+
+	/** Reserved */
+	LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
+};
+
+/** \ingroup misc
+ * Recipient bits of the
+ * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
+ * transfers. Values 4 through 31 are reserved. */
+enum libusb_request_recipient {
+	/** Device */
+	LIBUSB_RECIPIENT_DEVICE = 0x00,
+
+	/** Interface */
+	LIBUSB_RECIPIENT_INTERFACE = 0x01,
+
+	/** Endpoint */
+	LIBUSB_RECIPIENT_ENDPOINT = 0x02,
+
+	/** Other */
+	LIBUSB_RECIPIENT_OTHER = 0x03,
+};
+
+#define LIBUSB_ISO_SYNC_TYPE_MASK		0x0C
+
+/** \ingroup desc
+ * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
+ * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
+ * libusb_endpoint_descriptor.
+ */
+enum libusb_iso_sync_type {
+	/** No synchronization */
+	LIBUSB_ISO_SYNC_TYPE_NONE = 0,
+
+	/** Asynchronous */
+	LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
+
+	/** Adaptive */
+	LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
+
+	/** Synchronous */
+	LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
+};
+
+#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
+
+/** \ingroup desc
+ * Usage type for isochronous endpoints. Values for bits 4:5 of the
+ * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
+ * libusb_endpoint_descriptor.
+ */
+enum libusb_iso_usage_type {
+	/** Data endpoint */
+	LIBUSB_ISO_USAGE_TYPE_DATA = 0,
+
+	/** Feedback endpoint */
+	LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
+
+	/** Implicit feedback Data endpoint */
+	LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
+};
+
+/** \ingroup desc
+ * A structure representing the standard USB device descriptor. This
+ * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
+ * All multiple-byte fields are represented in host-endian format.
+ */
+struct libusb_device_descriptor {
+	/** Size of this descriptor (in bytes) */
+	uint8_t  bLength;
+
+	/** Descriptor type. Will have value
+	 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
+	 * context. */
+	uint8_t  bDescriptorType;
+
+	/** USB specification release number in binary-coded decimal. A value of
+	 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
+	uint16_t bcdUSB;
+
+	/** USB-IF class code for the device. See \ref libusb_class_code. */
+	uint8_t  bDeviceClass;
+
+	/** USB-IF subclass code for the device, qualified by the bDeviceClass
+	 * value */
+	uint8_t  bDeviceSubClass;
+
+	/** USB-IF protocol code for the device, qualified by the bDeviceClass and
+	 * bDeviceSubClass values */
+	uint8_t  bDeviceProtocol;
+
+	/** Maximum packet size for endpoint 0 */
+	uint8_t  bMaxPacketSize0;
+
+	/** USB-IF vendor ID */
+	uint16_t idVendor;
+
+	/** USB-IF product ID */
+	uint16_t idProduct;
+
+	/** Device release number in binary-coded decimal */
+	uint16_t bcdDevice;
+
+	/** Index of string descriptor describing manufacturer */
+	uint8_t  iManufacturer;
+
+	/** Index of string descriptor describing product */
+	uint8_t  iProduct;
+
+	/** Index of string descriptor containing device serial number */
+	uint8_t  iSerialNumber;
+
+	/** Number of possible configurations */
+	uint8_t  bNumConfigurations;
+};
+
+/** \ingroup desc
+ * A structure representing the standard USB endpoint descriptor. This
+ * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
+ * All multiple-byte fields are represented in host-endian format.
+ */
+struct libusb_endpoint_descriptor {
+	/** Size of this descriptor (in bytes) */
+	uint8_t  bLength;
+
+	/** Descriptor type. Will have value
+	 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
+	 * this context. */
+	uint8_t  bDescriptorType;
+
+	/** The address of the endpoint described by this descriptor. Bits 0:3 are
+	 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
+	 * see \ref libusb_endpoint_direction.
+	 */
+	uint8_t  bEndpointAddress;
+
+	/** Attributes which apply to the endpoint when it is configured using
+	 * the bConfigurationValue. Bits 0:1 determine the transfer type and
+	 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
+	 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
+	 * Bits 4:5 are also only used for isochronous endpoints and correspond to
+	 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
+	 */
+	uint8_t  bmAttributes;
+
+	/** Maximum packet size this endpoint is capable of sending/receiving. */
+	uint16_t wMaxPacketSize;
+
+	/** Interval for polling endpoint for data transfers. */
+	uint8_t  bInterval;
+
+	/** For audio devices only: the rate at which synchronization feedback
+	 * is provided. */
+	uint8_t  bRefresh;
+
+	/** For audio devices only: the address if the synch endpoint */
+	uint8_t  bSynchAddress;
+
+	/** Extra descriptors. If libusb encounters unknown endpoint descriptors,
+	 * it will store them here, should you wish to parse them. */
+	const unsigned char *extra;
+
+	/** Length of the extra descriptors, in bytes. */
+	int extra_length;
+};
+
+/** \ingroup desc
+ * A structure representing the standard USB interface descriptor. This
+ * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
+ * All multiple-byte fields are represented in host-endian format.
+ */
+struct libusb_interface_descriptor {
+	/** Size of this descriptor (in bytes) */
+	uint8_t  bLength;
+
+	/** Descriptor type. Will have value
+	 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
+	 * in this context. */
+	uint8_t  bDescriptorType;
+
+	/** Number of this interface */
+	uint8_t  bInterfaceNumber;
+
+	/** Value used to select this alternate setting for this interface */
+	uint8_t  bAlternateSetting;
+
+	/** Number of endpoints used by this interface (excluding the control
+	 * endpoint). */
+	uint8_t  bNumEndpoints;
+
+	/** USB-IF class code for this interface. See \ref libusb_class_code. */
+	uint8_t  bInterfaceClass;
+
+	/** USB-IF subclass code for this interface, qualified by the
+	 * bInterfaceClass value */
+	uint8_t  bInterfaceSubClass;
+
+	/** USB-IF protocol code for this interface, qualified by the
+	 * bInterfaceClass and bInterfaceSubClass values */
+	uint8_t  bInterfaceProtocol;
+
+	/** Index of string descriptor describing this interface */
+	uint8_t  iInterface;
+
+	/** Array of endpoint descriptors. This length of this array is determined
+	 * by the bNumEndpoints field. */
+	const struct libusb_endpoint_descriptor *endpoint;
+
+	/** Extra descriptors. If libusb encounters unknown interface descriptors,
+	 * it will store them here, should you wish to parse them. */
+	const unsigned char *extra;
+
+	/** Length of the extra descriptors, in bytes. */
+	int extra_length;
+};
+
+/** \ingroup desc
+ * A collection of alternate settings for a particular USB interface.
+ */
+struct libusb_interface {
+	/** Array of interface descriptors. The length of this array is determined
+	 * by the num_altsetting field. */
+	const struct libusb_interface_descriptor *altsetting;
+
+	/** The number of alternate settings that belong to this interface */
+	int num_altsetting;
+};
+
+/** \ingroup desc
+ * A structure representing the standard USB configuration descriptor. This
+ * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
+ * All multiple-byte fields are represented in host-endian format.
+ */
+struct libusb_config_descriptor {
+	/** Size of this descriptor (in bytes) */
+	uint8_t  bLength;
+
+	/** Descriptor type. Will have value
+	 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
+	 * in this context. */
+	uint8_t  bDescriptorType;
+
+	/** Total length of data returned for this configuration */
+	uint16_t wTotalLength;
+
+	/** Number of interfaces supported by this configuration */
+	uint8_t  bNumInterfaces;
+
+	/** Identifier value for this configuration */
+	uint8_t  bConfigurationValue;
+
+	/** Index of string descriptor describing this configuration */
+	uint8_t  iConfiguration;
+
+	/** Configuration characteristics */
+	uint8_t  bmAttributes;
+
+	/** Maximum power consumption of the USB device from this bus in this
+	 * configuration when the device is fully opreation. Expressed in units
+	 * of 2 mA. */
+	uint8_t  MaxPower;
+
+	/** Array of interfaces supported by this configuration. The length of
+	 * this array is determined by the bNumInterfaces field. */
+	const struct libusb_interface *interface;
+
+	/** Extra descriptors. If libusb encounters unknown configuration
+	 * descriptors, it will store them here, should you wish to parse them. */
+	const unsigned char *extra;
+
+	/** Length of the extra descriptors, in bytes. */
+	int extra_length;
+};
+
+/** \ingroup asyncio
+ * Setup packet for control transfers. */
+struct libusb_control_setup {
+	/** Request type. Bits 0:4 determine recipient, see
+	 * \ref libusb_request_recipient. Bits 5:6 determine type, see
+	 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
+	 * \ref libusb_endpoint_direction.
+	 */
+	uint8_t  bmRequestType;
+
+	/** Request. If the type bits of bmRequestType are equal to
+	 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
+	 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
+	 * \ref libusb_standard_request. For other cases, use of this field is
+	 * application-specific. */
+	uint8_t  bRequest;
+
+	/** Value. Varies according to request */
+	uint16_t wValue;
+
+	/** Index. Varies according to request, typically used to pass an index
+	 * or offset */
+	uint16_t wIndex;
+
+	/** Number of bytes to transfer */
+	uint16_t wLength;
+};
+
+#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
+
+/* libusb */
+
+struct libusb_context;
+struct libusb_device;
+struct libusb_device_handle;
+
+/** \ingroup lib
+ * Structure representing a libusb session. The concept of individual libusb
+ * sessions allows for your program to use two libraries (or dynamically
+ * load two modules) which both independently use libusb. This will prevent
+ * interference between the individual libusb users - for example
+ * libusb_set_debug() will not affect the other user of the library, and
+ * libusb_exit() will not destroy resources that the other user is still
+ * using.
+ *
+ * Sessions are created by libusb_init() and destroyed through libusb_exit().
+ * If your application is guaranteed to only ever include a single libusb
+ * user (i.e. you), you do not have to worry about contexts: pass NULL in
+ * every function call where a context is required. The default context
+ * will be used.
+ *
+ * For more information, see \ref contexts.
+ */
+typedef struct libusb_context libusb_context;
+
+/** \ingroup dev
+ * Structure representing a USB device detected on the system. This is an
+ * opaque type for which you are only ever provided with a pointer, usually
+ * originating from libusb_get_device_list().
+ *
+ * Certain operations can be performed on a device, but in order to do any
+ * I/O you will have to first obtain a device handle using libusb_open().
+ *
+ * Devices are reference counted with libusb_device_ref() and
+ * libusb_device_unref(), and are freed when the reference count reaches 0.
+ * New devices presented by libusb_get_device_list() have a reference count of
+ * 1, and libusb_free_device_list() can optionally decrease the reference count
+ * on all devices in the list. libusb_open() adds another reference which is
+ * later destroyed by libusb_close().
+ */
+typedef struct libusb_device libusb_device;
+
+
+/** \ingroup dev
+ * Structure representing a handle on a USB device. This is an opaque type for
+ * which you are only ever provided with a pointer, usually originating from
+ * libusb_open().
+ *
+ * A device handle is used to perform I/O and other operations. When finished
+ * with a device handle, you should call libusb_close().
+ */
+typedef struct libusb_device_handle libusb_device_handle;
+
+/** \ingroup misc
+ * Error codes. Most libusb functions return 0 on success or one of these
+ * codes on failure.
+ */
+enum libusb_error {
+	/** Success (no error) */
+	LIBUSB_SUCCESS = 0,
+
+	/** Input/output error */
+	LIBUSB_ERROR_IO = -1,
+
+	/** Invalid parameter */
+	LIBUSB_ERROR_INVALID_PARAM = -2,
+
+	/** Access denied (insufficient permissions) */
+	LIBUSB_ERROR_ACCESS = -3,
+
+	/** No such device (it may have been disconnected) */
+	LIBUSB_ERROR_NO_DEVICE = -4,
+
+	/** Entity not found */
+	LIBUSB_ERROR_NOT_FOUND = -5,
+
+	/** Resource busy */
+	LIBUSB_ERROR_BUSY = -6,
+
+	/** Operation timed out */
+	LIBUSB_ERROR_TIMEOUT = -7,
+
+	/** Overflow */
+	LIBUSB_ERROR_OVERFLOW = -8,
+
+	/** Pipe error */
+	LIBUSB_ERROR_PIPE = -9,
+
+	/** System call interrupted (perhaps due to signal) */
+	LIBUSB_ERROR_INTERRUPTED = -10,
+
+	/** Insufficient memory */
+	LIBUSB_ERROR_NO_MEM = -11,
+
+	/** Operation not supported or unimplemented on this platform */
+	LIBUSB_ERROR_NOT_SUPPORTED = -12,
+
+	/** Other error */
+	LIBUSB_ERROR_OTHER = -99,
+};
+
+/** \ingroup asyncio
+ * Transfer status codes */
+enum libusb_transfer_status {
+	/** Transfer completed without error. Note that this does not indicate
+	 * that the entire amount of requested data was transferred. */
+	LIBUSB_TRANSFER_COMPLETED,
+
+	/** Transfer failed */
+	LIBUSB_TRANSFER_ERROR,
+
+	/** Transfer timed out */
+	LIBUSB_TRANSFER_TIMED_OUT,
+
+	/** Transfer was cancelled */
+	LIBUSB_TRANSFER_CANCELLED,
+
+	/** For bulk/interrupt endpoints: halt condition detected (endpoint
+	 * stalled). For control endpoints: control request not supported. */
+	LIBUSB_TRANSFER_STALL,
+
+	/** Device was disconnected */
+	LIBUSB_TRANSFER_NO_DEVICE,
+
+	/** Device sent more data than requested */
+	LIBUSB_TRANSFER_OVERFLOW,
+};
+
+/** \ingroup asyncio
+ * libusb_transfer.flags values */
+enum libusb_transfer_flags {
+	/** Report short frames as errors */
+	LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
+
+	/** Automatically free() transfer buffer during libusb_free_transfer() */
+	LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
+
+	/** Automatically call libusb_free_transfer() after callback returns.
+	 * If this flag is set, it is illegal to call libusb_free_transfer()
+	 * from your transfer callback, as this will result in a double-free
+	 * when this flag is acted upon. */
+	LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
+};
+
+/** \ingroup asyncio
+ * Isochronous packet descriptor. */
+struct libusb_iso_packet_descriptor {
+	/** Length of data to request in this packet */
+	unsigned int length;
+
+	/** Amount of data that was actually transferred */
+	unsigned int actual_length;
+
+	/** Status code for this packet */
+	enum libusb_transfer_status status;
+};
+
+struct libusb_transfer;
+
+typedef void (*libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
+
+/** \ingroup asyncio
+ * The generic USB transfer structure. The user populates this structure and
+ * then submits it in order to request a transfer. After the transfer has
+ * completed, the library populates the transfer with the results and passes
+ * it back to the user.
+ */
+struct libusb_transfer {
+	/** Handle of the device that this transfer will be submitted to */
+	libusb_device_handle *dev_handle;
+
+	/** A bitwise OR combination of \ref libusb_transfer_flags. */
+	uint8_t flags;
+
+	/** Address of the endpoint where this transfer will be sent. */
+	unsigned char endpoint;
+
+	/** Type of the endpoint from \ref libusb_transfer_type */
+	unsigned char type;
+
+	/** Timeout for this transfer in millseconds. A value of 0 indicates no
+	 * timeout. */
+	unsigned int timeout;
+
+	/** The status of the transfer. Read-only, and only for use within
+	 * transfer callback function.
+	 *
+	 * If this is an isochronous transfer, this field may read COMPLETED even
+	 * if there were errors in the frames. Use the
+	 * \ref libusb_iso_packet_descriptor::status "status" field in each packet
+	 * to determine if errors occurred. */
+	enum libusb_transfer_status status;
+
+	/** Length of the data buffer */
+	int length;
+
+	/** Actual length of data that was transferred. Read-only, and only for
+	 * use within transfer callback function. Not valid for isochronous
+	 * endpoint transfers. */
+	int actual_length;
+
+	/** Callback function. This will be invoked when the transfer completes,
+	 * fails, or is cancelled. */
+	libusb_transfer_cb_fn callback;
+
+	/** User context data to pass to the callback function. */
+	void *user_data;
+
+	/** Data buffer */
+	unsigned char *buffer;
+
+	/** Number of isochronous packets. Only used for I/O with isochronous
+	 * endpoints. */
+	int num_iso_packets;
+
+	/** Isochronous packet descriptors, for isochronous transfers only. */
+	struct libusb_iso_packet_descriptor iso_packet_desc[0];
+};
+
+int libusb_init(libusb_context **ctx);
+void libusb_exit(libusb_context *ctx);
+void libusb_set_debug(libusb_context *ctx, int level);
+
+ssize_t libusb_get_device_list(libusb_context *ctx,
+	libusb_device ***list);
+void libusb_free_device_list(libusb_device **list, int unref_devices);
+libusb_device *libusb_ref_device(libusb_device *dev);
+void libusb_unref_device(libusb_device *dev);
+
+int libusb_get_configuration(libusb_device_handle *dev, int *config);
+int libusb_get_device_descriptor(libusb_device *dev,
+	struct libusb_device_descriptor *desc);
+int libusb_get_active_config_descriptor(libusb_device *dev,
+	struct libusb_config_descriptor **config);
+int libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index,
+	struct libusb_config_descriptor **config);
+int libusb_get_config_descriptor_by_value(libusb_device *dev,
+	uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
+void libusb_free_config_descriptor(struct libusb_config_descriptor *config);
+uint8_t libusb_get_bus_number(libusb_device *dev);
+uint8_t libusb_get_device_address(libusb_device *dev);
+int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint);
+
+int libusb_open(libusb_device *dev, libusb_device_handle **handle);
+void libusb_close(libusb_device_handle *dev_handle);
+libusb_device *libusb_get_device(libusb_device_handle *dev_handle);
+
+int libusb_set_configuration(libusb_device_handle *dev, int configuration);
+int libusb_claim_interface(libusb_device_handle *dev, int iface);
+int libusb_release_interface(libusb_device_handle *dev, int iface);
+
+libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx,
+	uint16_t vendor_id, uint16_t product_id);
+
+int libusb_set_interface_alt_setting(libusb_device_handle *dev,
+	int interface_number, int alternate_setting);
+int libusb_clear_halt(libusb_device_handle *dev, unsigned char endpoint);
+int libusb_reset_device(libusb_device_handle *dev);
+
+int libusb_kernel_driver_active(libusb_device_handle *dev, int interface);
+int libusb_detach_kernel_driver(libusb_device_handle *dev, int interface);
+int libusb_attach_kernel_driver(libusb_device_handle *dev, int interface);
+
+/* async I/O */
+
+/** \ingroup asyncio
+ * Get the data section of a control transfer. This convenience function is here
+ * to remind you that the data does not start until 8 bytes into the actual
+ * buffer, as the setup packet comes first.
+ *
+ * Calling this function only makes sense from a transfer callback function,
+ * or situations where you have already allocated a suitably sized buffer at
+ * transfer->buffer.
+ *
+ * \param transfer a transfer
+ * \returns pointer to the first byte of the data section
+ */
+static inline unsigned char *libusb_control_transfer_get_data(
+	struct libusb_transfer *transfer)
+{
+	return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
+}
+
+/** \ingroup asyncio
+ * Get the control setup packet of a control transfer. This convenience
+ * function is here to remind you that the control setup occupies the first
+ * 8 bytes of the transfer data buffer.
+ *
+ * Calling this function only makes sense from a transfer callback function,
+ * or situations where you have already allocated a suitably sized buffer at
+ * transfer->buffer.
+ *
+ * \param transfer a transfer
+ * \returns a casted pointer to the start of the transfer data buffer
+ */
+static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
+	struct libusb_transfer *transfer)
+{
+	return (struct libusb_control_setup *) transfer->buffer;
+}
+
+/** \ingroup asyncio
+ * Helper function to populate the setup packet (first 8 bytes of the data
+ * buffer) for a control transfer. The wIndex, wValue and wLength values should
+ * be given in host-endian byte order.
+ *
+ * \param buffer buffer to output the setup packet into
+ * \param bmRequestType see the
+ * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
+ * \ref libusb_control_setup
+ * \param bRequest see the
+ * \ref libusb_control_setup::bRequest "bRequest" field of
+ * \ref libusb_control_setup
+ * \param wValue see the
+ * \ref libusb_control_setup::wValue "wValue" field of
+ * \ref libusb_control_setup
+ * \param wIndex see the
+ * \ref libusb_control_setup::wIndex "wIndex" field of
+ * \ref libusb_control_setup
+ * \param wLength see the
+ * \ref libusb_control_setup::wLength "wLength" field of
+ * \ref libusb_control_setup
+ */
+static inline void libusb_fill_control_setup(unsigned char *buffer,
+	uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
+	uint16_t wLength)
+{
+	struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
+	setup->bmRequestType = bmRequestType;
+	setup->bRequest = bRequest;
+	setup->wValue = libusb_cpu_to_le16(wValue);
+	setup->wIndex = libusb_cpu_to_le16(wIndex);
+	setup->wLength = libusb_cpu_to_le16(wLength);
+}
+
+struct libusb_transfer *libusb_alloc_transfer(int iso_packets);
+int libusb_submit_transfer(struct libusb_transfer *transfer);
+int libusb_cancel_transfer(struct libusb_transfer *transfer);
+void libusb_free_transfer(struct libusb_transfer *transfer);
+
+/** \ingroup asyncio
+ * Helper function to populate the required \ref libusb_transfer fields
+ * for a control transfer.
+ *
+ * If you pass a transfer buffer to this function, the first 8 bytes will
+ * be interpreted as a control setup packet, and the wLength field will be
+ * used to automatically populate the \ref libusb_transfer::length "length"
+ * field of the transfer. Therefore the recommended approach is:
+ * -# Allocate a suitably sized data buffer (including space for control setup)
+ * -# Call libusb_fill_control_setup()
+ * -# If this is a host-to-device transfer with a data stage, put the data
+ *    in place after the setup packet
+ * -# Call this function
+ * -# Call libusb_submit_transfer()
+ *
+ * It is also legal to pass a NULL buffer to this function, in which case this
+ * function will not attempt to populate the length field. Remember that you
+ * must then populate the buffer and length fields later.
+ *
+ * \param transfer the transfer to populate
+ * \param dev_handle handle of the device that will handle the transfer
+ * \param buffer data buffer. If provided, this function will interpret the
+ * first 8 bytes as a setup packet and infer the transfer length from that.
+ * \param callback callback function to be invoked on transfer completion
+ * \param user_data user data to pass to callback function
+ * \param timeout timeout for the transfer in milliseconds
+ */
+static inline void libusb_fill_control_transfer(
+	struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
+	unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
+	unsigned int timeout)
+{
+	struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
+	transfer->dev_handle = dev_handle;
+	transfer->endpoint = 0;
+	transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
+	transfer->timeout = timeout;
+	transfer->buffer = buffer;
+	if (setup)
+		transfer->length = LIBUSB_CONTROL_SETUP_SIZE
+			+ libusb_le16_to_cpu(setup->wLength);
+	transfer->user_data = user_data;
+	transfer->callback = callback;
+}
+
+/** \ingroup asyncio
+ * Helper function to populate the required \ref libusb_transfer fields
+ * for a bulk transfer.
+ *
+ * \param transfer the transfer to populate
+ * \param dev_handle handle of the device that will handle the transfer
+ * \param endpoint address of the endpoint where this transfer will be sent
+ * \param buffer data buffer
+ * \param length length of data buffer
+ * \param callback callback function to be invoked on transfer completion
+ * \param user_data user data to pass to callback function
+ * \param timeout timeout for the transfer in milliseconds
+ */
+static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
+	libusb_device_handle *dev_handle, unsigned char endpoint,
+	unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
+	void *user_data, unsigned int timeout)
+{
+	transfer->dev_handle = dev_handle;
+	transfer->endpoint = endpoint;
+	transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
+	transfer->timeout = timeout;
+	transfer->buffer = buffer;
+	transfer->length = length;
+	transfer->user_data = user_data;
+	transfer->callback = callback;
+}
+
+/** \ingroup asyncio
+ * Helper function to populate the required \ref libusb_transfer fields
+ * for an interrupt transfer.
+ *
+ * \param transfer the transfer to populate
+ * \param dev_handle handle of the device that will handle the transfer
+ * \param endpoint address of the endpoint where this transfer will be sent
+ * \param buffer data buffer
+ * \param length length of data buffer
+ * \param callback callback function to be invoked on transfer completion
+ * \param user_data user data to pass to callback function
+ * \param timeout timeout for the transfer in milliseconds
+ */
+static inline void libusb_fill_interrupt_transfer(
+	struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
+	unsigned char endpoint, unsigned char *buffer, int length,
+	libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
+{
+	transfer->dev_handle = dev_handle;
+	transfer->endpoint = endpoint;
+	transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
+	transfer->timeout = timeout;
+	transfer->buffer = buffer;
+	transfer->length = length;
+	transfer->user_data = user_data;
+	transfer->callback = callback;
+}
+
+/** \ingroup asyncio
+ * Helper function to populate the required \ref libusb_transfer fields
+ * for an isochronous transfer.
+ *
+ * \param transfer the transfer to populate
+ * \param dev_handle handle of the device that will handle the transfer
+ * \param endpoint address of the endpoint where this transfer will be sent
+ * \param buffer data buffer
+ * \param length length of data buffer
+ * \param num_iso_packets the number of isochronous packets
+ * \param callback callback function to be invoked on transfer completion
+ * \param user_data user data to pass to callback function
+ * \param timeout timeout for the transfer in milliseconds
+ */
+static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
+	libusb_device_handle *dev_handle, unsigned char endpoint,
+	unsigned char *buffer, int length, int num_iso_packets,
+	libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
+{
+	transfer->dev_handle = dev_handle;
+	transfer->endpoint = endpoint;
+	transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
+	transfer->timeout = timeout;
+	transfer->buffer = buffer;
+	transfer->length = length;
+	transfer->num_iso_packets = num_iso_packets;
+	transfer->user_data = user_data;
+	transfer->callback = callback;
+}
+
+/** \ingroup asyncio
+ * Convenience function to set the length of all packets in an isochronous
+ * transfer, based on the num_iso_packets field in the transfer structure.
+ *
+ * \param transfer a transfer
+ * \param length the length to set in each isochronous packet descriptor
+ * \see libusb_get_max_packet_size()
+ */
+static inline void libusb_set_iso_packet_lengths(
+	struct libusb_transfer *transfer, unsigned int length)
+{
+	int i;
+	for (i = 0; i < transfer->num_iso_packets; i++)
+		transfer->iso_packet_desc[i].length = length;
+}
+
+/** \ingroup asyncio
+ * Convenience function to locate the position of an isochronous packet
+ * within the buffer of an isochronous transfer.
+ *
+ * This is a thorough function which loops through all preceding packets,
+ * accumulating their lengths to find the position of the specified packet.
+ * Typically you will assign equal lengths to each packet in the transfer,
+ * and hence the above method is sub-optimal. You may wish to use
+ * libusb_get_iso_packet_buffer_simple() instead.
+ *
+ * \param transfer a transfer
+ * \param packet the packet to return the address of
+ * \returns the base address of the packet buffer inside the transfer buffer,
+ * or NULL if the packet does not exist.
+ * \see libusb_get_iso_packet_buffer_simple()
+ */
+static inline unsigned char *libusb_get_iso_packet_buffer(
+	struct libusb_transfer *transfer, unsigned int packet)
+{
+	int i;
+	size_t offset = 0;
+
+	if (packet >= transfer->num_iso_packets)
+		return NULL;
+
+	for (i = 0; i < packet; i++)
+		offset += transfer->iso_packet_desc[i].length;
+
+	return transfer->buffer + offset;
+}
+
+/** \ingroup asyncio
+ * Convenience function to locate the position of an isochronous packet
+ * within the buffer of an isochronous transfer, for transfers where each
+ * packet is of identical size.
+ *
+ * This function relies on the assumption that every packet within the transfer
+ * is of identical size to the first packet. Calculating the location of
+ * the packet buffer is then just a simple calculation:
+ * <tt>buffer + (packet_size * packet)</tt>
+ *
+ * Do not use this function on transfers other than those that have identical
+ * packet lengths for each packet.
+ *
+ * \param transfer a transfer
+ * \param packet the packet to return the address of
+ * \returns the base address of the packet buffer inside the transfer buffer,
+ * or NULL if the packet does not exist.
+ * \see libusb_get_iso_packet_buffer()
+ */
+static inline unsigned char *libusb_get_iso_packet_buffer_simple(
+	struct libusb_transfer *transfer, unsigned int packet)
+{
+	if (packet >= transfer->num_iso_packets)
+		return NULL;
+
+	return transfer->buffer + (transfer->iso_packet_desc[0].length * packet);
+}
+
+/* sync I/O */
+
+int libusb_control_transfer(libusb_device_handle *dev_handle,
+	uint8_t request_type, uint8_t request, uint16_t value, uint16_t index,
+	unsigned char *data, uint16_t length, unsigned int timeout);
+
+int libusb_bulk_transfer(libusb_device_handle *dev_handle,
+	unsigned char endpoint, unsigned char *data, int length,
+	int *actual_length, unsigned int timeout);
+
+int libusb_interrupt_transfer(libusb_device_handle *dev_handle,
+	unsigned char endpoint, unsigned char *data, int length,
+	int *actual_length, unsigned int timeout);
+
+/** \ingroup desc
+ * Retrieve a descriptor from the default control pipe.
+ * This is a convenience function which formulates the appropriate control
+ * message to retrieve the descriptor.
+ *
+ * \param dev a device handle
+ * \param desc_type the descriptor type, see \ref libusb_descriptor_type
+ * \param desc_index the index of the descriptor to retrieve
+ * \param data output buffer for descriptor
+ * \param length size of data buffer
+ * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
+ */
+static inline int libusb_get_descriptor(libusb_device_handle *dev,
+	uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
+{
+	return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
+		LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
+		length, 1000);
+}
+
+/** \ingroup desc
+ * Retrieve a descriptor from a device.
+ * This is a convenience function which formulates the appropriate control
+ * message to retrieve the descriptor. The string returned is Unicode, as
+ * detailed in the USB specifications.
+ *
+ * \param dev a device handle
+ * \param desc_index the index of the descriptor to retrieve
+ * \param langid the language ID for the string descriptor
+ * \param data output buffer for descriptor
+ * \param length size of data buffer
+ * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
+ * \see libusb_get_string_descriptor_ascii()
+ */
+static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
+	uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
+{
+	return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
+		LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,
+		langid, data, length, 1000);
+}
+
+int libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
+	uint8_t index, unsigned char *data, int length);
+
+/* polling and timeouts */
+
+int libusb_try_lock_events(libusb_context *ctx);
+void libusb_lock_events(libusb_context *ctx);
+void libusb_unlock_events(libusb_context *ctx);
+int libusb_event_handling_ok(libusb_context *ctx);
+int libusb_event_handler_active(libusb_context *ctx);
+void libusb_lock_event_waiters(libusb_context *ctx);
+void libusb_unlock_event_waiters(libusb_context *ctx);
+int libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
+
+int libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv);
+int libusb_handle_events(libusb_context *ctx);
+int libusb_handle_events_locked(libusb_context *ctx, struct timeval *tv);
+int libusb_get_next_timeout(libusb_context *ctx, struct timeval *tv);
+
+/** \ingroup poll
+ * File descriptor for polling
+ */
+struct libusb_pollfd {
+	/** Numeric file descriptor */
+	int fd;
+
+	/** Event flags to poll for from <poll.h>. POLLIN indicates that you
+	 * should monitor this file descriptor for becoming ready to read from,
+	 * and POLLOUT indicates that you should monitor this file descriptor for
+	 * nonblocking write readiness. */
+	short events;
+};
+
+/** \ingroup poll
+ * Callback function, invoked when a new file descriptor should be added
+ * to the set of file descriptors monitored for events.
+ * \param fd the new file descriptor
+ * \param events events to monitor for, see \ref libusb_pollfd for a
+ * description
+ * \param user_data User data pointer specified in
+ * libusb_set_pollfd_notifiers() call
+ * \see libusb_set_pollfd_notifiers()
+ */
+typedef void (*libusb_pollfd_added_cb)(int fd, short events, void *user_data);
+
+/** \ingroup poll
+ * Callback function, invoked when a file descriptor should be removed from
+ * the set of file descriptors being monitored for events. After returning
+ * from this callback, do not use that file descriptor again.
+ * \param fd the file descriptor to stop monitoring
+ * \param user_data User data pointer specified in
+ * libusb_set_pollfd_notifiers() call
+ * \see libusb_set_pollfd_notifiers()
+ */
+typedef void (*libusb_pollfd_removed_cb)(int fd, void *user_data);
+
+const struct libusb_pollfd **libusb_get_pollfds(libusb_context *ctx);
+void libusb_set_pollfd_notifiers(libusb_context *ctx,
+	libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
+	void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/inlines.c b/src/inlines.c
new file mode 100644
--- /dev/null
+++ b/src/inlines.c
@@ -0,0 +1,116 @@
+#include <libusb.h>
+
+unsigned char*
+inline_libusb_control_transfer_get_data (
+ struct libusb_transfer * transfer )
+{
+ return libusb_control_transfer_get_data (transfer);
+}
+
+struct libusb_control_setup*
+inline_libusb_control_transfer_get_setup (
+ struct libusb_transfer * transfer )
+{
+ return libusb_control_transfer_get_setup (transfer);
+}
+
+void
+inline_libusb_fill_control_setup (unsigned char *buffer,
+  uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue,
+  uint16_t wIndex, uint16_t wLength)
+{
+  libusb_fill_control_setup(buffer,bmRequestType,bRequest,
+    wValue,wIndex,wLength);
+}
+
+void
+inline_libusb_fill_control_transfer (struct libusb_transfer *transfer,
+  libusb_device_handle *dev_handle, unsigned char *buffer,
+  libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
+{
+  libusb_fill_control_transfer(transfer,dev_handle,buffer,
+    callback,user_data,timeout);
+}
+
+void
+inline_libusb_fill_bulk_transfer (struct libusb_transfer *transfer,
+  libusb_device_handle *dev_handle, unsigned char endpoint,
+  unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
+  void *user_data, unsigned int timeout)
+{
+  libusb_fill_bulk_transfer(transfer,dev_handle,endpoint,buffer,
+    length,callback,user_data,timeout);
+}
+
+void
+inline_libusb_fill_interrupt_transfer (struct libusb_transfer *transfer,
+  libusb_device_handle *dev_handle, unsigned char endpoint,
+  unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
+  void *user_data, unsigned int timeout)
+{
+  libusb_fill_interrupt_transfer(transfer,dev_handle,endpoint,
+    buffer,length,callback,user_data,timeout);
+}
+
+void
+inline_libusb_fill_iso_transfer (struct libusb_transfer *transfer,
+  libusb_device_handle *dev_handle, unsigned char endpoint,
+  unsigned char *buffer, int length,
+  int num_iso_packets, libusb_transfer_cb_fn callback,
+  void *user_data, unsigned int timeout)
+{
+  libusb_fill_iso_transfer(transfer,dev_handle,endpoint,
+    buffer,length,num_iso_packets,callback,user_data,timeout);
+}
+
+void
+inline_libusb_set_iso_packet_lengths (struct libusb_transfer *transfer,
+  unsigned int length)
+{
+  libusb_set_iso_packet_lengths(transfer,length);
+}
+
+unsigned char *
+inline_libusb_get_iso_packet_buffer (
+  struct libusb_transfer *transfer, unsigned int packet)
+{
+  return  libusb_get_iso_packet_buffer(transfer,packet);
+}
+
+unsigned char *
+inline_libusb_get_iso_packet_buffer_simple (
+  struct libusb_transfer *transfer, unsigned int packet)
+{
+  return  libusb_get_iso_packet_buffer_simple(transfer,packet);
+}
+
+int 
+inline_libusb_get_descriptor (libusb_device_handle *dev,
+  uint8_t desc_type, uint8_t desc_index, unsigned char *data,
+  int length)
+{
+  return libusb_get_descriptor(dev,desc_type,desc_index,
+    data,length);
+}
+
+int 
+inline_libusb_get_string_descriptor (libusb_device_handle *dev,
+  uint8_t desc_index, uint16_t langid, unsigned char *data,
+  int length)
+{
+  return libusb_get_string_descriptor(dev,desc_index,langid,
+    data,length);
+}
+
+uint16_t
+inline_libusb_cpu_to_le16 (uint16_t x)
+{
+  return libusb_cpu_to_le16(x);
+}
+
+uint16_t
+inline_libusb_le16_to_cpu (uint16_t x)
+{
+  return libusb_le16_to_cpu(x);
+}
+
diff --git a/src/types.c b/src/types.c
deleted file mode 100644
--- a/src/types.c
+++ /dev/null
@@ -1,427 +0,0 @@
-#include <libusb.h>
-
-/*
-  Sizes of structs we are going to
-  use in 'sizeOf' method of Storable instances.
-*/
-
-int size_of_libusb_device_descriptor (void)
-{
-    return sizeof (struct libusb_device_descriptor);
-}
-
-int size_of_libusb_endpoint_descriptor (void)
-{
-    return sizeof (struct libusb_endpoint_descriptor);
-}
-
-int size_of_libusb_interface_descriptor (void)
-{
-    return sizeof (struct libusb_interface_descriptor);
-}
-
-int size_of_libusb_interface (void)
-{
-    return sizeof (struct libusb_interface);
-}
-
-int size_of_libusb_config_descriptor (void)
-{
-    return sizeof (struct libusb_config_descriptor);
-}
-
-int size_of_libusb_control_setup (void)
-{
-    return sizeof (struct libusb_control_setup);
-}
-
-int size_of_libusb_iso_packet_descriptor (void)
-{
-    return sizeof (struct libusb_iso_packet_descriptor);
-}
-
-int size_of_libusb_transfer (void)
-{
-    return sizeof (struct libusb_transfer);
-}
-
-int size_of_libusb_pollfd (void)
-{
-    return sizeof (struct libusb_pollfd);
-}
-
-/*
-  Functions that fill a C struct
-  after received parameters. They will
-  be used in 'poke' method of Storable
-  instances.
-*/
-
-void hs2c_libusb_device_descriptor (struct libusb_device_descriptor *p,
-    uint8_t p1,
-    uint8_t p2,
-    uint16_t p3,
-    uint8_t p4,
-    uint8_t p5,
-    uint8_t p6,
-    uint8_t p7,
-    uint16_t p8,
-    uint16_t p9,
-    uint16_t p10,
-    uint8_t p11,
-    uint8_t p12,
-    uint8_t p13,
-    uint8_t p14)
-{
-    p->bLength = p1;
-    p->bDescriptorType = p2;
-    p->bcdUSB = p3;
-    p->bDeviceClass = p4;
-    p->bDeviceSubClass = p5;
-    p->bDeviceProtocol = p6;
-    p->bMaxPacketSize0 = p7;
-    p->idVendor = p8;
-    p->idProduct = p9;
-    p->bcdDevice = p10;
-    p->iManufacturer = p11;
-    p->iProduct = p12;
-    p->iSerialNumber = p13;
-    p->bNumConfigurations = p14;
-}
-
-void hs2c_libusb_endpoint_descriptor (struct libusb_endpoint_descriptor *p,
-    uint8_t p1,
-    uint8_t p2,
-    uint8_t p3,
-    uint8_t p4,
-    uint16_t p5,
-    uint8_t p6,
-    uint8_t p7,
-    uint8_t p8,
-    const unsigned char *p9,
-    int p10)
-{
-    p->bLength = p1;
-    p->bDescriptorType = p2;
-    p->bEndpointAddress = p3;
-    p->bmAttributes = p4;
-    p->wMaxPacketSize = p5;
-    p->bInterval = p6;
-    p->bRefresh = p7;
-    p->bSynchAddress = p8;
-    p->extra = p9;
-    p->extra_length = p10;
-}
-
-void hs2c_libusb_interface_descriptor (struct libusb_interface_descriptor *p,
-    uint8_t p1,
-    uint8_t p2,
-    uint8_t p3,
-    uint8_t p4,
-    uint8_t p5,
-    uint8_t p6,
-    uint8_t p7,
-    uint8_t p8,
-    uint8_t p9,
-    struct libusb_endpoint_descriptor *p10,
-    const unsigned char *p11,
-    int p12)
-{
-    p->bLength = p1;
-    p->bDescriptorType = p2;
-    p->bInterfaceNumber = p3;
-    p->bAlternateSetting = p4;
-    p->bNumEndpoints = p5;
-    p->bInterfaceClass = p6;
-    p->bInterfaceSubClass = p7;
-    p->bInterfaceProtocol = p8;
-    p->iInterface = p9;
-    p->endpoint = p10;
-    p->extra = p11;
-    p->extra_length = p12;
-}
-
-void hs2c_libusb_interface (struct libusb_interface *p,
-    struct libusb_interface_descriptor *p1,
-    int p2)
-{
-    p->altsetting = p1;
-    p->num_altsetting = p2;
-}
-
-void hs2c_libusb_config_descriptor (struct libusb_config_descriptor *p,
-    uint8_t p1,
-    uint8_t p2,
-    uint16_t p3,
-    uint8_t p4,
-    uint8_t p5,
-    uint8_t p6,
-    uint8_t p7,
-    uint8_t p8,
-    struct libusb_interface *p9,
-    const unsigned char *p10,
-    int p11)
-{
-    p->bLength = p1;
-    p->bDescriptorType = p2;
-    p->wTotalLength = p3;
-    p->bNumInterfaces = p4;
-    p->bConfigurationValue = p5;
-    p->iConfiguration = p6;
-    p->bmAttributes = p7;
-    p->MaxPower = p8;
-    p->interface = p9;
-    p->extra = p10;
-    p->extra_length = p11;
-}
-
-void hs2c_libusb_control_setup (
-struct libusb_control_setup *p,
-    uint8_t p1,
-    uint8_t p2,
-    uint16_t p3,
-    uint16_t p4,
-    uint16_t p5)
-{
-    p->bmRequestType = p1;
-    p->bRequest = p2;
-    p->wValue = p3;
-    p->wIndex = p4;
-    p->wLength = p5;
-}
-
-void hs2c_libusb_iso_packet_descriptor (
-struct libusb_iso_packet_descriptor *p,
-    unsigned int p1,
-    unsigned int p2,
-    enum libusb_transfer_status p3)
-{
-    p->length = p1;
-    p->actual_length = p2;
-    p->status = p3;
-}
-
-void hs2c_libusb_transfer (struct libusb_transfer *p,
-    libusb_device_handle *p1,
-    uint8_t p2,
-    unsigned char p3,
-    unsigned char p4,
-    unsigned int p5,
-    enum libusb_transfer_status p6,
-    int p7,
-    int p8,
-    libusb_transfer_cb_fn p9,
-    void *p10,
-    unsigned char *p11,
-    int p12)
-{
-    p->dev_handle = p1;
-    p->flags = p2;
-    p->endpoint = p3;
-    p->type = p4;
-    p->timeout = p5;
-    p->status = p6;
-    p->length = p7;
-    p->actual_length = p8;
-    p->callback = p9;
-    p->user_data = p10;
-    p->buffer = p11;
-    p->num_iso_packets = p12;
-}
-
-void hs2c_libusb_pollfd (struct libusb_pollfd *p,
-    int p1,
-    short p2)
-{
-    p->fd = p1;
-    p->events = p2;
-}
-
-/*
-  Functions that read the values of
-  a C struct into pointers. They will
-  be used at 'peek' method of Storable
-  instances.
-*/
-
-void c2hs_libusb_device_descriptor (struct libusb_device_descriptor *p,
-    uint8_t *p1,
-    uint8_t *p2,
-    uint16_t *p3,
-    uint8_t *p4,
-    uint8_t *p5,
-    uint8_t *p6,
-    uint8_t *p7,
-    uint16_t *p8,
-    uint16_t *p9,
-    uint16_t *p10,
-    uint8_t *p11,
-    uint8_t *p12,
-    uint8_t *p13,
-    uint8_t *p14)
-{
-    *p1 = p->bLength;
-    *p2 = p->bDescriptorType;
-    *p3 = p->bcdUSB;
-    *p4 = p->bDeviceClass;
-    *p5 = p->bDeviceSubClass;
-    *p6 = p->bDeviceProtocol;
-    *p7 = p->bMaxPacketSize0;
-    *p8 = p->idVendor;
-    *p9 = p->idProduct;
-    *p10 = p->bcdDevice;
-    *p11 = p->iManufacturer;
-    *p12 = p->iProduct;
-    *p13 = p->iSerialNumber;
-    *p14 = p->bNumConfigurations;
-}
-
-void c2hs_libusb_endpoint_descriptor (
-struct libusb_endpoint_descriptor *p,
-    uint8_t *p1,
-    uint8_t *p2,
-    uint8_t *p3,
-    uint8_t *p4,
-    uint16_t *p5,
-    uint8_t *p6,
-    uint8_t *p7,
-    uint8_t *p8,
-    const unsigned char **p9,
-    int *p10)
-{
-    *p1 = p->bLength;
-    *p2 = p->bDescriptorType;
-    *p3 = p->bEndpointAddress;
-    *p4 = p->bmAttributes;
-    *p5 = p->wMaxPacketSize;
-    *p6 = p->bInterval;
-    *p7 = p->bRefresh;
-    *p8 = p->bSynchAddress;
-    *p9 = p->extra;
-    *p10 = p->extra_length;
-}
-
-void c2hs_libusb_interface_descriptor (
-struct libusb_interface_descriptor *p,
-    uint8_t *p1,
-    uint8_t *p2,
-    uint8_t *p3,
-    uint8_t *p4,
-    uint8_t *p5,
-    uint8_t *p6,
-    uint8_t *p7,
-    uint8_t *p8,
-    uint8_t *p9,
-    const struct libusb_endpoint_descriptor **p10,
-    const unsigned char **p11,
-    int *p12)
-{
-    *p1 = p->bLength;
-    *p2 = p->bDescriptorType;
-    *p3 = p->bInterfaceNumber;
-    *p4 = p->bAlternateSetting;
-    *p5 = p->bNumEndpoints;
-    *p6 = p->bInterfaceClass;
-    *p7 = p->bInterfaceSubClass;
-    *p8 = p->bInterfaceProtocol;
-    *p9 = p->iInterface;
-    *p10 = p->endpoint;
-    *p11 = p->extra;
-    *p12 = p->extra_length;
-}
-
-void c2hs_libusb_interface (struct libusb_interface *p,
-    const struct libusb_interface_descriptor **p1,
-    int *p2)
-{
-    *p1 = p->altsetting;
-    *p2 = p->num_altsetting;
-}
-
-void c2hs_libusb_config_descriptor (struct libusb_config_descriptor *p,
-    uint8_t *p1,
-    uint8_t *p2,
-    uint16_t *p3,
-    uint8_t *p4,
-    uint8_t *p5,
-    uint8_t *p6,
-    uint8_t *p7,
-    uint8_t *p8,
-    const struct libusb_interface **p9,
-    const unsigned char **p10,
-    int *p11)
-{
-    *p1 = p->bLength;
-    *p2 = p->bDescriptorType;
-    *p3 = p->wTotalLength;
-    *p4 = p->bNumInterfaces;
-    *p5 = p->bConfigurationValue;
-    *p6 = p->iConfiguration;
-    *p7 = p->bmAttributes;
-    *p8 = p->MaxPower;
-    *p9 = p->interface;
-    *p10 = p->extra;
-    *p11 = p->extra_length;
-}
-
-void c2hs_libusb_control_setup (struct libusb_control_setup *p,
-    uint8_t *p1,
-    uint8_t *p2,
-    uint16_t *p3,
-    uint16_t *p4,
-    uint16_t *p5)
-{
-    *p1 = p->bmRequestType;
-    *p2 = p->bRequest;
-    *p3 = p->wValue;
-    *p4 = p->wIndex;
-    *p5 = p->wLength;
-}
-
-void c2hs_libusb_iso_packet_descriptor (
-struct libusb_iso_packet_descriptor *p,
-    unsigned int *p1,
-    unsigned int *p2,
-    enum libusb_transfer_status *p3)
-{
-    *p1 = p->length;
-    *p2 = p->actual_length;
-    *p3 = p->status;
-}
-
-void c2hs_libusb_transfer (struct libusb_transfer *p,
-    libusb_device_handle **p1,
-    uint8_t *p2,
-    unsigned char *p3,
-    unsigned char *p4,
-    unsigned int *p5,
-    enum libusb_transfer_status *p6,
-    int *p7,
-    int *p8,
-    libusb_transfer_cb_fn *p9,
-    void **p10,
-    unsigned char **p11,
-    int *p12)
-{
-    *p1 = p->dev_handle;
-    *p2 = p->flags;
-    *p3 = p->endpoint;
-    *p4 = p->type;
-    *p5 = p->timeout;
-    *p6 = p->status;
-    *p7 = p->length;
-    *p8 = p->actual_length;
-    *p9 = p->callback;
-    *p10 = p->user_data;
-    *p11 = p->buffer;
-    *p12 = p->num_iso_packets;
-}
-
-void c2hs_libusb_pollfd (struct libusb_pollfd *p,
-    int *p1,
-    short *p2)
-{
-    *p1 = p->fd;
-    *p2 = p->events;
-}
-
