1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-16 04:15:21 +03:00
iris/boot-programs/keyboard.ccp

74 lines
2.3 KiB
Plaintext
Raw Normal View History

2009-05-22 23:48:49 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// thread0.ccp: Testing userspace thread.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-06-10 23:54:12 +03:00
#include <iris.h>
#include "devices.hh"
#include "jz4730.hh"
2009-05-22 23:48:49 +03:00
2009-06-08 14:46:13 +03:00
// GPIO pins for the keyboard://
2009-06-01 20:22:11 +03:00
// Rows = 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 125
// Cols = 0, 1, 2, 3, 4, 5, 6, 7
2009-06-08 14:46:13 +03:00
static void event (bool release, unsigned row, unsigned col):
2009-06-10 23:54:12 +03:00
kdebug (col * 2 + (release ? 1 : 0))
2009-06-08 14:46:13 +03:00
2009-06-10 23:54:12 +03:00
#define ROW_MASK 0x2000ffff
#define COL_MASK 0x000000ff
2009-06-01 20:22:11 +03:00
2009-05-22 23:48:49 +03:00
int main ():
2009-06-10 23:54:12 +03:00
map_gpio ()
2009-06-01 20:22:11 +03:00
// Disable all interrupts.
2009-06-10 23:54:12 +03:00
GPIO_GPIER (3) &= ~ROW_MASK
GPIO_GPIER (0) &= ~COL_MASK
2009-06-01 20:22:11 +03:00
2009-06-08 14:46:13 +03:00
// Set all to GPIO.
2009-06-10 23:54:12 +03:00
GPIO_GPALR (3) = 0
GPIO_GPAUR (3) &= ~0x0c000000
GPIO_GPALR (0) &= ~0x0003ffff
2009-06-01 20:22:11 +03:00
2009-06-08 14:46:13 +03:00
// Set all rows to input and enable the pull-ups.
2009-06-10 23:54:12 +03:00
GPIO_GPDIR (0) &= ~COL_MASK
GPIO_GPPUR (0) |= COL_MASK
2009-06-08 14:46:13 +03:00
2009-06-10 23:54:12 +03:00
// Set all columns to input and enable the pull-ups; set to 0 when output.
GPIO_GPDIR (3) &= ROW_MASK
GPIO_GPPUR (3) |= ROW_MASK
GPIO_GPDR (3) &= ~ROW_MASK
2009-06-08 14:46:13 +03:00
#define NUM_COLS 17
unsigned keys[NUM_COLS]
for unsigned i = 0; i < NUM_COLS; ++i:
keys[i] = 0
2009-06-01 20:22:11 +03:00
2009-06-08 14:46:13 +03:00
// Pin numbers for the cols, relative to the start of the port (so minus 0x60).
int const cols[NUM_COLS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 29 }
2009-05-22 23:48:49 +03:00
while true:
2009-06-01 20:22:11 +03:00
// read keyboard
2009-06-08 14:46:13 +03:00
unsigned data[NUM_COLS]
for unsigned col = 0; col < NUM_COLS; ++col:
2009-06-10 23:54:12 +03:00
GPIO_GPDIR (3) = (GPIO_GPDIR (3) & ~ROW_MASK) | 1 << cols[col]
udelay (100)
unsigned data = GPIO_GPDR (0) & COL_MASK
// Generate events.
2009-06-08 14:46:13 +03:00
for unsigned row = 0; row < 8; ++row:
2009-06-10 23:54:12 +03:00
if (data ^ keys[col]) & (1 << row):
event (data & (1 << row), row, col)
keys[col] = data
2009-06-01 20:22:11 +03:00
schedule ()