/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <assert.h>
#include "gpio_pins.h"
#include "board.h"
#include "gpio_imx.h"

gpio_config_t gpioLed = {
    "GPIO5",                      		/* name */
    &IOMUXC_LPSR_SW_MUX_CTL_PAD_GPIO1_IO01,  	/* muxReg */
    0,                                  	/* muxConfig */
    &IOMUXC_LPSR_SW_PAD_CTL_PAD_GPIO1_IO01,  	/* padReg */
    0,                                  	/* padConfig */
    GPIO1,                              	/* base */
    1                                   	/* pin */
};

gpio_config_t gpioKeyFunc1 = {
    "FUNC1",                                   	/* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA05,       	/* muxReg */
    5,                                         	/* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05,        	/* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_PS(2) |  	/* padConfig */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_PE_MASK |
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_HYS_MASK,
    GPIO2,                                     	/* base */
    5                                         	/* pin */
};

gpio_config_t gpioKeyFunc2 = {
    "FUNC2",                                  	/* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA02,        	/* muxReg */
    5,                                         	/* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02,        	/* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_PS(2) |  	/* padConfig */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_PE_MASK |
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_HYS_MASK,
    GPIO2,                                     	/* base */
    2                                         	/* pin */
};

/* The Embedian example using input and output as well as interrupt mode. The Embedian example uses GPIO6 and GPIO8 for button/keys, GPIO2 and GPIO4 for LEDs. On EVK-STD-CARRIER-S20 evaluation carrier, you can use header GPIO to connect the SMARC signals to a button or LED respectively. */

/* Switch 1 (GPIO6)
 * Golden Finger	BALL NAME       	GPIO            	ALT
 *    P114              EPDC_DATA05           	GPIO2_07              	5
 */
gpio_config_t gpioSwitch1 = {
    "GPIO6",                                   		/* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA05,			/* muxReg */
    5,                                              	/* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05,                	/* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_PS(2) |        	/* padConfig */
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_PE_MASK |
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA05_HYS_MASK,
    GPIO2,                                          	/* base */
    5                                              	/* pin */
};

gpio_init_config_t Switch1 = {
    .pin           = 5,	//pin number
    .direction     = gpioDigitalInput,
    .interruptMode = gpioNoIntmode
};

/* LED 1 (GPIO2)
 * Golden Finger        BALL NAME               GPIO                    ALT
 *    P110              EPDC_DATA02             GPIO2_02                5
 */

gpio_config_t gpioLed1 = {
    "GPIO2",                                   		/* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA02,               	/* muxReg */
    5,                                              	/* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02,                 /* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_PS(2) |        	/* padConfig */
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_PE_MASK |
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA02_HYS_MASK,
    GPIO2,                                          	/* base */
    2                                              	/* pin */
};

gpio_init_config_t Led1 = {
    .pin           = 2, 	//pin number
    .direction     = gpioDigitalOutput,
    .interruptMode = gpioNoIntmode
};

/* Switch 2 (GPIO8)
 * Golden Finger        BALL NAME               GPIO                    ALT
 *    P116              EPDC_DATA06             GPIO2_06                5
 */
gpio_config_t gpioSwitch2 = {
    "GPIO8",                                            /* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA06,                 /* muxReg */
    5,                                                  /* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA06,                 /* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA06_PS(2) |           /* padConfig */
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA06_PE_MASK |
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA06_HYS_MASK,
    GPIO2,                                              /* base */
    6                                                  /* pin */
};

gpio_init_config_t Switch2 = {
    .pin           = 6,        //pin number
    .direction     = gpioDigitalInput,
    .interruptMode = gpioNoIntmode
};

/* LED 2 (GPIO4)
 * Golden Finger        BALL NAME               GPIO                    ALT
 *    P112              EPDC_DATA04             GPIO2_04                5
 */

gpio_config_t gpioLed2 = {
    "GPIO4",                                            /* name */
    &IOMUXC_SW_MUX_CTL_PAD_EPDC_DATA04,                 /* muxReg */
    5,                                                  /* muxConfig */
    &IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA04,                 /* padReg */
    IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA04_PS(2) |           /* padConfig */
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA04_PE_MASK |
        IOMUXC_SW_PAD_CTL_PAD_EPDC_DATA04_HYS_MASK,
    GPIO2,                                              /* base */
    4                                                  /* pin */
};

gpio_init_config_t Led2 = {
    .pin           = 4,        //pin number
    .direction     = gpioDigitalOutput,
    .interruptMode = gpioNoIntmode
};

void configure_gpio_pin(gpio_config_t *config)
{
    assert(config);

    *(config->muxReg) = config->muxConfig;
    *(config->padReg) = config->padConfig;
}

/*******************************************************************************
 * EOF
 ******************************************************************************/
