Difference between revisions of "Unit RPISENSEHAT"

From Ultibo.org
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
'''Raspberry Pi SenstHat Driver unit'''
+
'''Raspberry Pi Sense HAT Driver unit'''
 
   
 
   
The SenseHAT 8x8 LED matrix is presented in Ultibo as an 8x8 pixel framebuffer. This allows full access to the display at both the individual pixel level and also using the higher level console functions to display text and graphics on the matrix.
+
The Sense HAT 8x8 LED matrix is presented in Ultibo as an 8x8 pixel framebuffer. This allows full access to the display at both the individual pixel level and also using the higher level console functions to display text and graphics on the matrix.
 
    
 
    
The framebuffer device supports rotation around the full 360 degrees by supplying the required rotation value in the framebuffer properties when calling FramebufferAllocate() or by calling the SenseHAT specific function RPiSenseFramebufferSetRotation().
+
The framebuffer device supports rotation around the full 360 degrees by supplying the required rotation value in the framebuffer properties when calling FramebufferAllocate() or by calling the Sense HAT specific function RPiSenseFramebufferSetRotation().
 
   
 
   
 
As per the official Python libraries, the default rotation (FRAMEBUFFER_ROTATION_0) gives correct viewing when the HDMI port is facing downwards.
 
As per the official Python libraries, the default rotation (FRAMEBUFFER_ROTATION_0) gives correct viewing when the HDMI port is facing downwards.
 
   
 
   
The SenseHAT joystick appears as a keyboard device and the pressed buttons are received as key presses that represent the Left, Right, Up, Down and Enter keys.
+
The Sense HAT joystick appears as a keyboard device and the pressed buttons are received as key presses that represent the Left, Right, Up, Down and Enter keys.
  
 
=== Constants ===
 
=== Constants ===
Line 123: Line 123:
 
----
 
----
  
''To be documented''
+
 
 +
'''RPi sense'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PRPiSense = ^TRPiSense;</code>
 +
 
 +
<code>TRPiSense = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Signature:LongWord;</code>
 +
| Signature for entry validation
 +
|-
 +
| <code>I2C:PI2CDevice;</code>
 +
| I2C device
 +
|-
 +
| <code>GPIO:PGPIODevice;</code>
 +
| GPIO device
 +
|-
 +
| <code>Framebuffer:PFramebufferDevice;</code>
 +
| Framebuffer device
 +
|-
 +
| <code>Joystick:PKeyboardDevice;</code>
 +
| Joystick (Keyboard) device
 +
|-
 +
|}
 +
</div></div>
 +
 +
'''RPi sense gamma'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PRPiSenseGamma = ^TRPiSenseGamma;</code>
 +
 
 +
<code>TRPiSenseGamma = array[0..31] of Byte;</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| &nbsp;
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''RPi sense framebuffer'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PRPiSenseFramebuffer = ^TRPiSenseFramebuffer;</code>
 +
 
 +
<code>TRPiSenseFramebuffer = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Framebuffer Properties''
 +
|-
 +
| <code>Framebuffer:TFramebufferDevice;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''RPiSense Properties''
 +
|-
 +
| <code>I2C:PI2CDevice;</code>
 +
| The I2C device the device is connected to
 +
|-
 +
| <code>Width:LongWord;</code>
 +
| Framebuffer Width in Pixels (Virtual)
 +
|-
 +
| <code>Height:LongWord;</code>
 +
| Framebuffer Height in Pixels (Virtual)
 +
|-
 +
| <code>Rotation:LongWord;</code>
 +
| Framebuffer Rotation (eg FRAMEBUFFER_ROTATION_180)
 +
|-
 +
| <code>DirtyY1:LongWord;</code>
 +
| First line of dirty region (or Height - 1 if none dirty)
 +
|-
 +
| <code>DirtyY2:LongWord;</code>
 +
| Last line of dirty region (or 0 if none dirty)
 +
|-
 +
| <code>Ready:LongBool;</code>
 +
| If True timer should be enabled during Mark operation
 +
|-
 +
| <code>Blank:LongBool;</code>
 +
| If True then display is currently blanked
 +
|-
 +
| <code>Lock:TMutexHandle;</code>
 +
| Lock for dirty region redraw
 +
|-
 +
| <code>Timer:TTimerHandle;</code>
 +
| Handle for dirty region redraw timer
 +
|-
 +
| <code>FrameRate:LongWord;</code>
 +
| Frame rate for display refresh (in Frames Per Second)
 +
