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


#ifndef ECXX_PLATFORM_NODEMCU_PIN_NAME_STD_GENERIC_ESP01_H
#define ECXX_PLATFORM_NODEMCU_PIN_NAME_STD_GENERIC_ESP01_H


//
// ESP-01
//

/*
 * ESP-01 pin layout, numbering, and function based on:
 *     https://i.stack.imgur.com/KVtEM.jpg
 *     https://www.researchgate.net/profile/Jayant_Shekhar/publication/329482423/figure/fig3/AS:701199250644994@1544190337481/ESP-01-pin-configuration-The-RESET-and-VCC-pins-of-the-module-are-connected-to-the-33-V.ppm
 *
 * ESP-01 from top (component side)
 *    ┌────────────────────────────────┐
 *    │ │                    ┌───┬───┐ │   1 GND
 *    │ │                    │ 7 │ 8 │ │   2 GPIO1  (TX)
 *    │ └────┐               ├───┼───┤ │   3 GPIO2
 *    │ ┌────┘ │             │ 5 │ 6 │ │   4 CH_PD
 *    │ └────┐ │             ├───┼───┤ │   5 GPIO0
 *    │ ┌────┘ │             │ 3 │ 4 │ │   6 RESET#
 *    │ └────┐ │             ├───┼───┤ │   7 GPIO3  (RX)
 *    │ ┌────┘ │             │ 1 │ 2 │ │   8 VCC
 *    │ └──────┴─            └───┴───┘ │
 *    └────────────────────────────────┘
 */

// Built-in LED pins
static constexpr uint8_t BuiltinLED1 =  2;          // Not all ESP-01 have this LED ; active low
static constexpr uint8_t BuiltinLED2 = 16;          // Not available for use

static constexpr uint8_t BuiltinLED  = BuiltinLED1;

// Digital pins (based on the NodeMCU PCB's silkscreen)
static constexpr uint8_t D0   = 16;                 // Not available for use
static constexpr uint8_t D1   =  5;                 // Not available for use
static constexpr uint8_t D2   =  4;                 // Not available for use
static constexpr uint8_t D3   =  0;
static constexpr uint8_t D4   =  2;
static constexpr uint8_t D5   = 14;                 // Not available for use
static constexpr uint8_t D6   = 12;                 // Not available for use
static constexpr uint8_t D7   = 13;                 // Not available for use
static constexpr uint8_t D8   = 15;                 // Not available for use
static constexpr uint8_t D9   =  3;
static constexpr uint8_t D10  =  1;

// ADC pin
static constexpr uint8_t A0   = 17;                 // Not available for use

static constexpr uint8_t AMin = A0;
static constexpr uint8_t AMax = A0;

// PWM pins
static constexpr uint8_t PWM0  =  0;
static constexpr uint8_t PWM1  =  1;
static constexpr uint8_t PWM2  =  2;
static constexpr uint8_t PWM3  =  3;
static constexpr uint8_t PWM4  =  4;                // Not available for use
static constexpr uint8_t PWM5  =  5;                // Not available for use
static constexpr uint8_t PWM6  = 12;                // Not available for use
static constexpr uint8_t PWM7  = 13;                // Not available for use
static constexpr uint8_t PWM8  = 14;                // Not available for use
static constexpr uint8_t PWM9  = 15;                // Not available for use
static constexpr uint8_t PWM10 = 16;                // Not available for use

// Interrupt pins
static constexpr uint8_t EINT0 =  0;
static constexpr uint8_t EINT1 =  1;
static constexpr uint8_t EINT2 =  2;
static constexpr uint8_t EINT3 =  3;
static constexpr uint8_t EINT4 =  4;                // Not available for use
static constexpr uint8_t EINT5 =  5;                // Not available for use
static constexpr uint8_t EINT6 = 12;                // Not available for use
static constexpr uint8_t EINT7 = 13;                // Not available for use
static constexpr uint8_t EINT8 = 14;                // Not available for use
static constexpr uint8_t EINT9 = 15;                // Not available for use

// Communication pins
static constexpr uint8_t UART0_RxDef =  3;
static constexpr uint8_t UART0_TxDef =  1;

static constexpr uint8_t UART0_RxAlt = 13;          // Not available for use
static constexpr uint8_t UART0_TxAlt = 15;          // Not available for use

static constexpr uint8_t UART1_Tx    =  2;

static constexpr uint8_t UART_Rx     = UART0_RxDef;
static constexpr uint8_t UART_Tx     = UART0_TxDef;

static constexpr uint8_t SPI_MISO    = 12;          // Not available for use
static constexpr uint8_t SPI_MOSI    = 13;          // Not available for use
static constexpr uint8_t SPI_SCK     = 14;          // Not available for use
static constexpr uint8_t SPI_SS      = 15;          // Not available for use

static constexpr uint8_t TWI_SDA     =  4;          // Not available for use
static constexpr uint8_t TWI_SCL     =  5;          // Not available for use

static constexpr uint8_t I2S_DATA    =  3;
static constexpr uint8_t I2S_BCK     = 15;          // Not available for use
static constexpr uint8_t I2S_WS      =  2;


#endif
