Skip to content

Commit

Permalink
Refactor project, add drivers for TFT display and touch, integrate LVGL.
Browse files Browse the repository at this point in the history
Board config, platform.io, drivers and build settings for new board and
display are borrowed from https://github.com/GthiN89/JC3248W535EN. Big
thanks to @GthiN89!
Setting new version of Arduino framework borrowed from this issue
platformio/platform-espressif32#1211 and
solution suggested by @maxgerhardt.
  • Loading branch information
gonzomir committed Dec 31, 2024
1 parent 76c8f83 commit 1f9c6c2
Show file tree
Hide file tree
Showing 23 changed files with 49,046 additions and 195 deletions.
2 changes: 2 additions & 0 deletions include/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "esp_adc_cal.h"
#include "soc/adc_channel.h"

#include "config.h"

// This fixes compile error, see https://github.com/esphome/issues/issues/2982.
#undef ADC_WIDTH_BIT_DEFAULT
#define ADC_WIDTH_BIT_DEFAULT ((adc_bits_width_t) ((int)ADC_WIDTH_MAX-1))
Expand Down
58 changes: 58 additions & 0 deletions include/bsp_err_check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_check.h"
#include "sdkconfig.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Assert on error, if selected in menuconfig. Otherwise return error code. */
#if CONFIG_BSP_ERROR_CHECK
#define BSP_ERROR_CHECK_RETURN_ERR(x) ESP_ERROR_CHECK(x)
#define BSP_ERROR_CHECK_RETURN_NULL(x) ESP_ERROR_CHECK(x)
#define BSP_ERROR_CHECK(x, ret) ESP_ERROR_CHECK(x)
#define BSP_NULL_CHECK(x, ret) assert(x)
#define BSP_NULL_CHECK_GOTO(x, goto_tag) assert(x)
#else
#define BSP_ERROR_CHECK_RETURN_ERR(x) do { \
esp_err_t err_rc_ = (x); \
if (unlikely(err_rc_ != ESP_OK)) { \
return err_rc_; \
} \
} while(0)

#define BSP_ERROR_CHECK_RETURN_NULL(x) do { \
if (unlikely((x) != ESP_OK)) { \
return NULL; \
} \
} while(0)

#define BSP_NULL_CHECK(x, ret) do { \
if ((x) == NULL) { \
return ret; \
} \
} while(0)

#define BSP_ERROR_CHECK(x, ret) do { \
if (unlikely((x) != ESP_OK)) { \
return ret; \
} \
} while(0)

#define BSP_NULL_CHECK_GOTO(x, goto_tag) do { \
if ((x) == NULL) { \
goto goto_tag; \
} \
} while(0)
#endif

#ifdef __cplusplus
}
#endif
59 changes: 59 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef EINK
#define GNSS_RX 16
#define GNSS_TX 17
#define GNSS_PPS 18
Expand All @@ -7,10 +8,68 @@
#define POWER_BTN 33
#define POWER_BTN_GPIO GPIO_NUM_33
#define BATTERY_STATUS 35
#define BATTERY_STATUS_ADC_CHANNEL ADC1_CHANNEL_7

#define DISPLAY_DIN 14
#define DISPLAY_CLK 13
#define DISPLAY_CS 15
#define DISPLAY_DC 27
#define DISPLAY_RST 26
#define DISPLAY_BUSY 25

#define LCD_QSPI_HOST (SPI2_HOST)
#define PIN_NUM_QSPI_CS (-1)
#define PIN_NUM_QSPI_PCLK (-1)
#define PIN_NUM_QSPI_DATA0 (-1)
#define PIN_NUM_QSPI_DATA1 (-1)
#define PIN_NUM_QSPI_DATA2 (-1)
#define PIN_NUM_QSPI_DATA3 (-1)
#define PIN_NUM_QSPI_RST (-1)
#define PIN_NUM_QSPI_DC (-1)
#define PIN_NUM_QSPI_TE (-1)
#define PIN_NUM_QSPI_BL (-1)

