IIC(4)
π IIC(4) β the I2C bestie edit π
ioctl man page, but make it cute β Debian vibes, May 15, 2015
β¨ NAME β¨
iic β the generic I/O device driver for I2C, aka your bestie for talking to tiny chips on the bus π¦
πΈ SYNOPSIS πΈ
device iic
#include <dev/iicbus/iic.h>
π DESCRIPTION π
Okay so the iic device driver gives you generic I/O to any iicbus(4) instance. Like, any of them. No cap. To actually control I2C devices you talk to /dev/iic? with these ioctls, bestie π
I2CSTART(struct iiccmd)β Sends the start condition to the slave specified by theslaveelement to the bus. Theslaveelement is a 7-bit address plus a read/write bit (that is, a 7-bit address << 1 | r/w). A read operation kicks off when the read/write bit is set, or a write operation when it is cleared. All other elements are ignored. If it succeeds, the file descriptor gets exclusive ownership of the underlyingiicbusinstance. πI2CRPTSTART(struct iiccmd)β Sends the repeated start condition to the slave specified by theslaveelement to the bus. The slave address should be specified as inI2CSTART. All other elements are ignored. And heads up:I2CSTARTmust have previously been issued on the same file descriptor, k? πI2CSTOPβ No argument is passed. Sends the stop condition to the bus. IfI2CSTARTwas previously issued on the file descriptor, the current transaction is terminated and exclusive ownership of the underlyingiicbusinstance is released. Otherwise, no action is performed. Chill. πI2CRSTCARD(struct iiccmd)β Resets the bus. The argument is completely ignored (like, literally don't even). This command does not requireI2CSTARTto have been previously issued on the file descriptor. But if it was previously issued, exclusive ownership of the underlyingiicbusinstance is released.I2CWRITE(struct iiccmd)β Writes data to theiicbus(4). The bus must already be started by a previousI2CSTARTon the file descriptor. Theslaveelement is ignored. Thecountelement is the number of bytes to write. Thelastelement is a boolean flag β it must be zero when additional read commands will follow, or non-zero if this is the last command. Thebufelement is a pointer to the data to write to the bus. βοΈI2CREAD(struct iiccmd)β Reads data from theiicbus(4). The bus must already be started by a previousI2CSTARTon the file descriptor. Theslaveelement is ignored. Thecountelement is the number of bytes to read. Thelastelement is a boolean flag β it must be zero when additional read commands will follow, or non-zero if this is the last command. Thebufelement is a pointer to where to store the data read from the bus. β οΈ Short reads on the bus produce undefined results β so like, don't do that, fr fr.I2CRDWR(struct iic_rdwr_data)β The generic read/write interface. Allows for an arbitrary number of commands to be sent to an arbitrary number of devices on the bus. Any previous transaction started byI2CSTARTmust be terminated byI2CSTOPorI2CRSTCARDbeforeI2CRDWRcan be issued on the same file descriptor. A read transfer is specified ifIIC_M_RDis set inflags. Otherwise the transfer is a write transfer. Theslaveelement specifies the 7-bit address with the read/write bit for the transfer. The read/write bit will be handled by theiicbusstack based on the specified transfer operation. Thelenelement is the number of(struct iic_msg)messages encoded on(struct iic_rdwr_data). Thebufelement is a buffer for that data. This ioctl is intended to be Linux compatible. π§I2CSADDR(uint8_t)β Associates the specified address with the file descriptor for use by subsequentread(2)orwrite(2)calls. The argument is an 8-bit address (that is, a 7-bit address << 1). The read/write bit in the least-significant position is ignored. Any subsequent read or write operation will set or clear that bit as needed. π―
The following data structures are defined in <dev/iicbus/iic.h> and referenced above β here they are in all their glory, verbatim, because icon behavior only:
struct iiccmd {
u_char slave;
int count;
int last;
char *buf;
};
/* Designed to be compatible with linux's struct i2c_msg */
struct iic_msg
{
uint16_t slave;
uint16_t flags;
#define IIC_M_WR 0 /* Fake flag for write */
#define IIC_M_RD 0x0001 /* read vs write */
#define IIC_M_NOSTOP 0x0002 /* do not send a I2C stop after message */
#define IIC_M_NOSTART 0x0004 /* do not send a I2C start before message */
uint16_t len; /* msg length */
uint8_t * buf;
};
struct iic_rdwr_data {
struct iic_msg *msgs;
uint32_t nmsgs;
};
It is also possible to use read(2) or write(2), in which case the I2C start/stop handshake is managed by iicbus(4). The address used for the read/write operation is the one passed to the most recent I2CSTART ioctl(2) or I2CSADDR ioctl(2) on the open /dev/iic? file descriptor. π«
Closing the file descriptor clears any addressing state established by a previous I2CSTART or I2CSADDR, stops any transaction established by a not-yet-terminated I2CSTART, and releases iicbus ownership. Because addressing state is stored on a per-file-descriptor basis, it is permissible for multiple file descriptors to be simultaneously open on the same /dev/iic? device. Concurrent transactions on those descriptors are synchronized by the exclusive-ownership requests issued to the underlying iicbus instance. So yes, bestie, you can have multiple tabs open β the bus keeps it all in check. π§
π¦ SEE ALSO π¦
ioctl(2), read(2), write(2), iicbus(4)
π HISTORY π
The iic manual page first appeared in FreeBSD 3.0 β she's been here a minute, an OG. π
π AUTHORS π
This manual page was written by Nicolas Souchu and M. Warner Losh. Absolute legends, no cap. π«Ά
kisses, this was the Debian IIC(4) page β dated May 15, 2015, and yes, it's still that girl. π
π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1998, Nicolas Souchu All rights reserved
- Copyright (c) 2006 M. Warner Losh <imp@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms