mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-18 11:09:32 +00:00
README.directories contains a description of the directories I created; read it if you have questions about them. doc/design is the design document I sent before through email. doc/useful_addresses.html contains links to I2C, SMBus and sensors information. Note that we may have to change minor i2c things, like Makefiles; this is why I put it in the archive too (we should, of course, send important changes to Simon Vogl). git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3 7894878c-1315-0410-8ee3-d5d059ff63e0
69 lines
1.5 KiB
C
69 lines
1.5 KiB
C
/* ------------------------------------------------------------------------- */
|
|
/* detect -- look who's there. Gets address acks from all devices on the bus.*/
|
|
/* It should not change any values in the peripherals. */
|
|
/* ------------------------------------------------------------------------- */
|
|
static char *rcsid="$Id: detect.c,v 2.2 1996/11/17 22:03:06 i2c Exp $";
|
|
|
|
#include <unistd.h>
|
|
#include <sys/ioctl.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <linux/delay.h>
|
|
#include "i2c.h"
|
|
|
|
#define Write(a,b,c) err(1,write(a,b,c))
|
|
#define Read(a,b,c) err(0,read(a,b,c))
|
|
|
|
void err(int wr, int d){
|
|
if (d==-1){
|
|
printf("%s error: %s !\n",(wr)?"Write":"Read",strerror(errno));
|
|
}
|
|
}
|
|
#define ERR(x) printf("return value: %d\n", (x) );
|
|
|
|
int main(int argc, char *argv[]){
|
|
int i,f;
|
|
char b[40],c;
|
|
char *device = "/dev/i2c0";
|
|
|
|
/* parse options */
|
|
opterr=1;
|
|
while ( (c=getopt(argc,argv,"hH?d:")) != -1) {
|
|
switch (c){
|
|
case 'd':
|
|
if (optarg)
|
|
device = optarg;
|
|
break;
|
|
case 'h':
|
|
case 'H':
|
|
case '?':
|
|
default:
|
|
printf("%s tries to detect devices on the i2c-bus. Usage:\n",argv[0]);
|
|
printf("-d device device to use\n");
|
|
return 0;
|
|
}
|
|
}
|
|
f=open(device,O_RDWR);
|
|
if (f<0){
|
|
perror("detect");
|
|
exit(1);
|
|
}
|
|
ERR( ioctl(f,I2C_UDELAY,10) );
|
|
ERR( ioctl(f,I2C_MDELAY,0) );
|
|
// ERR( ioctl(f,I2C_RETRIES,3) );
|
|
|
|
for (i=0;i<128;i++){
|
|
ioctl(f,I2C_SLAVE,i);
|
|
if (0>read (f,b,0) ) {
|
|
putchar('.');
|
|
} else {
|
|
printf("\n%d worked! \n",i);
|
|
}
|
|
usleep(100);
|
|
fflush(stdout);
|
|
}
|
|
putchar('\n');
|
|
return close(f);
|
|
}
|