We've just wrapped up a whitepaper that describes the creation of a sample driver that supports four sensors: compass, 2-axis accelerometer, ultrasonic distance, and passive-infrared (or motion). You can download the whitepaper and accompanying source