您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

136 行
3.4 KiB

  1. #include <time.h>
  2. #include <errno.h>
  3. #include <sys/fcntl.h>
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #include "esp_system.h"
  11. #include "driver/gpio.h"
  12. #include "esp_system.h"
  13. #include "esp_heap_alloc_caps.h"
  14. #include "spiffs_vfs.h"
  15. #include "esp_log.h"
  16. #include "spi_master_lobo.h"
  17. #include "img_hacking.c"
  18. #include "EPD.h"
  19. #define APP_VERSION "0.1"
  20. static struct tm* tm_info;
  21. static char tmp_buff[128];
  22. static time_t time_now, time_last = 0;
  23. static const char *file_fonts[3] = {"/spiffs/fonts/DotMatrix_M.fon", "/spiffs/fonts/Ubuntu.fon", "/spiffs/fonts/Grotesk24x48.fon"};
  24. static const char tag[] = "[LilyBook]";
  25. esp_err_t ret;
  26. void display_init()
  27. {
  28. disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
  29. assert(disp_buffer);
  30. drawBuff = disp_buffer;
  31. gs_disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA);
  32. assert(gs_disp_buffer);
  33. gs_drawBuff = gs_disp_buffer;
  34. }
  35. spi_lobo_device_interface_config_t devcfg;
  36. spi_lobo_bus_config_t buscfg;
  37. void spi_init()
  38. {
  39. gpio_set_direction(DC_Pin, GPIO_MODE_OUTPUT);
  40. gpio_set_level(DC_Pin, 1);
  41. gpio_set_direction(RST_Pin, GPIO_MODE_OUTPUT);
  42. gpio_set_level(RST_Pin, 0);
  43. gpio_set_direction(BUSY_Pin, GPIO_MODE_INPUT);
  44. gpio_set_pull_mode(BUSY_Pin, GPIO_PULLUP_ONLY);
  45. #ifdef POWER_Pin
  46. gpio_set_direction(POWER_Pin, GPIO_MODE_OUTPUT);
  47. gpio_set_level(POWER_Pin, 1);
  48. #endif
  49. buscfg.miso_io_num = -1; // set SPI MISO pin
  50. buscfg.mosi_io_num = MOSI_Pin; // set SPI MOSI pin
  51. buscfg.sclk_io_num = SCK_Pin; // set SPI CLK pin
  52. buscfg.quadwp_io_num=-1;
  53. buscfg.quadhd_io_num=-1;
  54. buscfg.max_transfer_sz = 5*1024; // max transfer size is 4736 bytes
  55. devcfg.clock_speed_hz=40000000; // SPI clock is 40 MHz
  56. devcfg.mode=0; // SPI mode 0
  57. devcfg.spics_io_num=-1; // we will use external CS pin
  58. devcfg.spics_ext_io_num = CS_Pin; // external CS pin
  59. devcfg.flags=SPI_DEVICE_HALFDUPLEX; // ALWAYS SET to HALF DUPLEX MODE for display spi !!
  60. }
  61. void display_connect()
  62. {
  63. ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &disp_spi);
  64. assert(ret==ESP_OK);
  65. printf("SPI: display device added to spi bus\r\n");
  66. ret = spi_lobo_device_select(disp_spi, 1);
  67. assert(ret==ESP_OK);
  68. ret = spi_lobo_device_deselect(disp_spi);
  69. assert(ret==ESP_OK);
  70. printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(disp_spi));
  71. printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(disp_spi) ? "true" : "false");
  72. }
  73. void fs_init()
  74. {
  75. vfs_spiffs_register();
  76. if (spiffs_is_mounted) {
  77. ESP_LOGI(tag, "File system mounted.");
  78. }
  79. else {
  80. ESP_LOGE(tag, "Error mounting file system.");
  81. }
  82. }
  83. extern "C" void app_main()
  84. {
  85. display_init();
  86. spi_init();
  87. vTaskDelay(500 / portTICK_RATE_MS);
  88. printf("\n LilyBook v%s\n\n", APP_VERSION);
  89. display_connect();
  90. EPD_DisplayClearFull();
  91. fs_init();
  92. printf("==== START ====\r\n\n");
  93. _gs = 1;
  94. uint32_t tstart;
  95. int pass = 0;
  96. int f = DEFAULT_FONT;
  97. while (1) {
  98. EPD_DisplayClearPart();
  99. EPD_fillScreen(_bg);
  100. _fg = 15;
  101. _bg = 0;
  102. EPD_setFont(f++ % USER_FONT, NULL);
  103. EPD_print("Welcome to LilyBook", 10, 10);
  104. EPD_UpdateScreen();
  105. EPD_wait(5000);
  106. EPD_PowerOff();
  107. EPD_wait(8000);
  108. }
  109. }