Difference between revisions of "Unit I2C"
(2 intermediate revisions by the same user not shown) | |||
Line 717: | Line 717: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2C |
− | | | + | | The I2C device to destroy |
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
|} | |} | ||
Line 729: | Line 732: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2C |
− | | | + | | The I2C device to register |
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
|} | |} | ||
Line 737: | Line 743: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceDeregister(I2C:PI2CDevice):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceDeregister(I2C:PI2CDevice):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister an I2C from the I2C table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2C |
− | | | + | | The I2C device to deregister |
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
|} | |} | ||
Line 749: | Line 758: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceFind(I2CId:LongWord):PI2CDevice;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceFind(I2CId:LongWord):PI2CDevice;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C device by ID in the I2C table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! I2CId |
− | | | + | | The ID number of the I2C device to find |
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C device entry or nil if not found | ||
|- | |- | ||
|} | |} | ||
Line 761: | Line 773: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceFindByName(const Name:String):PI2CDevice; inline;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceFindByName(const Name:String):PI2CDevice; inline;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C device by name in the device table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Name |
− | | | + | | The name of the I2C device to find (eg I2C0) |
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C device entry or nil if not found | ||
|- | |- | ||
|} | |} | ||
Line 773: | Line 788: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceFindByDescription(const Description:String):PI2CDevice; inline;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceFindByDescription(const Description:String):PI2CDevice; inline;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C device by description in the device table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Description |
− | | | + | | The description of the I2C to find (eg BCM2837 BSC1 Master I2C) |
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C device entry or nil if not found | ||
|- | |- | ||
|} | |} | ||
Line 785: | Line 803: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceEnumerate(Callback:TI2CEnumerate; Data:Pointer):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceEnumerate(Callback:TI2CEnumerate; Data:Pointer):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Enumerate all I2C devices in the I2C table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Callback |
− | | | + | | The callback function to call for each I2C device in the table |
+ | |- | ||
+ | ! Data | ||
+ | | A private data pointer to pass to callback for each I2C device in the table | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
|} | |} | ||
Line 797: | Line 821: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceNotification(I2C:PI2CDevice; Callback:TI2CNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceNotification(I2C:PI2CDevice; Callback:TI2CNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a notification for I2C device changes</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Device |
− | | | + | | The I2C device to notify changes for (Optional, pass nil for all I2C devices) |
+ | |- | ||
+ | ! Callback | ||
+ | | The function to call when a notification event occurs | ||
+ | |- | ||
+ | ! Data | ||
+ | | A private data pointer to pass to callback when a notification event occurs | ||
+ | |- | ||
+ | ! Notification | ||
+ | | The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER) | ||
+ | |- | ||
+ | ! Flags | ||
+ | | The flags to control the notification (eg NOTIFIER_FLAG_WORKER) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | '''I2C slave functions''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveStart(I2C:PI2CDevice):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Start the specified I2C slave ready for reading and writing</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to start | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveStop(I2C:PI2CDevice):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Stop the specified I2C slave and terminate reading and writing</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to stop | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveRead(I2C:PI2CDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from the specified I2C slave</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to read from | ||
+ | |- | ||
+ | ! Buffer | ||
+ | | Pointer to a buffer to receive the data | ||
+ | |- | ||
+ | ! Size | ||
+ | | The size of the buffer | ||
+ | |- | ||
+ | ! Count | ||
+ | | The number of bytes read on return | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveWrite(I2C:PI2CDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to the specified I2C slave</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to write to | ||
+ | |- | ||
+ | ! Buffer | ||
+ | | Pointer to a buffer of data to transmit | ||
+ | |- | ||
+ | ! Size | ||
+ | | The size of the buffer | ||
+ | |- | ||
+ | ! Count | ||
+ | | The number of bytes written on return | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveGetAddress(I2C:PI2CDevice):Word; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the address for the specified I2C slave</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to get the address from | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveSetAddress(I2C:PI2CDevice; Address:Word):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the address for the specified I2C slave</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to set the address for | ||
+ | |- | ||
+ | ! Address | ||
+ | | The address to set | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveGetProperties(I2C:PI2CDevice; Properties:PI2CProperties):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties for the specified I2C slave</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to get properties from | ||
+ | |- | ||
+ | ! Properties | ||
+ | | Pointer to a TI2CProperties structure to fill in | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveCreate:PI2CDevice;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create a new I2C slave entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to new I2C slave entry or nil if I2C could not be created | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveCreateEx(Size:LongWord):PI2CDevice;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create a new I2C slave entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Size | ||
+ | | Size in bytes to allocate for new I2C (Including the I2C slave entry) | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to new I2C slave entry or nil if I2C could not be created | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveDestroy(I2C:PI2CDevice):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Destroy an existing I2C slave entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to destroy | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveRegister(I2C:PI2CDevice):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a new I2C slave in the I2C table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to register | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveDeregister(I2C:PI2CDevice):LongWord; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister an I2C slave from the I2C table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C slave to deregister | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveFind(I2CId:LongWord):PI2CDevice;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C slave by ID in the I2C table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2CId | ||
+ | | The ID number of the I2C slave to find | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C slave entry or nil if not found | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveFindByName(const Name:String):PI2CDevice; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C slave by name in the device table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Name | ||
+ | | The name of the I2C slave to find (eg I2CSlave0) | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C slave entry or nil if not found | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CSlaveFindByDescription(const Description:String):PI2CDevice; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an I2C slave by description in the device table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Description | ||
+ | | The description of the I2C slave to find (eg BCM2837 I2C Slave) | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to I2C slave entry or nil if not found | ||
|- | |- | ||
|} | |} | ||
Line 1,021: | Line 1,306: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function I2CGetCount:LongWord | + | <pre style="border: 0; padding-bottom:0px;">function I2CGetCount:LongWord;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current I2C count</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current I2C count</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,033: | Line 1,318: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceGetDefault:PI2CDevice | + | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceGetDefault:PI2CDevice;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default I2C device</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default I2C device</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,059: | Line 1,344: | ||
<pre style="border: 0; padding-bottom:0px;">function I2CDeviceCheck(I2C:PI2CDevice):PI2CDevice;</pre> | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceCheck(I2C:PI2CDevice):PI2CDevice;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied I2C is in the I2C table</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied I2C is in the I2C table</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function I2CDeviceIsSlave(I2C:PI2CDevice):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied I2C is a slave device</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" |
Latest revision as of 03:47, 15 December 2022
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.
A small number of devices and hosts support 10bit addressing which expands the number of available addresses. The 10bit address format is defined here https://www.i2c-bus.org/addressing/10-bit-addressing/ and the reserved addresses are defined on this page https://www.i2c-bus.org/addressing/
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 get properties
TI2CDeviceGetProperties = function(I2C:PI2CDevice; Properties:PI2CProperties):LongWord;
|
I2C device
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; inline;
function I2CDeviceGetProperties(I2C:PI2CDevice; Properties:PI2CProperties):LongWord;
function I2CDeviceDestroy(I2C:PI2CDevice):LongWord;
function I2CDeviceRegister(I2C:PI2CDevice):LongWord;
function I2CDeviceDeregister(I2C:PI2CDevice):LongWord;
function I2CDeviceFind(I2CId:LongWord):PI2CDevice;
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;
I2C slave functions
function I2CSlaveStart(I2C:PI2CDevice):LongWord; inline;
function I2CSlaveStop(I2C:PI2CDevice):LongWord; inline;
function I2CSlaveRead(I2C:PI2CDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;
function I2CSlaveWrite(I2C:PI2CDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;
function I2CSlaveGetAddress(I2C:PI2CDevice):Word; inline;
function I2CSlaveSetAddress(I2C:PI2CDevice; Address:Word):LongWord; inline;
function I2CSlaveGetProperties(I2C:PI2CDevice; Properties:PI2CProperties):LongWord; inline;
function I2CSlaveCreateEx(Size:LongWord):PI2CDevice;
function I2CSlaveDestroy(I2C:PI2CDevice):LongWord; inline;
function I2CSlaveRegister(I2C:PI2CDevice):LongWord; inline;
function I2CSlaveDeregister(I2C:PI2CDevice):LongWord; inline;
function I2CSlaveFind(I2CId:LongWord):PI2CDevice;
function I2CSlaveFindByName(const Name:String):PI2CDevice; inline;
function I2CSlaveFindByDescription(const Description:String):PI2CDevice; inline;
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 I2CDeviceSetDefault(I2C:PI2CDevice):LongWord;
function I2CDeviceCheck(I2C:PI2CDevice):PI2CDevice;
function I2CDeviceIsSlave(I2C:PI2CDevice):Boolean;
function I2CTypeToString(I2CType:LongWord):String;
function I2CStateToString(I2CState:LongWord):String;
function I2CIs7BitAddress(Address:Word):Boolean;
function I2CIs10BitAddress(Address:Word):Boolean;
procedure I2CLog(Level:LongWord; I2C:PI2CDevice; const AText:String);
procedure I2CLogInfo(I2C:PI2CDevice; const AText:String); inline;
procedure I2CLogWarn(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