Skip to content

Commit

Permalink
Merge pull request #69 from fbiego/displays
Browse files Browse the repository at this point in the history
add esp32 multiple display configuration support
  • Loading branch information
fbiego authored Dec 11, 2024
2 parents 3875e8c + 4d487fb commit 7651b92
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 16 deletions.
17 changes: 10 additions & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
Add the path to your Mingw-w64 `bin` folder to the Windows PATH environment
variable (usually `C:\msys64\mingw64\bin`). See [instruction, 4](https://code.visualstudio.com/docs/cpp/config-mingw#_prerequisites).

**ESP32**

This project uses the Arduino framework and the LovyanGFX library for display drivers.

#### For Existing Display Configurations
1. Ensure the selected display configuration matches your hardware.
2. Open the `hal/esp32/app_hal.cpp` file.
- Include the appropriate `.hpp` file for your display.
- Ensure only **one** display configuration is uncommented at a time.
3. Verify that the `platformio.ini` file matches the board settings.
- Recommended settings can be found in the corresponding `.hpp` file.


#### Adding New Display Configurations
1. Create a new file under `hal/esp32/displays/`.
- Name it `lgfx_{board_name}.hpp`, replacing `{board_name}` with your board's name.
2. Add the new `.hpp` file to the `hal/esp32/app_hal.cpp` file and ensure it's included correctly.
3. In the newly created `.hpp` file, include the recommended board configuration for reference.

Make sure to test your setup to confirm compatibility.

### Install flasher drivers (optional)

Expand Down
13 changes: 7 additions & 6 deletions hal/esp32/app_hal.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

#include "app_hal.h"
#include "lvgl.h"
#include "PanelLan.h"


/* Set the board type. (Uses LovyanGFX internally to manage display drivers) */
PanelLan tft(BOARD_SC01_PLUS);
/* include only one display settings */
// #include "displays/lgfx_wt32sc01_plus.hpp"
#include "displays/lgfx_elecrow_3_5.hpp"

static const uint32_t screenWidth = 480;
static const uint32_t screenHeight = 320;

static const uint32_t screenWidth = WIDTH;
static const uint32_t screenHeight = HEIGHT;

const unsigned int lvBufferSize = screenWidth * 30;
uint8_t lvBuffer[2][lvBufferSize];
Expand Down Expand Up @@ -74,7 +75,7 @@ void hal_setup(void)
tft.fillScreen(TFT_BLACK);

/* Set display rotation to landscape */
tft.setRotation(1);
// tft.setRotation(1);

/* Set the tick callback */
lv_tick_set_cb(my_tick);
Expand Down
124 changes: 124 additions & 0 deletions hal/esp32/displays/LGFX_ELECROW_3_5.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#pragma once

#define LGFX_USE_V1
#include <LovyanGFX.hpp>


/**
* Recommended board settings for platformio.ini file
*
* board = esp32-s3-devkitc-1
* board_build.partitions = max_app_8MB.csv
*
*/

#define WIDTH 320
#define HEIGHT 480

class LGFX : public lgfx::LGFX_Device
{

lgfx::Panel_ILI9488 _panel_instance;

lgfx::Bus_Parallel16 _bus_instance;

lgfx::Light_PWM _light_instance;

lgfx::Touch_FT5x06 _touch_instance;

public:
LGFX(void)
{
{
auto cfg = _bus_instance.config();

cfg.port = 0;
cfg.freq_write = 40000000;
cfg.pin_wr = 18; // pin number connecting WR
cfg.pin_rd = 48; // pin number connecting RD
cfg.pin_rs = 45; // Pin number connecting RS(D/C)
cfg.pin_d0 = 47; // pin number connecting D0
cfg.pin_d1 = 21; // pin number connecting D1
cfg.pin_d2 = 14; // pin number connecting D2
cfg.pin_d3 = 13; // pin number connecting D3
cfg.pin_d4 = 12; // pin number connecting D4
cfg.pin_d5 = 11; // pin number connecting D5
cfg.pin_d6 = 10; // pin number connecting D6
cfg.pin_d7 = 9; // pin number connecting D7
cfg.pin_d8 = 3; // pin number connecting D8
cfg.pin_d9 = 8; // pin number connecting D9
cfg.pin_d10 = 16; // pin number connecting D10
cfg.pin_d11 = 15; // pin number connecting D11
cfg.pin_d12 = 7; // pin number connecting D12
cfg.pin_d13 = 6; // pin number connecting D13
cfg.pin_d14 = 5; // pin number connecting D14
cfg.pin_d15 = 4; // pin number connecting D15

_bus_instance.config(cfg); // Apply the settings to the bus.
_panel_instance.setBus(&_bus_instance); // Sets the bus to the panel.
}

{ // Set display panel control.
auto cfg = _panel_instance.config(); // Get the structure for display panel settings.

cfg.pin_cs = -1; // Pin number to which CS is connected (-1 = disable)
cfg.pin_rst = -1; // pin number where RST is connected (-1 = disable)
cfg.pin_busy = -1; // pin number to which BUSY is connected (-1 = disable)

// * The following setting values ​​are set to general default values ​​for each panel, and the pin number (-1 = disable) to which BUSY is connected, so please try commenting out any unknown items.

cfg.memory_width = 320; // Maximum width supported by driver IC
cfg.memory_height = 480; // Maximum height supported by driver IC
cfg.panel_width = 320; // actual displayable width
cfg.panel_height = 480; // actual displayable height
cfg.offset_x = 0; // Panel offset in X direction
cfg.offset_y = 0; // Panel offset in Y directioncfg.offset_rotation = 2;
cfg.dummy_read_pixel = 8;
cfg.dummy_read_bits = 1;
cfg.readable = false;
cfg.invert = false;
cfg.rgb_order = false;
cfg.dlen_16bit = true;
cfg.bus_shared = true;

_panel_instance.config(cfg);
}
{ // Set backlight control. (delete if not necessary)
auto cfg = _light_instance.config(); // Get the structure for backlight configuration.

cfg.pin_bl = 46; // pin number to which the backlight is connected
cfg.invert = false; // true to invert backlight brightness
cfg.freq = 44100; // backlight PWM frequency
cfg.pwm_channel = 0; // PWM channel number to use

_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance); // Sets the backlight to the panel.
}

{ // Configure settings for touch screen control. (delete if not necessary)
auto cfg = _touch_instance.config();

cfg.x_min = 0; // Minimum X value (raw value) obtained from the touchscreen
cfg.x_max = 319; // Maximum X value (raw value) obtained from the touchscreen
cfg.y_min = 0; // Minimum Y value obtained from touchscreen (raw value)
cfg.y_max = 479; // Maximum Y value (raw value) obtained from the touchscreen
cfg.pin_int = -1; // pin number to which INT is connected
cfg.bus_shared = true;
cfg.offset_rotation = 0;

// For I2C connection
cfg.i2c_port = 0; // Select I2C to use (0 or 1)
cfg.i2c_addr = 0x38; // I2C device address number
cfg.pin_sda = 38; // pin number where SDA is connected
cfg.pin_scl = 39; // pin number to which SCL is connected
cfg.freq = 400000; // set I2C clock

_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance); // Set the touchscreen to the panel.
}

setPanel(&_panel_instance); // Sets the panel to use.
}
};

