17
17
#include "supervisor/port_heap.h"
18
18
19
19
#if defined(DEFAULT_DVI_BUS_CLK_DP )
20
- static bool picodvi_autoconstruct_enabled (void ) {
20
+ static bool picodvi_autoconstruct_enabled (mp_int_t * default_width , mp_int_t * default_height ) {
21
21
char buf [sizeof ("detect" )];
22
22
buf [0 ] = 0 ;
23
23
@@ -42,6 +42,48 @@ static bool picodvi_autoconstruct_enabled(void) {
42
42
return false;
43
43
}
44
44
bool probed = common_hal_busio_i2c_probe (i2c , 0x50 );
45
+ if (probed ) {
46
+ uint8_t edid [128 ];
47
+ uint8_t out [1 ] = {0 };
48
+ common_hal_busio_i2c_write_read (i2c , 0x50 , out , 1 , edid , sizeof (edid ));
49
+ bool edid_ok = true;
50
+ if (edid [0 ] != 0x00 || edid [1 ] != 0xFF || edid [2 ] != 0xFF || edid [3 ] != 0xFF || edid [4 ] != 0xFF || edid [5 ] != 0xFF || edid [6 ] != 0xFF || edid [7 ] != 0x00 ) {
51
+ edid_ok = false;
52
+ }
53
+ uint8_t checksum = 0 ;
54
+ for (size_t i = 0 ; i < sizeof (edid ); i ++ ) {
55
+ checksum += edid [i ];
56
+ }
57
+ if (checksum != 0 ) {
58
+ edid_ok = false;
59
+ }
60
+
61
+ if (edid_ok ) {
62
+ uint8_t established_timings = edid [35 ];
63
+ if ((established_timings & 0xa0 ) == 0 ) {
64
+ // Check that 720x400@70Hz or 640x480@60Hz is supported. If not
65
+ // and we read EDID ok, then don't autostart.
66
+ probed = false;
67
+ } else {
68
+ size_t offset = 54 ;
69
+ uint16_t preferred_pixel_clock = edid [offset ] | (edid [offset + 1 ] << 8 );
70
+ if (preferred_pixel_clock != 0 ) {
71
+ size_t preferred_width = ((edid [offset + 4 ] & 0xf0 ) << 4 ) | edid [offset + 2 ];
72
+ size_t preferred_height = ((edid [offset + 7 ] & 0xf0 ) << 4 ) | edid [offset + 5 ];
73
+ // Use 720x400 on 1080p, 4k and 8k displays.
74
+ if ((established_timings & 0x80 ) != 0 &&
75
+ preferred_width % 1920 == 0 &&
76
+ preferred_height % 1080 == 0 ) {
77
+ * default_width = 720 / 2 ;
78
+ * default_height = 400 / 2 ;
79
+ } else {
80
+ * default_width = 640 / 2 ;
81
+ * default_height = 480 / 2 ;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
45
87
common_hal_busio_i2c_unlock (i2c );
46
88
return probed ;
47
89
}
@@ -53,11 +95,13 @@ void picodvi_autoconstruct(void) {
53
95
return ;
54
96
}
55
97
56
- if (!picodvi_autoconstruct_enabled ()) {
98
+ mp_int_t default_width = 320 ;
99
+ mp_int_t default_height = 240 ;
100
+ if (!picodvi_autoconstruct_enabled (& default_width , & default_height )) {
57
101
return ;
58
102
}
59
103
60
- mp_int_t width = 320 ;
104
+ mp_int_t width = default_width ;
61
105
mp_int_t height = 0 ;
62
106
mp_int_t color_depth = 16 ;
63
107
mp_int_t rotation = 0 ;
@@ -75,6 +119,9 @@ void picodvi_autoconstruct(void) {
75
119
case 320 :
76
120
height = 240 ;
77
121
break ;
122
+ case 360 :
123
+ height = 200 ;
124
+ break ;
78
125
}
79
126
}
80
127
@@ -85,8 +132,8 @@ void picodvi_autoconstruct(void) {
85
132
86
133
if (!common_hal_picodvi_framebuffer_preflight (width , height , color_depth )) {
87
134
// invalid configuration, set back to default
88
- width = 320 ;
89
- height = 240 ;
135
+ width = default_width ;
136
+ height = default_height ;
90
137
color_depth = 16 ;
91
138
}
92
139
0 commit comments