3

I am getting started with coding for HID devices. I got started with reading Apple documents and sample code. The code provided are terribly outdated that it doesn't even open in Xcode8.

Download Sample Code from Apple

I need help in finding a sample project / snippet for getting started with HID Services! Open a handle, read and write reports to device, Listen to reports generated by device in a run loop.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
matt007
  • 304
  • 3
  • 16

1 Answers1

6

OS X/macOS's HID stack is called IOHIDFamily, and much of it is open source. This includes kernel and userspace components. You can find the code for various different OS X/macOS releases at

https://opensource.apple.com/

For 10.12.2 (latest code released at time of writing) you can browse the IOHIDFamily code here:

https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-870.31.1/

or download it as a zip file here:

https://opensource.apple.com/tarballs/IOHIDFamily/IOHIDFamily-870.31.1.tar.gz

The "tools" directory contains some userspace sample/test code which might help with what you're trying to do.

As for sample code not being updated, documentation being incomplete/outdated/missing, and provided code requiring a lot of effort to build: welcome to Mac systems & driver development. That's unfortunately how it is. I've been doing OS X kernel/driver work for 7 years, and while some things get easier with experience, downloading code from Apple and building it still feels like playing the lottery.

pmdj
  • 22,018
  • 3
  • 52
  • 103