|-
 +
| <code>Gamma:TRPiSenseGamma;</code>
 +
| Current gamma values
 +
|-
 +
| <code>GammaUser:TRPiSenseGamma;</code>
 +
| User gamma values
 +
|-
 +
| <code>PixelData:array[0..63] of Word;</code>
 +
| Pixel data for framebuffer update
 +
|-
 +
| <code>BlockData:array[0..192] of Byte;</code>
 +
| Block data for display update
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''RPi sense joystick'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PRPiSenseJoystick = ^TRPiSenseJoystick;</code>
 +
 
 +
<code>TRPiSenseJoystick = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Keyboard Properties''
 +
|-
 +
| <code>Keyboard:TKeyboardDevice;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''RPiSense Properties''
 +
|-
 +
| <code>I2C:PI2CDevice;</code>
 +
| The I2C device the device is connected to
 +
|-
 +
| <code>GPIO:PGPIODevice;</code>
 +
| The GPIO device the device is connected to
 +
|-
 +
| <code>Pin:LongWord;</code>
 +
| The GPIO pin used to signal joystick events (GPIO_PIN_23)
 +
|-
 +
| <code>Trigger:LongWord;</code>
 +
| The GPIO trigger to detect joystick events (GPIO_TRIGGER_RISING)
 +
|-
 +
| <code>PreviousKeys:LongInt;</code>
 +
| The keys pressed on the last GPIO event callback
 +
|-
 +
|colspan="2"|''Statistics Properties''
 +
|-
 +
| <code>CallbackCount:LongWord;</code>
 +
| Number of callback requests received by the device
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
Line 196: Line 341:
 
----
 
----
  
''To be documented''
 
  
 +
