Skip to content

Commit

Permalink
1.update 3rdparty lvgl
Browse files Browse the repository at this point in the history
2.add theme example

3.update ugfx FreeRTOS adaptation

4.add input device calibrate, and add xpt2046 spi mutex semaphore

5.Update indev_drv.read function avoid can't click widget.

6.add roller action that switch the theme while the program is running

7.add vTaskDelay after xTimerStart to avoid 'error'
  • Loading branch information
mingfu authored and InfiniteYuan committed Oct 24, 2018
1 parent c4365b0 commit 059e0b4
Show file tree
Hide file tree
Showing 23 changed files with 1,187 additions and 179 deletions.
3 changes: 2 additions & 1 deletion components/hmi/gdrivers/gdisp/ILI9341/ILI9341_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void ex_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_
lcd_obj->drawBitmap((int16_t)x1, (int16_t)y1, (const uint16_t *)color_p, (int16_t)(x2 - x1 + 1), (int16_t)(y2 - y1 + 1));
}

void lvgl_lcd_display_init()
lv_disp_drv_t lvgl_lcd_display_init()
{
/*Initialize LCD*/
lcd_conf_t lcd_pins = {
Expand Down Expand Up @@ -285,6 +285,7 @@ void lvgl_lcd_display_init()

/* Finally register the driver */
lv_disp_drv_register(&disp_drv);
return disp_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
3 changes: 2 additions & 1 deletion components/hmi/gdrivers/gdisp/NT35510/NT35510_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void ex_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_
iot_nt35510_draw_bmp(nt35510_handle, (uint16_t *)color_p, (uint16_t)x1, (uint16_t)y1, (uint16_t)(x2 - x1 + 1), (uint16_t)(y2 - y1 + 1));
}

void lvgl_lcd_display_init()
lv_disp_drv_t lvgl_lcd_display_init()
{
/*Initialize LCD*/
i2s_lcd_config_t i2s_lcd_pin_conf = {
Expand Down Expand Up @@ -247,6 +247,7 @@ void lvgl_lcd_display_init()

/* Finally register the driver */
lv_disp_drv_register(&disp_drv);
return disp_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
3 changes: 2 additions & 1 deletion components/hmi/gdrivers/gdisp/SSD1306/SSD1306_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void ex_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_
lcd_obj->draw_bitmap((uint8_t)x1, (uint8_t)y1, (uint8_t *)color_p, (uint8_t)(x2 - x1 + 1), (uint8_t)(y2 - y1 + 1));
}

void lvgl_lcd_display_init()
lv_disp_drv_t lvgl_lcd_display_init()
{
/*Initialize LCD*/
i2c_bus = new CI2CBus((i2c_port_t)CONFIG_LVGL_LCD_IIC_NUM, (gpio_num_t)CONFIG_LVGL_LCD_SCL_GPIO, (gpio_num_t)CONFIG_LVGL_LCD_SDA_GPIO);
Expand All @@ -192,6 +192,7 @@ void lvgl_lcd_display_init()

/* Finally register the driver */
lv_disp_drv_register(&disp_drv);
return disp_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
3 changes: 2 additions & 1 deletion components/hmi/gdrivers/gdisp/ST7789/ST7789_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void ex_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_
lcd_obj->drawBitmap((int16_t)x1, (int16_t)y1, (const uint16_t *)color_p, (int16_t)(x2 - x1 + 1), (int16_t)(y2 - y1 + 1));
}

void lvgl_lcd_display_init()
lv_disp_drv_t lvgl_lcd_display_init()
{
/*Initialize LCD*/
lcd_conf_t lcd_pins = {
Expand Down Expand Up @@ -277,6 +277,7 @@ void lvgl_lcd_display_init()

/* Finally register the driver */
lv_disp_drv_register(&disp_drv);
return disp_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
58 changes: 35 additions & 23 deletions components/hmi/gdrivers/ginput/FT5X06/lvgl_indev_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include "iot_i2c_bus.h"

/* lvgl includes */
#include "lvgl_indev_config.h"
#include "iot_lvgl.h"

/* lvgl calibration includes */
#include "lv_calibration.h"

/* FT5x06 Include */
#include "FT5x06.h"

Expand Down Expand Up @@ -59,42 +61,51 @@ static uint16_t read_word(uint8_t reg)
}

/*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
bool ex_tp_read(lv_indev_data_t *data)
static bool ex_tp_read(lv_indev_data_t *data)
{
int16_t t;
static lv_coord_t x = 0xFFFF, y = 0xFFFF;
data->state = LV_INDEV_STATE_REL;
// please be sure that your touch driver every time return old (last clcked) value.
data->point.x = x;
data->point.y = y;
// Only take a reading if we are touched.
if ((read_byte(FT5x06_TOUCH_POINTS) & 0x07)) {

/* Get the X, Y, values */
data->point.x = (int16_t)(read_word(FT5x06_TOUCH1_XH) & 0x0fff);
data->point.y = (int16_t)read_word(FT5x06_TOUCH1_YH);
data->point.x = (lv_coord_t)(read_word(FT5x06_TOUCH1_XH) & 0x0fff);
data->point.y = (lv_coord_t)read_word(FT5x06_TOUCH1_YH);
data->state = LV_INDEV_STATE_PR;

// Rescale X,Y if we are using self-calibration

#ifdef CONFIG_LVGL_DISP_ROTATE_0
data->point.x = data->point.x;
data->point.y = data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_90)
t = data->point.x;
data->point.x = LV_HOR_RES - 1 - data->point.y;
data->point.y = t;
#elif defined(CONFIG_LVGL_DISP_ROTATE_180)
data->point.x = LV_HOR_RES - 1 - data->point.x;
data->point.y = LV_VER_RES - 1 - data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_270)
t = data->point.y;
data->point.y = LV_VER_RES - 1 - data->point.x;
data->point.x = t;
#endif
// Apply calibration, rotation
// Transform the co-ordinates
if (lvgl_calibration_transform(&(data->point))) {
lv_coord_t t;
// Rescale X,Y if we are using self-calibration
#ifdef CONFIG_LVGL_DISP_ROTATE_0
data->point.x = data->point.x;
data->point.y = data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_90)
t = data->point.x;
data->point.x = LV_HOR_RES - 1 - data->point.y;
data->point.y = t;
#elif defined(CONFIG_LVGL_DISP_ROTATE_180)
data->point.x = LV_HOR_RES - 1 - data->point.x;
data->point.y = LV_VER_RES - 1 - data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_270)
t = data->point.y;
data->point.y = LV_VER_RES - 1 - data->point.x;
data->point.x = t;
#endif
x = data->point.x;
y = data->point.y;
}
}
return false;
}

