-- -- file : ps2.jal -- author : Carlos Alfaro -- date : 14-DEC-2000 -- purpose : asynchronous PS/2 serial IO routines for host -- includes : jpic, ps2p -- -- Copyright (C) 2000 Carlos Alfaro -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 of the License, or (at your option) any later version. -- -- This library 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 -- Library General Public License for more details. -- -- You should have received a copy of the GNU Library General Public -- License along with this library; if not, write to the -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- Boston, MA 02111-1307, USA. -- -- required libraries include jpic -- the communication line settings include ps2p procedure ps2_wait_clock_low is while (ps2_clock_pin) loop end loop end procedure procedure ps2_wait_clock_high is while !(ps2_clock_pin) loop end loop end procedure -- send a bit procedure ps2_send_bit (bit in val) is if val then ps2_data_direction = input else ps2_data_direction = output ps2_data_pin = low end if ps2_wait_clock_low ps2_wait_clock_high end procedure -- receive a bit function ps2_read_bit return bit is var bit val val = ps2_data_pin ps2_wait_clock_high ps2_wait_clock_low return val end function -- send a byte procedure ps2_send( byte in x ) is var bit current_bit at x : 0 var bit parity ps2_clock_direction = output ps2_data_direction = output -- seize clock control ps2_clock_pin = low -- wait for abot 60 us for 0xFF loop end loop ps2_data_pin = low -- listen to device ps2_clock_pin = high ps2_clock_direction = input ps2_wait_clock_low -- send the 8 data bits parity = high for 8 loop parity = parity ^ current_bit ps2_send_bit(current_bit) x = x >> 1 end loop -- send parity bit ps2_send_bit(parity) -- disregard ACK ps2_data_direction = input ps2_read_bit end procedure procedure ps2'put( byte in x ) is ps2_send( x ) end procedure -- receive a bit procedure ps2_receive( byte out x ) is var bit current_bit at x : 7 ps2_clock_direction = input ps2_data_direction = input -- wait for device to seize clock ps2_wait_clock_low -- disregard start bit ps2_read_bit -- get the 8 data bits for 8 loop x = x >> 1 current_bit = ps2_read_bit end loop -- disregard parity and stop ps2_read_bit -- parity ps2_read_bit -- stop end procedure function ps2'get return byte is var byte x ps2_receive( x ) return x end function function ps2_poll( byte out x ) return bit is if ps2_clock_pin then ps2_receive (x) return true end if return false end function