# -*- coding: utf-8 -*-
# Copyright (c) 2018 Richard Hull & Contributors
# See LICENSE.md for details.

"""
Alternative pin mappings for Orange PI Zero 2
(see http://linux-sunxi.org/images/e/e7/Orange_Pi_Zero2_H616_Schematic_v1.3.pdf)

Usage:

.. code:: python
   import orangepi.zero2
   from OPi import GPIO

   GPIO.setmode(orangepi.zero2.BOARD) or GPIO.setmode(orangepi.zero2.BCM)
"""

# pin number = (position of letter in alphabet - 1) * 32 + pin number
# So, PD14 will be (4 - 1) * 32 + 14 = 110

# Orange Pi Zero 2 physical board pin to GPIO pin
BOARD = {
    3:  229,    # PH5
    5:  228,    # PH4
    7:   73,    # PC9
    8:  226,    # PH2
    10: 227,    # PH3
    11:  70,    # PC9
    12:  75,    # PC11
    13:  69,    # PC5
    15:  72,    # PC8
    16:  79,    # PC15
    18:  78,    # PC14
    19: 231,    # PH7
    21: 232,    # PH8
    22:  71,    # PC7
    23: 230,    # PH6
    24: 233,    # PH9
    26:  74     # PC10
}

# Orange Pi Zero Plus BCM pin to actual GPIO pin
# TODO
BCM = {
    2:   12,    # PA12/TWI0_SDA/DI_RX/PA_EINT12
    3:   11,    # PA11/TWI0_SCK/DI_TX/PA_EINT11
    4:    6,    # PA6/SIM_PWREN/PWM1/PA_EINT6
    7:   10,    # PA10/SIM_DET/PA_EINT10
    8:   13,    # PA13/SPI1_CS/UART3_TX/PA_EINT13
    9:   16,    # PA16/SPI1_MISO/UART3_CTS/PA_EINT16
    10:  15,    # PA15/SPI1_MOSI/UART3_RTS/PA_EINT15
    11:  14,    # PA14/SPI1_CLK/UART3_RX/PA_EINT14
    14: 198,    # PG6/UART1_TX/PG_EINT6
    15: 199,    # PG7/UART1_RX/PG_EINT7
    17:   1,    # PA1/UART2_RX/JTAG_CK/PA_EINT1
    18:   7,    # PA7/SIM_CLK/PA_EINT7
    22:   3,    # PA3/UART2_CTS/JTAG_DI0/PA_EINT3
    23:  19,    # PA19/PCM0_CLK/TWI1_SDA/PA_EINT19
    24:  18,    # PA18/PCM0_SYNC/TWI1_SCK/PA_EINT18
    25:   2,    # PA2/UART2_RTS/JTAG_DO/PA_EINT2
    27:   0     # PA0/UART2_TX/JTAG_MS0/PA_EINT0
}