#define PIN_NUM_QSPI_TOUCH_SCL (-1)
#define PIN_NUM_QSPI_TOUCH_SDA (-1)
#define PIN_NUM_QSPI_TOUCH_RST (-1)
#define PIN_NUM_QSPI_TOUCH_INT (-1)
#endif

#ifdef TFT
#define GNSS_RX 17
#define GNSS_TX 18
#define GNSS_PPS 6
#define GNSS_EN 7
#define GNSS_EN_GPIO GPIO_NUM_7

#define POWER_BTN 15
#define POWER_BTN_GPIO GPIO_NUM_15
#define BATTERY_STATUS 5
#define BATTERY_STATUS_ADC_CHANNEL ADC1_CHANNEL_4

#define DISPLAY_DIN -1
#define DISPLAY_CLK -1
#define DISPLAY_CS -1
#define DISPLAY_DC -1
#define DISPLAY_RST -1
#define DISPLAY_BUSY -1

#define LCD_QSPI_HOST (SPI2_HOST)
#define PIN_NUM_QSPI_CS (GPIO_NUM_45)
#define PIN_NUM_QSPI_PCLK (GPIO_NUM_47)
#define PIN_NUM_QSPI_DATA0 (GPIO_NUM_21)
#define PIN_NUM_QSPI_DATA1 (GPIO_NUM_48)
#define PIN_NUM_QSPI_DATA2 (GPIO_NUM_40)
#define PIN_NUM_QSPI_DATA3 (GPIO_NUM_39)
#define PIN_NUM_QSPI_RST (GPIO_NUM_NC)
#define PIN_NUM_QSPI_DC (GPIO_NUM_8)
#define PIN_NUM_QSPI_TE (GPIO_NUM_38)
#define PIN_NUM_QSPI_BL (GPIO_NUM_1)

#define PIN_NUM_QSPI_TOUCH_SCL (GPIO_NUM_8)
#define PIN_NUM_QSPI_TOUCH_SDA (GPIO_NUM_4)
#define PIN_NUM_QSPI_TOUCH_RST (-1)
#define PIN_NUM_QSPI_TOUCH_INT (-1)
#endif

#define LV_LVGL_H_INCLUDE_SIMPLE
138 changes: 138 additions & 0 deletions include/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief BSP LCD
*
* 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 with LVGL graphical library, you can call all-in-one function bsp_display_start().
*/

#pragma once
#include "esp_lcd_types.h"
#include "driver/gpio.h"

/* LCD color formats */
#define ESP_LCD_COLOR_FORMAT_RGB565 (1)
#define ESP_LCD_COLOR_FORMAT_RGB888 (2)

/* LCD display color format */
#define BSP_LCD_COLOR_FORMAT (ESP_LCD_COLOR_FORMAT_RGB565)
/* LCD display color bytes endianness */
#define BSP_LCD_BIGENDIAN (1)
/* LCD display color bits */
#define BSP_LCD_BITS_PER_PIXEL (16)
/* LCD display color space */
#define BSP_LCD_COLOR_SPACE (ESP_LCD_COLOR_SPACE_RGB)
/* LCD definition */
#define LCD_I80_H_RES (170)
#define LCD_I80_V_RES (560)

#define LCD_QSPI_H_RES (320)
#define LCD_QSPI_V_RES (480)

/**
* @brief Tear configuration structure
*
*/
#define BSP_SYNC_TASK_CONFIG(te_io, intr_type) \
{ \
.task_priority = 4, \
.task_stack = 2048, \
.task_affinity = -1, \
.time_Tvdl = 13, \
.time_Tvdh = 3, \
.te_gpio_num = te_io, \
.tear_intr_type = intr_type, \
}

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief BSP display configuration structure
*
*/
typedef struct {
int max_transfer_sz; /*!< Maximum transfer size, in bytes. */
struct {
int task_priority; /*!< Tear task priority */
int task_stack; /*!< Tear task stack size */
int task_affinity; /*!< Tear task pinned to core (-1 is no affinity) */
uint32_t time_Tvdl; /*!< The display panel is updated from the Frame Memory, Reference specifications */
uint32_t time_Tvdh; /*!< The display panel is not updated from the Frame Memory, Reference specifications */
int te_gpio_num; /*!< Tear gpio num */
gpio_int_type_t tear_intr_type; /*!< Tear intr type */
} tear_cfg;
} bsp_display_config_t;

