Shop OBEX P1 Docs P2 Docs Learn Events
Free a cog: Single cog keyboard + mouse object — Parallax Forums

Free a cog: Single cog keyboard + mouse object

GdSisGdSis Posts: 12
edited 2010-10-23 07:28 in Propeller 1
Hello all,

As learning exercise, I merged the Parallax keyboard and mouse objects on a single object.
It is working, but I couldn't found why·it sometimes freezes by a moment, at random intervals.
The same·also happens with the original objects, at least on my demoboard, but this "effect"
seems incrased on this version.
I also added a new method for lock settings·at runtime.
Plese consider to report any other glitches as it is very beta version that can be improved
considerably.

Thank you all, I found this forum very instructive.

Gus


·Edit: Please see usage inside.

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-05 10:40
    Excellent work well done.

    Graham
  • TimmooreTimmoore Posts: 1,031
    edited 2008-07-15 03:55
    Has anyone had this working on the protoboard with mouse and keyboard?
    Neither the mouse or keyboard are detected on my system and they are detected with the standard drivers.
    I debugged it a bit and can see several problems. I have started again from the original drivers but wondered whether anyone got it working before I go too far?
  • roglohrogloh Posts: 5,865
    edited 2010-10-23 03:35
    Hi all,

    I may have found the cause of the intermittent problem with this code after spending some time with a scope and tracking this down today. Combining the PS/2 keyboard and mouse driver is really great to save a COG but it was driving me crazy with occasional keyboard and mouse resets when typing and moving the mouse a lot.

    With the scope and a pin output showing the sampling time relative to the PS/2 clock signal I was seeing bad data pin sampling time periods from time to time and tracked it down to the delay code causing parity errors.

    I've made a couple of changes and now haven't seen the reset glitches that were happening before. I believe this code below that was doing the counter polling was problematic as it was modifying the "t" timestamp variable being compared to the cnt register within the loop itself which I don't believe was the original intention.

    Original code:
    nap                    rdlong  t,#0                    'get clkfreq
    napshr                 shr     t,#18/16/13             'shr scales time
                           min     t,#3                    'ensure waitcnt won't snag
                           add     t,cnt                   'add cnt to time
    napwait                jmpret  keycode,mousecode       'run a chunk of mouse code, then return
                           sub     t,cnt
                           cmps    t,#0            wc
           if_nc           jmp     #napwait
    nap_ret                ret
    
    ...
    
    mnap                   rdlong  tm,#0                   'get clkfreq
    mnapshr                shr     tm,#18/16/13            'shr scales time
                           min     tm,#3                   'ensure waitcnt won't snag
                           add     tm,cnt                  'add cnt to time
    mnapwait               jmpret  mousecode,keycode       'run a chunk of keyboard code, then return
                           sub     tm,cnt
                           cmps    tm,#0           wc
           if_nc           jmp     #mnapwait
    mnap_ret               ret
    
    
    
    
    
    New code with fixes in red:
    nap                    rdlong  t,#0                    'get clkfreq
    napshr                 shr     t,#18/16/13             'shr scales time
                           min     t,#3                    'ensure waitcnt won't snag
                           add     t,cnt                   'add cnt to time
    napwait                jmpret  keycode,mousecode       'run a chunk of mouse code, then return
    [COLOR="Red"]                       mov     phsb,cnt
                           sub     phsb,t
                           cmps    phsb,#0    wc
           if_c            jmp     #napwait
    [/COLOR]nap_ret                ret
    
    ... 
    
    mnap                   rdlong  tm,#0                   'get clkfreq
    mnapshr                shr     tm,#18/16/13            'shr scales time
                           min     tm,#3                   'ensure waitcnt won't snag
                           add     tm,cnt                  'add cnt to time
    mnapwait               jmpret  mousecode,keycode       'run a chunk of keyboard code, then return
    [COLOR="Red"]                       mov     phsb,cnt
                           sub     phsb,tm
                           cmps    phsb,#0    wc
           if_c            jmp     #mnapwait
    [/COLOR]mnap_ret               ret
    
    


    The two additional instructions I added to this code filled the COG so I didn't have space for the temporary result I required and I had to steal the phbs register, but it was not being used so it should be safe to use.

    Enjoy,
    Roger.
  • KyeKye Posts: 2,200
    edited 2010-10-23 07:10
    Good Job!

    Just so you know. I made a much better version of this driver...

    http://obex.parallax.com/objects/654/

    Way more features.
  • RaymanRayman Posts: 14,889
    edited 2010-10-23 07:28
    Nice work. I've very interested in a combined driver.

    I hope to hear from people who have tested this type driver...
Sign In or Register to comment.