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

SoftI2C is asking for an id parameter and it should not #374

Closed
couillonnade opened this issue Mar 31, 2023 · 12 comments
Closed

SoftI2C is asking for an id parameter and it should not #374

couillonnade opened this issue Mar 31, 2023 · 12 comments

Comments

@couillonnade
Copy link

SoftI2C stub is asking for an id parameter. This only exists for hardware I2C.

This is correct:
t = machine.SoftI2C(scl=machine.Pin(4),sda=machine.Pin(5),freq=400000)

This is incorrect:

t = machine.SoftI2C(0,scl=machine.Pin(4),sda=machine.Pin(5),freq=400000)
Traceback (most recent call last):
File "", line 1, in 
TypeError: extra keyword arguments given

Pylance is not happy with it:

i2c = machine.SoftI2C(scl=machine.Pin(sclpin),
sda=machine.Pin(sdapin),
freq=i2cfreq)

Expected 1 more positional argumentPylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)
(module) machine

It seems that this has changed in v1.14 in 2021 so this is quite old since the latest is 1.19
https://github.com/micropython/micropython/releases

Breaking changes in this release are:
machine.I2C and machine.SPI constructors are changed when using software-based I2C and SPI. Code that constructed I2C/SPI peripherals in the following way will need to be changed (or else their use will emit a warning which will eventually be an error):

machine.I2C(-1, ...) -> machine.SoftI2C(...)
machine.I2C(scl=scl, sda=sda) -> machine.SoftI2C(scl=scl, sda=sda)

machine.SPI(-1, ...) -> machine.SoftSPI(...)
machine.SPI(sck=sck, mosi=mosi, miso=miso)
-> machine.SoftSPI(sck=sck, mosi=mosi, miso=miso)

@couillonnade
Copy link
Author

Sorry, wrong repo.

@couillonnade couillonnade closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2023
@Josverl
Copy link
Owner

Josverl commented Apr 4, 2023

If this is for micropython stubs then I could move the issue, but not sure if I can understand the question or issue withiuth details of the port board and version of the stubs in that case

@couillonnade
Copy link
Author

I am using Pico-W-Stub with vscode and when machine.SoftI2C, Pylance ask for one more parameter (the id).

umachine has SoftI2C class with this:
def __init__(self, id: int, /, *, scl: Pin, sda: Pin, freq: int = 400_000):

However, the id parameter should not be there. Removing it solves Pylance error.
I am not really familiar with the structure of stubs nor a Python guy so please let me know if this is clear or not.

image

@Josverl
Copy link
Owner

Josverl commented Apr 5, 2023

Those stubs are not maintained by me, and are indeed incorrect.

I think mine are correct,
    def __init__(self, scl, sda, *, freq=400000, timeout=50000) -> None:

It should be possible to reconfigure your project to use the more up to date stubs

And/or raise this with the Pico maintainer

@couillonnade
Copy link
Author

Thanks! I figured out it was not the right repo that's why I closed it. I already raise it to the maintainer but no feedback so far.

I'll read how to switch to your stubs and replace it automatically.

@Josverl
Copy link
Owner

Josverl commented Apr 5, 2023

NP, happy to help

@couillonnade
Copy link
Author

Quick question about the stub since I could not find answer in the docs: why are there both init (initialize) and init function ? Not sure about the logic behind the duplicate def init()?

@Josverl
Copy link
Owner

Josverl commented Apr 14, 2023

All classes should have an init
I try to deduce the parameter signature from the documentation of the class

https://docs.micropython.org/en/latest/library/machine.I2C.html#machine.SoftI2C

class machine.SoftI2C(scl, sda, *, freq=400000, timeout=50000)

The I2C class also has an init method documented, with a slightly different signature

I2C.init(scl, sda, *, freq=400000)

Perhaps this is a Documentation error?

Have you tested if the SoftI2C class accepts/has both methods?

On the board firmware I find the SoftI2C method is reported as having the init method

https://github.com/Josverl/micropython-stubs/blob/main/stubs/micropython-v1_19_1-rp2/machine.py#L221-L222

@couillonnade
Copy link
Author

You are right and the documentation is right. I did not see it at first because I only looked at RP2 port and not the general documentation!

@Josverl
Copy link
Owner

Josverl commented Apr 19, 2023

Do you have a link to the page with the wrong info?
Then I can send a PR to correct the docs

@couillonnade
Copy link
Author

couillonnade commented Apr 20, 2023

I searched but what I see now is correct. The only thing I can think about is I may have looked at an older version of the doc. Thanks for your patience!

image

@Josverl
Copy link
Owner

Josverl commented Apr 20, 2023

No problem 👍

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

No branches or pull requests

2 participants