-
Notifications
You must be signed in to change notification settings - Fork 10
/
diag.c
192 lines (161 loc) · 5.3 KB
/
diag.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
/*
ESP32 Composite Video Library
Copyright (C) 2022 aquaticus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sdkconfig.h"
#if CONFIG_VIDEO_DIAG_DISPLAY_TEST_FUNC
#include <esp_log.h>
#include "esp_system.h"
#include <assert.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "video.h"
static const char* TAG = "VIDEO";
#define HEADER_PIXEL(data,pixel) {\
pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \
pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \
pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \
data += 4; \
}
#include "Philips_PM5544_384x288.h"
#include "Philips_PM5544_320x240.h"
static void display_pm554(bool pal_resolution)
{
uint8_t pixel[3];
uint8_t grey1,grey2;
uint8_t mask;
const char* p= pal_resolution ? pm5544_384x288_data : pm5544_320x240_data;
const size_t ratio = 8/g_video_signal.bits_per_pixel;
for(unsigned int y=0; y<g_video_signal.height_pixels; y++)
{
for(unsigned int x=0;x<g_video_signal.width_pixels/ratio; x++)
{
HEADER_PIXEL(p, pixel);
grey1 = 0.30*pixel[0] + 0.59*pixel[1] + 0.11*pixel[2];
if( g_video_signal.bits_per_pixel == 4 )
{
HEADER_PIXEL(p, pixel);
grey2 = 0.30*pixel[0] + 0.59*pixel[1] + 0.11*pixel[2];
g_video_signal.frame_buffer[y*g_video_signal.width_pixels/ratio+x] = (grey2/16) << 4 | (grey1/16);
}
else if(g_video_signal.bits_per_pixel == 8)
{
g_video_signal.frame_buffer[y*g_video_signal.width_pixels+x] = grey1;
}
else if(g_video_signal.bits_per_pixel == 1)
{
const uint8_t WHITE_LEVEL = 128;
mask = 0;
int i=8;
while(i--)
{
// 8 pixels
HEADER_PIXEL(p, pixel);
grey1 = 0.30*pixel[0] + 0.59*pixel[1] + 0.11*pixel[2];
if( grey1 >= WHITE_LEVEL )
{
mask |= 1U<<i;
}
}
g_video_signal.frame_buffer[y*g_video_signal.width_pixels/ratio+x] = mask;
}
else
{
assert(false);
}
}
}
}
static void display_test_image_checkers(void)
{
memset(g_video_signal.frame_buffer, 0, g_video_signal.frame_buffer_size_bytes);
for (uint8_t* it = g_video_signal.frame_buffer; it < g_video_signal.frame_buffer + g_video_signal.frame_buffer_size_bytes; it += 20)
{
memset(it, 0xFF, 20);
if (((it - g_video_signal.frame_buffer) + 40) % (20 * 400) == 0)
{
it += 40;
}
else if (((it - g_video_signal.frame_buffer) + 20) % (20 * 400) != 0)
{
it += 20;
}
}
}
static void display_test_image_white(void)
{
memset(g_video_signal.frame_buffer, 0xFF, g_video_signal.frame_buffer_size_bytes);
}
#if CONFIG_VIDEO_DIAG_ENABLE_INTERRUPT_STATS
static void stat_loop(void)
{
ESP_LOGI(TAG, "Stats Loop");
int n = 5;
while(n--)
{
vTaskDelay(5*1000/portTICK_PERIOD_MS); //5s
video_show_stats();
}
}
#endif
void video_test_pal(VIDEO_TEST_TYPE test)
{
switch (test)
{
case VIDEO_TEST_CHECKERS:
ESP_LOGI(TAG, "PAL Display test checkers");
video_init(320, 200, FB_FORMAT_GREY_8BPP, VIDEO_MODE_PAL, false);
display_test_image_checkers();
break;
case VIDEO_TEST_PM5544:
ESP_LOGI(TAG, "PAL Display test PM5544");
video_init(384, 288, FB_FORMAT_GREY_8BPP, VIDEO_MODE_PAL, false);
display_pm554(true);
break;
default:
case VIDEO_TEST_WHITE:
ESP_LOGI(TAG, "PAL Display test white");
video_init(384, 288, FB_FORMAT_GREY_8BPP, VIDEO_MODE_PAL, false);
display_test_image_white();
break;
}
#if CONFIG_VIDEO_DIAG_ENABLE_INTERRUPT_STATS
stat_loop();
#endif
}
void video_test_ntsc(VIDEO_TEST_TYPE test)
{
switch (test)
{
case VIDEO_TEST_CHECKERS:
ESP_LOGI(TAG, "NTSC Display test checkers");
video_init(320, 240, FB_FORMAT_GREY_8BPP, VIDEO_MODE_NTSC, false);
display_test_image_checkers();
break;
case VIDEO_TEST_PM5544:
ESP_LOGI(TAG, "NTSC Display test PM5544");
video_init(320, 240, FB_FORMAT_GREY_8BPP, VIDEO_MODE_PAL, false);
display_pm554(false);
break;
case VIDEO_TEST_WHITE:
ESP_LOGI(TAG, "NTSC Display test white");
video_init(320, 240, FB_FORMAT_GREY_8BPP, VIDEO_MODE_NTSC, false);
display_test_image_white();
break;
}
#if CONFIG_VIDEO_DIAG_ENABLE_INTERRUPT_STATS
stat_loop();
#endif
}
#endif