I2C bus master and slave.  HD Associates, Inc.

This will build both a master and slave end of a simulated I2C
bus and transfer "hello world" between the two ends.

Note: You DO NOT need any of the "i2cslave" routines unless you
wish to act as a slave on the bus.  I'm using this to drive
the simulated bus through its paces as a demonstration and test.
A real master-only needs to only provide the hooks defined in
i2csite.h and nano.h.  Stub versions for i2csite.h are in i2c.c.

To send or receive data on the i2c bus first provide the macros
as specified in "i2c.c":

/* You need these macros in i2csite.h:
 *
 * I2C_IMAGE:      An image of the output i2c register.
 *                 This is for a register with bits that you must preserve.
 *                 When undefined a local static is used.
 * I2C_IMAGE_LOCK():
 * I2C_IMAGE_UNLOCK():
 *                 Macros that lock/unlock the I2C_IMAGE register.
 *                 These can't be defined if I2C_IMAGE isn't defined.
 *
 * I2C_CLOCK:      Output bit for the i2c clock.
 * I2C_DATA:       Output bit for the i2c data.
 * I2C_OUT(val):   A macro or function that will send out to the i2c port.
 * I2C_IN():       A macro that will get from the i2c port.
 *
 * Optionally:
 *
 * I2C_CLOCK_IN:   input bit for the i2c clock.
 * I2C_DATA_IN:    input bit for the i2c data.
 *
 * When undefined these are defined as I2C_CLOCK and I2C_DATA.
 */

Then provide the nanotimer functions as specified in nano.h:

	typedef u_int nanotimer_t;

	nanotimer_t nanotimer_set(u_long);
	int nanotimer_elapsed(nanotimer_t *);
	void nanodelay(u_long);

	/* nanonow is for the debugging display and isn't needed.
	 */
	u_long _nanonow(void);

Finally, call "i2c_init() and do your reads/writes:

> int main(int argc, char *argv[])
> {
> 	ssize_t n;
> 	char s[] = "Hello world";
> 
> 	i2c_init();
> 
> 	if( (n = i2c_write(8, s, sizeof(s))) != sizeof(s))
> 		fprintf(stderr, "wrote %d not %d.\n", n, sizeof(s));
> 
> 	return errno;
> }
