Skip to content

Commit 71bc937

Browse files
committed
Add Qualia S3 Factory Reset Source
1 parent 23c79df commit 71bc937

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#include "Adafruit_TestBed.h"
2+
#include <Arduino_GFX_Library.h>
3+
4+
extern Adafruit_TestBed TB;
5+
6+
Arduino_XCA9554SWSPI *expander = new Arduino_XCA9554SWSPI(
7+
PCA_TFT_RESET, PCA_TFT_CS, PCA_TFT_SCK, PCA_TFT_MOSI,
8+
&Wire, 0x3F);
9+
10+
Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
11+
TFT_DE, TFT_VSYNC, TFT_HSYNC, TFT_PCLK,
12+
TFT_R1, TFT_R2, TFT_R3, TFT_R4, TFT_R5,
13+
TFT_G0, TFT_G1, TFT_G2, TFT_G3, TFT_G4, TFT_G5,
14+
TFT_B1, TFT_B2, TFT_B3, TFT_B4, TFT_B5,
15+
1 /* hsync_polarity */, 50 /* hsync_front_porch */, 2 /* hsync_pulse_width */, 44 /* hsync_back_porch */,
16+
1 /* vsync_polarity */, 16 /* vsync_front_porch */, 2 /* vsync_pulse_width */, 18 /* vsync_back_porch */
17+
//,1, 30000000
18+
);
19+
20+
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
21+
480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
22+
expander, GFX_NOT_DEFINED /* RST */, TL021WVC02_init_operations, sizeof(TL021WVC02_init_operations));
23+
24+
uint16_t *colorWheel;
25+
26+
void setup(void)
27+
{
28+
Serial.begin(115200);
29+
//while (!Serial) delay(100);
30+
31+
#ifdef GFX_EXTRA_PRE_INIT
32+
GFX_EXTRA_PRE_INIT();
33+
#endif
34+
35+
Serial.println("Beginning");
36+
// Init Display
37+
38+
Wire.setClock(1000000); // speed up I2C
39+
if (!gfx->begin()) {
40+
Serial.println("gfx->begin() failed!");
41+
}
42+
43+
Serial.println("Initialized!");
44+
45+
gfx->fillScreen(BLACK);
46+
47+
expander->pinMode(PCA_TFT_BACKLIGHT, OUTPUT);
48+
expander->digitalWrite(PCA_TFT_BACKLIGHT, HIGH);
49+
50+
TB.begin();
51+
colorWheel = (uint16_t *) ps_malloc(480 * 480 * sizeof(uint16_t));
52+
if (colorWheel) generateColorWheel(colorWheel);
53+
}
54+
55+
56+
uint8_t allpins[] = {SS, SCK, MOSI, MISO, A1, A0};
57+
58+
bool test = false;
59+
void loop()
60+
{
61+
if (!test) {
62+
gfx->draw16bitRGBBitmap(0, 0, colorWheel, 480, 480);
63+
delay(100);
64+
return;
65+
}
66+
Serial.println("** Test Display!");
67+
gfx->fillScreen(BLACK);
68+
gfx->setTextSize(5);
69+
gfx->setTextColor(WHITE);
70+
gfx->setTextWrap(false);
71+
gfx->setCursor(100, gfx->height() / 2 - 175);
72+
gfx->println("Display OK!");
73+
74+
if (! TB.testpins(MOSI, A1, allpins, sizeof(allpins))) return;
75+
if (! TB.testpins(MISO, SS, allpins, sizeof(allpins))) return;
76+
if (! TB.testpins(SCK, A0, allpins, sizeof(allpins))) return;
77+
gfx->setCursor(100, gfx->height() / 2 - 125);
78+
gfx->println("GPIO OK!");
79+
80+
gfx->setCursor(100, gfx->height() / 2 - 75);
81+
if (! TB.scanI2CBus(0x15)) return;
82+
gfx->println("I2C OK!");
83+
84+
gfx->setCursor(100, gfx->height() / 2 - 25);
85+
gfx->setTextColor(RED);
86+
gfx->println("RED");
87+
88+
gfx->setCursor(100, gfx->height() / 2 + 25);
89+
gfx->setTextColor(GREEN);
90+
gfx->println("GREEN");
91+
92+
gfx->setCursor(100, gfx->height() / 2 + 75);
93+
gfx->setTextColor(BLUE);
94+
gfx->println("BLUE");
95+
96+
Serial.println("** TEST OK!");
97+
test = false;
98+
}
99+
100+
// https://chat.openai.com/share/8edee522-7875-444f-9fea-ae93a8dfa4ec
101+
void generateColorWheel(uint16_t *colorWheel) {
102+
float angle;
103+
uint8_t r, g, b;
104+
int index, scaled_index;
105+
106+
for(int y = 0; y < 240; y++) {
107+
for(int x = 0; x < 240; x++) {
108+
index = y * 240 + x;
109+
angle = atan2(y - 120, x - 120);
110+
r = uint8_t(127.5 * (cos(angle) + 1));
111+
g = uint8_t(127.5 * (sin(angle) + 1));
112+
b = uint8_t(255 - (r + g) / 2);
113+
uint16_t color = RGB565(r, g, b);
114+
115+
// Scale this pixel into 4 pixels in the 480x480 buffer
116+
for(int dy = 0; dy < 2; dy++) {
117+
for(int dx = 0; dx < 2; dx++) {
118+
scaled_index = (y * 2 + dy) * 480 + (x * 2 + dx);
119+
colorWheel[scaled_index] = color;
120+
}
121+
}
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)