You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 rivejä
2.8 KiB

  1. #include "spidriver/spi_master_lobo.h"
  2. #include "epaper/EPD.h"
  3. #include <stdlib.h>
  4. #include "esp_system.h"
  5. #include "driver/gpio.h"
  6. #include "esp_system.h"
  7. #include "esp_heap_alloc_caps.h"
  8. #include "esp_log.h"
  9. #include "config.h"
  10. #include "display.h"
  11. void display_init()
  12. {
  13. // drawing buffer
  14. disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
  15. assert(disp_buffer);
  16. drawBuff = disp_buffer;
  17. // gray-scale drawing buffer
  18. gs_disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA);
  19. assert(gs_disp_buffer);
  20. gs_drawBuff = gs_disp_buffer;
  21. }
  22. spi_lobo_device_interface_config_t devcfg;
  23. spi_lobo_bus_config_t buscfg;
  24. void spi_init()
  25. {
  26. gpio_set_direction(DC_Pin, GPIO_MODE_OUTPUT);
  27. gpio_set_level(DC_Pin, 1);
  28. gpio_set_direction(RST_Pin, GPIO_MODE_OUTPUT);
  29. gpio_set_level(RST_Pin, 0);
  30. gpio_set_direction(BUSY_Pin, GPIO_MODE_INPUT);
  31. gpio_set_pull_mode(BUSY_Pin, GPIO_PULLUP_ONLY);
  32. #ifdef POWER_Pin
  33. gpio_set_direction(POWER_Pin, GPIO_MODE_OUTPUT);
  34. gpio_set_level(POWER_Pin, 1);
  35. #endif
  36. buscfg.miso_io_num = -1; // set SPI MISO pin
  37. buscfg.mosi_io_num = MOSI_Pin; // set SPI MOSI pin
  38. buscfg.sclk_io_num = SCK_Pin; // set SPI CLK pin
  39. buscfg.quadwp_io_num=-1;
  40. buscfg.quadhd_io_num=-1;
  41. buscfg.max_transfer_sz = 5*1024; // max transfer size is 4736 bytes
  42. devcfg.clock_speed_hz=40000000; // SPI clock is 40 MHz
  43. devcfg.mode=0; // SPI mode 0
  44. devcfg.spics_io_num=-1; // we will use external CS pin
  45. devcfg.spics_ext_io_num = CS_Pin; // external CS pin
  46. devcfg.flags=SPI_DEVICE_HALFDUPLEX; // ALWAYS SET to HALF DUPLEX MODE for display spi !!
  47. }
  48. void display_connect()
  49. {
  50. int ret;
  51. ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &disp_spi);
  52. assert(ret==ESP_OK);
  53. printf("SPI: display device added to spi bus\r\n");
  54. ret = spi_lobo_device_select(disp_spi, 1);
  55. assert(ret==ESP_OK);
  56. ret = spi_lobo_device_deselect(disp_spi);
  57. assert(ret==ESP_OK);
  58. printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(disp_spi));
  59. printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(disp_spi) ? "true" : "false");
  60. }
  61. void display_splash_screen()
  62. {
  63. EPD_DisplayClearPart();
  64. EPD_fillScreen(0);
  65. EPD_UpdateScreen();
  66. EPD_setFont(COMIC24_FONT, NULL);
  67. EPD_print("LilyBook", 30, 30);
  68. EPD_setFont(DEFAULT_FONT, NULL);
  69. EPD_print("Version:", 30, 70);
  70. EPD_print(APP_VERSION, 100, 70);
  71. EPD_UpdateScreen();
  72. }
  73. void display_clear()
  74. {
  75. EPD_fillScreen(_bg);
  76. }
  77. void display_refresh()
  78. {
  79. EPD_DisplayClearPart();
  80. EPD_fillScreen(_bg);
  81. }
  82. void display_update()
  83. {
  84. EPD_UpdateScreen();
  85. }
  86. extern void EPD_wake();
  87. void display_wake()
  88. {
  89. EPD_wake();
  90. }
  91. void display_sleep()
  92. {
  93. EPD_PowerOff();
  94. }