// PIN.h
#ifndef	PIN_H
#define	PIN_H


//#include <P24HJ128GP204.H>	// fast device with DMA
#include <P24FJ64GA002.H>	// device for proteus simulation, no DMA
//#include <P24FJ128GA006.H>	// device for MPLAB simulation, no W0 bug

#include 	<stdio.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"


#include	"pps.h"

typedef struct{ 
	volatile unsigned int *PORT;
	int BITMASK;
}PIN;
/*
#ifdef( (&TRISA - &PORTA)!=(&TRISB - &PORTB) || (&LATA - &PORTA)!=(&LATB - &PORTB) || (&ODCA - &PORTA)!=(&ODCB - &PORTB) )
#error
#endif
*/
#define		OUTPUT					0
#define		INPUT					1
#define		LOW						0
#define		HIGH					1
#define		OPEN_DRAIN				0
#define		NORMAL_DRAIN			1
#define		NO_PULL_UP				0
#define		PULL_UP					1
#define		NOT_CONNECTED			(PIN){NULL, 0}

#define		PIN_DELAY				asm( "nop" )

#define		TRIS					PORT[&TRISB - &PORTB]
//#define	PORT					PORT[&PORTB - &PORTB]
#define		LAT						PORT[&LATB - &PORTB]
#define		ODC						PORT[&ODCB - &PORTB]

extern int GET_OUT_PIN_TABLE[ 16 * 4 ];
extern int PIN_PULL_UP_TABLE[ 16 * 2 ];

PIN *PINOpen( PIN *this, char io, char v );
void PINClose( PIN *this );
char PINRead( PIN *this );
void PINWrite( PIN *this, char x );
void PINConfigDrain( PIN *this, char x );
void PINConfigDir( PIN *this, char x );

//void PINSetInFunc( PIN *this, int fn );
void PINSetOutFunc( PIN *this, int fn );

void PINSetPullUp( PIN *this, char pu );

//void _CNISR()
#endif	//PIN_H
