/*
 * @brief Pin auto detection support
 *
 * @note
 * Copyright(C) NXP Semiconductors, 2014
 * All rights reserved.
 *
 * @par
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * LPC products.  This software is supplied "AS IS" without any warranties of
 * any kind, and NXP Semiconductors and its licensor disclaim any and
 * all warranties, express or implied, including all implied warranties of
 * merchantability, fitness for a particular purpose and non-infringement of
 * intellectual property rights.  NXP Semiconductors assumes no responsibility
 * or liability for the use of the software, conveys no license or rights under any
 * patent, copyright, mask work right, or any other intellectual property rights in
 * or to any products. NXP Semiconductors reserves the right to make changes
 * in the software without notification. NXP Semiconductors also makes no
 * representation or warranty that such application will be suitable for the
 * specified use without further testing or modification.
 *
 * @par
 * Permission to use, copy, modify, and distribute this software and its
 * documentation is hereby granted, under NXP Semiconductors' and its
 * licensor's relevant copyrights in the software, without fee, provided that it
 * is used in conjunction with NXP Semiconductors microcontrollers.  This
 * copyright, permission, and disclaimer notice must appear in all copies of
 * this code.
 */

#include "sl_common.h"

/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/

/* Number of pins the secondary loader can alter */
#define SLMAX_PINS_USED     19

///* IOCON saved pins */
//typedef struct {
//	uint32_t        savedIoconState;
//	SL_PORTPIN_T    portPin;
//} SAVEDIOCON_T;
//static SAVEDIOCON_T savedIoconStates[SLMAX_PINS_USED] = {
//	/* I2C pins */
//	{0x00000000, {0, 11}},		/* I2C0 SCL, P0_23 */
//	{0x00000000, {0, 10}},		/* I2C0 SDA, P0_24 */
//	{0x00000000, {0, 25}},		/* I2C1 SCL, P0_25 */
//	{0x00000000, {0, 26}},		/* I2C1 SDA, P0_26 */
//	{0x00000000, {0, 27}},		/* I2C2 SCL, P0_27 */
//	{0x00000000, {0, 28}},		/* I2C2 SDA, P0_28 */

//	/* SPI pins */
//	{0x00000000, {0, 11}},		/* SPI0_SCK, P0_11 */
//	{0x00000000, {1, 3}},		/* SPI0_SCK/SPI1_SSEL2, P1_3 */
//	{0x00000000, {1, 6}},		/* SPI1_SCK, P1_6 */
//	{0x00000000, {1, 12}},		/* SPI1_SCK, P1_12 */
//	{0x00000000, {0, 12}},		/* SPI0_MOSI */
//	{0x00000000, {1, 9}},		/* SPI0_MOSI */
//	{0x00000000, {1, 7}},		/* SPI1_MOSI */
//	{0x00000000, {1, 13}},		/* SPI1_MOSI */
//	{0x00000000, {0, 0}},		/* SPI0_SSEL0 */
//	{0x00000000, {0, 9}},		/* SPI0_SSEL0 */
//	{0x00000000, {0, 14}},		/* SPI0_SSEL0 */
//	{0x00000000, {1, 5}},		/* SPI1_SSEL0 */
//	{0x00000000, {1, 15}},		/* SPI1_SSEL0 */
//};

/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/


/*****************************************************************************
 * Private functions
 ****************************************************************************/


/*****************************************************************************
 * Public functions
 ****************************************************************************/

bool pinCheckValidHostif(SL_PINSETUP_T *pinCfg)
{
	int32_t ret = FALSE;
	uint8_t xorVal = 0;

	/* XOR pin information */
	xorVal = pinCfg->img_type ^ pinCfg->ifSel ^ pinCfg->hostIrqPortPin ^ pinCfg->hostMisoPortPin
			 ^ pinCfg->hostMosiPortPin ^ pinCfg->hostSselPortPin ^ pinCfg->hostSckPortPin;

	if (pinCfg->checksum != xorVal) {
		return ret;
	}

	if (pinCfg->ifSel <= SL_SPI1) {
		/* IRQ line is valid */
		switch (PINCFG_GET_PORT(pinCfg->hostIrqPortPin)) {
		case 0:
			ret = TRUE;
			break;

		case 1:
			if (PINCFG_GET_PIN(pinCfg->hostIrqPortPin) <= 17) {
				ret = TRUE;
			}
			break;

		default:
			break;
		}
		if ( ret == TRUE) {

		}
	}

	return ret;
}
