Skip to content

Commit

Permalink
Merge pull request #3 from coseltech/master
Browse files Browse the repository at this point in the history
Added usb-control-msg and constantenums
  • Loading branch information
soemraws committed Feb 4, 2016
2 parents f6bf655 + 681703d commit db37ded
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cl-libusb.lisp
Expand Up @@ -164,6 +164,9 @@
(libusb-ffi:usb-interrupt-write (usb-handle-pointer device)
endpoint buffer timeout))

(defun usb-control-msg (device requesttype request value index buffer timeout)
(libusb-ffi:usb-control-msg (usb-handle-pointer device) requesttype request value index buffer timeout))

(defun usb-clear-halt (device endpoint)
"Clear the halt flag on the given endpoint of the device."
(libusb-ffi:usb-clear-halt (usb-handle-pointer device) endpoint))
21 changes: 21 additions & 0 deletions libusb-ffi.lisp
Expand Up @@ -104,6 +104,16 @@
(size :int)
(timeout :int))

(defcfun (usb-control-msg* "usb_control_msg") :int
(handle device-handle-ptr)
(requesttype :int)
(request :int)
(value :int)
(index :int)
(bytes :pointer)
(size :int)
(timeout :int))

;;;; Somewhat cleaned up interface

;;; Errors
Expand Down Expand Up @@ -428,6 +438,17 @@
(error 'libusb-error :text "Interrupt read failed.")
(grid:slice buffer `((:range 0 ,(- bytes-read 1)))))))

(defun usb-control-msg (handle requesttype request value index buffer timeout)
(let* ((bytes-to-write (grid:dim0 buffer))
(bytes-written
(usb-control-msg* handle requesttype request value index
(grid::foreign-pointer buffer)
bytes-to-write timeout)))
(if (< bytes-written 0)
(error 'libusb-error :text "Control message failed.")
bytes-written)))


(defun endpoint-in-p (endpoint)
"Check if an endpoint is an in endpoint (and thus can be read from)."
(unless (integerp endpoint)
Expand Down
29 changes: 29 additions & 0 deletions libusb-grovel.lisp
Expand Up @@ -38,6 +38,35 @@
((:endpoint-audio "USB_DT_ENDPOINT_AUDIO_SIZE"))
((:hub-nonvar "USB_DT_HUB_NONVAR_SIZE")))

(constantenum request
((:get-status "USB_REQ_GET_STATUS"))
((:clear-feature "USB_REQ_CLEAR_FEATURE"))
((:set-feature "USB_REQ_SET_FEATURE"))
((:set-address "USB_REQ_SET_ADDRESS"))
((:get-descriptor "USB_REQ_GET_DESCRIPTOR"))
((:set-descriptor "USB_REQ_SET_DESCRIPTOR"))
((:get-configuration "USB_REQ_GET_CONFIGURATION"))
((:set-configuration "USB_REQ_SET_CONFIGURATION"))
((:get-interface "USB_REQ_GET_INTERFACE"))
((:set-interface "USB_REQ_SET_INTERFACE"))
((:synch-frame "USB_REQ_SYNCH_FRAME")))

(constantenum type
((:standard "USB_TYPE_STANDARD"))
((:class "USB_TYPE_CLASS"))
((:vendor "USB_TYPE_VENDOR"))
((:reserved "USB_TYPE_RESERVED")))

(constantenum recip
((:device "USB_RECIP_DEVICE"))
((:interface "USB_RECIP_INTERFACE"))
((:endpoint "USB_RECIP_ENDPOINT"))
((:other "USB_RECIP_OTHER")))

(constantenum endpoint
((:in "USB_ENDPOINT_IN"))
((:out "USB_ENDPOINT_OUT")))

(cstruct bus "struct usb_bus"
(next "next" :type :pointer)
(previous "prev" :type :pointer)
Expand Down
2 changes: 2 additions & 0 deletions package.lisp
Expand Up @@ -29,6 +29,7 @@
#:usb-bulk-write
#:usb-interrupt-read
#:usb-interrupt-write
#:usb-control-msg

#:usb-claim-interface
#:usb-release-interface
Expand All @@ -55,6 +56,7 @@
#:usb-bulk-write
#:usb-interrupt-read
#:usb-interrupt-write
#:usb-control-msg

#:usb-get-vendor-id
#:usb-get-product-id
Expand Down

0 comments on commit db37ded

Please sign in to comment.