Difference between revisions of "Unit RPIGPIOEXPANDER"

From Ultibo.org
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
'''Raspberry Pi Firmware GPIO Expander Driver unit'''
 
'''Raspberry Pi Firmware GPIO Expander Driver unit'''
  
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.
+
As of February 2017 the Raspberry Pi firmware contains a mailbox interface to allow control of the GPIO expander on the Raspberry Pi 3/4 and Compute Module 3/4.
  
 
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.
 
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.
Line 13: Line 13:
 
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.
 
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.
+
When included in a project this driver replaces the Virtual GPIO functions provided by the PlatformRPi2, PlatformRPi3, PlatformRPi4 units.
 
    
 
    
 
According to /arch/arm/boot/dts/bcm2710-rpi-3-b.dts the following pin assignments are known:
 
According to /arch/arm/boot/dts/bcm2710-rpi-3-b.dts the following pin assignments are known:
Line 21: Line 21:
 
* GPIO_PIN_7 = Power LED (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:
+
For the Raspberry Pi 3B+ the assignments shown in /arch/arm/boot/dts/bcm2710-rpi-3-b.dts have changed as follows:
  
 
*GPIO_PIN_2 = Power LED (Active Low)
 
*GPIO_PIN_2 = Power LED (Active Low)
 
*GPIO_PIN_4 = HDMI Detect (Input / 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.
+
For the Raspberry Pi 4B the assignments shown in /arch/arm/boot/dts/bcm2711-rpi-4-b.dts are:
 +
 +
*GPIO_PIN_0 = Bluetooth Power (Active High) (BT_ON)
 +
*GPIO_PIN_1 = WiFi Power Sequencer (Active Low) (WL_ON)
 +
*GPIO_PIN_2 = Power LED (Active Low) (PWR_LED_OFF)
 +
*GPIO_PIN_3 = (GLOBAL_RESET) (ANT1 on CM4)
 +
*GPIO_PIN_4 = SDIO 1.8V regulator (Active High) (VDD_SD_IO_SEL)
 +
*GPIO_PIN_5 = CAM1 regulator (Active High) (CAM_GPIO)
 +
*GPIO_PIN_6 = SD VCC regulator (Active High) (SD_PWR_ON)
 +
*GPIO_PIN_7 = (SD_OC_N) (ANT2 on CM4)
 +
 
 +
The Pi 400 and CM4 files at bcm2711-rpi-400.dts and bcm2711-rpi-cm4.dts show identical assignments as the Pi 4B.
 +
 
 +
Note that this driver requires recent firmware (later than February 2017) and has been tested successfully with the firmware release from 8 October 2020.
 
   
 
   
 
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
Line 126: Line 139:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Called only during system startup
 
| Called only during system startup
 
|-
 
|-
Line 141: Line 154:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceStart instead
+
| Not intended to be called directly by applications, use GPIODeviceStart instead.
 
|-
 
|-
 
|}
 
|}
Line 153: Line 166:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceStop instead
+
| Not intended to be called directly by applications, use GPIODeviceStop instead.
 
|-
 
|-
 
|}
 
|}
Line 165: Line 178:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceInputGet instead
+
| Not intended to be called directly by applications, use GPIODeviceInputGet instead.
 
|-
 
|-
 
|}
 
|}
Line 177: Line 190:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceOutputSet instead
+
| Not intended to be called directly by applications, use GPIODeviceOutputSet instead.
 
|-
 
|-
 
|}
 
|}
Line 189: Line 202:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODevicePullGet instead
+
| Not intended to be called directly by applications, use GPIODevicePullGet instead.
 
|-
 
|-
 
|}
 
|}
Line 201: Line 214:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODevicePullSelect instead
+
| Not intended to be called directly by applications, use GPIODevicePullSelect instead.
 
|-
 
|-
 
|}
 
|}
Line 213: Line 226:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceFunctionGet instead
+
| Not intended to be called directly by applications, use GPIODeviceFunctionGet instead.
 
|-
 
|-
 
|}
 
|}
Line 225: Line 238:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead
+
| Not intended to be called directly by applications, use GPIODeviceFunctionSelect instead.
 
|-
 
|-
 
|}
 
|}
Line 240: Line 253:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Pin'''
+
! Pin
 
| The pin to get the state for (eg VIRTUAL_GPIO_PIN_1)
 
| The pin to get the state for (eg VIRTUAL_GPIO_PIN_1)
 
|-
 
|-
! '''Return'''
+
! Return
 
| The current state (eg GPIO_LEVEL_HIGH) or GPIO_LEVEL_UNKNOWN on failure
 
| The current state (eg GPIO_LEVEL_HIGH) or GPIO_LEVEL_UNKNOWN on failure
 
|-
 
|-
Line 255: Line 268:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Pin'''
+
! Pin
 
| The pin to set the state for (eg GPIO_PIN_1)
 
| The pin to set the state for (eg GPIO_PIN_1)
 
|-
 
|-
! '''Level'''
+
! Level
 
| The state to set the pin to (eg GPIO_LEVEL_HIGH)
 
| The state to set the pin to (eg GPIO_LEVEL_HIGH)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed successfully or another error code on failure
 
| ERROR_SUCCESS if completed successfully or another error code on failure
 
