Apple's adoption of open standards and support for standard peripheral families yields opportunities for both hardware and device-driver developers.
Hardware developers can take advantage of standard high-performance interfaces to develop add-on or peripheral products that extend the capabilities of the Macintosh.
Driver developers can use the I/O Kit, Apple's object-oriented driver-development framework, to create in-kernel or application-level drivers for their own or another vendor's devices.
In addition, OS X provides several services that allow applications to communicate with hardware from plug-ins, shared libraries, and other code running outside the kernel.
To write code that controls a hardware device in OS X, you should:
Decide whether your code should be in the kernel or in user space. In OS X, many drivers can be written in user space. Network kernel extensions and file systems generally must be in the kernel.
If you determine that you can write your code in user space, create matching dictionaries to match the appropriate device, then open the device.
If you determine that you must write a kernel-mode driver, determine what I/O Kit class your driver should subclass and what nubs your driver should publish (if applicable).
Also create a set of matching rules to tell the
kextddaemon when to load your kernel extension and create a property list file that reflects this.
Start writing code that communicates with the hardware.
To develop hardware devices for the Mac, read the relevant developer notes.
To develop a network kernel extension, read Network Kernel Extensions Programming Guide.
To develop a file system, read the MFSLives sample code.
Choose next how you want to get started—by reading about the basics, getting your hands on some code, or diving into specific technologies.
Want to get familiar with the fundamentals?
Coding in the Kernel explains the pros and cons of developing in-kernel code.
Network Kernel Extensions Programming Guide explains how to write kernel extensions that work with network packets.
Prefer to learn by example?
USBPrivateDataSample: Provides an example of controlling a USB device from user space code.
Hello Kernel: Creating a Kernel Extension With Xcode: Provides an overview of creating a non-I/O Kit kernel extension.
Hello I/O Kit: Creating a Device Driver With Xcode: Provides an overview of creating an I/O Kit kernel extension.
SimpleUserClient: Provides an example of how to provide communication between a kernel-mode driver and user-space applications.
SampleFilterScheme: Shows how to interpose a driver between existing driver layers.
MFSLives: Gives an example of how to add support for a local file system.
In addition to these examples and other examples in Hardware and Drivers Sample Code, the Darwin open source project provides dozens of device drivers that you can use as a starting point for understanding the I/O Kit.
Want to learn how to leverage your existing code and knowledge?
Porting UNIX/Linux Applications to OS X provides an overview of OS X targeted at UNIX developers. As a device-driver developer, you should read the Porting File, Device, and Network I/O chapter in particular.
Porting Drivers to OS X provides explanation of some of the fundamental driver constructs that OS X provides and relates them to driver architectures on other platforms.
Go In Depth
Sometimes you need task-focused information or answers to specific questions to get started. Browse the popular tasks described below for a more targeted way to start developing your web app or web content.
Using High-Level APIs to Access Hardware
Many applications can handle all their hardware-access needs using high-level APIs that are available through Carbon and Cocoa. Unless you’re absolutely certain you need to develop a device driver, read the following to find out if there is an easier solution:
Access a specific device. See the appropriate topic (such as Bluetooth) in Hardware & Drivers Guides for more information.
Accessing Hardware from Application
Access hardware from user space. Accessing Hardware From Applications explains how to use device interfaces to develop an application-based device driver.
Work with human interface devices. HID Class Device Interface Guide explains how to work with human interface devices (game controllers, keyboards, control surfaces, and so on) in user-space applicatinos.
Control USB devices from user space. USB Device Interface Guide explains how to control other USB devices from user-space applications.
Control FireWire devices from user space. FireWire Device Interface Guide explains how to control FireWire devices from user-space applications.
The subtopics in Hardware & Drivers Guides provide additional information about specific device types.
Developing an In-Kernel Device Driver
Developing a kernel-resident device driver is difficult at best and should be done only if there is no alternative. If you’ve determined that your device driver must reside in the kernel, you want to learn more about the kernel and how to program in it.
Kernel Programming Guide gives a high level overview of the kernel environment.
About Kernel Extensions provides an overview of how to create kernel extensions.
IOKit Device Driver Design Guidelines provides in-depth information on all aspects of in-kernel driver development for OS X.
If you need to know how to write a device driver for a specific device, see the appropriate topic (such as Bluetooth) in Hardware & Drivers Guides.
Developing, Supporting, and Servicing Hardware
Develop compatible add-on or peripheral devices. The Hardware and Drivers Reference Library provides hardware developer notes that explain the internal design of the system, its hardware input-output and expansion capabilities, and potential compatibility issues.
Sign up for AppleCare Technician Training to learn peripheral device installation or hardware diagnosis and repair. This program also gives you access to Apple’s Service Source materials, including diagnostic tools and take-apart instructions.
Ready for More?
The OS X Reference Library holds plenty more resources that make your job easier. To narrow the list of resources, you can set filters to focus on specific resource types (such as guides or sample code) or on specific topics (such as user experience or data management).