graphics/lvgl: Upgrade to lvgl v8 version
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
parent
542558f2c1
commit
a610b633d2
@ -12,104 +12,12 @@ menuconfig EXAMPLES_LVGLDEMO
|
||||
|
||||
if EXAMPLES_LVGLDEMO
|
||||
|
||||
config EXAMPLES_LVGLDEMO_BUFF_SIZE
|
||||
int "Display buffer size (in line)"
|
||||
default 20
|
||||
|
||||
config EXAMPLES_LVGLDEMO_DOUBLE_BUFFERING
|
||||
bool "Enable double buffering"
|
||||
default n
|
||||
---help---
|
||||
When double buffering is enabled, LVGL expects the size of both
|
||||
buffers as:
|
||||
CONFIG_LV_HOR_RES * CONFIG_EXAMPLES_LVGLDEMO_BUFF_SIZE.
|
||||
True double buffering support is enabled if both buffers have the
|
||||
same dimensions as the display device resolution. Otherwise,
|
||||
LVGL will perform a number of partial refreshes according to the
|
||||
defined buffer size.
|
||||
|
||||
config EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
bool "Flush the display buffer asynchronously"
|
||||
default n
|
||||
---help---
|
||||
Enable this option to perform an asynchronous write of the buffer
|
||||
contents to the display device.
|
||||
|
||||
choice
|
||||
prompt "Select a demo application"
|
||||
default EXAMPLES_LVGLDEMO_WIDGETS
|
||||
|
||||
config EXAMPLES_LVGLDEMO_BENCHMARK
|
||||
bool "Benchmark"
|
||||
|
||||
config EXAMPLES_LVGLDEMO_PRINTER
|
||||
bool "Printer"
|
||||
---help---
|
||||
This demo is optimized for 800 * 480 resolution
|
||||
|
||||
config EXAMPLES_LVGLDEMO_STRESS
|
||||
bool "Stress"
|
||||
|
||||
config EXAMPLES_LVGLDEMO_WIDGETS
|
||||
bool "Widgets"
|
||||
|
||||
endchoice
|
||||
|
||||
if EXAMPLES_LVGLDEMO_WIDGETS
|
||||
|
||||
config EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW
|
||||
bool "Enable Slideshow mode for Widgets example"
|
||||
default n
|
||||
---help---
|
||||
Slideshow mode consists of a non-interactive demonstration of the
|
||||
Widgets example.
|
||||
|
||||
endif # EXAMPLES_LVGLDEMO_WIDGETS
|
||||
|
||||
config EXAMPLES_LVGLDEMO_PRIORITY
|
||||
int "lvgl task priority"
|
||||
int "lvgldemo task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_LVGLDEMO_STACKSIZE
|
||||
int "lvgldemo stack size"
|
||||
default 16384
|
||||
|
||||
comment "Input configuration options"
|
||||
depends on INPUT_TOUCHSCREEN || INPUT_MOUSE
|
||||
|
||||
config EXAMPLES_LVGLDEMO_CALIBRATE
|
||||
bool "Calibrate touchscreen"
|
||||
default y
|
||||
depends on INPUT_TOUCHSCREEN || INPUT_MOUSE
|
||||
---help---
|
||||
Calibrate touchscreen before demo start, but some touchscreen
|
||||
don't need it, like capacitive touchscreen.
|
||||
|
||||
if INPUT_TOUCHSCREEN
|
||||
|
||||
config EXAMPLES_LVGLDEMO_MINOR
|
||||
int "Touchscreen minor device number"
|
||||
default 0
|
||||
---help---
|
||||
The minor device number. Minor=N corresponds to touchscreen device
|
||||
/dev/inputN. Note this value must with EXAMPLES_LVGLDEMO_DEVPATH.
|
||||
Default 0.
|
||||
|
||||
config EXAMPLES_LVGLDEMO_DEVPATH
|
||||
string "Touchscreen device path"
|
||||
default "/dev/input0"
|
||||
---help---
|
||||
The path to the touchscreen device. This must be consistent with
|
||||
EXAMPLES_LVGLDEMO_MINOR. Default: "/dev/input0"
|
||||
|
||||
endif # INPUT_TOUCHSCREEN
|
||||
|
||||
config EXAMPLES_LVGLDEMO_MOUSE
|
||||
bool "Mouse interface"
|
||||
default n
|
||||
depends on INPUT_MOUSE
|
||||
---help---
|
||||
The LittleVGL demo can also be configured to work with a mouse
|
||||
driver by setting this option.
|
||||
|
||||
endif # EXAMPLES_LVGLDEMO
|
||||
|
@ -20,80 +20,13 @@
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# LittleVGL demo built-in application info
|
||||
|
||||
CONFIG_LV_EXAMPLES_URL ?= https://github.com/lvgl/lv_demos/archive
|
||||
|
||||
LVGL_EXAMPLES_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LVGL_VERSION)))
|
||||
LVGL_EXAMPLES_TARBALL = v$(LVGL_EXAMPLES_VERSION).zip
|
||||
|
||||
LVGL_EXAMPLES_UNPACKNAME = lv_demos
|
||||
UNPACK ?= unzip -o
|
||||
|
||||
PROGNAME = lvgldemo
|
||||
PRIORITY = $(CONFIG_EXAMPLES_LVGLDEMO_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_LVGLDEMO_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_LVGLDEMO)
|
||||
|
||||
# LittleVGL demo Example
|
||||
|
||||
CSRCS += fbdev.c lcddev.c
|
||||
|
||||
ifneq ($(CONFIG_INPUT_TOUCHSCREEN)$(CONFIG_INPUT_MOUSE),)
|
||||
CSRCS += tp.c tp_cal.c
|
||||
endif
|
||||
|
||||
# static common assets used in multiple examples
|
||||
|
||||
LV_EXAMPLE_ASSETS = $(wildcard ./lv_demos/assets/*.c)
|
||||
CSRCS += $(notdir $(LV_EXAMPLE_ASSETS))
|
||||
VPATH += lv_demos/assets
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_BENCHMARK),)
|
||||
CSRCS += lv_demo_benchmark.c
|
||||
VPATH += lv_demos/src/lv_demo_benchmark
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_PRINTER),)
|
||||
LV_PRINTER_IMAGES = $(wildcard ./lv_demos/src/lv_demo_printer/images/*.c)
|
||||
CSRCS += lv_demo_printer.c lv_demo_printer_theme.c
|
||||
CSRCS += $(notdir $(LV_PRINTER_IMAGES))
|
||||
VPATH += lv_demos/src/lv_demo_printer
|
||||
VPATH += lv_demos/src/lv_demo_printer/images
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_STRESS),)
|
||||
CSRCS += lv_demo_stress.c
|
||||
VPATH += lv_demos/src/lv_demo_stress
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_WIDGETS),)
|
||||
CSRCS += lv_demo_widgets.c
|
||||
VPATH += lv_demos/src/lv_demo_widgets
|
||||
endif
|
||||
# LVGL demo Example
|
||||
|
||||
MAINSRC = lvgldemo.c
|
||||
|
||||
CFLAGS += ${DEFINE_PREFIX}LV_LVGL_H_INCLUDE_SIMPLE -Wno-format
|
||||
CXXFLAGS += ${DEFINE_PREFIX}LV_LVGL_H_INCLUDE_SIMPLE -Wno-format
|
||||
|
||||
$(LVGL_EXAMPLES_TARBALL):
|
||||
$(Q) echo "Downloading: $(LVGL_EXAMPLES_TARBALL)"
|
||||
$(Q) curl -O -L $(CONFIG_LV_EXAMPLES_URL)/$(LVGL_EXAMPLES_TARBALL)
|
||||
|
||||
$(LVGL_EXAMPLES_UNPACKNAME): $(LVGL_EXAMPLES_TARBALL)
|
||||
$(Q) echo "Unpacking: $(LVGL_EXAMPLES_TARBALL) -> $(LVGL_EXAMPLES_UNPACKNAME)"
|
||||
$(Q) $(UNPACK) $(LVGL_EXAMPLES_TARBALL)
|
||||
$(Q) mv lv_demos-$(LVGL_EXAMPLES_VERSION) $(LVGL_EXAMPLES_UNPACKNAME)
|
||||
$(Q) touch $(LVGL_EXAMPLES_UNPACKNAME)
|
||||
|
||||
# Download and unpack tarball if no git repo found
|
||||
ifeq ($(wildcard $(LVGL_EXAMPLES_UNPACKNAME)/.git),)
|
||||
context:: $(LVGL_EXAMPLES_UNPACKNAME)
|
||||
|
||||
distclean::
|
||||
$(call DELDIR, $(LVGL_EXAMPLES_UNPACKNAME))
|
||||
$(call DELFILE, $(LVGL_EXAMPLES_TARBALL))
|
||||
endif
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
@ -1,469 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/fbdev.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "fbdev.h"
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/video/rgbcolors.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef FBDEV_PATH
|
||||
# define FBDEV_PATH "/dev/fb0"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct fb_state_s
|
||||
{
|
||||
int fd;
|
||||
struct fb_videoinfo_s vinfo;
|
||||
struct fb_planeinfo_s pinfo;
|
||||
FAR void *fbmem;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct fb_state_s state;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
static pthread_t fb_write_thread;
|
||||
static sem_t flush_sem;
|
||||
static sem_t wait_sem;
|
||||
|
||||
static lv_area_t lv_area;
|
||||
static lv_color_t *lv_color_p;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_wait
|
||||
*
|
||||
* Description:
|
||||
* Wait for the flushing operation conclusion to notify LVGL.
|
||||
*
|
||||
* Input Parameters:
|
||||
* disp_drv - LVGL driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static void fbdev_wait(lv_disp_drv_t *disp_drv)
|
||||
{
|
||||
sem_wait(&wait_sem);
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_flush_internal
|
||||
*
|
||||
* Description:
|
||||
* Write the buffer to Framebuffer interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* area - Area of the screen to be flushed
|
||||
* color_p - A n array of colors
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int fbdev_flush_internal(const lv_area_t *area, lv_color_t *color_p)
|
||||
{
|
||||
#ifdef CONFIG_FB_UPDATE
|
||||
struct fb_area_s fb_area;
|
||||
#endif
|
||||
int32_t x1 = area->x1;
|
||||
int32_t y1 = area->y1;
|
||||
int32_t x2 = area->x2;
|
||||
int32_t y2 = area->y2;
|
||||
int32_t act_x1;
|
||||
int32_t act_y1;
|
||||
int32_t act_x2;
|
||||
int32_t act_y2;
|
||||
long int location = 0;
|
||||
|
||||
if (state.fbmem == NULL)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Return if the area is out the screen */
|
||||
|
||||
if (x2 < 0)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (y2 < 0)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (x1 > state.vinfo.xres - 1)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (y1 > state.vinfo.yres - 1)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Truncate the area to the screen */
|
||||
|
||||
act_x1 = x1 < 0 ? 0 : x1;
|
||||
act_y1 = y1 < 0 ? 0 : y1;
|
||||
act_x2 = x2 > state.vinfo.xres - 1 ? state.vinfo.xres - 1 : x2;
|
||||
act_y2 = y2 > state.vinfo.yres - 1 ? state.vinfo.yres - 1 : y2;
|
||||
|
||||
if (state.pinfo.bpp == 8)
|
||||
{
|
||||
uint8_t *fbp8 = (uint8_t *)state.fbmem;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
|
||||
for (y = act_y1; y <= act_y2; y++)
|
||||
{
|
||||
for (x = act_x1; x <= act_x2; x++)
|
||||
{
|
||||
location = x + (y * state.vinfo.xres);
|
||||
fbp8[location] = color_p->full;
|
||||
color_p++;
|
||||
}
|
||||
|
||||
color_p += x2 - act_x2;
|
||||
}
|
||||
}
|
||||
|
||||
if (state.pinfo.bpp == 16)
|
||||
{
|
||||
uint16_t *fbp16 = (uint16_t *)state.fbmem;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
|
||||
for (y = act_y1; y <= act_y2; y++)
|
||||
{
|
||||
for (x = act_x1; x <= act_x2; x++)
|
||||
{
|
||||
location = x + (y * state.vinfo.xres);
|
||||
fbp16[location] = color_p->full;
|
||||
color_p++;
|
||||
}
|
||||
|
||||
color_p += x2 - act_x2;
|
||||
}
|
||||
}
|
||||
|
||||
if (state.pinfo.bpp == 24 || state.pinfo.bpp == 32)
|
||||
{
|
||||
uint32_t *fbp32 = (uint32_t *)state.fbmem;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
|
||||
for (y = act_y1; y <= act_y2; y++)
|
||||
{
|
||||
for (x = act_x1; x <= act_x2; x++)
|
||||
{
|
||||
location = x + (y * state.vinfo.xres);
|
||||
fbp32[location] = color_p->full;
|
||||
color_p++;
|
||||
}
|
||||
|
||||
color_p += x2 - act_x2;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FB_UPDATE
|
||||
fb_area.x = act_x1;
|
||||
fb_area.y = act_y1;
|
||||
fb_area.w = act_x2 - act_x1 + 1;
|
||||
fb_area.h = act_y2 - act_y1 + 1;
|
||||
ioctl(state.fd, FBIO_UPDATE, (unsigned long)((uintptr_t)&fb_area));
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_async_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush a buffer to the marked area asynchronously.
|
||||
*
|
||||
* Input Parameters:
|
||||
* disp_drv - LVGL driver interface
|
||||
* area - Area of the screen to be flushed
|
||||
* color_p - A n array of colors
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static void fbdev_async_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
||||
lv_color_t *color_p)
|
||||
{
|
||||
UNUSED(disp_drv);
|
||||
|
||||
lv_area.y1 = area->y1;
|
||||
lv_area.y2 = area->y2;
|
||||
lv_area.x1 = area->x1;
|
||||
lv_area.x2 = area->x2;
|
||||
|
||||
lv_color_p = color_p;
|
||||
|
||||
sem_post(&flush_sem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_sync_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush a buffer to the marked area synchronously.
|
||||
*
|
||||
* Input Parameters:
|
||||
* disp_drv - LVGL driver interface
|
||||
* area - Area of the screen to be flushed
|
||||
* color_p - A n array of colors
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static void fbdev_sync_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
||||
lv_color_t *color_p)
|
||||
{
|
||||
fbdev_flush_internal(area, color_p);
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_write
|
||||
*
|
||||
* Description:
|
||||
* Thread for writing the buffer to Framebuffer interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg - Context data from the parent thread
|
||||
*
|
||||
* Returned Value:
|
||||
* Context data to the parent thread
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static pthread_addr_t fbdev_write(pthread_addr_t arg)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
UNUSED(arg);
|
||||
|
||||
while (ret == OK)
|
||||
{
|
||||
sem_wait(&flush_sem);
|
||||
|
||||
ret = fbdev_flush_internal(&lv_area, lv_color_p);
|
||||
|
||||
sem_post(&wait_sem);
|
||||
}
|
||||
|
||||
gerr("Failed to write buffer contents to display device\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_init
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Input Parameters:
|
||||
* lv_drvr -- LVGL driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int fbdev_init(lv_disp_drv_t *lv_drvr)
|
||||
{
|
||||
FAR const char *fbdev = "/dev/fb0";
|
||||
int ret;
|
||||
|
||||
/* Open the framebuffer driver */
|
||||
|
||||
state.fd = open(fbdev, O_RDWR);
|
||||
if (state.fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
gerr("Failed to open %s: %d\n", fbdev, errcode);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the characteristics of the framebuffer */
|
||||
|
||||
ret = ioctl(state.fd, FBIOGET_VIDEOINFO,
|
||||
(unsigned long)((uintptr_t)&state.vinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
gerr("ioctl(FBIOGET_VIDEOINFO) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ginfo("VideoInfo:\n\tfmt: %u\n\txres: %u\n\tyres: %u\n\tnplanes: %u\n",
|
||||
state.vinfo.fmt, state.vinfo.xres, state.vinfo.yres,
|
||||
state.vinfo.nplanes);
|
||||
|
||||
ret = ioctl(state.fd, FBIOGET_PLANEINFO,
|
||||
(unsigned long)((uintptr_t)&state.pinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ginfo("PlaneInfo (plane 0):\n"
|
||||
"\tfbmem: %p\n\tfblen: %l\n\tstride: %u\n"
|
||||
"\tdisplay: %u\n\tbpp: %u\n\t",
|
||||
state.pinfo.fbmem, (unsigned long)state.pinfo.fblen,
|
||||
state.pinfo.stride, state.pinfo.display, state.pinfo.bpp);
|
||||
|
||||
lv_drvr->hor_res = state.vinfo.xres;
|
||||
lv_drvr->ver_res = state.vinfo.yres;
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
lv_drvr->flush_cb = fbdev_sync_flush;
|
||||
#else
|
||||
lv_drvr->flush_cb = fbdev_async_flush;
|
||||
lv_drvr->wait_cb = fbdev_wait;
|
||||
|
||||
/* Initialize the mutexes for buffer flushing synchronization */
|
||||
|
||||
sem_init(&flush_sem, 0, 0);
|
||||
sem_init(&wait_sem, 0, 0);
|
||||
|
||||
/* Initialize the buffer flushing thread */
|
||||
|
||||
pthread_create(&fb_write_thread, NULL, fbdev_write, NULL);
|
||||
#endif
|
||||
|
||||
/* Only these pixel depths are supported. viinfo.fmt is ignored, only
|
||||
* certain color formats are supported.
|
||||
*/
|
||||
|
||||
if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 &&
|
||||
state.pinfo.bpp != 8 && state.pinfo.bpp != 1)
|
||||
{
|
||||
gerr("bpp=%u not supported\n", state.pinfo.bpp);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* mmap() the framebuffer.
|
||||
*
|
||||
* NOTE: In the FLAT build the frame buffer address returned by the
|
||||
* FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer
|
||||
* address. mmap(), however, is the preferred way to get the framebuffer
|
||||
* address because in the KERNEL build, it will perform the necessary
|
||||
* address mapping to make the memory accessible to the application.
|
||||
*/
|
||||
|
||||
state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FILE, state.fd, 0);
|
||||
if (state.fbmem == MAP_FAILED)
|
||||
{
|
||||
int errcode = errno;
|
||||
gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ginfo("Mapped FB: %p\n", state.fbmem);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/fbdev.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_LVGLDEMO_FBDEV_H
|
||||
#define __APPS_EXAMPLES_LVGLDEMO_FBDEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int fbdev_init(lv_disp_drv_t *lv_drvr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APPS_EXAMPLES_LVGLDEMO_FBDEV_H */
|
@ -1,315 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/lcddev.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "lcddev.h"
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/lcd/lcd_dev.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef LCDDEV_PATH
|
||||
# define LCDDEV_PATH "/dev/lcd0"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct lcd_state_s
|
||||
{
|
||||
int fd;
|
||||
struct fb_videoinfo_s vinfo;
|
||||
struct lcd_planeinfo_s pinfo;
|
||||
bool rotated;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct lcd_state_s state;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
static pthread_t lcd_write_thread;
|
||||
static sem_t flush_sem;
|
||||
static sem_t wait_sem;
|
||||
static struct lcddev_area_s lcd_area;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_wait
|
||||
*
|
||||
* Description:
|
||||
* Wait for the flushing operation conclusion to notify LVGL.
|
||||
*
|
||||
* Input Parameters:
|
||||
* disp_drv - LVGL driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static void lcddev_wait(lv_disp_drv_t *disp_drv)
|
||||
{
|
||||
sem_wait(&wait_sem);
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush a buffer to the marked area.
|
||||
*
|
||||
* Input Parameters:
|
||||
* disp_drv - LVGL driver interface
|
||||
* lv_area_t - Area of the screen to be flushed
|
||||
* color_p - A n array of colors
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static void lcddev_async_flush(lv_disp_drv_t *disp_drv,
|
||||
const lv_area_t *area,
|
||||
lv_color_t *color_p)
|
||||
{
|
||||
UNUSED(disp_drv);
|
||||
|
||||
lcd_area.row_start = area->y1;
|
||||
lcd_area.row_end = area->y2;
|
||||
lcd_area.col_start = area->x1;
|
||||
lcd_area.col_end = area->x2;
|
||||
|
||||
lcd_area.data = (uint8_t *)color_p;
|
||||
|
||||
sem_post(&flush_sem);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void lcddev_sync_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
||||
lv_color_t *color_p)
|
||||
{
|
||||
int ret;
|
||||
struct lcddev_area_s lcd_area;
|
||||
|
||||
lcd_area.row_start = area->y1;
|
||||
lcd_area.row_end = area->y2;
|
||||
lcd_area.col_start = area->x1;
|
||||
lcd_area.col_end = area->x2;
|
||||
|
||||
lcd_area.data = (uint8_t *)color_p;
|
||||
|
||||
ret = ioctl(state.fd, LCDDEVIO_PUTAREA,
|
||||
(unsigned long)((uintptr_t)&lcd_area));
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
gerr("ioctl(LCDDEVIO_PUTAREA) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_write
|
||||
*
|
||||
* Description:
|
||||
* Write the buffer to LCD interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
|
||||
static pthread_addr_t lcddev_write(pthread_addr_t addr)
|
||||
{
|
||||
int ret = OK;
|
||||
int errcode;
|
||||
|
||||
while (ret == OK)
|
||||
{
|
||||
sem_wait(&flush_sem);
|
||||
ret = ioctl(state.fd, LCDDEVIO_PUTAREA, (unsigned long)&lcd_area);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
}
|
||||
|
||||
sem_post(&wait_sem);
|
||||
}
|
||||
|
||||
if (ret != OK)
|
||||
{
|
||||
gerr("ioctl(LCDDEVIO_PUTAREA) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize LCD device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lv_drvr -- LVGL driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* EXIT_SUCCESS on success; EXIT_FAILURE on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int lcddev_init(lv_disp_drv_t *lv_drvr)
|
||||
{
|
||||
FAR const char *lcddev = LCDDEV_PATH;
|
||||
int ret;
|
||||
|
||||
/* Open the framebuffer driver */
|
||||
|
||||
state.fd = open(lcddev, 0);
|
||||
if (state.fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
gerr("Failed to open %s: %d\n", state.fd, errcode);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the characteristics of the framebuffer */
|
||||
|
||||
ret = ioctl(state.fd, LCDDEVIO_GETVIDEOINFO,
|
||||
(unsigned long)((uintptr_t)&state.vinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
gerr("ioctl(LCDDEVIO_GETVIDEOINFO) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ginfo("VideoInfo:\n\tfmt: %u\n\txres: %u\n\tyres: %u\n\tnplanes: %u\n",
|
||||
state.vinfo.fmt, state.vinfo.xres, state.vinfo.yres,
|
||||
state.vinfo.nplanes);
|
||||
|
||||
ret = ioctl(state.fd, LCDDEVIO_GETPLANEINFO,
|
||||
(unsigned long)((uintptr_t)&state.pinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
gerr("ioctl(LCDDEVIO_GETPLANEINFO) failed: %d\n", errcode);
|
||||
close(state.fd);
|
||||
state.fd = -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ginfo("PlaneInfo (plane 0):\n\tbpp: %u\n", state.pinfo.bpp);
|
||||
|
||||
if (state.pinfo.bpp != CONFIG_LV_COLOR_DEPTH)
|
||||
{
|
||||
/* For the LCD driver we do not have a great way to translate this
|
||||
* so fail to initialize.
|
||||
*/
|
||||
|
||||
gerr("Display bpp (%u) did not match CONFIG_LV_COLOR_DEPTH (%u)\n",
|
||||
state.pinfo.bpp, CONFIG_LV_COLOR_DEPTH);
|
||||
}
|
||||
|
||||
lv_drvr->hor_res = state.vinfo.xres;
|
||||
lv_drvr->ver_res = state.vinfo.yres;
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
||||
lv_drvr->flush_cb = lcddev_sync_flush;
|
||||
#else
|
||||
lv_drvr->flush_cb = lcddev_async_flush;
|
||||
lv_drvr->wait_cb = lcddev_wait;
|
||||
|
||||
/* Initialize the mutexes for buffer flushing synchronization */
|
||||
|
||||
sem_init(&flush_sem, 0, 0);
|
||||
sem_init(&wait_sem, 0, 0);
|
||||
|
||||
/* Initialize the buffer flushing thread */
|
||||
|
||||
pthread_create(&lcd_write_thread, NULL, lcddev_write, NULL);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/lv_ex_conf.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H
|
||||
#define __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Enable printf-ing data in demoes and examples */
|
||||
|
||||
#define LV_EX_PRINTF 1
|
||||
|
||||
/* Add PC keyboard support to some examples
|
||||
* (`lv_drivers` repository is required)
|
||||
*/
|
||||
|
||||
#define LV_EX_KEYBOARD 0
|
||||
|
||||
/* Add 'encoder' (mouse wheel) support to some examples
|
||||
* (`lv_drivers` repository is required)
|
||||
*/
|
||||
|
||||
#define LV_EX_MOUSEWHEEL 0
|
||||
|
||||
/* Show some widget */
|
||||
|
||||
#define LV_USE_DEMO_WIDGETS 1
|
||||
#if LV_USE_DEMO_WIDGETS
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW
|
||||
#define LV_DEMO_WIDGETS_SLIDESHOW CONFIG_EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW
|
||||
#else
|
||||
#define LV_DEMO_WIDGETS_SLIDESHOW 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Printer demo, optimized for 800x480 */
|
||||
|
||||
#define LV_USE_DEMO_PRINTER 1
|
||||
|
||||
/* Demonstrate the usage of encoder and keyboard */
|
||||
|
||||
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 1
|
||||
|
||||
/* Benchmark your system */
|
||||
|
||||
#define LV_USE_DEMO_BENCHMARK 1
|
||||
|
||||
/* Stress test for LVGL */
|
||||
|
||||
#define LV_USE_DEMO_STRESS 1
|
||||
|
||||
#endif /* __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H */
|
||||
|
@ -28,18 +28,13 @@
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include "fbdev.h"
|
||||
#include "lcddev.h"
|
||||
|
||||
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
||||
#include "tp.h"
|
||||
#include "tp_cal.h"
|
||||
#endif
|
||||
#include <port/lv_port.h>
|
||||
#include <lvgl/demos/lv_demos.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -62,46 +57,99 @@
|
||||
# define NEED_BOARDINIT 1
|
||||
#endif
|
||||
|
||||
#define DISPLAY_BUFFER_SIZE (CONFIG_LV_HOR_RES * \
|
||||
CONFIG_EXAMPLES_LVGLDEMO_BUFF_SIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
void lv_demo_benchmark(void);
|
||||
void lv_demo_printer(void);
|
||||
void lv_demo_stress(void);
|
||||
void lv_demo_widgets(void);
|
||||
typedef CODE void (*demo_create_func_t)(void);
|
||||
|
||||
struct func_key_pair_s
|
||||
{
|
||||
FAR const char *name;
|
||||
demo_create_func_t func;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct func_key_pair_s func_key_pair[] =
|
||||
{
|
||||
#ifdef CONFIG_LV_USE_DEMO_WIDGETS
|
||||
{ "widgets", lv_demo_widgets },
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER
|
||||
{ "keypad_encoder", lv_demo_keypad_encoder },
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LV_USE_DEMO_BENCHMARK
|
||||
{ "benchmark", lv_demo_benchmark },
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LV_USE_DEMO_STRESS
|
||||
{ "stress", lv_demo_stress },
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LV_USE_DEMO_MUSIC
|
||||
{ "music", lv_demo_music },
|
||||
#endif
|
||||
{ "", NULL }
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: monitor_cb
|
||||
*
|
||||
* Description:
|
||||
* Monitoring callback from lvgl every time the screen is flushed.
|
||||
*
|
||||
* Name: show_usage
|
||||
****************************************************************************/
|
||||
|
||||
static void monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px)
|
||||
static void show_usage(void)
|
||||
{
|
||||
ginfo("%" PRIu32 " px refreshed in %" PRIu32 " ms\n", px, time);
|
||||
int i;
|
||||
const int len = sizeof(func_key_pair)
|
||||
/ sizeof(struct func_key_pair_s) - 1;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
printf("lvgldemo: no demo available!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nUsage: lvgldemo demo_name\n");
|
||||
printf("\ndemo_name:\n");
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
printf(" %s\n", func_key_pair[i].name);
|
||||
}
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
* Name: find_demo_create_func
|
||||
****************************************************************************/
|
||||
|
||||
static lv_color_t buffer1[DISPLAY_BUFFER_SIZE];
|
||||
static demo_create_func_t find_demo_create_func(FAR const char *name)
|
||||
{
|
||||
int i;
|
||||
const int len = sizeof(func_key_pair)
|
||||
/ sizeof(struct func_key_pair_s) - 1;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_DOUBLE_BUFFERING
|
||||
static lv_color_t buffer2[DISPLAY_BUFFER_SIZE];
|
||||
#else
|
||||
# define buffer2 NULL
|
||||
#endif
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (strcmp(name, func_key_pair[i].name) == 0)
|
||||
{
|
||||
return func_key_pair[i].func;
|
||||
}
|
||||
}
|
||||
|
||||
printf("lvgldemo: '%s' not found.\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -122,34 +170,21 @@ static lv_color_t buffer2[DISPLAY_BUFFER_SIZE];
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
lv_disp_drv_t disp_drv;
|
||||
lv_disp_buf_t disp_buf;
|
||||
demo_create_func_t demo_create_func;
|
||||
|
||||
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE
|
||||
lv_point_t p[4];
|
||||
if (argc != 2)
|
||||
{
|
||||
show_usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* top left */
|
||||
demo_create_func = find_demo_create_func(argv[1]);
|
||||
|
||||
p[0].x = 0;
|
||||
p[0].y = 0;
|
||||
|
||||
/* top right */
|
||||
|
||||
p[1].x = LV_HOR_RES;
|
||||
p[1].y = 0;
|
||||
|
||||
/* bottom left */
|
||||
|
||||
p[2].x = 0;
|
||||
p[2].y = LV_VER_RES;
|
||||
|
||||
/* bottom right */
|
||||
|
||||
p[3].x = LV_HOR_RES;
|
||||
p[3].y = LV_VER_RES;
|
||||
#endif
|
||||
#endif
|
||||
if (demo_create_func == NULL)
|
||||
{
|
||||
show_usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef NEED_BOARDINIT
|
||||
/* Perform board-specific driver initialization */
|
||||
@ -167,71 +202,25 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
lv_init();
|
||||
|
||||
/* Basic LVGL display driver initialization */
|
||||
/* LVGL port initialization */
|
||||
|
||||
lv_disp_buf_init(&disp_buf, buffer1, buffer2, DISPLAY_BUFFER_SIZE);
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.buffer = &disp_buf;
|
||||
disp_drv.monitor_cb = monitor_cb;
|
||||
lv_port_init();
|
||||
|
||||
/* Display interface initialization */
|
||||
/* LVGL demo creation */
|
||||
|
||||
if (fbdev_init(&disp_drv) != EXIT_SUCCESS)
|
||||
{
|
||||
/* Failed to use framebuffer falling back to lcd driver */
|
||||
|
||||
if (lcddev_init(&disp_drv) != EXIT_SUCCESS)
|
||||
{
|
||||
/* No possible drivers left, fail */
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
||||
/* Touchpad Initialization */
|
||||
|
||||
tp_init();
|
||||
lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
|
||||
/* This function will be called periodically (by the library) to get the
|
||||
* mouse position and state.
|
||||
*/
|
||||
|
||||
indev_drv.read_cb = tp_read;
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_LVGLDEMO_BENCHMARK)
|
||||
lv_demo_benchmark();
|
||||
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_PRINTER)
|
||||
lv_demo_printer();
|
||||
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_STRESS)
|
||||
lv_demo_stress();
|
||||
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_WIDGETS)
|
||||
lv_demo_widgets();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
||||
/* Start TP calibration */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE
|
||||
tp_cal_create();
|
||||
#else
|
||||
tp_set_cal_values(p, p + 1, p + 2, p + 3);
|
||||
#endif
|
||||
#endif
|
||||
demo_create_func();
|
||||
|
||||
/* Handle LVGL tasks */
|
||||
|
||||
while (1)
|
||||
{
|
||||
lv_task_handler();
|
||||
usleep(10000);
|
||||
uint32_t idle;
|
||||
idle = lv_timer_handler();
|
||||
|
||||
/* Minimum sleep of 1ms */
|
||||
|
||||
idle = idle ? idle : 1;
|
||||
usleep(idle * 1000);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -1,279 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/tp.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE
|
||||
# include <nuttx/input/mouse.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/input/touchscreen.h>
|
||||
|
||||
#include "tp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static int fd;
|
||||
static bool calibrated = false;
|
||||
static int x_range;
|
||||
static int y_range;
|
||||
static int x_offset;
|
||||
static int y_offset;
|
||||
static bool xy_inv;
|
||||
static bool x_inv;
|
||||
static bool y_inv;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize The Touch pad
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a positive error code on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int tp_init(void)
|
||||
{
|
||||
int errval = 0;
|
||||
|
||||
/* Open the touchscreen device for reading */
|
||||
|
||||
printf("tp_init: Opening %s\n", CONFIG_EXAMPLES_LVGLDEMO_DEVPATH);
|
||||
fd = open(CONFIG_EXAMPLES_LVGLDEMO_DEVPATH, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("tp_init: open %s failed: %d\n",
|
||||
CONFIG_EXAMPLES_LVGLDEMO_DEVPATH, errno);
|
||||
errval = 2;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
errout:
|
||||
printf("Terminating!\n");
|
||||
fflush(stdout);
|
||||
return errval;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_read
|
||||
*
|
||||
* Description:
|
||||
* Read a TP data and store in 'data' argument
|
||||
*
|
||||
* Input Parameters:
|
||||
* indev_drv - Input device handler
|
||||
* data - Store the x, y and state information here
|
||||
*
|
||||
* Returned Value:
|
||||
* false: no more data to read; true: there are more data to read.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool tp_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
|
||||
{
|
||||
struct touch_sample_s sample;
|
||||
int nbytes;
|
||||
static int last_x = 0;
|
||||
static int last_y = 0;
|
||||
static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
|
||||
|
||||
/* Be sure at least the previous state is set */
|
||||
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = last_state;
|
||||
|
||||
/* Read one sample */
|
||||
|
||||
nbytes = read(fd, &sample, sizeof(struct touch_sample_s));
|
||||
|
||||
/* Handle unexpected return values */
|
||||
|
||||
if (nbytes < 0 || nbytes != sizeof(struct touch_sample_s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sample.point[0].flags & TOUCH_DOWN
|
||||
|| sample.point[0].flags & TOUCH_MOVE)
|
||||
{
|
||||
if (calibrated)
|
||||
{
|
||||
if (xy_inv)
|
||||
{
|
||||
last_x = sample.point[0].y;
|
||||
last_y = sample.point[0].x;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_x = sample.point[0].x;
|
||||
last_y = sample.point[0].y;
|
||||
}
|
||||
|
||||
/* Remove offset */
|
||||
|
||||
last_x -= x_offset;
|
||||
last_y -= y_offset;
|
||||
|
||||
last_x = (int)((int)last_x * LV_HOR_RES) / x_range;
|
||||
last_y = (int)((int)last_y * LV_VER_RES) / y_range;
|
||||
|
||||
if (x_inv)
|
||||
{
|
||||
last_x = LV_HOR_RES - last_x;
|
||||
}
|
||||
|
||||
if (y_inv)
|
||||
{
|
||||
last_y = LV_VER_RES - last_y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_x = sample.point[0].x;
|
||||
last_y = sample.point[0].y;
|
||||
}
|
||||
|
||||
last_state = LV_INDEV_STATE_PR;
|
||||
}
|
||||
else if (sample.point[0].flags & TOUCH_UP)
|
||||
{
|
||||
last_state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
else if (sample.point[0].flags & TOUCH_UP)
|
||||
{
|
||||
last_state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/* Update touchpad data */
|
||||
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = last_state;
|
||||
|
||||
fflush(stdout);
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_read
|
||||
*
|
||||
* Description:
|
||||
* Set calibration data
|
||||
*
|
||||
* Input Parameters:
|
||||
* ul - Upper left hand corner TP value
|
||||
* ur - Upper right hand corner TP value
|
||||
* lr - Lower right hand corner TP value
|
||||
* ll - Lower left hand corner TP value
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tp_set_cal_values(FAR lv_point_t *ul, FAR lv_point_t *ur,
|
||||
FAR lv_point_t *lr, FAR lv_point_t *ll)
|
||||
{
|
||||
/* Is x/y inverted? */
|
||||
|
||||
if (abs(ul->x - ur->x) < LV_HOR_RES / 2)
|
||||
{
|
||||
/* No real change in x horizontally */
|
||||
|
||||
xy_inv = true;
|
||||
}
|
||||
|
||||
if (xy_inv)
|
||||
{
|
||||
/* Is x inverted */
|
||||
|
||||
if (ur->y < ul->y)
|
||||
{
|
||||
x_inv = true;
|
||||
}
|
||||
|
||||
/* Is y inverted */
|
||||
|
||||
if (ll->x < ul->x)
|
||||
{
|
||||
y_inv = true;
|
||||
}
|
||||
|
||||
x_range = abs(ul->y - ur->y);
|
||||
y_range = abs(ul->x - ll->x);
|
||||
x_offset = x_inv ? ur->y : ul->y;
|
||||
y_offset = y_inv ? ll->x : ul->x;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Is x inverted */
|
||||
|
||||
if (ur->x < ul->x)
|
||||
{
|
||||
x_inv = true;
|
||||
}
|
||||
|
||||
/* Is y inverted */
|
||||
|
||||
if (ll->y < ul->y)
|
||||
{
|
||||
y_inv = true;
|
||||
}
|
||||
|
||||
x_range = abs(ul->x - ur->x);
|
||||
y_range = abs(ul->y - ll->y);
|
||||
x_offset = x_inv ? ur->x : ul->x;
|
||||
y_offset = y_inv ? ll->y : ul->y;
|
||||
}
|
||||
|
||||
calibrated = true;
|
||||
|
||||
printf("tp_cal result\n");
|
||||
printf("offset x:%d, y:%d\n", x_offset, y_offset);
|
||||
printf("range x:%d, y:%d\n", x_range, y_range);
|
||||
printf("invert x/y:%d, x:%d, y:%d\n\n", xy_inv, x_inv, y_inv);
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/tp.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_LVGLDEMO_TP_H
|
||||
#define __APPS_EXAMPLES_LVGLDEMO_TP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* CONFIG_EXAMPLES_LVGLDEMO_MINOR - The minor device number. Minor=N
|
||||
* corresponds to touchscreen device /dev/input0. Note this value must
|
||||
* with CONFIG_EXAMPLES_LVGLDEMO_DEVPATH. Default 0.
|
||||
* CONFIG_EXAMPLES_LVGLDEMO_DEVPATH - The path to the touchscreen
|
||||
* device. This must be consistent with CONFIG_EXAMPLES_LVGLDEMO_MINOR.
|
||||
* Default: "/dev/input0"
|
||||
* CONFIG_EXAMPLES_LVGLDEMO_MOUSE - The touchscreen test can also be
|
||||
* configured to work with a mouse driver by setting this option.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_INPUT_TOUCHSCREEN) && !defined(CONFIG_INPUT_MOUSE)
|
||||
# error "Input device support is not enabled (CONFIG_INPUT_TOUCHSCREEN || CONFIG_INPUT_MOUSE)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_MINOR
|
||||
# undef CONFIG_EXAMPLES_LVGLDEMO_DEVPATH
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_MINOR 0
|
||||
# ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/mouse0"
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/input0"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LVGLDEMO_DEVPATH
|
||||
# undef CONFIG_EXAMPLES_LVGLDEMO_MINOR
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_MINOR 0
|
||||
# ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/mouse0"
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/input0"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize The Touch pad
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a positive error code on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int tp_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_read
|
||||
*
|
||||
* Description:
|
||||
* Read a TP data and store in 'data' argument
|
||||
*
|
||||
* Input Parameters:
|
||||
* indev_drv - Input device handler
|
||||
* data - Store the x, y and state information here
|
||||
*
|
||||
* Returned Value:
|
||||
* false: no more data to read; true: there are more data to read.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool tp_read(FAR struct _lv_indev_drv_t *indev_drv,
|
||||
FAR lv_indev_data_t *data);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_read
|
||||
*
|
||||
* Description:
|
||||
* Set calibration data
|
||||
*
|
||||
* Input Parameters:
|
||||
* ul - Upper left hand corner TP value
|
||||
* ur - Upper right hand corner TP value
|
||||
* lr - Lower right hand corner TP value
|
||||
* ll - Lower left hand corner TP value
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tp_set_cal_values(FAR lv_point_t *ul, FAR lv_point_t *ur,
|
||||
FAR lv_point_t *lr, FAR lv_point_t *ll);
|
||||
|
||||
#endif /* __APPS_EXAMPLES_LVGLDEMO_TP_H */
|
@ -1,332 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/tp_cal.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "tp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CIRCLE_SIZE 20
|
||||
#define TP_MAX_VALUE 5000
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
enum tp_cal_state_e
|
||||
{
|
||||
TP_CAL_STATE_INIT,
|
||||
TP_CAL_STATE_WAIT_TOP_LEFT,
|
||||
TP_CAL_STATE_WAIT_TOP_RIGHT,
|
||||
TP_CAL_STATE_WAIT_BOTTOM_RIGHT,
|
||||
TP_CAL_STATE_WAIT_BOTTOM_LEFT,
|
||||
TP_CAL_STATE_WAIT_LEAVE,
|
||||
TP_CAL_STATE_READY,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void btn_click_action(FAR lv_obj_t *scr, lv_event_t event);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static enum tp_cal_state_e state;
|
||||
static lv_point_t p[4];
|
||||
static lv_obj_t *prev_scr;
|
||||
static lv_obj_t *big_btn;
|
||||
static lv_obj_t *label_main;
|
||||
static lv_obj_t *circ_area;
|
||||
static lv_theme_t *prev_theme;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btn_click_action
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Input Parameters:
|
||||
* scr
|
||||
* event
|
||||
*
|
||||
* Returned Value:
|
||||
* ?
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void btn_click_action(FAR lv_obj_t *scr, lv_event_t event)
|
||||
{
|
||||
if (event == LV_EVENT_CLICKED)
|
||||
{
|
||||
if (state == TP_CAL_STATE_WAIT_TOP_LEFT)
|
||||
{
|
||||
lv_indev_t *indev = lv_indev_get_act();
|
||||
char buf[64];
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_t a;
|
||||
#endif
|
||||
|
||||
lv_indev_get_point(indev, &p[0]);
|
||||
|
||||
sprintf(buf, "x: %d\ny: %d", p[0].x, p[0].y);
|
||||
lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label_coord, buf);
|
||||
|
||||
lv_label_set_text(label_main, "Click the circle in\n"
|
||||
"upper right-hand corner");
|
||||
|
||||
lv_obj_set_pos(label_main,
|
||||
(LV_HOR_RES - lv_obj_get_width(label_main)) / 2,
|
||||
(LV_VER_RES - lv_obj_get_height(label_main)) / 2);
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, circ_area);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
||||
lv_anim_set_time(&a, 500);
|
||||
lv_anim_set_values(&a, 0, LV_HOR_RES - CIRCLE_SIZE);
|
||||
lv_anim_set_delay(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
#else
|
||||
lv_obj_set_pos(circ_area, LV_HOR_RES - CIRCLE_SIZE, 0);
|
||||
#endif
|
||||
|
||||
state = TP_CAL_STATE_WAIT_TOP_RIGHT;
|
||||
}
|
||||
else if (state == TP_CAL_STATE_WAIT_TOP_RIGHT)
|
||||
{
|
||||
lv_indev_t *indev = lv_indev_get_act();
|
||||
char buf[64];
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_t a;
|
||||
#endif
|
||||
|
||||
lv_indev_get_point(indev, &p[1]);
|
||||
|
||||
sprintf(buf, "x: %d\ny: %d", p[1].x, p[1].y);
|
||||
lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label_coord, buf);
|
||||
lv_obj_set_pos(label_coord,
|
||||
LV_HOR_RES - lv_obj_get_width(label_coord),
|
||||
0);
|
||||
|
||||
lv_label_set_text(label_main, "Click the circle in\n"
|
||||
"lower right-hand corner");
|
||||
|
||||
lv_obj_set_pos(label_main,
|
||||
(LV_HOR_RES - lv_obj_get_width(label_main)) / 2,
|
||||
(LV_VER_RES - lv_obj_get_height(label_main)) / 2);
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, circ_area);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
||||
lv_anim_set_time(&a, 500);
|
||||
lv_anim_set_values(&a, 0, LV_VER_RES - CIRCLE_SIZE);
|
||||
lv_anim_set_delay(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
#else
|
||||
lv_obj_set_pos(circ_area,
|
||||
LV_HOR_RES - CIRCLE_SIZE, LV_VER_RES - CIRCLE_SIZE);
|
||||
#endif
|
||||
|
||||
state = TP_CAL_STATE_WAIT_BOTTOM_RIGHT;
|
||||
}
|
||||
else if (state == TP_CAL_STATE_WAIT_BOTTOM_RIGHT)
|
||||
{
|
||||
lv_indev_t *indev = lv_indev_get_act();
|
||||
char buf[64];
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_t a;
|
||||
#endif
|
||||
lv_indev_get_point(indev, &p[2]);
|
||||
|
||||
sprintf(buf, "x: %d\ny: %d", p[2].x, p[2].y);
|
||||
lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label_coord, buf);
|
||||
lv_obj_set_pos(label_coord,
|
||||
LV_HOR_RES - lv_obj_get_width(label_coord),
|
||||
LV_VER_RES - lv_obj_get_height(label_coord));
|
||||
|
||||
lv_label_set_text(label_main, "Click the circle in\n"
|
||||
"lower left-hand corner");
|
||||
|
||||
lv_obj_set_pos(label_main,
|
||||
(LV_HOR_RES - lv_obj_get_width(label_main)) / 2,
|
||||
(LV_VER_RES - lv_obj_get_height(label_main)) / 2);
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, circ_area);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
||||
lv_anim_set_time(&a, 500);
|
||||
lv_anim_set_values(&a, LV_HOR_RES - CIRCLE_SIZE, 0);
|
||||
lv_anim_set_delay(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
#else
|
||||
lv_obj_set_pos(circ_area, 0, LV_VER_RES - CIRCLE_SIZE);
|
||||
#endif
|
||||
|
||||
state = TP_CAL_STATE_WAIT_BOTTOM_LEFT;
|
||||
}
|
||||
else if (state == TP_CAL_STATE_WAIT_BOTTOM_LEFT)
|
||||
{
|
||||
lv_indev_t *indev = lv_indev_get_act();
|
||||
char buf[64];
|
||||
|
||||
lv_indev_get_point(indev, &p[3]);
|
||||
|
||||
lv_label_set_text(label_main, "Click the screen\n"
|
||||
"to leave calibration");
|
||||
|
||||
lv_obj_set_pos(label_main,
|
||||
(LV_HOR_RES - lv_obj_get_width(label_main)) / 2,
|
||||
(LV_VER_RES - lv_obj_get_height(label_main)) / 2);
|
||||
|
||||
sprintf(buf, "x: %d\ny: %d", p[3].x, p[3].y);
|
||||
lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label_coord, buf);
|
||||
lv_obj_set_pos(label_coord, 0,
|
||||
LV_VER_RES - lv_obj_get_height(label_coord));
|
||||
|
||||
lv_obj_del(circ_area);
|
||||
|
||||
state = TP_CAL_STATE_WAIT_LEAVE;
|
||||
}
|
||||
else if (state == TP_CAL_STATE_WAIT_LEAVE)
|
||||
{
|
||||
lv_theme_set_act(prev_theme);
|
||||
lv_scr_load(prev_scr);
|
||||
tp_set_cal_values(&p[0], &p[1], &p[2], &p[3]);
|
||||
state = TP_CAL_STATE_READY;
|
||||
}
|
||||
else if (state == TP_CAL_STATE_READY)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_cal_create
|
||||
*
|
||||
* Description:
|
||||
* Create a touchpad calibration screen
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tp_cal_create(void)
|
||||
{
|
||||
static lv_style_t style_circ;
|
||||
static lv_style_t style_big_btn;
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_t a;
|
||||
#endif
|
||||
|
||||
state = TP_CAL_STATE_INIT;
|
||||
|
||||
prev_scr = lv_scr_act();
|
||||
|
||||
lv_theme_t *theme = LV_THEME_DEFAULT_INIT(LV_THEME_DEFAULT_COLOR_PRIMARY,
|
||||
LV_THEME_DEFAULT_COLOR_SECONDARY,
|
||||
LV_THEME_DEFAULT_FLAG,
|
||||
LV_THEME_DEFAULT_FONT_SMALL,
|
||||
LV_THEME_DEFAULT_FONT_NORMAL,
|
||||
LV_THEME_DEFAULT_FONT_SUBTITLE,
|
||||
LV_THEME_DEFAULT_FONT_TITLE);
|
||||
|
||||
prev_theme = lv_theme_get_act();
|
||||
lv_theme_set_act(theme);
|
||||
|
||||
lv_obj_t *scr = lv_obj_create(NULL, NULL);
|
||||
lv_obj_set_size(scr, TP_MAX_VALUE, TP_MAX_VALUE);
|
||||
lv_scr_load(scr);
|
||||
|
||||
/* Create a big transparent button screen to receive clicks */
|
||||
|
||||
big_btn = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(big_btn, TP_MAX_VALUE, TP_MAX_VALUE);
|
||||
|
||||
lv_style_init(&style_big_btn);
|
||||
|
||||
lv_style_set_bg_opa(&style_big_btn, LV_STATE_DEFAULT | LV_STATE_PRESSED,
|
||||
LV_OPA_TRANSP);
|
||||
lv_obj_add_style(big_btn, LV_BTN_PART_MAIN, &style_big_btn);
|
||||
|
||||
lv_obj_set_event_cb(big_btn, btn_click_action);
|
||||
lv_btn_set_layout(big_btn, LV_LAYOUT_OFF);
|
||||
|
||||
label_main = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label_main, "Click the circle in\n"
|
||||
"upper left-hand corner");
|
||||
lv_label_set_align(label_main, LV_LABEL_ALIGN_CENTER);
|
||||
|
||||
lv_obj_set_pos(label_main, (LV_HOR_RES - lv_obj_get_width(label_main)) / 2,
|
||||
(LV_VER_RES - lv_obj_get_height(label_main)) / 2);
|
||||
|
||||
lv_style_init(&style_circ);
|
||||
lv_style_set_radius(&style_circ, LV_STATE_DEFAULT,
|
||||
LV_RADIUS_CIRCLE);
|
||||
lv_style_set_bg_color(&style_circ, LV_STATE_DEFAULT,
|
||||
LV_COLOR_BLUE);
|
||||
circ_area = lv_obj_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(circ_area, CIRCLE_SIZE, CIRCLE_SIZE);
|
||||
lv_obj_add_style(circ_area, LV_OBJ_PART_MAIN, &style_circ);
|
||||
lv_obj_set_click(circ_area, false);
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, circ_area);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
|
||||
lv_anim_set_time(&a, 200);
|
||||
lv_anim_set_values(&a, LV_HOR_RES / 2, 0);
|
||||
lv_anim_set_delay(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
||||
lv_anim_set_values(&a, LV_VER_RES / 2, 0);
|
||||
lv_anim_start(&a);
|
||||
#endif
|
||||
state = TP_CAL_STATE_WAIT_TOP_LEFT;
|
||||
}
|
@ -13,481 +13,215 @@ if GRAPHICS_LVGL
|
||||
|
||||
config LVGL_VERSION
|
||||
string "LVGL Version"
|
||||
default "7.3.0"
|
||||
default "8.3.3"
|
||||
|
||||
config LV_MEM_SIZE
|
||||
int "Heap size of the graphics library"
|
||||
default 32768
|
||||
---help---
|
||||
The size of a memory pool where the grapohisc library
|
||||
dynamically allocates data
|
||||
source "$APPSDIR/graphics/lvgl/lv_conf/Kconfig"
|
||||
|
||||
config LV_USE_USER_DATA
|
||||
bool "Use user data in driver and objects"
|
||||
default n
|
||||
---help---
|
||||
Add a `user_data` to drivers and objects
|
||||
|
||||
config LV_USE_PERF_MONITOR
|
||||
bool "Show CPU usage and FPS count"
|
||||
default n
|
||||
---help---
|
||||
Show CPU usage and FPS count in the right bottom corner
|
||||
|
||||
menu "Graphics settings"
|
||||
|
||||
config LV_HOR_RES
|
||||
int "Horizontal resolution."
|
||||
default 320
|
||||
---help---
|
||||
Number of pixels in horizontally.
|
||||
|
||||
config LV_VER_RES
|
||||
int "Vertical resolution."
|
||||
default 240
|
||||
---help---
|
||||
Number of pixels vertically. Double it if anti aliasing is used
|
||||
|
||||
config LV_DPI
|
||||
int "DPI (px/inch)"
|
||||
default 100
|
||||
---help---
|
||||
Number of pixels in 1 inch
|
||||
|
||||
config LV_ANTIALIAS
|
||||
bool "Anti aliasing of the screen"
|
||||
config LV_PORT_USE_LCDDEV
|
||||
bool "Enable LCD device port"
|
||||
default n
|
||||
|
||||
config LV_DISP_DEF_REFR_PERIOD
|
||||
int "Default refresh period in milliseconds"
|
||||
default 30
|
||||
---help---
|
||||
The graphics library will check for invalid areas an refresh
|
||||
them with this period time
|
||||
if LV_PORT_USE_LCDDEV
|
||||
|
||||
config LV_INV_FIFO_SIZE
|
||||
int "Average number of object on the screen"
|
||||
default 32
|
||||
---help---
|
||||
If too much area is invalidated (greater then this number) then
|
||||
the whole screen will be refreshed
|
||||
config LV_PORT_LCDDEV_DEFAULT_DEVICEPATH
|
||||
string "LCD default device path"
|
||||
default "/dev/lcd0"
|
||||
|
||||
endmenu
|
||||
config LV_PORT_LCDDEV_FULL_SCREEN_BUFFER
|
||||
bool "Use full screen buffer"
|
||||
default n
|
||||
|
||||
menu "Input device settings"
|
||||
if !LV_PORT_LCDDEV_FULL_SCREEN_BUFFER
|
||||
|
||||
config LV_INDEV_DEF_READ_PERIOD
|
||||
int "Input device default read period in milliseconds"
|
||||
default 30
|
||||
|
||||
config LV_INDEV_POINT_MARKER
|
||||
int "Mark the pressed points on the screen"
|
||||
default 0
|
||||
|
||||
config LV_INDEV_DEF_DRAG_LIMIT
|
||||
int "Default drag limit in pixels"
|
||||
config LV_PORT_LCDDEV_LINE_BUFFER_DEFAULT
|
||||
int "Default buffer size (in line)"
|
||||
default 10
|
||||
|
||||
config LV_INDEV_DEF_DRAG_THROW
|
||||
int "Default slow down ration when throwing on object by drag [%]"
|
||||
default 20
|
||||
endif # LV_PORT_LCDDEV_FULL_SCREEN_BUFFER
|
||||
|
||||
config LV_INDEV_DEF_LONG_PRESS_TIME
|
||||
int "Default long press time [ms]"
|
||||
default 400
|
||||
config LV_PORT_LCDDEV_DOUBLE_BUFFER
|
||||
bool "Use double buffer"
|
||||
default n
|
||||
|
||||
config LV_INDEV_DEF_LONG_PRESS_REP_TIME
|
||||
int "Default repeated trigger period in long press [ms]"
|
||||
default 100
|
||||
endif # LV_PORT_USE_LCDDEV
|
||||
|
||||
config LV_INDEV_DEF_GESTURE_LIMIT
|
||||
int "Gesture threshold in pixels"
|
||||
default 50
|
||||
config LV_PORT_USE_FBDEV
|
||||
bool "Enable framebuffer port"
|
||||
default n
|
||||
|
||||
config LV_INDEV_DEF_GESTURE_MIN_VELOCITY
|
||||
int "Gesture min velocity at release before swipe (pixels)"
|
||||
default 3
|
||||
config LV_PORT_FBDEV_DEFAULT_DEVICEPATH
|
||||
string "Framebuffer default device path"
|
||||
default "/dev/fb0"
|
||||
depends on LV_PORT_USE_FBDEV
|
||||
|
||||
endmenu
|
||||
config LV_PORT_USE_TOUCHPAD
|
||||
bool "Enable touchpad port"
|
||||
default n
|
||||
|
||||
menu "Color settings"
|
||||
config LV_PORT_TOUCHPAD_DEFAULT_DEVICEPATH
|
||||
depends on LV_PORT_USE_TOUCHPAD
|
||||
string "Touchpad default device path"
|
||||
default "/dev/input0"
|
||||
|
||||
config LV_COLOR_DEPTH
|
||||
int "Color depth (8/16/32)"
|
||||
default 16
|
||||
config LV_USE_ENCODER
|
||||
depends on INPUT_MOUSE_WHEEL
|
||||
bool "Encoder interface"
|
||||
default n
|
||||
|
||||
config LV_COLOR_16_SWAP
|
||||
bool "Swap the 2 bytes of RGB565 color"
|
||||
depends on LV_COLOR_DEPTH = 16
|
||||
menuconfig LV_PORT_USE_BUTTON
|
||||
bool "Enable button port"
|
||||
default n
|
||||
|
||||
if LV_PORT_USE_BUTTON
|
||||
|
||||
config LV_PORT_BUTTON_DEFAULT_DEVICEPATH
|
||||
string "Button default device path"
|
||||
default "/dev/buttons"
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_0_MAP_X
|
||||
int "Button 0 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
config LV_COLOR_SCREEN_TRANSP
|
||||
bool "Enable screen transparency.(If disabled, 32-bit color depth fall to 24-bit)"
|
||||
config LV_PORT_BUTTON_BUTTON_0_MAP_Y
|
||||
int "Button 0 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
config LV_COLOR_TRANSP
|
||||
hex "Chroma key color (pixels with this color will be transparent on images)"
|
||||
default 0x00ff00
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Text (font) settings"
|
||||
|
||||
config LV_TXT_UTF8
|
||||
bool "Unicode support"
|
||||
default n
|
||||
|
||||
config LV_TXT_BREAK_CHARS
|
||||
string "Characters where the words/line cab be wrapped"
|
||||
default " ,.;:-_"
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Feature usage"
|
||||
config USE_LV_ANIMATION
|
||||
bool "Enable animations"
|
||||
default y
|
||||
|
||||
config USE_LV_SHADOW
|
||||
bool "Enable shadows"
|
||||
default y
|
||||
|
||||
config USE_LV_GROUP
|
||||
bool "Enable object groups (for keyboard)"
|
||||
default y
|
||||
|
||||
config USE_LV_GPU
|
||||
bool "Enable GPU (hardware acceleration) API"
|
||||
default y
|
||||
|
||||
config USE_LV_REAL_DRAW
|
||||
bool "Enable function which draws directly to the frame buffer instead of VDB"
|
||||
default y
|
||||
|
||||
config USE_LV_FILESYSTEM
|
||||
bool "Enable filesystem (required for images, lv_img)"
|
||||
default y
|
||||
|
||||
if USE_LV_FILESYSTEM
|
||||
|
||||
config LV_FILESYSTEM_MOUNTPOINT
|
||||
string "File system mount point"
|
||||
default "/data"
|
||||
|
||||
endif
|
||||
|
||||
config USE_LV_MULTI_LANG
|
||||
int "Number of languages for labels to store (0 to disable)"
|
||||
config LV_PORT_BUTTON_BUTTON_1_MAP_X
|
||||
int "Button 1 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
endmenu
|
||||
config LV_PORT_BUTTON_BUTTON_1_MAP_Y
|
||||
int "Button 1 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
menu "Log usage"
|
||||
config LV_PORT_BUTTON_BUTTON_2_MAP_X
|
||||
int "Button 2 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
config LV_USE_LOG
|
||||
bool "Enable/disable the log module"
|
||||
config LV_PORT_BUTTON_BUTTON_2_MAP_Y
|
||||
int "Button 2 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_3_MAP_X
|
||||
int "Button 3 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_3_MAP_Y
|
||||
int "Button 3 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_4_MAP_X
|
||||
int "Button 4 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_4_MAP_Y
|
||||
int "Button 4 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_5_MAP_X
|
||||
int "Button 5 mapping coordinate x"
|
||||
default 0
|
||||
|
||||
config LV_PORT_BUTTON_BUTTON_5_MAP_Y
|
||||
int "Button 5 mapping coordinate y"
|
||||
default 0
|
||||
|
||||
endif # LV_PORT_USE_BUTTON
|
||||
|
||||
menuconfig LV_PORT_USE_KEYPAD
|
||||
bool "Enable keypad port"
|
||||
default n
|
||||
|
||||
choice
|
||||
prompt "Log level"
|
||||
depends on LV_USE_LOG
|
||||
default LV_LOG_LEVEL_WARN
|
||||
|
||||
config LV_LOG_LEVEL_TRACE
|
||||
bool "Trace"
|
||||
|
||||
config LV_LOG_LEVEL_INFO
|
||||
bool "Info"
|
||||
|
||||
config LV_LOG_LEVEL_WARN
|
||||
bool "Warn"
|
||||
|
||||
config LV_LOG_LEVEL_ERROR
|
||||
bool "Error"
|
||||
|
||||
endchoice
|
||||
|
||||
config LV_LOG_PRINTF
|
||||
bool "Use printf() for logging"
|
||||
depends on LV_USE_LOG
|
||||
default y
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Debug usage"
|
||||
|
||||
config LV_USE_DEBUG
|
||||
bool "Enable/disable the debug module"
|
||||
default n
|
||||
|
||||
config LV_USE_ASSERT_NULL
|
||||
bool "Check if the parameter is NULL"
|
||||
depends on LV_USE_DEBUG
|
||||
default n
|
||||
|
||||
config LV_USE_ASSERT_MEM
|
||||
bool "Checks is the memory is successfully allocated or no"
|
||||
depends on LV_USE_DEBUG
|
||||
default n
|
||||
|
||||
config LV_USE_ASSERT_STR
|
||||
bool "Check the strings"
|
||||
depends on LV_USE_DEBUG
|
||||
default n
|
||||
|
||||
config LV_USE_ASSERT_OBJ
|
||||
bool "Check object's type and existence"
|
||||
depends on LV_USE_DEBUG
|
||||
default n
|
||||
|
||||
config LV_USE_ASSERT_STYLE
|
||||
bool "Check if the styles are properly initialized"
|
||||
depends on LV_USE_DEBUG
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Theme usage"
|
||||
|
||||
config LV_USE_THEME_TEMPL
|
||||
bool "Use Template theme: just for test"
|
||||
default n
|
||||
|
||||
config LV_USE_THEME_MONO
|
||||
bool "Use Mono theme: mono color theme"
|
||||
default n
|
||||
|
||||
config LV_USE_THEME_MATERIAL
|
||||
bool "Use Material theme: material theme with bold colors"
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Base object settings"
|
||||
|
||||
config LV_OBJ_REALIGN
|
||||
bool "Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters"
|
||||
default y
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Object type usage settings"
|
||||
|
||||
config USE_LV_LABEL
|
||||
bool "Label usage"
|
||||
default y
|
||||
|
||||
config LV_LABEL_SCROLL_SPEED
|
||||
int "Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode"
|
||||
depends on USE_LV_LABEL
|
||||
default 25
|
||||
|
||||
config USE_LV_IMG
|
||||
bool "Image usage"
|
||||
default y
|
||||
|
||||
config LV_IMG_CF_INDEXED
|
||||
bool "Enable indexed (palette) images"
|
||||
depends on USE_LV_IMG
|
||||
default y
|
||||
|
||||
config LV_IMG_CF_ALPHA
|
||||
bool "Enable alpha indexed images"
|
||||
depends on USE_LV_IMG
|
||||
default y
|
||||
|
||||
config USE_LV_LINE
|
||||
bool "Line usage"
|
||||
default y
|
||||
|
||||
config USE_LV_ARC
|
||||
bool "Arc usage"
|
||||
default y
|
||||
|
||||
config USE_LV_CONT
|
||||
bool "Container usage"
|
||||
default y
|
||||
|
||||
config USE_LV_PAGE
|
||||
depends on USE_LV_CONT
|
||||
bool "Page usage"
|
||||
default y
|
||||
|
||||
config USE_LV_WIN
|
||||
depends on USE_LV_PAGE && USE_LV_LABEL && USE_LV_IMG && USE_LV_BTN
|
||||
bool "Window usage"
|
||||
default y
|
||||
|
||||
config USE_LV_TABVIEW
|
||||
depends on USE_LV_PAGE && USE_LV_BTNM
|
||||
bool "Tabview usage"
|
||||
default y
|
||||
|
||||
config LV_TABVIEW_ANIM_TIME
|
||||
int "Time of slide animation [ms] (0: no animation)"
|
||||
depends on USE_LV_TABVIEW
|
||||
default 300
|
||||
|
||||
config USE_LV_TILEVIEW
|
||||
depends on USE_LV_CONT && USE_LV_PAGE
|
||||
bool "Tileview usage"
|
||||
default y
|
||||
|
||||
config LV_TILEVIEW_ANIM_TIME
|
||||
int "Time of slide animation [ms] (0: no animation)"
|
||||
depends on USE_LV_TILEVIEW
|
||||
default 300
|
||||
|
||||
config USE_LV_BAR
|
||||
bool "Bar usage"
|
||||
default y
|
||||
|
||||
config USE_LV_LMETER
|
||||
depends on USE_LV_BAR
|
||||
bool "Line meter usage"
|
||||
default y
|
||||
|
||||
config USE_LV_GAUGE
|
||||
depends on USE_LV_BAR && USE_LV_LMETER
|
||||
bool "Gauge usage"
|
||||
default y
|
||||
|
||||
config USE_LV_CHART
|
||||
bool "Chart usage"
|
||||
default y
|
||||
|
||||
config LV_CHART_AXIS_TICK_LABEL_MAX_LEN
|
||||
depends on USE_LV_CHART
|
||||
int "Chart axis tick label max length"
|
||||
default 20
|
||||
|
||||
config USE_LV_TABLE
|
||||
bool "Table usage"
|
||||
depends on USE_LV_LABEL
|
||||
default y
|
||||
|
||||
config LV_TABLE_COL_MAX
|
||||
int "Maximum number of table columns"
|
||||
depends on USE_LV_TABLE
|
||||
default 12
|
||||
|
||||
config USE_LV_LED
|
||||
bool "LED usage"
|
||||
default y
|
||||
|
||||
config USE_LV_MBOX
|
||||
bool "Messagebox usage"
|
||||
depends on USE_LV_BTNM && USE_LV_LABEL
|
||||
default y
|
||||
|
||||
config USE_LV_TA
|
||||
bool "Text area usage"
|
||||
depends on USE_LV_LABEL && USE_LV_PAGE
|
||||
default y
|
||||
|
||||
config USE_LV_SPINBOX
|
||||
bool "Spinbox usage"
|
||||
depends on USE_LV_TA
|
||||
default y
|
||||
|
||||
config USE_LV_CALENDAR
|
||||
bool "Calendar usage"
|
||||
default y
|
||||
|
||||
config USE_LV_PRELOAD
|
||||
bool "Preload usage"
|
||||
depends on USE_LV_ARC
|
||||
default y
|
||||
|
||||
config LV_PRELOAD_DEF_ARC_LENGTH
|
||||
int "Degrees of arc length (default)"
|
||||
range 0 360
|
||||
depends on USE_LV_PRELOAD
|
||||
default 60
|
||||
|
||||
config LV_PRELOAD_DEF_SPIN_TIME
|
||||
int "Time (ms) preload spins (default)"
|
||||
depends on USE_LV_PRELOAD
|
||||
default 1000
|
||||
|
||||
choice
|
||||
prompt "Default preload animation"
|
||||
depends on USE_LV_PRELOAD
|
||||
default LV_PRELOAD_DEF_ANIM_SPINNING_ARC
|
||||
|
||||
config LV_PRELOAD_DEF_ANIM_SPINNING_ARC
|
||||
bool "Spinning Arc"
|
||||
|
||||
config LV_PRELOAD_DEF_ANIM_FILLSPIN_ARC
|
||||
bool "Fillspin Arc"
|
||||
|
||||
endchoice
|
||||
|
||||
config USE_LV_CANVAS
|
||||
bool "Canvas usage"
|
||||
depends on USE_LV_IMG
|
||||
default n
|
||||
|
||||
config USE_LV_BTN
|
||||
bool "Button usage"
|
||||
depends on USE_LV_CONT
|
||||
default y
|
||||
|
||||
config LV_BTN_INK_EFFECT
|
||||
bool "Enable button-state animations"
|
||||
depends on USE_LV_BTN && USE_LV_ANIMATION
|
||||
default y
|
||||
|
||||
config USE_LV_IMGBTN
|
||||
depends on USE_LV_BTN
|
||||
bool "Image button usage"
|
||||
default y
|
||||
|
||||
config LV_IMGBTN_TILED
|
||||
bool "Tiled image button"
|
||||
depends on USE_LV_IMGBTN
|
||||
---help---
|
||||
The imgbtn requires left, mid and right parts and the width can be set freely
|
||||
button bit map < 0 is no binding, must >= 0 and < 31 to binding button device.
|
||||
|
||||
config USE_LV_BTNM
|
||||
bool "Button matrix usage"
|
||||
default y
|
||||
if LV_PORT_USE_KEYPAD
|
||||
|
||||
config USE_LV_KB
|
||||
bool "Keyboard"
|
||||
depends on USE_LV_BTNM
|
||||
default y
|
||||
config LV_PORT_KEYPAD_DEFAULT_DEVICEPATH
|
||||
string "Button default device path"
|
||||
default "/dev/buttons"
|
||||
|
||||
config USE_LV_CB
|
||||
bool "Chekbox usage"
|
||||
depends on USE_LV_BTN
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_UP_MAP_BIT
|
||||
int "LV_KEY_UP button bit map"
|
||||
default -1
|
||||
|
||||
config USE_LV_SW
|
||||
bool "Switch usage"
|
||||
depends on USE_LV_BTN
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT
|
||||
int "LV_KEY_DOWN button bit map"
|
||||
default -1
|
||||
|
||||
config USE_LV_LIST
|
||||
bool "List usage"
|
||||
depends on USE_LV_BTN && USE_LV_PAGE
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT
|
||||
int "LV_KEY_RIGHT button bit map"
|
||||
default -1
|
||||
|
||||
config USE_LV_DDLIST
|
||||
bool "Drop down list usage"
|
||||
depends on USE_LV_PAGE && USE_LV_LABEL
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT
|
||||
int "LV_KEY_LEFT button bit map"
|
||||
default -1
|
||||
|
||||
config USE_LV_ROLLER
|
||||
bool "Roller usage"
|
||||
depends on USE_LV_DDLIST
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_ESC_MAP_BIT
|
||||
int "LV_KEY_ESC button bit map"
|
||||
default -1
|
||||
|
||||
config USE_LV_SLIDER
|
||||
bool "Slider usage"
|
||||
depends on USE_LV_BAR
|
||||
default y
|
||||
config LV_PORT_KEYPAD_KEY_DEL_MAP_BIT
|
||||
int "LV_KEY_DEL button bit map"
|
||||
default -1
|
||||
|
||||
endmenu
|
||||
config LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT
|
||||
int "LV_KEY_BACKSPACE button bit map"
|
||||
default -1
|
||||
|
||||
config LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT
|
||||
int "LV_KEY_ENTER button bit map"
|
||||
default -1
|
||||
|
||||
config LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT
|
||||
int "LV_KEY_NEXT button bit map"
|
||||
default -1
|
||||
|
||||
config LV_PORT_KEYPAD_KEY_PREV_MAP_BIT
|
||||
int "LV_KEY_PREV button bit map"
|
||||
default -1
|
||||
|
||||
config LV_PORT_KEYPAD_KEY_HOME_MAP_BIT
|
||||
int "LV_KEY_HOME button bit map"
|
||||
default -1
|
||||
|
||||
config LV_PORT_KEYPAD_KEY_END_MAP_BIT
|
||||
int "LV_KEY_END button bit map"
|
||||
default -1
|
||||
|
||||
endif # LV_PORT_USE_KEYPAD
|
||||
|
||||
if LV_PORT_USE_ENCODER
|
||||
|
||||
config LV_PORT_ENCODER_DEFAULT_DEVICEPATH
|
||||
string "Encoder default device path"
|
||||
default "/dev/input0"
|
||||
|
||||
endif # LV_USE_ENCODER
|
||||
|
||||
menu "Memory configuration"
|
||||
|
||||
config LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME
|
||||
string "LV_ATTRIBUTE_FAST_MEM Section Name"
|
||||
default ""
|
||||
---help---
|
||||
Set this option to configure custom memory as LV_ATTRIBUTE_FAST_MEM
|
||||
|
||||
if LV_MEM_CUSTOM
|
||||
|
||||
config LV_PORT_MEM_CUSTOM_SIZE
|
||||
int "Size of the custom memory used by `lv_mem_alloc` in kilobytes (>= 2kB)"
|
||||
default 0
|
||||
|
||||
if LV_PORT_MEM_CUSTOM_SIZE != 0
|
||||
|
||||
config LV_PORT_MEM_CUSTOM_NAME
|
||||
string "Name of the custom HEAP memory"
|
||||
default "lvgl"
|
||||
|
||||
endif # LV_PORT_MEM_CUSTOM_SIZE
|
||||
|
||||
endif # LV_MEM_CUSTOM
|
||||
|
||||
endmenu # "Memory configuration"
|
||||
|
||||
endif # GRAPHICS_LVGL
|
||||
|
@ -26,8 +26,4 @@ CONFIGURED_APPS += $(APPDIR)/graphics/lvgl
|
||||
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl
|
||||
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl
|
||||
|
||||
# It allows `<lvgl.h>` import.
|
||||
|
||||
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl/lvgl
|
||||
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl/lvgl
|
||||
endif
|
||||
|
@ -25,32 +25,67 @@ include $(APPDIR)/Make.defs
|
||||
LVGL_DIR = .
|
||||
LVGL_DIR_NAME = lvgl
|
||||
|
||||
# Relax format check for LVGL to avoid errors on prinf() use
|
||||
# Relax LVGL's format checking and unused variable checking to avoid errors
|
||||
|
||||
CFLAGS += -Wno-format
|
||||
CFLAGS += -Wno-format -Wno-unused-variable
|
||||
|
||||
# LVGL Libraries
|
||||
-include ./lvgl/lvgl.mk
|
||||
|
||||
-include ./lvgl/src/lv_core/lv_core.mk
|
||||
-include ./lvgl/src/lv_hal/lv_hal.mk
|
||||
-include ./lvgl/src/lv_widgets/lv_widgets.mk
|
||||
-include ./lvgl/src/lv_font/lv_font.mk
|
||||
-include ./lvgl/src/lv_misc/lv_misc.mk
|
||||
-include ./lvgl/src/lv_themes/lv_themes.mk
|
||||
-include ./lvgl/src/lv_draw/lv_draw.mk
|
||||
-include ./lvgl/src/lv_gpu/lv_gpu.mk
|
||||
CSRCS += port/lv_port.c
|
||||
CSRCS += port/lv_port_tick.c
|
||||
|
||||
CSRCS += lv_tick_interface.c
|
||||
|
||||
ifneq ($(CONFIG_USE_LV_FILESYSTEM),)
|
||||
CSRCS += lv_fs_interface.c
|
||||
ifeq ($(CONFIG_LV_PORT_USE_LCDDEV),y)
|
||||
CSRCS += port/lv_port_lcddev.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_PORT_USE_FBDEV),y)
|
||||
CSRCS += port/lv_port_fbdev.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_PORT_USE_TOUCHPAD),y)
|
||||
CSRCS += port/lv_port_touchpad.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_PORT_USE_BUTTON),y)
|
||||
CSRCS += port/lv_port_button.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_PORT_USE_KEYPAD),y)
|
||||
CSRCS += port/lv_port_keypad.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_PORT_USE_ENCODER),y)
|
||||
CSRCS += port/lv_port_encoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_USE_LOG),y)
|
||||
CSRCS += port/lv_port_syslog.c
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME), "")
|
||||
CFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=locate_data(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)"
|
||||
CXXFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=locate_data(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)"
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LV_MEM_CUSTOM),y)
|
||||
ifneq ($(CONFIG_LV_PORT_MEM_CUSTOM_SIZE), 0)
|
||||
CFLAGS += "-DLV_MEM_CUSTOM_ALLOC=lv_port_mem_alloc"
|
||||
CFLAGS += "-DLV_MEM_CUSTOM_FREE=lv_port_mem_free"
|
||||
CFLAGS += "-DLV_MEM_CUSTOM_REALLOC=lv_port_mem_realloc"
|
||||
CSRCS += port/lv_port_mem.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_LV_ASSERT_HANDLER_INCLUDE), "")
|
||||
CFLAGS += "-DLV_ASSERT_HANDLER=ASSERT(0);"
|
||||
endif
|
||||
|
||||
# Set up build configuration and environment
|
||||
|
||||
WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'}
|
||||
|
||||
CONFIG_GRAPH_LVGL_URL ?= "https://github.com/lvgl/lvgl/archive"
|
||||
CONFIG_GRAPH_LVGL_URL ?= "https://github.com/lvgl/lvgl/archive/refs/tags"
|
||||
|
||||
LVGL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LVGL_VERSION)))
|
||||
LVGL_TARBALL = v$(LVGL_VERSION).zip
|
||||
|
File diff suppressed because it is too large
Load Diff
1115
graphics/lvgl/lv_conf/Kconfig
Normal file
1115
graphics/lvgl/lv_conf/Kconfig
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,575 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/lv_fs_interface.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/statfs.h>
|
||||
#include "lv_fs_interface.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define LV_FS_LETTER '/'
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/* Create a type to store the required data about your file. */
|
||||
|
||||
typedef int file_t;
|
||||
|
||||
/* Similarly to `file_t` create a type for directory reading too */
|
||||
|
||||
typedef DIR *dir_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_open(lv_fs_drv_t *drv, void *file_p,
|
||||
const char *path, lv_fs_mode_t mode);
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p);
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p,
|
||||
void *buf, uint32_t btr, uint32_t *br);
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p,
|
||||
const void *buf, uint32_t btw, uint32_t *bw);
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t pos);
|
||||
static lv_fs_res_t fs_size(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *size_p);
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *pos_p);
|
||||
static lv_fs_res_t fs_remove(lv_fs_drv_t *drv, const char *path);
|
||||
static lv_fs_res_t fs_trunc(lv_fs_drv_t *drv, void *file_p);
|
||||
static lv_fs_res_t fs_rename(lv_fs_drv_t *drv, const char *oldname,
|
||||
const char *newname);
|
||||
static lv_fs_res_t fs_free(lv_fs_drv_t *drv, uint32_t *total_p,
|
||||
uint32_t *free_p);
|
||||
static lv_fs_res_t fs_dir_open(lv_fs_drv_t *drv, void *dir_p,
|
||||
const char *path);
|
||||
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn);
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_open
|
||||
*
|
||||
* Description:
|
||||
* Open a file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* path - path to the file beginning with the driver letter.
|
||||
* (e.g. /folder/file.txt)
|
||||
* mode - read: FS_MODE_RD, write: FS_MODE_WR,
|
||||
* both: FS_MODE_RD | FS_MODE_WR
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_open(lv_fs_drv_t *drv, void *file_p,
|
||||
const char *path, lv_fs_mode_t mode)
|
||||
{
|
||||
uint32_t flags = 0;
|
||||
if (mode == LV_FS_MODE_WR)
|
||||
{
|
||||
flags = O_WRONLY | O_CREAT;
|
||||
}
|
||||
else if (mode == LV_FS_MODE_RD)
|
||||
{
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
else if (mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
|
||||
{
|
||||
flags = O_RDWR | O_CREAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
file_t f = open(--path, flags);
|
||||
if (f < 0)
|
||||
{
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
/* 'file_p' is pointer to a file descriptor and
|
||||
* we need to store our file descriptor here
|
||||
*/
|
||||
|
||||
file_t *fp = file_p; /* Just avoid the confusing casings */
|
||||
*fp = f;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_close
|
||||
*
|
||||
* Description:
|
||||
* Close an opened file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
return close(*fp) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_read
|
||||
*
|
||||
* Description:
|
||||
* Read data from an opened file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* buf - pointer to a memory block where to store the read data.
|
||||
* btr - number of Bytes To Read.
|
||||
* br - the real number of read bytes (Byte Read).
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p,
|
||||
void *buf, uint32_t btr, uint32_t *br)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
*br = read(*fp, buf, btr);
|
||||
|
||||
return (int32_t)*br < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_write
|
||||
*
|
||||
* Description:
|
||||
* Write into a file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* buf - pointer to a buffer with the bytes to write.
|
||||
* btw - Bytes To Write.
|
||||
* bw - the number of real written bytes (Bytes Written).
|
||||
* NULL if unused.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p,
|
||||
const void *buf, uint32_t btw, uint32_t *bw)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
*bw = write(*fp, buf, btw);
|
||||
|
||||
return (int32_t)*bw < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_seek
|
||||
*
|
||||
* Description:
|
||||
* Set the read write pointer. Also expand the file size if necessary.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* pos - the new position of read write pointer.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
off_t offset = lseek(*fp, pos, SEEK_SET);
|
||||
|
||||
return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_size
|
||||
*
|
||||
* Description:
|
||||
* Give the size of a file bytes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* size - pointer to a variable to store the size.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_size(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *size_p)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
off_t cur = lseek(*fp, 0, SEEK_CUR);
|
||||
|
||||
*size_p = lseek(*fp, 0L, SEEK_END);
|
||||
|
||||
/* Restore file pointer */
|
||||
|
||||
lseek(*fp, cur, SEEK_SET);
|
||||
|
||||
return (int32_t)*size_p < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_tell
|
||||
*
|
||||
* Description:
|
||||
* Give the position of the read write pointer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
* pos_p - pointer to to store the result.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *pos_p)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
*pos_p = lseek(*fp, 0, SEEK_CUR);
|
||||
|
||||
return (int32_t)*pos_p < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_remove
|
||||
*
|
||||
* Description:
|
||||
* Delete a file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* path - path of the file to delete.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_remove(lv_fs_drv_t *drv, const char *path)
|
||||
{
|
||||
return remove(--path) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_trunc
|
||||
*
|
||||
* Description:
|
||||
* Truncate the file size to the current position of
|
||||
* the read write pointer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* file_p - pointer to a file_t variable.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_trunc(lv_fs_drv_t *drv, void *file_p)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
file_t *fp = file_p;
|
||||
|
||||
off_t p = lseek(*fp, 0, SEEK_CUR);
|
||||
|
||||
return ftruncate(*fp, p) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_rename
|
||||
*
|
||||
* Description:
|
||||
* Rename a file.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* oldname - path to the file.
|
||||
* newname - path with the new name
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_rename(lv_fs_drv_t *drv, const char *oldname,
|
||||
const char *newname)
|
||||
{
|
||||
return rename(--oldname, --newname) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_free
|
||||
*
|
||||
* Description:
|
||||
* Get the free and total size of a driver in kB.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* total_p - pointer to store the total size [kB].
|
||||
* free_p - pointer to store the free size [kB]
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_free(lv_fs_drv_t *drv, uint32_t *total_p,
|
||||
uint32_t *free_p)
|
||||
{
|
||||
struct statfs sfs;
|
||||
|
||||
if (statfs(CONFIG_LV_FILESYSTEM_MOUNTPOINT, &sfs) < 0)
|
||||
{
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
*total_p = sfs.f_blocks * sfs.f_bsize / 1024;
|
||||
*free_p = sfs.f_bfree * sfs.f_bsize / 1024;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_dir_open
|
||||
*
|
||||
* Description:
|
||||
* Initialize a 'fs_read_dir_t' variable for directory reading.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* dir_p - pointer to a 'fs_read_dir_t' variable.
|
||||
* path - path to a directory.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_dir_open(lv_fs_drv_t *drv, void *dir_p,
|
||||
const char *path)
|
||||
{
|
||||
dir_t d;
|
||||
|
||||
/* Make the path relative to the current directory
|
||||
* (the projects root folder)
|
||||
*/
|
||||
|
||||
if ((d = opendir(--path)) == NULL)
|
||||
{
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 'dir_p' is pointer to a file descriptor and
|
||||
* we need to store our file descriptor here
|
||||
*/
|
||||
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
dir_t *dp = dir_p;
|
||||
*dp = d;
|
||||
}
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_dir_read
|
||||
*
|
||||
* Description:
|
||||
* Read the next filename form a directory.
|
||||
* The name of the directories will begin with '/'.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* dir_p - pointer to an initialized 'fs_read_dir_t' variable.
|
||||
* fn - pointer to a buffer to store the filename.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn)
|
||||
{
|
||||
/* Just avoid the confusing casings */
|
||||
|
||||
dir_t *dp = dir_p;
|
||||
|
||||
do
|
||||
{
|
||||
struct dirent *entry = readdir(*dp);
|
||||
|
||||
if (entry)
|
||||
{
|
||||
if (entry->d_type == DT_DIR)
|
||||
{
|
||||
sprintf(fn, "/%s", entry->d_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(fn, entry->d_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(fn, "");
|
||||
}
|
||||
}
|
||||
while (strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fs_dir_read
|
||||
*
|
||||
* Description:
|
||||
* Close the directory reading.
|
||||
*
|
||||
* Input Parameters:
|
||||
* drv - pointer to a driver where this function belongs.
|
||||
* dir_p - pointer to an initialized 'fs_read_dir_t' variable.
|
||||
*
|
||||
* Returned Value:
|
||||
* LV_FS_RES_OK or any error from lv_fs_res_t enum.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p)
|
||||
{
|
||||
dir_t *dp = dir_p;
|
||||
|
||||
return closedir(*dp) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_fs_interface_init
|
||||
*
|
||||
* Description:
|
||||
* Register a driver for the File system interface.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void lv_fs_interface_init(void)
|
||||
{
|
||||
/* Add a simple drive to open images */
|
||||
|
||||
lv_fs_drv_t fs_drv; /* A driver descriptor */
|
||||
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
/* Set up fields... */
|
||||
|
||||
fs_drv.file_size = sizeof(file_t);
|
||||
fs_drv.letter = LV_FS_LETTER;
|
||||
fs_drv.open_cb = fs_open;
|
||||
fs_drv.close_cb = fs_close;
|
||||
fs_drv.read_cb = fs_read;
|
||||
fs_drv.write_cb = fs_write;
|
||||
fs_drv.seek_cb = fs_seek;
|
||||
fs_drv.tell_cb = fs_tell;
|
||||
fs_drv.free_space_cb = fs_free;
|
||||
fs_drv.size_cb = fs_size;
|
||||
fs_drv.remove_cb = fs_remove;
|
||||
fs_drv.rename_cb = fs_rename;
|
||||
fs_drv.trunc_cb = fs_trunc;
|
||||
|
||||
fs_drv.rddir_size = sizeof(dir_t);
|
||||
fs_drv.dir_close_cb = fs_dir_close;
|
||||
fs_drv.dir_open_cb = fs_dir_open;
|
||||
fs_drv.dir_read_cb = fs_dir_read;
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
}
|
91
graphics/lvgl/port/lv_port.c
Normal file
91
graphics/lvgl/port/lv_port.c
Normal file
@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "lv_port.h"
|
||||
#include "lv_port_button.h"
|
||||
#include "lv_port_encoder.h"
|
||||
#include "lv_port_fbdev.h"
|
||||
#include "lv_port_lcddev.h"
|
||||
#include "lv_port_mem.h"
|
||||
#include "lv_port_keypad.h"
|
||||
#include "lv_port_syslog.h"
|
||||
#include "lv_port_touchpad.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize all porting.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void lv_port_init(void)
|
||||
{
|
||||
#if defined(CONFIG_LV_USE_LOG)
|
||||
lv_port_syslog_init();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_LCDDEV)
|
||||
lv_port_lcddev_init(NULL, 0);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_FBDEV)
|
||||
lv_port_fbdev_init(NULL);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_BUTTON)
|
||||
lv_port_button_init(NULL);
|
||||
|
||||
#if defined(CONFIG_UINPUT_BUTTON)
|
||||
lv_port_button_init("/dev/ubutton");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_KEYPAD)
|
||||
lv_port_keypad_init(NULL);
|
||||
|
||||
#if defined(CONFIG_UINPUT_BUTTON)
|
||||
lv_port_keypad_init("/dev/ubutton");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_TOUCHPAD)
|
||||
lv_port_touchpad_init(NULL);
|
||||
|
||||
#if defined(CONFIG_UINPUT_TOUCH)
|
||||
lv_port_touchpad_init("/dev/utouch");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_ENCODER)
|
||||
lv_port_encoder_init(NULL);
|
||||
#endif
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/lv_fs_interface.h
|
||||
* apps/graphics/lvgl/port/lv_port.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -18,22 +18,17 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H
|
||||
#define __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
@ -54,13 +49,19 @@ extern "C"
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void lv_fs_interface_init(void);
|
||||
/****************************************************************************
|
||||
* Name: lv_port_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize all porting.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void lv_port_init(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LV_USE_FILESYSTEM */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H */
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_H */
|
238
graphics/lvgl/port/lv_port_button.c
Normal file
238
graphics/lvgl/port/lv_port_button.c
Normal file
@ -0,0 +1,238 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_button.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/input/buttons.h>
|
||||
#include "lv_port_button.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUTTON_0_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_X
|
||||
#define BUTTON_0_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_Y
|
||||
#define BUTTON_1_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_X
|
||||
#define BUTTON_1_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_Y
|
||||
#define BUTTON_2_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_X
|
||||
#define BUTTON_2_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_Y
|
||||
#define BUTTON_3_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_X
|
||||
#define BUTTON_3_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_Y
|
||||
#define BUTTON_4_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_X
|
||||
#define BUTTON_4_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_Y
|
||||
#define BUTTON_5_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_X
|
||||
#define BUTTON_5_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_Y
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct button_obj_s
|
||||
{
|
||||
int fd;
|
||||
uint8_t last_btn;
|
||||
lv_indev_drv_t indev_drv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Assign buttons to points on the screen */
|
||||
|
||||
static const lv_point_t g_button_points_map[6] =
|
||||
{
|
||||
{BUTTON_0_MAP_X, BUTTON_0_MAP_Y},
|
||||
{BUTTON_1_MAP_X, BUTTON_1_MAP_Y},
|
||||
{BUTTON_2_MAP_X, BUTTON_2_MAP_Y},
|
||||
{BUTTON_3_MAP_X, BUTTON_3_MAP_Y},
|
||||
{BUTTON_4_MAP_X, BUTTON_4_MAP_Y},
|
||||
{BUTTON_5_MAP_X, BUTTON_5_MAP_Y}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: button_get_pressed_id
|
||||
****************************************************************************/
|
||||
|
||||
static int button_get_pressed_id(int fd)
|
||||
{
|
||||
int btn_act = -1;
|
||||
btn_buttonset_t buttonset;
|
||||
const int buttonset_bits = sizeof(btn_buttonset_t) * 8;
|
||||
int bit;
|
||||
|
||||
int ret = read(fd, &buttonset, sizeof(btn_buttonset_t));
|
||||
if (ret < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (bit = 0; bit < buttonset_bits; bit++)
|
||||
{
|
||||
btn_buttonset_t mask = (btn_buttonset_t)(1 << bit);
|
||||
|
||||
if ((buttonset & mask) != 0)
|
||||
{
|
||||
btn_act = bit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return btn_act;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: button_read
|
||||
****************************************************************************/
|
||||
|
||||
static void button_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data)
|
||||
{
|
||||
FAR struct button_obj_s *button_obj = drv->user_data;
|
||||
|
||||
/* Get the pressed button's ID */
|
||||
|
||||
int btn_act = button_get_pressed_id(button_obj->fd);
|
||||
|
||||
if (btn_act >= 0)
|
||||
{
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
button_obj->last_btn = btn_act;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/* Save the last pressed button's ID */
|
||||
|
||||
data->btn_id = button_obj->last_btn;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: button_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_indev_t *button_init(int fd)
|
||||
{
|
||||
FAR struct button_obj_s *button_obj;
|
||||
FAR lv_indev_t *indev_button;
|
||||
|
||||
button_obj = malloc(sizeof(struct button_obj_s));
|
||||
|
||||
if (button_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("button_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
button_obj->fd = fd;
|
||||
button_obj->last_btn = 0;
|
||||
|
||||
lv_indev_drv_init(&(button_obj->indev_drv));
|
||||
button_obj->indev_drv.type = LV_INDEV_TYPE_BUTTON;
|
||||
button_obj->indev_drv.read_cb = button_read;
|
||||
#if ( LV_USE_USER_DATA != 0 )
|
||||
button_obj->indev_drv.user_data = button_obj;
|
||||
#else
|
||||
#error LV_USE_USER_DATA must be enabled
|
||||
#endif
|
||||
indev_button = lv_indev_drv_register(&(button_obj->indev_drv));
|
||||
lv_indev_set_button_points(indev_button, g_button_points_map);
|
||||
|
||||
return indev_button;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_button_init
|
||||
*
|
||||
* Description:
|
||||
* Button interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_button_init(FAR const char *dev_path)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
FAR lv_indev_t *indev;
|
||||
int fd;
|
||||
btn_buttonset_t supported;
|
||||
int ret;
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_BUTTON_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("button %s opening", device_path);
|
||||
fd = open(device_path, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("button %s open failed: %d", device_path, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the set of BUTTONs supported */
|
||||
|
||||
ret = ioctl(fd, BTNIOC_SUPPORTED,
|
||||
(unsigned long)((uintptr_t)&supported));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("button ioctl(BTNIOC_SUPPORTED) failed: %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("button supported BUTTONs 0x%08x", (unsigned int)supported);
|
||||
|
||||
indev = button_init(fd);
|
||||
|
||||
if (indev == NULL)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return indev;
|
||||
}
|
80
graphics/lvgl/port/lv_port_button.h
Normal file
80
graphics/lvgl/port/lv_port_button.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_button.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_BUTTON_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_BUTTON_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_BUTTON)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_button_init
|
||||
*
|
||||
* Description:
|
||||
* Button interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_button_init(FAR const char *dev_path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_BUTTON */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_BUTTON_H */
|
162
graphics/lvgl/port/lv_port_encoder.c
Normal file
162
graphics/lvgl/port/lv_port_encoder.c
Normal file
@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_encoder.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/input/mouse.h>
|
||||
#include "lv_port_encoder.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct encoder_obj_s
|
||||
{
|
||||
int fd;
|
||||
lv_indev_state_t last_state;
|
||||
lv_indev_drv_t indev_drv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: encoder_read
|
||||
****************************************************************************/
|
||||
|
||||
static void encoder_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data)
|
||||
{
|
||||
FAR struct encoder_obj_s *encoder_obj = drv->user_data;
|
||||
|
||||
/* Read one sample */
|
||||
|
||||
struct mouse_report_s sample;
|
||||
int16_t wheel = 0;
|
||||
|
||||
int nbytes = read(encoder_obj->fd, &sample,
|
||||
sizeof(struct mouse_report_s));
|
||||
|
||||
/* Handle unexpected return values */
|
||||
|
||||
if (nbytes == sizeof(struct mouse_report_s))
|
||||
{
|
||||
wheel = sample.wheel;
|
||||
encoder_obj->last_state = (sample.buttons & MOUSE_BUTTON_3) ?
|
||||
LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
|
||||
/* Update encoder data */
|
||||
|
||||
data->enc_diff = wheel;
|
||||
data->state = encoder_obj->last_state;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: encoder_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_indev_t *encoder_init(int fd)
|
||||
{
|
||||
FAR struct encoder_obj_s *encoder_obj;
|
||||
encoder_obj = malloc(sizeof(struct encoder_obj_s));
|
||||
|
||||
if (encoder_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("encoder_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
encoder_obj->fd = fd;
|
||||
encoder_obj->last_state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
lv_indev_drv_init(&(encoder_obj->indev_drv));
|
||||
encoder_obj->indev_drv.type = LV_INDEV_TYPE_ENCODER;
|
||||
encoder_obj->indev_drv.read_cb = encoder_read;
|
||||
#if ( LV_USE_USER_DATA != 0 )
|
||||
encoder_obj->indev_drv.user_data = encoder_obj;
|
||||
#else
|
||||
#error LV_USE_USER_DATA must be enabled
|
||||
#endif
|
||||
return lv_indev_drv_register(&(encoder_obj->indev_drv));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_encoder_init
|
||||
*
|
||||
* Description:
|
||||
* Encoder interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path.
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_encoder_init(FAR const char *dev_path)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
FAR lv_indev_t *indev;
|
||||
int fd;
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_ENCODER_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("encoder %s opening", device_path);
|
||||
fd = open(device_path, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("encoder %s open failed: %d", device_path, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("encoder %s open success", device_path);
|
||||
|
||||
indev = encoder_init(fd);
|
||||
|
||||
if (indev == NULL)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return indev;
|
||||
}
|
80
graphics/lvgl/port/lv_port_encoder.h
Normal file
80
graphics/lvgl/port/lv_port_encoder.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_encoder.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_ENCODER_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_ENCODER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_ENCODER)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_encoder_init
|
||||
*
|
||||
* Description:
|
||||
* Encoder interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path.
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_encoder_init(FAR const char *dev_path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_ENCODER */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_ENCODER_H */
|
673
graphics/lvgl/port/lv_port_fbdev.c
Normal file
673
graphics/lvgl/port/lv_port_fbdev.c
Normal file
@ -0,0 +1,673 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_fbdev.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/video/rgbcolors.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "lv_port_fbdev.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_FB_UPDATE)
|
||||
# define FBDEV_UPDATE_AREA(obj, area) fbdev_update_area(obj, area)
|
||||
#else
|
||||
# define FBDEV_UPDATE_AREA(obj, area)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct fbdev_obj_s
|
||||
{
|
||||
lv_disp_draw_buf_t disp_draw_buf;
|
||||
lv_disp_drv_t disp_drv;
|
||||
FAR lv_disp_t *disp;
|
||||
FAR void *last_buffer;
|
||||
FAR void *act_buffer;
|
||||
lv_area_t inv_areas[LV_INV_BUF_SIZE];
|
||||
uint16_t inv_areas_len;
|
||||
lv_area_t final_area;
|
||||
|
||||
int fd;
|
||||
FAR void *fbmem;
|
||||
uint32_t fbmem2_yoffset;
|
||||
struct fb_videoinfo_s vinfo;
|
||||
struct fb_planeinfo_s pinfo;
|
||||
|
||||
bool double_buffer;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: buf_rotate_copy
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_FB_UPDATE)
|
||||
static void fbdev_update_area(FAR struct fbdev_obj_s *fbdev_obj,
|
||||
FAR const lv_area_t *area_p)
|
||||
{
|
||||
struct fb_area_s fb_area;
|
||||
|
||||
fb_area.x = area_p->x1;
|
||||
fb_area.y = area_p->y1;
|
||||
fb_area.w = area_p->x2 - area_p->x1 + 1;
|
||||
fb_area.h = area_p->y2 - area_p->y1 + 1;
|
||||
|
||||
LV_LOG_TRACE("area: (%d, %d) %d x %d",
|
||||
fb_area.x, fb_area.y, fb_area.w, fb_area.h);
|
||||
|
||||
ioctl(fbdev_obj->fd, FBIO_UPDATE,
|
||||
(unsigned long)((uintptr_t)&fb_area));
|
||||
|
||||
LV_LOG_TRACE("finished");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_copy_areas
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_copy_areas(FAR lv_color_t *fb_dest,
|
||||
FAR const lv_color_t *fb_src,
|
||||
FAR const lv_area_t *areas,
|
||||
uint16_t len,
|
||||
int fb_width)
|
||||
{
|
||||
int i;
|
||||
LV_LOG_TRACE("%p -> %p, len = %d", fb_src, fb_dest, len);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
int y;
|
||||
FAR const lv_area_t *area = &(areas[i]);
|
||||
int width = lv_area_get_width(area);
|
||||
int height = lv_area_get_height(area);
|
||||
FAR lv_color_t *dest_pos =
|
||||
fb_dest + area->y1 * fb_width + area->x1;
|
||||
FAR const lv_color_t *src_pos =
|
||||
fb_src + area->y1 * fb_width + area->x1;
|
||||
size_t hor_size = width * sizeof(lv_color_t);
|
||||
|
||||
LV_LOG_TRACE("area[%d]: (%d, %d) %d x %d",
|
||||
i, area->x1, area->y1, width, height);
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
lv_memcpy(dest_pos, src_pos, hor_size);
|
||||
dest_pos += fb_width;
|
||||
src_pos += fb_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_switch_buffer
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_switch_buffer(FAR struct fbdev_obj_s *fbdev_obj)
|
||||
{
|
||||
FAR lv_disp_t *disp_refr = fbdev_obj->disp;
|
||||
uint16_t inv_index;
|
||||
|
||||
/* check inv_areas_len, it must == 0 */
|
||||
|
||||
if (fbdev_obj->inv_areas_len != 0)
|
||||
{
|
||||
LV_LOG_ERROR("Repeated flush action detected! "
|
||||
"inv_areas_len(%d) != 0",
|
||||
fbdev_obj->inv_areas_len);
|
||||
fbdev_obj->inv_areas_len = 0;
|
||||
}
|
||||
|
||||
/* Save dirty area table for next synchronizationn */
|
||||
|
||||
for (inv_index = 0; inv_index < disp_refr->inv_p; inv_index++)
|
||||
{
|
||||
if (disp_refr->inv_area_joined[inv_index] == 0)
|
||||
{
|
||||
fbdev_obj->inv_areas[fbdev_obj->inv_areas_len] =
|
||||
disp_refr->inv_areas[inv_index];
|
||||
fbdev_obj->inv_areas_len++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the buffer address for the next synchronization */
|
||||
|
||||
fbdev_obj->last_buffer = fbdev_obj->act_buffer;
|
||||
|
||||
LV_LOG_TRACE("Commit buffer = %p, yoffset = %" PRIu32,
|
||||
fbdev_obj->act_buffer,
|
||||
fbdev_obj->pinfo.yoffset);
|
||||
|
||||
if (fbdev_obj->act_buffer == fbdev_obj->fbmem)
|
||||
{
|
||||
fbdev_obj->pinfo.yoffset = 0;
|
||||
fbdev_obj->act_buffer = fbdev_obj->fbmem
|
||||
+ fbdev_obj->fbmem2_yoffset * fbdev_obj->pinfo.stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
fbdev_obj->pinfo.yoffset = fbdev_obj->fbmem2_yoffset;
|
||||
fbdev_obj->act_buffer = fbdev_obj->fbmem;
|
||||
}
|
||||
|
||||
/* Commit buffer to fb driver */
|
||||
|
||||
ioctl(fbdev_obj->fd, FBIOPAN_DISPLAY,
|
||||
(unsigned long)((uintptr_t)&(fbdev_obj->pinfo)));
|
||||
|
||||
LV_LOG_TRACE("finished");
|
||||
}
|
||||
|
||||
#if defined(CONFIG_FB_SYNC)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_disp_vsync_refr
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_disp_vsync_refr(FAR lv_timer_t *timer)
|
||||
{
|
||||
int ret;
|
||||
FAR struct fbdev_obj_s *fbdev_obj = timer->user_data;
|
||||
|
||||
LV_LOG_TRACE("Check vsync...");
|
||||
|
||||
ret = ioctl(fbdev_obj->fd, FBIO_WAITFORVSYNC, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
LV_LOG_TRACE("No vsync signal detect");
|
||||
return;
|
||||
}
|
||||
|
||||
LV_LOG_TRACE("Refresh start");
|
||||
|
||||
_lv_disp_refr_timer(NULL);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FB_SYNC */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_render_start
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_render_start(FAR lv_disp_drv_t *disp_drv)
|
||||
{
|
||||
FAR struct fbdev_obj_s *fbdev_obj = disp_drv->user_data;
|
||||
FAR lv_disp_t *disp_refr;
|
||||
lv_coord_t hor_res;
|
||||
lv_coord_t ver_res;
|
||||
int i;
|
||||
|
||||
/* No need sync buffer when inv_areas_len == 0 */
|
||||
|
||||
if (fbdev_obj->inv_areas_len == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
disp_refr = _lv_refr_get_disp_refreshing();
|
||||
hor_res = disp_drv->hor_res;
|
||||
ver_res = disp_drv->ver_res;
|
||||
|
||||
for (i = 0; i < disp_refr->inv_p; i++)
|
||||
{
|
||||
if (disp_refr->inv_area_joined[i] == 0)
|
||||
{
|
||||
FAR const lv_area_t *area_p = &disp_refr->inv_areas[i];
|
||||
|
||||
/* If a full screen redraw is detected, skip dirty areas sync */
|
||||
|
||||
if (lv_area_get_width(area_p) == hor_res
|
||||
&& lv_area_get_height(area_p) == ver_res)
|
||||
{
|
||||
LV_LOG_TRACE("Full screen redraw, skip dirty areas sync");
|
||||
fbdev_obj->inv_areas_len = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sync the dirty area of the previous frame */
|
||||
|
||||
fbdev_copy_areas(fbdev_obj->act_buffer, fbdev_obj->last_buffer,
|
||||
fbdev_obj->inv_areas, fbdev_obj->inv_areas_len,
|
||||
fbdev_obj->vinfo.xres);
|
||||
|
||||
fbdev_obj->inv_areas_len = 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_flush_direct
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_flush_direct(FAR lv_disp_drv_t *disp_drv,
|
||||
FAR const lv_area_t *area_p,
|
||||
FAR lv_color_t *color_p)
|
||||
{
|
||||
FAR struct fbdev_obj_s *fbdev_obj = disp_drv->user_data;
|
||||
|
||||
/* Commit the buffer after the last flush */
|
||||
|
||||
if (!lv_disp_flush_is_last(disp_drv))
|
||||
{
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
return;
|
||||
}
|
||||
|
||||
fbdev_switch_buffer(fbdev_obj);
|
||||
|
||||
FBDEV_UPDATE_AREA(fbdev_obj, area_p);
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_update_part
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_update_part(FAR struct fbdev_obj_s *fbdev_obj,
|
||||
FAR lv_disp_drv_t *disp_drv,
|
||||
FAR const lv_area_t *area_p)
|
||||
{
|
||||
FAR lv_area_t *final_area = &fbdev_obj->final_area;
|
||||
|
||||
if (final_area->x1 < 0)
|
||||
{
|
||||
*final_area = *area_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lv_area_join(final_area, final_area, area_p);
|
||||
}
|
||||
|
||||
if (!lv_disp_flush_is_last(disp_drv))
|
||||
{
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fbdev_obj->double_buffer)
|
||||
{
|
||||
fbdev_switch_buffer(fbdev_obj);
|
||||
}
|
||||
|
||||
FBDEV_UPDATE_AREA(fbdev_obj, final_area);
|
||||
|
||||
/* Mark it is invalid */
|
||||
|
||||
final_area->x1 = -1;
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_flush_normal
|
||||
****************************************************************************/
|
||||
|
||||
static void fbdev_flush_normal(FAR lv_disp_drv_t *disp_drv,
|
||||
FAR const lv_area_t *area_p,
|
||||
FAR lv_color_t *color_p)
|
||||
{
|
||||
FAR struct fbdev_obj_s *fbdev_obj = disp_drv->user_data;
|
||||
|
||||
int x1 = area_p->x1;
|
||||
int y1 = area_p->y1;
|
||||
int y2 = area_p->y2;
|
||||
int y;
|
||||
int w = lv_area_get_width(area_p);
|
||||
|
||||
FAR lv_color_t *fbp = fbdev_obj->act_buffer;
|
||||
fb_coord_t fb_xres = fbdev_obj->vinfo.xres;
|
||||
int hor_size = w * sizeof(lv_color_t);
|
||||
FAR lv_color_t *cur_pos = fbp + y1 * fb_xres + x1;
|
||||
|
||||
LV_LOG_TRACE("start copy");
|
||||
|
||||
for (y = y1; y <= y2; y++)
|
||||
{
|
||||
lv_memcpy(cur_pos, color_p, hor_size);
|
||||
cur_pos += fb_xres;
|
||||
color_p += w;
|
||||
}
|
||||
|
||||
LV_LOG_TRACE("end copy");
|
||||
|
||||
fbdev_update_part(fbdev_obj, disp_drv, area_p);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_get_pinfo
|
||||
****************************************************************************/
|
||||
|
||||
static int fbdev_get_pinfo(int fd, FAR struct fb_planeinfo_s *pinfo)
|
||||
{
|
||||
int ret = ioctl(fd, FBIOGET_PLANEINFO,
|
||||
(unsigned long)((uintptr_t)pinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("PlaneInfo (plane %d):", pinfo->display);
|
||||
LV_LOG_INFO(" fbmem: %p", pinfo->fbmem);
|
||||
LV_LOG_INFO(" fblen: %lu", (unsigned long)pinfo->fblen);
|
||||
LV_LOG_INFO(" stride: %u", pinfo->stride);
|
||||
LV_LOG_INFO(" display: %u", pinfo->display);
|
||||
LV_LOG_INFO(" bpp: %u", pinfo->bpp);
|
||||
|
||||
/* Only these pixel depths are supported. viinfo.fmt is ignored, only
|
||||
* certain color formats are supported.
|
||||
*/
|
||||
|
||||
if (pinfo->bpp != 32 && pinfo->bpp != 16 &&
|
||||
pinfo->bpp != 8 && pinfo->bpp != 1)
|
||||
{
|
||||
LV_LOG_ERROR("bpp = %u not supported", pinfo->bpp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_try_init_fbmem2
|
||||
****************************************************************************/
|
||||
|
||||
static int fbdev_try_init_fbmem2(FAR struct fbdev_obj_s *state)
|
||||
{
|
||||
uintptr_t buf_offset;
|
||||
struct fb_planeinfo_s pinfo;
|
||||
|
||||
memset(&pinfo, 0, sizeof(pinfo));
|
||||
|
||||
/* Get display[1] planeinfo */
|
||||
|
||||
pinfo.display = state->pinfo.display + 1;
|
||||
|
||||
if (fbdev_get_pinfo(state->fd, &pinfo) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check display and match bpp */
|
||||
|
||||
if (!(pinfo.display != state->pinfo.display
|
||||
&& pinfo.bpp == state->pinfo.bpp))
|
||||
{
|
||||
LV_LOG_INFO("fbmem2 is incorrect");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check the buffer address offset,
|
||||
* It needs to be divisible by pinfo.stride
|
||||
*/
|
||||
|
||||
buf_offset = pinfo.fbmem - state->fbmem;
|
||||
|
||||
if ((buf_offset % state->pinfo.stride) != 0)
|
||||
{
|
||||
LV_LOG_ERROR("The buf_offset(%" PRIuPTR ") is incorrect,"
|
||||
" it needs to be divisible"
|
||||
" by pinfo.stride(%d)",
|
||||
buf_offset, state->pinfo.stride);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Enable double buffer mode */
|
||||
|
||||
state->double_buffer = true;
|
||||
state->fbmem2_yoffset = buf_offset / state->pinfo.stride;
|
||||
|
||||
LV_LOG_INFO("Use non-consecutive fbmem2 = %p, yoffset = %" PRIu32,
|
||||
pinfo.fbmem, state->fbmem2_yoffset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fbdev_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_disp_t *fbdev_init(FAR struct fbdev_obj_s *state)
|
||||
{
|
||||
FAR struct fbdev_obj_s *fbdev_obj = malloc(sizeof(struct fbdev_obj_s));
|
||||
FAR lv_disp_drv_t *disp_drv;
|
||||
int fb_xres = state->vinfo.xres;
|
||||
int fb_yres = state->vinfo.yres;
|
||||
size_t fb_size = fb_xres * fb_yres;
|
||||
FAR lv_color_t *buf1 = NULL;
|
||||
FAR lv_color_t *buf2 = NULL;
|
||||
|
||||
if (fbdev_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("fbdev_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*fbdev_obj = *state;
|
||||
disp_drv = &(fbdev_obj->disp_drv);
|
||||
|
||||
lv_disp_drv_init(disp_drv);
|
||||
disp_drv->draw_buf = &(fbdev_obj->disp_draw_buf);
|
||||
disp_drv->screen_transp = false;
|
||||
disp_drv->user_data = fbdev_obj;
|
||||
disp_drv->hor_res = fb_xres;
|
||||
disp_drv->ver_res = fb_yres;
|
||||
|
||||
if (fbdev_obj->double_buffer)
|
||||
{
|
||||
LV_LOG_INFO("Double buffer mode");
|
||||
|
||||
buf1 = fbdev_obj->fbmem;
|
||||
buf2 = fbdev_obj->fbmem
|
||||
+ fbdev_obj->fbmem2_yoffset * fbdev_obj->pinfo.stride;
|
||||
|
||||
disp_drv->direct_mode = true;
|
||||
disp_drv->flush_cb = fbdev_flush_direct;
|
||||
disp_drv->render_start_cb = fbdev_render_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
LV_LOG_INFO("Single buffer mode");
|
||||
|
||||
buf1 = malloc(fb_size * sizeof(lv_color_t));
|
||||
LV_ASSERT_MALLOC(buf1);
|
||||
|
||||
if (!buf1)
|
||||
{
|
||||
LV_LOG_ERROR("failed to malloc draw buffer");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
disp_drv->flush_cb = fbdev_flush_normal;
|
||||
}
|
||||
|
||||
lv_disp_draw_buf_init(&(fbdev_obj->disp_draw_buf), buf1, buf2, fb_size);
|
||||
fbdev_obj->act_buffer = fbdev_obj->fbmem;
|
||||
fbdev_obj->disp = lv_disp_drv_register(&(fbdev_obj->disp_drv));
|
||||
|
||||
#if defined(CONFIG_FB_SYNC)
|
||||
/* If double buffer and vsync is supported, use active refresh method */
|
||||
|
||||
if (fbdev_obj->disp_drv.direct_mode)
|
||||
{
|
||||
FAR lv_timer_t *refr_timer = _lv_disp_get_refr_timer(fbdev_obj->disp);
|
||||
lv_timer_del(refr_timer);
|
||||
fbdev_obj->disp->refr_timer = NULL;
|
||||
lv_timer_create(fbdev_disp_vsync_refr, 1, fbdev_obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
return fbdev_obj->disp;
|
||||
|
||||
failed:
|
||||
free(fbdev_obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_fbdev_init
|
||||
*
|
||||
* Description:
|
||||
* Framebuffer device interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - Framebuffer device path, set to NULL to use the default path.
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_disp object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_disp_t *lv_port_fbdev_init(FAR const char *dev_path)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
struct fbdev_obj_s state;
|
||||
int ret;
|
||||
FAR lv_disp_t *disp;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_FBDEV_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("fbdev %s opening", device_path);
|
||||
|
||||
state.fd = open(device_path, O_RDWR);
|
||||
if (state.fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("fbdev %s open failed: %d", device_path, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the characteristics of the framebuffer */
|
||||
|
||||
ret = ioctl(state.fd, FBIOGET_VIDEOINFO,
|
||||
(unsigned long)((uintptr_t)&state.vinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("ioctl(FBIOGET_VIDEOINFO) failed: %d", errno);
|
||||
close(state.fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("VideoInfo:");
|
||||
LV_LOG_INFO(" fmt: %u", state.vinfo.fmt);
|
||||
LV_LOG_INFO(" xres: %u", state.vinfo.xres);
|
||||
LV_LOG_INFO(" yres: %u", state.vinfo.yres);
|
||||
LV_LOG_INFO(" nplanes: %u", state.vinfo.nplanes);
|
||||
|
||||
ret = fbdev_get_pinfo(state.fd, &state.pinfo);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
close(state.fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check color depth */
|
||||
|
||||
if (!(state.pinfo.bpp == LV_COLOR_DEPTH ||
|
||||
(state.pinfo.bpp == 24 && LV_COLOR_DEPTH == 32)))
|
||||
{
|
||||
LV_LOG_ERROR("fbdev bpp = %d, LV_COLOR_DEPTH = %d, "
|
||||
"color depth does not match.",
|
||||
state.pinfo.bpp, LV_COLOR_DEPTH);
|
||||
close(state.fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state.double_buffer = (state.pinfo.yres_virtual == (state.vinfo.yres * 2));
|
||||
|
||||
/* mmap() the framebuffer.
|
||||
*
|
||||
* NOTE: In the FLAT build the frame buffer address returned by the
|
||||
* FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer
|
||||
* address. mmap(), however, is the preferred way to get the framebuffer
|
||||
* address because in the KERNEL build, it will perform the necessary
|
||||
* address mapping to make the memory accessible to the application.
|
||||
*/
|
||||
|
||||
state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FILE, state.fd, 0);
|
||||
if (state.fbmem == MAP_FAILED)
|
||||
{
|
||||
LV_LOG_ERROR("ioctl(FBIOGET_PLANEINFO) failed: %d", errno);
|
||||
close(state.fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("Mapped FB: %p", state.fbmem);
|
||||
|
||||
if (state.double_buffer)
|
||||
{
|
||||
state.fbmem2_yoffset = state.vinfo.yres;
|
||||
}
|
||||
else
|
||||
{
|
||||
fbdev_try_init_fbmem2(&state);
|
||||
}
|
||||
|
||||
disp = fbdev_init(&state);
|
||||
|
||||
if (!disp)
|
||||
{
|
||||
munmap(state.fbmem, state.pinfo.fblen);
|
||||
close(state.fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return disp;
|
||||
}
|
80
graphics/lvgl/port/lv_port_fbdev.h
Normal file
80
graphics/lvgl/port/lv_port_fbdev.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_fbdev.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_FBDEV_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_FBDEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_FBDEV)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_fbdev_init
|
||||
*
|
||||
* Description:
|
||||
* Framebuffer device interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - Framebuffer device path, set to NULL to use the default path.
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_disp object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_disp_t *lv_port_fbdev_init(FAR const char *dev_path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_FBDEV */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_FBDEV_H */
|
251
graphics/lvgl/port/lv_port_keypad.c
Normal file
251
graphics/lvgl/port/lv_port_keypad.c
Normal file
@ -0,0 +1,251 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_keypad.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/input/buttons.h>
|
||||
#include "lv_port_keypad.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define LV_KEY_UP_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_UP_MAP_BIT
|
||||
#define LV_KEY_DOWN_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT
|
||||
#define LV_KEY_RIGHT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT
|
||||
#define LV_KEY_LEFT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT
|
||||
|
||||
#define LV_KEY_ESC_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ESC_MAP_BIT
|
||||
#define LV_KEY_DEL_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DEL_MAP_BIT
|
||||
#define LV_KEY_BACKSPACE_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT
|
||||
#define LV_KEY_ENTER_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT
|
||||
|
||||
#define LV_KEY_NEXT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT
|
||||
#define LV_KEY_PREV_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_PREV_MAP_BIT
|
||||
#define LV_KEY_HOME_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_HOME_MAP_BIT
|
||||
#define LV_KEY_END_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_END_MAP_BIT
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct keypad_map_s
|
||||
{
|
||||
const lv_key_t key;
|
||||
int bit;
|
||||
};
|
||||
|
||||
struct keypad_obj_s
|
||||
{
|
||||
int fd;
|
||||
uint32_t last_key;
|
||||
lv_indev_drv_t indev_drv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct keypad_map_s g_keypad_map[] =
|
||||
{
|
||||
{LV_KEY_UP, LV_KEY_UP_MAP_BIT},
|
||||
{LV_KEY_DOWN, LV_KEY_DOWN_MAP_BIT},
|
||||
{LV_KEY_RIGHT, LV_KEY_RIGHT_MAP_BIT},
|
||||
{LV_KEY_LEFT, LV_KEY_LEFT_MAP_BIT},
|
||||
{LV_KEY_ESC, LV_KEY_ESC_MAP_BIT},
|
||||
{LV_KEY_DEL, LV_KEY_DEL_MAP_BIT},
|
||||
{LV_KEY_BACKSPACE, LV_KEY_BACKSPACE_MAP_BIT},
|
||||
{LV_KEY_ENTER, LV_KEY_ENTER_MAP_BIT},
|
||||
{LV_KEY_NEXT, LV_KEY_NEXT_MAP_BIT},
|
||||
{LV_KEY_PREV, LV_KEY_PREV_MAP_BIT},
|
||||
{LV_KEY_HOME, LV_KEY_HOME_MAP_BIT},
|
||||
{LV_KEY_END, LV_KEY_END_MAP_BIT}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: keypad_get_key
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t keypad_get_key(int fd)
|
||||
{
|
||||
uint32_t act_key = 0;
|
||||
btn_buttonset_t buttonset;
|
||||
const int buttonset_bits = sizeof(btn_buttonset_t) * 8;
|
||||
int i;
|
||||
|
||||
int ret = read(fd, &buttonset, sizeof(btn_buttonset_t));
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++)
|
||||
{
|
||||
int bit = g_keypad_map[i].bit;
|
||||
|
||||
if (bit >= 0 && bit < buttonset_bits)
|
||||
{
|
||||
btn_buttonset_t mask = (btn_buttonset_t)(1 << bit);
|
||||
if ((buttonset & mask) != 0)
|
||||
{
|
||||
act_key = g_keypad_map[i].key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return act_key;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: keypad_read
|
||||
****************************************************************************/
|
||||
|
||||
static void keypad_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data)
|
||||
{
|
||||
FAR struct keypad_obj_s *keypad_obj = drv->user_data;
|
||||
|
||||
/* Get whether the a key is pressed and save the pressed key */
|
||||
|
||||
uint32_t act_key = keypad_get_key(keypad_obj->fd);
|
||||
|
||||
if (act_key != 0)
|
||||
{
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
keypad_obj->last_key = act_key;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
data->key = keypad_obj->last_key;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: keypad_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_indev_t *keypad_init(int fd)
|
||||
{
|
||||
FAR struct keypad_obj_s *keypad_obj;
|
||||
keypad_obj = malloc(sizeof(struct keypad_obj_s));
|
||||
|
||||
if (keypad_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("keypad_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
keypad_obj->fd = fd;
|
||||
keypad_obj->last_key = 0;
|
||||
|
||||
/* Register a keypad input device */
|
||||
|
||||
lv_indev_drv_init(&(keypad_obj->indev_drv));
|
||||
keypad_obj->indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
||||
keypad_obj->indev_drv.read_cb = keypad_read;
|
||||
#if ( LV_USE_USER_DATA != 0 )
|
||||
keypad_obj->indev_drv.user_data = keypad_obj;
|
||||
#else
|
||||
#error LV_USE_USER_DATA must be enabled
|
||||
#endif
|
||||
return lv_indev_drv_register(&(keypad_obj->indev_drv));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_keypad_init
|
||||
*
|
||||
* Description:
|
||||
* Keypad interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_keypad_init(FAR const char *dev_path)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
FAR lv_indev_t *indev;
|
||||
int fd;
|
||||
int ret;
|
||||
btn_buttonset_t supported;
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_KEYPAD_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("keypad %s opening", device_path);
|
||||
fd = open(device_path, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("keypad %s open failed: %d", device_path, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the set of BUTTONs supported */
|
||||
|
||||
ret = ioctl(fd, BTNIOC_SUPPORTED,
|
||||
(unsigned long)((uintptr_t)&supported));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("button ioctl(BTNIOC_SUPPORTED) failed: %d",
|
||||
errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("button supported BUTTONs 0x%08x", (unsigned int)supported);
|
||||
|
||||
indev = keypad_init(fd);
|
||||
|
||||
if (indev == NULL)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return indev;
|
||||
}
|
76
graphics/lvgl/port/lv_port_keypad.h
Normal file
76
graphics/lvgl/port/lv_port_keypad.h
Normal file
@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_keypad.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_KEYPAD_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_KEYPAD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_KEYPAD)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_keypad_init
|
||||
*
|
||||
* Description:
|
||||
* Keypad interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_keypad_init(FAR const char *dev_path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_KEYPAD */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_KEYPAD_H */
|
302
graphics/lvgl/port/lv_port_lcddev.c
Normal file
302
graphics/lvgl/port/lv_port_lcddev.c
Normal file
@ -0,0 +1,302 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_lcddev.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/lcd/lcd_dev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include "lv_port_lcddev.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct lcddev_obj_s
|
||||
{
|
||||
int fd;
|
||||
lv_disp_draw_buf_t disp_draw_buf;
|
||||
lv_disp_drv_t disp_drv;
|
||||
struct lcddev_area_s area;
|
||||
|
||||
pthread_t write_thread;
|
||||
sem_t flush_sem;
|
||||
sem_t wait_sem;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_wait
|
||||
****************************************************************************/
|
||||
|
||||
static void lcddev_wait(FAR lv_disp_drv_t *disp_drv)
|
||||
{
|
||||
FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data;
|
||||
|
||||
sem_wait(&(lcddev_obj->wait_sem));
|
||||
|
||||
/* Tell the flushing is ready */
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_update_thread
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *lcddev_update_thread(FAR void *arg)
|
||||
{
|
||||
int ret = OK;
|
||||
int errcode = 0;
|
||||
FAR struct lcddev_obj_s *lcddev_obj = arg;
|
||||
|
||||
while (ret == OK)
|
||||
{
|
||||
sem_wait(&lcddev_obj->flush_sem);
|
||||
|
||||
ret = ioctl(lcddev_obj->fd, LCDDEVIO_PUTAREA,
|
||||
(unsigned long)&(lcddev_obj->area));
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
}
|
||||
|
||||
sem_post(&lcddev_obj->wait_sem);
|
||||
}
|
||||
|
||||
LV_LOG_ERROR("ioctl(LCDDEVIO_PUTAREA) failed: %d", errcode);
|
||||
close(lcddev_obj->fd);
|
||||
lcddev_obj->fd = -1;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_flush
|
||||
****************************************************************************/
|
||||
|
||||
static void lcddev_flush(FAR lv_disp_drv_t *disp_drv,
|
||||
FAR const lv_area_t *area_p,
|
||||
FAR lv_color_t *color_p)
|
||||
{
|
||||
FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data;
|
||||
|
||||
lcddev_obj->area.row_start = area_p->y1;
|
||||
lcddev_obj->area.row_end = area_p->y2;
|
||||
lcddev_obj->area.col_start = area_p->x1;
|
||||
lcddev_obj->area.col_end = area_p->x2;
|
||||
lcddev_obj->area.data = (FAR uint8_t *)color_p;
|
||||
|
||||
sem_post(&lcddev_obj->flush_sem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddev_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_disp_t *lcddev_init(int fd,
|
||||
int hor_res,
|
||||
int ver_res,
|
||||
int line_buf)
|
||||
{
|
||||
FAR lv_color_t *buf1 = NULL;
|
||||
FAR lv_color_t *buf2 = NULL;
|
||||
FAR struct lcddev_obj_s *lcddev_obj;
|
||||
const size_t buf_size = hor_res * line_buf * sizeof(lv_color_t);
|
||||
lcddev_obj = malloc(sizeof(struct lcddev_obj_s));
|
||||
|
||||
if (lcddev_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("lcddev_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf1 = malloc(buf_size);
|
||||
if (buf1 == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("display buf1 malloc failed");
|
||||
free(lcddev_obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LV_PORT_LCDDEV_DOUBLE_BUFFER
|
||||
buf2 = malloc(buf_size);
|
||||
if (buf2 == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("display buf2 malloc failed");
|
||||
free(lcddev_obj);
|
||||
free(buf1);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
LV_LOG_INFO("display buffer malloc success, buf size = %lu", buf_size);
|
||||
|
||||
lcddev_obj->fd = fd;
|
||||
|
||||
lv_disp_draw_buf_init(&(lcddev_obj->disp_draw_buf), buf1, buf2,
|
||||
hor_res * line_buf);
|
||||
|
||||
lv_disp_drv_init(&(lcddev_obj->disp_drv));
|
||||
lcddev_obj->disp_drv.flush_cb = lcddev_flush;
|
||||
lcddev_obj->disp_drv.draw_buf = &(lcddev_obj->disp_draw_buf);
|
||||
lcddev_obj->disp_drv.hor_res = hor_res;
|
||||
lcddev_obj->disp_drv.ver_res = ver_res;
|
||||
lcddev_obj->disp_drv.screen_transp = false;
|
||||
#if ( LV_USE_USER_DATA != 0 )
|
||||
lcddev_obj->disp_drv.user_data = lcddev_obj;
|
||||
#else
|
||||
#error LV_USE_USER_DATA must be enabled
|
||||
#endif
|
||||
lcddev_obj->disp_drv.wait_cb = lcddev_wait;
|
||||
|
||||
/* Initialize the mutexes for buffer flushing synchronization */
|
||||
|
||||
sem_init(&lcddev_obj->flush_sem, 0, 0);
|
||||
sem_init(&lcddev_obj->wait_sem, 0, 0);
|
||||
|
||||
/* Initialize the buffer flushing thread */
|
||||
|
||||
pthread_create(&(lcddev_obj->write_thread), NULL,
|
||||
lcddev_update_thread, lcddev_obj);
|
||||
|
||||
return lv_disp_drv_register(&(lcddev_obj->disp_drv));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_lcddev_init
|
||||
*
|
||||
* Description:
|
||||
* Lcd interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - lcd device path, set to NULL to use the default path
|
||||
* line_buf - Number of line buffers,
|
||||
* set to 0 to use the default line buffer
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_disp object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_disp_t *lv_port_lcddev_init(FAR const char *dev_path, int line_buf)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
int line_buffer = line_buf;
|
||||
int fd;
|
||||
int ret;
|
||||
FAR lv_disp_t *disp;
|
||||
|
||||
struct fb_videoinfo_s vinfo;
|
||||
struct lcd_planeinfo_s pinfo;
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_LCDDEV_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("lcddev %s opening", device_path);
|
||||
fd = open(device_path, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("lcddev open failed: %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("lcddev %s open success", device_path);
|
||||
|
||||
ret = ioctl(fd, LCDDEVIO_GETVIDEOINFO,
|
||||
(unsigned long)((uintptr_t)&vinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("ioctl(LCDDEVIO_GETVIDEOINFO) failed: %d", errno);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("VideoInfo:");
|
||||
LV_LOG_INFO(" fmt: %u", vinfo.fmt);
|
||||
LV_LOG_INFO(" xres: %u", vinfo.xres);
|
||||
LV_LOG_INFO(" yres: %u", vinfo.yres);
|
||||
LV_LOG_INFO(" nplanes: %u", vinfo.nplanes);
|
||||
|
||||
ret = ioctl(fd, LCDDEVIO_GETPLANEINFO,
|
||||
(unsigned long)((uintptr_t)&pinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
LV_LOG_ERROR("ERROR: ioctl(LCDDEVIO_GETPLANEINFO) failed: %d",
|
||||
errno);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("PlaneInfo:");
|
||||
LV_LOG_INFO(" bpp: %u", pinfo.bpp);
|
||||
|
||||
if (pinfo.bpp != LV_COLOR_DEPTH)
|
||||
{
|
||||
LV_LOG_ERROR("lcddev bpp = %d, LV_COLOR_DEPTH = %d,"
|
||||
" color depth does not match", pinfo.bpp, LV_COLOR_DEPTH);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LV_PORT_LCDDEV_FULL_SCREEN_BUFFER
|
||||
line_buffer = vinfo.yres;
|
||||
#else
|
||||
if (line_buffer <= 0)
|
||||
{
|
||||
line_buffer = CONFIG_LV_PORT_LCDDEV_LINE_BUFFER_DEFAULT;
|
||||
}
|
||||
#endif
|
||||
|
||||
disp = lcddev_init(fd, vinfo.xres, vinfo.yres,
|
||||
line_buffer);
|
||||
if (disp == NULL)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return disp;
|
||||
}
|
82
graphics/lvgl/port/lv_port_lcddev.h
Normal file
82
graphics/lvgl/port/lv_port_lcddev.h
Normal file
@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_lcddev.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_LCDDEV_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_LCDDEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_LCDDEV)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_lcddev_init
|
||||
*
|
||||
* Description:
|
||||
* lcddev interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - lcd device path, set to NULL to use the default path
|
||||
* line_buf - Number of line buffers,
|
||||
* set to 0 to use the default line buffer
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_disp object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_disp_t *lv_port_lcddev_init(FAR const char *dev_path, int line_buf);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_LCDDEV */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_LCDDEV_H */
|
173
graphics/lvgl/port/lv_port_mem.c
Normal file
173
graphics/lvgl/port/lv_port_mem.c
Normal file
@ -0,0 +1,173 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_mem.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/mm/mm.h>
|
||||
#include "lv_port_mem.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
typedef CODE void *(*malloc_func_t)(FAR struct mm_heap_s *heap, size_t size);
|
||||
typedef CODE void *(*realloc_func_t)(FAR struct mm_heap_s *heap,
|
||||
FAR void *oldmem, size_t size);
|
||||
typedef CODE void *(*memalign_func_t)(FAR struct mm_heap_s *heap,
|
||||
size_t alignment, size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *malloc_first(FAR struct mm_heap_s *heap, size_t size);
|
||||
static FAR void *realloc_first(FAR struct mm_heap_s *heap,
|
||||
FAR void *oldmem, size_t size);
|
||||
static FAR void *memalign_first(FAR struct mm_heap_s *heap,
|
||||
size_t alignment, size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct mm_heap_s *g_lv_heap = NULL;
|
||||
static malloc_func_t g_malloc_func = malloc_first;
|
||||
static realloc_func_t g_realloc_func = realloc_first;
|
||||
static memalign_func_t g_memalign_func = memalign_first;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_init
|
||||
*
|
||||
* Description:
|
||||
* Memory interface initialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void lv_port_mem_init(void)
|
||||
{
|
||||
static uint32_t heap_buf[CONFIG_LV_PORT_MEM_CUSTOM_SIZE
|
||||
* 1024 / sizeof(uint32_t)];
|
||||
g_lv_heap = mm_initialize(CONFIG_LV_PORT_MEM_CUSTOM_NAME,
|
||||
heap_buf, sizeof(heap_buf));
|
||||
LV_ASSERT_NULL(g_lv_heap);
|
||||
if (g_lv_heap == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("NO memory for "
|
||||
CONFIG_LV_PORT_MEM_CUSTOM_NAME
|
||||
" heap");
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: malloc_first
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *malloc_first(FAR struct mm_heap_s *heap, size_t size)
|
||||
{
|
||||
if (g_lv_heap == NULL)
|
||||
{
|
||||
lv_port_mem_init();
|
||||
}
|
||||
|
||||
g_malloc_func = mm_malloc;
|
||||
return g_malloc_func(g_lv_heap, size);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: realloc_first
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *realloc_first(FAR struct mm_heap_s *heap,
|
||||
FAR void *oldmem, size_t size)
|
||||
{
|
||||
if (g_lv_heap == NULL)
|
||||
{
|
||||
lv_port_mem_init();
|
||||
}
|
||||
|
||||
g_realloc_func = mm_realloc;
|
||||
return g_realloc_func(g_lv_heap, oldmem, size);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: memalign_first
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *memalign_first(FAR struct mm_heap_s *heap,
|
||||
size_t alignment, size_t size)
|
||||
{
|
||||
if (g_lv_heap == NULL)
|
||||
{
|
||||
lv_port_mem_init();
|
||||
}
|
||||
|
||||
g_memalign_func = mm_memalign;
|
||||
return g_memalign_func(g_lv_heap, alignment, size);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_alloc
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_port_mem_alloc(size_t size)
|
||||
{
|
||||
return g_malloc_func(g_lv_heap, size);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_free
|
||||
****************************************************************************/
|
||||
|
||||
void lv_port_mem_free(FAR void *mem)
|
||||
{
|
||||
mm_free(g_lv_heap, mem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_realloc
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_port_mem_realloc(FAR void *oldmem, size_t size)
|
||||
{
|
||||
return g_realloc_func(g_lv_heap, oldmem, size);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_mem_custom_memalign
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_mem_custom_memalign(size_t alignment, size_t size)
|
||||
{
|
||||
return g_memalign_func(g_lv_heap, alignment, size);
|
||||
}
|
92
graphics/lvgl/port/lv_port_mem.h
Normal file
92
graphics/lvgl/port/lv_port_mem.h
Normal file
@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_mem.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_MEM_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_MEM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LV_PORT_MEM_CUSTOM_SIZE
|
||||
# define CONFIG_LV_PORT_MEM_CUSTOM_SIZE 0
|
||||
#endif
|
||||
|
||||
#if CONFIG_LV_PORT_MEM_CUSTOM_SIZE
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_alloc
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_port_mem_alloc(size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_free
|
||||
****************************************************************************/
|
||||
|
||||
void lv_port_mem_free(FAR void *mem);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_realloc
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_port_mem_realloc(FAR void *oldmem, size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_mem_memalign
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *lv_port_mem_memalign(size_t alignment, size_t size);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_MEM_CUSTOM_SIZE */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_MEM_H */
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/lcddev.h
|
||||
* apps/graphics/lvgl/port/lv_port_syslog.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -18,29 +18,40 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H
|
||||
#define __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include <syslog.h>
|
||||
#include "lv_port_syslog.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
int lcddev_init(lv_disp_drv_t *lv_drvr);
|
||||
/****************************************************************************
|
||||
* Name: syslog_print_cb
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static void syslog_print_cb(FAR const char *buf)
|
||||
{
|
||||
syslog(LOG_INFO, "[LVGL] %s", buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H */
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_syslog_init
|
||||
*
|
||||
* Description:
|
||||
* Syslog interface initialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void lv_port_syslog_init(void)
|
||||
{
|
||||
lv_log_register_print_cb(syslog_print_cb);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/lvgldemo/tp_cal.h
|
||||
* apps/graphics/lvgl/port/lv_port_syslog.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -18,36 +18,56 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H
|
||||
#define __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_SYSLOG_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_SYSLOG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_USE_LOG)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tp_cal_create
|
||||
* Name: lv_port_syslog_init
|
||||
*
|
||||
* Description:
|
||||
* Create a touchpad calibration screen
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* Syslog interface initialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tp_cal_create(void);
|
||||
void lv_port_syslog_init(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H */
|
||||
#endif /* CONFIG_LV_USE_LOG */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_SYSLOG_H */
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/lv_tick_interface.c
|
||||
* apps/graphics/lvgl/port/lv_port_tick.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -23,8 +23,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include "lv_tick_interface.h"
|
||||
#include <time.h>
|
||||
#include "lv_port_tick.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -50,24 +50,12 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t lv_tick_interface(void)
|
||||
uint32_t millis(void)
|
||||
{
|
||||
static bool first_time = true;
|
||||
static struct timeval t0;
|
||||
struct timespec ts;
|
||||
|
||||
if (first_time)
|
||||
{
|
||||
gettimeofday(&t0, NULL);
|
||||
first_time = false;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct timeval t;
|
||||
struct timeval delta;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
uint32_t tick = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
timersub(&t, &t0, &delta);
|
||||
return delta.tv_sec * 1000 + delta.tv_usec / 1000;
|
||||
}
|
||||
return tick;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/lv_tick_interface.h
|
||||
* apps/graphics/lvgl/port/lv_port_tick.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -18,15 +18,14 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LV_TICK_INTERFACE_H
|
||||
#define __APPS_GRAPHICS_LV_TICK_INTERFACE_H
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TICK_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TICK_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -52,11 +51,11 @@ extern "C"
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t lv_tick_interface(void);
|
||||
uint32_t millis(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __APPS_GRAPHICS_LV_TICK_INTERFACE_H
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TICK_H */
|
178
graphics/lvgl/port/lv_port_touchpad.c
Normal file
178
graphics/lvgl/port/lv_port_touchpad.c
Normal file
@ -0,0 +1,178 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_touchpad.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/input/touchscreen.h>
|
||||
#include "lv_port_touchpad.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct touchpad_obj_s
|
||||
{
|
||||
int fd;
|
||||
lv_coord_t last_x;
|
||||
lv_coord_t last_y;
|
||||
lv_indev_state_t last_state;
|
||||
lv_indev_drv_t indev_drv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: touchpad_read
|
||||
****************************************************************************/
|
||||
|
||||
static void touchpad_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data)
|
||||
{
|
||||
FAR struct touchpad_obj_s *touchpad_obj = drv->user_data;
|
||||
struct touch_sample_s sample;
|
||||
|
||||
/* Read one sample */
|
||||
|
||||
int nbytes = read(touchpad_obj->fd, &sample,
|
||||
sizeof(struct touch_sample_s));
|
||||
|
||||
/* Handle unexpected return values */
|
||||
|
||||
if (nbytes == sizeof(struct touch_sample_s))
|
||||
{
|
||||
uint8_t touch_flags = sample.point[0].flags;
|
||||
|
||||
if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
|
||||
{
|
||||
const FAR lv_disp_drv_t *disp_drv = drv->disp->driver;
|
||||
lv_coord_t ver_max = disp_drv->ver_res - 1;
|
||||
lv_coord_t hor_max = disp_drv->hor_res - 1;
|
||||
|
||||
touchpad_obj->last_x = LV_CLAMP(0, sample.point[0].x, hor_max);
|
||||
touchpad_obj->last_y = LV_CLAMP(0, sample.point[0].y, ver_max);
|
||||
touchpad_obj->last_state = LV_INDEV_STATE_PR;
|
||||
}
|
||||
else if (touch_flags & TOUCH_UP)
|
||||
{
|
||||
touchpad_obj->last_state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update touchpad data */
|
||||
|
||||
data->point.x = touchpad_obj->last_x;
|
||||
data->point.y = touchpad_obj->last_y;
|
||||
data->state = touchpad_obj->last_state;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: touchpad_init
|
||||
****************************************************************************/
|
||||
|
||||
static FAR lv_indev_t *touchpad_init(int fd)
|
||||
{
|
||||
FAR struct touchpad_obj_s *touchpad_obj;
|
||||
touchpad_obj = malloc(sizeof(struct touchpad_obj_s));
|
||||
|
||||
if (touchpad_obj == NULL)
|
||||
{
|
||||
LV_LOG_ERROR("touchpad_obj_s malloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
touchpad_obj->fd = fd;
|
||||
touchpad_obj->last_x = 0;
|
||||
touchpad_obj->last_y = 0;
|
||||
touchpad_obj->last_state = LV_INDEV_STATE_REL;
|
||||
|
||||
lv_indev_drv_init(&(touchpad_obj->indev_drv));
|
||||
touchpad_obj->indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
touchpad_obj->indev_drv.read_cb = touchpad_read;
|
||||
#if ( LV_USE_USER_DATA != 0 )
|
||||
touchpad_obj->indev_drv.user_data = touchpad_obj;
|
||||
#else
|
||||
#error LV_USE_USER_DATA must be enabled
|
||||
#endif
|
||||
return lv_indev_drv_register(&(touchpad_obj->indev_drv));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_touchpad_init
|
||||
*
|
||||
* Description:
|
||||
* Touchpad interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_touchpad_init(FAR const char *dev_path)
|
||||
{
|
||||
FAR const char *device_path = dev_path;
|
||||
FAR lv_indev_t *indev;
|
||||
int fd;
|
||||
|
||||
if (device_path == NULL)
|
||||
{
|
||||
device_path = CONFIG_LV_PORT_TOUCHPAD_DEFAULT_DEVICEPATH;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("touchpad %s opening", device_path);
|
||||
fd = open(device_path, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
LV_LOG_ERROR("touchpad %s open failed: %d", device_path, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("touchpad %s open success", device_path);
|
||||
|
||||
indev = touchpad_init(fd);
|
||||
|
||||
if (indev == NULL)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return indev;
|
||||
}
|
80
graphics/lvgl/port/lv_port_touchpad.h
Normal file
80
graphics/lvgl/port/lv_port_touchpad.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/lvgl/port/lv_port_touchpad.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TOUCHPAD_H
|
||||
#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TOUCHPAD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LV_PORT_USE_TOUCHPAD)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lv_port_touchpad_init
|
||||
*
|
||||
* Description:
|
||||
* Touchpad interface initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev_path - input device path, set to NULL to use the default path
|
||||
*
|
||||
* Returned Value:
|
||||
* lv_indev object address on success; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR lv_indev_t *lv_port_touchpad_init(FAR const char *dev_path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LV_PORT_USE_TOUCHPAD */
|
||||
|
||||
#endif /* __APPS_GRAPHICS_LVGL_PORT_LV_PORT_TOUCHPAD_H */
|
Loading…
x
Reference in New Issue
Block a user