很奇怪的一件事

TritiumX
Posts: 2
Joined: Thu Jun 22, 2023 8:45 am

很奇怪的一件事

Postby TritiumX » Thu Jun 22, 2023 8:55 am

我用官方文档搬了这串代码,刚开始有一个指针设置错误了,屏幕是可以显示的,但是会每隔1秒左右重启一次。修好这个Bug之后屏幕就不亮了。我再次用官方的example烧录进去,是可以正常显示的。于是我尝试把example里的代码搬过来改动,发现也是不能显示的,查看monitor并没有任何异常。这是怎么回事呢?
  1. // "main.c"
  2. #include <stdio.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "esp_timer.h"
  6. #include "esp_lcd_panel_io.h"
  7. #include "esp_lcd_panel_vendor.h"
  8. #include "esp_lcd_panel_ops.h"
  9. #include "driver/i2c.h"
  10. #include "esp_err.h"
  11. #include "esp_log.h"
  12. #include "lvgl/lvgl.h"
  13.  
  14. static const char *TAG = "Net_Clock";
  15.  
  16. #define I2C_HOST 0
  17.  
  18. // oled配置
  19. #define CLOCK_LCD_PIXEL_CLOCK_HZ (400 * 1000)
  20. #define CLOCK_PIN_NUM_SDA 3
  21. #define CLOCK_PIN_NUM_SCL 4
  22. #define CLOCK_PIN_NUM_RST -1
  23. #define CLOCK_I2C_HW_ADDR 0x3C
  24.  
  25. // 像素配置
  26. #define CLOCK_LCD_H_RES 128
  27. #define CLOCK_LCD_V_RES 64
  28.  
  29. // 流配置
  30. #define CLOCK_LCD_CMD_BITS 8
  31. #define CLOCK_LCD_PARAM_BITS 8
  32.  
  33. #define CLOCK_LVGL_TICK_PERIOD_MS 2
  34.  
  35. extern void clock_ui(lv_disp_t *disp);
  36.  
  37. static bool clock_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
  38. {
  39.     lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
  40.     lv_disp_flush_ready(disp_driver);
  41.     return false;
  42. }
  43.  
  44. static void clock_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
  45. {
  46.     esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
  47.     int offsetx1 = area->x1;
  48.     int offsetx2 = area->x2;
  49.     int offsety1 = area->y1;
  50.     int offsety2 = area->y2;
  51.     // copy a buffer's content to a specific area of the display
  52.     esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
  53. }
  54.  
  55. static void clock_lvgl_set_px_cb(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
  56.                                  lv_color_t color, lv_opa_t opa)
  57. {
  58.     uint16_t byte_index = x + ((y >> 3) * buf_w);
  59.     uint8_t bit_index = y & 0x7;
  60.  
  61.     if ((color.full == 0) && (LV_OPA_TRANSP != opa))
  62.     {
  63.         buf[byte_index] |= (1 << bit_index);
  64.     }
  65.     else
  66.     {
  67.         buf[byte_index] &= ~(1 << bit_index);
  68.     }
  69. }
  70.  
  71. static void clock_lvgl_rounder(lv_disp_drv_t *disp_drv, lv_area_t *area)
  72. {
  73.     area->y1 = area->y1 & (~0x7);
  74.     area->y2 = area->y2 | 0x7;
  75. }
  76.  
  77. static void clock_increase_lvgl_tick(void *arg)
  78. {
  79.     /* Tell LVGL how many milliseconds has elapsed */
  80.     lv_tick_inc(CLOCK_LVGL_TICK_PERIOD_MS);
  81. }
  82.  
  83. void app_main(void)
  84. {
  85.     static lv_disp_draw_buf_t disp_buf;
  86.     static lv_disp_drv_t disp_drv;
  87.  
  88.     // OLED驱动
  89.     ESP_LOGI(TAG, "Initialize I2C bus...");
  90.     i2c_config_t i2c_conf = {
  91.         .mode = I2C_MODE_MASTER,
  92.         .sda_io_num = CLOCK_PIN_NUM_SDA,
  93.         .scl_io_num = CLOCK_PIN_NUM_SCL,
  94.         .sda_pullup_en = GPIO_PULLDOWN_ENABLE,
  95.         .scl_pullup_en = GPIO_PULLDOWN_ENABLE,
  96.         .master.clk_speed = CLOCK_LCD_PIXEL_CLOCK_HZ,
  97.     };
  98.     ESP_ERROR_CHECK(i2c_param_config(I2C_HOST, &i2c_conf));
  99.     ESP_ERROR_CHECK(i2c_driver_install(I2C_HOST, I2C_MODE_MASTER, 0, 0, 0));
  100.  
  101.     ESP_LOGI(TAG, "Install panel IO...");
  102.     esp_lcd_panel_io_handle_t io_handle = NULL;
  103.     esp_lcd_panel_io_i2c_config_t io_config = {
  104.         .dev_addr = CLOCK_I2C_HW_ADDR,
  105.         .control_phase_bytes = 1,
  106.         .dc_bit_offset = 6,
  107.         .lcd_cmd_bits = CLOCK_LCD_CMD_BITS,
  108.         .lcd_param_bits = CLOCK_LCD_PARAM_BITS,
  109.         .on_color_trans_done = clock_notify_lvgl_flush_ready,
  110.         .user_ctx = &disp_drv,
  111.     };
  112.     ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)I2C_HOST, &io_config, &io_handle));
  113.  
  114.     ESP_LOGI(TAG, "Install SSD1306 panel driver");
  115.     esp_lcd_panel_handle_t panel_handle = NULL;
  116.     esp_lcd_panel_dev_config_t panel_config = {
  117.         .bits_per_pixel = 1,
  118.         .reset_gpio_num = CLOCK_PIN_NUM_RST,
  119.     };
  120.     ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));
  121.  
  122.     ESP_LOGI(TAG, "Initialize OLED Driver Done!");
  123.     esp_lcd_panel_reset(panel_handle);
  124.     esp_lcd_panel_init(panel_handle);
  125.     esp_lcd_panel_disp_on_off(panel_handle, true);
  126.  
  127.     ESP_LOGI(TAG, "Initialize LVGL library...");
  128.         lv_init();
  129.     lv_color1_t *buf1 = malloc(CLOCK_LCD_H_RES * 20 * sizeof(lv_color1_t));
  130.     assert(buf1);
  131.     lv_color1_t *buf2 = malloc(CLOCK_LCD_H_RES * 20 * sizeof(lv_color1_t));
  132.     assert(buf2);
  133.  
  134.     lv_disp_draw_buf_init(&disp_buf, buf1, buf2, CLOCK_LCD_H_RES * 20);
  135.  
  136.     ESP_LOGI(TAG, "Register display driver to LVGL");
  137.     lv_disp_drv_init(&disp_drv);
  138.     disp_drv.hor_res = CLOCK_LCD_H_RES;
  139.     disp_drv.ver_res = CLOCK_LCD_V_RES;
  140.     disp_drv.flush_cb = clock_lvgl_flush_cb;
  141.     disp_drv.draw_buf = &disp_buf;
  142.     disp_drv.user_data = panel_handle;
  143.     disp_drv.rounder_cb =clock_lvgl_rounder;
  144.     disp_drv.set_px_cb = clock_lvgl_set_px_cb;
  145.     lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
  146.  
  147.     ESP_LOGI(TAG, "Install LVGL tick timer...");
  148.     const esp_timer_create_args_t lvgl_tick_timer_args = {
  149.         .callback = &clock_increase_lvgl_tick,
  150.         .name = "display_tick"};
  151.     esp_timer_handle_t lvgl_tick_timer = NULL;
  152.     ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
  153.     ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, CLOCK_LVGL_TICK_PERIOD_MS * 1000));
  154.  
  155.     ESP_LOGI(TAG, "Displaying Time...");
  156.     clock_ui(disp);
  157.     while (1)
  158.     {
  159.         vTaskDelay(pdMS_TO_TICKS(10));
  160.         lv_timer_handler();
  161.     }
  162. }
  1. // "clock_ui.c"
  2. /*
  3.  * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  4.  *
  5.  * SPDX-License-Identifier: CC0-1.0
  6.  */
  7.  
  8. #include "lvgl.h"
  9.  
  10. void clock_ui(lv_disp_t *disp)
  11. {
  12.     lv_obj_t *scr = lv_disp_get_scr_act(disp);
  13.     lv_obj_t *label = lv_label_create(scr);
  14.     lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); /* Circular scroll */
  15.     lv_label_set_text(label, "Hi, There.");
  16.     lv_obj_set_width(label, 150);
  17.     lv_obj_align(label, LV_ALIGN_TOP_MID, 10, 0);
  18. }
  1. # 以下是monitor输出
  2.  
  3. ets Jul 29 2019 12:21:46
  4.  
  5. rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
  6. configsip: 0, SPIWP:0xee
  7. clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
  8. mode:DIO, clock div:2
  9. load:0x3fff0030,len:6940
  10. ho 0 tail 12 room 4
  11. load:0x40078000,len:15500
  12. load:0x40080400,len:3844
  13. 0x40080400: _init at ??:?
  14.  
  15. entry 0x4008064c
  16. I (29) boot: ESP-IDF v5.0.2 2nd stage bootloader
  17. I (29) boot: compile time 14:35:19
  18. I (29) boot: chip revision: v3.0
  19. I (32) boot.esp32: SPI Speed      : 40MHz
  20. I (37) boot.esp32: SPI Mode       : DIO
  21. I (41) boot.esp32: SPI Flash Size : 2MB
  22. I (46) boot: Enabling RNG early entropy source...
  23. I (51) boot: Partition Table:
  24. I (55) boot: ## Label            Usage          Type ST Offset   Length
  25. I (62) boot:  0 nvs              WiFi data        01 02 00009000 00006000
  26. I (70) boot:  1 phy_init         RF data          01 01 0000f000 00001000
  27. I (77) boot:  2 factory          factory app      00 00 00010000 00100000
  28. I (85) boot: End of partition table
  29. I (89) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0f244h ( 62020) map
  30. I (120) esp_image: segment 1: paddr=0001f26c vaddr=3ffb0000 size=00dach (  3500) load
  31. I (121) esp_image: segment 2: paddr=00020020 vaddr=400d0020 size=42c8ch (273548) map
  32. I (224) esp_image: segment 3: paddr=00062cb4 vaddr=3ffb0dac size=011f8h (  4600) load
  33. I (226) esp_image: segment 4: paddr=00063eb4 vaddr=40080000 size=0d1f0h ( 53744) load
  34. I (259) boot: Loaded app from partition at offset 0x10000
  35. I (259) boot: Disabling RNG early entropy source...
  36. I (270) cpu_start: Pro cpu up.
  37. I (271) cpu_start: Starting app cpu, entry point is 0x400811f8
  38. 0x400811f8: call_start_cpu1 at E:/Espressif/esp-idf/components/esp_system/port/cpu_start.c:141
  39.  
  40. I (0) cpu_start: App cpu up.
  41. I (287) cpu_start: Pro cpu start user code
  42. I (287) cpu_start: cpu freq: 160000000 Hz
  43. I (287) cpu_start: Application information:
  44. I (292) cpu_start: Project name:     ner_clock
  45. I (297) cpu_start: App version:      1
  46. I (301) cpu_start: Compile time:     Jun 22 2023 14:35:01
  47. I (307) cpu_start: ELF file SHA256:  c7099146562da7ac...
  48. I (313) cpu_start: ESP-IDF:          v5.0.2
  49. I (318) cpu_start: Min chip rev:     v0.0
  50. I (323) cpu_start: Max chip rev:     v3.99
  51. I (328) cpu_start: Chip rev:         v3.0
  52. I (333) heap_init: Initializing. RAM available for dynamic allocation:
  53. I (340) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
  54. I (346) heap_init: At 3FFBAD68 len 00025298 (148 KiB): DRAM
  55. I (352) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
  56. I (358) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
  57. I (365) heap_init: At 4008D1F0 len 00012E10 (75 KiB): IRAM
  58. I (372) spi_flash: detected chip: generic
  59. I (376) spi_flash: flash io: dio
  60. W (380) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
  61. I (394) cpu_start: Starting scheduler on PRO CPU.
  62. I (0) cpu_start: Starting scheduler on APP CPU.
  63. I (404) Net_Clock: Initialize I2C bus...
  64. I (414) Net_Clock: Install panel IO...
  65. I (414) Net_Clock: Install SSD1306 panel driver
  66. I (414) Net_Clock: Initialize OLED Driver Done!
  67. I (524) Net_Clock: Initialize LVGL library...
  68. I (524) Net_Clock: Register display driver to LVGL
  69. I (524) Net_Clock: Install LVGL tick timer...
  70. I (524) Net_Clock: Displaying Time...
  71.  

ESP_Xuxin
Posts: 83
Joined: Thu Sep 22, 2022 3:35 am

Re: 很奇怪的一件事

Postby ESP_Xuxin » Tue Jul 18, 2023 9:41 am

刚开始有一个指针设置错误了,屏幕是可以显示的,但是会每隔1秒左右重启一次。修好这个Bug之后屏幕就不亮了。
修改的是哪里?
屏幕就只是亮还会正常显示?

我再次用官方的example烧录进去,是可以正常显示的。于是我尝试把example里的代码搬过来改动,发现也是不能显示的,查看monitor并没有任何异常。这是怎么回事呢?
example 和 自己工程的区别是设么, 是否方便提供完整工程?

Who is online

Users browsing this forum: No registered users and 96 guests