/*
 * File:   MM7150_SensorModule.h
 * Author: Christian
 *
 * Created on 21 de marzo de 2018, 15:45
 */

#include "main.h"

#ifndef MM7150_SENSORMODULE_H
#define MM7150_SENSORMODULE_H
/* ================================= *\
** FUNCIONES DEFINIDAS POR CHRISTIAN **
*= Cada una de ellas ha sido creada  =*
*= a partir del la funcion           =*
*= mmain(void)del archivo mmain.c    =*
 * ================================= */

/*
 * Inicializar el modulo de sensores
 */
void Inic_SensorModule(void);  //Christian

/*
 * Cada uno de los sensores del modulo
 * requiere de activacion
 */
void Enable_INCLINOMETRO();  //Christian
void Enable_GIROSCOPIO();  //Christian
void Enable_RAWGYRO();  //Christian
void Enable_ACCELEROMETER();  //Christian

/*
 * Si un sensor esta activado, se le 
 * puede solicitar un dato actualizado
 * de uno o varios de los ejes
 */
double INCL_getData();  //Christian
double GYRO_getData();  //Christian
double RAWG_getData();  //Christian
//double ACC_getData();  //Christian
double ACC_getDataX();   //Christian
void ACC_readSensor(double* accData);  //Christian
void ACC_getData(double* accData);  //Christian

/*
 * Estas funciones simplemente muestran 
 * por pantalla (en tiempo real) la 
 * informacion del sensor en cuestion (todos los ejes)
 */
void INCL_FUNCTION(void);  //Christian
void GYRO_FUNCTION(void);  //Christian
void ORI_FUNCTION(void);  //Christian
void RAWG_FUNCTION(void);  //Christian
void ACC_FUNCTION(void);  //Christian
/*=  El resto  pertence a  microchip  =* 
 \* ================================= */


/* app.h */
#define TRUE 1
#define FALSE 0
#define DBNCE_VAL           300			// Debounce timer value (empirically derived)
#define MAX_SENSITIVITY     0

typedef unsigned char UINT8;        // 8-bit variables
typedef unsigned char BOOL;
   
typedef unsigned short UINT16;      // 16-bit variables
typedef unsigned long UINT32;

void delay(UINT16 usMs);
void delay2(UINT16 Ms4ths);
void delay3(UINT16 Ms4th);

#define MAX_DATA_RATE 10

/* vregs.h */
#define VREG_SHC        0x00    //Sensor Hub Configuration : VREG 0x00
#define VREG_SHC_WAKE_BIT           (1<<0)
#define VREG_SHC_SLP_BIT            (1<<1)
#define VREG_SHC_START_BIT          (1<<2)
#define VREG_SHC_ACC_EN             (1<<4)
#define VREG_SHC_RST_BIT            (1<<3)
#define VREG_SHC_GYRO_EN            (1<<5)
#define VREG_SHC_ORI_EN             (1<<7)
#define VREG_SHC_INC_EN             (1<<8)
#define VREG_SHC_RAWGYR_EN          (1<<13)

#define VREG_ORDR       0x0F                                        //Ori DataRate: VREG 0x0F
#define VREG_INDR       0x10                                        //Incl DataRate: VREG 0x10
#define VREG_GYDR       0x0D                                        //Gyro DataRate: VREG 0x0D
#define VREG_RGYDR      0x15                                        //Raw Gyro DataRate: VREG 0x15
#define VREG_ACDXR      0x0C                                        //Acc DataRate: VREG 0x0C

#define VREG_ORSEN      0x05                                        //Ori Sensitivity: VREG 0x05
#define VREG_GYSEN      0x03                                        //Gyro Sensitivity: VREG 0x03
#define VREG_INSEN      0x06                                        //Incl Sensitivity: VREG 0x06
#define VREG_RACSEN     0x09                                        //Raw Acc Sensitivity: VREG 0x09
#define VREG_RGYSEN     0x0B                                        //Raw Gyro Sensitivity: VREG 0x0B
#define VREG_ACSEN      0x02                                        //Acc Sensitivity: VREG 0x02

