

#ifndef smb_h_defined
#define smb_h_defined

#define SMB_PORT	PORTD
#define SMB_DDR		DDRD
#define SMB_PIN		PIND
#define SMB_CLK		7
#define SMB_DAT		6
#define L_DAT	SMB_PORT&=~(_BV(SMB_DAT)); SMB_DDR|=_BV(SMB_DAT)
#define H_DAT	SMB_DDR&=~(_BV(SMB_DAT)); SMB_PORT|=_BV(SMB_DAT)
#define L_CLK	SMB_PORT&=~(_BV(SMB_CLK)); SMB_DDR|=_BV(SMB_CLK)
#define H_CLK	SMB_DDR&=~(_BV(SMB_CLK)); SMB_PORT|=_BV(SMB_CLK)
#define uchar unsigned char
#define RE  1
#define WR	0
#define uint unsigned int
#define temp 0x08
#define voltage 0x09
#define rem_capacity 0x0f
#define full_capacity 0x10
#define	design_capacity	0x18
#define cycle_count 0x17
#define	man_date 0x1b
#define battery_mode 0x03
#define man_date 0x1b
#define full_charge_cap 0x10
#define checkCRC8 47
//LED
#define LED_OFF PORTB|=_BV(PB1)
#define LED_ON PORTB&=~(_BV(PB1))
#define LED_CHANGE PORTB^=_BV(PB1)






void SMBstart(void);
void SMBstop(void);
uchar SMBtx(uchar dataTX);
uchar SMBrx(uchar ack);
uchar BuildAdd(uchar ad, uchar rw);
uchar quick_c(uchar adr);
uchar write_w(uchar adr, uchar cmd, uint data);
uint read_w(uchar adr, uchar cmd);
uchar read_b(uchar adr, uchar cmd);
void detect(void);
uchar action(uchar *rx, uchar *tx);
uchar CrcUpdate(uchar crc, uchar data);

#endif
