epd.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "epd.h"
  2. static int cur_model_index = 1;
  3. typedef void (*eink_init)(UBYTE mode);
  4. typedef void (*eink_clear)(void);
  5. typedef void (*eink_sleep)(void);
  6. typedef void (*eink_display)(UBYTE *Image, UBYTE *Image2);
  7. typedef struct eink_reg
  8. {
  9. uint16_t tp;
  10. uint16_t colors;
  11. uint16_t w;
  12. uint16_t h;
  13. eink_init init;
  14. eink_clear clear;
  15. eink_sleep sleep;
  16. eink_display display;
  17. }eink_reg_t;
  18. static const eink_reg_t eink_regs[] = {
  19. {.tp=MODEL_1in02d, .colors=1, .init=EPD_1IN02_Init, .w = EPD_1IN02_WIDTH, .h = EPD_1IN02_HEIGHT, .clear = EPD_1IN02_Clear, .sleep =EPD_1IN02_Sleep, .display=EPD_1IN02_Display},
  20. {.tp=MODEL_1in54, .colors=1, .init=EPD_1IN54_Init, .w = EPD_1IN54_WIDTH, .h = EPD_1IN54_HEIGHT, .clear = EPD_1IN54_Clear, .sleep =EPD_1IN54_Sleep, .display=EPD_1IN54_Display},
  21. {.tp=MODEL_1in54b, .colors=1, .init=EPD_1IN54B_Init, .w = EPD_1IN54B_WIDTH, .h = EPD_1IN54B_HEIGHT, .clear = EPD_1IN54B_Clear, .sleep =EPD_1IN54B_Sleep, .display=EPD_1IN54B_Display},
  22. {.tp=MODEL_1in54b_V2, .colors=1, .init=EPD_1IN54B_V2_Init, .w = EPD_1IN54B_V2_WIDTH, .h = EPD_1IN54B_V2_HEIGHT, .clear = EPD_1IN54B_V2_Clear, .sleep =EPD_1IN54B_V2_Sleep, .display=EPD_1IN54B_V2_Display},
  23. {.tp=MODEL_1in54c, .colors=1, .init=EPD_1IN54C_Init, .w = EPD_1IN54C_WIDTH, .h = EPD_1IN54C_HEIGHT, .clear = EPD_1IN54C_Clear, .sleep =EPD_1IN54C_Sleep, .display=EPD_1IN54C_Display},
  24. // {.tp=MODEL_1in54f, .colors=1, .init=EPD_1IN54FF_Init, .w = EPD_1IN54F_WIDTH, .h = EPD_1IN54F_HEIGHT, .clear = EPD_1IN54FF_Clear, .sleep =EPD_1IN54FF_Sleep, .display=EPD_1IN54FF_Display},
  25. {.tp=MODEL_1in54_V2, .colors=1, .init=EPD_1IN54_V2_Init, .w = EPD_1IN54_V2_WIDTH, .h = EPD_1IN54_V2_HEIGHT, .clear = EPD_1IN54_V2_Clear, .sleep =EPD_1IN54_V2_Sleep, .display=EPD_1IN54_V2_Display},
  26. {.tp=MODEL_1in54_V3, .colors=1, .init=EPD_1IN54_V3_Init, .w = EPD_1IN54_V3_WIDTH, .h = EPD_1IN54_V3_HEIGHT, .clear = EPD_1IN54_V3_Clear, .sleep =EPD_1IN54_V3_Sleep, .display=EPD_1IN54_V3_Display},
  27. {.tp=MODEL_2in13, .colors=1, .init=EPD_2IN13_Init, .w = EPD_2IN13_WIDTH, .h = EPD_2IN13_HEIGHT, .clear = EPD_2IN13_Clear, .sleep =EPD_2IN13_Sleep, .display=EPD_2IN13_Display},
  28. {.tp=MODEL_2in13bc, .colors=1, .init=EPD_2IN13BC_Init, .w = EPD_2IN13BC_WIDTH, .h = EPD_2IN13BC_HEIGHT, .clear = EPD_2IN13BC_Clear, .sleep =EPD_2IN13BC_Sleep, .display=EPD_2IN13BC_Display},
  29. {.tp=MODEL_2in13b_V3, .colors=1, .init=EPD_2IN13B_V3_Init, .w = EPD_2IN13B_V3_WIDTH, .h = EPD_2IN13B_V3_HEIGHT, .clear = EPD_2IN13B_V3_Clear, .sleep =EPD_2IN13B_V3_Sleep, .display=EPD_2IN13B_V3_Display},
  30. {.tp=MODEL_2in13d, .colors=1, .init=EPD_2IN13D_Init, .w = EPD_2IN13D_WIDTH, .h = EPD_2IN13D_HEIGHT, .clear = EPD_2IN13D_Clear, .sleep =EPD_2IN13D_Sleep, .display=EPD_2IN13D_Display},
  31. {.tp=MODEL_2in13_V2, .colors=1, .init=EPD_2IN13_V2_Init, .w = EPD_2IN13_V2_WIDTH, .h = EPD_2IN13_V2_HEIGHT, .clear = EPD_2IN13_V2_Clear, .sleep =EPD_2IN13_V2_Sleep, .display=EPD_2IN13_V2_Display},
  32. {.tp=MODEL_2in66, .colors=1, .init=EPD_2IN66_Init, .w = EPD_2IN66_WIDTH, .h = EPD_2IN66_HEIGHT, .clear = EPD_2IN66_Clear, .sleep =EPD_2IN66_Sleep, .display=EPD_2IN66_Display},
  33. {.tp=MODEL_2in66b, .colors=1, .init=EPD_2IN66B_Init, .w = EPD_2IN66B_WIDTH, .h = EPD_2IN66B_HEIGHT, .clear = EPD_2IN66B_Clear, .sleep =EPD_2IN66B_Sleep, .display=EPD_2IN66B_Display},
  34. {.tp=MODEL_2in7, .colors=1, .init=EPD_2IN7_Init, .w = EPD_2IN7_WIDTH, .h = EPD_2IN7_HEIGHT, .clear = EPD_2IN7_Clear, .sleep =EPD_2IN7_Sleep, .display=EPD_2IN7_Display},
  35. {.tp=MODEL_2in7b, .colors=1, .init=EPD_2IN7B_Init, .w = EPD_2IN7B_WIDTH, .h = EPD_2IN7B_HEIGHT, .clear = EPD_2IN7B_Clear, .sleep =EPD_2IN7B_Sleep, .display=EPD_2IN7B_Display},
  36. {.tp=MODEL_2in9, .colors=1, .init=EPD_2IN9_Init, .w = EPD_2IN9_WIDTH, .h = EPD_2IN9_HEIGHT, .clear = EPD_2IN9_Clear, .sleep =EPD_2IN9_Sleep, .display=EPD_2IN9_Display},
  37. {.tp=MODEL_2in9bc, .colors=1, .init=EPD_2IN9BC_Init, .w = EPD_2IN9BC_WIDTH, .h = EPD_2IN9BC_HEIGHT, .clear = EPD_2IN9BC_Clear, .sleep =EPD_2IN9BC_Sleep, .display=EPD_2IN9BC_Display},
  38. {.tp=MODEL_2in9b_V3, .colors=1, .init=EPD_2IN9B_V3_Init, .w = EPD_2IN9B_V3_WIDTH, .h = EPD_2IN9B_V3_HEIGHT, .clear = EPD_2IN9B_V3_Clear, .sleep =EPD_2IN9B_V3_Sleep, .display=EPD_2IN9B_V3_Display},
  39. {.tp=MODEL_2in9d, .colors=1, .init=EPD_2IN9D_Init, .w = EPD_2IN9D_WIDTH, .h = EPD_2IN9D_HEIGHT, .clear = EPD_2IN9D_Clear, .sleep =EPD_2IN9D_Sleep, .display=EPD_2IN9D_Display},
  40. // {.tp=MODEL_2in9ff, .colors=1, .init=EPD_2IN9FF_Init, .w = EPD_2IN9FF_WIDTH, .h = EPD_2IN9FF_HEIGHT, .clear = EPD_2IN9FF_Clear, .sleep =EPD_2IN9FF_Sleep, .display=EPD_2IN9FF_Display},
  41. {.tp=MODEL_2in9_V2, .colors=1, .init=EPD_2IN9_V2_Init, .w = EPD_2IN9_V2_WIDTH, .h = EPD_2IN9_V2_HEIGHT, .clear = EPD_2IN9_V2_Clear, .sleep =EPD_2IN9_V2_Sleep, .display=EPD_2IN9_V2_Display},
  42. {.tp=MODEL_3in7, .colors=1, .init=EPD_3IN7_1Gray_Init, .w = EPD_3IN7_WIDTH, .h = EPD_3IN7_HEIGHT, .clear = EPD_3IN7_1Gray_Clear, .sleep =EPD_3IN7_Sleep, .display=EPD_3IN7_1Gray_Display},
  43. {.tp=MODEL_4in2, .colors=1, .init=EPD_4IN2_Init, .w = EPD_4IN2_WIDTH, .h = EPD_4IN2_HEIGHT, .clear = EPD_4IN2_Clear, .sleep =EPD_4IN2_Sleep, .display=EPD_4IN2_Display},
  44. {.tp=MODEL_4in2bc, .colors=2, .init=EPD_4IN2BC_Init, .w = EPD_4IN2BC_WIDTH, .h = EPD_4IN2BC_HEIGHT, .clear = EPD_4IN2BC_Clear, .sleep =EPD_4IN2BC_Sleep, .display=EPD_4IN2BC_Display},
  45. {.tp=MODEL_4in2b_V2, .colors=1, .init=EPD_4IN2B_V2_Init, .w = EPD_4IN2B_V2_WIDTH, .h = EPD_4IN2B_V2_HEIGHT, .clear = EPD_4IN2B_V2_Clear, .sleep =EPD_4IN2B_V2_Sleep, .display=EPD_4IN2B_V2_Display},
  46. {.tp=MODEL_5in65f, .colors=1, .init=EPD_5IN65F_Init, .w = EPD_5IN65F_WIDTH, .h = EPD_5IN65F_HEIGHT, .clear = EPD_5IN65F_Clear, .sleep =EPD_5IN65F_Sleep, .display=EPD_5IN65F_Display},
  47. {.tp=MODEL_5in83, .colors=1, .init=EPD_5IN83_Init, .w = EPD_5IN83_WIDTH, .h = EPD_5IN83_HEIGHT, .clear = EPD_5IN83_Clear, .sleep =EPD_5IN83_Sleep, .display=EPD_5IN83_Display},
  48. {.tp=MODEL_5in83bc, .colors=1, .init=EPD_5IN83BC_Init, .w = EPD_5IN83BC_WIDTH, .h = EPD_5IN83BC_HEIGHT, .clear = EPD_5IN83BC_Clear, .sleep =EPD_5IN83BC_Sleep, .display=EPD_5IN83BC_Display},
  49. {.tp=MODEL_5in83b_V2, .colors=1, .init=EPD_5IN83B_V2_Init, .w = EPD_5IN83B_V2_WIDTH, .h = EPD_5IN83B_V2_HEIGHT, .clear = EPD_5IN83B_V2_Clear, .sleep =EPD_5IN83B_V2_Sleep, .display=EPD_5IN83B_V2_Display},
  50. //{.tp=MODEL_5in83_V2, .colors=1, .init=EPD_5IN83_V2_Init, .w = EPD_5IN83_V2_WIDTH, .h = EPD_5IN83_V2_HEIGHT, .clear = EPD_5IN83_V2_Clear, .sleep =EPD_5IN83_V2_Sleep, .display=EPD_5IN83_V2_Display},
  51. {.tp=MODEL_7in5, .colors=1, .init=EPD_7IN5_Init, .w = EPD_7IN5_WIDTH, .h = EPD_7IN5_HEIGHT, .clear = EPD_7IN5_Clear, .sleep =EPD_7IN5_Sleep, .display=EPD_7IN5_Display},
  52. {.tp=MODEL_7in5bc, .colors=1, .init=EPD_7IN5BC_Init, .w = EPD_7IN5BC_WIDTH, .h = EPD_7IN5BC_HEIGHT, .clear = EPD_7IN5BC_Clear, .sleep =EPD_7IN5BC_Sleep, .display=EPD_7IN5BC_Display},
  53. {.tp=MODEL_7in5b_HD, .colors=2, .init=EPD_7IN5B_HD_Init, .w = EPD_7IN5B_HD_WIDTH, .h = EPD_7IN5B_HD_HEIGHT, .clear = EPD_7IN5B_HD_Clear, .sleep =EPD_7IN5B_HD_Sleep, .display=EPD_7IN5B_HD_Display},
  54. {.tp=MODEL_7in5b_V2, .colors=2, .init=EPD_7IN5B_V2_Init, .w = EPD_7IN5B_V2_WIDTH, .h = EPD_7IN5B_V2_HEIGHT, .clear = EPD_7IN5B_V2_Clear, .sleep =EPD_7IN5B_V2_Sleep, .display=EPD_7IN5B_V2_Display},
  55. {.tp=MODEL_7in5_HD, .colors=2, .init=EPD_7IN5_HD_Init, .w = EPD_7IN5_HD_WIDTH, .h = EPD_7IN5_HD_HEIGHT, .clear = EPD_7IN5_HD_Clear, .sleep =EPD_7IN5_HD_Sleep, .display=EPD_7IN5_HD_Display},
  56. //{.tp=MODEL_7in5_V2, .colors=1, .init=EPD_7IN5_V2_Init, .w = EPD_7IN5_V2_WIDTH, .h = EPD_7IN5_V2_HEIGHT, .clear = EPD_7IN5_V2_Clear, .sleep =EPD_7IN5_V2_Sleep, .display=EPD_7IN5_V2_Display},
  57. {.tp = 0xFF}
  58. };
  59. void EPD_Model(UBYTE model) {
  60. if (model >= MODEL_MAX)
  61. return;
  62. const eink_reg_t* reg = eink_regs;
  63. int index = 0;
  64. while (reg->tp != 0xFF) {
  65. if (reg->tp == model) {
  66. cur_model_index = index;
  67. break;
  68. }
  69. reg ++;
  70. index ++;
  71. }
  72. }
  73. int EPD_Init(UBYTE mode, size_t *w, size_t *h, size_t* colors) {
  74. eink_regs[cur_model_index].init(mode);
  75. *w = eink_regs[cur_model_index].w;
  76. *h = eink_regs[cur_model_index].h;
  77. *colors = eink_regs[cur_model_index].colors;
  78. return 0;
  79. }
  80. void EPD_Clear(void) {
  81. eink_regs[cur_model_index].clear();
  82. }
  83. void EPD_Display(UBYTE *Image, UBYTE *Image2) {
  84. if (Image2 == NULL)
  85. Image2 = Image;
  86. eink_regs[cur_model_index].display(Image, Image2);
  87. }
  88. void EPD_Sleep(void) {
  89. eink_regs[cur_model_index].sleep();
  90. }
  91. void EPD_Task(void *param){
  92. uint8_t event;
  93. while (1) {
  94. luat_rtos_queue_recv(econf.eink_queue_handle, &event, sizeof(uint8_t), LUAT_WAIT_FOREVER);
  95. if (event){
  96. if (event & EPD_CLEAR){
  97. EPD_Clear();
  98. }
  99. if (event & EPD_SHOW){
  100. if(event & EPD_CLEAR)
  101. EPD_Clear();
  102. if (econf.ctxs[1] == NULL)
  103. EPD_Display(econf.ctxs[0]->fb, NULL);
  104. else
  105. EPD_Display(econf.ctxs[0]->fb, econf.ctxs[1]->fb);
  106. }
  107. if (event & EPD_DRAW){//初始化时候已经创建缓冲区,zbuff好像意义不大了?
  108. }
  109. luat_cbcwait_noarg(econf.idp);
  110. }
  111. }
  112. }