/*
   *
   *  i2c16.h         (optimized version to minimize code size)
   *  v1.0 (22/04/2003)
   *
   *  16 bits address memory acces for i2c protocol
   *  Library for HI-TECH PIC C - master mode only.
   *  Optimized version to reduce code size
   *  Supported divices: 24xx32, 24xx64, 24xx65, 24xx128, 24xx256 
   *
   *  This library use i2c library for low level I/O.
   *
   *  Written by Philippe Corbes <philippe.corbes@laposte.net>
   *  This code is free for personal use.
   *  You need my agreement for a commercial use. 
   *
   */

  //-------------------- I2C global defs -------------------- 

  #define I2C_EEPROM_UPDATE   11      /* Delay for transfert cache to EEPROM */

  // Struct used to acces to i2c bus 
  typedef struct I2C16 {
      unsigned char   component;      /* Control byte in he i2c protocol*/
      unsigned int    address;        /* Addres to acces in the component */
      int             error;          /* Return value. If negative then ERROR */
                                      /* If positive then extract the lower byte to get read data */
                                      /* Check i2c.h to get more information about error codes */
  };

  extern struct I2C16  i2c16 ;        /* Global struct defined in i2c16.c */

  //------------------- TODO in your code: --------------------
  //
  // 1) Before anything, call i2c_init()
  // 2) You need before read or write component, init witch component you want acces 
  //    and at witch address. Take care to init :
  //    i2c16.component  and  i2c16.address
  // 3) Call read or write function
  // 4) Check i2c16.error 
  //

  //------------------- Functions interface --------------------

  /*
   *  Read a byte from the slave and acknowledges the transfer
   *
   *  Input:  - i2c16.component
   *          - i2c16.address
   *  Output: update i2c16.error
   *          - the byte if no error
   *          - I2C_BUSY on Line busy by an other node
   *          - I2C_ERROR on bus error
   *          - I2C_ACK_TIMEOUT on ack timeout
   */
  extern void
  i2c16_read(void);


  /*
   *  Write specified data byte in i2c device 
   *
   *  Input:  - i2c16.component
   *          - i2c16.address
   *  Output: update i2c16.error
   *          - I2C_OK if ack received from slave
   *          - I2C_BUSY on Line busy by an other node
   *          - I2C_ERROR on bus error
   *          - I2C_ACK_TIMEOUT on ack timeout
   */
  extern void
  i2c16_write(unsigned char   data );


  /*
   *  Read a numbrer of bytes and strore them at '*data'
   *  The number of bytes to read is specified by 'length'
   *
   *  Input:  - i2c16.component
   *          - i2c16.address
   *  Output: update i2c16.error
   *          - the lastbyte if no error
   *          - I2C_ERROR on bus error
   *          - I2C_BUSY on Line busy by an other node
   *          - I2C_ACK_TIMEOUT if no ack received eq no ack 
   */
  extern void
  i2c16_read_seq( unsigned char   length,
                  unsigned char   *abyte);


  /*
   *  Write a numbrer of bytes from '*data' to the i2c component
   *  The number of bytes to write is specified by 'length'
   *
   *  Input:  - i2c16.component
   *          - i2c16.address
   *  Output: update i2c16.error
   *          - I2C_OK if ack received from slave
   *          - I2C_BUSY on Line busy by an other node
   *          - I2C_ERROR on bus error
   *          - I2C_ACK_TIMEOUT on ack timeout
   */
  extern void
  i2c16_write_seq(unsigned char   length,
                  unsigned char   *abyte);