Unit RPISENSEHAT

From Ultibo.org
Jump to: navigation, search

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



[Expand]
RPiSenseHat specific constants RPISENSE_*


[Expand]
Framebuffer RPISENSE_FRAMEBUFFER_*


[Expand]
Joystick RPISENSE_JOYSTICK_*


[Expand]
RPiSenseHat register value RPISENSE_FB*


[Expand]
RPiSenseHat gamma reset value RPISENSE_GAMMA_*


Type definitions



RPi sense

[Expand]

PRPiSense = ^TRPiSense;

TRPiSense = record

RPi sense gamma

[Expand]

PRPiSenseGamma = ^TRPiSenseGamma;

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

RPi sense framebuffer

[Expand]

PRPiSenseFramebuffer = ^TRPiSenseFramebuffer;

TRPiSenseFramebuffer = record

RPi sense joystick

[Expand]

PRPiSenseJoystick = ^TRPiSenseJoystick;

TRPiSenseJoystick = record


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

[Expand]
procedure RPiSenseInit;
Description: Initialize the RPiSenseHat unit and parameters


[Expand]
function RPiSenseStart(const I2CDevice,GPIODevice:String; Rotation,Width,Height:LongWord):THandle;
Description: Start the RPiSenseHat driver and register the Framebuffer and Joystick devices


[Expand]
function RPiSenseStop(Handle:THandle):Boolean;
Description: Stop the RPiSenseHat driver and deregister the Framebuffer and Joystick devices


RPiSenseHat framebuffer functions

[Expand]
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


[Expand]
function RPiSenseFramebufferDestroy(Framebuffer:PFramebufferDevice):LongWord;
Description: Release, deregister and destroy an RPiSenseHat Framebuffer device created by this driver}


[Expand]
function RPiSenseFramebufferAllocate(Framebuffer:PFramebufferDevice; Properties:PFramebufferProperties):LongWord;
Description: Implementation of FramebufferDeviceAllocate API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferRelease(Framebuffer:PFramebufferDevice):LongWord;
Description: Implementation of FramebufferDeviceRelease API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferBlank(Framebuffer:PFramebufferDevice; Blank:Boolean):LongWord;
Description: Implementation of FramebufferDevicBlank API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferMark(Framebuffer:PFramebufferDevice; X,Y,Width,Height,Flags:LongWord):LongWord;
Description: Implementation of FramebufferDeviceMark API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferCommit(Framebuffer:PFramebufferDevice; Address:PtrUInt; Size,Flags:LongWord):LongWord;
Description: Implementation of FramebufferDeviceCommit API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferSetOffset(Framebuffer:PFramebufferDevice; X,Y:LongWord; Pan:Boolean):LongWord;
Description: Implementation of FramebufferDeviceSetOffset API for RPiSenseHat Framebuffer


[Expand]
function RPiSenseFramebufferGetGamma(Framebuffer:PFramebufferDevice; var Gamma:TRPiSenseGamma):LongWord;
Description: Get the current gamma values from the RPiSenseHat framebuffer


[Expand]
function RPiSenseFramebufferSetGamma(Framebuffer:PFramebufferDevice; const Gamma:TRPiSenseGamma):LongWord;
Description: Set the current gamma values for the RPiSenseHat framebuffer


[Expand]
function RPiSenseFramebufferResetGamma(Framebuffer:PFramebufferDevice; Value:LongWord):LongWord;
Description: Reset the current gamma values for the RPiSenseHat framebuffer to Default, Low or User


[Expand]
function RPiSenseFramebufferSetRotation(Framebuffer:PFramebufferDevice; Rotation:LongWord):LongWord;
Description: To be documented


[Expand]
procedure RPiSenseFramebufferUpdateDisplay(Framebuffer:PRPiSenseFramebuffer);
Description: Timer function for RPiSenseHat framebuffer dirty region redraw


RPiSenseHat joystick functions

[Expand]
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


[Expand]
function RPiSenseJoystickDestroy(Joystick:PKeyboardDevice):LongWord;
Description: Detach, deregister and destroy a RPiSenseHat Joystick device created by this driver


[Expand]
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


RPiSenseHat helper functions

[Expand]
function RPiSenseRegRead(I2C:PI2CDevice; Address:Word; Reg:Byte):LongInt;
Description: Read a byte from an RPiSenseHat register


[Expand]
function RPiSenseBlockWrite(I2C:PI2CDevice; Address:Word; Data:PByte; Size:Integer):LongWord;
Description: Write a block of data to the RPiSenseHat


Return to Unit Reference