/*
 * File:   EEPROM_24xx00-16.h
 * See 24xx00-16_EEPROM.c for title information
 * Created on Thursday, December 18, 2014
*/

#ifndef EEPROM_24XX00_16_H
#define EEPROM_24XX00_16_H

#include <xc.h>
#include "JWD-NHR_Common.h"       // Standard Defines & Generic Type Defs
#include "I2CM.h"                 // MSSP I²C routines

/*═══════════════════════════════ DEFINITIONS ════════════════════════════════*/
#ifdef EEP24XX16
   #define XEEPROMSIZE 0x800           // for 24xx16
#endif
#ifdef EEP24XX08
   #define XEEPROMSIZE 0x400           // for 24xx08
#endif
#ifdef EEP24XX01
   #define XEEPROMSIZE 0x80            // for 24xx01
#endif
#define PAGE_SIZE   16                 // EEPROM Page Size bytes

/*= = = = = = = = = = = = = = EEPROM I²C address = = = = = = = = = = = = = = =*/
#define EEPROM_WR       0b10100000u          // Control code & R/nW=0 bit, sans Block Addr
#define EEPROM_RD       0b10100001u          // Control code & R/nW=1 bit, sans Block Addr
#define EEPROMaddr      0b01010000u          // I²C buss address sans R/nW bit

/*═══════════════════════════ FUNCTION DECLARATIONS ══════════════════════════*/
/*──────────────────── Write data to an EEPROM address ───────────────────────*/
void xeeprom_wr_byte(uInt16 addr, Byte data);

/*────────────────── Write upto 16 Bytes to an EEPROM address ────────────────*/
void xeeprom_wr_page(uInt16 addr,Byte *data, uInt8 length);
// DON'T Cross the Blocks, it's a Bad WRAP
// 16 Bytes MAX & DON'T Cross the Blocks, ONLY increments LSNibble, it's a Bad WRAP

/*──────────────────────────── Read the next byte ────────────────────────────*/
Byte xeeprom_rd_next_byte(void);
// Must be preceeded by a command that sets the Block Select Bits.
// DON'T Cross the Blocks, it's a Bad WRAP

/*───────────────── Random Read byte from an EEPROM address ──────────────────*/
Byte xeeprom_rd_byte(uInt16 addr);

/*───────────────── Read Sequentially from an EEPROM address ─────────────────*/
void xeeprom_rd_page(uInt16 addr, Byte *data, uInt8 length);
// CAN'T CROSS BLOCK BOUNDARIES, WILL WRAP ???

#endif	/* 24XX00_16_EEPROM_H */
