diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-12-02 12:51:43 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-02 12:51:43 -0800 |
| commit | d7ba641ff646b48e5ad38ff72a2dcfe17bb54624 (patch) | |
| tree | a0c4f9fb561b2caa38636645ca27f0ddad59f087 /py | |
| parent | 5b3c930e384ef6440f0f7b5167bb54ea68a8be76 (diff) | |
| parent | 72fa7d88b881d2ed9978c0bd65ce5f8d6eb51703 (diff) | |
Merge pull request #3767 from dhalbert/sleep
Initial alarm and sleep PR: time alarms with light and deep sleep; PinAlarms not yet implemented
Diffstat (limited to 'py')
| -rw-r--r-- | py/circuitpy_defns.mk | 16 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.h | 9 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.mk | 6 | ||||
| -rw-r--r-- | py/enum.h | 4 | ||||
| -rw-r--r-- | py/genlast.py | 4 | ||||
| -rw-r--r-- | py/obj.h | 5 | ||||
| -rw-r--r-- | py/objexcept.c | 3 | ||||
| -rw-r--r-- | py/objfloat.c | 7 | ||||
| -rw-r--r-- | py/reload.c | 22 | ||||
| -rw-r--r-- | py/reload.h | 22 |
10 files changed, 84 insertions, 14 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index ccdf973e9..a3e18753b 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -99,6 +99,9 @@ endif ifeq ($(CIRCUITPY_AESIO),1) SRC_PATTERNS += aesio/% endif +ifeq ($(CIRCUITPY_ALARM),1) +SRC_PATTERNS += alarm/% +endif ifeq ($(CIRCUITPY_ANALOGIO),1) SRC_PATTERNS += analogio/% endif @@ -298,6 +301,9 @@ SRC_COMMON_HAL_ALL = \ _bleio/__init__.c \ _pew/PewPew.c \ _pew/__init__.c \ + alarm/__init__.c \ + alarm/pin/PinAlarm.c \ + alarm/time/TimeAlarm.c \ analogio/AnalogIn.c \ analogio/AnalogOut.c \ analogio/__init__.c \ @@ -387,15 +393,17 @@ $(filter $(SRC_PATTERNS), \ _bleio/Address.c \ _bleio/Attribute.c \ _bleio/ScanEntry.c \ - canio/Match.c \ _eve/__init__.c \ camera/ImageFormat.c \ + canio/Match.c \ digitalio/Direction.c \ digitalio/DriveMode.c \ digitalio/Pull.c \ fontio/Glyph.c \ math/__init__.c \ + microcontroller/ResetReason.c \ microcontroller/RunMode.c \ + supervisor/RunReason.c \ ) SRC_BINDINGS_ENUMS += \ @@ -406,9 +414,6 @@ SRC_SHARED_MODULE_ALL = \ _bleio/Attribute.c \ _bleio/ScanEntry.c \ _bleio/ScanResults.c \ - canio/Match.c \ - canio/Message.c \ - canio/RemoteTransmissionRequest.c \ _eve/__init__.c \ _pixelbuf/PixelBuf.c \ _pixelbuf/__init__.c \ @@ -433,6 +438,9 @@ SRC_SHARED_MODULE_ALL = \ bitbangio/__init__.c \ board/__init__.c \ busio/OneWire.c \ + canio/Match.c \ + canio/Message.c \ + canio/RemoteTransmissionRequest.c \ displayio/Bitmap.c \ displayio/ColorConverter.c \ displayio/Display.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index bffab4f30..18af71719 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -245,6 +245,13 @@ extern const struct _mp_obj_module_t aesio_module; #define AESIO_MODULE #endif +#if CIRCUITPY_ALARM +extern const struct _mp_obj_module_t alarm_module; +#define ALARM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&alarm_module }, +#else +#define ALARM_MODULE +#endif + #if CIRCUITPY_ANALOGIO #define ANALOGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, extern const struct _mp_obj_module_t analogio_module; @@ -609,7 +616,6 @@ extern const struct _mp_obj_module_t sdioio_module; #define SDIOIO_MODULE #endif - #if CIRCUITPY_SHARPDISPLAY extern const struct _mp_obj_module_t sharpdisplay_module; #define SHARPDISPLAY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sharpdisplay),(mp_obj_t)&sharpdisplay_module }, @@ -774,6 +780,7 @@ extern const struct _mp_obj_module_t wifi_module; // Some are omitted because they're in MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS above. #define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \ AESIO_MODULE \ + ALARM_MODULE \ ANALOGIO_MODULE \ AUDIOBUSIO_MODULE \ AUDIOCORE_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 08e773718..a84dff539 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -39,6 +39,12 @@ CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT) CIRCUITPY_AESIO ?= 0 CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO) +# TODO: CIRCUITPY_ALARM will gradually be added to +# as many ports as possible +# so make this 1 or CIRCUITPY_FULL_BUILD eventually +CIRCUITPY_ALARM ?= 0 +CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM) + CIRCUITPY_ANALOGIO ?= 1 CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO) @@ -35,12 +35,12 @@ typedef struct { } cp_enum_obj_t; #define MAKE_ENUM_VALUE(type, prefix, name, value) \ - STATIC const cp_enum_obj_t prefix ## _ ## name ## _obj = { \ + const cp_enum_obj_t prefix ## _ ## name ## _obj = { \ { &type }, value, MP_QSTR_ ## name, \ } #define MAKE_ENUM_MAP(name) \ - STATIC const mp_rom_map_elem_t name ## _locals_table[] = + const mp_rom_map_elem_t name ## _locals_table[] = #define MAKE_ENUM_MAP_ENTRY(prefix, name) \ { MP_ROM_QSTR(MP_QSTR_ ## name), MP_ROM_PTR(&prefix ## _ ## name ## _obj) } diff --git a/py/genlast.py b/py/genlast.py index 1df2a2482..5b195d23e 100644 --- a/py/genlast.py +++ b/py/genlast.py @@ -47,7 +47,9 @@ def preprocess(command, output_dir, fn): print(e, file=sys.stderr) def maybe_preprocess(command, output_dir, fn): - if subprocess.call(["grep", "-lqE", "(MP_QSTR|translate)", fn]) == 0: + # Preprocess the source file if it contains "MP_QSTR", "translate", + # or if it uses enum.h (which generates "MP_QSTR" strings. + if subprocess.call(["grep", "-lqE", r"(MP_QSTR|translate|enum\.h)", fn]) == 0: preprocess(command, output_dir, fn) if __name__ == '__main__': @@ -640,6 +640,10 @@ extern const mp_obj_type_t mp_type_UnicodeError; extern const mp_obj_type_t mp_type_ValueError; extern const mp_obj_type_t mp_type_ViperTypeError; extern const mp_obj_type_t mp_type_ZeroDivisionError; +#if CIRCUITPY_ALARM +extern const mp_obj_type_t mp_type_DeepSleepRequest; +#endif + // Constant objects, globally accessible // The macros are for convenience only @@ -679,6 +683,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/objexcept.c b/py/objexcept.c index 01ba6da9c..afefee2ca 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -319,6 +319,9 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(UnicodeError, ValueError) //TODO: Implement more UnicodeError subclasses which take arguments #endif +#if CIRCUITPY_ALARM + MP_DEFINE_EXCEPTION(DeepSleepRequest, BaseException) +#endif MP_DEFINE_EXCEPTION(MpyError, ValueError) /* MP_DEFINE_EXCEPTION(Warning, Exception) 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 diff --git a/py/reload.c b/py/reload.c index 95305f2c9..f9f8a590a 100644 --- a/py/reload.c +++ b/py/reload.c @@ -1,6 +1,22 @@ -// -// Created by Roy Hooper on 2018-05-14. -// + /* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 by Roy Hooper + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #include "reload.h" #include "py/mpstate.h" diff --git a/py/reload.h b/py/reload.h index 72e84e5ca..3e8928a32 100644 --- a/py/reload.h +++ b/py/reload.h @@ -1,6 +1,22 @@ -// -// Created by Roy Hooper on 2018-05-14. -// + /* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 by Roy Hooper + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef CIRCUITPYTHON_RELOAD_H #define CIRCUITPYTHON_RELOAD_H |
