#ifndef __EPD_7INCH3_H
#define __EPD_7INCH3_H

#include <stdint.h>
#include <stdio.h>
#include <string.h>

 /* Pin wiring definion
 *      3.3V --> VCC  
 *      GND  --> GND
 *      IO21 --> CS
 *      IO12 --> CLK
 *      IO11 --> MOSI
 *      IO3  --> DC
 *      IO46  --> RST
 *      IO9  --> BUSY
 * */
//IO settings
#define BUSY_Pin  9 
#define RES_Pin   46 
#define DC_Pin    3 

#define CS_Pin    21 
#define SCK_Pin   12 
#define SDI_Pin   11

#define EPD_W21_MOSI_0  digitalWrite(SDI_Pin,LOW)
#define EPD_W21_MOSI_1  digitalWrite(SDI_Pin,HIGH) 
#define EPD_W21_CLK_0 digitalWrite(SCK_Pin,LOW)
#define EPD_W21_CLK_1 digitalWrite(SCK_Pin,HIGH)
#define EPD_W21_CS_0 digitalWrite(CS_Pin,LOW)
#define EPD_W21_CS_1 digitalWrite(CS_Pin,HIGH)
#define EPD_W21_DC_0  digitalWrite(DC_Pin,LOW)
#define EPD_W21_DC_1  digitalWrite(DC_Pin,HIGH)
#define EPD_W21_RST_0 digitalWrite(RES_Pin,LOW)
#define EPD_W21_RST_1 digitalWrite(RES_Pin,HIGH)
#define isEPD_W21_BUSY digitalRead(BUSY_Pin)
#define EPD_7IN3F_WIDTH       800
#define EPD_7IN3F_HEIGHT      480

/**********************************
Color Index
**********************************/
//8bit
#define Black   0x00  
#define White   0x11  
#define Green   0x66  
#define Blue    0x55  
#define Red     0x33  
#define Yellow  0x22 
#define Clean   0x77

#define EPD_7IN3F_BLACK   0x0	//  000
#define EPD_7IN3F_WHITE   0x1	//	001
#define EPD_7IN3F_YELLOW  0x2	//	010
#define EPD_7IN3F_RED     0x3	//	011
#define EPD_7IN3F_BLUE    0x5	//	100
#define EPD_7IN3F_GREEN   0x6	//	101
#define EPD_7IN3F_CLEAN   0x7 //  111 

#define PSR         0x00
#define PWRR        0x01
#define POF         0x02
#define POFS        0x03
#define PON         0x04
#define BTST1       0x05
#define BTST2       0x06
#define DSLP        0x07
#define BTST3       0x08
#define DTM         0x10
#define DRF         0x12
#define PLL         0x30
#define CDI         0x50
#define TCON        0x60
#define TRES        0x61
#define REV         0x70
#define VDCS        0x82
#define T_VDCS      0x84
#define PWS         0xE3

////////FUNCTION//////
void driver_delay_us(unsigned int xus);
void driver_delay_xms(unsigned long xms);
void DELAY_S(unsigned int delaytime);     
void SPI_Delay(unsigned char xrate);
void SPI_Write(unsigned char value);
void E_Paper_Gpio_Init(void);
void Epaper_Write_Command(unsigned char command);
void Epaper_Write_Data(unsigned char command);
void Epaper_READBUSY(void);
//EPD
void EPD_Init(void); //Electronic paper initialization
void EPD_Clear(unsigned char color);
void EPD_DeepSleep(void);
//Display 
void EPD_7IN3F_Display(const unsigned char *Image);
void EPD_Display_6colors(void);

#endif
