/* Copyright 2015 Castle Technology Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* EDIDModes.h */

/* TODO: comments required throughout this file */

#define MAXMODENAMESIZE (25)

#define EDID_SIZE (128)

/* Defines which is the most advanced timing calculation available
 * We use DMT if defined for that mode and calculate using the timing
 * If not. If USE_DMT is highest it is DMT or nothing.
 */
#define EDID_USE_DMT   (0)
#define EDID_USE_GTF   (1)
#define EDID_USE_GTF2  (2)
#define EDID_USE_CVT   (3)
#define EDID_USE_CVTRB (4)

typedef struct _STDMODE
{
    char     ModeName[MAXMODENAMESIZE];
    uint32_t Refresh;
    uint32_t SyncPulse;
    uint32_t HTotal;
    uint32_t XRes;
    uint32_t HSync;
    uint32_t HFrontPorch;
    uint32_t HBackPorch;
    double   PixRate;
    uint32_t VTotal;
    uint32_t YRes;
    uint32_t VSync;
    uint32_t VFrontPorch;
    uint32_t VBackPorch;
} STDMODE;

typedef struct _EDIDBlock
{
    /* 8 bytes of header */
    uint8_t header[8];
    /* 10 bytes of vendor id */
    uint8_t manufacturer_id[2];
    uint8_t product_id[2];
    uint8_t serial[4];
    uint8_t week_made;
    uint8_t year_made;
    /* 2 bytes of EDID Structure and version */
    uint8_t edid_version;
    uint8_t edid_revision;
    /* 5 bytes of Basic parameters */
    uint8_t video_input_definition;
    uint8_t horizontal_screen_size; /* Listed in cm. Aspect ratio - landscape */
    uint8_t vertical_screen_size;   /* Listed in cm. Aspect ratio - portrait */
    uint8_t gamma;
    uint8_t feature_support;
    /* 10 bytes of colour characteristics */
    uint8_t colour_characteristics[10];
    /* 3 bytes of established timings */
    uint8_t established_timings[3];
    /* 16 bytes of standard timings identification 1-8 */
    uint8_t standard_timings[16];
    /* 72 bytes of 18 byte data blocks; */
    uint8_t data_block[4][18];
    /* Extension blocks */
    uint8_t extension_block_count;
    uint8_t checksum;
} EDIDBlock, *EDIDBlockRef;

typedef struct _EDIDExtensionBlock
{
    uint8_t tag;
    uint8_t revision;
    uint8_t data[125];
    uint8_t checksum;
} EDIDExtensionBlock, *EDIDExtensionBlockRef;