// TODO 11.01
#include <stdarg.h>


// TODO 11.02
#define SYS_CONSOLE_PRINT_BUFFER_SIZE	200
static char consolePrintBuffer[SYS_CONSOLE_PRINT_BUFFER_SIZE];
volatile uint8_t TC3_HasExpired = 0;
volatile uint8_t TC4_HasExpired = 0;


// TODO 11.03
void myprintf(const char *format, ...)
{
    size_t len = 0;
    va_list args = {0};
    va_start(args, format);
    len = vsnprintf(consolePrintBuffer, SYS_CONSOLE_PRINT_BUFFER_SIZE, format, args);
    va_end(args);

    if ((len > 0) && (len < SYS_CONSOLE_PRINT_BUFFER_SIZE))
    {
        consolePrintBuffer[len] = '\0';
        SERCOM5_USART_Write(consolePrintBuffer, len);
        while (SERCOM5_USART_WriteIsBusy());
    }
}


// TODO 11.04
        TC3_HasExpired = 1;
        // LED1_Toggle();
        // sprintf((char *) USARTRTxBuffer, "Hello world!\r\n" );
        // SERCOM5_USART_Write( USARTRTxBuffer, strlen((char*)USARTRTxBuffer) );


// TODO 11.05
        TC4_HasExpired = 1;
        // LED2_Toggle();


// TODO 11.06
    myprintf("\033[2J");
    myprintf("\033[?25l");


// TODO 11.07
        if (TC3_HasExpired)
        {
            TC3_HasExpired = 0;
            LED1_Toggle();
            myprintf( "\033[1;1HHello World!" );
        }
        

// TODO 11.08
            // sprintf((char *) USARTRTxBuffer, "\r\nReceived Data : %1c\r\n", USART5_ReceiveData[0] );
            // SERCOM5_USART_Write( USARTRTxBuffer, strlen((char*)USARTRTxBuffer) );
            // while( SERCOM5_USART_WriteIsBusy() );
            myprintf("\033[6;1HReceived Data : %1c", USART5_ReceiveData[0] );
            SERCOM5_USART_Read( USART5_ReceiveData, 1 );

