PORTING 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. PORTING LIBUSB TO OTHER PLATFORMS
  2. Introduction
  3. ============
  4. This document is aimed at developers wishing to port libusb to unsupported
  5. platforms. I believe the libusb API is OS-independent, so by supporting
  6. multiple operating systems we pave the way for cross-platform USB device
  7. drivers.
  8. Implementation-wise, the basic idea is that you provide an interface to
  9. libusb's internal "backend" API, which performs the appropriate operations on
  10. your target platform.
  11. In terms of USB I/O, your backend provides functionality to submit
  12. asynchronous transfers (synchronous transfers are implemented in the higher
  13. layers, based on the async interface). Your backend must also provide
  14. functionality to cancel those transfers.
  15. Your backend must also provide an event handling function to "reap" ongoing
  16. transfers and process their results.
  17. The backend must also provide standard functions for other USB operations,
  18. e.g. setting configuration, obtaining descriptors, etc.
  19. File descriptors for I/O polling
  20. ================================
  21. For libusb to work, your event handling function obviously needs to be called
  22. at various points in time. Your backend must provide a set of file descriptors
  23. which libusb and its users can pass to poll() or select() to determine when
  24. it is time to call the event handling function.
  25. On Linux, this is easy: the usbfs kernel interface exposes a file descriptor
  26. which can be passed to poll(). If something similar is not true for your
  27. platform, you can emulate this using an internal library thread to reap I/O as
  28. necessary, and a pipe() with the main library to raise events. The file
  29. descriptor of the pipe can then be provided to libusb as an event source.
  30. Interface semantics and documentation
  31. =====================================
  32. Documentation of the backend interface can be found in libusbi.h inside the
  33. usbi_os_backend structure definition.
  34. Your implementations of these functions will need to call various internal
  35. libusb functions, prefixed with "usbi_". Documentation for these functions
  36. can be found in the .c files where they are implemented.
  37. You probably want to skim over *all* the documentation before starting your
  38. implementation. For example, you probably need to allocate and store private
  39. OS-specific data for device handles, but the documentation for the mechanism
  40. for doing so is probably not the first thing you will see.
  41. The Linux backend acts as a good example - view it as a reference
  42. implementation which you should try to match the behaviour of.
  43. Getting started
  44. ===============
  45. 1. Modify configure.ac to detect your platform appropriately (see the OS_LINUX
  46. stuff for an example).
  47. 2. Implement your backend in the libusb/os/ directory, modifying
  48. libusb/os/Makefile.am appropriately.
  49. 3. Add preprocessor logic to the top of libusb/core.c to statically assign the
  50. right usbi_backend for your platform.
  51. 4. Produce and test your implementation.
  52. 5. Send your implementation to libusb-devel mailing list.
  53. Implementation difficulties? Questions?
  54. =======================================
  55. If you encounter difficulties porting libusb to your platform, please raise
  56. these issues on the libusb-devel mailing list. Where possible and sensible, I
  57. am interested in solving problems preventing libusb from operating on other
  58. platforms.
  59. The libusb-devel mailing list is also a good place to ask questions and
  60. make suggestions about the internal API. Hopefully we can produce some
  61. better documentation based on your questions and other input.
  62. You are encouraged to get involved in the process; if the library needs
  63. some infrastructure additions/modifications to better support your platform,
  64. you are encouraged to make such changes (in cleanly distinct patch
  65. submissions). Even if you do not make such changes yourself, please do raise
  66. the issues on the mailing list at the very minimum.