From bed829366e29d76046a312ace153f2a225c494cb Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 14 Apr 2023 12:54:10 +0200 Subject: [PATCH] edid: add di_edid_format() Signed-off-by: Simon Ser --- edid.c | 25 +++++++++++++++++++++++++ include/libdisplay-info/edid.h | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/edid.c b/edid.c index 7abe7bb..d2bf74e 100644 --- a/edid.c +++ b/edid.c @@ -1707,3 +1707,28 @@ error: di_edid_destroy(copy); return NULL; } + +ssize_t +di_edid_format(const struct di_edid *edid, void *buf, size_t buf_size) +{ + size_t size; + uint8_t *data; + + size = EDID_BLOCK_SIZE * (1 + edid->exts_len); + if (buf == NULL) { + return (ssize_t) size; + } else if (buf_size < size) { + return -1; + } + + memset(buf, 0, size); + + data = buf; + memcpy(data, header, sizeof(header)); + data[0x12] = (uint8_t) edid->version; + data[0x13] = (uint8_t) edid->revision; + + /* TODO */ + + return (ssize_t) size; +} diff --git a/include/libdisplay-info/edid.h b/include/libdisplay-info/edid.h index 5272e1c..68ef81d 100644 --- a/include/libdisplay-info/edid.h +++ b/include/libdisplay-info/edid.h @@ -12,6 +12,7 @@ #include #include #include +#include /** * EDID data structure. @@ -33,6 +34,18 @@ di_edid_destroy(struct di_edid *edid); struct di_edid * di_edid_dup(const struct di_edid *edid); +/** + * Format an EDID. + * + * If buf is NULL, the size of the EDID is returned without writing the EDID. + * If buf is not NULL, buf_size must be its capacity in bytes. + * + * On success, the size of the EDID in bytes is returned. On error, a negative + * integer is returned. + */ +ssize_t +di_edid_format(const struct di_edid *edid, void *buf, size_t buf_size); + /** * Get the EDID version. */