50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
#include <kernel/hardware/keysc.h>
|
|
#include <kernel/hardware/intc.h>
|
|
|
|
// Internal functions
|
|
extern void keycache_update(int row, int column, uint8_t key_frame);
|
|
extern void keycache_clean(uint8_t key_frame);
|
|
|
|
// Device internal indicator to
|
|
// avoid reentrace with the key list.
|
|
volatile uint8_t keylist_isUpdate = 0;
|
|
|
|
void keysc_handler(void)
|
|
{
|
|
static uint8_t key_frame = 0;
|
|
int column;
|
|
int row;
|
|
|
|
// Block / disable KEYSC interrupt.
|
|
SH7305_INTC.IMR5.KEYI = 1;
|
|
SH7305_INTC.IPRF.KEYSC = 0;
|
|
|
|
// Update key frame.
|
|
key_frame = key_frame + 1;
|
|
|
|
// Scan the keyboard.
|
|
row = 6;
|
|
while (--row >= 0)
|
|
{
|
|
column = 16;
|
|
while (--column >= 0)
|
|
{
|
|
if (SH7305_KEYSC.KIUDATA[row] & (0x8000 >> column))
|
|
keycache_update(row, column, key_frame);
|
|
}
|
|
}
|
|
|
|
// Clean key cache (remove unpressed key)
|
|
keycache_clean(key_frame);
|
|
|
|
// Indicate that the key list has been udpated.
|
|
keylist_isUpdate = 1;
|
|
|
|
// Clear KEYSC interrupt, really.
|
|
SH7305_KEYSC.INTERRUPT.WORD = SH7305_KEYSC.INTERRUPT.WORD;
|
|
|
|
// Unblock / enable KEYSC interrupt.
|
|
SH7305_INTC.IPRF.KEYSC = 15;
|
|
SH7305_INTC.IMCR5.KEYI = 1;
|
|
}
|