Difference between revisions of "Unit RPISENSEHAT"
Line 5: | Line 5: | ||
---- | ---- | ||
− | '''Raspberry Pi | + | '''Raspberry Pi Sense HAT Driver unit''' |
− | The | + | 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 SenseHAT specific function RPiSenseFramebufferSetRotation(). | ||
Line 13: | Line 13: | ||
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 | + | 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 === |
Revision as of 05:49, 5 May 2018
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 SenseHAT 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
RPISENSE_*
RPISENSE_SIGNATURE = $EAEBECED;
|
RPISENSE_FRAMEBUFFER_*
RPISENSE_FRAMEBUFFER_DESCRIPTION = 'Raspberry Pi Sense HAT Framebuffer';
|
Description of RPiSense framebuffer device |
RPISENSE_PHYSICAL_WIDTH = 8;
|
|
RPISENSE_PHYSICAL_HEIGHT = 8;
|
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
|
RPISENSE_FB*
RPISENSE_FB = $00;
|
|
RPISENSE_WAI = $F0;
|
|
RPISENSE_VER = $F1;
|
|
RPISENSE_KEYS = $F2;
|
|
RPISENSE_EE_WP = $F3;
|
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;
Note | Called only during system startup |
---|
function RPiSenseStart(const I2CDevice,GPIODevice:String; Rotation,Width,Height:LongWord):THandle;
I2C | The name of the I2C device that the SenseHat is connected to |
---|---|
GPIO | The name of the GPIO device that the SenseHat 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;
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;
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;
Framebuffer | The Framebuffer device to destroy |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function RPiSenseFramebufferAllocate(Framebuffer:PFramebufferDevice; Properties:PFramebufferProperties):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDeviceAllocate instead. |
---|
function RPiSenseFramebufferRelease(Framebuffer:PFramebufferDevice):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDeviceRelease instead. |
---|
function RPiSenseFramebufferBlank(Framebuffer:PFramebufferDevice; Blank:Boolean):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDevicBlank instead. |
---|
function RPiSenseFramebufferMark(Framebuffer:PFramebufferDevice; X,Y,Width,Height,Flags:LongWord):LongWord;
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,Size,Flags:LongWord):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDeviceCommit instead. |
---|
function RPiSenseFramebufferSetOffset(Framebuffer:PFramebufferDevice; X,Y:LongWord; Pan:Boolean):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDeviceSetOffset instead. |
---|
function RPiSenseFramebufferSetProperties(Framebuffer:PFramebufferDevice; Properties:PFramebufferProperties):LongWord;
Note | Not intended to be called directly by applications, use FramebufferDeviceSetProperties instead. |
---|
function RPiSenseFramebufferGetGamma(Framebuffer:PFramebufferDevice; var Gamma:TRPiSenseGamma):LongWord;
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;
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;
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;
Note | None documented |
---|
procedure RPiSenseFramebufferUpdateDisplay(Framebuffer:PRPiSenseFramebuffer);
Note | Not intended to be called directly by applications |
---|
RPiSenseHat joystick functions
function RPiSenseJoystickCreate(I2C:PI2CDevice; GPIO:PGPIODevice; const Name:String):PKeyboardDevice;
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;
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);
Note | Not intended to be called directly by applications |
---|
RPiSenseHat helper functions
function RPiSenseRegRead(I2C:PI2CDevice; Address:Word; Reg:Byte):LongInt;
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;
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