mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-08-22 13:52:04 +03:00
119 lines
3.5 KiB
COBOL
119 lines
3.5 KiB
COBOL
#pypp 0
|
|
// 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/>.
|
|
|
|
#include "iris.h"
|
|
|
|
// GPIO pins for the keyboard://
|
|
// 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
|
|
|
|
// Rows: 60...6f; 7d
|
|
|
|
// Nicely aligned to a port: use rows as output; cols as input.
|
|
|
|
// Map memory from b0010000, which is really 10010000 in kseg1.
|
|
|
|
#define D(n) (*(volatile unsigned *)(0x00 + 0x30 * n + address))
|
|
#define DI(n) (*(volatile unsigned *)(0x04 + 0x30 * n + address))
|
|
#define PU(n) (*(volatile unsigned *)(0x0c + 0x30 * n + address))
|
|
#define AL(n) (*(volatile unsigned *)(0x10 + 0x30 * n + address))
|
|
#define AU(n) (*(volatile unsigned *)(0x14 + 0x30 * n + address))
|
|
#define IE(n) (*(volatile unsigned *)(0x20 + 0x30 * n + address))
|
|
|
|
unsigned const address = 0x00010000
|
|
|
|
static void event (bool release, unsigned row, unsigned col):
|
|
debug_set_led (col * 2 + (release ? 1 : 0))
|
|
|
|
static void delay ():
|
|
for unsigned i = 0; i < 100000; ++i:
|
|
IE (3) &= ~0x2000ffff
|
|
|
|
int main ():
|
|
// map memory
|
|
Capability page = memory_create_page (__my_memory)
|
|
alloc_physical (page, 0x10010000, 0)
|
|
memory_map (__my_memory, page, address, 1)
|
|
|
|
#if 0
|
|
// Keyboard stuff doesn't seem to work. Try the simpler part: touchpad buttons.
|
|
IE (0) &= ~0x00012000
|
|
AL (0) &= ~0x0c000000
|
|
AU (0) &= ~0x00000003
|
|
DI (0) &= ~0x00012000
|
|
PU (0) &= ~0x00012000
|
|
|
|
unsigned old = 0
|
|
while true:
|
|
unsigned data = D (0) & 0x00012000
|
|
if data == old:
|
|
continue
|
|
if data & ~old & 0x00010000:
|
|
event (true, 0, 0)
|
|
else if ~data & old & 0x00010000:
|
|
event (false, 0, 0)
|
|
if data & ~old & 0x00002000:
|
|
event (true, 1, 1)
|
|
else if ~data & old & 0x00002000:
|
|
event (false, 1, 1)
|
|
old = data
|
|
#else
|
|
// Disable all interrupts.
|
|
IE (3) &= ~0x2000ffff
|
|
IE (0) &= ~0x000001ff
|
|
|
|
// Set all to GPIO.
|
|
AL (3) = 0
|
|
AU (3) &= ~0x0c000000
|
|
AL (0) &= ~0x0003ffff
|
|
|
|
// Set all rows to input and enable the pull-ups.
|
|
DI (0) &= ~0x000000ff
|
|
PU (0) |= 0x000000ff
|
|
|
|
// Set all columns to output, 0.
|
|
DI (3) |= 0x2000ffff
|
|
D (3) &= ~0x2000ffff
|
|
|
|
#define NUM_COLS 17
|
|
unsigned keys[NUM_COLS]
|
|
for unsigned i = 0; i < NUM_COLS; ++i:
|
|
keys[i] = 0
|
|
|
|
// 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 }
|
|
while true:
|
|
// read keyboard
|
|
unsigned data[NUM_COLS]
|
|
for unsigned col = 0; col < NUM_COLS; ++col:
|
|
D (3) &= ~0x2000ffff
|
|
delay ()
|
|
unsigned zero = ~D (0) & 0x000000ff
|
|
D (3) = (D (3) & ~0x2000ffff) | (1 << cols[col])
|
|
delay ()
|
|
data[col] = D (0) & zero
|
|
|
|
// Generate events.
|
|
for unsigned col = 0; col < NUM_COLS; ++col:
|
|
for unsigned row = 0; row < 8; ++row:
|
|
if (data[col] ^ keys[col]) & (1 << row):
|
|
event (data[col] & (1 << row), row, col)
|
|
keys[col] = data[col]
|
|
schedule ()
|
|
#endif
|