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

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 GetSystemClock()            SYS_CLOCK
#define GetPeripheralClock()        SYS_CLOCK
#define GetInstructionClock()

/** LED **************************************/
#define LED_BLINK_INTERVAL          25
#define LED1                        BIT_0
#define LED2                        BIT_1
#define LED3                        BIT_2

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

#define mLED_1                      PORTDbits.RD0
#define mLED_2                      PORTDbits.RD1
#define mLED_3                      PORTDbits.RD2

#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 BUTTON_DEBOUNCE_LIMIT       5
#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 CONFIG                      (CN_ON | CN_IDLE_CON)
#define PINS                        (CN19_ENABLE)
#define INTERRUPT                   (CHANGE_INT_OFF | CHANGE_INT_PRI_3)
#define PULLUPS                     (PU19 | PU16 | PU15)

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

#define mToggleONOff()              mLED_1_Toggle()
#define mTurnOFF()                  mLED_1_Off()
#define mTurnON()                   mLED_1_On()
#define mSuspended()                mLED_3_On()
#define mNotSuspended()             mLED_3_Off()
#define mWakeEnabled()              mLED_2_On()
#define mWakeDisabled()             mLED_2_Off()
#define mLinkActive()               mLED_1 _Toggle()

/** USER DEBUG MESSAGE *********************************/
#ifdef __DEBUG
    #include "db_utils.h"
    #define mInitMessage()          DBINIT()
    #define mSendMessage1()         DBPUTS("**** PIC32 USB Starter Board Generic Device Demo ****")
    #define mSendMessage2()         DBPUTS("SW1: Up=Increase/Dn=Decrease SW2=POT Value, SW2=Temperature")
#else
    #define mInitMessage()
    #define mSendMessage1()
    #define mSendMessage2()
#endif

#define     mSendMessage3()
#define STARTUP_EMULATION_STATE     TRUE

