Skip to content

Commit

Permalink
Merge pull request #139 from espressif/bsp/general_touch_support
Browse files Browse the repository at this point in the history
bsp: Add generic touch init functions
  • Loading branch information
tore-espressif authored Mar 9, 2023
2 parents ea56f81 + bed4c92 commit 160c0d6
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ Best way to start with ESP-BSP is trying one of the [examples](examples) on your
| [sensors_example](examples/sensors_example) | Azure-IoT-kit |

### BSP headers
Each BSP provides its header file in 'bsp' subfolder, so it can be included as follows: `#include "bsp/name-of-the-bsp.h"`.

Each BSP provides its header file in 'bsp' subfolder, so it can be included as follows: `#include "bsp/name-of-the-bsp.h"`.
For you convenience, each BSP also provides a wrapper header, which has the same name for all BSPs: `#include "bsp/esp-bsp.h"`.

BSPs that contain LCD screen or touchscreen also provide `bsp/display.h` and `bsp/touch.h`. These files provide functions for LCD or touchscreen initialization without LVGL graphics library, which is used by default.

> **_NOTE:_** There can be only one BSP in a single esp-idf project.
### In a custom project
Expand Down
14 changes: 10 additions & 4 deletions esp-box/esp-box.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
Expand All @@ -17,6 +17,7 @@

#include "bsp/esp-box.h"
#include "bsp/display.h"
#include "bsp/touch.h"
#include "esp_lcd_touch_tt21100.h"
#include "esp_lvgl_port.h"
#include "bsp_err_check.h"
Expand Down Expand Up @@ -272,7 +273,7 @@ static lv_disp_t *bsp_display_lcd_init(void)
return lvgl_port_add_disp(&disp_cfg);
}

static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
esp_err_t bsp_touch_new(esp_lcd_touch_handle_t *ret_touch)
{
/* Initialize touch */
const esp_lcd_touch_config_t tp_cfg = {
Expand All @@ -292,8 +293,13 @@ static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
};
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG();
BSP_ERROR_CHECK_RETURN_NULL(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_NULL(esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, &tp));
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, "");
return esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, ret_touch);
}

static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
{
BSP_ERROR_CHECK_RETURN_NULL(bsp_touch_new(&tp));
assert(tp);

/* Add touch input (for selected screen) */
Expand Down
2 changes: 1 addition & 1 deletion esp-box/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.3.0"
version: "2.3.1"
description: Board Support Package for ESP-BOX
url: https://github.com/espressif/esp-bsp/tree/master/esp-box

Expand Down
2 changes: 1 addition & 1 deletion esp-box/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down
34 changes: 34 additions & 0 deletions esp-box/include/bsp/touch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/

/**
* @file
* @brief BSP Touchscreen
*
* This file offers API for basic touchscreen initialization.
* It is useful for users who want to use the touchscreen without the default Graphical Library LVGL.
*
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
#include "esp_lcd_touch.h"

/**
* @brief Create new touchscreen
*
* If you want to free resources allocated by this function, you can use esp_lcd_touch API, ie.:
*
* \code{.c}
* esp_lcd_touch_del(tp);
* \endcode
*
* @param[out] ret_touch esp_lcd_touch touchscreen handle
* @return
* - ESP_OK On success
* - Else esp_lcd_touch failure
*/
esp_err_t bsp_touch_new(esp_lcd_touch_handle_t *ret_touch);
2 changes: 1 addition & 1 deletion esp32_s2_kaluga_kit/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion esp32_s3_eye/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down
14 changes: 10 additions & 4 deletions esp32_s3_korvo_2/esp32_s3_korvo_2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
Expand All @@ -20,6 +20,7 @@

#include "bsp/esp32_s3_korvo_2.h"
#include "bsp/display.h"
#include "bsp/touch.h"
#include "esp_lcd_ili9341.h"
#include "esp_io_expander_tca9554.h"
#include "esp_lcd_touch_tt21100.h"
Expand Down Expand Up @@ -298,7 +299,7 @@ static lv_disp_t *bsp_display_lcd_init(void)
return lvgl_port_add_disp(&disp_cfg);
}

static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
esp_err_t bsp_touch_new(esp_lcd_touch_handle_t *ret_touch)
{
/* Initialize touch */
const esp_lcd_touch_config_t tp_cfg = {
Expand All @@ -318,8 +319,13 @@ static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
};
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG();
BSP_ERROR_CHECK_RETURN_NULL(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_NULL(esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, &tp));
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, "");
return esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, ret_touch);
}

static lv_indev_t *bsp_display_indev_init(lv_disp_t *disp)
{
BSP_ERROR_CHECK_RETURN_NULL(bsp_touch_new(&tp));
assert(tp);

/* Add touch input (for selected screen) */
Expand Down
2 changes: 1 addition & 1 deletion esp32_s3_korvo_2/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.0"
version: "1.1.1"
description: Board Support Package for ESP32-S3-Korvo-2
url: https://github.com/espressif/esp-bsp/tree/master/esp32_s3_korvo_2

Expand Down
2 changes: 1 addition & 1 deletion esp32_s3_korvo_2/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down
34 changes: 34 additions & 0 deletions esp32_s3_korvo_2/include/bsp/touch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/

/**
* @file
* @brief BSP Touchscreen
*
* This file offers API for basic touchscreen initialization.
* It is useful for users who want to use the touchscreen without the default Graphical Library LVGL.
*
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
#include "esp_lcd_touch.h"

/**
* @brief Create new touchscreen
*
* If you want to free resources allocated by this function, you can use esp_lcd_touch API, ie.:
*
* \code{.c}
* esp_lcd_touch_del(tp);
* \endcode
*
* @param[out] ret_touch esp_lcd_touch touchscreen handle
* @return
* - ESP_OK On success
* - Else esp_lcd_touch failure
*/
esp_err_t bsp_touch_new(esp_lcd_touch_handle_t *ret_touch);
2 changes: 1 addition & 1 deletion esp32_s3_usb_otg/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion esp_wrover_kit/include/bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This file offers API for basic LCD control.
* It is useful for users who want to use the LCD without the default Graphical Library LVGL.
*
* For standard LCD initialization, you can call all-in-one function bsp_display_start().
* For standard LCD initialization with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
Expand Down

0 comments on commit 160c0d6

Please sign in to comment.