esp-epaper-29-ws.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* 2.9" Waveshare ePaper Driver Example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include <string.h>
  10. #include "esp_log.h"
  11. #include "imagedata.h"
  12. #include "epaper-29-ws.h"
  13. #include "epaper_fonts.h"
  14. static const char *TAG = "ePaper Example";
  15. // Pin definition of the ePaper module
  16. #define MOSI_PIN 5
  17. #define MISO_PIN -1
  18. #define SCK_PIN 18
  19. #define BUSY_PIN 22
  20. #define DC_PIN 21
  21. #define RST_PIN 23
  22. #define CS_PIN 19
  23. // Color inverse. 1 or 0 = set or reset a bit if set a colored pixel
  24. #define IF_INVERT_COLOR 1
  25. void e_paper_task(void *pvParameter)
  26. {
  27. epaper_handle_t device = NULL;
  28. epaper_conf_t epaper_conf = {
  29. .busy_pin = BUSY_PIN,
  30. .cs_pin = CS_PIN,
  31. .dc_pin = DC_PIN,
  32. .miso_pin = MISO_PIN,
  33. .mosi_pin = MOSI_PIN,
  34. .reset_pin = RST_PIN,
  35. .sck_pin = SCK_PIN,
  36. .rst_active_level = 0,
  37. .busy_active_level = 1,
  38. .dc_lev_data = 1,
  39. .dc_lev_cmd = 0,
  40. .clk_freq_hz = 20 * 1000 * 1000,
  41. .spi_host = HSPI_HOST,
  42. .width = EPD_WIDTH,
  43. .height = EPD_HEIGHT,
  44. .color_inv = 1,
  45. };
  46. uint32_t cnt = 0;
  47. char hum_str[7];
  48. char tsens_str[7];
  49. while(1){
  50. ESP_LOGI(TAG, "Before ePaper driver init, heap: %d", esp_get_free_heap_size());
  51. device = iot_epaper_create(NULL, &epaper_conf);
  52. iot_epaper_set_rotate(device, E_PAPER_ROTATE_270);
  53. ESP_LOGI(TAG, "e-Paper Display Espressif logo");
  54. iot_epaper_display_frame(device, IMAGE_DATA); // display IMAGE_DATA
  55. vTaskDelay(5000 / portTICK_PERIOD_MS);
  56. ESP_LOGI(TAG, "e-Paper Display sample graphics");
  57. iot_epaper_clean_paint(device, UNCOLORED);
  58. iot_epaper_draw_string(device, 200, 0, "@espressif", &epaper_font_12, COLORED);
  59. iot_epaper_draw_string(device, 10, 10, "e-Paper Demo ", &epaper_font_16, COLORED);
  60. iot_epaper_draw_string(device, 15, 50, "Humidity", &epaper_font_16, COLORED);
  61. iot_epaper_draw_string(device, 15, 80, "Temperature", &epaper_font_16, COLORED);
  62. memset(hum_str, 0x00, sizeof(hum_str));
  63. memset(tsens_str, 0x00, sizeof(tsens_str));
  64. sprintf(hum_str, "%4d %%", (uint8_t) (esp_random() * 100.0 / UINT32_MAX));
  65. sprintf(tsens_str, "%4d C", (int8_t) (esp_random() * 100.0 / UINT32_MAX - 50));
  66. iot_epaper_draw_string(device, 170, 50, hum_str, &epaper_font_16, COLORED);
  67. iot_epaper_draw_string(device, 170, 80, tsens_str, &epaper_font_16, COLORED);
  68. iot_epaper_draw_horizontal_line(device, 10, 27, 140, COLORED);
  69. iot_epaper_draw_horizontal_line(device, 10, 73, 240, COLORED);
  70. iot_epaper_draw_vertical_line(device, 150, 43, 60, COLORED);
  71. iot_epaper_draw_rectangle(device, 10, 43, 250, 103, COLORED);
  72. iot_epaper_display_frame(device, NULL); // display internal frame buffer
  73. iot_epaper_delete(device, true);
  74. ESP_LOGI(TAG, "EPD Display update count: %d", cnt++);
  75. ESP_LOGI(TAG, "After ePaper driver delete, heap: %d", esp_get_free_heap_size());
  76. vTaskDelay(5000 / portTICK_PERIOD_MS);
  77. }
  78. }
  79. void app_main()
  80. {
  81. ESP_LOGI(TAG, "Starting example");
  82. xTaskCreate(&e_paper_task, "epaper_task", 4 * 1024, NULL, 5, NULL);
  83. }