#define VREG_ORXD       0x29                                        //OriX Data: VREG 0x29
#define VREG_ORYD       0x2A                                        //OriY Data: VREG 0x2A
#define VREG_ORZD       0x2B                                        //OriZ Data: VREG 0x2B
#define VREG_ORWD       0x2C                                        //OriW Data: VREG 0x2C
#define VREG_GYXD       0x1C                                        //GyroX Data: VREG 0x1C
#define VREG_GYYD       0x1D                                        //GyroY Data: VREG 0x1D
#define VREG_GYZD       0x1E                                        //GyroZ Data: VREG 0x1E
#define VREG_INXD       0x2D                                        //InclX Data: VREG 0x2D
#define VREG_INYD       0x2E                                        //InclY Data: VREG 0x2E
#define VREG_INZD       0x2F                                        //InclZ Data: VREG 0x2F
#define VREG_RGYXD      0x1F                                        //Raw GyroX Data: VREG 0x1F
#define VREG_RGYYD      0x20                                        //Raw GyroY Data: VREG 0x20
#define VREG_RGYZD      0x21                                        //Raw GyroZ Data: VREG 0x21
#define VREG_ACXD       0x16                                        //AccX Data: VREG 0x16
#define VREG_ACYD       0x17                                        //AccY Data: VREG 0x17
#define VREG_ACZD       0x18                                        //AccZ Data: VREG 0x18

#define VREG_SHC_ACC_EN_VAL         4
#define VREG_SHC_RAWACC_EN_VAL      11
#define VREG_SHC_RAWMAG_EN_VAL      12
#define VREG_SHC_RAWGYR_EN_VAL      13
#define VREG_RST_CMD_SUCCESS            1
#define VREG_RESET_CMD_FAIL             3
#define VREG_SLEEP_SUCCESS              1
#define VREG_WAKE_SUCCESS               2
#define VREG_WAKE_FAIL                  6
#define VREG_SLEEP_FAIL                 5
#define VREG_ENABLE_SUCCESS             1
#define VREG_DISABLE_SUCCESS	        2
#define VREG_ENA_DIS_FAIL               3
#define VREG_UPDATE_SENS_FAIL           5
#define VREG_UPDATE_SENS_SUCCESS        1
#define VREG_UPDATE_DATARATE_SUCCESS    2
#define VREG_UPDATE_DATARATE_FAIL       6

#define VREG_SL         0x01                                        //Sensor List: VREG 0x01
#define VREG_EXPCSS3    0x3E                                        //ExponentCS3: VREG 0x3E
#define FULL_POWER                      0x02
#define LOW_POWER                       0x03
#define VREG_SHSTART_SUCCESS            1                           //status codes
#define VREG_SHSTART_FAIL               3
#define ARB_ID                          1                           // Arbitrary report ID to be used for POWER_ON and RESET commands (these commands do not require a specific ID)
#define MAX_RETRIES                     3                           // as per SF API spec
#define RPT_SIZE_LSB            0
#define STATUS1_MASK    0x03
#define STATUS2_MASK    0x07
#define VREG_STAT1      0x3F                                        //Status 1: VREG 0x3F
#define VREG_STAT4      0x42                                        //Status 4: VREG 0x42
#define VREG_STAT2      0x40                                        //Status 2 VREG 0x40
#define VREG_EXP1       0x39                                        //Exponent1: VREG 0x39
#define VREG_RESET_SUCCESS              0
#define VREG_RESET_INIT                 1

