Skip to content

Commit

Permalink
Merge pull request #13 from C47D/master
Browse files Browse the repository at this point in the history
Update README and code to support ESP_WROVER_KIT
  • Loading branch information
kisvegabor committed Jul 18, 2019
2 parents cc542b5 + 935a63b commit 5c0a45c
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 31 deletions.
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# LittlevGL project for ESP32

![Example GUI with LittlevGL on ESP32](screenshot.jpg)

## Get started
### Install the ESP32 SDK
Expand All @@ -18,12 +17,49 @@ Next to this README file you find two component.mk template files:

Rename `lvgl_component.mk` to `component.mk` and move it to the `lvgl` directory, then rename `lv_example_component.mk` to `component.mk` and move it to the `lv_examples` directory, remember `lvgl` and `lv_examples` directories are located into the **components** directory.

Then also move the `lv_conf.h` and `lv_ex_conf.h` files into the **components** directory.
### Configuration options
Some displays doesn't support the same options, for example, the ESP-Wrover-Kit doesn't have the touch controller and this is usual on other ILI9341 displays.

#### Touch controller
To configure the support for the touch controller go to `components/drv/component.mk` and change the value of `TOUCH_SUPPORT`. To enable the support for touch, set `TOUCH_SUPPORT=1`, like so `CFLAGS+=-DTOUCH_SUPPORT=1`, to disable set `TOUCH_SUPPORT=0`, like so `CFLAGS+=-DTOUCH_SUPPORT=0`.

#### TFT Display backlight level
Some displays turn on the backlight of the display with a logic 1, other with a logic 0, to set the correct value for your display go to `components/drv/component.mk` and change the value of `ILI9341_BCLK_ACTIVE_LVL`. For example, if your display turn on the backlight with a logic 0 set `CFLAGS+= -DILI9341_BCKL_ACTIVE_LVL=0`, if your display turn on the backlight with a logic 1 set `CFLAGS+= -DILI9341_BCKL_ACTIVE_LVL=1`.

### Assign the correct pinout depending on your ESP32 dev board
#### Display size
You can change the size of your display in `lv_conf.h` in `LV_HOR\VER_RES_MAX`.

### AssTign the correct pinout depending on your ESP32 dev board
There are several development boards based on the ESP32 chip, make sure you assign the correct pin numbers to the signals that interface with the TFT display board, below are some examples:

## ESP32 Dev Board as the picture above
## ESP-Wrover-Kit v4.1 (Default)

![Example GUI with LittlevGL on ESP32](esp_wrover_kit.jpg)

This board comes with an embedded TFT screen with the **ILI9341** display driver and it doesn't have touch screen. The screen size is 340 x 220 px.

Make sure the uart selected to flash is ttyUSB1, you can change it on the `Serial flasher config` of make menuconfig.

### ILI9341
For ILI9341 HSPI is used, modify the pin configuration in `components/drv/disp_spi.h` to:

```c
#define DISP_SPI_MOSI 23
#define DISP_SPI_CLK 19
#define DISP_SPI_CS 22
```
and `components/drv/ili9341.h` to:
```c
#define ILI9341_DC 21
#define ILI9341_RST 18
#define ILI9341_BCKL 5
```

## ESP32 Dev Board with 38 GPIOs

![Example GUI with LittlevGL on ESP32](screenshot.jpg)

This project comes with an **ILI9341** display driver and an **XPT2046** resistive touchpad driver. Both devices are communicating via SPI.

### ILI9341
Expand Down
6 changes: 5 additions & 1 deletion components/drv/component.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# drv

CFLAGS += -DLV_CONF_INCLUDE_SIMPLE
CFLAGS += -DILI9341_BCKL_ACTIVE_LVL=0

# Set to 1 if your display have touch support, otherwise set it to 0.
CFLAGS += -DTOUCH_SUPPORT=1

COMPONENT_SRCDIRS := .

COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) .. ../..
COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) .. ../
19 changes: 11 additions & 8 deletions components/drv/disp_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void disp_spi_init(void)
.queue_size=1,
.pre_cb=NULL,
.post_cb=spi_ready,
.flags = SPI_DEVICE_HALFDUPLEX
};

//Initialize the SPI bus
Expand All @@ -82,10 +83,11 @@ void disp_spi_send_data(uint8_t * data, uint16_t length)

while(spi_trans_in_progress);

