Forum Discussion
Altera_Forum
Honored Contributor
20 years agobuttons and leds
Hello all and hippo, Can anyone out there help me with buttons and leds ? I am running uclinux on cyclone ii 2c35 nios ii dev board. I have 8 leds, 2 7-segment leds, 4 buttons and 16x...
Altera_Forum
Honored Contributor
20 years agoI'm not using the drivers for these devices, so I leave them out of the kernel compile. I could never get the button device /dev/btn to work.
What I do instead is just directly read and write the ports. So I have # include "nios2_system.h" VUINT16 *button_address = (VUINT16*) na_button_pio; VUINT16 *led_7seg_address = (VUINT16*) na_seven_seg_pio; VUINT8 *led_address = (VUINT8*) na_led_pio; and then just read and write to these ports. For the buttons: int get_button_press(void) { int button_value = ~*button_address; if (button_value & 0x08) return 1; else if (button_value & 0x04) return 2; else if (button_value & 0x02) return 3; else if (button_value & 0x01) return 4; else return 0; } For the leds just read and write values. I can share my digit code and alphabetic characters for the seven segment display if you want. Cheers, Josh