/*
 * 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_SPI_H
#define ECXX_PLATFORM_COMMON_SPI_H


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

#include <eCxx/CTL/BasicOutputWriter.h>

#include <eCxx/Platform/Common/SPIConstant.h>


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

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

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

// Dummy (for testing the eCxx library in the host PC)
#ifdef INCLUDE_ECXX_PLATFORM_SPECIFIC_SPI_H
    #include "../Dummy/SPI.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_spi_check {

        // Member types
        ECXX_CHECK_HAVE_MEMBER_TYPE(SPI, SPIMode);
        ECXX_CHECK_HAVE_MEMBER_TYPE(SPI, DataMode);

        // Member constants/variables/functions
        ECXX_CHECK_HAVE_MEMBER(SPI, DefaultSPIFrequency);

        ECXX_CHECK_HAVE_MEMBER(SPI, begin);
        ECXX_CHECK_HAVE_MEMBER(SPI, end);

        ECXX_CHECK_HAVE_MEMBER(SPI, beginTransaction);
        ECXX_CHECK_HAVE_MEMBER(SPI, endTransaction);

        ECXX_CHECK_HAVE_MEMBER(SPI, transfer);
        ECXX_CHECK_HAVE_MEMBER(SPI, write);

        ECXX_CHECK_HAVE_MEMBER(SPI, ntmBegin);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmSelectSlave);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmDeselectSlave);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmRead);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmReadX00);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmReadXFF);
        ECXX_CHECK_HAVE_MEMBER(SPI, ntmWrite);

    } // namespace internal

} // namespace eCxx

#endif


#endif