spi_transaction_t t;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length = length * 8; //Length is in bytes, transaction length is in bits.
t.tx_buffer = data; //Data
spi_transaction_t t = {
.length = length * 8, // transaction length is in bits
.tx_buffer = data
};

spi_trans_in_progress = true;
spi_color_sent = false; //Mark the "lv_flush_ready" NOT needs to be called in "spi_ready"
spi_device_queue_trans(spi, &t, portMAX_DELAY);
Expand All @@ -98,10 +100,11 @@ void disp_spi_send_colors(uint8_t * data, uint16_t length)

while(spi_trans_in_progress);

spi_transaction_t t;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length = length * 8; //Length is in bytes, transaction length is in bits.
t.tx_buffer = data; //Data
spi_transaction_t t = {
.length = length * 8, // transaction length is in bits
.tx_buffer = data
};

spi_trans_in_progress = true;
spi_color_sent = true; //Mark the "lv_flush_ready" needs to be called in "spi_ready"
spi_device_queue_trans(spi, &t, portMAX_DELAY);
Expand Down
6 changes: 3 additions & 3 deletions components/drv/disp_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extern "C" {
* DEFINES
*********************/

#define DISP_SPI_MOSI 13
#define DISP_SPI_CLK 14
#define DISP_SPI_CS 5
#define DISP_SPI_MOSI 23
#define DISP_SPI_CLK 19
#define DISP_SPI_CS 22


/**********************
Expand Down
2 changes: 1 addition & 1 deletion components/drv/ili9341.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ili9341_init(void)

///Enable backlight
printf("Enable backlight.\n");
gpio_set_level(ILI9341_BCKL, 1);
gpio_set_level(ILI9341_BCKL, ILI9341_BCKL_ACTIVE_LVL);
}


Expand Down
4 changes: 2 additions & 2 deletions components/drv/ili9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extern "C" {
* DEFINES
*********************/
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#define ILI9341_DC 19
#define ILI9341_DC 21
#define ILI9341_RST 18
#define ILI9341_BCKL 23
#define ILI9341_BCKL 5

/**********************
* TYPEDEFS
Expand Down
21 changes: 11 additions & 10 deletions components/drv/tp_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ void tp_spi_init(void)

uint8_t tp_spi_xchg(uint8_t data_send)
{
uint8_t data_rec = 0;
spi_transaction_t t;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length = 8; //Length is in bytes, transaction length is in bits.
t.tx_buffer = &data_send; //Data
t.rx_buffer = &data_rec;
uint8_t data_recv = 0;

spi_transaction_t t = {
.length = 8, // length is in bits
.tx_buffer = &data_send,
.rx_buffer = &data_recv
};

spi_device_queue_trans(spi, &t, portMAX_DELAY);
spi_device_queue_trans(spi, &t, portMAX_DELAY);

spi_transaction_t * rt;
spi_device_get_trans_result(spi, &rt, portMAX_DELAY);
spi_transaction_t * rt;
spi_device_get_trans_result(spi, &rt, portMAX_DELAY);

return data_rec;
return data_recv;
}


Expand Down
2 changes: 2 additions & 0 deletions components/drv/tp_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extern "C" {
* DEFINES
*********************/

#define ENABLE_TOUCH_INPUT TOUCH_SUPPORT

#define TP_SPI_MOSI 32
#define TP_SPI_MISO 35
#define TP_SPI_CLK 26
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added esp_wrover_kit.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lv_examples_component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CFLAGS += -DLV_CONF_INCLUDE_SIMPLE
COMPONENT_SRCDIRS := . \
lv_apps/demo

COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) ../..
COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) ../
2 changes: 1 addition & 1 deletion lvgl_component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ COMPONENT_SRCDIRS := . \
src/lv_misc \
src/lv_themes \
src/lv_font
COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) ../..
COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) ../
4 changes: 4 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ void app_main()
disp_drv.buffer = &disp_buf;
lv_disp_drv_register(&disp_drv);

// Set TOUCH_SUPPORT on drv\component.mk to 1 if
// your board have touch support
#if ENABLE_TOUCH_INPUT
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.read_cb = xpt2046_read;
indev_drv.type = LV_INDEV_TYPE_POINTER;
lv_indev_drv_register(&indev_drv);
#endif

esp_register_freertos_tick_hook(lv_tick_task);

Expand Down

0 comments on commit 5c0a45c

Please sign in to comment.