#include "stm32f0xx.h"
#include "i2c.h"
#include "utils.h"
#include "m24c01.h"

void m24c01_write(uint8_t address, uint8_t *data, uint8_t length)
{
  uint8_t i;

  while(length)
  {
    i = 16 - (address % 16); // number of bytes to the end of current page
    if(length < i)
      i = length;
    i2c_write(M24C01_ADDR << 1, address, data, i);
    delay_ms(5); // write time delay
    address += i;
    data += i;
    length -= i;
  }
}

void m24c01_read(uint8_t address, uint8_t *data, uint8_t length)
{
  i2c_read(M24C01_ADDR << 1, address, data, length);
}
