Permalink
Browse files

Added usb-control-msg and constenums

  • Loading branch information...
1 parent f6bf655 commit 681703d04fe2a6d71ef4ec2eaff2cacfc16ef1cf Michael Kuijn committed Jan 7, 2016
Showing with 55 additions and 0 deletions.
  1. +3 −0 cl-libusb.lisp
  2. +21 −0 libusb-ffi.lisp
  3. +29 −0 libusb-grovel.lisp
  4. +2 −0 package.lisp
View
@@ -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))
View
@@ -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
@@ -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)
View
@@ -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)
View
@@ -29,6 +29,7 @@
#:usb-bulk-write
#:usb-interrupt-read
#:usb-interrupt-write
+ #:usb-control-msg
#:usb-claim-interface
#:usb-release-interface
@@ -55,6 +56,7 @@
#:usb-bulk-write
#:usb-interrupt-read
#:usb-interrupt-write
+ #:usb-control-msg
#:usb-get-vendor-id
#:usb-get-product-id

0 comments on commit 681703d

Please sign in to comment.