#include <inttypes.h>
#include <avr/io.h>
#include "bootloader.h"
uint8_t bootloader_start(void) {
    
    #if ( defined (__AVR_ATmega2561__) || \
      defined (__AVR_ATmega64__))
        DDRG  = 0x00;
        PORTG = _BV(2);
        delay_ms(50);
        if (PING & _BV(2)) {
            PORTG = 0x00;
            return 0x00;
        }
        PORTG = 0x00;
    #else
        DDRB  = 0x00;
        PORTB = _BV(2);
        delay_ms(50);
        if (PINB & _BV(2)) {
            PORTB = 0x00;
            return 0x00;
        }
        PORTB = 0x00;
    #endif
    uart0_send('~');
    string_from_const(display_print, "Bootloader  V4.0");
    display_gotoxy(0,1);
    string_from_const(display_print, "P.W.  23.10.2015");
    return 0xFF;
}
void bootloader_end(void) {
    display_clear();
    uart0_flush();
    delay_ms(10);
    uart0_disable();
}
uint8_t bootloader_data_in(void) {
    return uart0_get();
}
uint8_t bootloader_data_stat(void) {
    return uart0_rxcount_get();
}
void bootloader_data_out(uint8_t data) {
    uart0_send(data);
}
uint8_t bootloader_idle(void) {
    return 0xFF;
}
void bootloader_command(void) {
}
void bootloader_help(void) {
}
uint8_t bootloader_error(void) {
    return 0xFF;
}