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

[DO NOT MERGE] Update for forthcoming beta MicroPython #97

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

microbit-matt-hillsdon
Copy link
Contributor

API is not yet final.

Issues:

  • I think the docs PRs are missing get_touches too but will revisit that.

I think the docs PRs are missing get_touches too but will revisit that.
These are not final and we have outstanding queries.
To match changes in docs: Update Power Mgm to change run_every behaviour #769
To match PR docs: Add missing days parameter to microbit.run_every. (#767)
This reverts commit 5ff1eb7.
Accidentally changed lang/ca/typeshed (Welsh one) instead of en.
Comment on lines +59 to +68
def ticks_cpu() -> int:
"""
Similar to ticks_ms and ticks_us, but with higher resolution in CPU cycles.

Example: ``time.ticks_cpu()``

:return: The counter value in CPU cycles.
"""
...

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @microbit-carlos, this is the best guess we made for ticks_cpu because we couldn't find micropython docs on it. Is this right and are there any more specific information we can add about this? Thanks!

Copy link
Contributor

@microbit-carlos microbit-carlos Apr 3, 2024

Choose a reason for hiding this comment

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

Hi Grace,

I wasn't aware that the ticks_cpu function was enabled in the V2 MicroPython port, do you know when it was added? Has it been added only in the latest release?

There is some upstream documentation here: https://docs.micropython.org/en/latest/library/time.html#time.ticks_cpu

But it would be good to understand the exact implementation for micro:bit and to have that in the official micro:bit docs as well. I'll have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgraded here: microbit-foundation/micropython-microbit-v2@fdaf840

That diff contains the implementation that uses CYCCNT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the moment we always return zero in the sim for ticks_cpu but we could return the same as ticks_us or a multiple. ticks_us is already a 1000 * multiple of ticks_ms which is our real resolution in the sim.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it was added with the update to MicroPython 1.22.0 in January: microbit-foundation/micropython-microbit-v2#166
It uses low level Arm register to count cycles, so this should be correct (of course, there will be a bit of overhead by calling and returning from a Python function but that's the same for every other time.ticks_xx function):
https://github.com/microbit-foundation/micropython-microbit-v2/blob/8d9067d91bcfe316cd3aea5af1a873a37ca23d13/src/codal_port/mphalport.h#L48-L55

The thing to keep in mind is that this is register is 32 bits and we run at 64 MHz, so the register overflows every minute ish ( 2^32 / 64_000_000 = 67 seconds)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @microbit-carlos !

Copy link
Contributor

Choose a reason for hiding this comment

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

Correction, it's likely 30-bits due to small int size in MicroPython.

To be updated once there is a doc for it.
Comment on lines +57 to +69
The ``SoundEvent.LOUD`` event is triggered when the sound level crosses the
threshold from "quiet" to "loud", and the ``SoundEvent.QUIET`` event is
triggered when the sound level crosses from "loud" to "quiet".

If the ``SoundEvent.LOUD`` threshold is set lower than the
``SoundEvent.QUIET`` threshold, then the ``SoundEvent.QUIET`` threshold
will decrease by one unit below the ``SoundEvent.LOUD`` threshold. If the
``SoundEvent.QUIET`` threshold is set higher than the ``SoundEvent.LOUD``
threshold, then the ``SoundEvent.LOUD`` threshold will increase by one unit
above the ``SoundEvent.QUIET`` threshold.

:param event: A sound event, such as ``SoundEvent.LOUD`` or ``SoundEvent.QUIET``.
:param value: The threshold level in the range 0-255.
:param value: The threshold level in the range 0-255. Values outside this range will be clamped.
Copy link
Contributor

@microbit-grace microbit-grace Apr 12, 2024

Choose a reason for hiding this comment

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

This is an update based on recently merged micropython doc PR.

f5ca4aa - I copied set_threshold doc from the PR
936b172 - my update of it to make the tenses match the rest of the docs and to make it clearer (maybe)?

Looks quite verbose, so I am tempted to cut it down, but am not sure how
Screenshot 2024-04-12 at 17 17 21

Comment on lines +82 to +89
def sound_level_db() -> int:
"""Get the sound pressure level in decibels.

Example: ``microphone.sound_level_db()``

:return: A representation of the sound pressure level in decibels (dB).
"""
...
Copy link
Contributor

Choose a reason for hiding this comment

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

May be subject to change following bbcmicrobit/micropython#803 PR

We'll have to do something about dunder docs as they're really key to
this API
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.

3 participants