# Copyright (c) 2018-2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
# SPDX-License-Identifier: Apache-2.0

menuconfig LVGL
	bool "LittlevGL GUI library"
	help
	  This option enables the LittlevGL GUI library.

if LVGL

module = LVGL
module-str = lvgl
source "subsys/logging/Kconfig.template.log_config"

config LVGL_DISPLAY_DEV_NAME
	string "Display device name"
	default "DISPLAY"
	help
	  Name of the display device to use for rendering.

config LVGL_POINTER_KSCAN
	bool "Keyboard scan pointer input"
	depends on KSCAN
	help
	  Enable keyboard scan pointer input

if LVGL_POINTER_KSCAN

config LVGL_POINTER_KSCAN_DEV_NAME
	string "Keyboard scan device name for pointer input"
	default "KSCAN"
	help
	  Name of the keyboard scan device to use for pointer input.

config LVGL_POINTER_KSCAN_MSGQ_COUNT
	int "Keyboard scan message queue count maximum"
	default 10
	help
	  Maximum number of items in the keyboard scan message queue.

endif # LVGL_POINTER_KSCAN

config LVGL_HOR_RES
	int "Horizontal Screen Resolution"
	default 320
	help
	  Horizontal screen resolution in pixels

config LVGL_VER_RES
	int "Vertical Screen Resolution"
	default 240
	help
	  Vertical screen resolution in pixels

config LVGL_DPI
	int "DPI"
	default 100
	help
	  Dots per inch (DPI)

choice LVGL_COLOR_DEPTH
	prompt "Color Depth"
	default LVGL_COLOR_DEPTH_32
	help
	  Color depth to be used by library

	config LVGL_COLOR_DEPTH_32
		bool "32-bit"

	config LVGL_COLOR_DEPTH_16
		bool "16-bit"

	config LVGL_COLOR_DEPTH_8
		bool "8-bit"

	config LVGL_COLOR_DEPTH_1
		bool "1-bit"

endchoice

config LVGL_BITS_PER_PIXEL
	int "Bits per pixel"
	default 32
	range 1 32
	depends on LVGL_BUFFER_ALLOC_STATIC
	help
	  Number of bits per pixel.

config LVGL_COLOR_16_SWAP
	bool "RGB565 byte swap"
	depends on LVGL_COLOR_DEPTH_16
	help
	  Swap the 2 bytes of a RGB565 pixel.

config LVGL_COLOR_SCREEN_TRANSP
	bool "Transparency support"
	depends on LVGL_COLOR_DEPTH_32
	help
	  Enable screen transparency. Useful for OSD or other overlapping GUISs.

choice
	prompt "Chroma key color"
	default LVGL_CHROMA_KEY_GREEN
	help
	  Color to to use as chroma key

	config LVGL_CHROMA_KEY_RED
		bool "Red"

	config LVGL_CHROMA_KEY_GREEN
		bool "Green"

	config LVGL_CHROMA_KEY_BLUE
		bool "Blue"

	config LVGL_CHROMA_KEY_CUSTOM
		bool "Custom"

endchoice

if LVGL_CHROMA_KEY_CUSTOM
config LVGL_CUSTOM_CHROMA_KEY_RED
	hex "Chroma Key Red"
	range 0x00 0xFF
	default 0x00
	help
	  Value of the color red to be used in the chroma key

config LVGL_CUSTOM_CHROMA_KEY_GREEN
	hex "Chroma Key Green"
	range 0x00 0xFF
	default 0xFF
	help
	  Value of the color green to be used in the chroma key

config LVGL_CUSTOM_CHROMA_KEY_BLUE
	hex "Chroma Key Blue"
	range 0x00 0xFF
	default 0x00
	help
	  Value of the color blue to be used in the chroma key

endif

choice
	prompt "Memory pool"
	default LVGL_MEM_POOL_HEAP_KERNEL
	help
	  Memory pool to use for lvgl allocated objects

	config LVGL_MEM_POOL_HEAP_KERNEL
		bool "Kernel Heap"
		depends on HEAP_MEM_POOL_SIZE != 0
		help
		  Use k_malloc and k_free to allocate objects on the kernel heap

	config LVGL_MEM_POOL_HEAP_LIB_C
	  bool "C library Heap"
	  depends on !MINIMAL_LIBC || (MINIMAL_LIBC_MALLOC_ARENA_SIZE != 0)
	  help
		Use C library malloc and free to allocate objects on the C library heap

	config LVGL_MEM_POOL_KERNEL
		bool "Kernel space lvgl pool"
		help
		  Use a dedicated memory pool in kernel space to allocate lvgl objects
		  on

	config LVGL_MEM_POOL_USER
		bool "User space lvgl pool"
		help
		  Use a dedicated memory pool in user space to allocate lvgl objects on

