Skip to content

esp8266 port missing time.{sleep_us, sleep_ms} #803

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

Closed
larsks opened this issue May 3, 2018 · 9 comments
Closed

esp8266 port missing time.{sleep_us, sleep_ms} #803

larsks opened this issue May 3, 2018 · 9 comments

Comments

@larsks
Copy link

larsks commented May 3, 2018

I wanted to use this tm1637 module with CircuitPython, but it requires the utime.sleep_us method. I see this reference in modutime.c in the CircuitPython sources, but it doesn't appear to be available on the time module once the board boots.

That tm1637 module works fine with upstream micropython.

@sommersoft
Copy link

According to what I'm seeing in the Makefile, neither modtime.c nor extmod/utime_mphal.x are used in the CircuitPython version. Like @tannewt alluded to in Discord, a lot of the time.xxx functions in utime are not CPython compatible...which goes against one of the goals of CircuitPython.

I do think we'll need to figure something out though. With attempting to bring pulseio functions to the ESP8266 port (Issue #716), we'll most likely need some microsecond counting mechanism. Milliseconds just won't cut it...

@sommersoft
Copy link

So, I should have looked before, but I was pretty confident there are some timers available...

delay_us is available from microcontroller. There are some additional delay/tick functions available at the C level in esp_mphal...

@larsks
Copy link
Author

larsks commented May 3, 2018

@sommersoft, thanks for the feedback.

I see that microcontroller.delay_us is available, but it doesn't seem to work. That is, I would expect microcontroller.delay_us(1000000) to delay for 1 second, but it returns immediately. It's defined in terms of os_delay_us(), which I can't find anywhere.

@larsks
Copy link
Author

larsks commented May 4, 2018

I have the utime module working now; the necessary changes are here. I would be happy to submit this as a pull-request if it's the sort of thing people would like, but I'm not sure what CP thinks about the u* modules in general...

@dhalbert
Copy link
Collaborator

dhalbert commented May 4, 2018

We're discussing in issue #519 about how and where to add more time functionality. @tannewt has suggested adding a precise_time module for functionality above and beyond time.

We are moving away from the u* modules in favor of more descriptive ones with a more consistent API. We either provide a subset of or the same functionality provided by a CPython module, or we come up with a new module that has its own API, not necessarily derivative in terms of naming

@tannewt
Copy link
Member

tannewt commented May 4, 2018

I wouldn't be surprised if os_delay_us had a maximum time it will wait. Precise microsecond timing is whole different beast to timing out a second. Microsecond timing can only be done reliably with interrupts off while second level timing can leave them on.

Even if we did provide a way to measure 10 microseconds, the actual delay would be longer due to the speed of the VM. It does given you a minimum delay though.

@larsks
Copy link
Author

larsks commented May 4, 2018

@tannewt while I understand your comments about timing accuracy, I will note that with the sleep_us function available, CircuitPython has no problem driving the TM1637 display.

Either the accuracy is "good enough" or the TM1637 is really lenient.

@tannewt
Copy link
Member

tannewt commented May 4, 2018 via email

@tannewt
Copy link
Member

tannewt commented May 7, 2018

We won't be adding any extra functions to time that aren't in CPython. #519 covers CircuitPython specific options so closing this issue.

@tannewt tannewt closed this as completed May 7, 2018
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

4 participants