Skip to content

Commit c507109

Browse files
authored
Merge pull request #7 from bkrepo/master
wiringPi : change the kernel version getting method for ADC files
2 parents 2ab7013 + b8e185f commit c507109

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

wiringPi/wiringPi.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#include <sys/stat.h>
6969
#include <sys/wait.h>
7070
#include <sys/ioctl.h>
71-
#include <linux/version.h>
71+
#include <sys/utsname.h>
7272

7373
#include "softPwm.h"
7474
#include "softTone.h"
@@ -679,13 +679,8 @@ static int adcFds [2] = {
679679
#define GPIO_B3_PUD_OFFSET 0x00C8
680680
#define GPIO_B3_END 214
681681

682-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)
683-
#define piAinNode0_xu "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage0_raw"
684-
#define piAinNode1_xu "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage3_raw"
685-
#else
686-
#define piAinNode0_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw"
687-
#define piAinNode1_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw"
688-
#endif
682+
static char *piAinNode0_xu;
683+
static char *piAinNode1_xu;
689684

690685
static int piModel = PI_MODEL_UNKNOWN;
691686

@@ -2913,6 +2908,21 @@ int wiringPiSetup (void)
29132908
adcFds [1] = open (C2_piAinNode1, O_RDONLY) ;
29142909
}
29152910
else if ( model == PI_MODEL_ODROIDXU_34 ) {
2911+
// Check the kernel version and then set the ADC files
2912+
struct utsname uname_buf;
2913+
2914+
uname(&uname_buf);
2915+
if (strncmp(uname_buf.release, "4.14", 4) == 0) {
2916+
piAinNode0_xu = "/sys/devices/platform/soc/12d10000.adc/iio:device0/in_voltage0_raw";
2917+
piAinNode1_xu = "/sys/devices/platform/soc/12d10000.adc/iio:device0/in_voltage3_raw";
2918+
} else if (strncmp(uname_buf.release, "4.9", 3) == 0) {
2919+
piAinNode0_xu = "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage0_raw";
2920+
piAinNode1_xu = "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage3_raw";
2921+
} else { // 3.10 kernel
2922+
piAinNode0_xu = "/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw";
2923+
piAinNode1_xu = "/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw";
2924+
}
2925+
29162926
pinToGpio = pinToGpioOdroidXU;
29172927
pin_array_count = ARRAY_SIZE(pinToGpioOdroidXU);
29182928
physToGpio = physToGpioOdroidXU;
@@ -3100,6 +3110,21 @@ int wiringPiSetupSys (void)
31003110
adcFds [1] = open (C2_piAinNode1, O_RDONLY) ;
31013111
}
31023112
else if ( model == PI_MODEL_ODROIDXU_34 ) {
3113+
// Check the kernel version and then set the ADC files
3114+
struct utsname uname_buf;
3115+
3116+
uname(&uname_buf);
3117+
if (strncmp(uname_buf.release, "4.14", 4) == 0) {
3118+
piAinNode0_xu = "/sys/devices/platform/soc/12d10000.adc/iio:device0/in_voltage0_raw";
3119+
piAinNode1_xu = "/sys/devices/platform/soc/12d10000.adc/iio:device0/in_voltage3_raw";
3120+
} else if (strncmp(uname_buf.release, "4.9", 3) == 0) {
3121+
piAinNode0_xu = "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage0_raw";
3122+
piAinNode1_xu = "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage3_raw";
3123+
} else { // 3.10 kernel
3124+
piAinNode0_xu = "/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw";
3125+
piAinNode1_xu = "/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw";
3126+
}
3127+
31033128
pinToGpio = pinToGpioOdroidXU ;
31043129
pin_array_count = ARRAY_SIZE(pinToGpioOdroidXU);
31053130
physToGpio = physToGpioOdroidXU ;

0 commit comments

Comments
 (0)