README.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. HIDAPI library for Windows, Linux, FreeBSD and Mac OS X
  2. =========================================================
  3. About
  4. ======
  5. HIDAPI is a multi-platform library which allows an application to interface
  6. with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and Mac
  7. OS X. HIDAPI can be either built as a shared library (.so or .dll) or
  8. can be embedded directly into a target application by adding a single source
  9. file (per platform) and a single header.
  10. HIDAPI has four back-ends:
  11. * Windows (using hid.dll)
  12. * Linux/hidraw (using the Kernel's hidraw driver)
  13. * Linux/libusb (using libusb-1.0)
  14. * FreeBSD (using libusb-1.0)
  15. * Mac (using IOHidManager)
  16. On Linux, either the hidraw or the libusb back-end can be used. There are
  17. tradeoffs, and the functionality supported is slightly different.
  18. Linux/hidraw (linux/hid.c):
  19. This back-end uses the hidraw interface in the Linux kernel. While this
  20. back-end will support both USB and Bluetooth, it has some limitations on
  21. kernels prior to 2.6.39, including the inability to send or receive feature
  22. reports. In addition, it will only communicate with devices which have
  23. hidraw nodes associated with them. Keyboards, mice, and some other devices
  24. which are blacklisted from having hidraw nodes will not work. Fortunately,
  25. for nearly all the uses of hidraw, this is not a problem.
  26. Linux/FreeBSD/libusb (libusb/hid-libusb.c):
  27. This back-end uses libusb-1.0 to communicate directly to a USB device. This
  28. back-end will of course not work with Bluetooth devices.
  29. HIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses
  30. Fox Toolkit (http://www.fox-toolkit.org). It will build on every platform
  31. which HIDAPI supports. Since it relies on a 3rd party library, building it
  32. is optional but recommended because it is so useful when debugging hardware.
  33. What Does the API Look Like?
  34. =============================
  35. The API provides the the most commonly used HID functions including sending
  36. and receiving of input, output, and feature reports. The sample program,
  37. which communicates with a heavily hacked up version of the Microchip USB
  38. Generic HID sample looks like this (with error checking removed for
  39. simplicity):
  40. #ifdef WIN32
  41. #include <windows.h>
  42. #endif
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include "hidapi.h"
  46. #define MAX_STR 255
  47. int main(int argc, char* argv[])
  48. {
  49. int res;
  50. unsigned char buf[65];
  51. wchar_t wstr[MAX_STR];
  52. hid_device *handle;
  53. int i;
  54. // Initialize the hidapi library
  55. res = hid_init();
  56. // Open the device using the VID, PID,
  57. // and optionally the Serial number.
  58. handle = hid_open(0x4d8, 0x3f, NULL);
  59. // Read the Manufacturer String
  60. res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
  61. wprintf(L"Manufacturer String: %s\n", wstr);
  62. // Read the Product String
  63. res = hid_get_product_string(handle, wstr, MAX_STR);
  64. wprintf(L"Product String: %s\n", wstr);
  65. // Read the Serial Number String
  66. res = hid_get_serial_number_string(handle, wstr, MAX_STR);
  67. wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);
  68. // Read Indexed String 1
  69. res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
  70. wprintf(L"Indexed String 1: %s\n", wstr);
  71. // Toggle LED (cmd 0x80). The first byte is the report number (0x0).
  72. buf[0] = 0x0;
  73. buf[1] = 0x80;
  74. res = hid_write(handle, buf, 65);
  75. // Request state (cmd 0x81). The first byte is the report number (0x0).
  76. buf[0] = 0x0;
  77. buf[1] = 0x81;
  78. res = hid_write(handle, buf, 65);
  79. // Read requested state
  80. res = hid_read(handle, buf, 65);
  81. // Print out the returned buffer.
  82. for (i = 0; i < 4; i++)
  83. printf("buf[%d]: %d\n", i, buf[i]);
  84. // Finalize the hidapi library
  85. res = hid_exit();
  86. return 0;
  87. }
  88. If you have your own simple test programs which communicate with standard
  89. hardware development boards (such as those from Microchip, TI, Atmel,
  90. FreeScale and others), please consider sending me something like the above
  91. for inclusion into the HIDAPI source. This will help others who have the
  92. same hardware as you do.
  93. License
  94. ========
  95. HIDAPI may be used by one of three licenses as outlined in LICENSE.txt.
  96. Download
  97. =========
  98. HIDAPI can be downloaded from github
  99. git clone git://github.com/signal11/hidapi.git
  100. Build Instructions
  101. ===================
  102. This section is long. Don't be put off by this. It's not long because it's
  103. complicated to build HIDAPI; it's quite the opposite. This section is long
  104. because of the flexibility of HIDAPI and the large number of ways in which
  105. it can be built and used. You will likely pick a single build method.
  106. HIDAPI can be built in several different ways. If you elect to build a
  107. shared library, you will need to build it from the HIDAPI source
  108. distribution. If you choose instead to embed HIDAPI directly into your
  109. application, you can skip the building and look at the provided platform
  110. Makefiles for guidance. These platform Makefiles are located in linux/
  111. libusb/ mac/ and windows/ and are called Makefile-manual. In addition,
  112. Visual Studio projects are provided. Even if you're going to embed HIDAPI
  113. into your project, it is still beneficial to build the example programs.
  114. Prerequisites:
  115. ---------------
  116. Linux:
  117. -------
  118. On Linux, you will need to install development packages for libudev,
  119. libusb and optionally Fox-toolkit (for the test GUI). On
  120. Debian/Ubuntu systems these can be installed by running:
  121. sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev
  122. If you downloaded the source directly from the git repository (using
  123. git clone), you'll need Autotools:
  124. sudo apt-get install autotools-dev autoconf automake libtool
  125. FreeBSD:
  126. ---------
  127. On FreeBSD you will need to install GNU make, libiconv, and
  128. optionally Fox-Toolkit (for the test GUI). This is done by running
  129. the following:
  130. pkg_add -r gmake libiconv fox16
  131. If you downloaded the source directly from the git repository (using
  132. git clone), you'll need Autotools:
  133. pkg_add -r autotools
  134. Mac:
  135. -----
  136. On Mac, you will need to install Fox-Toolkit if you wish to build
  137. the Test GUI. There are two ways to do this, and each has a slight
  138. complication. Which method you use depends on your use case.
  139. If you wish to build the Test GUI just for your own testing on your
  140. own computer, then the easiest method is to install Fox-Toolkit
  141. using ports:
  142. sudo port install fox
  143. If you wish to build the TestGUI app bundle to redistribute to
  144. others, you will need to install Fox-toolkit from source. This is
  145. because the version of fox that gets installed using ports uses the
  146. ports X11 libraries which are not compatible with the Apple X11
  147. libraries. If you install Fox with ports and then try to distribute
  148. your built app bundle, it will simply fail to run on other systems.
  149. To install Fox-Toolkit manually, download the source package from
  150. http://www.fox-toolkit.org, extract it, and run the following from
  151. within the extracted source:
  152. ./configure && make && make install
  153. Windows:
  154. ---------
  155. On Windows, if you want to build the test GUI, you will need to get
  156. the hidapi-externals.zip package from the download site. This
  157. contains pre-built binaries for Fox-toolkit. Extract
  158. hidapi-externals.zip just outside of hidapi, so that
  159. hidapi-externals and hidapi are on the same level, as shown:
  160. Parent_Folder
  161. |
  162. +hidapi
  163. +hidapi-externals
  164. Again, this step is not required if you do not wish to build the
  165. test GUI.
  166. Building HIDAPI into a shared library on Unix Platforms:
  167. ---------------------------------------------------------
  168. On Unix-like systems such as Linux, FreeBSD, Mac, and even Windows, using
  169. Mingw or Cygwin, the easiest way to build a standard system-installed shared
  170. library is to use the GNU Autotools build system. If you checked out the
  171. source from the git repository, run the following:
  172. ./bootstrap
  173. ./configure
  174. make
  175. make install <----- as root, or using sudo
  176. If you downloaded a source package (ie: if you did not run git clone), you
  177. can skip the ./bootstrap step.
  178. ./configure can take several arguments which control the build. The two most
  179. likely to be used are:
  180. --enable-testgui
  181. Enable build of the Test GUI. This requires Fox toolkit to
  182. be installed. Instructions for installing Fox-Toolkit on
  183. each platform are in the Prerequisites section above.
  184. --prefix=/usr
  185. Specify where you want the output headers and libraries to
  186. be installed. The example above will put the headers in
  187. /usr/include and the binaries in /usr/lib. The default is to
  188. install into /usr/local which is fine on most systems.
  189. Building the manual way on Unix platforms:
  190. -------------------------------------------
  191. Manual Makefiles are provided mostly to give the user and idea what it takes
  192. to build a program which embeds HIDAPI directly inside of it. These should
  193. really be used as examples only. If you want to build a system-wide shared
  194. library, use the Autotools method described above.
  195. To build HIDAPI using the manual makefiles, change to the directory
  196. of your platform and run make. For example, on Linux run:
  197. cd linux/
  198. make -f Makefile-manual
  199. To build the Test GUI using the manual makefiles:
  200. cd testgui/
  201. make -f Makefile-manual
  202. Building on Windows:
  203. ---------------------
  204. To build the HIDAPI DLL on Windows using Visual Studio, build the .sln file
  205. in the windows/ directory.
  206. To build the Test GUI on windows using Visual Studio, build the .sln file in
  207. the testgui/ directory.
  208. To build HIDAPI using MinGW or Cygwin using Autotools, use the instructions
  209. in the section titled "Building HIDAPI into a shared library on Unix
  210. Platforms" above. Note that building the Test GUI with MinGW or Cygwin will
  211. require the Windows procedure in the Prerequisites section above (ie:
  212. hidapi-externals.zip).
  213. To build HIDAPI using MinGW using the Manual Makefiles, see the section
  214. "Building the manual way on Unix platforms" above.
  215. HIDAPI can also be built using the Windows DDK (now also called the Windows
  216. Driver Kit or WDK). This method was originally required for the HIDAPI build
  217. but not anymore. However, some users still prefer this method. It is not as
  218. well supported anymore but should still work. Patches are welcome if it does
  219. not. To build using the DDK:
  220. 1. Install the Windows Driver Kit (WDK) from Microsoft.
  221. 2. From the Start menu, in the Windows Driver Kits folder, select Build
  222. Environments, then your operating system, then the x86 Free Build
  223. Environment (or one that is appropriate for your system).
  224. 3. From the console, change directory to the windows/ddk_build/ directory,
  225. which is part of the HIDAPI distribution.
  226. 4. Type build.
  227. 5. You can find the output files (DLL and LIB) in a subdirectory created
  228. by the build system which is appropriate for your environment. On
  229. Windows XP, this directory is objfre_wxp_x86/i386.
  230. Cross Compiling
  231. ================
  232. This section talks about cross compiling HIDAPI for Linux using autotools.
  233. This is useful for using HIDAPI on embedded Linux targets. These
  234. instructions assume the most raw kind of embedded Linux build, where all
  235. prerequisites will need to be built first. This process will of course vary
  236. based on your embedded Linux build system if you are using one, such as
  237. OpenEmbedded or Buildroot.
  238. For the purpose of this section, it will be assumed that the following
  239. environment variables are exported.
  240. $ export STAGING=$HOME/out
  241. $ export HOST=arm-linux
  242. STAGING and HOST can be modified to suit your setup.
  243. Prerequisites
  244. --------------
  245. Note that the build of libudev is the very basic configuration.
  246. Build Libusb. From the libusb source directory, run:
  247. ./configure --host=$HOST --prefix=$STAGING
  248. make
  249. make install
  250. Build libudev. From the libudev source directory, run:
  251. ./configure --disable-gudev --disable-introspection --disable-hwdb \
  252. --host=$HOST --prefix=$STAGING
  253. make
  254. make install
  255. Building HIDAPI
  256. ----------------
  257. Build HIDAPI:
  258. PKG_CONFIG_DIR= \
  259. PKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \
  260. PKG_CONFIG_SYSROOT_DIR=$STAGING \
  261. ./configure --host=$HOST --prefix=$STAGING
  262. Signal 11 Software - 2010-04-11
  263. 2010-07-28
  264. 2011-09-10
  265. 2012-05-01
  266. 2012-07-03