/*
 * 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_AVRX_PIN_NAME_STD_H
#error "this file cannot be included directly"
#endif
#undef INCLUDE_ECXX_PLATFORM_AVRX_PIN_NAME_STD_H


#ifndef ECXX_PLATFORM_AVR_PIN_MAPPING_STD_ABCDEF_H
#define ECXX_PLATFORM_AVR_PIN_MAPPING_STD_ABCDEF_H


//
// Available ports : A B C D E F (e.g. Arduino variant nona4809)
//

// Maximum digital pin number
static constexpr uint8_t DMax = 39;

// ADC pins
static constexpr uint8_t A0   = 14;
static constexpr uint8_t A1   = 15;
static constexpr uint8_t A2   = 16;
static constexpr uint8_t A3   = 17;
static constexpr uint8_t A4   = 18;                           /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t A5   = 19;                           /** PF 3 (D19) and PA 3 (D23) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t A6   = 20;
static constexpr uint8_t A7   = 21;
static constexpr uint8_t A8   =  3;
static constexpr uint8_t A9   =  6;
static constexpr uint8_t A10  = 26;                           /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t A11  = 27;                           /** Pin is not available for use in Arduino Nano Every board (it is also the VREFA pin) **/

static constexpr uint8_t AMin =  A8;
static constexpr uint8_t AMax = A11;

// PWM pins
static constexpr uint8_t PWM0 = 17;
static constexpr uint8_t PWM1 = 16;
static constexpr uint8_t PWM2 = 15;
static constexpr uint8_t PWM3 = 14;
static constexpr uint8_t PWM4 = 20;
static constexpr uint8_t PWM5 = 21;

// Interrupt pins
static constexpr uint8_t EINT0 = 22;                          /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t EINT1 =  5;
static constexpr uint8_t EINT2 =  4;
static constexpr uint8_t EINT3 = 15;
static constexpr uint8_t EINT4 = 13;
static constexpr uint8_t EINT5 = 18;                          /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t EINT6 = 30;                          /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t EINT7 = 35;                          /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t EINT8 = 26;                          /** Pin is not available for use in Arduino Nano Every board **/

// Communication pins
static constexpr uint8_t UART0_Rx = 24;                       /** Pin is not connected to any header pin in Arduino Nano Every board **/
static constexpr uint8_t UART0_Tx = 25;                       /** Pin is not connected to any header pin in Arduino Nano Every board **/

static constexpr uint8_t UART1_Rx =  0;
static constexpr uint8_t UART1_Tx =  1;

static constexpr uint8_t UART2_Rx =  7;
static constexpr uint8_t UART2_Tx =  2;

static constexpr uint8_t UART_Rx  = UART0_Rx;
static constexpr uint8_t UART_Tx  = UART0_Tx;

static constexpr uint8_t SPI_MISO = 12;
static constexpr uint8_t SPI_MOSI = 11;
static constexpr uint8_t SPI_SCK  = 13;
static constexpr uint8_t SPI_SS   =  8;

static constexpr uint8_t TWI_SDA  = 22;                       /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t TWI_SCL  = 23;                       /** PF 3 (D19) and PA 3 (D23) share the same header pin in Arduino Nano Every board **/

// Configurable custom logic pins
static constexpr uint8_t LUT0_In0    =  2;         /* PA 0 */
static constexpr uint8_t LUT0_In1    =  7;         /* PA 1 */
static constexpr uint8_t LUT0_In2    = 22;         /* PA 2 */ /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t LUT0_OutDef = 23;         /* PA 3 */ /** PF 3 (D19) and PA 3 (D23) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t LUT0_OUTAlt = 30;         /* PA 6 */ /** Pin is not available for use in Arduino Nano Every board **/

static constexpr uint8_t LUT1_In0    = 33;         /* PC 0 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT1_In1    = 34;         /* PC 1 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT1_In2    = 35;         /* PC 2 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT1_OutDef = 36;         /* PC 3 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT1_OutAlt =  4;         /* PC 6 */

