#include "key.h"
#include "nrf_delay.h"

void KEY_Init(void)
{
	//Configure GPIO pins as in Pullup input
	nrf_gpio_cfg_input(21,NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_input(22,NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_input(23,NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_input(30,NRF_GPIO_PIN_PULLUP);
}

void Delay(uint32_t temp)
{
	for(; temp!= 0; temp--) ;
}

uint8_t KEY_Down(uint8_t KEY_X)
{
	/*Check the Key  */
	if( nrf_gpio_pin_read(KEY_X)== 0 )
	{
		/*Delay for a while to prevent unexpected read*/
		// Delay(10000);
		nrf_delay_ms(20);
		if(nrf_gpio_pin_read(KEY_X)== 0 )
		{
			/*Wait for the Key released */
			while(nrf_gpio_pin_read(KEY_X)== 0 );
			return 0;
		}
		else
			return 1;
	}
	else
		return 1;
}
