/*
 *
 * Copyright (C) 2012-2019, Samsung Electronics Co., Ltd.
 *
 * Cypress touchscreen. Driver header file
 */

#ifndef _CYPRESS_DRIVER_H_
#define _CYPRESS_DRIVER_H_

#include <stdint.h>
#include "tuiHal.h"
#include "touch_queue.h"

/*
 * The type of touch object for a given record.
 */
enum Touch_Type
{
    Standard_finger_and_glove = 0,
    Stylus = 2,
    Hover  = 3
};

/*
 * Indicates touch liftoff status.
 */
#define TIP_MASK   0x80
enum Tip {
    on_the_panel = 0,
    liftoff      = 0x80
};

/*
 * Indicates an event associated with this touch instance.
 */
#define EVENT_ID_MASK 0x60
enum Event_ID {
    No_event  = (0 << 5),
    Touchdown = (1 << 5),
    Significant_displacement = (2 << 5),
    Liftoff   = (3 << 5)
};

#define TOUCH_TIP_MASK  0x80
#define TOUCH_EVID_MASK 0x60
#define TOUCH_ID_MASK   0x1F

typedef struct Touch_Record {
    uint8_t  Touch_Type;
    uint8_t  ID; /* Tip Event_ID Touch_ID */
    uint16_t X;
    uint16_t Y;
    uint8_t  Pressure;
    uint16_t Major_Axis_Length;
    uint8_t  Orientation;
} __attribute__((packed)) Touch_Record_t;

#define LO_MASK        0x20  /* Large object indicator */
#define NUM_OF_RECS    0x1F
#define REPORT_COUNTER 0xC0
#define NOISE_EFFECTS  0x07

#define TOUCH_RECORD_NUM 32
typedef struct Touch_Report {
    uint16_t Length;      /* 7 + Number of Records * Record Length */
    uint8_t  Report_ID;   /* 01h */
    uint16_t Timestamp;   /* is unsigned in units of 0.1 milliseconds */
    uint8_t  data1;       /* Reserved:LO:Number_of_Records */
    uint8_t  data2;       /* Report_Counter:Reserved:Noise_Effects */
    Touch_Record_t TR[TOUCH_RECORD_NUM];
} __attribute__((packed)) Touch_Report_t;

typedef struct cypress_ts_info {
    unsigned int max_x;
    unsigned int max_y;
} cypress_ts_info_t;

int cts_irq_process(void);
int cts_driver_init(void);

#endif /* _CYPRESS_DRIVER_H_ */
