better keypad stuff

master
Clyne Sullivan
parent 50233fff40
commit 234beaee5d

@ -53,7 +53,7 @@ $(OUT): $(OFILES) initrd/init libinterp.a
@$(CROSS)$(AR) r $(INITRD) initrd/* @$(CROSS)$(AR) r $(INITRD) initrd/*
@$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm $(INITRD) out/initrd.img.o @$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm $(INITRD) out/initrd.img.o
@echo " LINK " $(OUT) @echo " LINK " $(OUT)
@$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) out/*.o -o $(OUT) -L. -linterp @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) out/*.o -o $(OUT) -L. -linterp -lm
$(OUTDIR)/%.o: src/%.c $(OUTDIR)/%.o: src/%.c
@echo " CC " $< @echo " CC " $<

Binary file not shown.

@ -53,18 +53,20 @@ static const port_t keypad_cols[COLS] = {
{ COL_3 }, { COL_4 } { COL_3 }, { COL_4 }
}; };
static const int keypad_map[ROWS][COLS] = { static const char keypad_map[ROWS * COLS * 4] = {
{ '&', '|', '^', ' ', ' ' }, "&\0\0\0" "|\0\0\0" "pi\0\0" "==\0\0" "!=\0\0"
{ 'x', 'y', 'z', '=', ' ' }, "x\0\0\0" "y\0\0\0" "z\0\0\0" "=\0\0\0" "sin\0"
{ '7', '8', '9', '(', ')' }, "7\0\0\0" "8\0\0\0" "9\0\0\0" "(\0\0\0" ")\0\0\0"
{ '4', '5', '6', '/', '%' }, "4\0\0\0" "5\0\0\0" "6\0\0\0" "/\0\0\0" "%\0\0\0"
{ '1', '2', '3', '*', '-' }, "1\0\0\0" "2\0\0\0" "3\0\0\0" "*\0\0\0" "-\0\0\0"
{ '.', '0', '\b', '\n', '+' } ".\0\0\0" "0\0\0\0" "\b\0\0\0" "\n\0\0\0" "+\0\0\0"
}; };
#define KEY(r, c, i) keypad_map[r * COLS * 4 + c * 4 + i]
#define BUFFER_SIZE 8 #define BUFFER_SIZE 8
static char keypad_buffer = 0;//[BUFFER_SIZE]; static char keypad_buffer[BUFFER_SIZE];
//static int keypad_buffer_pos = -1; static int keypad_buffer_pos = -1;
void keypad_task(void) void keypad_task(void)
{ {
@ -74,8 +76,10 @@ void keypad_task(void)
delay(10); delay(10);
for (unsigned int row = 0; row < ROWS; row++) { for (unsigned int row = 0; row < ROWS; row++) {
if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) { if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) {
//if (keypad_buffer_pos < BUFFER_SIZE) if (keypad_buffer_pos < BUFFER_SIZE) {
keypad_buffer/*[++keypad_buffer_pos]*/ = keypad_map[row][col]; for (unsigned int i = 0; KEY(row, col, i) != '\0'; i++)
keypad_buffer[++keypad_buffer_pos] = KEY(row, col, i);
}
while (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) while (gpio_din(keypad_rows[row].port, keypad_rows[row].pin))
delay(1); delay(1);
break; break;
@ -117,15 +121,12 @@ void keypad_start(void)
int keypad_get(void) int keypad_get(void)
{ {
//if (keypad_buffer_pos < 0) if (keypad_buffer_pos < 0)
// return 0; return 0;
//int key = keypad_buffer[0]; int key = keypad_buffer[0];
//for (int i = keypad_buffer_pos - 1; i > 0; i--) for (int i = 0; i < BUFFER_SIZE - 1; i++)
// keypad_buffer[i - 1] = keypad_buffer[i]; keypad_buffer[i] = keypad_buffer[i + 1];
//keypad_buffer_pos--; keypad_buffer_pos--;
//return key; return key;
int ret = keypad_buffer;
keypad_buffer = 0;
return ret;
} }

@ -26,11 +26,12 @@
#include <display_draw.h> #include <display_draw.h>
#include <heap.h> #include <heap.h>
#include <initrd.h> #include <initrd.h>
#include <it/string.h>
#include <keypad.h>
#include <math.h>
#include <random.h> #include <random.h>
#include <serial.h> #include <serial.h>
#include <stdlib.h> #include <stdlib.h>
#include <it/string.h>
#include <keypad.h>
#define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f) #define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f)
@ -48,8 +49,12 @@ int script_pixel(instance *it);
int script_menu(instance *it); int script_menu(instance *it);
int script_filemenu(instance *it); int script_filemenu(instance *it);
int math_sin(instance *it);
void script_loadlib(instance *it) void script_loadlib(instance *it)
{ {
inew_number(it, "pi", 3.1415926f);
inew_cfunc(it, "print", script_puts); inew_cfunc(it, "print", script_puts);
inew_cfunc(it, "putchar", script_putchar); inew_cfunc(it, "putchar", script_putchar);
inew_cfunc(it, "gets", script_gets); inew_cfunc(it, "gets", script_gets);
@ -66,6 +71,16 @@ void script_loadlib(instance *it)
inew_cfunc(it, "menu", script_menu); inew_cfunc(it, "menu", script_menu);
inew_cfunc(it, "filemenu", script_filemenu); inew_cfunc(it, "filemenu", script_filemenu);
inew_cfunc(it, "sin", math_sin);
}
int math_sin(instance *it)
{
variable *n = igetarg(it, 0);
variable *v = make_varf(0, sinf(n->value.f));
ipush(it, (uint32_t)v);
return 0;
} }
int script_menu(instance *it) int script_menu(instance *it)

Loading…
Cancel
Save