/*
Diplomova prace : Palubni pocitac

ibutton.c

Atmega128A 10 MHz XTAL

Autor: Ondrej Lutera

2011/2012

*/
#include "ibutton.h"


unsigned char ibuttonFind(void)
{

    ow_set_bus(&IBUT_PIN,&IBUT_PORT,&IBUT_DDR,IBUT);
    ow_parasite_enable();

    return !ow_reset();

}

void ibuttonRead(ibutton_t * pStruct)
{

    unsigned char i;

    ow_set_bus(&IBUT_PIN,&IBUT_PORT,&IBUT_DDR,IBUT);
    ow_parasite_enable();


    ow_reset();

    ow_byte_wr(0x33)  ;

    for ( i = 0; i < SP_SIZE; i++ )
    {
        pStruct->romCode[SP_SIZE-1-i] = ow_byte_rd();
    }



#ifdef CAR_DEBUG
    uart_puts_P("iButton:");
    for ( i = 0; i < SP_SIZE; i++ )uart_puthex_byte(pStruct->romCode[i]);
    uart_putc('\n');
#endif
}

void ibuttonLed(unsigned char bit)
{

    IBUT_LED_DDR |= 1 << IBUT_LED;

    if(bit)IBUT_LED_PORT|= 1 << IBUT_LED;
    else IBUT_LED_PORT&=~(1 << IBUT_LED);

}
