Difference between revisions of "Unit RPIGPIOEXPANDER"

From Ultibo.org
Jump to: navigation, search
Line 21: Line 21:
 
* GPIO_PIN_7 = Power LED (Input / Active Low)
 
* GPIO_PIN_7 = Power LED (Input / Active Low)
  
Note that this driver requires the most recent firmware (later than February 2017) and has been tested successfully with the firmware release from 22 May 2017.
+
For the Raspberry Pi 3B+ the assignments show in /arch/arm/boot/dts/bcm2710-rpi-3-b.dts have changed as follows:
 +
 
 +
*GPIO_PIN_2 = Power LED (Active Low)
 +
*GPIO_PIN_4 = HDMI Detect (Input / Active Low)
 +
 
 +
Note that this driver requires the most recent firmware (later than February 2017) and has been tested successfully with the firmware release from 17 March 2018.
 
   
 
   
 
The latest version of the firmware is available from https://github.com/raspberrypi/firmware
 
The latest version of the firmware is available from https://github.com/raspberrypi/firmware

Revision as of 04:58, 27 March 2018

Return to Unit Reference


Description


Raspberry Pi Firmware GPIO Expander Driver

As of February 2017 the Raspberry Pi firmware contains a mailbox interface to allow control of the GPIO expander on the Raspberry Pi 3 and Compute Module 3.

Unlike the earlier virtual GPIO interface this mailbox service now supports most GPIO functionality including getting and setting a pin value, getting and changing the pin function and getting or changing the pull up/down options.

This driver implements most of the functionality available in the new mailbox service as a standard Ultibo GPIO device and also provides direct mailbox calls to allow access to any additional options not covered by the GPIO device API.

When included in a project this driver replaces the Virtual GPIO functions provided by the PlatformRPi2 and PlatformRPi3 units.

According to /arch/arm/boot/dts/bcm2710-rpi-3-b.dts the following pin assignments are known:

  • GPIO_PIN_2 = Activity LED
  • GPIO_PIN_4 = HDMI Detect (Input / Active Low)
  • GPIO_PIN_7 = Power LED (Input / Active Low)

For the Raspberry Pi 3B+ the assignments show in /arch/arm/boot/dts/bcm2710-rpi-3-b.dts have changed as follows:

  • GPIO_PIN_2 = Power LED (Active Low)
  • GPIO_PIN_4 = HDMI Detect (Input / Active Low)

Note that this driver requires the most recent firmware (later than February 2017) and has been tested successfully with the firmware release from 17 March 2018.

The latest version of the firmware is available from https://github.com/raspberrypi/firmware

Constants



RPiGPIO expander specific constants RPIGPIOEXP_GPIO_*
RPIGPIOEXP_GPIO_DESCRIPTION = 'Raspberry Pi Firmware GPIO Expander'; Description of RPiGPIO Expander device
 
RPIGPIOEXP_GPIO_MIN_PIN = GPIO_PIN_0;  
RPIGPIOEXP_GPIO_MAX_PIN = GPIO_PIN_7;  
 
RPIGPIOEXP_GPIO_PIN_COUNT = 8;  
 
RPIGPIOEXP_GPIO_PIN_OFFSET = 128;  
 
RPIGPIOEXP_GPIO_MAX_LEVEL = GPIO_LEVEL_HIGH;  
 
RPIGPIOEXP_GPIO_MAX_PULL = GPIO_PULL_DOWN;  
 
RPIGPIOEXP_GPIO_MIN_FUNCTION = GPIO_FUNCTION_IN;  
RPIGPIOEXP_GPIO_MAX_FUNCTION = GPIO_FUNCTION_OUT;  


Type definitions



RPiGPIO expander specific types

PRPiGPIOExpander = ^TRPiGPIOExpander;

TRPiGPIOExpander = record

GPIO Properties
GPIO:TGPIODevice;  
RPiGPIO Expander Properties
   


Public variables


None defined

Function declarations



Initialization functions

procedure RPiGPIOExpanderInit;
Description: Initialize the RPiGPIO Expander unit and create, register and start the device
Note Called only during system startup


RPiGPIO expander GPIO functions

function RPiGPIOExpanderStart(GPIO:PGPIODevice):LongWord;
Description: Implementation of GPIODeviceStart API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceStart instead


function RPiGPIOExpanderStop(GPIO:PGPIODevice):LongWord;
Description: Implementation of GPIODeviceStop API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceStop instead


function RPiGPIOExpanderInputGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODeviceInputGet API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceInputGet instead


function RPiGPIOExpanderOutputSet(GPIO:PGPIODevice; Pin,Level:LongWord):LongWord;
Description: Implementation of GPIODeviceOutputSet API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceOutputSet instead


function RPiGPIOExpanderPullGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODevicePullGet API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODevicePullGet instead


function RPiGPIOExpanderPullSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Description: Implementation of GPIODevicePullSelect API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODevicePullSelect instead


function RPiGPIOExpanderFunctionGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODeviceFunctionGet API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceFunctionGet instead


function RPiGPIOExpanderFunctionSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Description: Implementation of GPIODeviceFunctionSelect API for RPiGPIO Expander
Note Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead


RTL virtual GPIO functions

function SysVirtualGPIOInputGet(Pin:LongWord):LongWord;
Description: Get the current state of a virtual GPIO input pin
Pin The pin to get the state for (eg VIRTUAL_GPIO_PIN_1)
Return The current state (eg GPIO_LEVEL_HIGH) or GPIO_LEVEL_UNKNOWN on failure


function SysVirtualGPIOOutputSet(Pin,Level:LongWord):LongWord;
Description: Set the state of a virtual GPIO output pin
Pin The pin to set the state for (eg GPIO_PIN_1)
Level The state to set the pin to (eg GPIO_LEVEL_HIGH)
Return ERROR_SUCCESS if completed successfully or another error code on failure


function SysVirtualGPIOFunctionGet(Pin:LongWord):LongWord;
Description: Get the current function of a virtual GPIO pin
Pin The pin to get the function for (eg GPIO_PIN_1)
Return The current function of the pin (eg GPIO_FUNCTION_IN) or GPIO_FUNCTION_UNKNOWN on failure


function SysVirtualGPIOFunctionSelect(Pin,Mode:LongWord):LongWord;
Description: Change the function of a virtual GPIO pin
Pin The pin to change the function for (eg GPIO_PIN_1)
Mode The function to set for the pin (eg GPIO_FUNCTION_OUT)
Return ERROR_SUCCESS if completed successfully or another error code on failure


RPiGPIO expander helper functions

function RPiGPIOExpanderGetState(GPIO:LongWord; var State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Get GPIO State
Note None documented


function RPiGPIOExpanderSetState(GPIO,State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Set GPIO State
Note None documented


function RPiGPIOExpanderGetConfig(GPIO:LongWord; var Direction,Polarity,Terminator,PullUp:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Get GPIO Config
Note None documented


function RPiGPIOExpanderSetConfig(GPIO,Direction,Polarity,Terminator,PullUp,State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Set GPIO Config
Note None documented


Return to Unit Reference