paul@207 | 1 | /* |
paul@207 | 2 | * Keyboard scanning task. |
paul@207 | 3 | * |
paul@207 | 4 | * Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@207 | 5 | * |
paul@207 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@207 | 7 | * it under the terms of the GNU General Public License as published by |
paul@207 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@207 | 9 | * (at your option) any later version. |
paul@207 | 10 | * |
paul@207 | 11 | * This program is distributed in the hope that it will be useful, |
paul@207 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@207 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@207 | 14 | * GNU General Public License for more details. |
paul@207 | 15 | * |
paul@207 | 16 | * You should have received a copy of the GNU General Public License |
paul@207 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@207 | 18 | */ |
paul@207 | 19 | |
paul@207 | 20 | #include "board.h" |
paul@207 | 21 | #include "tasks.h" |
paul@207 | 22 | #include "task_gpio.h" |
paul@215 | 23 | #include "jzlcd.h" |
paul@215 | 24 | #include "lcd.h" |
paul@215 | 25 | |
paul@215 | 26 | extern vidinfo_t panel_info; |
paul@215 | 27 | |
paul@215 | 28 | void plot_value(unsigned short xmin, unsigned short xmax, unsigned short ymin, unsigned short ymax, u8 value) |
paul@215 | 29 | { |
paul@215 | 30 | unsigned short x, y; |
paul@215 | 31 | u32 pixel; |
paul@215 | 32 | |
paul@215 | 33 | for (y = ymin; (y < panel_info.vl_row) && (y < ymax); y++) |
paul@215 | 34 | { |
paul@215 | 35 | pixel = (value >> (((y - ymin) * 8) / (ymax - ymin))) % 2 ? 0xffffffff : 0; |
paul@215 | 36 | |
paul@215 | 37 | for (x = xmin; (x < panel_info.vl_col) && (x < xmax); x++) |
paul@215 | 38 | { |
paul@215 | 39 | set_pixel(x, y, pixel); |
paul@215 | 40 | } |
paul@215 | 41 | } |
paul@215 | 42 | } |
paul@215 | 43 | |
paul@215 | 44 | void init_keyscan() |
paul@215 | 45 | { |
paul@215 | 46 | int column; |
paul@215 | 47 | |
paul@215 | 48 | for (column = 0; column < GPIO_KEYOUT_COUNT; column++) |
paul@215 | 49 | { |
paul@215 | 50 | task_gpio_set_pin(GPIO_KEYOUT_BASE + column); |
paul@215 | 51 | } |
paul@215 | 52 | } |
paul@215 | 53 | |
paul@215 | 54 | /* Tasks. */ |
paul@207 | 55 | |
paul@207 | 56 | void keyscan(unsigned short task) |
paul@207 | 57 | { |
paul@215 | 58 | int column, row; |
paul@215 | 59 | u8 value; |
paul@215 | 60 | |
paul@215 | 61 | init_keyscan(); |
paul@207 | 62 | |
paul@207 | 63 | while (1) |
paul@207 | 64 | { |
paul@207 | 65 | /* Select each column and read the key states. */ |
paul@207 | 66 | |
paul@207 | 67 | for (column = 0; column < GPIO_KEYOUT_COUNT; column++) |
paul@207 | 68 | { |
paul@215 | 69 | task_gpio_clear_pin(GPIO_KEYOUT_BASE + column); |
paul@215 | 70 | |
paul@207 | 71 | value = 0; |
paul@207 | 72 | |
paul@207 | 73 | for (row = 0; row < GPIO_KEYIN_COUNT; row++) |
paul@207 | 74 | { |
paul@215 | 75 | value = (value << 1) | !task_gpio_get_pin(GPIO_KEYIN_BASE + row); |
paul@207 | 76 | } |
paul@207 | 77 | |
paul@207 | 78 | /* Perform an operation indicating the status. */ |
paul@207 | 79 | |
paul@215 | 80 | plot_value(column * 10, column * 10 + 10, 0, 10 * GPIO_KEYIN_COUNT, value); |
paul@215 | 81 | |
paul@215 | 82 | task_gpio_set_pin(GPIO_KEYOUT_BASE + column); |
paul@207 | 83 | } |
paul@207 | 84 | } |
paul@207 | 85 | } |
paul@207 | 86 | |
paul@207 | 87 | void start_keyscan(unsigned short task) |
paul@207 | 88 | { |
paul@207 | 89 | u32 args[] = {task}; |
paul@207 | 90 | |
paul@207 | 91 | task_gpio_init(task); |
paul@207 | 92 | |
paul@207 | 93 | /* Invoke the task. */ |
paul@207 | 94 | |
paul@207 | 95 | start_task(task, (void (*)()) keyscan, args, 1); |
paul@207 | 96 | } |