#include "DS3231.h"
#include "pinout.h"
#include <avr/io.h>
#include "i2cmaster.h"

void DS3231_read(uint8_t dest[3]){
    // set address to 0
    i2c_start_wait(0xD0);
    i2c_write(0x00);
    i2c_stop();

    // read addresses 0, 1 and 2
    i2c_start_wait(0xD1);
    dest[0] = i2c_readAck();
    dest[1] = i2c_readAck();
    dest[2] = i2c_readNak();
    i2c_stop();
}

void DS3231_write(uint8_t inbuffer[3]){
    i2c_start_wait(0xD0);
    i2c_write(0x00);
    i2c_write(inbuffer[0]);
    i2c_write(inbuffer[1]);
    i2c_write(inbuffer[2]);
    i2c_stop();
}
