UserGuide GraphicsCanvas - mchpgfx/legato.docs GitHub Wiki

Microchip Technology Graphics Canvas User Guide

What is the Graphics Canvas feature?

NOTE: The Graphics Canvas feature is only supported for devices with internal graphics controller with layer support such as the PIC32MZ DA or the SAM 9x60.

Click here for a visual demonstration of the Graphics Canvas feature.

Click here to expand details

Virtual display

Graphics Canvas is a virtual display

A ‘Virtual Display’ software layer for:

  • Storing or pre-rendering frame data using the Legato Graphics Library
  • Configuring the Display Controller Layers to display the Frames
  • Applying effects like Motion, Sprite Animation, Cropping and Fade In/Out using Display Controller Layers

Legato Graphics Canvas Architecture

Canvas Objects

A Canvas Object contains frame information

  • Buffer address, resolution, color mode
  • Layer ID, size, position, alpha
  • Layer effects status and settings

A Canvas Object is assigned a HW Layer in the Display Controller Application calls Canvas APIs to set Display and Effects settings

Legato Graphics Canvas Object Diagram

Canvas Effects

Graphics Canvas can be used to display a frame in various ways – cropped, translated, alpha blended, etc.

Graphics Canvas has ready-to-use APIs to apply ‘Effects’ like Motion or Fade In/Out

Legato Graphics Canvas Application Diagram

How to Configure Graphics Canvas in MPLAB® Harmony Configurator?

Click here to expand details

Graphics Canvas is added as a component between the Legato component and the graphics controller component.

Legato Graphics Canvas MHC Component Diagram

Here are some of the settings in the Graphics Canvas component

Legato Graphics Canvas Component Settings

How to interface Graphics Canvas with Application Code?

Click here to expand details

In application code, make sure to include the follow header files:

  • gfx_canvas.h – Core module, private functions, glue code to library and display controller driver
  • gfx_canvas_api.h – Public module, interface functions

This is an example of how Graphics Canvas should be initialized:

(This is an example from Legato Climate Control)

Legato Graphics Canvas App Init

This is an example of how Graphics Canvas API should be accessed during application runtime operations:

(This is an example from Legato Dashboard)

Legato Graphics Canvas App Runtime

How to use Graphics Canvas to add Move and Fade effects?

Click here to expand details

This is what needs to be set at application initialization:

(This is an example from Legato Climate Control)

Legato Graphics Effects App Init

Call this API to move a layer from one set of coordinates to another. Delta is the speed adjustment:

(This is an example from Legato Climate Control)

Legato Graphics Canvas Move Effect Code

Call this API to fade a layer from one alpha value to another in step value:

(This is an example from Legato Dashboard)

Legato Graphics Canvas Fade Effect Code

How to use Graphics Canvas to add Sprite Animation effects?

Click here to expand details

Sprite Animation

  • Graphics Canvas can be used to do sprite animation of multiple RAW images in memory
  • Images must have the same color mode as Canvas Object
  • A graphics controller layer is assigned to the Canvas Object
  • The Pixel Buffer for the Canvas Object is updated to the address of the current image to be shown

Legato Graphics Canvas Sprite Animation Explanation

Example Code

Here is how to call canvas APIs to execute sprite animations:

(This is an example from Legato Dashboard)

Legato Graphics Canvas Sprite Animation Code

How to use Graphics Canvas to create smooth screen transitions?

Click here to expand details

As seen in Legato Dashboard, Graphics Canvas can be used to create smooth screen transition.

Smooth Screen Transition Example

Click the image or here to see video demonstration.

Here are the steps to do it:

  1. Use 2 canvas objects per layer

For static screen (normal screen size)

For sliding screen transition (oversized to 2x width)

  1. Start with Screen 0 in Canvas 0
  2. Copy Canvas 0 buffer to Left Side of Canvas 1
  3. Show Left Side of Canvas 1 (Screen 0)
  4. Switch to Screen 1, GFX Library draws on Canvas 0
  5. Copy Canvas 0 (screen 1) to right side of Canvas 1 (gfxcCopyBuffer)
  6. Use Canvas Move to slide Canvas 1 from left (Screen 0) to right (Screen 1) (gfxcStartEffectMove)
  7. Show Canvas 0 for Screen 1

Smooth Screen Transition Setup Diagram


If you are new to MPLAB® Harmony, you should probably start with these tutorials:


Is this page helpful? Send feedback.

⚠️ **GitHub.com Fallback** ⚠️