struct SENSOR_HUB_CONFIG                                       
{
    UINT16 SHwake:1;                                              // Set when device is awake
    UINT16 sleep:1;                                               // Set to enter sleep; clears shWAKE bit
    UINT16 SHstart:1;                                             // HID cannot be enabled unless set
    UINT16 reset:1;                                               // Set to start HID reset and set all VREGS to POR
    UINT16 AccelEnable:1;                                         // Set to enable accelerometer
    UINT16 GyroEnable:1;                                          // Set to enable gyrometer
    UINT16 CmpEnable:1;                                           // Set to enable compass
    UINT16 OriEnable:1;                                           // Set to enable orientation sensor
    UINT16 InclEnable:1;                                          // Set to enable inclinometer
    UINT16 BarEnable:1;                                           // Set to enable BAR sensor
    UINT16 AlsEnable:1;                                           // Set to enable ALS sensor
    UINT16 RawAccelEnable:1;                                      // Set to enable user to read raw accelerometer data
    UINT16 RawMagEnable:1;                                        // Set to enable user to read raw magnometer data
    UINT16 RawGyroEnable:1;                                       // Set to enagle user to read raw gryrometer data
    UINT16 res:2;
};
struct SENSOR_LIST
{
    UINT16 accel:1;                                               //sensor available bit
    UINT16 gyro:1;           
    UINT16 cmp:1;
    UINT16 ori:1;
    UINT16 incl:1;
    UINT16 res:11;
};
struct SENSIT_REGS
{
    UINT16 ACSEN;                                                   // Acc Sensitivity : VREG 0x02
    UINT16 GYSEN;                                                   // Gyro Sensitivity : VREG 0x03
    UINT16 CMSEN;                                                   // Cmp Sensitivity : VREG 0x04
    UINT16 ORSEN;                                                   // Ori Sensitivity : VREG 0x05
    UINT16 INSEN;                                                   // Incl Sensitivity : VREG 0x06
    UINT16 RES_VREG07;                                              // Reserved : VREG 0x07
    UINT16 RES_VREG08;                                              // Reserved : VREG 0x08
    UINT16 RACSEN;                                                  // Raw Acc Sensitivity : VREG 0x09
    UINT16 RMGSEN;                                                  // Raw MAg Sensitivity : VREG 0x0A
    UINT16 RGYSEN;                                                  // Raw Gyro Sensitivity : VREG 0x0B
};
struct DATA_RT_REGS
{
    UINT16 ACDXR;                                                   // Acc DataRate : VREG 0x0C
    UINT16 GYDR;                                                    // Gyro DataRate : VREG 0x0D
    UINT16 CMDR;                                                    // Cmp DataRate : VREG 0x0E
    UINT16 ORDR;                                                    // Ori DataRate : VREG 0x0F
    UINT16 INDR;                                                    // Incl DataRate : VREG 0x10
    UINT16 RES_VREG11;                                              // Reserved : VREG 0x11
    UINT16 RES_VREG12;                                              // Reserved : VREG 0x12
    UINT16 RACDR;                                                   // Raw Acc DataRate : VREG 0x13
    UINT16 RMGDR;                                                   // Raw Mag DataRate : VREG 0x14
    UINT16 RGYDR;                                                   // Raw Gyro DataRate : VREG 0x15
};
struct DATA_REGS
{
    UINT16 ACXD;                                                    // AccX Data : VREG 0x16
    UINT16 ACYD;                                                    // AccY Data : VREG 0x17
    UINT16 ACZD;                                                    // AccZ Data : VREG 0x18
    UINT16 RACXD;                                                   // Raw AccX Data : VREG 0x19
    UINT16 RACYD;                                                   // Raw AccY Data : VREG 0x1A
    UINT16 RACZD;                                                   // Raw AccZ Data : VREG 0x1B
    UINT16 GYXD;                                                    // GyroX Data : VREG 0x1C
    UINT16 GYYD;                                                    // GyroY Data : VREG 0x1D
    UINT16 GYZD;                                                    // GyroZ Data : VREG 0x1E
    UINT16 RGYXD;                                                   // Raw GyroX Data : VREG 0x1F
    UINT16 RGYYD;                                                   // Raw GyroY Data : VREG 0x20
    UINT16 RGYZD;                                                   // Raw GyroZ Data : VREG 0x21
    UINT16 CMD;                                                     // Cmp Data : VREG 0x22
    UINT16 MGFXD;                                                   // Mag FluxX Data: VREG 0x23
    UINT16 MGFYD;                                                   // Mag FluxY Data: VREG 0x24
    UINT16 MGFZD;                                                   // Mag FluxZ Data: VREG 0x25
    UINT16 RMGXD;                                                   // Raw MagX Data : VREG 0x26
    UINT16 RMGYD;                                                   // Raw MagY Data : VREG 0x27
    UINT16 RMGZD;                                                   // Raw MagZ Data : VREG 0x28
    UINT16 ORXD;                                                    // OriX Data : VREG 0x29
    UINT16 ORYD;                                                    // OriY Data : VREG 0x2A
    UINT16 ORZD;                                                    // OriZ Data : VREG 0x2B
    UINT16 ORWD;                                                    // OriW Data : VREG 0x2C
    UINT16 INXD;                                                    // InclX Data : VREG 0x2D
    UINT16 INYD;                                                    // InclY Data : VREG 0x2E
    UINT16 INZD;                                                    // InclZ Data : VREG 0x2F
    UINT16 RES_VREG30;                                              // Reserved : VREG 0x30
    UINT16 RES_VREG31;                                              // Reserved : VREG 0x31
    UINT16 RES_VREG32;                                              // Reserved : VREG 0x32
    UINT16 RES_VREG33;                                              // Reserved : VREG 0x33
    UINT16 RES_VREG34;                                              // Reserved : VREG 0x34
    UINT16 RES_VREG35;                                              // Reserved : VREG 0x35
};
struct IDS
{
    UINT16 PID;                                                     //ProductID : VREG 0x36   Note:  The product ID can be retrieved from the HID descriptor table
    UINT16 VID;                                                     //VendorID : VREG 0x37  Note: The vendor ID can be retrieved from the HID descriptor table
    UINT16 DID;                                                     //DeviceID : VREG 0x38 Note: The device ID can be retrieved from the HID descriptor table
};
struct EXPONENT1                    
{
    UINT16 expA:4;
    UINT16 expG:4;
    UINT16 expC:4;
    UINT16 expO:4;
};
struct EXPONENT2                     
{
    UINT16 expIN:4;
    UINT16 expB:4;
    UINT16 expAL:4;
    UINT16 expRA:4;
};
struct EXPONENT3                     
{
    UINT16 expRM:4;
    UINT16 expRG:4;
    UINT16 res:8;
};
struct EXPONENT
{
    struct EXPONENT1 exp1;
    struct EXPONENT2 exp2;
    struct EXPONENT3 exp3;
};
struct EXPONENTCS1                   
{
    UINT16 expCSA:4;
    UINT16 expCSG:4;
    UINT16 expCSC:4;
    UINT16 expCSO:4;
};
struct EXPONENTCS2
{
    UINT16 expSCIN:4;
    UINT16 expCSB:4;
    UINT16 expCSAL:4;
    UINT16 expCSRA:4;
};
struct EXPONENTCS3                   
{
    UINT16 expCSRM:4;
    UINT16 expCSRG:4;
    UINT16 res:8;
};
struct EXPONENTCS
{
    struct EXPONENTCS1 expCS1;
    struct EXPONENTCS2 expCS2;
    struct EXPONENTCS3 expCS3;
};
struct STATUS1                       
{
    UINT16 Accstatus:2;
    UINT16 GyroStatus:2;
    UINT16 CmpStatus:2;
    UINT16 OriStatus:2;
    UINT16 IncStatus:2;
    UINT16 ResStatus1:2;
    UINT16 ResStatus2:2;
    UINT16 RawAccStatus:2;
};
struct STATUS2                       
{
    UINT16 RawMagStatus:2;
    UINT16 RawGyroStatus:2;
    UINT16 AccCSData:3;
    UINT16 GyroCSData:3;
    UINT16 CmpCSData:3;
    UINT16 OriCSData:3;
};
struct STATUS3                       
{
    UINT16 InclCSData:3;
    UINT16 resCSData1:3;
    UINT16 resCSData2:3;
    UINT16 RawAccCSData:3;
    UINT16 RawMagCSData:3;
    UINT16 res:1;
};
struct STATUS4                       
{
    UINT16 RawGyroCSDAta:3;
    UINT16 SHStartStatus:2;
    UINT16 ResetStatus:2;
    UINT16 ShSleepWakeStatus:3;
    UINT16 res:6;
};
struct STATUS
{
    struct STATUS1 stat1;
    struct STATUS2 stat2;
    struct STATUS3 stat3;
    struct STATUS4 stat4;
};
typedef struct SF_VREGS                                             // The entire set of virtual registers
{
    struct SENSOR_HUB_CONFIG SHC;
    struct SENSOR_LIST SL;
    struct SENSIT_REGS sensitivity;
    struct DATA_RT_REGS data_rt;
    struct DATA_REGS data;
    struct IDS IDs;
    struct EXPONENT expo;
    struct EXPONENTCS expCS;
    struct STATUS stat;
} SF_VREGS;
typedef struct SENSOR                                               // parameters for individual sensors
{
   UINT8 id;
   UINT8 type;
   UINT8 DatRtOffset;
   UINT8 SensOffset;
   UINT8 SensExp;
   UINT8 DatOffset;
   UINT8 DatExp;
} SF_SENSOR, SF_TEMP;

