PS/2 with RLP

Hi guys,

Forgive me if this is a dumb question - I’m pretty new to this newfangled hardware trickery. :slight_smile:

I’m trying to get a PS/2 keyboard working with my Panda II. Originally I was using interrupts in C# but it appears they’re too slow, so I’m now developing an RLP module for it.

PS/2 uses a “packet” size of 11 bits - so I should see 11 interrupts with the following whenever I press down on a key (and then multiples of 11 on releasing the key etc):

RLP_InterruptInputPinArgs ia;
ia.GlitchFilterEnable = RLP_FALSE;
ia.IntEdge = RLP_GPIO_INT_EDGE_LOW;
ia.ResistorState = RLP_GPIO_RESISTOR_PULLUP;

RLPext->GPIO.EnableInterruptInputMode(clock_pin, &ia, clock_isr, 0);

Weird thing is, I seem to get exactly 6 interrupts per packet. I’ve tried with two keyboards and it does exactly the same thing - 6 interrupts per packet. (I made the ISR simply increase a counter and added a function to retrieve the counter value.)

I’m using this site for reference: [url]http://www.computer-engineering.org/ps2protocol/[/url]

If anyone has any ideas, I’d be grateful!

Thanks for reading. :slight_smile:

Use PinCapture class so it is easier for you to debug this in C# side instead of RLP. Then you can determine how many edges you receive.

or use a scope if you have one

Hi Gus, thanks for your answer. I didn’t know about PinCapture, very useful! :slight_smile:

PinCapture shows all 11 changes, with gaps of about 40 microseconds in between (which I think is about right). My ISR looks like this:

void clock_isr(unsigned int p, unsigned int ps, void *pa)
{	
	unsigned int data = RLPext->GPIO.ReadPin(data_pin);
	
	if (read_pos == 0)			/* start bit = 0 */
		read_pos++;
	else if (read_pos == 9)		/* parity - odd */
		read_pos++;
	else if (read_pos == 10)	/* stop bit = 1 */
	{
		b_pos = b_next;
		b_next = buf_inc(b_next);
		*b_next = 0;
		read_pos = 0;
	}
	else						/* data bits, LSB first */
	{
		*b_next = *b_next | (data << (read_pos - 1));
		read_pos++;
	}	
}

Are my expectations too high, or should I be able to manage this with RLP?

RLP can handle that and a lot more :slight_smile:

Start simple, enable a pin with interrupt edge low and then your ISR will only contain variable++
Then there is another RLP to read “variable”

If it doesn’t work then do this:

  1. enable interrupt on the clock pin
  2. once inside the ISR, stay there to read all 11 bits
  3. exit ISR

Note that you are reading a clock that is changing every about 30 microsoceonds so you should read the pin directly instead of using RLP extensions. Make a pin input and ready inside C# but then read the pin directly from the processor.

my_pin = (IOxPIN&(1<<pin)>0);// x is the port and pin is the pin on that port. You need the schematics to determine the port/pin that is related to the NETMF IO you are using.

==================

Another option?
Open SPI in 11 bit more in RLP and let the hardware take care of everything.

=================

Another option? :slight_smile:
You will have to buy me a beer first :slight_smile:

Unfortunately, even if I just have the ISR do a variable++ and read it out in the code, I only appear to be getting 6 IRQs. I tried reading all 11 bits inside the ISR but I think I don’t understand enough about what I’m doing yet; this is my first foray into the world of hardware programming (I’m a C# web applications developer by trade). I will continue to read and poke and hopefully not burn myself with solder too much until I get it. :slight_smile: If nothing else, it’s good fun, and I’m learning things I never knew about microprocessors!

Thanks again for all your help, it’s much appreciated - if I lived close enough, I would definitely be buying you beer! :slight_smile:

Just in case anyone is interested, I eventually managed to get this roughly working. :slight_smile:

I’ve put what I managed to do on the ‘Code’ site ( [url]http://code.tinyclr.com/project/359/read-from-a-ps2-keyboard-with-rlp/[/url] ). Where there’s a will, there’s a way! :slight_smile:

great work

You are bringing back memories of my DOS programming days :slight_smile:
How about adding support for shift / alt / ctrl combinations and function keys.