forked from Lephenixnoir/gint
25 lines
454 B
C
25 lines
454 B
C
#include <keyboard_internals.h>
|
|
|
|
/*
|
|
getPressedKey()
|
|
Finds a pressed key in the keyboard state and returns it.
|
|
*/
|
|
int getPressedKey(volatile unsigned char *keyboard_state)
|
|
{
|
|
int row = 1, column = 0;
|
|
int state;
|
|
if(keyboard_state[0] & 1) return KEY_AC_ON;
|
|
|
|
while(row <= 9 && !keyboard_state[row]) row++;
|
|
if(row > 9) return KEY_NONE;
|
|
|
|
state = keyboard_state[row];
|
|
while(!(state & 1))
|
|
{
|
|
state >>= 1;
|
|
column++;
|
|
}
|
|
|
|
return (column << 4) | row;
|
|
}
|