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


#include <eCxx/eCxx.h>

#include "AVR_Common.h"


//
// Include common source code for HWInfo test application
//
#include "../CommonCode/HWInfo_Common.h"


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

    // Initialize UART and print common hardware information
    auto& u = initUARTAndPrintCommonHWInfo();

    // Print platform-specific hardware information
    u.writeString( PGM_STR("Text section   size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::textSectionSize    (), 9 );
    u.writeString( PGM_STR("Data section   size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::dataSectionSize    (), 9 );
    u.writeString( PGM_STR("BSS  section   size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::bssSectionSize     (), 9 );
    u.write      ( '\n'                                          );
    App::yield();
    u.writeString( PGM_STR("Used stack     size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::usedStackSize      (), 9 );
    u.writeString( PGM_STR("Used heap      size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::usedHeapSize       (), 9 );
    u.write      ( '\n'                                          );
    App::yield();
    u.writeString( PGM_STR("Free RAM       size     (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::freeRAMSize        (), 9 );
    u.writeString( PGM_STR("Malloc margin           (bytes) : ") ); u.writeDecStringln( eCxx::HWInfo::mallocMargin       (), 9 );
    u.write      ( '\n'                                          );
    App::yield();
    u.writeString( PGM_STR("Number of digital pins          : ") ); u.writeDecStringln( eCxx::HWInfo::numberOfDigitalPins(), 9 );
    u.writeString( PGM_STR("Number of PWM     pins          : ") ); u.writeDecStringln( eCxx::HWInfo::numberOfPWMPins    (), 9 );
    u.writeString( PGM_STR("Number of ADC     pins          : ") ); u.writeDecStringln( eCxx::HWInfo::numberOfADCPins    (), 9 );
    u.write      ( '\n'                                          );
    App::yield();

#ifdef ECXX_HAVE_PROGRAM_STRING_LITERALS
    // Test string literals in program memory by using literal operators for string literals
    testProgramStringLiterals(u);
#endif
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event
    eCxx::Application::processEvent();
}
