"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from workspace_tools.paths import *
from workspace_tools.data.support import *

TEST_CMSIS_LIB = join(TEST_DIR, "cmsis", "lib")
TEST_MBED_LIB = join(TEST_DIR, "mbed", "env")

PERIPHERALS = join(TEST_DIR, "peripherals")
BENCHMARKS_DIR = join(TEST_DIR, "benchmarks")

SD = join(TEST_DIR, "sd")
TMP102 = join(PERIPHERALS, 'TMP102')

"""
Wiring:
  * Ground:
    * LPC1*: p1
    * KL25Z: GND

  * Vout
    * LPC1*: p40
    * KL25Z: P3V3

  * TMP102 (I2C):
      * LPC1*: (SDA=p28 , SCL=p27)
      * KL25Z: (SDA=PTC9, SCL=PTC8)
      * MAXWSNENV: (SDA=TP6, SCL=TP5)

  * digital_loop (Digital(In|Out|InOut), InterruptIn):
      * Arduino headers: (D0 <-> D7)
      * LPC1549: (D2 <-> D7)
      * LPC1*: (p5   <-> p25 )
      * KL25Z: (PTA5<-> PTC6)
      * NUCLEO_F103RB: (PC_6 <-> PB_8)
      * MAXWSNENV: (TP3 <-> TP4)
      * MAX32600MBED: (P1_0 <-> P4_7)

  * port_loop (Port(In|Out|InOut)):
      * Arduino headers: (D0 <-> D7), (D1 <-> D6)
      * LPC1*: (p5   <-> p25), (p6   <-> p26)
      * KL25Z: (PTA5 <-> PTC6), (PTA4 <-> PTC5)
      * NUCLEO_F103RB: (PC_6 <-> PB_8), (PC_5 <-> PB_9)
      * MAXWSNENV: (TP1 <-> TP3), (TP2 <-> TP4)
      * MAX32600MBED: (P1_0 <-> P4_7), (P1_1 <-> P4_6)

  * analog_loop (AnalogIn, AnalogOut):
      * Arduino headers: (A0 <-> A5)
      * LPC1549: (A0 <-> D12)
      * LPC1*: (p17   <-> p18 )
      * KL25Z: (PTE30 <-> PTC2)

  * analog_pot (AnalogIn):
      * Arduino headers: (A0, A1)

  * SD (SPI):
      * LPC1*: (mosi=p11 , miso=p12 , sclk=p13 , cs=p14 )
      * KL25Z: (mosi=PTD2, miso=PTD3, sclk=PTD1, cs=PTD0)

  * MMA7660 (I2C):
      * LPC1*: (SDA=p28 , SCL=p27)

  * i2c_loop:
      * LPC1768: (p28 <-> p9), (p27 <-> p10)

  * i2c_eeprom:
      * LPC1*: (SDA=p28 , SCL=p27)
      * KL25Z: (SDA=PTE0, SCL=PTE1)

  * can_transceiver:
     * LPC1768: (RX=p9,   TX=p10)
     * LPC1549: (RX=D9,   TX=D8)
     * LPC4088: (RX=p9,   TX=p10)

"""
TESTS = [
    # Automated MBED tests
    {
        "id": "MBED_A1", "description": "Basic",
        "source_dir": join(TEST_DIR, "mbed", "basic"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
    },
    {
        "id": "MBED_A2", "description": "Semihost file system",
        "source_dir": join(TEST_DIR, "mbed", "file"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        "mcu": ["LPC1768", "LPC2368", "LPC11U24"]
    },
    {
        "id": "MBED_A3", "description": "C++ STL",
        "source_dir": join(TEST_DIR, "mbed", "stl"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": False,
    },
    {
        "id": "MBED_A4", "description": "I2C TMP102",
        "source_dir": join(TEST_DIR, "mbed", "i2c_TMP102"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, TMP102],
        "automated": True,
        "peripherals": ["TMP102"]
    },
    {
        "id": "MBED_A5", "description": "DigitalIn DigitalOut",
        "source_dir": join(TEST_DIR, "mbed", "digitalin_digitalout"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        "peripherals": ["digital_loop"]
    },
    {
        "id": "MBED_A6", "description": "DigitalInOut",
        "source_dir": join(TEST_DIR, "mbed", "digitalinout"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        "peripherals": ["digital_loop"]
    },
    {
        "id": "MBED_A7", "description": "InterruptIn",
        "source_dir": join(TEST_DIR, "mbed", "interruptin"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "duration": 15,
        "automated": True,
        "peripherals": ["digital_loop"]
    },
    {
        "id": "MBED_A8", "description": "Analog",
        "source_dir": join(TEST_DIR, "mbed", "analog"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        "peripherals": ["analog_loop"],
        "mcu": ["LPC1768", "LPC2368", "LPC2460", "KL25Z", "K64F", "K22F", "LPC4088", "LPC1549",
                "NUCLEO_F072RB", "NUCLEO_F091RC", "NUCLEO_F302R8", "NUCLEO_F303RE",
                "NUCLEO_F334R8", "NUCLEO_L053R8", "NUCLEO_L073RZ", "NUCLEO_L152RE",
                "NUCLEO_F411RE", "NUCLEO_F446RE", "DISCO_F407VG", "DISCO_F746NG", "ARCH_MAX", "MAX32600MBED"]
    },
    {
        "id": "MBED_A9", "description": "Serial Echo at 115200",
        "source_dir": join(TEST_DIR, "mbed", "echo"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        #"host_test": "echo"
    },
    {
        "id": "MBED_A10", "description": "PortOut PortIn",
        "source_dir": join(TEST_DIR, "mbed", "portout_portin"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "peripherals": ["port_loop"],
        "supported": DEFAULT_SUPPORT,
        "automated": True,
    },
    {
        "id": "MBED_A11", "description": "PortInOut",
        "source_dir": join(TEST_DIR, "mbed", "portinout"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "peripherals": ["port_loop"],
        "supported": DEFAULT_SUPPORT,
        "automated": True,
    },
    {
        "id": "MBED_A12", "description": "SD File System",
        "source_dir": join(TEST_DIR, "mbed", "sd"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, FS_LIBRARY],
        "automated": True,
        "duration": 15,
        "peripherals": ["SD"]
    },
    {
        "id": "MBED_A13", "description": "I2C MMA7660 accelerometer",
        "source_dir": join(TEST_DIR, "mbed", "i2c_MMA7660"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA7660')],
        "automated": True,
        "peripherals": ["MMA7660"]
    },
    {
        "id": "MBED_A14", "description": "I2C Master",
        "source_dir": join(TEST_DIR, "mbed", "i2c_master"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
    },
    {
        "id": "MBED_A15", "description": "I2C Slave",
        "source_dir": join(TEST_DIR, "mbed", "i2c_slave"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
    },
    {
        "id": "MBED_A16", "description": "SPI Master",
        "source_dir": join(TEST_DIR, "mbed", "spi_master"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
    },
    {
        "id": "MBED_A17", "description": "SPI Slave",
        "source_dir": join(TEST_DIR, "mbed", "spi_slave"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
    },
    {
        "id": "MBED_A18", "description": "Interrupt vector relocation",
        "source_dir": join(TEST_DIR, "mbed", "vtor_reloc"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
        "mcu": ["LPC1768"],
        "automated": True,
    },
    {
        "id": "MBED_A19", "description": "I2C EEPROM read/write test",
        "source_dir": join(TEST_DIR, "mbed", "i2c_eeprom"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "peripherals": ["24LC256"],
        "automated": True,
        "duration": 15,
    },
    {
        "id": "MBED_A20", "description": "I2C master/slave test",
        "source_dir": join(TEST_DIR, "mbed", "i2c_master_slave"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
        "mcu": ["LPC1768", "RZ_A1H"],
        "peripherals": ["i2c_loop"]
    },
    {
        "id": "MBED_A21", "description": "Call function before main (mbed_main)",
        "source_dir": join(TEST_DIR, "mbed", "call_before_main"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
    },
    {
        "id": "MBED_A22", "description": "SPIFI for LPC4088 (test 1)",
        "source_dir": join(TEST_DIR, "mbed", "spifi1"),
        "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
        "automated": True,
        "duration": 30,
        "mcu": ["LPC4088","LPC4088_DM"]