# HG changeset patch # User Paul Boddie # Date 1500824664 -7200 # Node ID 1c82a374620ad5c259ba40699d10d3f54418fd07 # Parent 825b572484c67db8b7bdb86f285e818c9a8a4278 Made keypad detection function by fixing page table entries and pin definitions. diff -r 825b572484c6 -r 1c82a374620a stage2/minipc_gpio.c --- a/stage2/minipc_gpio.c Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/minipc_gpio.c Sun Jul 23 17:44:24 2017 +0200 @@ -19,10 +19,11 @@ * Boston, MA 02110-1301, USA */ +#include "minipc_gpio.h" #include "minipc.h" #include -#define PIN(x) (3 * 32 + x) +#define PIN(x) gpio_global_pin(3, x) const uint8_t GPIO_KEYIN_ROW[GPIO_KEYIN_COUNT] = { 0, 1, 2, 3, 4, 5, 6, 7 /* if jz_keypad.c is understood correctly */ diff -r 825b572484c6 -r 1c82a374620a stage2/minipc_gpio.h --- a/stage2/minipc_gpio.h Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/minipc_gpio.h Sun Jul 23 17:44:24 2017 +0200 @@ -26,6 +26,8 @@ #include +#define gpio_global_pin(port, pin) (port * 32 + pin) + extern const uint8_t GPIO_KEYIN_ROW[GPIO_KEYIN_COUNT]; extern const uint8_t GPIO_KEYOUT_COL[GPIO_KEYOUT_COUNT]; diff -r 825b572484c6 -r 1c82a374620a stage2/nanonote_gpio.c --- a/stage2/nanonote_gpio.c Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/nanonote_gpio.c Sun Jul 23 17:44:24 2017 +0200 @@ -19,20 +19,21 @@ * Boston, MA 02110-1301, USA */ +#include "nanonote_gpio.h" #include "nanonote.h" #include -#define PIN(x) (3 * 32 + 18 + x) +#define PIN(x) gpio_global_pin(3, 18 + x) const uint8_t GPIO_KEYIN_ROW[GPIO_KEYIN_COUNT] = { - 0, 1, 2, 3, 4, 5, 6, 7 + PIN(0), PIN(1), PIN(2), PIN(3), PIN(4), PIN(5), PIN(6), PIN(8) }; #undef PIN -#define PIN(x) (2 * 32 + 10 + x) +#define PIN(x) gpio_global_pin(2, 10 + x) const uint8_t GPIO_KEYOUT_COL[GPIO_KEYOUT_COUNT] = { - PIN(0), PIN(1), PIN(2), PIN(3), PIN(4), PIN(5), PIN(6), PIN(8), + PIN(0), PIN(1), PIN(2), PIN(3), PIN(4), PIN(5), PIN(6), PIN(7), }; #undef PIN diff -r 825b572484c6 -r 1c82a374620a stage2/nanonote_gpio.h --- a/stage2/nanonote_gpio.h Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/nanonote_gpio.h Sun Jul 23 17:44:24 2017 +0200 @@ -26,6 +26,8 @@ #include +#define gpio_global_pin(port, pin) (port * 32 + pin) + extern const uint8_t GPIO_KEYIN_ROW[GPIO_KEYIN_COUNT]; extern const uint8_t GPIO_KEYOUT_COL[GPIO_KEYOUT_COUNT]; diff -r 825b572484c6 -r 1c82a374620a stage2/task_gpio.c --- a/stage2/task_gpio.c Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/task_gpio.c Sun Jul 23 17:44:24 2017 +0200 @@ -33,10 +33,11 @@ for (virtual = TASK_GPIO_BASE, physical = GPIO_BASE_PHYSICAL; virtual < (uint32_t) TASK_GPIO_BASE + (uint32_t) GPIO_REGION_SIZE; - virtual += page_size(STAGE2_PAGESIZE), physical += page_size(STAGE2_PAGESIZE)) + virtual = next_page(virtual, STAGE2_PAGESIZE), + physical = next_page(physical, STAGE2_PAGESIZE)) { init_page_table(STAGE2_PAGE_TABLE_BASE, virtual, physical, - page_size(STAGE2_PAGESIZE), TLB_UNCACHED | TLB_DIRTY | TLB_VALID, task); + STAGE2_PAGESIZE, TLB_UNCACHED | TLB_DIRTY | TLB_VALID, task); } } diff -r 825b572484c6 -r 1c82a374620a stage2/tasks/keyscan.c --- a/stage2/tasks/keyscan.c Wed Jul 12 15:46:53 2017 +0200 +++ b/stage2/tasks/keyscan.c Sun Jul 23 17:44:24 2017 +0200 @@ -56,7 +56,7 @@ task_gpio_as_input(GPIO_KEYOUT_COL[pin]); } - task_gpio_as_input(GPIO_POWER); + task_gpio_as_input(gpio_global_pin(GPIO_PORT_POWER, GPIO_POWER)); } /* Tasks. */ @@ -74,9 +74,11 @@ for (column = 0; column < GPIO_KEYOUT_COUNT; column++) { task_gpio_as_output(GPIO_KEYOUT_COL[column]); + task_gpio_clear_pin(GPIO_KEYOUT_COL[column]); + + /* Employ a delay to avoid catching the last column's reading. */ for (unsigned int delay = 0; delay < 1000; delay++) - task_gpio_clear_pin(GPIO_KEYOUT_COL[column]); value = 0; @@ -92,7 +94,7 @@ task_gpio_as_input(GPIO_KEYOUT_COL[column]); } - plot_value(100, 110, 0, 80, task_gpio_get_pin(GPIO_POWER) ? 0xff : 0); + plot_value(100, 110, 0, 80, task_gpio_get_pin(gpio_global_pin(GPIO_PORT_POWER, GPIO_POWER)) ? 0xff : 0); } }