From d0b2544f88fe9bed4e25e9bff4220fdd5d4d8fe4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 8 Oct 2021 10:20:52 -0400 Subject: [PATCH 1/2] Add precision info to time.monotonic() --- shared-bindings/time/__init__.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 1529f1de50a6..3aa9b11b6f41 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -39,12 +39,26 @@ //| """time and timing related functions //| //| The `time` module is a strict subset of the CPython `cpython:time` module. So, code -//| written in MicroPython will work in CPython but not necessarily the other +//| using `time` written in CircuitPython will work in CPython but not necessarily the other //| way around.""" //| //| def monotonic() -> float: //| """Returns an always increasing value of time with an unknown reference -//| point. Only use it to compare against other values from `monotonic`. +//| point. Only use it to compare against other values from `time.monotonic()`. +//| +//| On most boards, `time.monotonic()` converts a 64-bit millisecond tick counter +//| to a float. Floats on most boards are encoded in 30 bits internally, with +//| effectively 22 bits of precision. The float returned by `time.monotonic()` will +//| accurately represent time to millisecond precision only up to 2**22 milliseconds +//| (about 1.165 hours). +//| At that point it will start losing precision, and its value will change only +//| every second millisecond. At 2**23 milliseconds it will change every fourth +//| millisecond, and so forth. +//| +//| If you need more consistent precision, use `time.monotonic_ns()`, or `supervisor.ticks_ms()`. +//| `time.monotonic_ns()` is not available on boards without long integer support. +//| `supervisor.ticks_ms()` uses intervals of a millisecond, but wraps around, and is not +//| CPython-compatible. //| //| :return: the current monotonic time //| :rtype: float""" @@ -216,7 +230,8 @@ STATIC mp_obj_t time_time(void) { MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); //| def monotonic_ns() -> int: -//| """Return the time of the monotonic clock, cannot go backward, in nanoseconds. +//| """Return the time of the monotonic clock, which cannot go backward, in nanoseconds. +//| Not available on boards without long integer support. //| //| :return: the current time //| :rtype: int""" From f0e29457478c1adb0913037c2e4bb6d52981a4f7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 8 Oct 2021 10:40:49 -0400 Subject: [PATCH 2/2] clarify RP2040 IncrementalEncoder sequential pin message --- locale/circuitpython.pot | 7 ++++++- ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f79a4c7285a3..00f72241fcca 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1900,10 +1900,13 @@ msgid "" msgstr "" #: ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c -#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c msgid "Pins must be sequential" msgstr "" +#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c +msgid "Pins must be sequential GPIO pins" +msgstr "" + #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "Pins must share PWM slice" msgstr "" @@ -3943,6 +3946,7 @@ msgstr "" #: ports/espressif/boards/adafruit_funhouse/mpconfigboard.h #: ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/espressif/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h #: ports/espressif/boards/ai_thinker_esp_12k_nodemcu/mpconfigboard.h #: ports/espressif/boards/artisense_rd00/mpconfigboard.h #: ports/espressif/boards/atmegazero_esp32s2/mpconfigboard.h @@ -3961,6 +3965,7 @@ msgstr "" #: ports/espressif/boards/gravitech_cucumber_rs/mpconfigboard.h #: ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h #: ports/espressif/boards/lolin_s2_mini/mpconfigboard.h +#: ports/espressif/boards/microdev_micro_c3/mpconfigboard.h #: ports/espressif/boards/microdev_micro_s2/mpconfigboard.h #: ports/espressif/boards/morpheans_morphesp-240/mpconfigboard.h #: ports/espressif/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h diff --git a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c index 7849130ff79a..00cf54b221b0 100644 --- a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c @@ -68,7 +68,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode pins[1] = MP_OBJ_FROM_PTR(pin_a); self->swapped = false; if (!common_hal_rp2pio_pins_are_sequential(2, pins)) { - mp_raise_RuntimeError(translate("Pins must be sequential")); + mp_raise_RuntimeError(translate("Pins must be sequential GPIO pins")); } }