1.1 --- a/stage2/tasks/keyscan.c Wed Jun 28 16:31:54 2017 +0200
1.2 +++ b/stage2/tasks/keyscan.c Thu Jun 29 23:26:39 2017 +0200
1.3 @@ -43,20 +43,27 @@
1.4
1.5 void init_keyscan()
1.6 {
1.7 - int column;
1.8 + uint8_t pin;
1.9
1.10 - for (column = 0; column < GPIO_KEYOUT_COUNT; column++)
1.11 + for (pin = 0; pin < GPIO_KEYIN_COUNT; pin++)
1.12 {
1.13 - task_gpio_set_pin(GPIO_KEYOUT_BASE + column);
1.14 + task_gpio_as_input(GPIO_KEYIN_ROW[pin]);
1.15 + task_gpio_enable_pull(GPIO_KEYIN_ROW[pin]);
1.16 }
1.17 +
1.18 + for (pin = 0; pin < GPIO_KEYOUT_COUNT; pin++)
1.19 + {
1.20 + task_gpio_as_input(GPIO_KEYOUT_COL[pin]);
1.21 + }
1.22 +
1.23 + task_gpio_as_input(GPIO_POWER);
1.24 }
1.25
1.26 /* Tasks. */
1.27
1.28 void keyscan(uint8_t task)
1.29 {
1.30 - int column, row;
1.31 - uint8_t value;
1.32 + uint8_t column, row, value;
1.33
1.34 init_keyscan();
1.35
1.36 @@ -66,21 +73,26 @@
1.37
1.38 for (column = 0; column < GPIO_KEYOUT_COUNT; column++)
1.39 {
1.40 - task_gpio_clear_pin(GPIO_KEYOUT_BASE + column);
1.41 + task_gpio_as_output(GPIO_KEYOUT_COL[column]);
1.42 +
1.43 + for (unsigned int delay = 0; delay < 1000; delay++)
1.44 + task_gpio_clear_pin(GPIO_KEYOUT_COL[column]);
1.45
1.46 value = 0;
1.47
1.48 for (row = 0; row < GPIO_KEYIN_COUNT; row++)
1.49 {
1.50 - value = (value << 1) | !task_gpio_get_pin(GPIO_KEYIN_BASE + row);
1.51 + value = (value << 1) | (task_gpio_get_pin(GPIO_KEYIN_ROW[row]) ? 0 : 1);
1.52 }
1.53
1.54 /* Perform an operation indicating the status. */
1.55
1.56 plot_value(column * 10, column * 10 + 10, 0, 10 * GPIO_KEYIN_COUNT, value);
1.57
1.58 - task_gpio_set_pin(GPIO_KEYOUT_BASE + column);
1.59 + task_gpio_as_input(GPIO_KEYOUT_COL[column]);
1.60 }
1.61 +
1.62 + plot_value(100, 110, 0, 80, task_gpio_get_pin(GPIO_POWER) ? 0xff : 0);
1.63 }
1.64 }
1.65