i.MX93EVK -- Add GPIO control in gui-guider example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.MX93EVK -- Add GPIO control in gui-guider example

No ratings

i.MX93EVK -- Add GPIO control in gui-guider example

Board : i.MX93 EVK

BSP: imx L6.1.1-1.0.0

Gui guider: 1.6.1

 

We have a GUI software tool called GUI Guider. It is a user-friendly graphical user interface development tool from NXP that enables the rapid development of high quality displays with the open-source LVGL graphics library. The GUI demo can run on the i.MX93EVK board. (https://www.nxp.com/design/software/development-software/gui-guider:GUI-GUIDER)

 

This document will show you an example how the buttons(gpio) on the EVK to interacting with the GUI. Basically, customer could use the same method to use the gpio pins to control everything.

 

On the i.MX93 EVK board, there are two buttons BTN1 and BTN2. They are connected to GPIO IO23 and GPIO IO24. Below is the schematic.

jumper.png

 

 Buttons on the board.

 button.jpeg

 

 SW1005 on the board

sw1005.jpeg

 

In the EVK's device tree file, need to change the pinmux for the two buttons like this:

pinctrl_spdif: spdifgrp {
      fsl,pins = <
           // MX93_PAD_GPIO_IO22__SPDIF_IN 0x31e
           // MX93_PAD_GPIO_IO23__SPDIF_OUT 0x31e
           MX93_PAD_GPIO_IO23__GPIO2_IO23 0x31e
           MX93_PAD_GPIO_IO24__GPIO2_IO24 0x31e
      >;

note: all the pins are defined in imx93-pinfunc.h.

 

For getting the input value of the buttons in user's space, I use the sysfs gpio. Build the imx-image-multimedia image first and then select the GPIO_SYSFS in kernel's menuconfig.

 

$ DISTRO=fsl-imx-xwayland MACHINE=imx93evk source imx-setup-release.sh -b build-xwayland

$ bitbake imx-image-multimedia

 

After the build completed, go to the kernel's menuconfig to select the GPIO sysfs.

$ bitbake linux-imx -c menuconfig

[*] General setup-> Configure standard kernel features (expert users)

[*] Device Drivers->GPIO Support-> /sys/class/gpio/... (sysfs interface)

 

Build the whole image again by "$ bitbake imx-image-multimedia".

 

Using the UUU to program the image to the EMMC on the EVK board.

uuu -b emmc_all imx-image-multimedia-imx93evk.rootfs.wic.zst

 

Connect the LVDS to the board. Use the corresponding dtb to boot the board. In u-boot, set the dtb file.

=> setenv fdtfile imx93-11x11-evk-boe-wxga-lvds-panel.dtb

=> saveenv

 

Then restart the board. After the board boot up, it will look like below.

lvds.jpeg

 

 

You need to calibrate the LVDS touch screen before it can normally use. Please use this command:

$ weston-touch-calibrator LVDS-1

 

 

Now, build the GUI guider example. I use the Air Conditioner example.

aircon.png

Download the GUI guider from the gui-guider web page:

https://www.nxp.com/design/software/development-software/gui-guider:GUI-GUIDER

 

Follow the steps from the below web page to build the i.MX BSP and the gui example code.

https://docs.nxp.com/bundle/GUIGUIDERUG-1.6.1/page/topics/yocto.html

 

After the gui-guider build completed, use the 'scp' command to transfer the gui_guider executable file to the board. Execute the command on your host PC like this:

$ scp bld-imx93evk/tmp/work/armv8a-poky-linux/gui-guider/1.6.0-r0/image/usr/bin/gui_guider root@<Your Board IP address>:/

Note: You could use a router to connect your board and your host PC. They are on the same network so could use the 'scp' command to transfer the file to your board.

 

On your board, type the following commands to execute the gui.

$ chmod 755 gui_guider

$ ./gui_guider &

 

Then the GUI is running like this:

gui-demo.jpeg

 

Now, let me explain how to find out the gpio number. Type the following command to show the mapping addresses of gpio.

root@imx93evk:/# cat /sys/kernel/debug/gpio
gpiochip3: GPIOs 0-31, parent: platform/47400080.gpio, 47400080.gpio:

gpiochip0: GPIOs 32-63, parent: platform/43810080.gpio, 43810080.gpio:

gpiochip1: GPIOs 64-95, parent: platform/43820080.gpio, 43820080.gpio:
gpio-64 ( |cd ) in hi IRQ ACTIVE LOW
gpio-71 ( |regulator-usdhc2 ) out lo

gpiochip2: GPIOs 96-127, parent: platform/43830080.gpio, 43830080.gpio:

gpiochip6: GPIOs 472-477, parent: i2c/0-001a, wm8962, can sleep:

gpiochip5: GPIOs 478-487, parent: platform/adp5585-gpio.1.auto, adp5585-gpio, can sleep:
gpio-479 ( |regulator-audio-pwr ) out hi
gpio-483 ( |regulator-can2-stby ) out hi ACTIVE LOW
gpio-486 ( |enable ) out hi

gpiochip4: GPIOs 488-511, parent: i2c/1-0022, 1-0022, can sleep:
gpio-492 ( |Headphone detection ) in lo IRQ
gpio-501 ( |? ) out hi
gpio-502 ( |regulator-vdd-12v ) out hi
gpio-505 ( |reset ) out lo
gpio-507 ( |? ) out hi
gpio-508 ( |reset ) out lo ACTIVE LOW

 

The gpio pins of two buttons are GPIO2_IO23 and GPIO2_IO24. They are belongs to gpio2. In the imx93.dtsi, the gpio2's address is "gpio2: gpio@43810080". So, base on the information output from "/sys/kernel/debug/gpio", the gpio2 is mapping to "gpiochip0: GPIOs 32-63".

So, the GPIO2_IO23 is 32+23=55, and the GPIO2_IO24 is 32+24=56.

 

To verify the gpio number is correct or not. We could do the following test.

root@imx93evk:/# echo 55 > /sys/class/gpio/export
root@imx93evk:/# echo in > /sys/class/gpio/gpio55/direction
root@imx93evk:/# echo 56 > /sys/class/gpio/export
root@imx93evk:/# echo in > /sys/class/gpio/gpio56/direction

 

Then, run these two commands to check the values.

root@imx93evk:/# cat /sys/class/gpio/gpio55/value
root@imx93evk:/# cat /sys/class/gpio/gpio55/value

 

When the button is not pressed, the value is 1. When press the button, the value is 0. 

We could add the same in the GUI's custom.c. Open the GUI Guider software and add the code in the custom.c.

/*********************
 *      INCLUDES
 *********************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include "lvgl.h"
#include "custom.h"
#include "ui_Aircon.h"
#include "guider_customer_fonts.h"

/**********************
 *  STATIC VARIABLES
 **********************/
int fdbtn1,fdbtn2,fdgpio;
int btn1_pressed;
int btn2_pressed;
char btn1_value, btn2_value;

void custom_func(void)
{
		
	fdbtn1 = open("/sys/class/gpio/gpio55/value", O_RDWR);
	fdbtn2 = open("/sys/class/gpio/gpio56/value", O_RDWR);

	read(fdbtn1, &btn1_value, 1);
	read(fdbtn2, &btn2_value, 1);

	if(btn1_value=='0' && btn1_pressed) 
	{
		btn1_pressed=0;
		ui_aircon_update_temp(0, kAIRCON_TempUp);
	}
	
	if(btn1_value=='1')
		btn1_pressed=1;

	if(btn2_value=='0' && btn2_pressed) 
	{
		btn2_pressed=0;
		ui_aircon_update_temp(0, kAIRCON_TempDown);
	}	
	
	if(btn2_value=='1')
		btn2_pressed=1;

	close(fdbtn1);
	close(fdbtn2);
}

void custom_init(lv_ui *ui)
{
    fdbtn1 = open("/sys/class/gpio/gpio55/value", O_WRONLY);
    if (fdbtn1 == -1) {        
    fdgpio = open("/sys/class/gpio/export", O_WRONLY);
    write(fdgpio,"55",3);
    write(fdgpio,"56",3);
    close(fdgpio);

    fdgpio = open("/sys/class/gpio/gpio55/direction", O_WRONLY);
    write(fdgpio,"in",3);
    close(fdgpio);
    
    fdgpio = open("/sys/class/gpio/gpio56/direction", O_WRONLY);
    write(fdgpio,"in",3);
    close(fdgpio);
    }
    else
	close(fdbtn1);
...
...
...
...

 

Add the custom_func() in the custom.h.

#ifndef __CUSTOM_H_
#define __CUSTOM_H_
#ifdef __cplusplus
extern "C" {
#endif

#include "gui_guider.h"

void custom_init(lv_ui *ui);
+  void custom_func(void);   

 

Also, need to add the custom function() into the dead loop in main.c.

 

To modify the code,

bld-imx93evk$ vim tmp/work/armv8a-poky-linux/gui-guider/1.6.0-r0/gui-guider-1.6.0/ports/linux/main.c

 

    while(1) {

+	custom_func();  // <--- Add the custom function here.

        /* Periodically call the lv_task handler.
         * It could be done in a timer interrupt or an OS task too.*/
        time_till_next = lv_wayland_timer_handler();
#if LV_USE_VIDEO
        video_play(&guider_ui);
#endif
        /* Run until the last window closes */
        if (!lv_wayland_window_is_open(NULL)) {
            break;
        }

 

Re-build the code after modified.

bld-imx93evk$ bitbake gui-guider -c compile -f

 

Build the whole image again.

bld-imx93evk$ bitbake gui-guider

Then use the 'scp' command to transfer the new gui-guider file to the board.

 

Finally, you can use the buttons on the EVK board to set the temperature up and down.

 

 

 

 

 

 

 

 

 

 

 

 

 

Labels (2)
Version history
Last update:
‎11-28-2023 01:24 AM
Updated by: