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


#ifndef ECXX_PLATFORM_AVR_PIN_NAME_H
#define ECXX_PLATFORM_AVR_PIN_NAME_H


namespace eCxx {


//
// Define some predefined pin names for convenience
//
namespace AVR {


//
// For convenience
//
static constexpr uint8_t InvalidPin = Application_Base::InvalidPin;


//
// Builtin LED pin
//
static constexpr uint8_t BuiltinLED = 13;


//
// Measure temperature using ADC (only supported in some newer MCUs)
//     # Measured using the on-chip temperature sensor.
//     # The result is in (Kelvin * 100) and it may need further user calibration.
static constexpr uint8_t A_TempSenseK = 251;


//
// Measure the bandgap reference voltage using ADC
//     # Measured against the currently active ADCVRef.
//     # The result is in raw ADC value.
static constexpr uint8_t A_Bandgap = 252;


//
// Include the appropriate standard pin naming header file
//
#define INCLUDE_ECXX_PLATFORM_AVR_PIN_NAME_STD_H


#if defined(__AVR_ATmega8__  ) || defined(__AVR_ATmega8A__  ) ||                                                                                                \
    defined(__AVR_ATmega48__ ) || defined(__AVR_ATmega48A__ ) || defined(__AVR_ATmega48P__ ) || defined(__AVR_ATmega48PA__ ) || defined(__AVR_ATmega48PB__ ) || \
    defined(__AVR_ATmega88__ ) || defined(__AVR_ATmega88A__ ) || defined(__AVR_ATmega88P__ ) || defined(__AVR_ATmega88PA__ ) || defined(__AVR_ATmega88PB__ ) || \
    defined(__AVR_ATmega168__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega168PA__) || defined(__AVR_ATmega168PB__) || \
    defined(__AVR_ATmega328__) ||                                defined(__AVR_ATmega328P__)

    #include "PinName_Std_XBCD.h"


#elif  defined(__AVR_ATmega328PB__)

    #include "PinName_Std_XBCDE.h"


#elif defined(__AVR_ATmega16__  ) || defined(__AVR_ATmega16A__ ) ||                                                                 \
                                     defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__ ) || defined(__AVR_ATmega164PA__) || \
      defined(__AVR_ATmega32__  ) || defined(__AVR_ATmega32A__ ) ||                                                                 \
                                     defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324P__ ) || defined(__AVR_ATmega324PA__) || \
      defined(__AVR_ATmega644__ ) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__ ) || defined(__AVR_ATmega644PA__) || \
      defined(__AVR_ATmega1284__) ||                                defined(__AVR_ATmega1284P__)

    #include "PinName_Std_ABCD.h"


#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega64A__) || defined(__AVR_ATmega128__) ||  defined(__AVR_ATmega128A__)

    #include "PinName_Std_ABCDEFG.h"


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

    #include "PinName_Std_ABCDEFGHXJKL.h"


#elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)

    #include "PinName_Std_XBCDEF.h"


#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)

    #include "PinName_Std_ABCDEF.h"


#endif


#ifdef INCLUDE_ECXX_PLATFORM_AVR_PIN_NAME_STD_H
    #error "unsupported AVR MCU"
#endif


} // namespace AVR


} // namespace eCxx


#endif
