From 180614e6196381cb5cac614282c012a1d2e14850 Mon Sep 17 00:00:00 2001 From: Joshua Yang Date: Tue, 27 Feb 2018 15:36:51 +0900 Subject: [PATCH] wiringPi: Enable 'gpio i2cdetect' command Change-Id: I7c2e13e9bb4b6ba9147f2bf16bf94468902b3b98 --- gpio/gpio_odroid.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/gpio/gpio_odroid.c b/gpio/gpio_odroid.c index 362a81b..4616f80 100755 --- a/gpio/gpio_odroid.c +++ b/gpio/gpio_odroid.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -54,9 +55,9 @@ extern void doPins (void) ; #endif #define PI_USB_POWER_CONTROL 38 -#define I2CDETECT "/usr/sbin/i2cdetect" -#define MODPROBE "/sbin/modprobe" -#define RMMOD "/sbin/rmmod" +#define I2CDETECT "i2cdetect" +#define MODPROBE "modprobe" +#define RMMOD "rmmod" int wpMode ; @@ -238,17 +239,39 @@ static void doUnLoad (int argc, char *argv []) */ static void doI2Cdetect (UNU int argc, char *argv []) { - int port = piGpioLayout () == 1 ? 0 : 1 ; + int model, rev, mem, maker, overVolted, port; + const char *device = NULL; char *c, *command ; + piBoardId(&model, &rev, &mem, &maker, &overVolted); + + switch (model) { + case MODEL_ODROID_C1: case MODEL_ODROID_C2: + case MODEL_ODROID_XU3: + device = "/dev/i2c-1"; + port = 1; + break; + case MODEL_ODROID_N1: + device = "/dev/i2c-4"; + port = 4; + break; + default: + break; + } + if ((c = findExecutable (I2CDETECT)) == NULL) { fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ; return ; } - if (!moduleLoaded ("i2c_dev")) { - fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ; - return ; + switch (maker) { + case MAKER_AMLOGIC: + if (!moduleLoaded ("aml_i2c")) { + fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ; + return ; + } + default: + break; } command = malloc (strlen (c) + 16) ;