typedef struct GET_SET_PARAMS
{
    UINT8 ucid;
    UINT8 ucPowerState;
    UINT16 usSensitivityVal;
    BOOL bSensitivityValid;
    UINT16 usDataRateVal;
    BOOL bDataRateValid;
} GET_SET_PARAMS;

/* i2cIO */
#define WRITE           1
#define READ            2
#define WR_RD           3
#define SLAVE_ADDR      0x40
#define I2C_POR_TIMEOUT 2000				//i.e. 2 seconds @ 1ms

/* sf.h */
#define VREG_MAX_OFFSET         0x3F                                // Maximum VREG offset#define ACCEL_VREG_OFFSET       0                                   // SENSOR TYPES (set in order that they are stored in VREGS struct)
#define ACCEL_VREG_OFFSET       0                                   // SENSOR TYPES (set in order that they are stored in VREGS struct)
#define GYRO_VREG_OFFSET        1
#define CMP_VREG_OFFSET         2
#define ORI_VREG_OFFSET         3
#define INCL_VREG_OFFSET        4
#define RAW_VREG_OFFSET         7           
#define RAW_ACC_VREG_OFFSET     7
#define RAW_MAG_VREG_OFFSET     8
#define RAW_GYR_VREG_OFFSET     9
#define BUF_40                  40   
#define BYTE_ADJ_VAL            3
#define NUM_SENS                12                                  // max number of sensors per API spec
#define BYTE_SHIFT              8
#define RESET_DEV_CMD           1
#define POWER_ON                2
#define SLEEP                   3
#define GET_HID_DESC            1
#define GET_RPT_DESC            2
#define RESET_DEV_CMD           1
#define POWER_ON                2
#define SLEEP                   3
#define HID_GET_RPT_INPT        4
#define HID_GET_RPT_FEAT        5
#define HID_SET_RPT_OUTP        6
#define HID_SET_RPT_FEAT        7
#define RPT_REPORT_STATE        4
#define HID_USAGE_SENSOR_PROPERTY_REPORTING_STATE_ALL_EVENTS_ENUM 0x02
#define HID_USAGE_SENSOR_TYPE                   0x09
#define HID_USAGE_SENSOR_PROPERTY               0x0A
#define HID_USAGE_SENSOR_PROPERTY_CONN_TYPE     0x09                //HID byte sequence : 0x0A,0x09,0x03
#define HID_USAGE_SENSOR_PROPERTY_RPT_STATE     0x16                //HID byte sequence : 0x0A,0x16,0x03
#define HID_USAGE_SENSOR_PROPERTY_PWR_STATE     0x19                //HID byte sequence : 0x0A,0x19,0x03
#define HID_USAGE_SENSOR_                       0x0A
#define HID_USAGE_SENSOR_STATE_1                0x01                //HID byte sequence : 0x0A,0x01,0x02
#define HID_USAGE_SENSOR_STATE_2                0x02                //HID byte sequence : 0x0A,0x01,0x02
#define HID_USAGE_SENSOR_EVENT_1                0x02                //HID byte sequence : 0x0A,0x02,0x02
#define HID_USAGE_SENSOR_EVENT_2                0x02                //HID byte sequence : 0x0A,0x02,0x02
#define HID_USAGE_SENSOR_PROPERTY_RPT_INT       0x0E                //HID byte sequence : 0x0A,0x0E,0x03

