Difference between revisions of "Unit PCF857X"
(Created page with "Return to Unit Reference === Description === ---- ''To be documented'' === Constants === ---- ''To be documented'' === Type definitions === ---- ''To...") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
---- | ---- | ||
− | '' | + | '''NXP PCF857X I/O Expander Driver unit''' |
+ | |||
+ | The NXP PCF8574 is an 8 bit I/O expander that provides GPIO pin control functions over an I2C connection. | ||
+ | |||
+ | The device can be represented in Ultibo as a standard GPIO device which is accessible via the GPIO unit functions. Because the PCF857X is a chip that can be used and configured in multiple different scenarios this unit does not autocreate a GPIO device, instead you need to call the function PCF8574GPIOCreate and pass an I2C device and address. The function will create and return a GPIO device with the appropriate number of pins and other information for the specified chip, the returned devices will have been registered with the GPIO device unit and started ready for use. | ||
+ | |||
+ | Note: This unit does not currently implement the interrupt capabilities of the PCF857X chips however it could be expanded to allow the interrupt pin to be connected to a GPIO pin on the SoC and use a trigger event from that to enable GPIOInputWait/GPIOInputEvent functions for the PCF857X chips. | ||
=== Constants === | === Constants === | ||
---- | ---- | ||
− | '' | + | |
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PCF857X specific constants''' <code> PCF8574_GPIO_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PCF8574_GPIO_DESCRIPTION = 'NXP PCF8574 8-bit I/O Expander';</code> | ||
+ | | style="width: 50%;"|Description of PCF8574 device | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF8574_GPIO_MIN_PIN = GPIO_PIN_0;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>PCF8574_GPIO_MAX_PIN = GPIO_PIN_7;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>PCF8574_GPIO_PIN_COUNT = 8;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF857X_GPIO_MAX_LEVEL = GPIO_LEVEL_HIGH;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF857X_GPIO_MAX_PULL = GPIO_PULL_UP;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF857X_GPIO_MIN_FUNCTION = GPIO_FUNCTION_IN;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>PCF857X_GPIO_MAX_FUNCTION = GPIO_FUNCTION_OUT;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PCF857X chip''' <code> PCF857X_CHIP_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>PCF857X_CHIP_PCF8574 = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''PCF857X I2C''' <code> PCF8574_I2C_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|Note: The PCF857X is a single register device and does not have any direction, pull or configuration registers | ||
+ | |- | ||
+ | | <code>PCF8574_I2C_RATE = 100000;</code> | ||
+ | | style="width: 50%;"|Default I2C clock rate (Device supports 100KHz only) | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF8574_I2C_SIZE = 1;</code> | ||
+ | | Number of bytes to read/write all pin values | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>PCF857X_I2C_MAX_SIZE = 2;</code> | ||
+ | | Maximum number of bytes to read/write all pin values | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Type definitions === | === Type definitions === | ||
---- | ---- | ||
− | '' | + | |
+ | '''PCF857X GPIO''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PPCF857XGPIO = ^TPCF857XGPIO;</code> | ||
+ | |||
+ | <code>TPCF857XGPIO = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''GPIO Properties'' | ||
+ | |- | ||
+ | | <code>GPIO:TGPIODevice;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |colspan="2"|''PCF857X Properties'' | ||
+ | |- | ||
+ | | <code>I2C:PI2CDevice;</code> | ||
+ | | The I2C device this GPIO is connected to | ||
+ | |- | ||
+ | | <code>Address:Word;</code> | ||
+ | | The I2C address of the device | ||
+ | |- | ||
+ | | <code>Chip:LongWord;</code> | ||
+ | | The chip type (eg PCF857X_CHIP_PCF8574) | ||
+ | |- | ||
+ | | <code>Size:LongWord;</code> | ||
+ | | Size of an I2C read/write for the device | ||
+ | |- | ||
+ | | <code>Rate:LongWord;</code> | ||
+ | | Clock rate for this device | ||
+ | |- | ||
+ | | <code>GPIOValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for GPIO port values (Output only) | ||
+ | |- | ||
+ | | <code>GPPUValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for GPPU pull up values | ||
+ | |- | ||
+ | | <code>IODIRValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;</code> | ||
+ | | Buffer for IODIR I/O direction values | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === | ||
---- | ---- | ||
− | '' | + | ''None defined'' |
=== Function declarations === | === Function declarations === | ||
---- | ---- | ||
− | |||
+ | '''PCF857X 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 PCF8574GPIOCreate(I2C:PI2CDevice; Address:Word):PGPIODevice;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create, register and start a new PCF8574 GPIO device connected to the specified I2C device</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! I2C | ||
+ | | The I2C device this PCF8574 is connected to | ||
+ | |- | ||
+ | ! Address | ||
+ | | The I2C address for this PCF8574 | ||
+ | |- | ||
+ | ! Return | ||
+ | | Pointer to the new GPIO device or nil 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 PCF857XGPIODestroy(GPIO:PGPIODevice):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Stop, deregister and destroy a PCF857X GPIO device created by this driver</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! GPIO | ||
+ | | The GPIO device to destroy | ||
+ | |- | ||
+ | ! Return | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | '''PCF857X GPIO 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 PCF857XGPIOStart(GPIO:PGPIODevice):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceStart API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceStart instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOStop(GPIO:PGPIODevice):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceStop API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceStop instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIORead(GPIO:PGPIODevice; Reg:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceRead API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceRead instead. | ||
+ | Will read only a single register byte. | ||
+ | |- | ||
+ | |} | ||
+ | </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;">procedure PCF857XGPIOWrite(GPIO:PGPIODevice; Reg,Value:LongWord);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceWrite API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceWrite instead. | ||
+ | Will write only a single register byte. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOInputGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceInputGet API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceInputGet instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOOutputSet(GPIO:PGPIODevice; Pin,Level:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceOutputSet API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceOutputSet instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOPullGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODevicePullGet API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODevicePullGet instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOFunctionGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceFunctionGet API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceFunctionGet instead. | ||
+ | |- | ||
+ | |} | ||
+ | </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 PCF857XGPIOFunctionSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of GPIODeviceFunctionSelect API for PCF857X</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead. | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
Return to [[Unit_Reference|Unit Reference]] | Return to [[Unit_Reference|Unit Reference]] |
Latest revision as of 05:45, 31 August 2021
Return to Unit Reference
Description
NXP PCF857X I/O Expander Driver unit
The NXP PCF8574 is an 8 bit I/O expander that provides GPIO pin control functions over an I2C connection.
The device can be represented in Ultibo as a standard GPIO device which is accessible via the GPIO unit functions. Because the PCF857X is a chip that can be used and configured in multiple different scenarios this unit does not autocreate a GPIO device, instead you need to call the function PCF8574GPIOCreate and pass an I2C device and address. The function will create and return a GPIO device with the appropriate number of pins and other information for the specified chip, the returned devices will have been registered with the GPIO device unit and started ready for use.
Note: This unit does not currently implement the interrupt capabilities of the PCF857X chips however it could be expanded to allow the interrupt pin to be connected to a GPIO pin on the SoC and use a trigger event from that to enable GPIOInputWait/GPIOInputEvent functions for the PCF857X chips.
Constants
PCF8574_GPIO_*
PCF8574_GPIO_DESCRIPTION = 'NXP PCF8574 8-bit I/O Expander';
|
Description of PCF8574 device |
PCF8574_GPIO_MIN_PIN = GPIO_PIN_0;
|
|
PCF8574_GPIO_MAX_PIN = GPIO_PIN_7;
|
|
PCF8574_GPIO_PIN_COUNT = 8;
|
|
PCF857X_GPIO_MAX_LEVEL = GPIO_LEVEL_HIGH;
|
|
PCF857X_GPIO_MAX_PULL = GPIO_PULL_UP;
|
|
PCF857X_GPIO_MIN_FUNCTION = GPIO_FUNCTION_IN;
|
|
PCF857X_GPIO_MAX_FUNCTION = GPIO_FUNCTION_OUT;
|
PCF857X_CHIP_*
PCF857X_CHIP_PCF8574 = 0;
|
PCF8574_I2C_*
Note: The PCF857X is a single register device and does not have any direction, pull or configuration registers | |
PCF8574_I2C_RATE = 100000;
|
Default I2C clock rate (Device supports 100KHz only) |
PCF8574_I2C_SIZE = 1;
|
Number of bytes to read/write all pin values |
PCF857X_I2C_MAX_SIZE = 2;
|
Maximum number of bytes to read/write all pin values |
Type definitions
PCF857X GPIO
PPCF857XGPIO = ^TPCF857XGPIO;
TPCF857XGPIO = record
GPIO Properties | |
GPIO:TGPIODevice;
|
|
PCF857X Properties | |
I2C:PI2CDevice;
|
The I2C device this GPIO is connected to |
Address:Word;
|
The I2C address of the device |
Chip:LongWord;
|
The chip type (eg PCF857X_CHIP_PCF8574) |
Size:LongWord;
|
Size of an I2C read/write for the device |
Rate:LongWord;
|
Clock rate for this device |
GPIOValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for GPIO port values (Output only) |
GPPUValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for GPPU pull up values |
IODIRValues:array[0..PCF857X_I2C_MAX_SIZE - 1] of Byte;
|
Buffer for IODIR I/O direction values |
Public variables
None defined
Function declarations
PCF857X functions
function PCF8574GPIOCreate(I2C:PI2CDevice; Address:Word):PGPIODevice;
I2C | The I2C device this PCF8574 is connected to |
---|---|
Address | The I2C address for this PCF8574 |
Return | Pointer to the new GPIO device or nil on failure |
function PCF857XGPIODestroy(GPIO:PGPIODevice):LongWord;
GPIO | The GPIO device to destroy |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
PCF857X GPIO functions
function PCF857XGPIOStart(GPIO:PGPIODevice):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceStart instead. |
---|
function PCF857XGPIOStop(GPIO:PGPIODevice):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceStop instead. |
---|
function PCF857XGPIORead(GPIO:PGPIODevice; Reg:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceRead instead.
Will read only a single register byte. |
---|
procedure PCF857XGPIOWrite(GPIO:PGPIODevice; Reg,Value:LongWord);
Note | Not intended to be called directly by applications, use GPIODeviceWrite instead.
Will write only a single register byte. |
---|
function PCF857XGPIOInputGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceInputGet instead. |
---|
function PCF857XGPIOOutputSet(GPIO:PGPIODevice; Pin,Level:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceOutputSet instead. |
---|
function PCF857XGPIOPullGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODevicePullGet instead. |
---|
function PCF857XGPIOFunctionGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceFunctionGet instead. |
---|
function PCF857XGPIOFunctionSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Note | Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead. |
---|
Return to Unit Reference