/*******************************************************************************
*
*     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
*     SOLELY forUSE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
*     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
*     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
*     OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
*     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
*     AND YOU ARE RESPONSIBLE forOBTAINING ANY RIGHTS YOU MAY REQUIRE
*     forYOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
*     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
*     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
*     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
*     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*     forA PARTICULAR PURPOSE.
*     
*     (c) Copyright 2004 Xilinx, Inc.
*     All rights reserved.
*
******************************************************************************/

#include <stdio.h>
#include "xrom_led.h"
#include "xrom_input.h"
#include "xgpio_l.h"
#include "xparameters.h"
#include "sleep.h"

#define GPIO_0_BASEADDR XPAR_OPB_GPIO_0_BASEADDR

#define DIP1 0x00200000
#define DIP2 0x00100000
#define DIP3 0x00080000
#define DIP4 0x00040000
#define DIP5 0x00020000
#define DIP6 0x00010000
#define DIP7 0x00008000
#define DIP8 0x00004000

void XromDipsInit(){
	XGpio_mSetDataDirection(GPIO_0_BASEADDR, 1, 0x003FC000);
}

void XromTestDips(){

	unsigned long dataRead, oldDataRead;
	bool init=1;

	xil_printf("Press ESC to return to the main menu\r\n");
	oldDataRead = 0x0;

	while (1)
  	{
    	dataRead = XGpio_mGetDataReg(GPIO_0_BASEADDR, 1);
    	dataRead = dataRead & 0x003FC000;  // Clear out "unused" bits
    	
		if((dataRead != oldDataRead) || init) {
			xil_printf("\r\n 1  2  3  4  5  6  7  8\r\n");

			if((dataRead & DIP1)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP2)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP3)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP4)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP5)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP6)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP7)>0) xil_printf(" * ");
				else 	xil_printf("   ");
			if((dataRead & DIP8)>0) xil_printf(" *\r\n");
				else 	xil_printf("  \r\n");

			oldDataRead = dataRead;
			init = 0;
		}

		if (WaitForEscape()){
			XGpio_mSetDataReg(GPIO_0_BASEADDR, 1, 0x0);
			break;
		}
	}
	return;
}