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

applet.interface.i2c_master: add "scan" command #166

Merged
merged 2 commits into from Oct 6, 2019

Conversation

electroniceel
Copy link
Member

"scan" scans for i2c devices on read and write addresses in one go.
Some devices only ACK one of the addresses, so scanning both gives
a better overview of the bus. With this command you don't need to
do a "scan-read" and then a "scan-write" to get the result.

@whitequark
Copy link
Member

Should we maybe have a single scan command with options -r, -w, (combined) -rw instead?

@electroniceel
Copy link
Member Author

would also be an option. I'm indifferent, both ways are a reasonable interface IMO.

@whitequark
Copy link
Member

Let's do that instead. Would you adjust the PR please?

@electroniceel
Copy link
Member Author

will do


p_scan.add_argument(
"--readwrite", "-rw", action="store_true", default=False,
help="scan read and write addresses")
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't the combination of -r and -w already work as -rw with no additional effort? Or does argparse not provide that?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, you are right. I didn't give argparse enough credit, it can do it.
Will fix it in the next rev.

@@ -233,6 +233,24 @@ def __init__(self, interface, logger):
revision = device_id[2] & 0x7
return (manufacturer, part_ident, revision)

async def scan(self, read_addrs=True, write_addrs=True):
Copy link
Member

Choose a reason for hiding this comment

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

You should mark any boolean flags as keyword-only arguments, like async def scan(self, *, read_addrs=True, write_addrs=True):. (I should add a CONTRIBUTING.md file that explains these things...)

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, I wasn't thinking pythonic enough. Will fix that in the next rev.

…mands with "scan"

"-r", "-w" and "-rw" allow to select which type of addresses to scan.
"-rw" is the default.

Some devices only ACK one of the addresses, so scanning both gives
a better overview of the bus.
…sterInterface

Allows to use it from other applets or the repl interface
@whitequark whitequark merged commit 89c5c05 into GlasgowEmbedded:master Oct 6, 2019
@whitequark
Copy link
Member

Thanks!

@electroniceel
Copy link
Member Author

Do you think side effects are more likely with read scanning than write scanning?
If so, we could change the order of read and write scanning.

@whitequark
Copy link
Member

In case of read scanning you're reading one byte, in case of write scanning you're aborting the transaction after the address, which is why I thought it's more likely.

@electroniceel
Copy link
Member Author

I remember reading a datasheet where the interrupt line was reset when reading out the irq register or something like that. That would match your line of thought.
So let's do the write scan first. If the device answers, no read scan is done. This will reduce the likeliness of read-side effects.

@whitequark
Copy link
Member

Let's.

@electroniceel
Copy link
Member Author

grmpf. additions to a branch aren't possible in github once it's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants