/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2022/04/11
* IC:			SN8F5762
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2022/04/15	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/
#include <SN8F5762.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 GPIO_PORT_PULLDOWN        P0DR

#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;


/**
 *	@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 P0.0,P0.1 pull-up circuit
	    (3)	Enable P0.2,P0.3 pull-down circuit
			(4)	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);								                                /*	(2)	*/
//	GPIO_PORT_PULLDOWN |= (BIT_2|BIT_3);								                              /*	(3)	*/
//	bGPIO_ReadDataBuf = GPIO_PORT_DATA;			                                          /*	(4)	*/
	
	/*	GPIO output mode example	*/
	/*	(1)	Set port the whole pins to output mode, default output low
			(2)	Set Pn0~Pn3 to output low, Pn4~Pn7 output high	*/
	GPIO_PORT_DIRECTION |= (BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7);			  	/*	(1)	*/
	GPIO_PORT_DATA = (BIT_4|BIT_5|BIT_6|BIT_7);								        	            	/*	(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
}