/* Input device interface */
/* Initialize your touchpad */
void lvgl_indev_init()
lv_indev_drv_t lvgl_indev_init()
{
i2c_bus_handle_t i2c_bus = NULL;
i2c_config_t conf = {
Expand Down Expand Up @@ -143,6 +154,7 @@ void lvgl_indev_init()
indev_drv.read = ex_tp_read; /*Library ready your touchpad via this function*/

lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
return indev_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
158 changes: 37 additions & 121 deletions components/hmi/gdrivers/ginput/XPT2046/XPT2046_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,123 +78,48 @@ int board_touch_get_position(int port)
/* lvgl include */
#include "lvgl_indev_config.h"

static const char *TAG = "TOUCH_SCREEN";

//calibration parameters
float xFactor, yFactor;
int _offset_x, _offset_y;
int m_width, m_height;
// #define NEED_CALI

void touch_calibration(int width, int height, int rotation)
{
uint16_t px[2], py[2], xPot[4], yPot[4];

m_width = width;
m_height = height;

ESP_LOGD(TAG, "please input top-left button...");

while (!xpt->is_pressed()) {
vTaskDelay(50 / portTICK_RATE_MS);
};
xPot[0] = xpt->get_raw_position().x;
yPot[0] = xpt->get_raw_position().y;
ESP_LOGD(TAG, "X:%d; Y:%d.", xPot[0], yPot[0]);

vTaskDelay(500 / portTICK_RATE_MS);
ESP_LOGD(TAG, "please input top-right button...");

while (!xpt->is_pressed()) {
vTaskDelay(50 / portTICK_RATE_MS);
};
xPot[1] = xpt->get_raw_position().x;
yPot[1] = xpt->get_raw_position().y;
ESP_LOGD(TAG, "X:%d; Y:%d.", xPot[1], yPot[1]);

vTaskDelay(500 / portTICK_RATE_MS);
ESP_LOGD(TAG, "please input bottom-right button...");

while (!xpt->is_pressed()) {
vTaskDelay(50 / portTICK_RATE_MS);
};
xPot[2] = xpt->get_raw_position().x;
yPot[2] = xpt->get_raw_position().y;
ESP_LOGD(TAG, "X:%d; Y:%d.", xPot[2], yPot[2]);

vTaskDelay(500 / portTICK_RATE_MS);
ESP_LOGD(TAG, "please input bottom-left button...");

while (!xpt->is_pressed()) {
vTaskDelay(50 / portTICK_RATE_MS);
};
xPot[3] = xpt->get_raw_position().x;
yPot[3] = xpt->get_raw_position().y;
ESP_LOGD(TAG, "X:%d; Y:%d.", xPot[3], yPot[3]);

px[0] = (xPot[0] + xPot[1]) / 2;
py[0] = (yPot[0] + yPot[3]) / 2;

px[1] = (xPot[2] + xPot[3]) / 2;
py[1] = (yPot[2] + yPot[1]) / 2;
ESP_LOGD(TAG, "X:%d; Y:%d.", px[0], py[0]);
ESP_LOGD(TAG, "X:%d; Y:%d.", px[1], py[1]);

xFactor = (float)m_height / (px[1] - px[0]);
yFactor = (float)m_width / (py[1] - py[0]);

_offset_x = (int16_t)m_height - ((float)px[1] * xFactor);
_offset_y = (int16_t)m_width - ((float)py[1] * yFactor);

ESP_LOGD(TAG, "xFactor:%f, yFactor:%f, Offset X:%d; Y:%d.", xFactor, yFactor, _offset_x, _offset_y);
}

position get_screen_position(position pos)
{
position m_pos;
int x = _offset_x + pos.x * xFactor;
int y = _offset_y + pos.y * yFactor;

if (x > m_height) {
x = m_height;
} else if (x < 0) {
x = 0;
}
if (y > m_width) {
y = m_width;
} else if (y < 0) {
y = 0;
}

#ifdef CONFIG_LVGL_DISP_ROTATE_0
m_pos.x = LV_HOR_RES - x;
m_pos.y = y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_90)
m_pos.x = LV_HOR_RES - y;
m_pos.y = LV_VER_RES - x;
#elif defined(CONFIG_LVGL_DISP_ROTATE_180)
m_pos.x = x;
m_pos.y = LV_VER_RES - y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_270)
m_pos.x = y;
m_pos.y = x;
#endif

return m_pos;
}

