From 7c07bdc08c61a8d751d05a1823911337a50dd7dd Mon Sep 17 00:00:00 2001 From: YoungSoo Shin Date: Wed, 2 Jul 2025 09:58:38 +0900 Subject: [PATCH] Revert "ODROID-C5: analog: fix for ODROID-C5" This reverts commit 4a66eefe5d88ebfe6f7755ae43e9b07e332e926a. --- src/linux/analog.c | 48 ++++++++-------------------------------------- src/linux/gpio.h | 2 -- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/linux/analog.c b/src/linux/analog.c index 94c97347..7ca1ee2d 100644 --- a/src/linux/analog.c +++ b/src/linux/analog.c @@ -14,54 +14,30 @@ #include "sched.h" // sched_shutdown // ODROID-C5 -DECL_CONSTANT("ADC_MAX", 1800); +DECL_CONSTANT("ADC_MAX", 1800); // Assume 12bit adc #define ANALOG_START (1<<12) DECL_ENUMERATION_RANGE("pin", "analog0", ANALOG_START, 8); // ODROID-C5 -#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage0_raw" -#define SCALE_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_scale" -#define OFFSET_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_offset" +#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage%d_input" struct gpio_adc gpio_adc_setup(uint32_t pin) { - struct gpio_adc g; - int fd; - char buf[64]; - int ret; + char fname[256]; + snprintf(fname, sizeof(fname), IIO_PATH, pin-ANALOG_START); - fd = open(SCALE_PATH, O_RDONLY); - ret = read(fd, buf, sizeof(buf)-1); - if (ret <= 0) { - goto fail; - } - buf[ret] = '\0'; - g.scale = atof(buf) * 1000; - close(fd); - - fd = open(OFFSET_PATH, O_RDONLY); - ret = read(fd, buf, sizeof(buf)-1); - if (ret <= 0) { - goto fail; - } - buf[ret] = '\0'; - g.offset = atoi(buf); - close(fd); - - fd = open(IIO_PATH, O_RDONLY|O_CLOEXEC); + int fd = open(fname, O_RDONLY|O_CLOEXEC); if (fd < 0) { report_errno("analog open", fd); goto fail; } - ret = set_non_blocking(fd); + int ret = set_non_blocking(fd); if (ret < 0) goto fail; - - g.fd = fd; - return g; + return (struct gpio_adc){ .fd = fd }; fail: if (fd >= 0) close(fd); @@ -78,7 +54,6 @@ uint16_t gpio_adc_read(struct gpio_adc g) { char buf[64]; - int voltage; int ret = pread(g.fd, buf, sizeof(buf)-1, 0); if (ret <= 0) { report_errno("analog read", ret); @@ -86,14 +61,7 @@ gpio_adc_read(struct gpio_adc g) return 0; } buf[ret] = '\0'; - - voltage = atoi(buf) + g.offset; - voltage = voltage > 0 ? voltage : 0; - voltage = voltage * g.scale; - voltage = voltage < 1800000 ? voltage : 1800000; - voltage /= 1000; - - return voltage; + return atoi(buf); } void diff --git a/src/linux/gpio.h b/src/linux/gpio.h index 302063b1..d72007c2 100644 --- a/src/linux/gpio.h +++ b/src/linux/gpio.h @@ -20,8 +20,6 @@ void gpio_in_reset(struct gpio_in g, int8_t pull_up); uint8_t gpio_in_read(struct gpio_in g); struct gpio_adc { - int scale; - int offset; int fd; }; struct gpio_adc gpio_adc_setup(uint32_t pin);