|-
 
|-
Line 273: Line 286:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Pin'''
+
! Pin
 
| The pin to get the function for (eg GPIO_PIN_1)
 
| The pin to get the function for (eg GPIO_PIN_1)
 
|-
 
|-
! '''Return'''
+
! Return
 
| The current function of the pin (eg GPIO_FUNCTION_IN) or GPIO_FUNCTION_UNKNOWN on failure
 
| The current function of the pin (eg GPIO_FUNCTION_IN) or GPIO_FUNCTION_UNKNOWN on failure
 
|-
 
|-
Line 288: Line 301:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Pin'''
+
! Pin
 
| The pin to change the function for (eg GPIO_PIN_1)
 
| The pin to change the function for (eg GPIO_PIN_1)
 
|-
 
|-
! '''Mode'''
+
! Mode
 
| The function to set for the pin (eg GPIO_FUNCTION_OUT)
 
| The function to set for the pin (eg GPIO_FUNCTION_OUT)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed successfully or another error code on failure
 
| ERROR_SUCCESS if completed successfully or another error code on failure
 
|-
 
|-
Line 309: Line 322:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 321: Line 334:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 333: Line 346:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 345: Line 358:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-

Latest revision as of 05:19, 17 June 2021

Return to Unit Reference


Description


Raspberry Pi Firmware GPIO Expander Driver unit

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

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, PlatformRPi3, PlatformRPi4 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 shown 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)

For the Raspberry Pi 4B the assignments shown in /arch/arm/boot/dts/bcm2711-rpi-4-b.dts are:

  • GPIO_PIN_0 = Bluetooth Power (Active High) (BT_ON)
  • GPIO_PIN_1 = WiFi Power Sequencer (Active Low) (WL_ON)
  • GPIO_PIN_2 = Power LED (Active Low) (PWR_LED_OFF)
  • GPIO_PIN_3 = (GLOBAL_RESET) (ANT1 on CM4)
  • GPIO_PIN_4 = SDIO 1.8V regulator (Active High) (VDD_SD_IO_SEL)
  • GPIO_PIN_5 = CAM1 regulator (Active High) (CAM_GPIO)
  • GPIO_PIN_6 = SD VCC regulator (Active High) (SD_PWR_ON)
  • GPIO_PIN_7 = (SD_OC_N) (ANT2 on CM4)

The Pi 400 and CM4 files at bcm2711-rpi-400.dts and bcm2711-rpi-cm4.dts show identical assignments as the Pi 4B.

Note that this driver requires recent firmware (later than February 2017) and has been tested successfully with the firmware release from 8 October 2020.

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

Constants



[Expand]
RPiGPIO expander specific constants RPIGPIOEXP_GPIO_*


Type definitions



RPiGPIO expander specific types

[Expand]

PRPiGPIOExpander = ^TRPiGPIOExpander;

TRPiGPIOExpander = record


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure RPiGPIOExpanderInit;
Description: Initialize the RPiGPIO Expander unit and create, register and start the device


RPiGPIO expander GPIO functions

[Expand]
function RPiGPIOExpanderStart(GPIO:PGPIODevice):LongWord;
Description: Implementation of GPIODeviceStart API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderStop(GPIO:PGPIODevice):LongWord;
Description: Implementation of GPIODeviceStop API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderInputGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODeviceInputGet API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderOutputSet(GPIO:PGPIODevice; Pin,Level:LongWord):LongWord;
Description: Implementation of GPIODeviceOutputSet API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderPullGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODevicePullGet API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderPullSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Description: Implementation of GPIODevicePullSelect API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderFunctionGet(GPIO:PGPIODevice; Pin:LongWord):LongWord;
Description: Implementation of GPIODeviceFunctionGet API for RPiGPIO Expander


[Expand]
function RPiGPIOExpanderFunctionSelect(GPIO:PGPIODevice; Pin,Mode:LongWord):LongWord;
Description: Implementation of GPIODeviceFunctionSelect API for RPiGPIO Expander


RTL virtual GPIO functions

[Expand]
function SysVirtualGPIOInputGet(Pin:LongWord):LongWord;
Description: Get the current state of a virtual GPIO input pin


[Expand]
function SysVirtualGPIOOutputSet(Pin,Level:LongWord):LongWord;
Description: Set the state of a virtual GPIO output pin


[Expand]
function SysVirtualGPIOFunctionGet(Pin:LongWord):LongWord;
Description: Get the current function of a virtual GPIO pin


[Expand]
function SysVirtualGPIOFunctionSelect(Pin,Mode:LongWord):LongWord;
Description: Change the function of a virtual GPIO pin


RPiGPIO expander helper functions

[Expand]
function RPiGPIOExpanderGetState(GPIO:LongWord; var State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Get GPIO State


[Expand]
function RPiGPIOExpanderSetState(GPIO,State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Set GPIO State


[Expand]
function RPiGPIOExpanderGetConfig(GPIO:LongWord; var Direction,Polarity,Terminator,PullUp:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Get GPIO Config


[Expand]
function RPiGPIOExpanderSetConfig(GPIO,Direction,Polarity,Terminator,PullUp,State:LongWord):LongWord;
Description: Raspberry Pi Firmware Mailbox call for Set GPIO Config


Return to Unit Reference