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