LGFX tft;
19 changes: 19 additions & 0 deletions hal/esp32/displays/LGFX_WT32SC01_PLUS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "PanelLan.h"


/**
* Recommended board settings for platformio.ini file
*
* board = esp32-s3-devkitm-1
*
*/

#define WIDTH 320
#define HEIGHT 480


/* Set the board type. (Uses LovyanGFX internally to manage display drivers) */
PanelLan tft(BOARD_SC01_PLUS);

7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ build_src_filter =
; Force compile LVGL demo, remove when working on your own project
+<../.pio/libdeps/stm32f429_disco/lvgl/demos>

[env:esp32_sc01_plus]
[env:esp32_boards]
platform = espressif32
board = esp32-s3-devkitm-1
board = esp32-s3-devkitc-1 ; check displays hpp file for recommended settings
framework = arduino
build_flags =
${env.build_flags}
Expand All @@ -102,9 +102,10 @@ build_flags =
!python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/esp32')]))"
lib_deps =
${env.lib_deps}
lovyan03/LovyanGFX@^1.2.0
smartpanle/PanelLan@^0.0.1
build_src_filter =
+<*>
+<../hal/esp32>
; Force compile LVGL demo, remove when working on your own project
+<../.pio/libdeps/esp32_sc01_plus/lvgl/demos>
+<../.pio/libdeps/esp32_boards/lvgl/demos>

0 comments on commit 7651b92

Please sign in to comment.