F439_CPP_SPI_RA8875_TFT_LCD_03 1.0
STM32F439 SPI RA8875 7-inch TFT display demo built on the STM32_GFX and STM32_RA8875 libraries
Loading...
Searching...
No Matches
entryPointCPP.hpp File Reference

C-callable entry points into the C++ RA8875 display code. More...

#include "main.h"

Go to the source code of this file.

Functions

void initTest (SPI_HandleTypeDef *halSPI)
 Creates the display object and starts the RA8875 controller.
 
void testLCD (bool buildTest)
 Runs one of the two display demonstrations.
 

Detailed Description

C-callable entry points into the C++ RA8875 display code.

Project: F439_CPP_SPI_RA8875_TFT_LCD_03

The CubeMX-generated main.c is plain C, so it cannot create or call the C++ Adafruit_RA8875 object directly. This header declares the small set of extern "C" functions that main.c calls instead; their bodies are in entryPointCPP.cpp, which owns the display object.

Created on: Jan 26, 2025 Author: johng

Definition in file entryPointCPP.hpp.

Function Documentation

◆ initTest()

void initTest ( SPI_HandleTypeDef * halSPI)

Creates the display object and starts the RA8875 controller.

Parameters
halSPIHandle of the SPI peripheral wired to the display (SPI1 here, set up by CubeMX as master, full duplex, 8-bit, mode 0, MSB first, software NSS).

Constructs an Adafruit_RA8875 with the SPI handle and the CS (RA8875_CS_*) and RESET (LCD_RESET_*) pins from main.h, then calls Adafruit_RA8875::begin() for an 800x480 panel. begin() sets CS high, pulses RESET, reads the chip ID (it must be 0x75), initialises the controller and raises the SPI clock, so nothing else needs to be done here. Prints "RA8875 Found" on the redirected USART; if the chip does not answer it prints a message and calls Error_Handler(). The WAIT and INT pins are not used.

Note
Call it once from main.c, after the CubeMX MX_..._Init() calls, inside a USER CODE section. The object is created with new at this point, not as a global, so it is not constructed before the clocks and the SPI peripheral exist.
Warning
Not thread-safe and not ISR-safe: it stores the new object in a shared global pointer without any lock, and begin() is a sequence of separate SPI transactions. A task switch (or an interrupt) that called testLCD() or any other display call in between would use a half-initialised display or interleave its SPI transfers with begin()'s. Call it once, from the main thread, before anything else touches the display.

Definition at line 21 of file entryPointCPP.cpp.

References Adafruit_RA8875::begin(), initTest(), and RA8875_800x480.

Referenced by initTest(), and main().

◆ testLCD()

void testLCD ( bool buildTest)

Runs one of the two display demonstrations.

Parameters
buildTesttrue runs the graphics demo, false runs the text demo.

The graphics demo turns the display on, enables the backlight output, fills the screen with seven colours in turn, then draws a circle, rectangles, a rounded rectangle, single pixels, a line, triangles, ellipses and curves using the RA8875's hardware drawing commands. The text demo clears the screen, switches to the controller's text mode and prints "Hello, World!" in several foreground and background colours and four enlargement sizes, with a blinking cursor. Progress is printed on the redirected USART. If PWM is defined at build time, the graphics demo also sweeps the PWM1 output down and up; it is compiled out by default because on Adafruit's board PWM1 does not reach the backlight (see the Adafruit_RA8875 documentation).

Note
initTest() must have run first. If it has not, testLCD() prints an error and calls Error_Handler() instead of using a NULL display.
Warning
Not thread-safe and not ISR-safe: every drawing call is several separate SPI transactions (set the cursor, then the colour, then the draw command), all on one shared display object. A task switch between two of them lets a second caller's commands interleave with the first caller's and corrupt both. Call it from one thread only, and never from an interrupt. The demos also block for several seconds in HAL_Delay().

Definition at line 33 of file entryPointCPP.cpp.

References Adafruit_RA8875::cursorBlink(), Adafruit_RA8875::displayOn(), Adafruit_RA8875::drawCircle(), Adafruit_RA8875::drawCurve(), Adafruit_RA8875::drawEllipse(), Adafruit_RA8875::drawLine(), Adafruit_RA8875::drawPixel(), Adafruit_RA8875::drawRect(), Adafruit_RA8875::drawTriangle(), Adafruit_RA8875::fillCircle(), Adafruit_RA8875::fillCurve(), Adafruit_RA8875::fillEllipse(), Adafruit_RA8875::fillRect(), Adafruit_RA8875::fillRoundRect(), Adafruit_RA8875::fillScreen(), Adafruit_RA8875::fillTriangle(), Adafruit_RA8875::GPIOX(), Adafruit_RA8875::graphicsMode(), Adafruit_RA8875::PWM1config(), Adafruit_RA8875::PWM1out(), RA8875_BLACK, RA8875_BLUE, RA8875_CYAN, RA8875_GREEN, RA8875_MAGENTA, RA8875_PWM_CLK_DIV1024, RA8875_RED, RA8875_WHITE, RA8875_YELLOW, testLCD(), Adafruit_RA8875::textColor(), Adafruit_RA8875::textEnlarge(), Adafruit_RA8875::textMode(), Adafruit_RA8875::textSetCursor(), Adafruit_RA8875::textTransparent(), and Adafruit_RA8875::textWrite().

Referenced by main(), and testLCD().