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.cpp
1/*
2 * entryPointCPP.cpp
3 *
4 * Created on: Jan 26, 2025
5 * Author: johng
6 */
7
8#include <stdio.h>
9#include "entryPointCPP.hpp"
10#include "Adafruit_RA8875.h"
11
13Adafruit_RA8875 *tft = nullptr;
14
15/*
16 * Creates the display object and starts it. With the STM32_RA8875 library the
17 * constructor takes the SPI handle plus the CS and RESET port/pin directly, and
18 * begin() itself sets CS high, pulses RESET, reads the chip ID and raises the
19 * SPI clock, so none of that is done here. WAIT and INT are not used.
20 */
21void initTest(SPI_HandleTypeDef *halSPI) {
22 tft = new Adafruit_RA8875(halSPI, RA8875_CS_GPIO_Port, RA8875_CS_Pin,
23 LCD_RESET_GPIO_Port, LCD_RESET_Pin);
24
25 if (tft->begin(RA8875_800x480)) {
26 printf("RA8875 Found\r\n");
27 } else {
28 printf("RA8875 not found (expected chip ID 0x75)\r\n");
29 Error_Handler();
30 }
31}
32
33void testLCD(bool buildTest) {
34 if (tft == nullptr) { // initTest() has not run yet; fail loudly instead of dereferencing NULL
35 printf("ERROR: testLCD() called before initTest()\r\n");
36 Error_Handler();
37 }
38
39 if (buildTest) {
40 printf("================ Graphics Mode =============\r\n");
41
42 tft->displayOn(true);
43 HAL_Delay(1);
44 tft->GPIOX(true);
45 HAL_Delay(1);
47 tft->PWM1out(255);
48 HAL_Delay(1);
49
50 tft->graphicsMode();
51
52 printf("FillSreen White\r\n");
54
55 HAL_Delay(1000);
56#ifdef PWM
57 // Play with PWM
58 printf("Start: Play with PWM\r\n");
59
60 for (uint8_t i=255; i!=0; i-=5 )
61 {
62 tft->PWM1out(i);
63 delay(100);
64 }
65 for (uint8_t i=0; i!=255; i+=5 )
66 {
67 tft->PWM1out(i);
68 delay(100);
69 }
70 tft->PWM1out(255);
71
72 printf("END: Play with PWM\r\n");
73 HAL_Delay(2000);
74#endif
75 printf("FillSreen Red\r\n");
77 HAL_Delay(1000);
78 printf("FillSreen Yellow\r\n");
80 HAL_Delay(1000);
81 printf("FillSreen Green\r\n");
83 HAL_Delay(1000);
84 printf("FillSreen Cyan\r\n");
86 HAL_Delay(1000);
87 printf("FillSreen Magenta\r\n");
89 HAL_Delay(1000);
90 printf("FillSreen Black\r\n");
92 HAL_Delay(1000);
93
94 // Try some GFX acceleration!
95 printf("drawCircle\r\n");
96 tft->drawCircle(100, 100, 50, RA8875_BLACK);
97 printf("fillCircle\r\n");
98 tft->fillCircle(100, 100, 49, RA8875_GREEN);
99
100 HAL_Delay(1000);
101
102 printf("fillRect\r\n");
103 tft->fillRect(11, 11, 398, 198, RA8875_BLUE);
104 HAL_Delay(1000);
105 printf("drawRect\r\n");
106 tft->drawRect(10, 10, 400, 200, RA8875_GREEN);
107 HAL_Delay(1000);
108 printf("fillRoundRect\r\n");
109 tft->fillRoundRect(200, 10, 200, 100, 10, RA8875_RED);
110 HAL_Delay(1000);
111 printf("drawPixel\r\n");
112 tft->drawPixel(10,10,RA8875_BLACK);
113 HAL_Delay(1000);
114 printf("drawPixel\r\n");
115 tft->drawPixel(11,11,RA8875_BLACK);
116 HAL_Delay(1000);
117 printf("drawLine\r\n");
118 tft->drawLine(10, 10, 200, 100, RA8875_RED);
119 HAL_Delay(1000);
120 printf("drawTriangle\r\n");
121 tft->drawTriangle(200, 15, 250, 100, 150, 125, RA8875_BLACK);
122 HAL_Delay(1000);
123 printf("fillTriangle\r\n");
124 tft->fillTriangle(200, 16, 249, 99, 151, 124, RA8875_YELLOW);
125 HAL_Delay(1000);
126 printf("drawEllipse\r\n");
127 tft->drawEllipse(300, 100, 100, 40, RA8875_BLACK);
128 HAL_Delay(1000);
129 printf("fillEllipse\r\n");
130 tft->fillEllipse(300, 100, 98, 38, RA8875_GREEN);
131 HAL_Delay(1000);
132 // Argument 5 (curvePart) is a 2-bit value to control each corner (select 0, 1, 2, or 3)
133 printf("drawCurve\r\n");
134 tft->drawCurve(50, 100, 80, 40, 2, RA8875_BLACK);
135 HAL_Delay(1000);
136 printf("fillCurve\r\n");
137 tft->fillCurve(50, 100, 78, 38, 2, RA8875_WHITE);
138 } else {
139 printf("================ Text Mode =============\r\n");
140 tft->displayOn(true);
141 tft->GPIOX(true); // Enable TFT - display enable tied to GPIOX
142 tft->PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
143 tft->PWM1out(255);
144 printf("fillScreen\r\n");
146
147 /* Switch to text mode */
148 tft->textMode();
149 tft->cursorBlink(32);
150
151
152 /* Set a solid for + bg color ... */
153
154 /* ... or a fore color plus a transparent background */
155
156
157 /* Set the cursor location (in pixels) */
158 tft->textSetCursor(10, 10);
159
160 /* Render some text! */
161 printf("Render lots of Texts\r\n");
162 char string[80] = "Hello, World! ";
164 tft->textWrite(string);
165 HAL_Delay(500);
167 tft->textWrite(string);
168 HAL_Delay(500);
170 tft->textWrite(string);
171 HAL_Delay(500);
173 tft->textWrite(string);
174 HAL_Delay(500);
176 tft->textWrite(string);
177 HAL_Delay(500);
179 tft->textWrite(string);
180
181 HAL_Delay(1000);
182
183 tft->textSetCursor(100, 100);
184 tft->textEnlarge(1);
186 tft->textWrite(string);
187
188 tft->textSetCursor(100, 150);
189 tft->textEnlarge(2);
191 tft->textWrite(string);
192
193 tft->textSetCursor(100, 200);
194 tft->textEnlarge(3);
196 tft->textWrite(string);
197
198 tft->textSetCursor(100, 300);
199 tft->textEnlarge(0);
201 tft->textWrite(string);
202 }
203}
#define RA8875_GREEN
Green Color.
#define RA8875_YELLOW
Yellow Color.
#define RA8875_MAGENTA
Magenta Color.
#define RA8875_CYAN
Cyan Color.
#define RA8875_PWM_CLK_DIV1024
See datasheet.
#define RA8875_BLACK
Black Color.
#define RA8875_WHITE
White Color.
#define RA8875_RED
Red Color.
#define RA8875_BLUE
Blue Color.
@ RA8875_800x480
Class that stores state and functions for interacting with the RA8875 display controller.
void GPIOX(boolean on)
void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
void drawPixel(int16_t x, int16_t y, uint16_t color)
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color)
void fillScreen(uint16_t color)
void fillCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color)
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
void fillEllipse(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color)
void cursorBlink(uint8_t rate)
boolean begin(enum RA8875sizes s)
void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color)
void textEnlarge(uint8_t scale)
void textSetCursor(uint16_t x, uint16_t y)
void PWM1out(uint8_t p)
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
void drawCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color)
void textColor(uint16_t foreColor, uint16_t bgColor)
void displayOn(boolean on)
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
void textTransparent(uint16_t foreColor)
void PWM1config(boolean on, uint8_t clock)
void textWrite(const char *buffer, uint16_t len=0)
void drawEllipse(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color)
C-callable entry points into the C++ RA8875 display code.
void testLCD(bool buildTest)
Runs one of the two display demonstrations.
void initTest(SPI_HandleTypeDef *halSPI)
Creates the display object and starts the RA8875 controller.