#define HID_USAGE_SENSOR_DATA_ACCU              0x44 
#define HID_USAGE_SENSOR_DATA_RAW_ACCU          0x45
#define HID_USAGE_SENSOR_DATA_RES               0x54
#define HID_USAGE_SENSOR_DATA_RAW_RES           0x55
#define HID_USAGE_SENSOR_DATA_MOD_SENS          0x14    
#define HID_USAGE_SENSOR_DATA_RAW_MOD_SENS      0x15
#define HID_USAGE_SENSOR_DATA_MOD_MAX           0x24
#define HID_USAGE_SENSOR_DATA_RAW_MOD_MAX       0x25
#define HID_USAGE_SENSOR_DATA_MOD_MIN           0x34
#define HID_USAGE_SENSOR_DATA_RAW_MOD_MIN       0x35
#define HID_UNIT_EXP                            0x55

#define RPT_PWR_STATE           5
#define RPT_REPORT_INTVAL_LSB   7
#define RPT_REPORT_INTVAL_MSB   8
#define RPT_CHG_SENS_LSB        13
#define RPT_CHG_SENS_MSB        14

#define HID_CNFG_LEN            BUF_30
#define HID_RPT_LEN             3500                                //size of HID Report Descriptor
#define RESET_CMD_MSB           0x01                                // RESET command bytes
#define RESET_CMD_LSB           0x00
#define TIMEOUT_5SEC            5000                                // RESET timeout 5 secs per HID spec
#define CMD_LEN                 0x04
#define POWER_CMD_MSB           0x08                                // POWER command bytes
#define POWER_CMD_LSB           0x00
#define SLEEP_ON_LSB            0x01                                // SLEEP command bytes
#define GET_RRT_INPT            0x10
#define GET_RPT_FEAT            0x30
#define GF_SENS_OFFSET_MSB      7
#define GF_SENS_OFFSET_LSB      6
#define GF_DATR_OFFSET_MSB      4
#define GF_DATR_OFFSET_LSB      3
#define SET_RPT_FEAT            0x30
#define BUF_150                 150                               
#define BUF_30                  30  
#define GET_RPT_CMD_MSB         0x02                                // GET REPORT commmand bytes
#define RPT_LEN                 6
#define SET_OPCODE              0x03
#define HID_DESC_CMD_LSB        01
#define HID_DESC_CMD_MSB        00
#define DESC_CMD_LEN            2
#define HID_COLLECTION          0xA1
#define HID_PHYSICAL            0x00
#define HID_REPORT_ID           0x85
#define HID_END_COLLECTION      0xC0
#define ACCEL_SENSOR_TYPE       0x73
#define GYRO_SENSOR_TYPE        0x76               
#define CMP_SENSOR_TYPE         0x83               
#define ORI_SENSOR_TYPE         0x8A               
#define INCL_SENSOR_TYPE        0x86               
#define RAW_SENSOR_TYPE         0xE1

