summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-11-25 15:07:57 -0500
committerDan Halbert <halbert@halwitz.org>2020-11-25 15:09:27 -0500
commit9dbea36eac9a78cf324bba8d32a5cb2c9940d411 (patch)
tree7d54888455af9db4599a9928b709859296924a01 /py
parentf868cc5dd02319957500180541281f41ec0d0573 (diff)
changed alarm.time API
Diffstat (limited to 'py')
-rw-r--r--py/circuitpy_defns.mk2
-rw-r--r--py/obj.h1
-rw-r--r--py/objfloat.c7
3 files changed, 9 insertions, 1 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 27466282a..14b658df4 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -303,7 +303,7 @@ SRC_COMMON_HAL_ALL = \
_pew/__init__.c \
alarm/__init__.c \
alarm/pin/PinAlarm.c \
- alarm/time/DurationAlarm.c \
+ alarm/time/MonotonicTimeAlarm.c \
analogio/AnalogIn.c \
analogio/AnalogOut.c \
analogio/__init__.c \
diff --git a/py/obj.h b/py/obj.h
index 805b26e48..e055c9750 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -679,6 +679,7 @@ mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
#if MICROPY_PY_BUILTINS_FLOAT
mp_obj_t mp_obj_new_int_from_float(mp_float_t val);
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
+extern mp_float_t uint64_to_float(uint64_t ui64);
#endif
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type);
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg);
diff --git a/py/objfloat.c b/py/objfloat.c
index 59f1eb2f6..80f10e816 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -333,6 +333,13 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
return mp_obj_new_float(lhs_val);
}
+// Convert a uint64_t to a 32-bit float without invoking the double-precision math routines,
+// which are large.
+mp_float_t uint64_to_float(uint64_t ui64) {
+ // 4294967296 = 2^32
+ return (mp_float_t) ((uint32_t) (ui64 >> 32) * 4294967296.0f + (uint32_t) (ui64 & 0xffffffff));
+}
+
#pragma GCC diagnostic pop
#endif // MICROPY_PY_BUILTINS_FLOAT