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


#ifndef ECXX_PLATFORM_COMMON_UART_H
#define ECXX_PLATFORM_COMMON_UART_H


#ifdef ECXX_BUILDING_ECXX_LIBRARY
    #include <eCxx/CTL/HaveMemberCheck.h>
#endif

#include <eCxx/CTL/BasicOutputWriter.h>
#include <eCxx/CTL/RingBuffer.h>


//
// Include the platform-specific's implementation
//
#define INCLUDE_ECXX_PLATFORM_SPECIFIC_UART_H

// AVR
#if defined(__AVR_ARCH_X__)
    #include "../AVRX/UART.h"
#elif defined(__AVR_ARCH__)
    #include "../AVR/UART.h"
#endif

// AVR  - virtual UART
#ifdef ECXX_AVR_HAVE_HARDWARE_USB
    #define INCLUDE_ECXX_PLATFORM_SPECIFIC_VIRTUAL_UART_H
    #include "../AVR/VirtualUART.h"
#endif

// NodeMCU-ESP8266
#ifdef __XTENSA__
    #include "../NodeMCU/UART.h"
#endif

// Dummy (for testing the eCxx library in the host PC)
#ifdef INCLUDE_ECXX_PLATFORM_SPECIFIC_UART_H
    #include "../Dummy/UART.h"
#endif


//
// Check if the platform-specific's implementation provides the necessary member types/constants/variables/functions/etc.
//
#ifdef ECXX_BUILDING_ECXX_LIBRARY

namespace eCxx {

    namespace internal_uart_check {

        // Member types
        ECXX_CHECK_HAVE_MEMBER_TYPE(UART, DataFormat);

        // Member constants/variables/functions
        ECXX_CHECK_HAVE_MEMBER(UART, begin);
        ECXX_CHECK_HAVE_MEMBER(UART, end);

        ECXX_CHECK_HAVE_MEMBER(UART, changeBaudrate);

        ECXX_CHECK_HAVE_MEMBER(UART, canRead);
        ECXX_CHECK_HAVE_MEMBER(UART, read);
        ECXX_CHECK_HAVE_MEMBER(UART, peek);

        ECXX_CHECK_HAVE_MEMBER(UART, canWrite);
        ECXX_CHECK_HAVE_MEMBER(UART, write);
        ECXX_CHECK_HAVE_MEMBER(UART, flush);

    } // namespace internal

} // namespace eCxx

#endif


#endif
