I2C (Inter-Integrated Circuit) Framework
I2C (Inter-Integrated Circuit) is a simple serial protocol that connects multiple devices in a master-slave relationship. Multiple master devices may share a single bus. The same device may function as both a master and a slave in different transactions. The I2C specification defines these transfer speed ranges:
- ≤ 100 Kbit/s
- ≤ 400 Kbit/s
- ≤ 3.4 Mbit/s
The I2C framework is intended to facilitate consistent implementation of I2C interfaces. The framework consists of the following parts:
- hardware/i2c/*
- The hardware interface.
- lib/i2c
- The resource manager layer.
- <hw/i2c.h>
- A public header file that defines the hardware and application interfaces.
The most common application of the I2C bus is low-bandwidth access to a slave device's registers, such as:
- programming an audio codec
- programming a RTC
- reading a temperature sensor
- reading from an EPROM
Typically, only a few bytes are exchanged on the bus.
You can implement the I2C master as a single-threaded resource manager, or as a dedicated application. The primary advantages of a resource manager interface are:
- It presents a clear, easy-to-understand interface to the application developer.
- It mediates between accesses by multiple applications to one or more slave devices.
- It enforces consistency between different I2C interfaces.
For a dedicated I2C-bus application, a hardware access library is more efficient. The hardware interface, which defines the interface to this library, is useful as a starting point for developers and facilitates maintenance and code portability.