Re: Recommendations for programming HID in FreeBSD 9
On 06/04/12 01:29, Engineering wrote: if (id != 0) copyin(ugd-ugd_data,id, 1); error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, imin(ugd-ugd_maxlen, size)); Hans is right. That code should do the trick. Last year I've fixed uhid driver to handle multiple report IDs. Even user-level tools are able to do it now. id != 0 should be correct condition. According to HID spec, if device has at least one non-zero report ID, report ID should be included into any transfer. So now uhid driver assumes that report ID should be in the first byte of request, if it found some non-zero ID in descriptor. Thanks to all for your help, I have it working, and am very happy to be up to date in BSD. For the record, one of my HID had different report IDs AND different report sizes, so I had to add my hack to send the size for it to work correctly. That should also work fine now. uhid driver only enforces maximal transfer sizes calculated from the descriptor. User can request smaller transfers, specifying size in ugd.ugd_maxlen field. Look at hid_(get|set)_report() functions in lib/libusbhid sources. The bonus with that is that my touchscreen, which has badly ported HID code from the original USB firmware, and does not correctly report its report sizes, can also work with uhid. -- Alexander Motin ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
RE: Recommendations for programming HID in FreeBSD 9
if (id != 0) copyin(ugd-ugd_data,id, 1); error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, imin(ugd-ugd_maxlen, size)); Hans is right. That code should do the trick. Last year I've fixed uhid driver to handle multiple report IDs. Even user-level tools are able to do it now. id != 0 should be correct condition. According to HID spec, if device has at least one non-zero report ID, report ID should be included into any transfer. So now uhid driver assumes that report ID should be in the first byte of request, if it found some non-zero ID in descriptor. Thanks to all for your help, I have it working, and am very happy to be up to date in BSD. For the record, one of my HID had different report IDs AND different report sizes, so I had to add my hack to send the size for it to work correctly. The bonus with that is that my touchscreen, which has badly ported HID code from the original USB firmware, and does not correctly report its report sizes, can also work with uhid. Thanks again Sam ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
Re: Recommendations for programming HID in FreeBSD 9
Hi. On 06/01/12 20:10, Engineering wrote: -Original Message- From: Hans Petter Selasky [mailto:hsela...@c2i.net] I think mav @ did some work in that area? Are you sure you cannot use: ... if (id != 0) copyin(ugd-ugd_data,id, 1); error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, imin(ugd-ugd_maxlen, size)); break; That's definitely cleaner, using the ugd fields to denote a special case. I'm not sure about the (id != 0) - I'll need to check my specific devices, but something like: Hans is right. That code should do the trick. Last year I've fixed uhid driver to handle multiple report IDs. Even user-level tools are able to do it now. id != 0 should be correct condition. According to HID spec, if device has at least one non-zero report ID, report ID should be included into any transfer. So now uhid driver assumes that report ID should be in the first byte of request, if it found some non-zero ID in descriptor. -- Alexander Motin ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
Re: Recommendations for programming HID in FreeBSD 9
On Thursday 31 May 2012 18:30:56 Engineering wrote: Hi all, I hope this is the right place to ask this I am in process of migrating an embedded system from BSD 7.0 to 9.0, as we need upgraded video card drivers which will not compile on the old system. To confuse matters a bit, I believe it was 7.0 with some of HPS updated USB stack worked in. The system has 4 HID devices attached, and I need to read data and set feature reports to talk to them. I had been using read() and ioctl() - with the evolution of BSD, is there a different recommended way to do this? I also need open() and to be able to get the usage page, to tell one device from another. If I recall, at the time the uhid driver had problems with devices that had feature reports of varying sizes - I see I hacked it a bit to allow the application to specify the size of the report. Is this still the case? I of course will be looking into this myself, but initial compile gives me the following errors - does this ring a bell to anyone? Thanks, Sam Compiling usbhid.cpp... usbhid.cpp:35: error: 'usb_ctl_report_desc' does not name a type usbhid.cpp: In function 'int hid_set_feature(int, unsigned char*, int)': usbhid.cpp:157: error: 'usb_ctl_report' was not declared in this scope usbhid.cpp:157: error: expected `;' before 'ucr' usbhid.cpp:161: error: 'ucr' was not declared in this scope usbhid.cpp:169: error: invalid application of 'sizeof' to incomplete type 'usb_ctl_report' usbhid.cpp:174: error: 'USB_SET_REPORT' was not declared in this scope usbhid.cpp: In function 'void usbhid_populate_list()': usbhid.cpp:331: error: 'USB_GET_REPORT_DESC' was not declared in this scope usbhid.cpp:331: error: 'struct hid_t' has no member named 'ucrd' usbhid.cpp:334: error: 'struct hid_t' has no member named 'ucrd' usbhid.cpp:336: error: 'struct hid_t' has no member named 'ucrd' usbhid.cpp:337: error: 'struct hid_t' has no member named 'ucrd' *** Error code 1 See: man usbhid Else use LibUSB to access the device. --HPS ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
RE: Recommendations for programming HID in FreeBSD 9
[original post moved to end for brevity - or should I just delete it when replying?] From: Hans Petter Selasky [mailto:hsela...@c2i.net] See: man usbhid Else use LibUSB to access the device. --HPS Thank you for replying I should point out that the usbhid.cpp compile below is my file - I didn't know there was a 'real' usbhid. Usbhid looks great, but it is probably a little higher level than I need. I should mention that the devices I am talking with are a known quantity - I wrote the firmware on some of them, and have extensive datasheets on the rest. I just need to get a usage page, or VID and PID so I can tell which one is which, i.e. who's at uhid0 and who's at uhid3. I had been researching libusb for a while, but their webpage says it is not recommended for HID devices and to use HIDAPI, which does not seem to be on BSD. I saw your version, and it looks great! I wish I had that a few years ago when you helped me with getting an isochronous device working on BSD 7.0. However, due to time constraints, I'd rather not write a HID front end using that if I don't need to. I see uhid is still around - is there any reason not to just use that? I already have cross-platform HID code that used to work with uhid - I suspect my problem might just be that the headers I need have moved or changed. I will grep... According to the uhid man page, these should all still exist somewhere: usbhid.cpp:35: error: 'usb_ctl_report_desc' does not name a type usbhid.cpp:157: error: 'usb_ctl_report' was not declared in this scope usbhid.cpp:174: error: 'USB_SET_REPORT' was not declared in this scope usbhid.cpp:331: error: 'USB_GET_REPORT_DESC' was not declared in this Or is uhid being obsoleted? Thanks Sam On Thursday 31 May 2012 18:30:56 Engineering wrote: Hi all, I hope this is the right place to ask this I am in process of migrating an embedded system from BSD 7.0 to 9.0, as we need upgraded video card drivers which will not compile on the old system. To confuse matters a bit, I believe it was 7.0 with some of HPS updated USB stack worked in. The system has 4 HID devices attached, and I need to read data and set feature reports to talk to them. I had been using read() and ioctl() - with the evolution of BSD, is there a different recommended way to do this? I also need open() and to be able to get the usage page, to tell one device from another. If I recall, at the time the uhid driver had problems with devices that had feature reports of varying sizes - I see I hacked it a bit to allow the application to specify the size of the report. Is this still the case? I of course will be looking into this myself, but initial compile gives me the following errors - does this ring a bell to anyone? Thanks, Sam Compiling usbhid.cpp... usbhid.cpp:35: error: 'usb_ctl_report_desc' does not name a type ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
Re: Recommendations for programming HID in FreeBSD 9
On Fri, Jun 1, 2012 at 9:45 PM, Engineering e...@athyriogames.com wrote: I had been researching libusb for a while, but their webpage says it is not recommended for HID devices and to use HIDAPI, which does not seem to be on BSD. HIDAPI does work under FreeBSD using libusb (1.0 API) as the backend. https://github.com/signal11/hidapi/commit/74440e2dbbba80b4abcc4304ddae9e484231b72d https://github.com/signal11/hidapi/tree/master/libusb -- Xiaofan ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
Re: Recommendations for programming HID in FreeBSD 9
On Friday 01 June 2012 15:45:40 Engineering wrote: [original post moved to end for brevity - or should I just delete it when replying?] Or is uhid being obsoleted? uhid is not going to get obsoleted, though using libraries from user-space is sometimes more convenient. --HPS ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
RE: Recommendations for programming HID in FreeBSD 9
From: Hans Petter Selasky [mailto:hsela...@c2i.net] uhid is not going to get obsoleted, though using libraries from user-space is sometimes more convenient. Thanks HPS (and Xiaofan) I definitely agree with that, but I've got legacy code... Last question - I've updated my code to convert the old 'usb_ctl_report' and such to the new generic descriptors at runtime, and I've got two HIDs up and running. As I read uhid.c, it seems to assume only one feature report ID and size. I have devices that have multiple feature report sizes. And one device which I'm pretty sure has bad device descriptors, so the size is wrong. In the BSD7, I added the following fakery to uhid.c: case USB_SET_REPORTZ: // report id and size are in first two bytes re = (struct usb_ctl_report *)addr; id = re-ucr_data[0]; size = re-ucr_data[1]; err = usbd_set_report(sc-sc_iface, re-ucr_report, id, re-ucr_data[2],size); if (err) { return (EIO); } break; Do you think it would make sense to do this again with the BSD9 uhid.c? If so, is there a way to recompile the kernel so it only updates the uhid part? Pardon my ignorance on that. Sam ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
Re: Recommendations for programming HID in FreeBSD 9
On Friday 01 June 2012 18:12:20 Engineering wrote: From: Hans Petter Selasky [mailto:hsela...@c2i.net] uhid is not going to get obsoleted, though using libraries from user-space is sometimes more convenient. Thanks HPS (and Xiaofan) I definitely agree with that, but I've got legacy code... Last question - I've updated my code to convert the old 'usb_ctl_report' and such to the new generic descriptors at runtime, and I've got two HIDs up and running. As I read uhid.c, it seems to assume only one feature report ID and size. I have devices that have multiple feature report sizes. And one device which I'm pretty sure has bad device descriptors, so the size is wrong. In the BSD7, I added the following fakery to uhid.c: case USB_SET_REPORTZ: // report id and size are in first two bytes re = (struct usb_ctl_report *)addr; id = re-ucr_data[0]; size = re-ucr_data[1]; err = usbd_set_report(sc-sc_iface, re-ucr_report, id, re-ucr_data[2],size); if (err) { return (EIO); } break; Do you think it would make sense to do this again with the BSD9 uhid.c? I think mav @ did some work in that area? Are you sure you cannot use: case USB_SET_REPORT: if (!(fflags FWRITE)) { error = EPERM; break; } ugd = addr; switch (ugd-ugd_report_type) { case UHID_INPUT_REPORT: size = sc-sc_isize; id = sc-sc_iid; break; case UHID_OUTPUT_REPORT: size = sc-sc_osize; id = sc-sc_oid; break; case UHID_FEATURE_REPORT: size = sc-sc_fsize; id = sc-sc_fid; break; default: return (EINVAL); } if (id != 0) copyin(ugd-ugd_data, id, 1); error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, imin(ugd-ugd_maxlen, size)); break; --HPS ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org
RE: Recommendations for programming HID in FreeBSD 9
-Original Message- From: Hans Petter Selasky [mailto:hsela...@c2i.net] I think mav @ did some work in that area? Are you sure you cannot use: ... if (id != 0) copyin(ugd-ugd_data, id, 1); error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, imin(ugd-ugd_maxlen, size)); break; That's definitely cleaner, using the ugd fields to denote a special case. I'm not sure about the (id != 0) - I'll need to check my specific devices, but something like: if(ugd-ugd_config_index) // abusing variables to set a flag, use passed in id and size in lang_id and actlen error = uhid_set_report(sc, ugd-ugd_report_type, ugd-ugd_lang_id, NULL, ugd-ugd_data, ugd-ugd_actlen); else error = uhid_set_report(sc, ugd-ugd_report_type, id, NULL, ugd-ugd_data, size); Would suit my needs well, as long as I remember to zero out ugd_config_index on a normal one! I suppose I need to rebuild the kernel. Thanks for your time and help! Sam ___ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org