Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Key pressed?

Altera_Forum
Honored Contributor II
1,273 Views

Hello! 

 

How can I check if a key was pressed? 

 

I didn't found a appropriate function in the C which is used by Microtronix. 

 

 

Bye, Lothar.
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
328 Views

Are you referring to a key press at the console? ... like fgetc() ?

0 Kudos
Altera_Forum
Honored Contributor II
328 Views

Hi! 

 

fgetc() is not a solution for me, because I only have to check if key was pressed or not.  

And fgetc() is waiting for a key. 

 

 

Bye, Lothar.
0 Kudos
Altera_Forum
Honored Contributor II
328 Views

Hi 

 

There are a few choices of what you can do here. 

 

One is to use the inl() functions defined in linux/io.h or asm/io.h. You will have to include the nios system header file for the io structures you want to use and the base address of the buttons. 

 

The second and better 'Linux way' I would say is edit the existing altera_pio_buttons.c (or something like that) in drivers/char/ with adding support for ioctl() commands. Here you would place the inl() functions. 

 

There is a thread where I asked about drivers ect where you can find a link to some documentation on Linux device drivers. There are a lot of links here on drivers, makefiles ect. 

 

Good luck. 

Rual
0 Kudos
Altera_Forum
Honored Contributor II
328 Views

Hi Lothar, 

 

> fgetc() is not a solution for me, because I only have to check if key was 

> pressed or not. 

 

Okay ... I'll take a giant step into the abstract ;-) and just assume you're referring 

to a serial device, consonle, pty, etc. rather than some sort of custom keypad 

or custom hardware: 

 

You can use the select() system call with an appropriate timeout. If you just want 

to poll, set the timeout to zero. 

 

Regards, 

--Scott
0 Kudos
Reply