-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.c
211 lines (170 loc) · 5.22 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <string.h>
#include <stdlib.h>
#include "ili9341/ili9341.h"
#include "touch/msp2807_touch.h"
// TODO: PSE uncomment one mode only.
//#define MODE_TEST_TEXTBOX_DRAWING
#define MODE_TEST_TOUCH_DRAWING
//#define MODE_TEST_RANDOM_LINES
//#define MODE_TEST_RANDOM_LABELS
void PRN32(uint32_t *val)
{
*val ^= *val << 13;
*val ^= *val >> 17;
*val ^= *val << 5;
}
void TestBoxDraw(screen_control_t *p_screen)
{
assert_(p_screen);
static int x = 0, y = 0;
if(!x && !y)
{
memset(p_screen->mpPixBuffer, 0xFF, sizeof(p_screen->mpPixBuffer));
TftFullScreenWrite(p_screen);
}
TftClearRect8(p_screen, x, y);
if(++x >= TEXT_WIDTH)
{
x = 0;
if(++y >= TEXT_HEIGHT)
y = 0;
}
TftFullScreenSelectiveWrite(p_screen, 16);
}
void TestRandomLabels(screen_control_t *p_screen)
{
assert_(p_screen);
static uint32_t rnd_seed = 0xa5efddbd;
PRN32(&rnd_seed);
const int x = rnd_seed % 240;
PRN32(&rnd_seed);
const int y = rnd_seed % 312;
TftPutTextLabel(p_screen, "Pico RULEZZ", x, y, false);
TftFullScreenSelectiveWrite(p_screen, 10000);
}
void TestRandomLines(screen_control_t *p_screen)
{
assert_(p_screen);
static uint32_t rnd_seed = 0xa5efddbd;
PRN32(&rnd_seed);
const int x0 = rnd_seed % 240;
PRN32(&rnd_seed);
const int x1 = rnd_seed % 240;
PRN32(&rnd_seed);
const int y0 = rnd_seed % 320;
PRN32(&rnd_seed);
const int y1 = rnd_seed % 320;
TftPutLine(p_screen, x0, y0, x1, y1);
TftFullScreenSelectiveWrite(p_screen, 10000);
}
int main()
{
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(250);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
static screen_control_t sScreen =
{
.mCursorX = 0,
.mCursorY = 0,
.mCursorType = 0,
.mCanvasPaper = kBlack,
.mCanvasInk = kWhite
};
/*
DISPLAY
=======
Pico pin Disp.pin Description
(pin 36) VCC 3.3V power input.
(pin 38) GND Ground.
(pin 07) CS LCD chip select signal, low level enable.
(pin 11) RESET LCD reset signal, low level reset.
(pin 12) DC/RS LCD register / data selection signal; high level: register.
(pin 10) SDI(MOSI) SPI bus write data signal.
(pin 09) SCK SPI bus clock signal.
(pin 36) LED Backlight control.
(pin 06) SDO(MISO) SPI bus read data signal. Hasn't been used so far in here.
TOUCH PANEL
===========
Pico pin Dev.pin Description
(pin 20) T_IRQ Touch event indicator (active low).
(pin 15) T_DIN SPI MOSI signal.
(pin 14) T_CLK SPI SCK signal.
(pin 17) T_CS Device chip select (active low).
(pin 16) T_DO SPI MISO signal.
*/
ili9341_config_t ili9341_hw_config;
sScreen.mpHWConfig = &ili9341_hw_config;
ILI9341_Init(sScreen.mpHWConfig, spi0, 90 * MHz, 4, 5, 6, 7, 8, 9);
sScreen.mCanvasPaper = kBlack;
sScreen.mCanvasInk = kMagenta;
TftClearScreenBuffer(&sScreen, kBlack, kRed);
TftFullScreenWrite(&sScreen);
#ifdef MODE_TEST_TOUCH_DRAWING
touch_hwconfig_t touch_hwc;
TouchInitHW(&touch_hwc, spi1, 1 * MHz, 12, 13, 10, 11, 15);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
touch_control_t touch_config;
TouchInitCtl(&touch_config, &touch_hwc, 1000, 50000, 5);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
calibration_mat_t cmat;
const int16_t refpoints[] =
{
0, 0,
240, 0,
0, 320,
240, 320
};
const int16_t smplpoints[] =
{
10, 120,
119, 119,
9, 11,
118, 12
};
CalculateCalibrationMat(refpoints, smplpoints, 4, &cmat);
TftPrintf(&sScreen, 0, 8, 0, 7,
"Calibration mat:\n %.2f %.2f %.2f\n%.2f %.2f %.2f\n",
cmat.KX1, cmat.KX2, cmat.KX3, cmat.KY1, cmat.KY2, cmat.KY3);
TftPrintf(&sScreen, 0, 8, 0, 3, "Please draw using the pen!!!");
TftFullScreenSelectiveWrite(&sScreen, 10000);
#endif
int led_state = 0;
for(;;)
{
gpio_put(PICO_DEFAULT_LED_PIN, (led_state & 1));
++led_state;
#ifdef MODE_TEST_TEXTBOX_DRAWING
TestBoxDraw(&sScreen);
sleep_ms(100);
continue;
#endif
#ifdef MODE_TEST_RANDOM_LINES
TestRandomLines(&sScreen);
continue;
#endif
#ifdef MODE_TEST_RANDOM_LABELS
TestRandomLabels(&sScreen);
//sleep_ms(250);
continue;
#endif
#ifdef MODE_TEST_TOUCH_DRAWING
CheckTouch(&touch_config);
if(touch_config.mIsProcessed)
{
static int touch_tick = 0;
touch_tick++;
int32_t x = (touch_config.mXf + 8) >> 4;
int32_t y = (touch_config.mYf + 8) >> 4;
TouchTransformCoords(&cmat, &x, &y);
TftPutPixel(&sScreen, x, y, kBlack, kYellow);
if(0 == led_state % 128)
TftPrintf(&sScreen, 0, 8, ~(touch_tick&7), touch_tick&7, "%u %d %d %d %d\n", touch_tick,
touch_config.mX, touch_config.mY, x, y);
TftFullScreenSelectiveWrite(&sScreen, 10000);
touch_config.mIsProcessed = false;
}
#endif
}
}