Toolbox-2/source/boulder/bellatrix/Keyboard.spin

1 line
28 KiB
Plaintext
Raw Normal View History

2014-05-02 20:16:37 +02:00
''***************************************''* PS/2 Keyboard Driver v1.0.1 *''* Author: Chip Gracey *''* Copyright (c) 2004 Parallax, Inc. *''* See end of file for terms of use. *''***************************************{-----------------REVISION HISTORY----------------- v1.0.1 - Updated 6/15/2006 to work with Propeller Tool 0.96} VAR long cog long par_tail 'key buffer tail read/write (19 contiguous longs) long par_head 'key buffer head read-only long par_present 'keyboard present read-only long par_states[8] 'key states (256 bits) read-only long par_keys[8] 'key buffer (16 words) read-only (also used to pass initial parameters)PUB start(dpin, cpin) : okay'' Start keyboard driver - starts a cog'' returns false if no cog available'''' dpin = data signal on PS/2 jack'' cpin = clock signal on PS/2 jack'''' use 100-ohm resistors between pins and jack'' use 10K-ohm resistors to pull jack-side signals to VDD'' connect jack-power to 5V, jack-gnd to VSS'''' all lock-keys will be enabled, NumLock will be initially 'on','' and auto-repeat will be set to 15cps with a delay of .5s okay := startx(dpin, cpin, %0_000_100, %01_01000)PUB startx(dpin, cpin, locks, auto) : okay'' Like start, but allows you to specify lock settings and auto-repeat'''' locks = lock setup'' bit 6 disallows shift-alphas (case set soley by CapsLock)'' bits 5..3 disallow toggle of NumLock/CapsLock/ScrollLock state'' bits 2..0 specify initial state of NumLock/CapsLock/ScrollLock'' (eg. %0_001_100 = disallow ScrollLock, NumLock initially 'on')'''' auto = auto-repeat setup'' bits 6..5 specify delay (0=.25s, 1=.5s, 2=.75s, 3=1s)'' bits 4..0 specify repeat rate (0=30cps..31=2cps)'' (eg %01_00000 = .5s delay, 30cps repeat) stop longmove(@par_keys, @dpin, 4) okay := cog := cognew(@entry, @par_tail) + 1PUB stop'' Stop keyboard driver - frees a cog if cog cogstop(cog~ - 1) longfill(@par_tail, 0, 19)PUB present : truefalse'' Check if keyboard present - valid ~2s after start'' returns t|f truefalse := -par_presentPUB key : keycode'' Get key (never waits)'' returns key (0 if buffer empty) if par_tail <> par_head keycode := par_keys.word[par_tail] par_tail := ++par_tail & $FPUB getkey : keycode'' Get next key (may wait for keypress)'' returns key repeat until (keycode := key)PUB newkey : keycode'' Clear buffer and get new key (always waits for keypress)'' returns key par_tail := par_head keycode := getkeyPUB gotkey : truefalse'' Check if any key in buffer'' returns t|f truefalse := par_tail <> par_headPUB clearkeys'' Clear key buffer par_tail := par_headPUB keystate(k) : state'' Get the state of a particular key'' returns t|f state := -(par_states[k >> 5] >> k & 1)DAT'******************************************'* Assembly language PS/2 keyboard driver *'****************************************** org''' Entry'entry movd :par,#_dpin 'load input parameters _dpin/_cpin/_locks/_auto mov x,par add x,#11*4 mov y,#4:par rdlong 0,x add :par,dlsb add x,#4 djnz y,#:par mov dmask,#1 'set pin masks shl dmask,_dpin mov cmask,#1 shl cmask,_cpin test _dpin,#$20 wc 'modify port registers within code muxc _d1,dlsb muxc _d2,dlsb muxc _d3,#1 muxc _d4,#1 test _cpin,#$20 wc muxc _c1,dlsb muxc _c2,dlsb muxc _c3,#1 mov _head,#0 'reset output parameter