# HG changeset patch # User Paul Boddie # Date 1475448071 -7200 # Node ID b59bce1670f9376f8c9671f384c60651f6302226 # Parent ca1a8a522be1bfdb76225c0579da3293831d2076 Added a keyboard scanning task. diff -r ca1a8a522be1 -r b59bce1670f9 stage2/tasks/keyscan.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage2/tasks/keyscan.c Mon Oct 03 00:41:11 2016 +0200 @@ -0,0 +1,58 @@ +/* + * Keyboard scanning task. + * + * Copyright (C) 2016 Paul Boddie + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "board.h" +#include "tasks.h" +#include "task_gpio.h" + +void keyscan(unsigned short task) +{ + int column, row, value; + + while (1) + { + /* Select each column and read the key states. */ + + for (column = 0; column < GPIO_KEYOUT_COUNT; column++) + { + task_gpio_set_pin(GPIO_KEYOUT_BASE + column); + value = 0; + + for (row = 0; row < GPIO_KEYIN_COUNT; row++) + { + value = (value << 1) | task_gpio_get_pin(GPIO_KEYIN_BASE + row); + } + + /* Perform an operation indicating the status. */ + + task_gpio_clear_pin(GPIO_KEYOUT_BASE + column); + } + } +} + +void start_keyscan(unsigned short task) +{ + u32 args[] = {task}; + + task_gpio_init(task); + + /* Invoke the task. */ + + start_task(task, (void (*)()) keyscan, args, 1); +} diff -r ca1a8a522be1 -r b59bce1670f9 stage2/tasks/keyscan.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage2/tasks/keyscan.h Mon Oct 03 00:41:11 2016 +0200 @@ -0,0 +1,6 @@ +#ifndef __KEYSCAN_H__ +#define __KEYSCAN_H__ + +void start_keyscan(unsigned short); + +#endif /* __KEYSCAN_H__ */ diff -r ca1a8a522be1 -r b59bce1670f9 stage2/tasks/manifest.c --- a/stage2/tasks/manifest.c Mon Oct 03 00:40:57 2016 +0200 +++ b/stage2/tasks/manifest.c Mon Oct 03 00:41:11 2016 +0200 @@ -19,12 +19,14 @@ #include "manifest.h" #include "example.h" +#include "keyscan.h" /* A list of task-starting functions accepting their task identifier. */ void (*initial_task_array[])(unsigned short) = { start_plot_pattern, start_plot_pattern, + start_keyscan, /* Employ a zero terminator, and make sure that max_tasks is not exceeded