#ifndef _EPD_SPI_H_
#define _EPD_SPI_H_
#include "Arduino.h"

//IO settings
/*
ESP32-WROOM-32D (Using hardware SPI)
BUSY——23 ~~A14~~
RES——21 ~~A15~~
DC——22 ~~A16~~
CS——16 ~~A17~~
SCK—GPIO18
SDIN—GPIO23
*/

// hardware SPI (ESP32-C6 devkit-m1)
extern uint8_t SPI_SCK;
extern uint8_t SPI_MISO;
extern uint8_t SPI_MOSI;
extern uint8_t SPI_CS;
// 電子紙
extern uint8_t PIN_RES;
extern uint8_t PIN_DC;
extern uint8_t PIN_CS;
extern uint8_t PIN_BUSY;

void EPD_Pin_Init(uint8_t spi_sck=6, uint8_t spi_miso=2, uint8_t spi_mosi=7, uint8_t spi_cs=16,
    uint8_t epd_res=22, uint8_t epd_dc=23, uint8_t epd_cs=1, uint8_t epd_busy=0);

#define isEPD_W21_BUSY digitalRead(PIN_BUSY) //digitalRead(A14)  //BUSY
#define EPD_W21_RST_0 digitalWrite(PIN_RES, LOW) //digitalWrite(A15,LOW)  //RES
#define EPD_W21_RST_1 digitalWrite(PIN_RES, HIGH) //digitalWrite(A15,HIGH)
#define EPD_W21_DC_0  digitalWrite(PIN_DC,LOW) //digitalWrite(A16,LOW) //DC
#define EPD_W21_DC_1  digitalWrite(PIN_DC,HIGH) //digitalWrite(A16,HIGH)
#define EPD_W21_CS_0 digitalWrite(PIN_CS,LOW) //digitalWrite(A17,LOW) //CS
#define EPD_W21_CS_1 digitalWrite(PIN_CS,HIGH) //digitalWrite(A17,HIGH)


void SPI_Write(unsigned char value);
void EPD_W21_WriteDATA(unsigned char datas);
void EPD_W21_WriteCMD(unsigned char command);
unsigned char EPD_W21_ReadDATA(void);

#endif 