/*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
bool ex_tp_read(lv_indev_data_t *data)
static bool ex_tp_read(lv_indev_data_t *data)
{
data->state = xpt->is_pressed() ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
position pos = get_screen_position(xpt->get_raw_position());
data->point.x = pos.x;
data->point.y = pos.y;
static lv_coord_t x = 0xFFFF, y = 0xFFFF;
data->state = LV_INDEV_STATE_REL;
// please be sure that your touch driver every time return old (last clcked) value.
data->point.x = x;
data->point.y = y;
if (xpt->is_pressed()) {
position pos = xpt->get_raw_position();
data->point.x = pos.x;
data->point.y = pos.y;
data->state = LV_INDEV_STATE_PR;
// Apply calibration, rotation
// Transform the co-ordinates
if (lvgl_calibration_transform(&(data->point))) {
lv_coord_t t;
// Rescale X,Y if we are using self-calibration
#ifdef CONFIG_LVGL_DISP_ROTATE_0
data->point.x = data->point.x;
data->point.y = data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_90)
t = data->point.x;
data->point.x = LV_HOR_RES - 1 - data->point.y;
data->point.y = t;
#elif defined(CONFIG_LVGL_DISP_ROTATE_180)
data->point.x = LV_HOR_RES - 1 - data->point.x;
data->point.y = LV_VER_RES - 1 - data->point.y;
#elif defined(CONFIG_LVGL_DISP_ROTATE_270)
t = data->point.y;
data->point.y = LV_VER_RES - 1 - data->point.x;
data->point.x = t;
#endif
x = data->point.x;
y = data->point.y;
}
}
return false;
}

/* Input device interface,Initialize your touchpad */
void lvgl_indev_init()
lv_indev_drv_t lvgl_indev_init()
{
xpt_conf_t xpt_conf = {
.pin_num_cs = CONFIG_LVGL_TOUCH_CS_GPIO, /*!<SPI Chip Select Pin*/
Expand All @@ -211,16 +136,6 @@ void lvgl_indev_init()
if (xpt == NULL) {
xpt = new CTouchAdapter(&xpt_conf, 0);
}
#ifdef NEED_CALI
touch_calibration(320, 240, 1);
#else
xFactor = 0.070651;
yFactor = 0.089435;
_offset_x = -17;
_offset_y = -26;
m_width = 320;
m_height = 240;
#endif

lv_indev_drv_t indev_drv; /*Descriptor of an input device driver*/
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
Expand All @@ -229,6 +144,7 @@ void lvgl_indev_init()
indev_drv.read = ex_tp_read; /*Library ready your touchpad via this function*/

lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
return indev_drv;
}

#endif /* CONFIG_LVGL_GUI_ENABLE */
2 changes: 1 addition & 1 deletion components/hmi/gdrivers/include/lvgl_disp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C"
/**
* @brief Initialize display
*/
void lvgl_lcd_display_init();
lv_disp_drv_t lvgl_lcd_display_init();

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion components/hmi/gdrivers/include/lvgl_indev_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C"
/**
* @brief Initialize input device
*/
void lvgl_indev_init();
lv_indev_drv_t lvgl_indev_init();

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions components/hmi/lvgl_gui/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COMPONENT_SRCDIRS := . \
$(LVGLLIB)/lv_draw \
$(LVGLLIB)/lv_hal \
$(LVGLLIB)/lv_misc \
$(LVGLLIB)/lv_misc/lv_fonts \
$(LVGLLIB)/lv_fonts \
$(LVGLLIB)/lv_objx \
$(LVGLLIB)/lv_themes \

Expand All @@ -27,7 +27,7 @@ COMPONENT_ADD_INCLUDEDIRS := . \
$(LVGLLIB)/lv_draw \
$(LVGLLIB)/lv_hal \
$(LVGLLIB)/lv_misc \
$(LVGLLIB)/lv_misc/lv_fonts \
$(LVGLLIB)/lv_fonts \
$(LVGLLIB)/lv_objx \
$(LVGLLIB)/lv_themes \

Expand All @@ -38,7 +38,7 @@ COMPONENT_PRIV_INCLUDEDIRS += . \
$(LVGLLIB)/lv_draw \
$(LVGLLIB)/lv_hal \
$(LVGLLIB)/lv_misc \
$(LVGLLIB)/lv_misc/lv_fonts \
$(LVGLLIB)/lv_fonts \
$(LVGLLIB)/lv_objx \
$(LVGLLIB)/lv_themes \

Expand Down
Loading

0 comments on commit 059e0b4

Please sign in to comment.