vxKernel/src/drivers/mpu/sh/sh7305/keysc/handler.c

49 lines
1.2 KiB
C

#include <vhex/keyboard.h>
#include <vhex/drivers/mpu/sh/sh7305/keysc.h>
#include <vhex/drivers/mpu/sh/sh7305/intc.h>
/* Internal indicator used by high-level function to notice when the key list
is updated */
volatile uint8_t keylist_isUpdate = 0;
/* sh7305_keysc_int_handler() : SH7305 KEYSC interrupt handler */
void sh7305_keysc_int_handler(void)
{
static uint8_t keyframe = 0;
int intlevel;
int column;
int row;
/* Block / disable KEYSC interrupt (otherwise the module will crash) */
SH7305_INTC._MSK->IMR5.KEYSC = 1;
intlevel = SH7305_INTC._IPRX->IPRF.KEYSC;
SH7305_INTC._IPRX->IPRF.KEYSC = 0;
/* update the keyframe */
keyframe = keyframe + 1;
/* update the keycache */
row = 6;
while (--row >= 0) {
column = 16;
while (--column >= 0) {
if (SH7305_KEYSC.KIUDATA[row] & (0x8000 >> column))
keycache_update(row, column, keyframe);
}
}
/* Clean key cache (remove unpressed key) */
keycache_clean(keyframe);
/* Indicate that the key list has been udpated */
keylist_isUpdate = 1;
/* Clear KEYSC interrupt, really */
SH7305_KEYSC.KIUINTREG.word = SH7305_KEYSC.KIUINTREG.word;
/* Unblock / enable KEYSC interrupt. */
SH7305_INTC._IPRX->IPRF.KEYSC = intlevel;
SH7305_INTC._MSKCLR->IMR5.KEYSC = 1;
}