EPD.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. {
  30. SCREEN_LEFT = 1,
  31. SCREEN_RIGHT = 2,
  32. } screen_t;
  33. typedef struct
  34. {
  35. uint8_t cmd;
  36. uint8_t data[16];
  37. uint8_t databytes; // No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
  38. } epd_init_cmd_t;
  39. extern spi_device_handle_t epd_spi;
  40. extern bool is_epd_ok_cplt;
  41. void epd_write_cmd(screen_t screen, unsigned char command, bool keep_cs_active);
  42. void epd_write_data(screen_t screen, const uint8_t *data, int len);
  43. void epd_init(void);
  44. void epd_display(screen_t screen, const unsigned char *picData);
  45. void epd_cache(screen_t screen, const unsigned char *picData);
  46. void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  47. screen_t screen, const unsigned char *picData);
  48. void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  49. screen_t screen, const unsigned char *picData);
  50. void epd_partial_cache1(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
  51. screen_t screen, const unsigned char *picData);
  52. void epd_powerOn_refresh(screen_t screen);
  53. void epd_init_cmd(screen_t screen);
  54. void epd_sleep(screen_t screen);
  55. bool epd_check_status(screen_t screen);
  56. void epd_refresh(screen_t screen);
  57. void epd_check_power_off(screen_t screen);
  58. void epd_check_power_on(screen_t screen);
  59. void epd_cache_quick_full_screen_refresh(screen_t screen, const unsigned char *old, const unsigned char *new);
  60. 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);
  61. unsigned int compressRLE(uint8_t *input, unsigned int size, uint8_t *output);
  62. // 解压函数
  63. unsigned int decompressRLE(uint8_t *input, unsigned int size, uint8_t *output);
  64. void deepsleep_epd_check_status(screen_t screen);
  65. void deepsleep_epd_powerOn_refresh_sleep(screen_t screen);
  66. bool epd_cache_quick(screen_t screen, const unsigned char *old, const unsigned char *new);
  67. void epd_powerOn_refresh_sleep(screen_t screen);
  68. // esp_err_t user_spi_get_result(spi_device_handle_t spi);
  69. #else /*HARDWARE_SPI*/
  70. #define LOW_LEVEL 0
  71. #define HIGH_LEVEL 1
  72. struct EPD_INFO_SET
  73. {
  74. char *epd_name;
  75. uint8_t sclk_pin;
  76. uint8_t sda_pin;
  77. uint8_t busy_pin;
  78. uint8_t res_pin;
  79. uint8_t dc_pin;
  80. uint8_t cs_pin;
  81. };
  82. #define epd_set_level(EPD_PIN, LEVEL) gpio_set_level(EPD_PIN, LEVEL)
  83. #define epd_get_level(EPD_PIN) gpio_get_level(EPD_PIN)
  84. void epd_screen_init(struct EPD_INFO_SET *epd_pin_set);
  85. void epd_pin_init(struct EPD_INFO_SET *epd_pin_set);
  86. void epd_spi_write(struct EPD_INFO_SET *epd_pin_set, unsigned char value);
  87. void epd_write_cmd(struct EPD_INFO_SET *epd_pin_set, unsigned char command);
  88. void epd_write_data(struct EPD_INFO_SET *epd_pin_set, unsigned char command);
  89. void epd_init(struct EPD_INFO_SET *epd_pin_set);
  90. void epd_check_status(struct EPD_INFO_SET *epd_pin_set);
  91. void epd_refresh(struct EPD_INFO_SET *epd_pin_set);
  92. void epd_sleep(struct EPD_INFO_SET *epd_pin_set);
  93. void epd_clear_black(struct EPD_INFO_SET *epd_pin_set);
  94. void epd_clear_write(struct EPD_INFO_SET *epd_pin_set);
  95. void epd_display(struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
  96. 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);
  97. void epd_cache(struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
  98. 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);
  99. void epd_powerOn_refresh(struct EPD_INFO_SET *epd_pin_set);
  100. #endif /*HARDWARE_SPI*/
  101. #endif /*_EPD_H_*/