# HG changeset patch # User Paul Boddie # Date 1475526347 -7200 # Node ID 1f51b3efd042851c72144c57e4492139accbb133 # Parent aee4b1c755b549b61afb604402c3ee34d7167c5a Adjusted GPIO usage and added a form of visual feedback. Unfortunately, it appears that GPIO locations are not accessible in user mode, even through the memory management unit. diff -r aee4b1c755b5 -r 1f51b3efd042 stage2/tasks/keyscan.c --- a/stage2/tasks/keyscan.c Mon Oct 03 22:24:54 2016 +0200 +++ b/stage2/tasks/keyscan.c Mon Oct 03 22:25:47 2016 +0200 @@ -20,10 +20,45 @@ #include "board.h" #include "tasks.h" #include "task_gpio.h" +#include "jzlcd.h" +#include "lcd.h" + +extern vidinfo_t panel_info; + +void plot_value(unsigned short xmin, unsigned short xmax, unsigned short ymin, unsigned short ymax, u8 value) +{ + unsigned short x, y; + u32 pixel; + + for (y = ymin; (y < panel_info.vl_row) && (y < ymax); y++) + { + pixel = (value >> (((y - ymin) * 8) / (ymax - ymin))) % 2 ? 0xffffffff : 0; + + for (x = xmin; (x < panel_info.vl_col) && (x < xmax); x++) + { + set_pixel(x, y, pixel); + } + } +} + +void init_keyscan() +{ + int column; + + for (column = 0; column < GPIO_KEYOUT_COUNT; column++) + { + task_gpio_set_pin(GPIO_KEYOUT_BASE + column); + } +} + +/* Tasks. */ void keyscan(unsigned short task) { - int column, row, value; + int column, row; + u8 value; + + init_keyscan(); while (1) { @@ -31,17 +66,20 @@ for (column = 0; column < GPIO_KEYOUT_COUNT; column++) { - task_gpio_set_pin(GPIO_KEYOUT_BASE + column); + task_gpio_clear_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); + 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); + plot_value(column * 10, column * 10 + 10, 0, 10 * GPIO_KEYIN_COUNT, value); + + task_gpio_set_pin(GPIO_KEYOUT_BASE + column); } } }