Mouse / Keyboard interface
Posted: Tue Sep 03, 2013 1:18 pm
Hi,
the last days I worked on a new ATmega8 firmware which supports the second PS/2 port for mouse handling. I can receive and send data from and to the mouse. Sending has to be implemented as the mouse doesn't report it's state after reset.
Now I am working on a protocol to send both - mouse- and keyboard-data - via one serial link. My idea is the ATmega8 fills two buffers within its interrupt routines: a kbd and a mouse buffer. The main function contains a simple loop only. This loop sends data as packets only and adds a magic byte for mouse data. E.g. every byte is interpreted as Ascii except 0x82 for example. If the kbd/mouse driver of the 68k recognizes this 0x82 it knows that the following three bytes are a mouse-data-packet.
In theory this should work but what about the details. What happens if the m68k wants to read a key but for a while the ATmega8 is sending mouse packets? Should it just drop the mouse packets? Should the packets be buffered? If the packets are buffered, the mouse routine has to read bytes from the buffer instead of accessing the hardware direct.
I came around that I would need three functions. The first is the only function which communicates with the ATmega. This function dispatches received data for two buffers. These buffers are for the two other functions. One to read from the keyboard and the other to read from the mouse. The last question is when to call function 1? I think it would be nice to call it independently. A periodical interrupt could do this task. Or I could call it from both routines. Thus I wouldn't waste a interrupt... What do you think?
Simon
the last days I worked on a new ATmega8 firmware which supports the second PS/2 port for mouse handling. I can receive and send data from and to the mouse. Sending has to be implemented as the mouse doesn't report it's state after reset.
Now I am working on a protocol to send both - mouse- and keyboard-data - via one serial link. My idea is the ATmega8 fills two buffers within its interrupt routines: a kbd and a mouse buffer. The main function contains a simple loop only. This loop sends data as packets only and adds a magic byte for mouse data. E.g. every byte is interpreted as Ascii except 0x82 for example. If the kbd/mouse driver of the 68k recognizes this 0x82 it knows that the following three bytes are a mouse-data-packet.
In theory this should work but what about the details. What happens if the m68k wants to read a key but for a while the ATmega8 is sending mouse packets? Should it just drop the mouse packets? Should the packets be buffered? If the packets are buffered, the mouse routine has to read bytes from the buffer instead of accessing the hardware direct.
I came around that I would need three functions. The first is the only function which communicates with the ATmega. This function dispatches received data for two buffers. These buffers are for the two other functions. One to read from the keyboard and the other to read from the mouse. The last question is when to call function 1? I think it would be nice to call it independently. A periodical interrupt could do this task. Or I could call it from both routines. Thus I wouldn't waste a interrupt... What do you think?
Simon