typedef struct HID_DESCRIPTOR_TABLE                                 // Struct to store HID descriptor fields
{
    UINT16 wHIDDescLen;                                             // MSB 1; LSB 0
    UINT16 wRepDescLen;                                             // MSB 5; LSB 4
    UINT16 wRepDescReg;                                             // MSB 6; LSB 7
    UINT16 wMaxInpLen;                                              // MSB 11; LSB 10
    UINT16 wCmdReg;                                                 // MSB 17; LSB 16
    UINT16 wDatReg;                                                 // MSB 19; LSB 18
    UINT16 wVenID;                                                  // MSB 21; LSB 20
    UINT16 wProdID;                                                 // MSB 23; LSB 22
    UINT16 wVerID;                                                  // MSB 25; LSB 24
} HID_DESCRIPTOR_TABLE;


/* err.h */
//i2c definitions
#define I2_TIMEOUT_PERIOD       500                                       //500 ms
// Error code definitions 
#define VREG_OFFSET_ERR         (0x33)
#define SUCCESS                 0 
#define HID_INT_FAIL            (0x31)
#define VREG_ACCESS_ERR         (0x32)
#define RESET_FAIL              (0x16)
#define WAKE_CMD_FAIL           (0x1E)
#define SET_FEAT_FAIL           (0x19)
#define SLEEP_CMD_FAIL          (0x1B)
#define POWER_ON_FAIL           (0x17)
#define HID_GET_RPT_FEAT_FAIL   (0x1D)
#define HID_GET_RPT_INPT_FAIL   (0x1C)
#define SET_RPT_FAIL            (0x1A)
#define I2C_BUF_OVRFLO          (0x22)
#define I2C_ERROR               (0x21)
#define I2C_TIMEOUT_ERR         (0x29)
#define NOT_ACK                 (0x24)
#define I2C_SUCCESS             0
#define HID_DESC_FAIL           (0x11)
#define ID_FAIL                 (0x10)
#define RPT_DESC_FAIL           (0x12)
#define REP_PARS_FAIL           (0x14)
#define NO_EOC_FAIL             (0x15)

