Altera_Forum
Honored Contributor
12 years agoNios II PS2 Keyboard
In QSYS I added a PS/2 Controller IP Core and wired it in Verilog.
My code:#include <stdio.h># include <stdlib.h># include "system.h"
# include <altera_up_avalon_ps2.h># include <altera_up_ps2_keyboard.h>
alt_up_ps2_dev *ps2;
KB_CODE_TYPE *decode_mode;
alt_u8 buf;
char ascii;
int main()
{
ps2 = alt_up_ps2_open_dev("/dev/ps2");
alt_up_ps2_init(ps2);
printf("Detected device: %d\n",ps2->device_type);
while (1)
{
decode_scancode(ps2,decode_mode,&buf,&ascii);
if (*decode_mode != 6)
printf("Decode mode: %d Buffer: 0x%X ASCII: %c\n",*decode_mode,buf,ascii);
}
return 0;
}Decode mode is always 1 or 2, and the buffer is always one byte even if it should be longer. (for example Right Alt key)