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


#ifndef INCLUDE_ECXX_PLATFORM_SPECIFIC_CONFIG_H
#error "this file cannot be included directly"
#endif
#undef INCLUDE_ECXX_PLATFORM_SPECIFIC_CONFIG_H


#ifndef ECXX_PLATFORM_AVR_CONFIG_H
#define ECXX_PLATFORM_AVR_CONFIG_H


//
// Report a fatal error if the __AVR_ARCH_X__ macro is defined here
//
#ifdef __AVR_ARCH_X__
    #error "the selected MCU is not an AVRX and yet the __AVR_ARCH_X__ macro is defined"
#endif


//
// This MCU has more than one SPI and TWI interfaces
//
#ifdef __AVR_ATmega328PB__
    #define ECXX_AVR_HAVE_MULTIPLE_SPI_INTERFACES
    #define ECXX_AVR_HAVE_MULTIPLE_TWI_INTERFACES
#endif


//
// These MCUs have hardware USB device module
//
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__ ) || \
    defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)

    #define ECXX_AVR_HAVE_HARDWARE_USB

#endif


//
// Needed for RAMSTART and RAMEND
//
#include <avr/io.h>

// Workaround for missing RAMSTART macros in older versions of AVR GCC
#ifndef RAMSTART
    #if defined(__AVR_ATmega64__  ) || defined(__AVR_ATmega64A__  ) || \
        defined(__AVR_ATmega128__ ) || defined(__AVR_ATmega128A__ ) || \
        defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)

        #define RAMSTART 0x100

    #elif defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

        #define RAMSTART 0x200

    #endif
#endif

// Workaround for incorrect macro definitions in older versions of AVR GCC
#include "Undef.h"


//
// Include the common implementation file
//
#define INCLUDE_ECXX_PLATFORM_SPECIFIC_AVR_COMMON_CONFIG_H
#include "../AVRCommon/Config.h"


#endif
