Compare commits

...

2 Commits

Author SHA1 Message Date
Potter360 4ec1493af1 Add keypressed() function 2024-03-24 10:12:18 +01:00
Potter360 8b906d9d59 Ugly timer wait on TIMER_CONTINUE bug fix 2024-03-22 18:54:06 +01:00
3 changed files with 27 additions and 3 deletions

View File

@ -6,6 +6,7 @@ void keyboard_refresh();
void keyboard_setup();
uint8_t keyboard_get_line(int line);
bool keydown(int key);
bool keypressed(int key);
// Keycodes

View File

@ -1,8 +1,10 @@
#include <omega/utils.h>
#include <omega/display.h>
#include <stdbool.h>
uint8_t scan[12];
uint8_t buff[12];
void keyboard_setup()
{
for(int i=0;i<12;i++)
@ -32,3 +34,19 @@ bool keydown(int key)
return (scan[row] & col) != 0;
}
bool keypressed(int key)
{
int row = (key >> 4);
int col = 0x80 >> (key & 0x7);
memcpy((uint32_t *)scan,(uint32_t *)buff,sizeof(uint8_t)*12);
keyboard_refresh();
for(int i=0;i<12;i++)
{
if(scan[i]!=buff[i])
{
return (scan[row] & col) != 0;
}
}
return 0;
}

View File

@ -1,4 +1,5 @@
#include <omega/tmu.h>
#include <omega/display.h>
#include <omega/defs/calls.h>
@ -6,7 +7,7 @@ static tmu_channel_t *CHANNELS = TMU.CHANNELS;
static volatile uint8_t *TSTR = &TMU.TSTR;
call_t tmu_callbacks[3];
uint8_t wait_unf;
int default_callback(void)
{
return TIMER_STOP;
@ -15,6 +16,7 @@ void back(int id)
{
tmu_channel_t *channel = &CHANNELS[id];
channel->TCR.UNF = 0;
wait_unf = 1;
int return_value = tmu_callbacks[id]();
if(return_value == TIMER_STOP)
@ -66,7 +68,8 @@ int timer_new(uint64_t delay, call_t call)
uint32_t final_delay = timer_delay(delay);
timer_configure(i,final_delay,call);
timer_start(i);
return i;
}
@ -97,5 +100,7 @@ void timer_stop(int id)
void timer_wait(int id)
{
tmu_channel_t *channel = &CHANNELS[id];
while(*TSTR & (1 << id)) if(channel->TCR.UNIE) __asm__("sleep");
while(!(wait_unf)) if(channel->TCR.UNIE) __asm__("sleep");
wait_unf = 0;
}