/*
 * Copyright(C) Paul und Scherer (mct.de/mct.net)
 *
 * This example demonstrates how to...
 *
 *  ... master the IIC bus.
 */

#include <stdio.h>
#include "iic.h"

/*
 * Scan the IIC bus for available devices.
 *
 * Scanning is done by dummy writes to all devices,
 * i.e. each device is selected for write, but with
 * no data actually written. Instead, the operation
 * is aborted by the start condition addressing the
 * next device.
 *
 * All devices acknowledge their addresses, so each
 * successful access indicates a present device.
 */
int
main(void)
{
	int devs;				// # of devices
	int addr;				// IIC bus device addr

	iic_init();				// initialize IIC bus interface

	while (1) {
		puts("\nHit any key to scan the IIC bus..."), getchar();
		puts("Scanning...");
		for (devs = addr = 0; addr < 256; addr += 2) if (!iic_start(addr)) printf("device found @0x%02x\n", addr), devs++;
		printf("done.\n\n%d devices found.\n", devs);
	}
}
