Difference between revisions of "Unit I2C"
Line 103: | Line 103: | ||
---- | ---- | ||
− | '' | + | |
+ | '''I2C properties''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PI2CProperties = ^TI2CProperties;</code> | ||
+ | |||
+ | <code>TI2CProperties = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>Flags:LongWord;</code> | ||
+ | | Device flags (eg I2C_FLAG_SLAVE) | ||
+ | |- | ||
+ | | <code>MaxSize:LongWord;</code> | ||
+ | | Maximum supported data transfer size | ||
+ | |- | ||
+ | | <code>MinClock:LongWord;</code> | ||
+ | | Minimum supported clock rate | ||
+ | |- | ||
+ | | <code>MaxClock:LongWord;</code> | ||
+ | | Maximum supported clock rate | ||
+ | |- | ||
+ | | <code>ClockRate:LongWord;</code> | ||
+ | | Current clock rate | ||
+ | |- | ||
+ | | <code>SlaveAddress:Word;</code> | ||
+ | | Current slave address | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''I2C enumeration callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CEnumerate = function(I2C:PI2CDevice; Data:Pointer):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C notification callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device start''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceStart = function(I2C:PI2CDevice;Rate:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device stop''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceStop = function(I2C:PI2CDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device read''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceRead = function(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device write''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceWrite = function(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device write read''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceWriteRead = function(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device write write''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceWriteWrite = function(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device get rate''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceGetRate = function(I2C:PI2CDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device set rate''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceSetRate = function(I2C:PI2CDevice; Rate:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device get address''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceGetAddress = function(I2C:PI2CDevice):Word;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device set address''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceSetAddress = function(I2C:PI2CDevice; Address:Word):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device properties''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TI2CDeviceProperties = function(I2C:PI2CDevice; Properties:PI2CProperties):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''I2C device types''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PI2CDevice = ^TI2CDevice;</code> | ||
+ | |||
+ | <code>TI2CDevice = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''Device Properties'' | ||
+ | |- | ||
+ | | <code>Device:TDevice;</code> | ||
+ | | The Device entry for this I2C | ||
+ | |- | ||
+ | |colspan="2"|''I2C Properties'' | ||
+ | |- | ||
+ | | <code>I2CId:LongWord;</code> | ||
+ | | Unique Id of this I2C in the I2C table | ||
+ | |- | ||
+ | | <code>I2CState:LongWord;</code> | ||
+ | | I2C state (eg I2C_STATE_ENABLED) | ||
+ | |- | ||
+ | | <code>DeviceStart:TI2CDeviceStart;</code> | ||
+ | | A Device specific DeviceStart method implementing the standard I2C device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceStop:TI2CDeviceStop;</code> | ||
+ | | A Device specific DeviceStop method implementing the standard I2C device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceRead:TI2CDeviceRead;</code> | ||
+ | | A Device specific DeviceRead method implementing the standard I2C device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceWrite:TI2CDeviceWrite;</code> | ||
+ | | A Device specific DeviceWrite method implementing the standard I2C device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceWriteRead:TI2CDeviceWriteRead;</code> | ||
+ | | A Device specific DeviceWriteRead method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceWriteWrite:TI2CDeviceWriteWrite;</code> | ||
+ | | A Device specific DeviceWriteWrite method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceGetRate:TI2CDeviceGetRate;</code> | ||
+ | | A Device specific DeviceGetRate method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceSetRate:TI2CDeviceSetRate;</code> | ||
+ | | A Device specific DeviceSetRate method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceGetAddress:TI2CDeviceGetAddress;</code> | ||
+ | | A Device specific DeviceGetAddress method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceSetAddress:TI2CDeviceSetAddress;</code> | ||
+ | | A Device specific DeviceSetAddress method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceProperties:TI2CDeviceProperties;</code> | ||
+ | | A Device specific DeviceProperties method implementing the standard I2C device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | |colspan="2"|''Statistics Properties'' | ||
+ | |- | ||
+ | | <code>ReadCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>WriteCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ReadErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>WriteErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Driver Properties'' | ||
+ | |- | ||
+ | | <code>Lock:TMutexHandle;</code> | ||
+ | | Device lock | ||
+ | |- | ||
+ | | <code>Wait:TSemaphoreHandle;</code> | ||
+ | | Read/Write wait event | ||
+ | |- | ||
+ | | <code>ClockRate:LongWord;</code> | ||
+ | | Clock rate (Hz) | ||
+ | |- | ||
+ | | <code>SlaveAddress:Word;</code> | ||
+ | | Slave address | ||
+ | |- | ||
+ | | <code>Properties:TI2CProperties;</code> | ||
+ | | Device properties | ||
+ | |- | ||
+ | |colspan="2"|''Internal Properties'' | ||
+ | |- | ||
+ | | <code>Prev:PI2CDevice;</code> | ||
+ | | Previous entry in I2C table | ||
+ | |- | ||
+ | | <code>Next:PI2CDevice;</code> | ||
+ | | Next entry in I2C table | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === |
Revision as of 05:42, 19 January 2017
Return to Unit Reference
Contents
[hide]Description
Ultibo I2C interface unit
I2C (Inter-Integrated Circuit) is a serial bus for communication between peripheral components.
Originally invented by Phillips the I2C protocol is used by thousands of common chips that perform a wide range of tasks such as real time clocks, temperature and other sensors, small LCD displays and many more.
Each device is assigned a 7bit address which is used by the host (or master) to signal the device that a message written to the bus is intended for that device or that the host wants to read data from that device.
Speeds range from 10Kbps to 3.4Mbps although the typical speed is either 100Kbps or 400Kbps.
This unit implements the standardized interface for I2C devices and allows reading or writing to a specific address, setting a clock rate for the communication and determining device properties.
For the purpose of this interface a device is the I2C controller attached to the local system and may be either a master or a slave. Since the protocol does not include any form of enumeration or identification the interface does not attempt to represent the devices connected to the bus,any driver written to communicate with a connected I2C device should know (or allow configuration of) the address to read and write to and the specific message format required for that device. The Intel System Management Bus (SMBus) is a variation of the I2C bus and in certain cases the two are compatible with each other.
Constants
I2C_*
I2C_TYPE_*
I2C_STATE_*
I2C_FLAG_*
I2C_LOG_*
Type definitions
I2C properties
I2C enumeration callback
TI2CEnumerate = function(I2C:PI2CDevice; Data:Pointer):LongWord;
|
I2C notification callback
TI2CNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
I2C device start
TI2CDeviceStart = function(I2C:PI2CDevice;Rate:LongWord):LongWord;
|
I2C device stop
TI2CDeviceStop = function(I2C:PI2CDevice):LongWord;
|
I2C device read
TI2CDeviceRead = function(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
|
I2C device write
TI2CDeviceWrite = function(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
|
I2C device write read
TI2CDeviceWriteRead = function(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
|
I2C device write write
TI2CDeviceWriteWrite = function(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
|
I2C device get rate
TI2CDeviceGetRate = function(I2C:PI2CDevice):LongWord;
|
I2C device set rate
TI2CDeviceSetRate = function(I2C:PI2CDevice; Rate:LongWord):LongWord;
|
I2C device get address
TI2CDeviceGetAddress = function(I2C:PI2CDevice):Word;
|
I2C device set address
TI2CDeviceSetAddress = function(I2C:PI2CDevice; Address:Word):LongWord;
|
I2C device properties
TI2CDeviceProperties = function(I2C:PI2CDevice; Properties:PI2CProperties):LongWord;
|
I2C device types
Public variables
I2C logging
I2C_DEFAULT_LOG_LEVEL:LongWord = I2C_LOG_LEVEL_DEBUG;
|
Minimum level for I2C messages. Only messages with level greater than or equal to this will be printed. |
I2C_LOG_ENABLED:Boolean;
|
Function declarations
Initialization functions
I2C functions
function I2CDeviceStart(I2C:PI2CDevice; Rate:LongWord):LongWord;
function I2CDeviceStop(I2C:PI2CDevice):LongWord;
function I2CDeviceRead(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function I2CDeviceWrite(I2C:PI2CDevice; Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function I2CDeviceWriteRead(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function I2CDeviceWriteWrite(I2C:PI2CDevice; Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function I2CDeviceGetRate(I2C:PI2CDevice):LongWord;
function I2CDeviceSetRate(I2C:PI2CDevice; Rate:LongWord):LongWord;
function I2CDeviceGetAddress(I2C:PI2CDevice):Word;
function I2CDeviceSetAddress(I2C:PI2CDevice; Address:Word):LongWord;
function I2CDeviceProperties(I2C:PI2CDevice; Properties:PI2CProperties):LongWord;
function I2CDeviceDestroy(I2C:PI2CDevice):LongWord;
function I2CDeviceRegister(I2C:PI2CDevice):LongWord;
function I2CDeviceDeregister(I2C:PI2CDevice):LongWord;
function I2CDeviceFindByName(const Name:String):PI2CDevice; inline;
function I2CDeviceFindByDescription(const Description:String):PI2CDevice; inline;
function I2CDeviceEnumerate(Callback:TI2CEnumerate; Data:Pointer):LongWord;
function I2CDeviceNotification(I2C:PI2CDevice; Callback:TI2CNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
RTL I2C functions
function SysI2CStart(Rate:LongWord):LongWord;
function SysI2CStop:LongWord;
function SysI2CRead(Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysI2CWrite(Address:Word; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysI2CWriteRead(Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysI2CWriteWrite(Address:Word; Initial:Pointer; Len:LongWord; Data:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysI2CSetRate(Rate:LongWord):LongWord;
function SysI2CGetAddress:Word;
function SysI2CSetAddress(Address:Word):LongWord;
I2C helper functions
function I2CDeviceGetDefault:PI2CDevice; inline;
function I2CDeviceSetDefault(I2C:PI2CDevice):LongWord;
function I2CDeviceCheck(I2C:PI2CDevice):PI2CDevice;
procedure I2CLog(Level:LongWord; I2C:PI2CDevice; const AText:String);
procedure I2CLogInfo(I2C:PI2CDevice; const AText:String); inline;
procedure I2CLogError(I2C:PI2CDevice; const AText:String); inline;
procedure I2CLogDebug(I2C:PI2CDevice; const AText:String); inline;
Return to Unit Reference