Raspberry Pi 7" Touchscreen

Description

Attempting to run littleVGL demos on Raspberry Pi 3 with the ‘official’ 7" touchscreen display. Struggling with touchscreen. Also uncertain of how SDL\terminal text input relate to LittleVGL.

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

Raspberry Pi 3

What do you want to achieve?

Use LittleVGL on a framebuffer from a RaspberryPi with the official 7" touchscreen device.

What have you tried so far?

As far as I can tell, I have exhausted Google searches and the forum. I have found several relevant posts here, and a few web pages via google. Using this info I have been able to get the screen working at the correct resolution and compile. However I havent been able to get mouse, keyboard or touchscreen input to work.

Some info came from here: http://www.vk3erw.com/index.php/16-software/63-raspberry-pi-official-7-touchscreen-and-littlevgl

One initial confusion I am having is that many examples reference
indev_drv.read = evdev_read;, but the compiler complains. Is indev_drv.read_cb a new version of the method everyone is using in the example code? Is there a better driver to be using for this device? It shows up using evtest. It works fine on /dev/input/event0

I am also trying to figure out how to compile with mouse or keyboard support, though my final application will just be touchscreen. I have both enabled in lv_drv_conf.h, I think, however neither work when I run the program. When I type on a keyboard, it just shows text on the screen. and does not seem to respond

Any advice would be great!

I will post code if it seems helpful. Right now it wont let me attach.

I use this repo, not the generic linux one,

lv_port_linux_frame_buffer

This thread may help you for the touch screen aspects, I previously posted some specific advice there. I think it is still the most recent post.

I have not used mouse or keyboard on raspberry pi, only touch screen for input.

Not sure about this, have not used it.

1 Like
//main.c

#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
//#include "lv_drivers/indev/mouse.h"
//#include "lv_drivers/indev/keyboard.h"
#include "lv_drivers/indev/evdev.h"
#include "lv_examples/lv_apps/demo/demo.h"
#include "lv_examples/lv_apps/benchmark/benchmark.h"
#include "lv_examples/lv_tests/lv_test_theme/lv_test_theme_1.h"
#include "lv_examples/lv_tutorial/10_keyboard/lv_tutorial_keyboard.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>

/*********************
*      DEFINES
*********************/
#define DISP_BUF_SIZE (80*LV_HOR_RES_MAX)


/**********************
*      TYPEDEFS
**********************/

/**********************
*  STATIC PROTOTYPES
**********************/
static void hal_init(void);


/**********************
*  STATIC VARIABLES
**********************/
//static lv_indev_t * kb_indev;

/**********************
*      MACROS
**********************/

/**********************
*   GLOBAL FUNCTIONS
**********************/

int main(int argc, char** argv)
{
    /*LittlevGL init*/
    lv_init();
	
	/*Linux frame buffer device init*/
    fbdev_init();
	
	/*Initialize the HAL for LittlevGL*/
    hal_init();	


    /*Create a Demo*/
    //demo_create();
    //benchmark_create();
    lv_test_theme_1(lv_theme_night_init(210, NULL));
    //lv_test_theme_1(lv_theme_night_init(100, NULL));
    //lv_test_theme_1(lv_theme_material_init(210, NULL));
    //lv_test_theme_1(lv_theme_alien_init(210, NULL));
    //lv_test_theme_1(lv_theme_zen_init(210, NULL));
    //lv_test_theme_1(lv_theme_nemo_init(210, NULL));
    //lv_test_theme_1(lv_theme_mono_init(210, NULL));
    //lv_test_theme_1(lv_theme_default_init(210, NULL));
    //lv_tutorial_keyboard(kb_indev);
	
    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
		lv_tick_inc(5);
        lv_task_handler();
        usleep(5000);
    }

    return 0;
}
/**********************
*   STATIC FUNCTIONS
**********************/

/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
*/
static void hal_init(void)
{

	evdev_init();
	lv_indev_drv_t indev_drv;
	lv_indev_drv_init(&indev_drv);
	indev_drv.type = LV_INDEV_TYPE_POINTER;
	indev_drv.read_cb = evdev_read;
	lv_indev_drv_register(&indev_drv);
	 
    /*A small buffer for LittlevGL to draw the screen's content*/
    static lv_color_t buf[DISP_BUF_SIZE];

    /*Initialize a descriptor for the buffer*/
    static lv_disp_buf_t disp_buf;
    lv_disp_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);

    /*Initialize and register a display driver*/
    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.buffer = &disp_buf;
    disp_drv.flush_cb = fbdev_flush;
    lv_disp_drv_register(&disp_drv);

}

/*Set in lv_conf.h as `LV_TICK_CUSTOM_SYS_TIME_EXPR`*/
uint32_t custom_tick_get(void)
{
    static uint64_t start_ms = 0;
    if(start_ms == 0) {
        struct timeval tv_start;
        gettimeofday(&tv_start, NULL);
        start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
    }

    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint64_t now_ms;
    now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;

    uint32_t time_ms = now_ms - start_ms;
    return time_ms;
}

Next time please format your code like this:

```
your 
code 
here
```
1 Like

Probably the examples you are reading are for LittlevGL 5.3. There were some minor changes made to input device APIs in LittlevGL 6.0 (one of which was making callback names end with _cb).

I strongly recommend starting out with the repository @deonm recommended, although since you mentioned that you already have the display itself working, I wouldn’t bother switching now if you didn’t start with that.

The code you sent should work. Did you configure the right evdev device in lv_drv_conf.h? Can you set a breakpoint inside the while loop in evdev_read and see if it ever reads any data?

Hi!

Thank you for your replies. I have already been through everything I could find with google, including your recommended resource. So far nothing helped me get the touchscreen working. To be fair, I also still have not managed to get the mouse or keyboard input working either, though I have not been trying, instead working in the PC simulator to rough up my application.

Once I have had some more experience, I will come back and report what fixed it, or come back with more pointed questions. Setting up some watch variables and stepping through will be a next step for sure.

If anyone has any general notes on running 'headless (no x windows?)" linux framebuffer with keyboard/mouse input? When running my program from the terminal, if I type, it just shows up on the screen. Is this prevented by the program being configured properly, or do I need to figure out how to turn off the display of keystrokes?

Thank you!

I think you need to manually turn off the framebuffer console. As far as I know, our driver doesn’t do that for you.

I suggest you work on getting the touchscreen working before you try to use the keyboard.

Have you tried my suggestion above? Did you check if evdev_read ever reads anything from the touchscreen?

I have not re-visited running LVGL on the Raspberry Pi with touchscreen since posting the original request for help.

I will be getting around to it in the next day or two, hopefully later today. I had to set it aside, and was discouraged when the forum immediately locked me out for copy-pasting code too fast for a new user, or something like this.

Thank you for the note on the console text output!

Thanks for the heads-up; I’ll have a look at the settings. We do encourage people to show their code so it shouldn’t be blocking them for copying and pasting it.

It looks pretty straightforward to do: c - using linux framebuffer for graphics but disabling console text - Stack Overflow

1 Like

Do you recall any of the contents of the message, by chance? I can’t find the setting that would make it do that.

I don’t recall seeing any message. The board let me make one post right after signing up, but then it locked me out until I contacted you.

I am now trying to figure out how to remote-debug my C code on the raspberry Pi, since I am not writing\compiling on the Pi itself, and have zero interest in doing so.

Do you have a command-line tool called gdbserver on the Pi? That should work for what you’re trying to do.