#ifndef SYSTEM_H
#define SYSTEM_H

#ifdef __cplusplus
extern "C" {
#endif

#include "io430.h"
#include <stdint.h>

#define int8                                    int8_t
#define uint8                                   uint8_t
#define int16                                   int16_t
#define uint16                                  uint16_t
#define uint32                                  uint32_t

#define WORD                                    uint16_t
#define BYTE                                    uint8_t

#define PIN_CAL                                 (0x01)
#define CALIBRATION_LENGTH                      (256)
#define CALIBRATION_START_COUNT                 (10)

#define SEGMENT_START                           (0x01000)  //Segment = 0x01000~0x010FF
#define SEGMENT_SIZE                            8   
  
#define MAX_FINGER_NUM                          2
    
#define IX_THRESHOLD                            (242 + 5)
#define IY_THRESHOLD                            (566 + 5)

#define Z1_THRESHOLD                            0

#define IX_MAX                                  143
#define IY_MAX                                  213

#define ENABLE_HAPTICS                          0
#define ENABLE_HAPTICS_DRV2603                  1
#define ENABLE_HAPTICS_DRV2605                  0
  
#define ENABLE_FLICK_GESTURE                    1
#define DEBUG_GESTURE_ENGINE                    0 
  
#define ENABLE_DEBUG_UART_GUI                   0
#define ENABLE_DEBUG_UART_GUI_GESTURE           1
#define ENABLE_DEBUG_UART_GUI_FINGER_POS        1 
#define ENABLE_DEBUG_UART_GUI_RAW_DATA          1

#define ENABLE_DEBUG_UART                       1
#define ENABLE_DEBUG_UART_RAW_DATA              1 
#define ENABLE_DEBUG_UART_GESTURE_ID            1 
#define ENABLE_DEBUG_UART_GESTURE               1

#define X_ZOOM_STEP                             (5)
#define Y_ZOOM_STEP                             (5)
#define X_ROTATE_STEP                           (1)
#define Y_ROTATE_STEP                           (1)
  
#define SCROLL_X_DISTANCE_THRESHOLD             (60 * 4)
#define SCROLL_Y_DISTANCE_THRESHOLD             (60 * 4)
#define DEBOUNCE_SINGLETOUCH_PAN_COUNT          2
#define DEBOUNCE_ZOOM_TO_MULTITOUCH_PAN_COUNT   10

#define FLICK_X_DISTANCE_THRESHOLD              35
#define FLICK_Y_DISTANCE_THRESHOLD              50 

#define FLICK_X_ACCELERATION_THRESHOLD          40
#define FLICK_Y_ACCELERATION_THRESHOLD          45   
    
#define MT_SETTLING_COUNT                       7  
#define DEBOUNCE_MULTITOUCH_ZOOM_COUNT          3   
#define DEBOUNCE_MULTITOUCH_ROTATE_COUNT        3
#define DEBOUNCE_ROTATE_ZOOM_COUNT              50
#define DEBOUNCE_ZOOM_ROTATE_COUNT              20
  
#define DEBOUNCE_MULTITOUCH_PAN_TO_ZOOM_COUNT   10

void board_init(void);
uint8 flash_read_byte(uint8 index);
void flash_write_array(uint8 *value,uint8 size,uint8 index);

#ifdef __cplusplus
};
#endif

#endif