Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved PS/2 decoder, added stacked mouse decoder #104

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kamocat
Copy link

@kamocat kamocat commented Apr 12, 2023

PS/2 decoder now recognizes host communication
Mouse decoder recognizes standard streaming mouse messages and provides human-readable "binary" output

I haven't made unit tests yet, I was hoping for some pointers on that.

decoders/ps2/pd.py Outdated Show resolved Hide resolved
decoders/ps2/pd.py Outdated Show resolved Hide resolved
decoders/ps2_keyboard/pd.py Outdated Show resolved Hide resolved
@fenugrec
Copy link
Contributor

General notes :

  • some of my comments in the code maybe irrelevant, I'm not super well versed in PD internals
  • maybe the 'Fixed copyright notices' should be squashed into one of the others ?
  • check log of this repo, your commit messages don't follow the pattern e.g. ps2: implement XYZ etc

@fenugrec
Copy link
Contributor

Also, unit tests : yes, absolutely want those. You may want to add some captures in the sigrok-dumps repo; then add your tests in the sigrok-test repo. I suggest looking at the 'spiflash' tests for an example of a stacked decoder test, it should be fairly straightforward to apply to kbd/mouse tests.

@kamocat
Copy link
Author

kamocat commented Apr 27, 2023

General notes :

  • some of my comments in the code maybe irrelevant, I'm not super well versed in PD internals
  • maybe the 'Fixed copyright notices' should be squashed into one of the others ?
  • check log of this repo, your commit messages don't follow the pattern e.g. ps2: implement XYZ etc

Thanks for the advice. I'll do some code cleanup and then squash the commits with better names.

Detects if host or device is initiaing communication
Outputs byte for stacked decoder
Outputs human-readable "binary" for logging
@kamocat kamocat reopened this Apr 28, 2023
@kamocat kamocat marked this pull request as ready for review April 28, 2023 22:36
Mouse decoder interprets the 3-byte packets for movement and clicking, but
ignores the configuration commands from the host.
Keyboard decoder interprets press and release messages for each key but does not keep track of state (capslock, shift, etc).
@@ -18,9 +19,11 @@
##

'''
This protocol decoder can decode PS/2 device -> host communication.
This protocol decoder can decode PS/2 device -> host communication \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed - are you sure you need the trailing \ ? see e.g. the uart PD

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I don't actually want to force a line break there, but I also don't want to exceed the standard column width (80 characters)

Improved name consistency to assist in unit tests
"mouse" and "keyboard" decoders renamed to "ps2_mouse" and "ps2_keyboard"
"ps2_packet" output renamed to simply "ps2"
- Changed start-bit to begin on data edge rather than clock edge
- Increased timeout to accept borderline slow clock speeds
- Changed Host RTS to look for the clock line held low for 100us, rather than
  a low clock on the falling edge of the data. Some hosts release the clock
  immidiately after pulling the data low, which may look simultaneous even at
  1MHz sample rates.
- Added Host RTS annotation
- Removed confusing "annotation offset" constant, expanded Ann class with host annotations
- Changed to not annotate bits if less than 9 are captured (incomplete word)
Host RTS is cleared if data is pulled low within 100us
Start bit doesn't have a maxium length requirement, the timer now begins when
the client pulls the clock low (after the host has released it)
@kamocat
Copy link
Author

kamocat commented Apr 29, 2023

Man. I keep thinking I'm done and then I find more edge-cases.
The stacked mouse decoder is going to need some work to handle the Microsoft mouse protocol. I haven't decided if I want to interpret the initialization bytes to determine the mode, or if I want to use heuristics to guess the packet size.

@kamocat
Copy link
Author

kamocat commented Apr 30, 2023 via email

@fenugrec
Copy link
Contributor

fenugrec commented May 1, 2023

This is due to the minimum clock rate of 10kHz, so one bit period becomes 100 microseconds. Would it be more pythonic to enter the constant in the constructor, and to use Hz instead of seconds?

Not sure. I'm always wary of unexplained magic constants in code; if they're not meant to be changed by the user at runtime then IMO it should at least be well documented in the code.

Refactored timeout into a class property instead of a function argument.
Now based on minimum clock frequency, rather than maximum clock period
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants