/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2021/12/29
* IC:			SN8F5754
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2021/12/29	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/
#define __XRAM_SFR_H__
#include <SN8F5754.h>

/*_____ F U N C T I O N S _______________________________*/
void GPIO_Initialization(void);

/*_____ D E F I N I T I O N S ___________________________*/
#define GPIO_PORT_DIRECTION			  P0M
#define GPIO_PORT_DATA						P0
#define GPIO_PORT_PULLUP					P0UR

#define BIT_0                     (0x01U<<0)
#define BIT_1                     (0x01U<<1)
#define BIT_2                     (0x01U<<2)
#define BIT_3                     (0x01U<<3)
#define BIT_4                     (0x01U<<4)
#define BIT_5                     (0x01U<<5)
#define BIT_6                     (0x01U<<6)
#define BIT_7                     (0x01U<<7)

/*_____ D E C L A R A T I O N S _________________________*/
uint8_t bGPIO_ReadDataBuf;

/*_____ M A C R O S _____________________________________*/
#define	IO_PORT0_OUTPUT_LOW		P0M |= 0xFF;	P0 &= 0x00;
#define	IO_PORT1_OUTPUT_LOW		P1M |= 0xFF;	P1 &= 0x00;
#define	IO_PORT2_OUTPUT_LOW		P2M |= 0xFF;	P2 &= 0x00;
#define	IO_PORT3_OUTPUT_LOW		P3M |= 0xFF;	P3 &= 0x00;

/**
 *	@Brief		main: GPIO Test Demo Function
 *	@param		None
 *	@retval		None
 */

void main(void)
{
	/*	Initialize GPIO status	*/
	GPIO_Initialization();															
	
	/*	GPIO input mode example	*/
	/*	(1)	Set port the whole pins to input mode
			(2)	Enable Pn0~Pn3 pull-up circuit
			(3)	Capture port IO status	on input mode, bit0-bit3 = "1"	*/
	GPIO_PORT_DIRECTION	&= ~(BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7);			  /*	(1)	*/
	GPIO_PORT_PULLUP |= (BIT_0|BIT_1|BIT_2|BIT_3);								                    /*	(2)	*/
	bGPIO_ReadDataBuf = GPIO_PORT_DATA;			                                          /*	(3)	*/
	
	/*	GPIO output mode example	*/
	/*	(1)	Set port the whole pins to output mode, default output low
			(2)	Set Pn0~Pn3 to output high, Pn4~Pn7 output low	*/
	GPIO_PORT_DIRECTION |= (BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7);			  	/*	(1)	*/
	GPIO_PORT_DATA = (BIT_0|BIT_1|BIT_2|BIT_3);								        	            	/*	(2)	*/

	while(1);
}


/**
 *	@Brief		Initialize GPIO status
 *	@param		None
 *	@retval		None
 */
void GPIO_Initialization(void)
{
	/*	Set whole IOs to output low	*/
	IO_PORT0_OUTPUT_LOW
	IO_PORT1_OUTPUT_LOW
	IO_PORT2_OUTPUT_LOW
	IO_PORT3_OUTPUT_LOW
}
