/* 
* classM41T00.h
*
* Created: 06/02/2020 19:34:16
* Author: Ledo
*/


#ifndef __CLASSM41T00_H__
#define __CLASSM41T00_H__

#include "classPio.h"
#include "classTwi.h"


#define RTC_SLAVE_ADDRESS          0x68 //MT41T00 non shifted address

/// Structure to store time and date
typedef struct m41t00_time_t
{
	uint8_t sec;            ///< Seconds:       0  to 59
	uint8_t min;            ///< Minutes:       0  to 59
	uint8_t hour;           ///< Hours:         0  to 23
	uint8_t day_of_week;    ///< Day of Week:   1  to 7
	uint8_t day_of_month;   ///< Days of Month: 1  to 31 (depending on month)
	uint8_t month;          ///< Months:        1  to 12
	uint8_t year;           ///< Years:         00 to 99
	uint8_t creg;
} m41t00_time_t;

extern classTwi I2C;
extern classPio Puerto;

class classM41T00
{
//variables
public:
    m41t00_time_t decoded_time;
    m41t00_time_t time;
    twi_packet_t twiPacket_m41t00;

protected:
private:
    char segundos;
    char minutos;
    char horas;
    char dia;


//functions
public:
	classM41T00();
	~classM41T00();
	void twi0_init_m41t00(void);
    void  minute_adjust(uint8_t min);
    void  hour_adjust(uint8_t hora);
    void  day_adjust(uint8_t dia);
    void  Time_adjust(uint8_t min,uint8_t hora, uint8_t dia);
	void twi_read_rtc(void);


protected:
private:
	classM41T00( const classM41T00 &c );
	classM41T00& operator=( const classM41T00 &c );
	void twi_write_rtc(void);
	uint8_t m41t00_bcd_to_byte(uint8_t bcd_val);
	uint8_t m41t00_byte_to_bcd(uint8_t byte_val);


}; //classM41T00

#endif //__CLASSM41T00_H__
