Reputation: 314
I have to create a software/driver for OSX that interact with HID device connected through USB. The purposes of the application are as follows,
I am not a driver developer, but have experience in C, C++, Obj C etc. I am wondering what will be the best way to achieve the mentioned objectives. That is should I develop kernel extension (driver) or is there a better alternative?.
The challenges I face are,
Either way, this is a new field for me. Can you please suggest some documents or sample codes, from with I can start.
Also kindly mention forums, or communities which might be helpful in developing device driver for mac.
Thankyou you all for the help. :)
Upvotes: 2
Views: 13914
Reputation: 23438
(Note: Updated 12/2023 with information about DriverKit; original question and answer predate the introduction of DriverKit.)
The other answer (hidapi) to this question certainly holds true for a bunch of different use cases, and I advise going down that route where possible. Rather than using the hidapi wrapper, you can also use the IOHIDManager
system API directly.
There are certainly cases where you'll need to dig into driver development proper, however. In particular, if the HID device needs to act as the system keyboard or pointing device, but isn't picked up as you want it to by the built-in HID stack, you might need to (or want to) develop a DriverKit (pre-10.15: kernel-space) driver. (You do have the option of injecting events into the windowing system from userspace too, though, so I'd prototype your use case with that first, if in doubt.)
You haven't quite given us enough detail about what you're trying to do, or the nature of the device to really say for sure what approach might be best.
For HIDDriverKit sample code, Apple publishes some here. For kernel level, check out Apple's own Open Source code. (IOHIDFamily, IOUSBFamily, etc.) Searching the web for the classes you're working with will also turn up some third-party OSS code on Github etc.
Stack Overflow and the relevant Apple developer mailing lists (Darwin-drivers, Darwin-kernel, or Usb, depending on the question), and maybe the developer forums (I find them hard to follow/monitor consistently) are probably the best communities for this kind of thing.
Upvotes: 1
Reputation: 129
You have three options to develop your driver:
Build from scratch with c lib: https://github.com/libusb/hidapi
Follow HID Driver documentation from Apple: https://developer.apple.com/documentation/hiddriverkit, for example:
Reference to some of GitHub resource like: https://github.com/astarasikov/osxhidtouch
As I aware, it seems that number 2 is the best way to develop your driver. But number 3 also a great place to start your development. Overall, my suggestion is number 2 or number 3.
Upvotes: 0