EPD.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef _EPD_H_
  2. #define _EPD_H_
  3. #include <inttypes.h>
  4. #include "driver/gpio.h"
  5. #define SOFTWARE_SPI_ENABLE 0
  6. #define QUICK_DISPLAY 0 //快刷
  7. #define HARDWARE_SPI 1
  8. #if HARDWARE_SPI
  9. #include "driver/spi_master.h"
  10. #define SPI_MAX_LEN 3200
  11. #define EPD_HOST SPI2_HOST
  12. #define PIN_SPI_MOSI 45
  13. #define PIN_SPI_CLK 48
  14. #define PIN_L_CS 39
  15. #define PIN_L_DC 40
  16. #define PIN_L_RST 41
  17. #define PIN_L_BUSY 42
  18. #define PIN_R_CS 47
  19. #define PIN_R_DC 21
  20. #define PIN_R_RST 14
  21. #define PIN_R_BUSY 13
  22. #if !SOFTWARE_SPI_ENABLE //
  23. #define PIN_EPD_OUTPUT ((1ULL<<PIN_L_CS)|(1ULL<<PIN_L_DC)|(1ULL<<PIN_L_RST)|(1ULL<<PIN_R_CS)|(1ULL<<PIN_R_DC)|(1ULL<<PIN_R_RST))
  24. #else
  25. #define PIN_EPD_OUTPUT ((1ULL<<PIN_SPI_MOSI)|(1ULL<<PIN_SPI_CLK)|(1ULL<<PIN_L_CS)|(1ULL<<PIN_L_DC)|(1ULL<<PIN_L_RST)|(1ULL<<PIN_R_CS)|(1ULL<<PIN_R_DC)|(1ULL<<PIN_R_RST))
  26. #endif
  27. #define PIN_EPD_INPUT ((1ULL<<PIN_L_BUSY)|(1ULL<<PIN_R_BUSY))
  28. typedef enum {
  29. SCREEN_LEFT = 1,
  30. SCREEN_RIGHT = 2,
  31. }screen_t;
  32. typedef struct {
  33. uint8_t cmd;
  34. uint8_t data[16];
  35. uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
  36. } epd_init_cmd_t;
  37. extern spi_device_handle_t epd_spi;
  38. void epd_write_cmd(screen_t screen, unsigned char command,bool keep_cs_active);
  39. void epd_write_data(screen_t screen, const uint8_t *data, int len);
  40. void epd_init(void);
  41. void epd_display(screen_t screen,const unsigned char* picData);
  42. void epd_cache(screen_t screen,const unsigned char* picData);
  43. void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  44. screen_t screen,const unsigned char* picData);
  45. void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  46. screen_t screen,const unsigned char* picData);
  47. void epd_partial_cache1(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  48. screen_t screen,const unsigned char* picData);
  49. void epd_powerOn_refresh(screen_t screen);
  50. void epd_init_cmd(screen_t screen);
  51. void epd_sleep(screen_t screen);
  52. bool epd_check_status(screen_t screen);
  53. void epd_refresh(screen_t screen);
  54. void epd_check_power_off(screen_t screen);
  55. void epd_check_power_on(screen_t screen);
  56. void epd_cache_quick_full_screen_refresh(screen_t screen,const unsigned char* old,const unsigned char* new);
  57. void epd_cache_quick_partial_screen_refresh(screen_t screen,uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,const unsigned char* old,const unsigned char* new);
  58. unsigned int compressRLE(uint8_t *input, unsigned int size, uint8_t *output);
  59. // 解压函数
  60. unsigned int decompressRLE(uint8_t *input, unsigned int size, uint8_t *output);
  61. void deepsleep_epd_check_status(screen_t screen);
  62. void deepsleep_epd_powerOn_refresh_sleep(screen_t screen);
  63. bool epd_cache_quick(screen_t screen,const unsigned char* old,const unsigned char* new);
  64. void epd_powerOn_refresh_sleep(screen_t screen);
  65. #else /*HARDWARE_SPI*/
  66. #define LOW_LEVEL 0
  67. #define HIGH_LEVEL 1
  68. struct EPD_INFO_SET
  69. {
  70. char* epd_name;
  71. uint8_t sclk_pin;
  72. uint8_t sda_pin;
  73. uint8_t busy_pin;
  74. uint8_t res_pin;
  75. uint8_t dc_pin;
  76. uint8_t cs_pin;
  77. };
  78. #define epd_set_level(EPD_PIN, LEVEL) gpio_set_level(EPD_PIN, LEVEL)
  79. #define epd_get_level(EPD_PIN) gpio_get_level(EPD_PIN)
  80. void epd_screen_init(struct EPD_INFO_SET* epd_pin_set);
  81. void epd_pin_init(struct EPD_INFO_SET* epd_pin_set);
  82. void epd_spi_write(struct EPD_INFO_SET* epd_pin_set, unsigned char value);
  83. void epd_write_cmd(struct EPD_INFO_SET* epd_pin_set, unsigned char command);
  84. void epd_write_data(struct EPD_INFO_SET* epd_pin_set, unsigned char command);
  85. void epd_init(struct EPD_INFO_SET* epd_pin_set);
  86. void epd_check_status(struct EPD_INFO_SET* epd_pin_set);
  87. void epd_refresh(struct EPD_INFO_SET* epd_pin_set);
  88. void epd_sleep(struct EPD_INFO_SET* epd_pin_set);
  89. void epd_clear_black(struct EPD_INFO_SET* epd_pin_set);
  90. void epd_clear_write(struct EPD_INFO_SET* epd_pin_set);
  91. void epd_display(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
  92. void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
  93. void epd_cache(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
  94. void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
  95. void epd_powerOn_refresh(struct EPD_INFO_SET* epd_pin_set);
  96. #endif /*HARDWARE_SPI*/
  97. #endif/*_EPD_H_*/