From e52c38f0515adbc51e8b2c4d5addde2be4ea1067 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Tue, 20 Aug 2024 11:42:12 +0200 Subject: [PATCH] edid-decode: check if linux/i2c-dev.h is available Skip building ddc.cpp and disable related options if linux/i2c-dev.h is not found. This makes it easier to build on non-linux environments. Signed-off-by: Hans Verkuil --- ddc.cpp | 4 ---- edid-decode.cpp | 19 +++++++------------ edid-decode.h | 10 ++++++++++ meson.build | 7 ++++++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ddc.cpp b/ddc.cpp index 6bdd50b..939e968 100644 --- a/ddc.cpp +++ b/ddc.cpp @@ -5,8 +5,6 @@ * Author: Hans Verkuil */ -#ifndef __EMSCRIPTEN__ - #include #include #include @@ -346,5 +344,3 @@ int read_hdcp_ri(int adapter_fd, double ri_time) } return 0; } - -#endif diff --git a/edid-decode.cpp b/edid-decode.cpp index 11c85c7..d565da0 100644 --- a/edid-decode.cpp +++ b/edid-decode.cpp @@ -107,10 +107,12 @@ static struct option long_options[] = { { "fbmode", no_argument, 0, OptFBModeTimings }, { "v4l2-timings", no_argument, 0, OptV4L2Timings }, { "diagonal", required_argument, 0, OptDiag }, +#ifdef __HAS_I2C_DEV__ { "i2c-adapter", required_argument, 0, OptI2CAdapter }, { "i2c-edid", no_argument, 0, OptI2CEDID }, { "i2c-hdcp", no_argument, 0, OptI2CHDCP }, { "i2c-hdcp-ri", required_argument, 0, OptI2CHDCPRi }, +#endif { "std", required_argument, 0, OptSTD }, { "dmt", required_argument, 0, OptDMT }, { "vic", required_argument, 0, OptVIC }, @@ -164,10 +166,12 @@ static void usage(void) " -u, --utf8 Convert strings in EDIDs to UTF-8.\n" " --version Show the edid-decode version (SHA).\n" " --diagonal Set the display's diagonal in inches.\n" +#ifdef __HAS_I2C_DEV__ " -a, --i2c-adapter Use /dev/i2c- to access the DDC lines.\n" " --i2c-edid Read the EDID from the DDC lines.\n" " --i2c-hdcp Read the HDCP from the DDC lines.\n" " --i2c-hdcp-ri= Read and print the HDCP Ri information every seconds.\n" +#endif " --std , Show the standard timing represented by these two bytes.\n" " --dmt Show the timings for the DMT with the given DMT ID.\n" " --vic Show the timings for this VIC.\n" @@ -2329,7 +2333,7 @@ int main(int argc, char **argv) case OptDiag: state.diagonal = strtod(optarg, NULL); break; -#ifndef __EMSCRIPTEN__ +#ifdef __HAS_I2C_DEV__ case OptI2CAdapter: { unsigned num = strtoul(optarg, NULL, 0); @@ -2446,26 +2450,17 @@ int main(int argc, char **argv) if (optind == argc) { if (adapter_fd >= 0 && options[OptI2CEDID]) { -#ifndef __EMSCRIPTEN__ ret = read_edid(adapter_fd, edid); -#else - ret = -ENODEV; -#endif if (ret > 0) { state.edid_size = ret * EDID_PAGE_SIZE; state.num_blocks = ret; ret = 0; } } else if (adapter_fd >= 0) { -#ifndef __EMSCRIPTEN__ if (options[OptI2CHDCP]) - read_hdcp(adapter_fd); + ret = read_hdcp(adapter_fd); if (options[OptI2CHDCPRi]) - read_hdcp_ri(adapter_fd, hdcp_ri_sleep); -#else - ret = -ENODEV; -#endif - ret = 0; + ret = read_hdcp_ri(adapter_fd, hdcp_ri_sleep); } else if (options[OptInfoFrame] && !options[OptGTF]) { ret = 0; } else { diff --git a/edid-decode.h b/edid-decode.h index c62650e..926fa33 100644 --- a/edid-decode.h +++ b/edid-decode.h @@ -615,9 +615,19 @@ char *extract_string(const unsigned char *x, unsigned len, bool is_cp437); #define oneoui(c,k,n) const unsigned kOUI_##k = __LINE__<<12; #include "oui.h" +#ifdef __HAS_I2C_DEV__ + int request_i2c_adapter(unsigned adapnr); int read_edid(int adapter_fd, unsigned char *edid); int read_hdcp(int adapter_fd); int read_hdcp_ri(int adapter_fd, double ri_time); +#else + +static inline int read_edid(int adapter_fd, unsigned char *edid) { return -ENODEV; } +static inline int read_hdcp(int adapter_fd) { return -ENODEV; } +static inline int read_hdcp_ri(int adapter_fd, double ri_time) { return -ENODEV; } + +#endif + #endif diff --git a/meson.build b/meson.build index 513ba93..5cd94cd 100644 --- a/meson.build +++ b/meson.build @@ -50,7 +50,6 @@ endif edid_decode_sources = [ 'calc-gtf-cvt.cpp', 'calc-ovt.cpp', - 'ddc.cpp', 'edid-decode.cpp', 'parse-base-block.cpp', 'parse-cta-block.cpp', @@ -61,6 +60,12 @@ edid_decode_sources = [ 'parse-if.cpp', ] +cc = meson.get_compiler('cpp') +if cc.has_header('linux/i2c-dev.h') + edid_decode_sources += ['ddc.cpp'] + edid_decode_args += ['-D__HAS_I2C_DEV__'] +endif + edid_decode = executable( 'edid-decode', sources: edid_decode_sources, -- 2.11.4.GIT