Skip to content

Commit

Permalink
initial changes for waveshare s3 touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
KenVanHoeylandt committed Jan 23, 2024
1 parent ed2d0cc commit 8e01cba
Show file tree
Hide file tree
Showing 48 changed files with 804 additions and 455 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ cmake_minimum_required(VERSION 3.16)

add_definitions(-DTT_DEBUG)

if (ESP_PLATFORM)
if ($ENV{ESP_IDF_VERSION})
message("Building with ESP-IDF v$ENV{ESP_IDF_VERSION}")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

add_definitions(-DESP_TARGET)
add_compile_definitions(ESP_TARGET)

set(COMPONENTS app-esp)
set(EXTRA_COMPONENT_DIRS
"boards"
Expand All @@ -24,6 +26,7 @@ if (ESP_PLATFORM)
# T-Deck is an S3 platform
if(NOT "${IDF_TARGET}" STREQUAL "esp32s3")
set(EXCLUDE_COMPONENTS "lilygo_tdeck")
set(EXCLUDE_COMPONENTS "waveshare_s3_touch")
endif()
else()
message("Building for sim target")
Expand All @@ -35,7 +38,7 @@ add_subdirectory(libs/mlib)
add_subdirectory(tactility)
add_subdirectory(tactility-core)

if (NOT ESP_PLATFORM)
if (NOT $ENV{ESP_IDF_VERSION})
add_subdirectory(libs/freertos-kernel)
target_include_directories(freertos-kernel
PUBLIC app-sim/src # for FreeRTOSConfig.h
Expand Down
76 changes: 76 additions & 0 deletions CODING_STYLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# C coding Style

The basic formatting rules are set in `.clang-format`. Use auto-formatting in your editor.

All code should target C language revision C11/C17.

## Naming

### Files

Files are snake-case.

- Files: `^[0-9a-z_]+$`
- Directories: `^[0-9a-z_]+$`

Example:
```c
some_feature.c
some_feature.h
```

Private/internal headers are postfixed with `_i` before the file extension.
Like `some_feature_i.h`

### Function names

Names are snake-case.

Public functions are prefixed with `tt_` for `tactility-core` and `tactility` projects.
Internal/static functions don't have prefix requirements, but prefixes are allowed.

Public functions have the feature name after `tt_`.

If a feature has setters or getters, it's added after the feature name part.

Example:

```c
void tt_feature_get_name() {
// ...
}
```

Function names that allocate or free memory should end in `_alloc` and `_free`.

### Type names

Consts are snake-case with capital letters.

Typedefs for structs and datatype aliases are PascalCase.
Examples:

```c
typedef uint32_t SomeAlias;

typedef struct {
// ...
} SomeStruct;
```

### Internal struct with public handle

When you have a `struct` data type that is private and you want to expose a handle (pointer),
append the internal name with `Data` like this:

**feature.c**
```c
typedef struct {
// ...
} MutexData;
```

**feature.h**
```c
typedef void* Mutex;
```
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Note

During the pre-alpha stage, contributions will not yet be considered.
Too many things are changing too rapidly:
I don't want to disappoint people with huge merge conflicts.

# Code Style

See [this document](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/CODING_STYLE.md).
See [this document](CODING_STYLE.md).

1 change: 1 addition & 0 deletions app-esp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif()
# T-Deck is an S3 platform
if("${IDF_TARGET}" STREQUAL "esp32s3")
list(APPEND BOARD_COMPONENTS lilygo_tdeck)
list(APPEND BOARD_COMPONENTS waveshare_s3_touch)
endif()

idf_component_register(
Expand Down
2 changes: 2 additions & 0 deletions app-esp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ menu "Tactility App"
bool "Yellow Board (2.4\" capacitive)"
config TT_BOARD_LILYGO_TDECK
bool "LilyGo T-Deck"
config TT_BOARD_WAVESHARE_S3_TOUCH
bool "Waveshare S3 Touch LCD 4.3\""
endchoice
endmenu
3 changes: 3 additions & 0 deletions app-esp/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#elif defined(CONFIG_TT_BOARD_YELLOW_BOARD_24_CAP)
#include "yellow_board.h"
#define TT_BOARD_HARDWARE &yellow_board_24inch_cap
#elif defined(CONFIG_TT_BOARD_WAVESHARE_S3_TOUCH)
#include "waveshare_s3_touch.h"
#define TT_BOARD_HARDWARE &waveshare_s3_touch
#else
#define TT_BOARD_HARDWARE NULL
#error Replace TT_BOARD_HARDWARE in main.c with your own. Or copy one of the ./sdkconfig.board.* files into ./sdkconfig.
Expand Down
13 changes: 7 additions & 6 deletions app-esp/src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "board_config.h"
#include "tactility-esp.h"
#include "tactility_esp.h"

// Apps
#include "hello_world/hello_world.h"
Expand All @@ -12,6 +12,11 @@ extern const AppManifest wifi_manage_app;

TT_UNUSED void app_main(void) {
static const Config config = {
/**
* Auto-select a board based on the ./sdkconfig.board.* file
* that you copied to ./sdkconfig before you opened this project.
*/
.hardware = TT_BOARD_HARDWARE,
.apps = {
&hello_world_app,
&wifi_connect_app,
Expand All @@ -23,11 +28,7 @@ TT_UNUSED void app_main(void) {
.auto_start_app_id = NULL
};

/**
* Auto-select a board based on the ./sdkconfig.board.* file
* that you copied to ./sdkconfig before you opened this project.
*/
tt_esp_init(TT_BOARD_HARDWARE);
tt_esp_init();

tt_init(&config);

Expand Down
2 changes: 1 addition & 1 deletion boards/lilygo_tdeck/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
idf_component_register(
SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES tactility-esp esp_lcd esp_lcd_touch_gt911
REQUIRES tactility-esp esp_lcd esp_lcd_touch_gt911 driver
)

3 changes: 3 additions & 0 deletions boards/lilygo_tdeck/bootstrap.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "esp_log.h"
#include "driver/gpio.h"
#include "kernel.h"
#include "esp_lvgl_port.h"

#define TAG "lilygo_tdeck_bootstrap"
#define TDECK_PERI_POWERON GPIO_NUM_10

lv_disp_t* lilygo_tdeck_init_display();

static void tdeck_power_on() {
ESP_LOGI(TAG, "power on");
gpio_config_t device_power_signal_config = {
Expand Down
54 changes: 30 additions & 24 deletions boards/lilygo_tdeck/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_log.h"
#include "tactility-esp.h"
#include "esp_lvgl_port.h"

#define TAG "lilygo_tdeck_display"

Expand Down Expand Up @@ -57,7 +57,7 @@ static void tdeck_backlight() {
ESP_ERROR_CHECK(ledc_set_duty(LCD_BACKLIGHT_LEDC_MODE, LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_DUTY));
}

static bool create_display_device(DisplayDevice* display) {
lv_disp_t* lilygo_tdeck_init_display() {
ESP_LOGI(TAG, "creating display");

int draw_buffer_size = LCD_HORIZONTAL_RESOLUTION * LCD_DRAW_BUFFER_HEIGHT * (LCD_BITS_PER_PIXEL / 8);
Expand Down Expand Up @@ -96,7 +96,8 @@ static bool create_display_device(DisplayDevice* display) {
}
};

if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_SPI_HOST, &panel_io_config, &display->io_handle) != ESP_OK) {
esp_lcd_panel_io_handle_t io_handle;
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_SPI_HOST, &panel_io_config, &io_handle) != ESP_OK) {
ESP_LOGD(TAG, "failed to create panel IO");
return false;
}
Expand All @@ -113,56 +114,61 @@ static bool create_display_device(DisplayDevice* display) {
.vendor_config = NULL
};

if (esp_lcd_new_panel_st7789(display->io_handle, &panel_config, &display->display_handle) != ESP_OK) {
esp_lcd_panel_handle_t panel_handle;
if (esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle) != ESP_OK) {
ESP_LOGD(TAG, "failed to create panel");
return false;
}

if (esp_lcd_panel_reset(display->display_handle) != ESP_OK) {
if (esp_lcd_panel_reset(panel_handle) != ESP_OK) {
ESP_LOGD(TAG, "failed to reset panel");
return false;
}

if (esp_lcd_panel_init(display->display_handle) != ESP_OK) {
if (esp_lcd_panel_init(panel_handle) != ESP_OK) {
ESP_LOGD(TAG, "failed to init panel");
return false;
}

if (esp_lcd_panel_invert_color(display->display_handle, true) != ESP_OK) {
if (esp_lcd_panel_invert_color(panel_handle, true) != ESP_OK) {
ESP_LOGD(TAG, "failed to init panel");
return false;
}

if (esp_lcd_panel_swap_xy(display->display_handle, true) != ESP_OK) {
if (esp_lcd_panel_swap_xy(panel_handle, true) != ESP_OK) {
ESP_LOGD(TAG, "failed to init panel");
return false;
}

if (esp_lcd_panel_mirror(display->display_handle, true, false) != ESP_OK) {
if (esp_lcd_panel_mirror(panel_handle, true, false) != ESP_OK) {
ESP_LOGD(TAG, "failed to init panel");
return false;
}

if (esp_lcd_panel_disp_on_off(display->display_handle, true) != ESP_OK) {
if (esp_lcd_panel_disp_on_off(panel_handle, true) != ESP_OK) {
ESP_LOGD(TAG, "failed to turn display on");
return false;
}

display->horizontal_resolution = LCD_HORIZONTAL_RESOLUTION;
display->vertical_resolution = LCD_VERTICAL_RESOLUTION;
display->draw_buffer_height = LCD_DRAW_BUFFER_HEIGHT;
display->bits_per_pixel = LCD_BITS_PER_PIXEL;
display->monochrome = false;
display->double_buffering = false;
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = io_handle,
.panel_handle = panel_handle,
.buffer_size = LCD_HORIZONTAL_RESOLUTION * LCD_DRAW_BUFFER_HEIGHT * (LCD_BITS_PER_PIXEL / 8),
.double_buffer = false,
.hres = LCD_HORIZONTAL_RESOLUTION,
.vres = LCD_VERTICAL_RESOLUTION,
.monochrome = false,
.rotation = {
.swap_xy = true, // TODO: check if code above is still needed
.mirror_x = true,
.mirror_y = false,
},
.flags = {
.buff_dma = true,
}
};

tdeck_backlight();

return true;
}

DisplayDriver lilygo_tdeck_display_driver() {
return (DisplayDriver) {
.name = "lilygo_tdeck_display",
.create_display_device = &create_display_device
};
return lvgl_port_add_disp(&disp_cfg);
}
7 changes: 5 additions & 2 deletions boards/lilygo_tdeck/lilygo_tdeck.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "lilygo_tdeck.h"
#include <stdbool.h>

bool lilygo_tdeck_bootstrap();
bool lilygo_init_lvgl();

const HardwareConfig lilygo_tdeck = {
.bootstrap = &lilygo_tdeck_bootstrap,
.display_driver = &lilygo_tdeck_display_driver,
.touch_driver = &lilygo_tdeck_touch_driver
.init_lvgl = &lilygo_init_lvgl
};
7 changes: 1 addition & 6 deletions boards/lilygo_tdeck/lilygo_tdeck.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#pragma once

#include "tactility-esp.h"
#include "hardware_config.h"

#ifdef __cplusplus
extern "C" {
#endif

// Available for HardwareConfig customizations
void lilygo_tdeck_bootstrap();
DisplayDriver lilygo_tdeck_display_driver();
TouchDriver lilygo_tdeck_touch_driver();

extern const HardwareConfig lilygo_tdeck;

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 8e01cba

Please sign in to comment.