You are here

Using I2C in Windows

Submitted by kombarov_mv on Mon, 02/16/2015 - 02:25

On Microsoft Windows XP and later, after the Plug and Play manager has enumerated a video adapter's child devices, the miniport driver can communicate with the adapter's child devices on an I2C bus using the I2C protocol. Communication between the miniport driver and WDM drivers for those devices on an I2C bus can occur via a software interface exposed by the miniport driver (as described in Communicating with the Driver of a Child Device). The miniport driver can initiate physical communication between those devices on the I2C bus by way of a new hardware interface exposed by the video port driver. If the miniport driver needs the I2C master device (usually the graphics chip) to read from or write to a physical child device over the I2C bus, it can use the hardware I2C interface provided by the video port driver'sVideoPortQueryServices routine. Note that this communication over the I2C bus is limited strictly to hardware devices on the same I2C bus. Miniport driver writers are strongly encouraged to use these routines for all such communication.

This mode of communication is also useful in cases where a video adapter has components for which there is no WDM driver. For example, a video adapter may have a daughter board or circuit that is used to send the video image to a digital flat panel. In this case, the miniport driver can make use of the hardware I2C interface provided byVideoPortQueryServices to send commands to that circuit over the I2C bus.

The preceding figure illustrates how a miniport driver can initiate communication between two hardware devices on an I2C bus.

To take advantage of the video port's I2C routines, the miniport driver must query the video port driver for an I2C interface. In preparation for this, the miniport driver must allocate a VIDEO_PORT_I2C_INTERFACE structure, and initialize its first two members (the Size and Version members) to appropriate values. The miniport driver then calls the video port driver's VideoPortQueryServices routine, setting the servicesType parameter to VideoPortServicesI2C, and setting the pInterface parameter to the partially-initialized VIDEO_PORT_I2C_INTERFACE structure.

If the call to VideoPortQueryServices is successful, the video port driver fills in the remaining members of the VIDEO_PORT_I2C_INTERFACE structure, including the addresses of four I2C routines: I2CStart, I2CStop, I2CRead, andI2CWrite.

I2CStart and I2CStop are used, respectively, to initiate communication with the child device, and to terminate communication with it.

I2CRead reads a specified number of bytes from the child device; I2CWrite writes a specified number of bytes to it.

For Windows 8, Microsoft created a new HID miniport driver that allows devices to communicate over an Inter-Integrated Circuit (I2C) bus.

The new HID miniport solution extends the HID protocol, beyond USB and Bluetooth, to support I2C devices. I2C is a simple but efficient protocol and has been used for over a decade in phone and embedded platforms. This protocol is supported in Windows 8 by an in-box KMDF driver named HIDI2C.sys.

This combined support for I2C over HID in the inbox driver, allows hardware manufactures to get their devices running quickly on windows without imposing the need to create a driver.

In order to ensure correct behavior on a system with multiple ACPI resources, the following two resources must appear first:

  • HID I2C connection
  • Device interrupt

After these resources are defined, additional ACPI resources, of other types, may follow.

Important notes:

  • Today, the HID I2C driver targets SoC systems that support Simple Peripheral Bus (SPB) and GPIO. In the future, Microsoft may support this driver on non-SoC systems.
  • The HID I2C driver is optimized to support all HID Clients.
  • The HID I2C driver enables devices and system manufacturers to reduce the total number of drivers they have to develop to support common device types like keyboards, touchpads, touch screens, sensors, and so on.
  • The HID I2C driver is available on all client SKUs of Windows and is included in WinPE.