Hi,
I am working on user push buttons to turn on led.
I am able to handle leds through system calls.
I need a help to see the key press condition other than "evtest" so that i can use the read value to handle in a code.
Regards,
Sowmya
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I am working on user push buttons to turn on led.
I am able to handle leds through system calls.
I need a help to see the key press condition other than "evtest" so that i can use the read value to handle in a code.
Regards,
Sowmya
Could you kindly tell us what is your system and what software are you using?
Hi Sowmya,
If you wish to do this from user space, you will have to use polling to see if a GPIO interrupt has arrived. This is the user-space way of doing this.
If you do it inside a kernel module, it's as easy as registering an interrupt handler and letting it do its job when a GPIO interrupt arrives. You can read more about GPIO driver usage on a kernel level here: http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide
Best regards,
Miroslav
Hi Miroslav,
Can I know the path to access the interrupts.
Now for led blinking I am using :
while (1)
{
system ("echo 1 >/sys/class/leds/am335x:EVM_SK:usr0/brightness");
system ("echo 0 >/sys/class/leds/am335x:EVM_SK:usr0/brightness");
}
Like this , is there a way to read SW1/2 or any key press signal events?
Regards,
Sowmya
Sowmya, the IRQ handling for GPIOs is described in the guide above: http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide#IRQ_handling
1. Map GPIO number to corresponding IRQ number:
irq_num = gpio_to_irq(30);
2. Request IRQ:
request_irq(irq_num, handler, 0, "gpio_test", NULL);
"handler" is your IRQ handler function where you would blink your LED.
3. Set IRQ type Raising/Falling/Level triggered:
set_irq_type(irq_num, IRQ_TYPE_EDGE_RISING);
4. During the clean-up path free the IRQ and gpio:
free_irq(irq_num, NULL);
gpio_free(30);
Follow these steps in the kernel module you write. If you don't know what a kernel module is or how to write one, there are plenty of guides online. For example, a good reading is the Linux Device Drivers 3rd edition.
Best regards,
Miroslav
Thank you Miroslav.
I am reading on IRQ handling and related documents. And I will go through the link above given by you.
Regards,
Sowmya
Sowmya, you can also take a look at this sample kernel module, that use a interrupt handler to print the irq number every time an interrupt is triggered. The irq number is passed as a module parameter when inserting the module. You will have to modify this and use gpio_to_irq() to get an irq number, of course.
Best regards,
Miroslav
Hi Miroslav,
I used fread to read the key event and display key pressed value and code.
Now I am able to get key event.
And the link you are giving is not opening.
Regards,
Sowmya
Sowmya BR said:And the link you are giving is not opening.
Sorry, Just fixed the link.
Best regards,
Miroslav
Now my code is working. I am handling through event of key press.
Thank you Miroslav.
Regards,
Sowmya