/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx_LCD.h>

#include "AVR_Common.h"


//
// Check the MCU
//
#ifndef __AVR_ARCH_X__

    #ifndef __AVR_ATmega2560__
    #warning "the UART configuration in this test application is meant for ATmega2560 (e.g. Arduino Mega 2560 at 16 MHz)"
    #endif

#else

    #ifndef __AVR_ATmega4808__
    #warning "the pin configuration in this test application is meant for ATmega4808 (e.g. Thinary ATmega4808 at 16 MHz)"
    #endif

#endif


//
// Instantiate a character LCD driver using UART as output method
// (the pin numbers below are the pins of the LCD driver board)
//
#ifndef __AVR_ARCH_X__
//                                 Use UART3         EN  RW  RS     D4  D5  D6  D7     BL BL
static eCxx::CharacterLCD_UART lcd(*App::uart3(),    2,  1,  0,     4,  5,  6,  7,     3, eCxx::ActiveState::High);
#else
//                                 Use UART1         EN  RW  RS     D4  D5  D6  D7     BL BL
static eCxx::CharacterLCD_UART lcd(*App::uart1(),    2,  1,  0,     4,  5,  6,  7,     3, eCxx::ActiveState::High);
#endif


//
// Include common source code for StreamSampler test application
//
#include "../CommonCode/CharacterLCD_Common.h"


//
// The init function
//
void eCxx_user_init()
{
    // Initialize application
    initBasicAVRApp();

    // Initialize UART
#ifndef __AVR_ARCH_X__
    App::uart3()->begin(115200);
#else
    App::uart1()->begin(115200);
#endif

    // Initialize and test the LCD
    eCxx_user_init_lcdInitAndTest();
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event and create animation using the LCD
    eCxx_user_task_lcdAnimate();
}