endchoice

if LVGL_MEM_POOL_KERNEL || LVGL_MEM_POOL_USER

config LVGL_MEM_POOL_MIN_SIZE
	int "Minimum memory pool block size"
	default 16
	help
	  Size of the smallest block in the memory pool in bytes

config LVGL_MEM_POOL_MAX_SIZE
	int "Maximum memory pool block size"
	default 2048
	help
	  Size of the largest block in the memory pool in bytes

config LVGL_MEM_POOL_NUMBER_BLOCKS
	int "Number of max size blocks in memory pool"
	default 1
	help
	  Number of maximum sized blocks in the memory pool.

endif

config LVGL_VDB_SIZE
	int "Rendering buffer size"
	default 10
	range 1 100
	help
	  Size of the buffer used for rendering screen content as a percentage
	  of total display size.

config LVGL_DOUBLE_VDB
	bool "Use two rendering buffers"
	help
	  Use two buffers to render and flush data in parallel

choice
	prompt "Rendering Buffer Allocation"
	default LVGL_BUFFER_ALLOC_STATIC
	help
	  Type of allocation that should be used for allocating rendering buffers

config LVGL_BUFFER_ALLOC_STATIC
	bool "Static"
	help
	  Rendering buffers are statically allocated based on the following
	  configuration parameters:
	  * Horizontal screen resolution
	  * Vertical screen resolution
	  * Rendering buffer size
	  * Bytes per pixel

config LVGL_BUFFER_ALLOC_DYNAMIC
	bool "Dynamic"
	help
	  Rendering buffers are dynamically allocated based on the actual
	  display parameters

endchoice

config LVGL_SCREEN_REFRESH_PERIOD
	int "Screen refresh period"
	default 50
	help
	  Screen refresh period in milliseconds

config LVGL_INPUT_REFRESH_PERIOD
	int "Input device refresh period"
	default 50
	help
	  Refresh period for input devices in milliseconds

config LVGL_INPUT_DRAG_THRESHOLD
	int "Drag Threshold"
	default 10
	help
	  Threshold in pixels before entering drag mode

config LVGL_INPUT_DRAG_THROW_SLOW_DOWN
	int "Drag throw slow-down"
	default 20
	range 0 100
	help
	  Percentage of slow down of a throw following a drag.
	  Greater percentage means faster slow-down.

config LVGL_INPUT_LONG_PRESS_TIME
	int "Long press time"
	default 400
	help
	  Period in milliseconds before a press is seen as a long press

config LVGL_INPUT_LONG_RESS_REPEAT_TIME
	int "Long press repeat time"
	default 100
	help
	  Period in milliseconds after which a new trigger is generated
	  for a long press

choice
	prompt "String character encoding"
	default LVGL_TXT_ENC_ASCII

config LVGL_TXT_ENC_ASCII
	bool "ASCII string encoding"

config LVGL_TXT_ENC_UTF8
	bool "UTF-8 string encoding"

endchoice

config LVGL_TEXT_BREAK_CHARACTERS
	string "Text break characters"
	default " ,.;:-_"
	help
	  Characters on which a text break can take place

config LVGL_TEXT_LINE_BREAK_LONG_LEN
	int "Minimal word length for line break"
	default 12
	help
	  If a word is at least this long, a line break is allowed in the word.

	  If the length is 0, no line break is allowed in the middle of a word.

config LVGL_TEXT_LINE_BREAK_LONG_PRE_MIN_LEN
	int "Minimal number of characters on line before line break"
	default 3
	help
	  Minimal number of characters to place on a line before a line break
	  in the middle of a word can occur.

config LVGL_TEXT_LINE_BREAK_LONG_POST_MIN_LEN
	int "Minimal number of characters on line after line break"
	default 3
	help
	  Minimal number of characters to place on a line after a line break
	  occurred in the middle of a word.

