#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

struct iiccmd { unsigned char slave; int count; int last; char *buf; };
#define I2CSTART  _IOW('i', 1, struct iiccmd)
#define I2CSTOP   _IO('i', 2)
#define I2CRSTCARD _IOW('i', 3, struct iiccmd)

int main(void) {
	struct iiccmd c; int fd, r;
	fd = open("/dev/iic0", O_RDWR);
	if (fd < 0) { printf("open /dev/iic0: %s\n", strerror(errno)); return 1; }
	printf("opened /dev/iic0\n");
	memset(&c, 0, sizeof(c)); c.slave = 0x50;
	r = ioctl(fd, I2CRSTCARD, &c);
	printf("I2CRSTCARD -> r=%d errno=%d (%s)\n", r, errno, strerror(errno));
	memset(&c, 0, sizeof(c)); c.slave = 0x50;
	r = ioctl(fd, I2CSTART, &c);
	printf("I2CSTART -> r=%d errno=%d (%s)\n", r, errno, strerror(errno));
	if (r == 0) { r = ioctl(fd, I2CSTOP); printf("I2CSTOP -> %d\n", r); }
	return 0;
}