'''Initialization 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;">procedure RPiSenseInit;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the RPiSenseHat unit and parameters</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Called only during system startup
 +
|-
 +
|}
 +
</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 RPiSenseStart(const I2CDevice,GPIODevice:String; Rotation,Width,Height:LongWord):THandle;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Start the RPiSenseHat driver and register the Framebuffer and Joystick devices</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! I2C
 +
| The name of the I2C device that the Sense HAT is connected to
 +
|-
 +
! GPIO
 +
| The name of the GPIO device that the Sense HAT is connected to
 +
|-
 +
! Rotation
 +
| The rotation value of the framebuffer (eg FRAMEBUFFER_ROTATION_180)
 +
|-
 +
! Width
 +
| The width of the framebuffer in pixels (Virtual width only, the Physical width is fixed at 8 pixels)
 +
|-
 +
! Height
 +
| The height of the framebuffer in pixels (Virtual height only, the Physical height is fixed at 8 pixels)
 +
|-
 +
! Return
 +
| The handle of the RPiSenseHat on success or INVALID_HANDLE_VALUE on failure
 +
|-
 +
! Note
 +
| This function will be called during startup if the parameter RPISENSE_AUTOSTART is True
 +
|-
 +
|}
 +
</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 RPiSenseStop(Handle:THandle):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Stop the RPiSenseHat driver and deregister the Framebuffer and Joystick devices</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Handle
 +
| The handle of the RPiSenseHat or INVALID_HANDLE_VALUE for the default
 +
|-
 +
! Return
 +
| True if completed or False on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''RPiSenseHat framebuffer 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 RPiSenseFramebufferCreate(I2C:PI2CDevice; const Name:String; Rotation,Width,Height:LongWord):PFramebufferDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create, register and allocate a new RPiSenseHat Framebuffer device which can be accessed using the framebuffer API</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 that the RPiSenseHat is connected to
 +
|-
 +
! Name
 +
| The text description of this device which will show in the device list (Optional)
 +
|-
 +
! Rotation
 +
| The rotation value of the framebuffer (eg FRAMEBUFFER_ROTATION_180)
 +
|-
 +
! Width
 +
| The width of the framebuffer in pixels (Virtual width only, the Physical width is fixed at 8 pixels)
 +
|-
 +
! Height
 +
| The height of the framebuffer in pixels (Virtual height only, the Physical height is fixed at 8 pixels)
 +
|-
 +
! Return
 +
| Pointer to the new Framebuffer device or nil if the framebuffer device 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 RPiSenseFramebufferDestroy(Framebuffer:PFramebufferDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Release, deregister and destroy an RPiSenseHat Framebuffer 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;"
 +
|-
 +
! Framebuffer
 +
| The Framebuffer device 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 RPiSenseFramebufferAllocate(Framebuffer:PFramebufferDevice; Properties:PFramebufferProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDeviceAllocate API for RPiSenseHat Framebuffer</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 FramebufferDeviceAllocate 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 RPiSenseFramebufferRelease(Framebuffer:PFramebufferDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDeviceRelease API for RPiSenseHat Framebuffer</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 FramebufferDeviceRelease 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 RPiSenseFramebufferBlank(Framebuffer:PFramebufferDevice; Blank:Boolean):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDevicBlank API for RPiSenseHat Framebuffer</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 FramebufferDevicBlank 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 RPiSenseFramebufferMark(Framebuffer:PFramebufferDevice; X,Y,Width,Height,Flags:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDeviceMark API for RPiSenseHat Framebuffer</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 FramebufferDeviceMark instead.
 +
Marks full lines only, X and Width are ignored for RPiSenseHat Framebuffer
 +
|-
 +
|}
 +
</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 RPiSenseFramebufferCommit(Framebuffer:PFramebufferDevice; Address:PtrUInt; Size,Flags:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDeviceCommit API for RPiSenseHat Framebuffer</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 FramebufferDeviceCommit 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 RPiSenseFramebufferSetOffset(Framebuffer:PFramebufferDevice; X,Y:LongWord; Pan:Boolean):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of FramebufferDeviceSetOffset API for RPiSenseHat Framebuffer</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 FramebufferDeviceSetOffset 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 RPiSenseFramebufferGetGamma(Framebuffer:PFramebufferDevice; var Gamma:TRPiSenseGamma):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current gamma values from the RPiSenseHat framebuffer</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Framebuffer
 +
| The Framebuffer device to get from
 +
|-
 +
! Gamma
 +
| An array of gamma values returned on completion
 +
|-
 +
! 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 RPiSenseFramebufferSetGamma(Framebuffer:PFramebufferDevice; const Gamma:TRPiSenseGamma):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the current gamma values for the RPiSenseHat framebuffer</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Framebuffer
 +
| The Framebuffer device to set for
 +
|-
 +
! Gamma
 +
| An array of gamma values 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 RPiSenseFramebufferResetGamma(Framebuffer:PFramebufferDevice; Value:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Reset the current gamma values for the RPiSenseHat framebuffer to Default, Low or User</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Framebuffer
 +
| The Framebuffer device to set for
 +
|-
 +
! Value
 +
| The gamma values to set (0 = Default / 1 = Low / 2 = User)
 +
|-
 +
! 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 RPiSenseFramebufferSetRotation(Framebuffer:PFramebufferDevice; Rotation:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;">procedure RPiSenseFramebufferUpdateDisplay(Framebuffer:PRPiSenseFramebuffer);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Timer function for RPiSenseHat framebuffer dirty region redraw</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
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''RPiSenseHat joystick 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 RPiSenseJoystickCreate(I2C:PI2CDevice; GPIO:PGPIODevice; const Name:String):PKeyboardDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create, register and attach a new RPiSenseHat Joystick device which can be accessed using the keyboard API</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 that the RPiSenseHat is connected to
 +
|-
 +
! GPIO
 +
| The GPIO device that the RPiSenseHat is connected to
 +
|-
 +
! Name
 +
| The text description of this device which will show in the device list (Optional)
 +
|-
 +
! Return
 +
| Pointer to the new Joystick (Keyboard) device or nil if the device 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 RPiSenseJoystickDestroy(Joystick:PKeyboardDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Detach, deregister and destroy a RPiSenseHat Joystick 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;"
 +
|-
 +
! Joystick
 +
| The Joystick (Keyboard) device 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;">procedure RPiSenseJoystickCallback(Joystick:PRPiSenseJoystick; Pin,Trigger:LongWord);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Callback function for the RPiSenseHat Joystick device, called on a worker thread when the registered GPIO event is triggered by a rising edge on the specified pin</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
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''RPiSenseHat helper 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 RPiSenseRegRead(I2C:PI2CDevice; Address:Word; Reg:Byte):LongInt;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read a byte from an RPiSenseHat register</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 the RPiSenseHat is connected to
 +
|-
 +
! Address
 +
| The I2C address of the RPiSenseHat
 +
|-
 +
! Reg
 +
| The register to read
 +
|-
 +
! Return
 +
| The register value on success or -1 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 RPiSenseBlockWrite(I2C:PI2CDevice; Address:Word; Data:PByte; Size:Integer):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write a block of data to the RPiSenseHat</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 the RPiSenseHat is connected to
 +
|-
 +
! Address
 +
| The I2C address of the RPiSenseHat
 +
|-
 +
! Data
 +
| Pointer to the data block to be written
 +
|-
 +
! Size
 +
| Size of the data block in bytes
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
Return to [[Unit_Reference|Unit Reference]]
 
Return to [[Unit_Reference|Unit Reference]]

Latest revision as of 05:07, 23 November 2022

Return to Unit Reference


Description


Raspberry Pi Sense HAT Driver unit

The Sense HAT 8x8 LED matrix is presented in Ultibo as an 8x8 pixel framebuffer. This allows full access to the display at both the individual pixel level and also using the higher level console functions to display text and graphics on the matrix.

The framebuffer device supports rotation around the full 360 degrees by supplying the required rotation value in the framebuffer properties when calling FramebufferAllocate() or by calling the Sense HAT specific function RPiSenseFramebufferSetRotation().

As per the official Python libraries, the default rotation (FRAMEBUFFER_ROTATION_0) gives correct viewing when the HDMI port is facing downwards.

The Sense HAT joystick appears as a keyboard device and the pressed buttons are received as key presses that represent the Left, Right, Up, Down and Enter keys.

Constants



RPiSenseHat specific constants RPISENSE_*
RPISENSE_SIGNATURE = $EAEBECED;  


Framebuffer RPISENSE_FRAMEBUFFER_*
RPISENSE_FRAMEBUFFER_DESCRIPTION = 'Raspberry Pi Sense HAT Framebuffer'; Description of RPiSense framebuffer device
 
RPISENSE_PHYSICAL_WIDTH = 8;  
RPISENSE_PHYSICAL_HEIGHT = 8;  


Joystick RPISENSE_JOYSTICK_*
RPISENSE_JOYSTICK_DESCRIPTION = 'Raspberry Pi Sense HAT Joystick'; Description of RPiSense joystick device
 
RPISENSE_JOYSTICK_KEYMAP:array[0..4] of Word = (
SCAN_CODE_DOWN_ARROW,  
SCAN_CODE_RIGHT_ARROW,  
SCAN_CODE_UP_ARROW,  
SCAN_CODE_ENTER,  
SCAN_CODE_LEFT_ARROW  


RPiSenseHat register value RPISENSE_FB*
RPISENSE_FB = $00;  
RPISENSE_WAI = $F0;  
RPISENSE_VER = $F1;  
RPISENSE_KEYS = $F2;  
RPISENSE_EE_WP = $F3;  


RPiSenseHat gamma reset value RPISENSE_GAMMA_*
RPISENSE_GAMMA_VALUES_DEFAULT = 0;  
RPISENSE_GAMMA_VALUES_LOW = 1;  
RPISENSE_GAMMA_VALUES_USER = 2;  


Type definitions



RPi sense

PRPiSense = ^TRPiSense;

TRPiSense = record

Signature:LongWord; Signature for entry validation
I2C:PI2CDevice; I2C device
GPIO:PGPIODevice; GPIO device
Framebuffer:PFramebufferDevice; Framebuffer device
Joystick:PKeyboardDevice; Joystick (Keyboard) device

RPi sense gamma

PRPiSenseGamma = ^TRPiSenseGamma;

TRPiSenseGamma = array[0..31] of Byte;

   

RPi sense framebuffer

PRPiSenseFramebuffer = ^TRPiSenseFramebuffer;

TRPiSenseFramebuffer = record

Framebuffer Properties
Framebuffer:TFramebufferDevice;  
RPiSense Properties
I2C:PI2CDevice; The I2C device the device is connected to
Width:LongWord; Framebuffer Width in Pixels (Virtual)
Height:LongWord; Framebuffer Height in Pixels (Virtual)
Rotation:LongWord; Framebuffer Rotation (eg FRAMEBUFFER_ROTATION_180)
DirtyY1:LongWord; First line of dirty region (or Height - 1 if none dirty)
DirtyY2:LongWord; Last line of dirty region (or 0 if none dirty)
Ready:LongBool; If True timer should be enabled during Mark operation
Blank:LongBool; If True then display is currently blanked
Lock:TMutexHandle; Lock for dirty region redraw
Timer:TTimerHandle; Handle for dirty region redraw timer
FrameRate:LongWord; Frame rate for display refresh (in Frames Per Second)
Gamma:TRPiSenseGamma; Current gamma values
GammaUser:TRPiSenseGamma; User gamma values
PixelData:array[0..63] of Word; Pixel data for framebuffer update
BlockData:array[0..192] of Byte; Block data for display update

RPi sense joystick

PRPiSenseJoystick = ^TRPiSenseJoystick;

TRPiSenseJoystick = record

Keyboard Properties
Keyboard:TKeyboardDevice;  
RPiSense Properties
I2C:PI2CDevice; The I2C device the device is connected to
GPIO:PGPIODevice; The GPIO device the device is connected to
Pin:LongWord; The GPIO pin used to signal joystick events (GPIO_PIN_23)
Trigger:LongWord; The GPIO trigger to detect joystick events (GPIO_TRIGGER_RISING)
PreviousKeys:LongInt; The keys pressed on the last GPIO event callback
Statistics Properties
CallbackCount:LongWord; Number of callback requests received by the device


Public variables



RPiSenseHat specific variables

RPISENSE_I2C_DEVICE:String = 'I2C0';
RPISENSE_GPIO_DEVICE:String = 'GPIO0';
RPISENSE_FRAMEBUFFER_ROTATION:LongWord = FRAMEBUFFER_ROTATION_0;
RPISENSE_FRAMEBUFFER_WIDTH:LongWord = RPISENSE_PHYSICAL_WIDTH;
RPISENSE_FRAMEBUFFER_HEIGHT:LongWord = RPISENSE_PHYSICAL_HEIGHT;
RPISENSE_I2C_ADDRESS:Word = $46;
RPISENSE_LSM9DS1_MAGN_ADDRESS:Word = $1C;
RPISENSE_LSM9DS1_ACCEL_ADDRESS:Word = $6A;
RPISENSE_LPS25H_PRESS_ADDRESS:Word = $5C;
RPISENSE_HTS221_HUMID_ADDRESS:Word = $5F;


Function declarations



Initialization functions

procedure RPiSenseInit;
Description: Initialize the RPiSenseHat unit and parameters
Note Called only during system startup


function RPiSenseStart(const I2CDevice,GPIODevice:String; Rotation,Width,Height:LongWord):THandle;
Description: Start the RPiSenseHat driver and register the Framebuffer and Joystick devices
I2C The name of the I2C device that the Sense HAT is connected to
GPIO The name of the GPIO device that the Sense HAT is connected to
Rotation The rotation value of the framebuffer (eg FRAMEBUFFER_ROTATION_180)
Width The width of the framebuffer in pixels (Virtual width only, the Physical width is fixed at 8 pixels)
Height The height of the framebuffer in pixels (Virtual height only, the Physical height is fixed at 8 pixels)
Return The handle of the RPiSenseHat on success or INVALID_HANDLE_VALUE on failure
Note This function will be called during startup if the parameter RPISENSE_AUTOSTART is True


function RPiSenseStop(Handle:THandle):Boolean;
Description: Stop the RPiSenseHat driver and deregister the Framebuffer and Joystick devices
Handle The handle of the RPiSenseHat or INVALID_HANDLE_VALUE for the default
Return True if completed or False on failure


RPiSenseHat framebuffer functions

function RPiSenseFramebufferCreate(I2C:PI2CDevice; const Name:String; Rotation,Width,Height:LongWord):PFramebufferDevice;
Description: Create, register and allocate a new RPiSenseHat Framebuffer device which can be accessed using the framebuffer API
I2C The I2C device that the RPiSenseHat is connected to
Name The text description of this device which will show in the device list (Optional)
Rotation The rotation value of the framebuffer (eg FRAMEBUFFER_ROTATION_180)
Width The width of the framebuffer in pixels (Virtual width only, the Physical width is fixed at 8 pixels)
Height The height of the framebuffer in pixels (Virtual height only, the Physical height is fixed at 8 pixels)
Return Pointer to the new Framebuffer device or nil if the framebuffer device could not be created


function RPiSenseFramebufferDestroy(Framebuffer:PFramebufferDevice):LongWord;
Description: Release, deregister and destroy an RPiSenseHat Framebuffer device created by this driver}
Framebuffer The Framebuffer device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


function RPiSenseFramebufferAllocate(Framebuffer:PFramebufferDevice; Properties:PFramebufferProperties):LongWord;
Description: Implementation of FramebufferDeviceAllocate API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDeviceAllocate instead.


function RPiSenseFramebufferRelease(Framebuffer:PFramebufferDevice):LongWord;
Description: Implementation of FramebufferDeviceRelease API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDeviceRelease instead.


function RPiSenseFramebufferBlank(Framebuffer:PFramebufferDevice; Blank:Boolean):LongWord;
Description: Implementation of FramebufferDevicBlank API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDevicBlank instead.


function RPiSenseFramebufferMark(Framebuffer:PFramebufferDevice; X,Y,Width,Height,Flags:LongWord):LongWord;
Description: Implementation of FramebufferDeviceMark API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDeviceMark instead.

Marks full lines only, X and Width are ignored for RPiSenseHat Framebuffer


function RPiSenseFramebufferCommit(Framebuffer:PFramebufferDevice; Address:PtrUInt; Size,Flags:LongWord):LongWord;
Description: Implementation of FramebufferDeviceCommit API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDeviceCommit instead.


function RPiSenseFramebufferSetOffset(Framebuffer:PFramebufferDevice; X,Y:LongWord; Pan:Boolean):LongWord;
Description: Implementation of FramebufferDeviceSetOffset API for RPiSenseHat Framebuffer
Note Not intended to be called directly by applications, use FramebufferDeviceSetOffset instead.


function RPiSenseFramebufferGetGamma(Framebuffer:PFramebufferDevice; var Gamma:TRPiSenseGamma):LongWord;
Description: Get the current gamma values from the RPiSenseHat framebuffer
Framebuffer The Framebuffer device to get from
Gamma An array of gamma values returned on completion
Return ERROR_SUCCESS if completed or another error code on failure


function RPiSenseFramebufferSetGamma(Framebuffer:PFramebufferDevice; const Gamma:TRPiSenseGamma):LongWord;
Description: Set the current gamma values for the RPiSenseHat framebuffer
Framebuffer The Framebuffer device to set for
Gamma An array of gamma values to set
Return ERROR_SUCCESS if completed or another error code on failure


function RPiSenseFramebufferResetGamma(Framebuffer:PFramebufferDevice; Value:LongWord):LongWord;
Description: Reset the current gamma values for the RPiSenseHat framebuffer to Default, Low or User
Framebuffer The Framebuffer device to set for
Value The gamma values to set (0 = Default / 1 = Low / 2 = User)
Return ERROR_SUCCESS if completed or another error code on failure


function RPiSenseFramebufferSetRotation(Framebuffer:PFramebufferDevice; Rotation:LongWord):LongWord;
Description: To be documented
Note None documented


procedure RPiSenseFramebufferUpdateDisplay(Framebuffer:PRPiSenseFramebuffer);
Description: Timer function for RPiSenseHat framebuffer dirty region redraw
Note Not intended to be called directly by applications


RPiSenseHat joystick functions

function RPiSenseJoystickCreate(I2C:PI2CDevice; GPIO:PGPIODevice; const Name:String):PKeyboardDevice;
Description: Create, register and attach a new RPiSenseHat Joystick device which can be accessed using the keyboard API
I2C The I2C device that the RPiSenseHat is connected to
GPIO The GPIO device that the RPiSenseHat is connected to
Name The text description of this device which will show in the device list (Optional)
Return Pointer to the new Joystick (Keyboard) device or nil if the device could not be created


function RPiSenseJoystickDestroy(Joystick:PKeyboardDevice):LongWord;
Description: Detach, deregister and destroy a RPiSenseHat Joystick device created by this driver
Joystick The Joystick (Keyboard) device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


procedure RPiSenseJoystickCallback(Joystick:PRPiSenseJoystick; Pin,Trigger:LongWord);
Description: Callback function for the RPiSenseHat Joystick device, called on a worker thread when the registered GPIO event is triggered by a rising edge on the specified pin
Note Not intended to be called directly by applications


RPiSenseHat helper functions

function RPiSenseRegRead(I2C:PI2CDevice; Address:Word; Reg:Byte):LongInt;
Description: Read a byte from an RPiSenseHat register
I2C The I2C device the RPiSenseHat is connected to
Address The I2C address of the RPiSenseHat
Reg The register to read
Return The register value on success or -1 on failure


function RPiSenseBlockWrite(I2C:PI2CDevice; Address:Word; Data:PByte; Size:Integer):LongWord;
Description: Write a block of data to the RPiSenseHat
I2C The I2C device the RPiSenseHat is connected to
Address The I2C address of the RPiSenseHat
Data Pointer to the data block to be written
Size Size of the data block in bytes
Return ERROR_SUCCESS if completed or another error code on failure


Return to Unit Reference