/******************************************************************************

Software License Agreement

The software supplied herewith by Microchip Technology Incorporated
(the “Company”) for its PICmicro® Microcontroller is intended and
supplied to you, the Company’s customer, for use solely and
exclusively on Microchip PICmicro Microcontroller products. The
software is owned by the Company and/or its supplier, and is
protected under applicable copyright laws. All rights are reserved.
Any use in violation of the foregoing restrictions may subject the
user to criminal sanctions under applicable laws, as well as to
civil liability for the breach of the terms and conditions of this
license.

THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

*******************************************************************************/
#ifndef SYS_CLOCK
	#error "Define SYS_CLOCK (ex. -DSYS_CLOCK=80000000) on compiler command line"
#endif

#define CLOCK_FREQ 					SYS_CLOCK
#define GetSystemClock()            SYS_CLOCK
#define GetPeripheralClock()        SYS_CLOCK
#define GetInstructionClock()

/** LED **************************************/
#define LED1						BIT_0
#define LED2						BIT_1
#define LED3						BIT_3

#define mInitAllLEDs()      		(mPORTDSetPinsDigitalOut(LED1 | LED2 | LED3), \
                            		mPORTDClearBits(LED1 | LED2 | LED3))

#define mLED_1             		 	mPORTDReadBits(LED1)
#define mLED_2              		mPORTDReadBits(LED2)
#define mLED_3             			mPORTDReadBits(LED3)

#define mLED_1_On()         		(LATDSET = LED1)
#define mLED_2_On()         		(LATDSET = LED2)
#define mLED_3_On()         		(LATDSET = LED3)

#define mLED_1_Off()        		(LATDCLR = LED1)
#define mLED_2_Off()        		(LATDCLR = LED2)
#define mLED_3_Off()        		(LATDCLR = LED3)

#define mLED_1_Toggle()     		(LATDINV = LED1)
#define mLED_2_Toggle()     		(LATDINV = LED2)
#define mLED_3_Toggle()     		(LATDINV = LED3)

/** BUTTONS AND CHANGE NOTICE *********************/
#define SW1							BIT_6
#define SW2							BIT_7
#define SW3							BIT_13
#define PU15						CN15_PULLUP_ENABLE
#define PU16						CN16_PULLUP_ENABLE
#define PU19						CN19_PULLUP_ENABLE

#define mInitAllSwitches()  		mPORTDSetPinsDigitalIn(SW1 | SW2 | SW3),\
									ConfigCNPullups(PU15 | PU16 | PU19)
							
#define mGetSW1						mPORTDReadBits(SW1)
#define mGetSW2						mPORTDReadBits(SW2)
#define mGetSW3						mPORTDReadBits(SW3)

/** USER DEBUG MESSAGE *********************************/
#ifdef __DEBUG
	#include "db_utils.h"
    #define mInitMessage()          DBINIT()
    #define mSendMessage1()         DBPUTS("**** PIC32 USB Starter Kit CDC Serial Device Demo ****")
    #define mSendMessage2()         DBPUTS("This demo enumerates the PIC32 as a USB Serial Device.")
    #define mSendMessage3()         DBPUTS("On your PC, select appropriate COM port and open a terminal emulation program.")
    #define mSendMessage4()         DBPUTS("Press SW1 on Starter Board to send message to PC.")
#else // user may wish to assign their own debug io, such as UART, SPI, etc.
	#define mInitMessage()
    #define mSendMessage1()
    #define mSendMessage2()
    #define mSendMessage3()
    #define mSendMessage4()
#endif
