]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/video_common_v4_3/src/xvidc_edid_ext.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / video_common_v4_3 / src / xvidc_edid_ext.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2017 - 2018 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xhdmi_edid.h
36 *
37 * <b>Software Initalization & Configuration</b>
38 *
39 * <b>Interrupts </b>
40 *
41 * <b> Virtual Memory </b>
42 *
43 * This driver supports Virtual Memory. The RTOS is responsible for calculating
44 * the correct device base address in Virtual Memory space.
45 *
46 * <b> Threads </b>
47 *
48 * This driver is not thread safe. Any needs for threads or thread mutual
49 * exclusion must be satisfied by the layer above this driver.
50 *
51 * <b> Asserts </b>
52 *
53 * Asserts are used within all Xilinx drivers to enforce constraints on argument
54 * values. Asserts can be turned off on a system-wide basis by defining at
55 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
56 * is recommended that users leave asserts on during development.
57 *
58 * <b> Building the driver </b>
59 *
60 * <pre>
61 * MODIFICATION HISTORY:
62 *
63 * Ver   Who  Date       Changes
64 * ----- ---- ---------- --------------------------------------------------
65 * 1.0   mmo  24-01-2017 EDID Parser capability
66 * </pre>
67 *
68 ******************************************************************************/
69 #include "stdio.h"
70 #include "string.h"
71 #include "stdlib.h"
72 #include "stdbool.h"
73 #include "xil_types.h"
74 #include "xstatus.h"
75 #include "xil_exception.h"
76 #include "xvidc_edid_ext.h"
77
78 static XV_VidC_PicAspectRatio xv_vidc_getPicAspectRatio(u16 hres, u16 vres);
79
80 static XV_VidC_PicAspectRatio xv_vidc_getPicAspectRatio(u16 hres, u16 vres) {
81     XV_VidC_PicAspectRatio ar;
82 #define HAS_RATIO_OF(x, y)  (hres == (vres*(x)/(y))&&!((vres*(x))%(y)))
83     if (HAS_RATIO_OF(16, 10)) {
84         ar.width = 16;
85         ar.height = 10;
86         return ar;
87     }
88     if (HAS_RATIO_OF(4, 3)) {
89         ar.width = 4;
90         ar.height = 3;
91         return ar;
92     }
93     if (HAS_RATIO_OF(5, 4)) {
94         ar.width = 5;
95         ar.height = 4;
96         return ar;
97     }
98     if (HAS_RATIO_OF(16, 9)) {
99         ar.width = 16;
100         ar.height = 9;
101         return ar;
102 #undef HAS_RATIO
103     } else {
104         ar.width = 0;
105         ar.height = 0;
106         return ar;
107     }
108 }
109
110
111 void XV_VidC_EdidCtrlParamInit (XV_VidC_EdidCntrlParam *EdidCtrlParam) {
112         
113         /* Verify arguments. */
114         Xil_AssertVoid(EdidCtrlParam != NULL);
115
116         (void)memset((void *)EdidCtrlParam,  0,
117                         sizeof(XV_VidC_EdidCntrlParam));
118                         
119         EdidCtrlParam->IsHdmi                = XVIDC_ISDVI;
120     EdidCtrlParam->IsYCbCr444Supp        = XVIDC_NOT_SUPPORTED;
121     EdidCtrlParam->IsYCbCr420Supp        = XVIDC_NOT_SUPPORTED;
122     EdidCtrlParam->IsYCbCr422Supp        = XVIDC_NOT_SUPPORTED;
123     EdidCtrlParam->IsYCbCr444DeepColSupp = XVIDC_NOT_SUPPORTED;
124     EdidCtrlParam->Is30bppSupp           = XVIDC_NOT_SUPPORTED;
125     EdidCtrlParam->Is36bppSupp           = XVIDC_NOT_SUPPORTED;
126     EdidCtrlParam->Is48bppSupp           = XVIDC_NOT_SUPPORTED;
127     EdidCtrlParam->IsYCbCr420dc30bppSupp = XVIDC_NOT_SUPPORTED;
128     EdidCtrlParam->IsYCbCr420dc36bppSupp = XVIDC_NOT_SUPPORTED;
129     EdidCtrlParam->IsYCbCr420dc48bppSupp = XVIDC_NOT_SUPPORTED;
130     EdidCtrlParam->IsSCDCReadRequestReady= XVIDC_NOT_SUPPORTED;
131     EdidCtrlParam->IsSCDCPresent         = XVIDC_NOT_SUPPORTED;
132     EdidCtrlParam->MaxFrameRateSupp      = 0;
133     EdidCtrlParam->MaxTmdsMhz            = 0;
134 }
135
136 XV_VidC_TimingParam
137 XV_VidC_timing
138             (const struct xvidc_edid_detailed_timing_descriptor * const dtb)
139 {
140     XV_VidC_TimingParam timing;
141
142     timing.hres   = xvidc_edid_detailed_timing_horizontal_active(dtb);
143     timing.vres   = xvidc_edid_detailed_timing_vertical_active(dtb);
144     timing.htotal = timing.hres +
145                         xvidc_edid_detailed_timing_horizontal_blanking(dtb);
146     timing.vtotal = timing.vres +
147                           xvidc_edid_detailed_timing_vertical_blanking(dtb);
148     timing.hfp    = xvidc_edid_detailed_timing_horizontal_sync_offset(dtb);
149     timing.vfp    = xvidc_edid_detailed_timing_vertical_sync_offset(dtb);
150     timing.hsync_width  =
151                 xvidc_edid_detailed_timing_horizontal_sync_pulse_width(dtb);
152     timing.vsync_width  =
153                   xvidc_edid_detailed_timing_vertical_sync_pulse_width(dtb);
154     timing.pixclk       = xvidc_edid_detailed_timing_pixel_clock(dtb);
155     timing.vfreq        = (timing.pixclk / (timing.vtotal * timing.htotal));
156     timing.vidfrmt      = (XVidC_VideoFormat) dtb->interlaced;
157     timing.aspect_ratio =
158                          xv_vidc_getPicAspectRatio (timing.hres, timing.vres);
159     timing.hsync_polarity = dtb->signal_pulse_polarity;
160     timing.vsync_polarity = dtb->signal_serration_polarity;
161
162     return timing;
163 }
164
165 #if XVIDC_EDID_VERBOSITY > 1
166 XV_VidC_DoubleRep Double2Int (double in_val) {
167         XV_VidC_DoubleRep DR;
168
169         DR.Integer = in_val;
170         DR.Decimal = (in_val - DR.Integer) * 10000;
171
172         return (DR);
173 }
174 #endif