config LVGL_TEXT_COLOR_CMD
	string "Text recoloring control character"
	default "#"
	help
	  Control character to use for signalling text recoloring

config LVGL_TEXT_USE_BIDI
	bool "Enable bidirectional text support"
	help
	  Enable bidirectional text support

	  The direction of the text will be processed according to the
	  Unicode Bidirectional Algorithm:
	  https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/

choice LVGL_TEXT_BIDI_MODE
	prompt "Bidirectional text processing direction"
	default LVGL_TEXT_BIDI_DIR_AUTO
	depends on LVGL_TEXT_USE_BIDI
	help
	  Direction of bidirectional text processing

	config LVGL_TEXT_BIDI_DIR_AUTO
		bool "Automatically detect direction"

	config LVGL_TEXT_BIDI_DIR_LTR
		bool "Left-to-right"

	config LVGL_TEXT_BIDI_DIR_RTL
		bool "Right-to-left"

endchoice

config LVGL_ANTIALIAS
	bool "Enable anti-aliasing"
	help
	  Enable anti-aliasing

config LVGL_ANIMATION
	bool "Enable animations"
	help
	  Enable animations

config LVGL_SHADOW
	bool "Enable shadows"
	help
	  Enable shadows

config LVGL_GROUP
	bool "Enable group support"
	help
	  Enable group support.
	  Used by keyboard and button input

config LVGL_GPU
	bool "Enable GPU support"
	help
	  Enable GPU support

config LVGL_IMG_CF_INDEXED
	bool "Enable indexed image support"
	default y
	help
	  Enable support for indexed images

config LVGL_IMG_CF_ALPHA
	bool "Enable alpha indexed image support"
	default y
	help
	  Enable support for alpha indexed images

config LVGL_IMG_INDEXED_CHROMA
	bool "Enable chroma keying for indexed images"
	help
	  Enable chroma keying for indexed images

config LVGL_FILESYSTEM
	bool "Enable file system"
	depends on FILE_SYSTEM
	default y if FILE_SYSTEM
	help
	  Enable LittlevGL file system

config LVGL_IMG_CACHE_DEF_SIZE
	int "Default image cache size"
	default 1
	help
	  Default image cache size, image caching keeps the images open.
	  If only the built-in image formats are used there is no real
	  advantage of caching. With complex image decoders (e.g. PNG or JPG)
	  caching can save the continuous decoding of images. However the
	  opened images might consume additional RAM.

config LVGL_USE_DEBUG
	bool "Enable debug support"
	default y if TEST
	help
	  Enable debug support.

	  If debug support is enabled LVGL will validate the parameters of
	  any function call made and if an invalid parameter is found __ASSERT
	  is called.

if LVGL_USE_DEBUG

config LVGL_USE_ASSERT_NULL
	bool "Enable null pointer assertion"
	default y if TEST
	help
	  Enable null pointer assertion

	  Check if a null pointer is passed as a parameter (Quite fast)

config LVGL_USE_ASSERT_MEM
	bool "Enable memory allocation assertion"
	default y if TEST
	help
	  Enable memory allocation assertion

	  Check if memory allocation is successful (Quite fast)

config LVGL_USE_ASSERT_STR
	bool "Enable string assertion"
	default y if TEST
	help
	  Enable string assertion

	  Check if the string is not a NULL pointer, unusually long string,
	  contains invalid characters or contains unusual repetitions. (Slow)

	  If this option is disabled and NULL pointer checking is enabled, the
	  NULL pointer check is executed instead.

config LVGL_USE_ASSERT_OBJ
	bool "Enable object assertion"
	default y if TEST
	help
	  Enable object assertion

	  Check if an object is not a NULL pointer, has the correct type and
	  does exists. (Quite Slow)

	  If this option is disabled and NULL pointer checking is enabled, the
	  NULL pointer check is executed instead.

config LVGL_USE_ASSERT_STYLE
	bool "Enable style assertion"
	default y if TEST
	help
	  Enable style assertion

	  Check if a used style is correctly initialized. (Fast)

endif

rsource "Kconfig.themes"
rsource "Kconfig.fonts"
rsource "Kconfig.objects"

config APP_LINK_WITH_LVGL
	bool "Link 'app' with LVGL"
	default y
	help
	  Add LVGL header files to the 'app' include path. It may be
	  disabled if the include paths for LVGL are causing aliasing
	  issues for 'app'.

endif # LVGL
