Difference between revisions of "ADC overo 2.6.39+"
m (→Using the ADC's) |
m (added brief example on reading adc's in c via fopen and fread) |
||
Line 81: | Line 81: | ||
>>> | >>> | ||
− | == | + | ==Using sysfs in c and fopen and fread== |
+ | <nowiki> | ||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | #include <sys/types.h> | ||
+ | #include <sys/stat.h> | ||
+ | #include <unistd.h> | ||
+ | #include <fcntl.h> | ||
+ | #include <sys/mman.h> | ||
+ | #include <time.h> | ||
+ | #include <string.h> | ||
+ | |||
+ | FILE *fp; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | |||
+ | |||
+ | char read_value[4]; | ||
+ | |||
+ | char adcVal2[6]; | ||
+ | |||
+ | if (( fp = fopen("/sys/class/hwmon/hwmon1/device/in2_input", "r")) == NULL) | ||
+ | { | ||
+ | printf("Can not open hwmon1 \n"); | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | rewind(fp); | ||
+ | |||
+ | fread(&read_value, sizeof(char), 1 , fp); | ||
+ | strcpy(adcVal2 , read_value); | ||
+ | |||
+ | fclose(fp); | ||
+ | printf("\nADC 2 value = %s \n",adcVal2); | ||
+ | |||
+ | |||
+ | |||
+ | return 0; | ||
+ | }</nowiki> | ||
==Building your own kernel == | ==Building your own kernel == |
Revision as of 22:44, 20 September 2011
Contents
Using the ADC's
From posts in the mailing list by Steve Sakoman and others
In linux-omap3-2.6.39 and 3.0 and above
The madc driver is now upstream and in the process it moved to the hwmon subsystem. It is now even easier to access using the /sys/class interface:
root@omap3-multi:~# ls /sys/class/hwmon/hwmon1/device/
curr10_input in11_input in3_input in7_input power
driver in12_input in4_input in8_input subsystem
hwmon in15_input in5_input in9_input temp1_input
in0_input in2_input in6_input modalias uevent
root@omap3-multi:~# cat /sys/class/hwmon/hwmon1/device/temp1_input
56
root@omap3-multi:~# cat /sys/class/hwmon/hwmon1/device/curr10_input
-750
ADC's via a system call
a quick and very nasty way to access them is by a system call
C
system("cat /sys/class/hwmon/hwmon1/device/in7_input");
Python
os.system("cat /sys/class/hwmon/hwmon1/device/in7_input")
Python
import os
import sys
import subprocess
cmd1 = "cat /sys/class/hwmon/hwmon1/device/in7_input"
process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
udata = process.stdout.read().strip()
print udata
In console (in interactive mode)
python
Python 2.6.6 (r266:84292, Sep 1 2011, 13:08:10)
[GCC 4.3.3] on linux2
>>> import os
>>> import sys
>>> import subprocess
>>> cmd1 = "cat /sys/class/hwmon/hwmon1/device/in7_input"
>>> process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
>>> os.waitpid(process.pid, 0)[1]
0
>>> udata = process.stdout.read().strip()
>>> print udata
1388
>>>
Using sysfs in c and fopen and fread
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <time.h> #include <string.h> FILE *fp; int main(void) { char read_value[4]; char adcVal2[6]; if (( fp = fopen("/sys/class/hwmon/hwmon1/device/in2_input", "r")) == NULL) { printf("Can not open hwmon1 \n"); exit(1); } rewind(fp); fread(&read_value, sizeof(char), 1 , fp); strcpy(adcVal2 , read_value); fclose(fp); printf("\nADC 2 value = %s \n",adcVal2); return 0; }
Building your own kernel
When building your own kernel Make sure your defconfig has CONFIG_TWL4030_MADC and CONFIG_SENSORS_TWL4030_MADC and make sure your rootfs has the module.
Link to kernel docs for Kernel driver twl4030-madc http://www.sakoman.com/cgi-bin/gitweb.cgi?p=linux-omap-2.6.git;a=blob;f=Documentation/hwmon/twl4030-madc-hwmon;h=ef7984317cecb29eca6ef23a30c21d920e66ef31;hb=refs/heads/omap-2.6.39-pm