How to control(read value) of an input GPIO(gpio-keys) ?

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

How to control(read value) of an input GPIO(gpio-keys) ?

2,250 Views
LAAZIBI
Contributor II

I am using a iMX93 QS93, In the device tree I configured the gpio as an input line as you can see below

gpio-keys {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_pmic>;

		// nPBOUT Line Input
		power_button_npbout {
			label = "nPBOUT";
			gpios = <&gpio2 18 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
			debounce-interval = <0>;
			//interrupt-parent = <&gpio2>;
			//interrupts = <18 IRQ_TYPE_EDGE_BOTH>;
		};
	};

 And here the Pin Multiplexing configuration: 

	pinctrl_gpio_pmic: gpio_pmicgrp {
		fsl,pins = <
			MX93_PAD_GPIO_IO18__GPIO2_IO18				0x1c0
		>;
	};

 

I am building my image using yocto and after the successful build, I run the image in the target and tried to export the gpio by running `echo 50 > /sys/class/gpio/export`. The export fails with the error : 

-bash: echo: write error: Device or resource busy


The `gpioinfo` shows this line under `gpiochip0 - 32lines:` 

line  18:       unnamed                 input active-low consumer=nPBOUT

 The output of `cat /sys/kernel/debug/gpio` shows :

 gpio-0   (                    |scl                 ) out lo
 gpio-1   (                    |sda                 ) in  lo
 gpio-2   (                    |scl                 ) out lo
 gpio-3   (                    |sda                 ) in  lo
 gpio-9   (                    |PSHOLD              ) out lo

gpiochip0: GPIOs 32-63, parent: platform/43810080.gpio, 43810080.gpio:
 gpio-50  (                    |nPBOUT              ) in  hi IRQ ACTIVE LOW
 gpio-60  (                    |sda                 ) in  lo
 gpio-61  (                    |scl                 ) out lo

gpiochip1: GPIOs 64-95, parent: platform/43820080.gpio, 43820080.gpio:

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

 

 

Am writing C++ code to interact with gpios, I wanted to test this input gpio by export it and read it value but I can't. Could anyone help me out to be able to read the value of the gpio (I am connecting the gpio pin to GND and 3.3V pins for testing)

 

Labels (3)
Tags (2)
0 Kudos
Reply
4 Replies

2,109 Views
LAAZIBI
Contributor II

I changed my device tree to use gpio-controller `insteag gpio-keys` and `gpio-leds`, like you see below 

 

 

&gpio1 {
	gpio-pwr_pshold {
		line-name = "PWR_PSHOLD";
		gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
		output-high;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_pwr_pshold>;
	};
};
&gpio2 {
	gpio-pwr_pbout {
		line-name = "PWR_PBOUT";
		gpios = <&gpio2 18 GPIO_ACTIVE_LOW>;
		input;
		interrupts = <18 IRQ_TYPE_EDGE_BOTH>; // Generate an interrupt on both rising and falling edges	
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_pwr_pbout>;
	};

	gpio-usr_pbout {
		line-name = "USR_PBOUT";
		gpios = <&gpio2 20 GPIO_ACTIVE_LOW>;
		input;
		interrupts = <20 IRQ_TYPE_EDGE_BOTH>; // Generate an interrupt on both edges	
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_usr_pbout>;
	};
};

 

 

gpioget gives me "pin" inactive. 

I wanted to write a C++ code to control these pins: toggle value to output gpio, get value from input gpios and be able to watch the input lines because I want to detect from a button if it is long/short press etc. 

I am trying to use libgpiod v2.0, but I can't find some examples for this purpose using libgpiod 2.0 or later. 

Could anyone help me in this ?  

0 Kudos
Reply

2,107 Views
Chavira
NXP TechSupport
NXP TechSupport

HI @LAAZIBI!

You are declaring wrong your device tree please check the official documentation.

leds-gpio.yaml 

gpio-keys.yaml 

 

Best Regards!

Chavira

 

 

0 Kudos
Reply

2,091 Views
LAAZIBI
Contributor II
But am not using `leds-gpio` and `gpio-keys` anymore. I just changed my configuration to the generic way to define GPIO controllers.
0 Kudos
Reply

2,206 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @LAAZIBI!
Thank you for contacting NXP Support!

Do you try with the command gpioget?

 

Best Regards!

Chavira

0 Kudos
Reply