WIP lcd
This commit is contained in:
parent
6cd7d7db29
commit
043fa2fabb
4
esp/cpp/06_lcd-panel/.gitignore
vendored
Normal file
4
esp/cpp/06_lcd-panel/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
build
|
||||||
|
managed_components
|
||||||
|
dependencies.lock
|
||||||
|
sdkconfig.old
|
17
esp/cpp/06_lcd-panel/CMakeLists.txt
Normal file
17
esp/cpp/06_lcd-panel/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# For more information about build system see
|
||||||
|
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||||
|
# The following five lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
project(
|
||||||
|
#[[NAME]] lcd-panel
|
||||||
|
VERSION 0.1
|
||||||
|
DESCRIPTION "Example of using the SSDLCD"
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
# For writing pure cmake components, see the documentation
|
||||||
|
# https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#writing-pure-cmake-components
|
||||||
|
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
|
31
esp/cpp/06_lcd-panel/README.md
Normal file
31
esp/cpp/06_lcd-panel/README.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# 06_lcd-panel
|
||||||
|
|
||||||
|
This example is largely adapted from those in [ESP32-basic-starter-kit.pdf](./ESP32-basic-starter-kit.pdf).
|
||||||
|
|
||||||
|
The APIs in the original examples paired with this PDF have changed, and I decided to do some different things with the code and/or circuits, but the original code can be [found here](https://www.dropbox.com/scl/fo/6znlij3eb23ih4jxcpv2w/AKvB1t9CCUgoVRVtGen8Yrw?rlkey=z84anl0hs940qf9fpl7l8q8q2&e=1&dl=0).
|
||||||
|
|
||||||
|
This is the same example in [03_temp-humidity-web](./../03_temp-humidity-web), ported to the cmake ESP-IDF build system.
|
||||||
|
|
||||||
|
For instructions on setting up the ESP-IDF see [04_-esp-idf-arduino](./../04_esp-idf-arduino)
|
||||||
|
|
||||||
|
This example is largely adapted from those in [ESP32-basic-starter-kit.pdf](./ESP32-basic-starter-kit.pdf).
|
||||||
|
|
||||||
|
The APIs in the original examples paired with this PDF have changed, and I decided to do some different things with the code and/or circuits, but the original code can be [found here](https://www.dropbox.com/scl/fo/6znlij3eb23ih4jxcpv2w/AKvB1t9CCUgoVRVtGen8Yrw?rlkey=z84anl0hs940qf9fpl7l8q8q2&e=1&dl=0).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Temperature and humidity sensor served on a web page within the local network.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
To build this example run the following commands.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source ~/path/to/esp-idf/export.sh
|
||||||
|
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make flash
|
||||||
|
```
|
5
esp/cpp/06_lcd-panel/main/CMakeLists.txt
Normal file
5
esp/cpp/06_lcd-panel/main/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "main.cpp"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
)
|
||||||
|
add_compile_definitions(PUBLIC "-DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE")
|
19
esp/cpp/06_lcd-panel/main/idf_component.yml
Normal file
19
esp/cpp/06_lcd-panel/main/idf_component.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
## IDF Component Manager Manifest File
|
||||||
|
dependencies:
|
||||||
|
## Required IDF version
|
||||||
|
idf:
|
||||||
|
version: '>=4.1.0'
|
||||||
|
# # Put list of dependencies here
|
||||||
|
# # For components maintained by Espressif:
|
||||||
|
# component: "~1.0.0"
|
||||||
|
# # For 3rd party components:
|
||||||
|
# username/component: ">=1.0.0,<2.0.0"
|
||||||
|
# username2/component2:
|
||||||
|
# version: "~1.0.0"
|
||||||
|
# # For transient dependencies `public` flag can be set.
|
||||||
|
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||||
|
# # All dependencies of `main` are public by default.
|
||||||
|
# public: true
|
||||||
|
espressif/arduino-esp32: ^3.1.1
|
||||||
|
espressif/esp_lvgl_port: ^2.4.4
|
||||||
|
# fasani/adafruit_gfx: ^1.7.8
|
131
esp/cpp/06_lcd-panel/main/main.cpp
Normal file
131
esp/cpp/06_lcd-panel/main/main.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include <driver/i2c_master.h>
|
||||||
|
#include <esp_lcd_io_i2c.h>
|
||||||
|
#include "esp_lcd_panel_ssd1306.h"
|
||||||
|
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
#include "WiFi.h"
|
||||||
|
|
||||||
|
#include "lvgl.h"
|
||||||
|
#include "soc/gpio_num.h"
|
||||||
|
#include "esp_lvgl_port.h"
|
||||||
|
|
||||||
|
static const char *TAG = "lcd-panel";
|
||||||
|
|
||||||
|
// According to SSD1306 datasheet
|
||||||
|
// Bit number used to represent command and parameter
|
||||||
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||||
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||||
|
#define I2C_HW_ADDR 0x3C
|
||||||
|
#define LCD_PIXEL_CLOCK_HZ (400 * 1000)
|
||||||
|
#define LCD_CMD_BITS 8
|
||||||
|
#define LCD_PARAM_BITS 8
|
||||||
|
#define PIN_NUM_RST -1
|
||||||
|
#define LCD_H_RES 128
|
||||||
|
|
||||||
|
#define LCD_V_RES 64
|
||||||
|
// TODO: Or?
|
||||||
|
//#define LCD_V_RES 32
|
||||||
|
|
||||||
|
// Pin number may vary based on your schematic
|
||||||
|
#define SDA_PIN GPIO_NUM_21
|
||||||
|
#define SCL_PIN GPIO_NUM_22
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
ESP_LOGI(TAG, "Initialize I2C bus");
|
||||||
|
i2c_master_bus_handle_t i2c_bus = nullptr;
|
||||||
|
i2c_master_bus_config_t bus_config = {
|
||||||
|
.i2c_port = I2C_STATUS_READ,
|
||||||
|
.sda_io_num = SDA_PIN,
|
||||||
|
.scl_io_num = SCL_PIN,
|
||||||
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
|
.glitch_ignore_cnt = 7,
|
||||||
|
.intr_priority = 0,
|
||||||
|
.trans_queue_depth = 0,
|
||||||
|
.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 = nullptr;
|
||||||
|
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||||
|
.dev_addr = I2C_HW_ADDR,
|
||||||
|
.control_phase_bytes = 1,
|
||||||
|
.dc_bit_offset = 6,
|
||||||
|
.lcd_cmd_bits = LCD_CMD_BITS,
|
||||||
|
.lcd_param_bits = LCD_PARAM_BITS,
|
||||||
|
.scl_speed_hz = LCD_PIXEL_CLOCK_HZ,
|
||||||
|
};
|
||||||
|
ESP_LOGI(TAG, "Install SSD1306 panel driver");
|
||||||
|
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus, &io_config, &io_handle));
|
||||||
|
|
||||||
|
esp_lcd_panel_handle_t panel_handle = nullptr;
|
||||||
|
esp_lcd_panel_dev_config_t panel_config = {
|
||||||
|
.reset_gpio_num = PIN_NUM_RST,
|
||||||
|
.bits_per_pixel = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_lcd_panel_ssd1306_config_t ssd1306_config = {
|
||||||
|
.height = LCD_V_RES,
|
||||||
|
};
|
||||||
|
panel_config.vendor_config = &ssd1306_config;
|
||||||
|
ESP_LOGI(TAG, "Install SSD1306 panel driver");
|
||||||
|
ESP_ERROR_CHECK(
|
||||||
|
esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));
|
||||||
|
|
||||||
|
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 = LCD_H_RES * LCD_V_RES,
|
||||||
|
.double_buffer = true,
|
||||||
|
.hres = LCD_H_RES,
|
||||||
|
.vres = LCD_V_RES,
|
||||||
|
.monochrome = true,
|
||||||
|
.rotation = {
|
||||||
|
.swap_xy = false,
|
||||||
|
.mirror_x = false,
|
||||||
|
.mirror_y = false,
|
||||||
|
},
|
||||||
|
.color_format = LV_COLOR_FORMAT_RGB565,
|
||||||
|
.flags = {
|
||||||
|
.sw_rotate = false,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lv_disp_t *disp = lvgl_port_add_disp(&disp_cfg);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Display Scroll Text");
|
||||||
|
// Lock the mutex due to the LVGL APIs are not thread-safe
|
||||||
|
if (lvgl_port_lock(0)) {
|
||||||
|
/* Rotation of the screen */
|
||||||
|
lv_disp_set_rotation(disp, LV_DISPLAY_ROTATION_0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Set text here
|
||||||
|
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||||
|
lv_obj_t *label = lv_label_create(scr);
|
||||||
|
// Circular scroll
|
||||||
|
lv_label_set_long_mode(label,
|
||||||
|
LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||||
|
lv_label_set_text(label, "Hello world!");
|
||||||
|
// Size of the screen
|
||||||
|
// If you use rotation 90 or 270, please set disp->driver->ver_res
|
||||||
|
lv_obj_set_width(label,
|
||||||
|
lv_display_get_physical_horizontal_resolution(disp));
|
||||||
|
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
|
||||||
|
|
||||||
|
// Release the mutex
|
||||||
|
lvgl_port_unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
4
esp/cpp/06_lcd-panel/main/main.h
Normal file
4
esp/cpp/06_lcd-panel/main/main.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef MAIN_H
|
||||||
|
#define MAIN_H
|
||||||
|
|
||||||
|
#endif // MAIN_H
|
2785
esp/cpp/06_lcd-panel/sdkconfig
Normal file
2785
esp/cpp/06_lcd-panel/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user