[V8] Input Device, How to Implement, Callback never called

Description

I tried to implement my ILI9341 based touchpad now. The Touchpad itself is working, i get correct coordinates. I tried to register my driver with LVGL but unfortunately the Callback is never ever called.

What MCU/Processor/Board and compiler are you using?

STM32 / FreeRTOS / STMCubeIDE

What do you want to achieve?

Touch Input :smiley:

What have you tried so far?

Implemented the Driver According to LVGL Documentation. Breakpoints in the Callback never trigger.

Code to reproduce

Here you can have access to the complete project:
GITHUB

Here is the Initialization

lv_init();

	/*Initialize `disp_buf` with the buffer(s) */
	lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, MY_DISP_HOR_RES * 10);
	/* INIT DISPLAY */
	static lv_disp_drv_t disp_drv; /*A variable to hold the drivers. Can be local variable*/
	lv_disp_drv_init(&disp_drv); /*Basic initialization*/
	disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
	disp_drv.flush_cb = my_flush_cb; /*Set a flush callback to draw to the display*/
	disp_drv.rounder_cb = 0;
	lv_disp_t *disp;
	disp = lv_disp_drv_register(&disp_drv); /*Register the driver and save the created display objects*/
	/*INIT INPUT DEVICE*/
	static lv_indev_drv_t indev_drv;
	indev_drv.type = LV_INDEV_TYPE_POINTER;
	indev_drv.read_cb = my_input_read;

	lv_indev_drv_init(&indev_drv); /*Basic initialization*/

	lv_indev_t *my_indev = lv_indev_drv_register(&indev_drv);

	/* Create Test Object */
	lv_tick_inc(1);
	btn = lv_btn_create(lv_scr_act());
	lv_obj_align(btn, LV_ALIGN_CENTER, 0, -40);
	lv_obj_t *label;
	label = lv_label_create(btn);
	lv_label_set_text(label, "Button");

	/* USER CODE END 2 */

	/* Init scheduler */
	osKernelInitialize();

This is my Input Callback

bool my_input_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
	data->point.x = _lcd->touch_coordinate.x;
	data->point.y = _lcd->touch_coordinate.y;
	data->state = _lcd->touch_pressed; // or LV_INDEV_STATE_REL;
	return false; /*No buffering now so no more data read*/
}

These are the changed lines in the lvgl config


#if 1/*Set it to "1" to enable content*/

#ifndef LV_CONF_H
#define LV_CONF_H
/*clang-format off*/

#include <stdint.h>


/*====================
   COLOR SETTINGS
 *====================*/

/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH     16
#define LV_HOR_RES_MAX 320
#define LV_VER_RES_MAX 240
/*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP   1

/*Enable more complex drawing routines to manage screens transparency.
 *Can be used if the UI is above an other layer, e.g. an OSD menu or video player.
 *Requires `LV_COLOR_DEPTH = 32` colors and the screen's `bg_opa` should be set to non LV_OPA_COVER value*/
#define LV_COLOR_SCREEN_TRANSP    0

/*Images pixels with this color will not be drawn if they are  chroma keyed)*/
#define LV_COLOR_CHROMA_KEY    lv_color_hex(0x00ff00)         /*pure green*/

/*=========================
   MEMORY SETTINGS
 *=========================*/

/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM      0
#if LV_MEM_CUSTOM ==0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#  define LV_MEM_SIZE    (32U * 1024U)          /*[bytes]*/

/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
#  define LV_MEM_ADR          0     /*0: unused*/
#else       /*LV_MEM_CUSTOM*/
#  define LV_MEM_CUSTOM_INCLUDE <FreeRTOS.h>   /*Header for the dynamic memory function*/
#  define LV_MEM_CUSTOM_ALLOC     pvPortMalloc
#  define LV_MEM_CUSTOM_FREE      vPortFree
#  define LV_MEM_CUSTOM_REALLOC   vPortReAlloc
#endif     /*LV_MEM_CUSTOM*/

/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/
#define LV_MEMCPY_MEMSET_STD    0

As recommended i call lv_tick_inc in Application Hook of freertos which gets called once every ms


void vApplicationTickHook( void )
{
   /* This function will be called by each tick interrupt if
   configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
   added here, but the tick hook is called from an interrupt context, so
   code must not attempt to block, and only the interrupt safe FreeRTOS API
   functions can be used (those that end in FromISR()). */
   lv_tick_inc(1);
}

Thanky you very much in advance for your help!

Maybe you should first call the lv_indev_drv_init:

    static lv_indev_drv_t indev_drv;

    lv_indev_drv_init (&indev_drv);            // First initialize 

    indev_drv.type    = LV_INDEV_TYPE_POINTER; // then set type
    indev_drv.read_cb = my_input_read;         // and set call-back function

    lv_indev_t *my_indev = lv_indev_drv_register (&indev_drv);  // register driver

BTW, if you want to use the FreeRTOS malloc and free functions you should set

#define LV_MEM_CUSTOM      1
1 Like

Thanks, somehow messed this up :smiley:
LV_MEM_CUSTOM was just a test, do you see any advantage using this?

Maybe this solution will help you: Input device. Callback is never called