/**
* @brief Create new display panel
*
* For maximum flexibility, this function performs only reset and initialization of the display.
* You must turn on the display explicitly by calling esp_lcd_panel_disp_on_off().
* The display's backlight is not turned on either. You can use bsp_display_backlight_on/off(),
* bsp_display_brightness_set() (on supported boards) or implement your own backlight control.
*
* If you want to free resources allocated by this function, you can use esp_lcd API, ie.:
*
* \code{.c}
* esp_lcd_panel_del(panel);
* esp_lcd_panel_io_del(io);
* spi_bus_free(spi_num_from_configuration);
* \endcode
*
* @param[in] config display configuration
* @param[out] ret_panel esp_lcd panel handle
* @param[out] ret_io esp_lcd IO handle
* @return
* - ESP_OK On success
* - Else esp_lcd failure
*/
esp_err_t bsp_display_new(const bsp_display_config_t *config, esp_lcd_panel_handle_t *ret_panel, esp_lcd_panel_io_handle_t *ret_io);

/**
* @brief Set display's brightness
*
* Brightness is controlled with PWM signal to a pin controlling backlight.
* Display must be already initialized by calling bsp_display_new()
*
* @param[in] brightness_percent Brightness in [%]
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t bsp_display_brightness_set(int brightness_percent);

/**
* @brief Turn on display backlight
*
* Display must be already initialized by calling bsp_display_new()
*
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t bsp_display_backlight_on(void);

/**
* @brief Turn off display backlight
*
* Display must be already initialized by calling bsp_display_new()
*
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t bsp_display_backlight_off(void);

#ifdef __cplusplus
}
#endif
98 changes: 98 additions & 0 deletions include/draw_eink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <cmath>

#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>

#define USE_HSPI_FOR_EPD
#define ENABLE_GxEPD2_GFX 0

#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
#define GxEPD2_DRIVER_CLASS GxEPD2_420_M01

#define GxEPD2_BW_IS_GxEPD2_BW true
#define GxEPD2_3C_IS_GxEPD2_3C true
#define GxEPD2_7C_IS_GxEPD2_7C true
#define GxEPD2_1248_IS_GxEPD2_1248 true
#define IS_GxEPD(c, x) (c##x)
#define IS_GxEPD2_BW(x) IS_GxEPD(GxEPD2_BW_IS_, x)
#define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
#define IS_GxEPD2_7C(x) IS_GxEPD(GxEPD2_7C_IS_, x)
#define IS_GxEPD2_1248(x) IS_GxEPD(GxEPD2_1248_IS_, x)

/**
* Setup the display.
*/
void setup_display_eink();

/**
* Power off the display.
*/
void power_off_display_eink();

/**
* Clear the display.
*/
void clear_display_eink();

/**
* Draw speed in knots.
*
* @param speed
*/
void draw_speed_eink(float speed);

/**
* Draw top status bar.
*/
void draw_top_bar_eink();

/**
* Draw bottom status bar.
*/
void draw_bottom_bar_eink();

/**
* Draw status text.
*
* @param text
*/
void draw_status_eink(String text);

/**
* Clear status text area.
*/
void clear_status_eink();

/**
* Draw battery capacity indicator.
*
* @param percentage Battery capacity.
*/
void draw_battery_status_eink(int percentage);

/**
* Draw time.
*
* @param hours
* @param minutes
* @param seconds
*/
void draw_time_eink(int hours, int minutes, int seconds);

/**
* Draw units.
*
* @param text
*/
void draw_units_eink(String text);

/**
* Draw rectangle on the screen.
*
* @param x Start point X coordinate.
* @param y Start point Y coordinate.
* @param w Width of the rectangle.
* @param h Height of the rectangle.
* @param partial Partial or full screen draw.
*/
void draw_box_eink(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial);
Loading

1 comment on commit 1f9c6c2

@GthiN89
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.