Complete documentation and references

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Complete documentation and references

Post by PureBasic » Sat May 23, 2020 12:42 pm

Hello all,

New to Micropython and I like it so far.
However I struggle to find some deep documentation of the various functions implemented. For example:
I2C.readfrom_mem()
The documentation is very evasive about the various types this function is expecting, and a search in the GitHub codebase only returns some usage and some references in the documentation.

Where is it? *lost*

PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Re: Complete documentation and references

Post by PureBasic » Sun May 24, 2020 1:24 am

Hi again,

The true real problem for me is that I am trying to talk to a device with 16bits register addresses.
In the I2C documentation, readfrom_mem seems to accept an addrsize parameter (that I set to 2).
In the ESP32 documentation, addrsize is not shown in the example, so does it means it is not working for ESP32?
When trying on the actual device with an addrsize argument, the function executes normally as long as you feed it an integer address (no error raised and a bytearray is returned); but if you look at it with an analyzer, you can see than the reg address is never sent.
I tried with different address types (byte array, array, list)...

I tried to dig around and well, I'm feeling blind.
I just can't find where readfrom_mem() is implemented. I will workaround with multiple writes and reads commands.

I still would love to know where it is implemented. ;)

PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Re: Complete documentation and references

Post by PureBasic » Sun May 24, 2020 1:27 am

Alright, just found out that addrsize is in bits, not bytes. :mrgreen:

User avatar
pythoncoder
Posts: 4171
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Complete documentation and references

Post by pythoncoder » Sun May 24, 2020 7:56 am

The docs assume familiarity with I2C concepts. I suggest you read an introduction to understand the issues common to all implementations.
Peter Hinch

PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Re: Complete documentation and references

Post by PureBasic » Sun May 24, 2020 3:49 pm

Yeah I am a newb for mpy but I'm not THAT noob :mrgreen:
I know the I2C bus and various implementations quite well, and already wrote my routines in C... I just don't know the usual python way and even less so the mpy way (I'm discovering).
Also my bad I didn't read the mpy I2C documentation well enough and I assumed addrsize was a bytes count. But, why would it be in bits? I2c is byte-based, and I've never seen a peripheral with partial bytes writes... Never seen an implementation of the I2C protocol where you can send bits...
Sending something else than bytes makes no sense to me. But again, idk, there may be corner cases.

Edit: reading machine_i2c.c, the address is actually processed by bytes (line [548:553]). There are no checks to see if the addrsize is a multiple of 8 before entering a for that does i-=8 ! So yeah, I just don't get it. Weird implementation. All sizes seem to be in bytes everywhere in mpy, and then you have this exception.

Could it be fixed without breaking a ton of apps? I guess not. Should it be fixed? Well... I would love to fix it because the way it is now is just scary. :mrgreen:

PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Re: Complete documentation and references

Post by PureBasic » Sun May 24, 2020 3:57 pm

But back to the Documentation, because I was talking documentation at first.

I can see now by reading the code that it is impossible to make proper doxygen documentation for the python API because of the way mpy is written. I don't really know the internals of doxy but would it be possible to still make one with some clever scripts? Generating a dummy python lib for the programming for example (I love having auto-completion and helps when I code, punching ctrl space when I don't remember the args for example).

I really don't know how it could be done.
I just wonder If that discussion already took place and if some possible ways to do it have been discussed.

User avatar
tve
Posts: 203
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: Complete documentation and references

Post by tve » Sun May 24, 2020 10:12 pm

I don't think you specified what type of device you're accessing but could it be that you should use I2C.readfrom and not I2C.readfrom_mem?

PureBasic
Posts: 6
Joined: Fri May 22, 2020 2:36 am

Re: Complete documentation and references

Post by PureBasic » Mon May 25, 2020 6:01 am

It's an ADAU1452.
https://imgur.com/a/YXoriPx

Post Reply