[fpc-pascal] USB Human Interface Devices
James Richters
james at productionautomation.net
Mon Aug 12 01:13:06 CEST 2019
Thank you for the help. I made most of the changes you recommend and I was able to get it to compile, the only one I had trouble with was
If I take out the ^ from:
if (EP^.bmAttributes and LIBUSB_TRANSFER_TYPE_MASK =
LIBUSB_TRANSFER_TYPE_INTERRUPT) and
(EP^.bEndpointAddress and LIBUSB_ENDPOINT_DIR_MASK <> 0) then
So it looks like this:
if (EP.bmAttributes and LIBUSB_TRANSFER_TYPE_MASK =
LIBUSB_TRANSFER_TYPE_INTERRUPT) and
(EP.bEndpointAddress and LIBUSB_ENDPOINT_DIR_MASK <> 0) then
I get a compiler error:
libusboop.pas(1168,14) Error: Illegal qualifier
libusboop.pas(1168,14) Fatal: Syntax error, ")" expected but "identifier BMATTRIBUTES" found
libusboop.pas(0) Fatal: Compilation aborted
With the ^ in it compiles anyway... I don't know how to adjust the format to not have the ^
I have not tried to do anything with TLibUsbPseudoHIDInterface yet, I was just trying to get libusboop.pas to compile, and be able to still run the previous examples.
I've updated my repository at https://github.com/Zaaphod/pas-libusb/tree/Test
Let me know if I should do something different with the ^ above, or if you see anything else I missed.
James
-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Johann Glaser
Sent: Sunday, August 11, 2019 4:16 PM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] USB Human Interface Devices
Hi!
Am Samstag, den 10.08.2019, 17:50 -0400 schrieb James Richters:
> I'm making an attempt to copy TUSBPseudoHIDInterface into
> libusboop.pas. I've made the recomended name changes and then tried
> to compile it. Some things I found like the names changing from
> things like
>
> PUSBInterfaceDescriptop to Plibusb_interface_descriptor
OK, there are two things. Names directly from libusb-1.0 (as used in
libusb.pas) should be identical to the original C code, i.e., Plibusb_interface_descriptor as you've written.
The second thing are the classes in the OOP wrapper in libusboop.pas.
Please use CamelCase for them, e.g., TLibusbPseudoHIDInterface.
> are pretty obvious, but just taking a guess on other things like:
>
> changing:
> if (EP.bmAttributes and USB_ENDPOINT_TYPE_MASK =
> USB_ENDPOINT_TYPE_INTERRUPT) and
> (EP.bEndpointAddress and USB_ENDPOINT_DIR_MASK <> 0) then
>
> To:
> if (EP^.bmAttributes and LIBUSB_TRANSFER_TYPE_MASK =
> LIBUSB_TRANSFER_TYPE_INTERRUPT) and
> (EP^.bEndpointAddress and LIBUSB_ENDPOINT_DIR_MASK <> 0) then
Yes, very good, thanks!
Whether EP is a pointer (--> EP^.bmAttributes) or a record
(EP.bmAttributs) just depends on the usage in the code. As I see in usb.pas in line 846, in TUSBPseudoHIDInterface.Create, it is actually the record, so you should stay without the '^'.
> Based on looking at something similar in libusbutil... but I'm not
> sure it's right at all.... I'm not sure if USB_ENDPOINT_TYPE_MASK was
> really changed to LIBUSB_TRANSFER_TYPE_MASK or if something else
> happened. But at least it compiles...
You translated it correctly.
> but now I've hit a few items that I just don't know what to do
> with. I can't find anything similar to get a reference from:
>
> libusboop.pas(1198,28) Error: Identifier not found "USB_TYPE_CLASS"
Use LIBUSB_REQUEST_TYPE_CLASS.
> libusboop.pas(1199,5) Error: Identifier not found
> "USB_REQ_HID_SET_REPORT"
> libusboop.pas(1216,27) Error: Identifier not found "USB_TYPE_CLASS"
> libusboop.pas(1217,5) Error: Identifier not found
> "USB_REQ_HID_GET_REPORT"
> libusboop.pas(1227,23) Error: Identifier not found
> "HID_REPORT_TYPE_OUTPUT"
Please copy the constants USB_REQ_HID_* and HID_REPORT_* from libusb.pas (branch master) lines 248-257 to the interface section of libusboop.pas (branch libusb-1.0) directly above the class declaration of TLibusbPseudoHIDInterface. Then please rename USB_REQ_HID_* to
LIBUSB_REQUEST_HID_* and HID_REPORT_* to LIBUSB_HID_REPORT_*.
> I've tried things that seem to be in line with other changes, like
> changing USB_Type_Class to LIBUSB_TYPE_CLASS or spelling out REQUEST
> instead of REQ which also seems to be done in other places, but still
> the identifiers are not found... the problem is I have no idea where
> these identifiers were/are defined.
>
> I made a fork in github and a branch called "test" here:
> https://github.com/Zaaphod/pas-libusb/tree/Test
Great approach, thanks, then we can use pull requests.
Thanks
Hansi
> > Actually you could copy the class TUSBPseudoHIDInterface (plus the
> > types THIDReport and TIntrReportFunc) from usb.pas to libusboop.pas
> > and change everything necessary.
> > At least one difference is that all names change from TUSB* to
> > TLibUsb*. I'm sure there are more, but I don't know by heart.
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list