Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "esp_err.h"
#include "esp_log.h"
#include "driver/i2c_master.h"
#include "esp_lvgl_port.h"
#include "lvgl.h"
#include "esp_lcd_sh1107.h"
#include "esp_lcd_panel_vendor.h"
TAG
#define I2C_BUS_PORT
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ
#define EXAMPLE_PIN_NUM_SDA
#define EXAMPLE_PIN_NUM_SCL
#define EXAMPLE_PIN_NUM_RST
#define EXAMPLE_I2C_HW_ADDR
#define EXAMPLE_LCD_H_RES
#define EXAMPLE_LCD_V_RES
#define EXAMPLE_LCD_H_RES
#define EXAMPLE_LCD_V_RES
#define EXAMPLE_LCD_CMD_BITS
#define EXAMPLE_LCD_PARAM_BITS
app_main()
Files
loading...
SourceVuESP-IDF Framework and Examplesi2c_oled samplemain/i2c_oled_example_main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 *//* ... */ #include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_lcd_panel_io.h" #include "esp_lcd_panel_ops.h" #include "esp_err.h" #include "esp_log.h" #include "driver/i2c_master.h" #include "esp_lvgl_port.h" #include "lvgl.h"10 includes #if CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107 #include "esp_lcd_sh1107.h" #else #include "esp_lcd_panel_vendor.h" #endif static const char *TAG = "example"; #define I2C_BUS_PORT 0 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// Please update the following configuration according to your LCD spec ////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define EXAMPLE_LCD_PIXEL_CLOCK_HZ (400 * 1000) #define EXAMPLE_PIN_NUM_SDA 3 #define EXAMPLE_PIN_NUM_SCL 4 #define EXAMPLE_PIN_NUM_RST -1 #define EXAMPLE_I2C_HW_ADDR 0x3C6 defines // The pixel number in horizontal and vertical #if CONFIG_EXAMPLE_LCD_CONTROLLER_SSD1306 #define EXAMPLE_LCD_H_RES 128 #define EXAMPLE_LCD_V_RES CONFIG_EXAMPLE_SSD1306_HEIGHT/* ... */ #elif CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107 #define EXAMPLE_LCD_H_RES 64 #define EXAMPLE_LCD_V_RES 128/* ... */ #endif // Bit number used to represent command and parameter #define EXAMPLE_LCD_CMD_BITS 8 #define EXAMPLE_LCD_PARAM_BITS 8 extern void example_lvgl_demo_ui(lv_disp_t *disp); void app_main(void) { ESP_LOGI(TAG, "Initialize I2C bus"); i2c_master_bus_handle_t i2c_bus = NULL; i2c_master_bus_config_t bus_config = { .clk_source = I2C_CLK_SRC_DEFAULT, .glitch_ignore_cnt = 7, .i2c_port = I2C_BUS_PORT, .sda_io_num = EXAMPLE_PIN_NUM_SDA, .scl_io_num = EXAMPLE_PIN_NUM_SCL, .flags.enable_internal_pullup = true, }{...}; ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &i2c_bus)); 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 = EXAMPLE_I2C_HW_ADDR, .scl_speed_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ, .control_phase_bytes = 1, // According to SSD1306 datasheet .lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS, // According to SSD1306 datasheet .lcd_param_bits = EXAMPLE_LCD_CMD_BITS, // According to SSD1306 datasheet #if CONFIG_EXAMPLE_LCD_CONTROLLER_SSD1306 .dc_bit_offset = 6, // According to SSD1306 datasheet #elif CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107 .dc_bit_offset = 0, // According to SH1107 datasheet .flags = { .disable_control_phase = 1, }{...} /* ... */#endif }{...}; ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus, &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 = EXAMPLE_PIN_NUM_RST, }{...}; #if CONFIG_EXAMPLE_LCD_CONTROLLER_SSD1306 esp_lcd_panel_ssd1306_config_t ssd1306_config = { .height = EXAMPLE_LCD_V_RES, }{...}; panel_config.vendor_config = &ssd1306_config; ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));/* ... */ #elif CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107 ESP_ERROR_CHECK(esp_lcd_new_panel_sh1107(io_handle, &panel_config, &panel_handle)); #endif ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle)); ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); #if CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107 ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_handle, true)); #endif ESP_LOGI(TAG, "Initialize LVGL"); const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG(); lvgl_port_init(&lvgl_cfg); const lvgl_port_display_cfg_t disp_cfg = { .io_handle = io_handle, .panel_handle = panel_handle, .buffer_size = EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES, .double_buffer = true, .hres = EXAMPLE_LCD_H_RES, .vres = EXAMPLE_LCD_V_RES, .monochrome = true, .rotation = { .swap_xy = false, .mirror_x = false, .mirror_y = false, }{...} }{...}; lv_disp_t *disp = lvgl_port_add_disp(&disp_cfg); /* Rotation of the screen */ lv_disp_set_rotation(disp, LV_DISP_ROT_NONE); ESP_LOGI(TAG, "Display LVGL Scroll Text"); // Lock the mutex due to the LVGL APIs are not thread-safe if (lvgl_port_lock(0)) { example_lvgl_demo_ui(disp); // Release the mutex lvgl_port_unlock(); }{...} }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.