Drawing APIs
Building and Flashing the Program
Create a new Pico SDK project named tftlcd-apis.
Create Pico SDK Project
- In VSCode, run
>Raspberry Pi Pico: New Pico Projectin the command palette. -
In the dialog below, select
C/C++.
-
Create a project with the following settings:
- Name ... Enter the project name.
- Board type ... Select your board type.
- Location ... Select the parent directory where the project directory will be created.
- Stdio support ... Leave
Console over USBunchecked when you use LABOPlatform or other USB features because they conflict with each other. You can enable it by editing theCMakeLists.txtfile later. - Code generation options ... Check
Generate C++ code.

Open Existing Pico SDK Project
Open the project folder in VSCode using one of the following methods:
- In a command prompt, change the current directory to the project folder and execute
code .. -
In a Explorer, choose the project folder, push
Alt+Dto focus the address bar, and executecode ..
If the folder is already prepared as a Pico SDK project, just proceed with editing and building the project.
If not, you will see the following message at the bottom right corner of VSCode.

Click Yes and you will see the following window.

Click Import and the project will be prepared as a Pico SDK project.
When the Do you want to import this project as Raspberry Pi Pico project? message disappears before you click Yes, you can reveal it by clicking the icon
at the bottom right corner of VSCode.
Clone the pico-jxglib repository from GitHub so the direcory structure looks like this:
Clone the Repository
Change the current directory to the parent directory where you want to clone the pico-jxglib repository and run the following commands:
$ git clone https://github.com/ypsitau/pico-jxglib.git
$ cd pico-jxglib
$ git submodule update --init --recursive
pico-jxglib is updated almost daily. If you've already cloned it, run the following command in the pico-jxglib directory to get the latest version:
A directory from a Git repository can safely be moved to another location even after cloning.
Add the following lines to the end of CMakeLists.txt:
| CMakeLists.txt | |
|---|---|
Edit the source file as follows:
Running the Program

Program Explanation
The first half of the source file initializes the device.
This is a Pico SDK function. It initializes SPI1 with a clock of 125MHz.
Sets GPIO14 and GPIO15 to SPI1 SCK and TX (MOSI), respectively.
Creates an instance to operate the ST7789. Specify the SPI to connect, display size, and GPIOs to connect (RST: Reset, DC: Data/Command, CS: Chip Select, BL: Backlight).
Initializes the LCD and makes it ready for drawing. The argument specifies the LCD drawing direction as follows:
Display::Dir::Rotate0orDisplay::Dir::Normal... Draws in the normal directionDisplay::Dir::Rotate90... Rotates 90 degreesDisplay::Dir::Rotate180... Rotates 180 degreesDisplay::Dir::Rotate270... Rotates 270 degreesDisplay::Dir::MirrorHorz... Mirrors horizontallyDisplay::Dir::MirrorVert... Mirrors vertically
After this, you can perform drawing operations on the display instance.
Draws an image at the specified coordinates. The fourth argument specifies the clipping region within the image.
Specifies the font data Font::shinonome16 defined in the include file jxglib/Font/shinonome16-japanese-level1.h.
Calculates the size when drawing the string with the specified font.
Draws the string at the specified coordinates.
Draws a rectangle with specified coordinates, size, and color.
Draws filled rectangles with specified coordinates, size, and color.