Max' EDID generation implementation in C.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

#include <stdio.h>
#include "edid.h"
#define FAILURE(buf_str, line) \
fprintf(stderr, "X Failed on line %d: [%s]\n", line, buf_str); \
return EXIT_FAILURE;
#define SUCCESS(buf_str, line) \
fprintf(stdout, "✓ Success on line %d: [%s]\n", line, buf_str);
#define CHECK_TRUE(expr) \
if (!(expr)) { \
FAILURE(#expr, __LINE__); \
} else { \
SUCCESS(#expr, __LINE__); \
}
static const uint8_t i2c_data_screen_0[EDID_LEN] = {
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1e, 0x6d, 0xd5, 0x59, 0x04, 0x45, 0x09, 0x00,
0x03, 0x17, 0x01, 0x03, 0x68, 0x35, 0x1e, 0x78, 0xea, 0x33, 0x31, 0xa4, 0x57, 0x51, 0xa0, 0x26,
0x10, 0x50, 0x54, 0xa7, 0x6b, 0x80, 0xb3, 0x00, 0x81, 0x80, 0x95, 0x00, 0x71, 0x4f, 0xa9, 0xc0,
0x81, 0x00, 0x81, 0xc0, 0x90, 0x40, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c,
0x45, 0x00, 0x09, 0x25, 0x21, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, 0x4b, 0x1e,
0x53, 0x0f, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x32,
0x34, 0x45, 0x4e, 0x33, 0x33, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xff,
0x00, 0x33, 0x30, 0x33, 0x4e, 0x44, 0x51, 0x41, 0x48, 0x56, 0x34, 0x39, 0x32, 0x0a, 0x00, 0xf1
};
/**
* @brief Helper function to compare EDID data structure with golden design data structure extracted from real
* VGA screen.
*/
static int compare_edid(const uint8_t* const edid, const uint8_t* const edid_golden)
{
for (int sanny=0; sanny<EDID_LEN; sanny++) {
CHECK_TRUE(edid[sanny] == edid_golden[sanny]);
}
return 0;
}
/**
* @brief Helper function to show buffer
*/
static void disp_buf(uint8_t *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
printf("%02x ", buf[i]);
if ((i + 1) % 16 == 0) {
printf("\n");
}
}
printf("\n");
}
int main(void)
{
edid_t edith;
const char* const json_file = "edid0.json";
/* 1) If check fails the structure has been build up in the wrong way on the target platform.
*/
CHECK_TRUE(sizeof(edid_t) == EDID_LEN);
/* 2) If check fails the EDID data structure could not be generated.
*/
CHECK_TRUE(generate_edid(&edith, json_file) == 0);
/* 3) 128 checks in one function to probe every single byte.
*/
int ret = 0;
if (ret = compare_edid((uint8_t*)&edith, i2c_data_screen_0)) {
printf("ret> %d\n", ret);
return ret;
}
printf("\n");
printf("Generated EDID data from %s:\n", json_file);
disp_buf((uint8_t*)&edith, EDID_LEN);
return 0;
}