Controlling GPIO and user's buttons

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

Controlling GPIO and user's buttons

3,429 Views
ChaimA
Contributor I

Hi,

How can i control/configure the gpio?

I want to  read signal from the user's buttons and control the leds?

I'll be very grateful for code examples as well.
TNX,
0 Kudos
17 Replies

2,054 Views
StevieRG
Contributor II

Thanks to Freescale tech support, I have this working.

The fix is to remove the lines from mx53_loco.c that configure these GPIO as "buttons", or they can't be used as simple GPIO and won't appear in /sys/class/gpio:

static struct gpio_keys_button loco_buttons[] = {

        GPIO_BUTTON(MX53_nONKEY, KEY_POWER, 1, "power", 0),
/*      GPIO_BUTTON(USER_UI1, KEY_VOLUMEUP, 1, "volume-up", 0),
        GPIO_BUTTON(USER_UI2, KEY_VOLUMEDOWN, 1, "volume-down", 0),

*/
};

 

Now these commands work to read the pins:

echo 46 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio46/direction
cat /sys/class/gpio/gpio46/value

echo 47 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio47/direction
cat /sys/class/gpio/gpio47/value

0 Kudos

2,054 Views
praveendosapati
Contributor I

Hi Steeve,

     I would like to use USERDEF GPIO's on IMX53 Quick STart-R Board Ubuntu(Linux). I couldn't find the file mx53_loco.c in kernel source which you said in above conversation. Did u said the above one for Ubuntu Linux or is it for Android. Could you please help me in enabling this Pins for Linux.

     Thanks in advance.

0 Kudos

2,054 Views
StevieRG
Contributor II

I have an unexpected problem with exporting (opening) the two user defined buttons on the QSB.

/sys/class/gpio is enabled in the kernel.

According to the QSB users manual:
USERDEF1: USERDEF2:
These two buttons are user defined buttons attached to PATA_DATA14 (P6) and PATA_DATA15 (P5).

---------------------------------------------
iomux-mx53.h is unmodified and contains:

#define _MX53_PAD_PATA_DATA14__GPIO2_14 IOMUX_PAD(0x660, 0x2DC, 1, 0x0, 0, 0)
....
#define _MX53_PAD_PATA_DATA15__GPIO2_15 IOMUX_PAD(0x664, 0x2E0, 1, 0x0, 0, 0)
....
....
#define MX53_PAD_PATA_DATA14__GPIO2_14 (_MX53_PAD_PATA_DATA14__GPIO2_14 | MUX_PAD_CTRL(NO_PAD_CTRL))
....
#define MX53_PAD_PATA_DATA15__GPIO2_15 (_MX53_PAD_PATA_DATA15__GPIO2_15 | MUX_PAD_CTRL(NO_PAD_CTRL))
....

---------------------------------------------
mx53_loco.c is unmodified and contains:

static iomux_v3_cfg_t mx53_loco_pads[]
{
....
/* GPIO */
....
MX53_PAD_PATA_DATA14__GPIO2_14,
MX53_PAD_PATA_DATA15__GPIO2_15,
....
};
---------------------------------------------

Calculating GPIO number:
GPIO2_14 = (2 - 1) * 32 + 14 = 46
GPIO2_15 = (2 - 1) * 32 + 15 = 47

At the command line, export GPIO2_14 and GPIO_15:
echo 46 > /sys/class/gpio/export
echo 47 > /sys/class/gpio/export

.... no error is shown.

Then do "ls /sys/class/gpio" but they do not appear in the file list

I can do the same with GPIO number 199, which is the LED on the QSB, and it works fine.

/sys/class/gpio/gpio199 appears in the file list when I do ls and I can set and clear it to turn the LED on and off.

Any ideas? Thanks.

0 Kudos

2,053 Views
enaud
Contributor III

if other users have solved this problem, pls explain all :D

0 Kudos

2,054 Views
jose
Contributor I

I am also lookin forward to that but... we just have to wait bec. we are just askin a favor right?

I hope sir kurt will give a follow up on this and we should thank him for his effort.

sir kurt... just sayin hello here...

everyone is waitin for your tutorial sir... thank you

0 Kudos

2,054 Views
enaud
Contributor III


kurt said:

Jose,

I will post something soon.

Nothing?
0 Kudos

2,054 Views
jose
Contributor I

That's great man.

Thank you so much.

kurt said:

Jose,

I will post something soon.

0 Kudos

2,054 Views
kurt1z
Contributor I

Jose,

I will post something soon.

0 Kudos

2,054 Views
jose
Contributor I

any update on the kernel side Kurt?

0 Kudos

2,054 Views
kurt1z
Contributor I

jose,

this is for the user-space side.

I'm trying now to setup a kernel module.

gr.

Kurt

jose said:

By the way, this is for the user-space side right?

How about the kernel-space? Or should i say the driver part?

I don't know if i make sense sorry correct me if im wrong.


kurt said:

hi all,
if someone still looking for a very good starting point
https://www.ridgerun.com/developer/wiki/index.php/Gpio-int-test.c
0 Kudos

2,054 Views
fabio_estevam
NXP Employee
NXP Employee

See this post where I explain how you can access GPIOs in Linux:

http://forums.freescale.com/t5/i-MX-Microprocessors/iMX28-SYSFS-and-GPIO/td-p/60938

0 Kudos

2,054 Views
kurt1z
Contributor I
hi all, if someone still looking for a very good starting pointhttps://www.ridgerun.com/developer/wiki/index.php/Gpio-int-test.c
0 Kudos

2,054 Views
KevinChen_ng
Contributor I

see the file arch/arm/mach-mx5/mx53_evk.c ,

you can find much sample code which control/configure the gpio.

it's under linux kernel in freescale's bsp.

"What's tha function/API to read the event of press on the buttuns" ?

it's standard input event API . you can use evtest to monitor the button event. 

if you want your function,  can reference the evtest's source code.

in ubuntu PC, you can install evtest through  apt-get install evtest.

hope helpful.

0 Kudos

2,054 Views
kurt1z
Contributor I

Hi Miroslav,

thanks for the tip, it's a starting point. I did already some test in the console. Now I try to figure it out the irq base inputs in a user program.

0 Kudos

2,054 Views
ChaimA
Contributor I

I

What's tha function/API to read the event of press on the buttuns.

0 Kudos

2,054 Views
MiroslavIMX53QS
Contributor I

Take a look at file i.MX53 System Development User’s GuideChapter 13 

Configuring the IOMUX Controller (IOMUXC).

There you can find a way to control a gpio pin from user space.

0 Kudos

2,054 Views
kurt1z
Contributor I

I need also some sample code to access the buttons and user led of the IMX53QSB.

The second step is to change the hardware and add some buttons and leds on the expansionslot. 

0 Kudos