Introduction
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.
Start Here
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
kextd
daemon 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.
What Is the I/O Kit? in IOKit Fundamentals provides an overview of the OS X driver development environment.
The Darwin and Core Technologies article in Mac Technology Overview describes Darwin (the UNIX-based foundation of OS X) and other low-level technologies.
I/O Kit Family Device-Access Support in Accessing Hardware From Applications provides guidance about what device access is available from user-space applications.
I/O Kit Family Reference in IOKit Fundamentals provides additional details for some device types.
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.
AppleFWAudio Vendor Specific Override Driver and SampleUSBAudioPlugin: Shows how to extend Apple’s existing USB and FireWire audio drivers to add device-specific functionality.
MFSLives: Gives an example of how to add support for a local file system.
enetlognke and tcplognke: Demonstrates how to write network kernel extensions.
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:
Learn alternative approaches to accessing hardware. Read Hardware-Access Options in Accessing Hardware From Applications to learn how to access hardware devices from user-space code.
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.
The Hello Kernel and Hello I/O Kit tutorials provide step-by-step directions about creating an in-kernel device driver.
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.
Add support for a printer. Getting Started with Printing lists the resources you should read first. Bonjour Overview explains Bonjour, Apple’s zero-configuration networking solution.
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).
Copyright © 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-05-28