|
|
@ -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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|