1 /* 2 * Keyboard scanning task. 3 * 4 * Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "board.h" 21 #include "tasks.h" 22 #include "task_gpio.h" 23 24 void keyscan(unsigned short task) 25 { 26 int column, row, value; 27 28 while (1) 29 { 30 /* Select each column and read the key states. */ 31 32 for (column = 0; column < GPIO_KEYOUT_COUNT; column++) 33 { 34 task_gpio_set_pin(GPIO_KEYOUT_BASE + column); 35 value = 0; 36 37 for (row = 0; row < GPIO_KEYIN_COUNT; row++) 38 { 39 value = (value << 1) | task_gpio_get_pin(GPIO_KEYIN_BASE + row); 40 } 41 42 /* Perform an operation indicating the status. */ 43 44 task_gpio_clear_pin(GPIO_KEYOUT_BASE + column); 45 } 46 } 47 } 48 49 void start_keyscan(unsigned short task) 50 { 51 u32 args[] = {task}; 52 53 task_gpio_init(task); 54 55 /* Invoke the task. */ 56 57 start_task(task, (void (*)()) keyscan, args, 1); 58 }