static constexpr uint8_t LUT2_In0    = 17;         /* PD 0 */
static constexpr uint8_t LUT2_In1    = 16;         /* PD 1 */
static constexpr uint8_t LUT2_In2    = 15;         /* PD 2 */
static constexpr uint8_t LUT2_OutDef = 14;         /* PD 3 */
static constexpr uint8_t LUT2_OutAlt = 26;         /* PD 6 */ /** Pin is not available for use in Arduino Nano Every board **/

static constexpr uint8_t LUT3_In0    = 38;         /* PF 0 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT3_In1    = 39;         /* PF 1 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t LUT3_In2    = 18;         /* PF 2 */ /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t LUT3_OutDef = 19;         /* PF 3 */ /** PF 3 (D19) and PA 3 (D23) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t LUT3_OutAlt = InvalidPin; /* PF 6 */ /** Pin is not available for use (it is the reset pin) **/

// Analog comparator pins
static constexpr uint8_t AC0_InPos0 = 15;          /* PD 2 */
static constexpr uint8_t AC0_InPos1 = 20;          /* PD 4 */
static constexpr uint8_t AC0_InPos2 = 26;          /* PD 6 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t AC0_InPos3 = 16;          /* PD 1 */

static constexpr uint8_t AC0_InNeg0 = 14;          /* PD 3 */
static constexpr uint8_t AC0_InNeg1 = 21;          /* PD 5 */
static constexpr uint8_t AC0_InNeg2 = 27;          /* PD 7 */ /** Pin is not available for use in Arduino Nano Every board (it is also the VREFA pin) **/

static constexpr uint8_t AC0_Out    = 31;          /* PA 7 */ /** Pin is not available for use in Arduino Nano Every board **/

// Event system pins
static constexpr uint8_t EvOutA_Def = 22;          /* PA 2 */ /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t EvOutA_Alt = 31;          /* PA 7 */ /** Pin is not available for use in Arduino Nano Every board **/

static constexpr uint8_t EvOutB_Def =  5;          /* PB 2 */
static constexpr uint8_t EvOutB_Alt = InvalidPin;  /* PB 7 */ /** Pin is not available for use in any package **/

static constexpr uint8_t EvOutC_Def = 35;          /* PC 2 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t EvOutC_Alt = 37;          /* PC 7 */ /** Pin is not available for use in Arduino Nano Every board **/

static constexpr uint8_t EvOutD_Def = 15;          /* PD 2 */
static constexpr uint8_t EvOutD_Alt = 27;          /* PD 7 */ /** Pin is not available for use in Arduino Nano Every board (it is also the VREFA pin) **/

static constexpr uint8_t EvOutE_Def = 13;          /* PE 2 */
static constexpr uint8_t EvOutE_Alt = InvalidPin;  /* PE 7 */ /** Pin is not available for use in any package **/

static constexpr uint8_t EvOutF_Def = 18;          /* PF 2 */ /** PF 2 (D18) and PA 2 (D22) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t EvOutF_Alt = InvalidPin;  /* PF 7 */ /** Pin is not available for use in any package **/

// Additional timer/counter B pins
static constexpr uint8_t TCB1_OutDef = 23;         /* PA 3 */ /** PF 3 (D19) and PA 3 (D23) share the same header pin in Arduino Nano Every board **/
static constexpr uint8_t TCB1_OutAlt =  3;         /* PF 5 */

static constexpr uint8_t TCB2_OutDef = 33;         /* PC 0 */ /** Pin is not available for use in Arduino Nano Every board **/
static constexpr uint8_t TCB2_OutAlt = 25;         /* PB 4 */ /** Pin is not connected to any header pin in Arduino Nano Every board **/

static constexpr uint8_t TCB3_OutDef = 24;         /* PB 5 */ /** Pin is not connected to any header pin in Arduino Nano Every board **/
static constexpr uint8_t TCB3_OutAlt = 34;         /* PC 1 */ /** Pin is not available for use in Arduino Nano Every board **/


#endif
