1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/stage2/tasks/keyscan.c Mon Oct 03 00:41:11 2016 +0200
1.3 @@ -0,0 +1,58 @@
1.4 +/*
1.5 + * Keyboard scanning task.
1.6 + *
1.7 + * Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software: you can redistribute it and/or modify
1.10 + * it under the terms of the GNU General Public License as published by
1.11 + * the Free Software Foundation, either version 3 of the License, or
1.12 + * (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.21 + */
1.22 +
1.23 +#include "board.h"
1.24 +#include "tasks.h"
1.25 +#include "task_gpio.h"
1.26 +
1.27 +void keyscan(unsigned short task)
1.28 +{
1.29 + int column, row, value;
1.30 +
1.31 + while (1)
1.32 + {
1.33 + /* Select each column and read the key states. */
1.34 +
1.35 + for (column = 0; column < GPIO_KEYOUT_COUNT; column++)
1.36 + {
1.37 + task_gpio_set_pin(GPIO_KEYOUT_BASE + column);
1.38 + value = 0;
1.39 +
1.40 + for (row = 0; row < GPIO_KEYIN_COUNT; row++)
1.41 + {
1.42 + value = (value << 1) | task_gpio_get_pin(GPIO_KEYIN_BASE + row);
1.43 + }
1.44 +
1.45 + /* Perform an operation indicating the status. */
1.46 +
1.47 + task_gpio_clear_pin(GPIO_KEYOUT_BASE + column);
1.48 + }
1.49 + }
1.50 +}
1.51 +
1.52 +void start_keyscan(unsigned short task)
1.53 +{
1.54 + u32 args[] = {task};
1.55 +
1.56 + task_gpio_init(task);
1.57 +
1.58 + /* Invoke the task. */
1.59 +
1.60 + start_task(task, (void (*)()) keyscan, args, 1);
1.61 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/stage2/tasks/keyscan.h Mon Oct 03 00:41:11 2016 +0200
2.3 @@ -0,0 +1,6 @@
2.4 +#ifndef __KEYSCAN_H__
2.5 +#define __KEYSCAN_H__
2.6 +
2.7 +void start_keyscan(unsigned short);
2.8 +
2.9 +#endif /* __KEYSCAN_H__ */
3.1 --- a/stage2/tasks/manifest.c Mon Oct 03 00:40:57 2016 +0200
3.2 +++ b/stage2/tasks/manifest.c Mon Oct 03 00:41:11 2016 +0200
3.3 @@ -19,12 +19,14 @@
3.4
3.5 #include "manifest.h"
3.6 #include "example.h"
3.7 +#include "keyscan.h"
3.8
3.9 /* A list of task-starting functions accepting their task identifier. */
3.10
3.11 void (*initial_task_array[])(unsigned short) = {
3.12 start_plot_pattern,
3.13 start_plot_pattern,
3.14 + start_keyscan,
3.15
3.16 /*
3.17 Employ a zero terminator, and make sure that max_tasks is not exceeded