patch: make i2c(8) usable for scripting

Poul-Henning Kamp phk at phk.freebsd.dk
Sat May 15 20:14:10 UTC 2021


Here is a patch to make i2c(8) much more usable from scripts and scripting languages:

	http://phk.freebsd.dk/misc/i2c.patch

That patch applies only to -current, I had to give i2c.c a good wash first.

If you are not -current, it will be easier to fetch:

	http://phk.freebsd.dk/misc/i2c.c

	http://phk.freebsd.dk/misc/i2c.8

The patch adds two new modes "-i" and "-iv"

"-i" mode is intended to use from hardware-initialization scripts etc, and treats any error as fatal.

"-iv" on the other hand treats no error as fatal, and is targeted more at python classes, continous
data collection etc.

In both cases i2c(8) takes (argv/stdin) commands like:

	r 0 0x50 16BE 24 8

or

	w 0 0x50 16BE 24 48656c6c 6f20576f 726c6421 0a

(see manpage for details)

These modes always use the I2CRDWR ioctl, which works on all the hardware I have.

The /dev/iic%d filedescriptor is opened and closed for every single
command, in the hope that it will aid multiple separate programs
sharing I2C busses.  I have not actually tried that yet, so it may
need more work (exclusive opens etc.).

Comments & inputs welcome...

Poul-Henning

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-hackers mailing list