/* system.h*/
#define _SW_S3_UP       0                                           //UP button
#define _SW_S6_DWN      1                                           //DOWN button
#define _SW_S5_SLCT     2                                           //SELECT button
#define _SW_S4_RST      3                                           //RESET (return to main menu) button
#define DELAY100        100
#define DELAY250        250
#define SW_S5_LOW !PORTAbits.RA7
#define LED_D03         (1<<0)

/* pin_manager.h */
//
//#define LED_D3_SetHigh()          _LATA0 = 1
//#define LED_D3_SetLow()           _LATA0 = 0
//#define LED_D3_Toggle()           _LATA0 ^= 1
//#define LED_D3_GetValue()         _RA0
//#define LED_D3_SetDigitalInput()  _TRISA0 = 1
//#define LED_D3_SetDigitalOutput() _TRISA0 = 0
//#define LED_D4_SetHigh()          _LATA1 = 1
//#define LED_D4_SetLow()           _LATA1 = 0
//#define LED_D4_Toggle()           _LATA1 ^= 1
//#define LED_D4_GetValue()         _RA1
//#define LED_D4_SetDigitalInput()  _TRISA1 = 1
//#define LED_D4_SetDigitalOutput() _TRISA1 = 0
//#define LED_D5_SetHigh()          _LATA2 = 1
//#define LED_D5_SetLow()           _LATA2 = 0
//#define LED_D5_Toggle()           _LATA2 ^= 1
//#define LED_D5_GetValue()         _RA2
//#define LED_D5_SetDigitalInput()  _TRISA2 = 1
//#define LED_D5_SetDigitalOutput() _TRISA2 = 0
//#define LED_D6_SetHigh()          _LATA3 = 1
//#define LED_D6_SetLow()           _LATA3 = 0
//#define LED_D6_Toggle()           _LATA3 ^= 1
//#define LED_D6_GetValue()         _RA3
//#define LED_D6_SetDigitalInput()  _TRISA3 = 1
//#define LED_D6_SetDigitalOutput() _TRISA3 = 0
//#define LED_D7_SetHigh()          _LATA4 = 1
//#define LED_D7_SetLow()           _LATA4 = 0
//#define LED_D7_Toggle()           _LATA4 ^= 1
//#define LED_D7_GetValue()         _RA4
//#define LED_D7_SetDigitalInput()  _TRISA4 = 1
//#define LED_D7_SetDigitalOutput() _TRISA4 = 0
//#define LED_D8_SetHigh()          _LATA5 = 1
//#define LED_D8_SetLow()           _LATA5 = 0
//#define LED_D8_Toggle()           _LATA5 ^= 1
//#define LED_D8_GetValue()         _RA5
//#define LED_D8_SetDigitalInput()  _TRISA5 = 1
//#define LED_D8_SetDigitalOutput() _TRISA5 = 0
//#define LED_D9_SetHigh()          _LATA6 = 1
//#define LED_D9_SetLow()           _LATA6 = 0
//#define LED_D9_Toggle()           _LATA6 ^= 1
//#define LED_D9_GetValue()         _RA6
//#define LED_D9_SetDigitalInput()  _TRISA6 = 1
//#define LED_D9_SetDigitalOutput() _TRISA6 = 0
//#define SW_S5_SetHigh()          _LATA7 = 1
//#define SW_S5_SetLow()           _LATA7 = 0
//#define SW_S5_Toggle()           _LATA7 ^= 1
//#define SW_S5_GetValue()         _RA7
//#define SW_S5_SetDigitalInput()  _TRISA7 = 1
//#define SW_S5_SetDigitalOutput() _TRISA7 = 0
//#define SW_S4_SetHigh()          _LATD13 = 1
//#define SW_S4_SetLow()           _LATD13 = 0
//#define SW_S4_Toggle()           _LATD13 ^= 1
//#define SW_S4_GetValue()         _RD13
//#define SW_S4_SetDigitalInput()  _TRISD13 = 1
//#define SW_S4_SetDigitalOutput() _TRISD13 = 0
//#define SW_S3_SetHigh()          _LATD6 = 1
//#define SW_S3_SetLow()           _LATD6 = 0
//#define SW_S3_Toggle()           _LATD6 ^= 1
//#define SW_S3_GetValue()         _RD6
//#define SW_S3_SetDigitalInput()  _TRISD6 = 1
//#define SW_S3_SetDigitalOutput() _TRISD6 = 0
//#define SW_S6_SetHigh()          _LATD7 = 1
//#define SW_S6_SetLow()           _LATD7 = 0
//#define SW_S6_Toggle()           _LATD7 ^= 1
//#define SW_S6_GetValue()         _RD7
//#define SW_S6_SetDigitalInput()  _TRISD7 = 1
//#define SW_S6_SetDigitalOutput() _TRISD7 = 0
//#define I2C_ALERT_SetHigh()          _LATE8 = 1
//#define I2C_ALERT_SetLow()           _LATE8 = 0
//#define I2C_ALERT_Toggle()           _LATE8 ^= 1
//#define I2C_ALERT_GetValue()         _RE8
//#define I2C_ALERT_SetDigitalInput()  _TRISE8 = 1
//#define I2C_ALERT_SetDigitalOutput() _TRISE8 = 0
//#define WAKE_SetHigh()          _LATE9 = 1
//#define WAKE_SetLow()           _LATE9 = 0
//#define WAKE_Toggle()           _LATE9 ^= 1
//#define WAKE_GetValue()         _RE9
//#define WAKE_SetDigitalInput()  _TRISE9 = 1
//#define WAKE_SetDigitalOutput() _TRISE9 = 0
//#define WAKE_SetLow()           _LATE9 = 0
//#define WAKE_SetHigh()          _LATE9 = 1
//#define I2C_ALERT_GetValue()         _RE8

/* flashupdate.h */
#define FLASH_UPDATE_RPT_ID         0xE

/* i2c1.h */
//typedef enum
//{
//    I2C1_MESSAGE_FAIL,
//    I2C1_MESSAGE_PENDING,
//    I2C1_MESSAGE_COMPLETE,
//    I2C1_STUCK_START,
//    I2C1_MESSAGE_ADDRESS_NO_ACK,
//    I2C1_DATA_NO_ACK,
//    I2C1_LOST_STATE
//} I2C1_MESSAGE_STATUS;
//typedef struct
//{
//    uint16_t  address;          // Bits <10:1> are the 10 bit address.
//                                // Bits <7:1> are the 7 bit address
//                                // Bit 0 is R/W (1 for read)
//    #ifdef MM7150_APPS
//    uint16_t length;
//    #else
//    uint8_t   length;           // the # of bytes in the buffer
//    #endif
//    uint8_t   *pbuffer;         // a pointer to a buffer of length bytes
//} I2C1_TRANSACTION_REQUEST_BLOCK;

#endif /*MM7150_SENSORMODULE_H*/