-
-
Save pdp7/93e10fb94bd65eebc411 to your computer and use it in GitHub Desktop.
grizmio's Patch to make Adafruit's ADC python libraries works with ubuntu xenial, kernel 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/source/c_adc.c b/source/c_adc.c | |
index e0c754c..5269407 100644 | |
--- a/source/c_adc.c | |
+++ b/source/c_adc.c | |
@@ -30,29 +30,28 @@ SOFTWARE. | |
#include "c_adc.h" | |
#include "common.h" | |
-char adc_prefix_dir[40]; | |
+char adc_prefix_dir[49]; | |
int adc_initialized = 0; | |
int initialize_adc(void) | |
{ | |
- char test_path[40]; | |
+ char test_path[49]; | |
FILE *fh; | |
if (adc_initialized) { | |
return 1; | |
} | |
- if (load_device_tree("cape-bone-iio")) { | |
- build_path("/sys/devices", "ocp.", ocp_dir, sizeof(ocp_dir)); | |
- build_path(ocp_dir, "helper.", adc_prefix_dir, sizeof(adc_prefix_dir)); | |
- strncat(adc_prefix_dir, "/AIN", sizeof(adc_prefix_dir)); | |
- | |
+ if (load_device_tree("BB-ADC")) { | |
+ strncat(adc_prefix_dir, "/sys/bus/iio/devices/iio:device0/in_voltage", sizeof(adc_prefix_dir)); | |
+ | |
// Test that the directory has an AIN entry (found correct devicetree) | |
- snprintf(test_path, sizeof(test_path), "%s%d", adc_prefix_dir, 0); | |
+ snprintf(test_path, sizeof(test_path), "%s%d_raw", adc_prefix_dir, 1); | |
fh = fopen(test_path, "r"); | |
if (!fh) { | |
+ puts("wiiii"); | |
return 0; | |
} | |
fclose(fh); | |
@@ -67,10 +66,10 @@ int initialize_adc(void) | |
int read_value(unsigned int ain, float *value) | |
{ | |
FILE * fh; | |
- char ain_path[40]; | |
+ char ain_path[49]; | |
int err, try_count=0; | |
int read_successful; | |
- snprintf(ain_path, sizeof(ain_path), "%s%d", adc_prefix_dir, ain); | |
+ snprintf(ain_path, sizeof(ain_path), "%s%d_raw", adc_prefix_dir, ain); | |
read_successful = 0; | |
@@ -106,5 +105,5 @@ int adc_setup() | |
void adc_cleanup(void) | |
{ | |
- unload_device_tree("cape-bone-iio"); | |
+ unload_device_tree("BB-ADC"); | |
} | |
diff --git a/source/common.c b/source/common.c | |
index 8911a9c..4b07e7c 100644 | |
--- a/source/common.c | |
+++ b/source/common.c | |
@@ -361,12 +361,14 @@ int get_spi_bus_path_number(unsigned int spi) | |
int load_device_tree(const char *name) | |
{ | |
FILE *file = NULL; | |
- char slots[40]; | |
+ char slots[41]; | |
char line[256]; | |
- build_path("/sys/devices", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir)); | |
- snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir); | |
+ // build_path("/sys/devices/platform", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir)); | |
+ snprintf(ctrl_dir, sizeof(ctrl_dir), "/sys/devices/platform/bone_capemgr"); | |
+ snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir); | |
+ | |
file = fopen(slots, "r+"); | |
if (!file) { | |
PyErr_SetFromErrnoWithFilename(PyExc_IOError, slots); | |
@@ -394,11 +396,12 @@ int load_device_tree(const char *name) | |
int unload_device_tree(const char *name) | |
{ | |
FILE *file = NULL; | |
- char slots[40]; | |
+ char slots[41]; | |
char line[256]; | |
char *slot_line; | |
- build_path("/sys/devices", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir)); | |
+ // build_path("/sys/devices/platform", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir)); | |
+ snprintf(ctrl_dir, sizeof(ctrl_dir), "/sys/devices/platform/bone_capemgr"); | |
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir); | |
file = fopen(slots, "r+"); | |
diff --git a/source/common.h b/source/common.h | |
index 2600b40..a9a2c88 100644 | |
--- a/source/common.h | |
+++ b/source/common.h | |
@@ -39,8 +39,8 @@ SOFTWARE. | |
int gpio_mode; | |
int gpio_direction[120]; | |
-char ctrl_dir[35]; | |
-char ocp_dir[25]; | |
+char ctrl_dir[43]; | |
+char ocp_dir[33]; | |
int get_gpio_number(const char *key, unsigned int *gpio); | |
int get_pwm_key(const char *input, char *key); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related to: adafruit/adafruit-beaglebone-io-python#80