commit
da7edf80e0
|
@ -100,6 +100,7 @@ msgstr ""
|
|||
msgid "%q failure: %d"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||
#: shared-bindings/digitalio/DigitalInOut.c
|
||||
#: shared-bindings/microcontroller/Pin.c
|
||||
msgid "%q in use"
|
||||
|
@ -913,9 +914,9 @@ msgid "Error: Failure to bind"
|
|||
msgstr ""
|
||||
|
||||
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
|
||||
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
|
||||
#: shared-bindings/coproc/Coproc.c shared-bindings/coproc/__init__.c
|
||||
#: shared-bindings/microcontroller/Pin.c
|
||||
#: shared-bindings/alarm/__init__.c shared-bindings/alarm/coproc/CoprocAlarm.c
|
||||
#: shared-bindings/busio/SPI.c shared-bindings/coproc/Coproc.c
|
||||
#: shared-bindings/coproc/__init__.c shared-bindings/microcontroller/Pin.c
|
||||
#: shared-bindings/neopixel_write/__init__.c
|
||||
msgid "Expected a %q"
|
||||
msgstr ""
|
||||
|
@ -1615,8 +1616,9 @@ msgid ""
|
|||
"%d bpp given"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/alarm/coproc/CoprocAlarm.c
|
||||
#: ports/espressif/common-hal/alarm/touch/TouchAlarm.c
|
||||
msgid "Only one TouchAlarm can be set in deep sleep."
|
||||
msgid "Only one %q can be set in deep sleep."
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/i2ctarget/I2CTarget.c
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -35,6 +35,7 @@
|
|||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/alarm/touch/TouchAlarm.h"
|
||||
#include "shared-bindings/alarm/coproc/CoprocAlarm.h"
|
||||
|
||||
#include "shared-bindings/wifi/__init__.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
@ -62,6 +63,7 @@ void alarm_reset(void) {
|
|||
alarm_pin_pinalarm_reset();
|
||||
alarm_time_timealarm_reset();
|
||||
alarm_touch_touchalarm_reset();
|
||||
alarm_coproc_coprocalarm_reset();
|
||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||
}
|
||||
|
||||
|
@ -76,6 +78,9 @@ STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(void) {
|
|||
if (alarm_touch_touchalarm_woke_this_cycle()) {
|
||||
return ESP_SLEEP_WAKEUP_TOUCHPAD;
|
||||
}
|
||||
if (alarm_coproc_coprocalarm_woke_this_cycle()) {
|
||||
return ESP_SLEEP_WAKEUP_ULP;
|
||||
}
|
||||
// If waking from true deep sleep, modules will have lost their state,
|
||||
// so check the deep wakeup cause manually
|
||||
return esp_sleep_get_wakeup_cause();
|
||||
|
@ -104,6 +109,10 @@ mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
|||
return alarm_touch_touchalarm_create_wakeup_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_ULP: {
|
||||
return alarm_coproc_coprocalarm_create_wakeup_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_UNDEFINED:
|
||||
default:
|
||||
// Not a deep sleep reset.
|
||||
|
@ -117,6 +126,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t
|
|||
alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms);
|
||||
alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms);
|
||||
alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms);
|
||||
alarm_coproc_coprocalarm_set_alarm(deep_sleep, n_alarms, alarms);
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) {
|
||||
|
@ -143,6 +153,10 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
|
|||
wake_alarm = alarm_touch_touchalarm_find_triggered_alarm(n_alarms,alarms);
|
||||
break;
|
||||
}
|
||||
case ESP_SLEEP_WAKEUP_ULP: {
|
||||
wake_alarm = alarm_coproc_coprocalarm_find_triggered_alarm(n_alarms,alarms);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Should not reach this, if all light sleep types are covered correctly
|
||||
break;
|
||||
|
@ -169,6 +183,7 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala
|
|||
void NORETURN common_hal_alarm_enter_deep_sleep(void) {
|
||||
alarm_pin_pinalarm_prepare_for_deep_sleep();
|
||||
alarm_touch_touchalarm_prepare_for_deep_sleep();
|
||||
alarm_coproc_coprocalarm_prepare_for_deep_sleep();
|
||||
|
||||
// We no longer need to remember the pin preservations, since any pin resets are all done.
|
||||
clear_pin_preservations();
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* 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 "shared-bindings/alarm/coproc/CoprocAlarm.h"
|
||||
#include "shared-bindings/coproc/__init__.h"
|
||||
|
||||
#include "esp_sleep.h"
|
||||
|
||||
#if CIRCUITPY_COPROC
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms) {
|
||||
for (size_t i = 0; i < n_alarms; i++) {
|
||||
if (mp_obj_is_type(alarms[i], &alarm_coproc_coprocalarm_type)) {
|
||||
return alarms[i];
|
||||
}
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void) {
|
||||
// Create CoprocAlarm object.
|
||||
alarm_coproc_coprocalarm_obj_t *alarm = m_new_obj(alarm_coproc_coprocalarm_obj_t);
|
||||
alarm->base.type = &alarm_coproc_coprocalarm_type;
|
||||
return alarm;
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms) {
|
||||
bool coproc_alarm_set = false;
|
||||
alarm_coproc_coprocalarm_obj_t *coproc_alarm = MP_OBJ_NULL;
|
||||
|
||||
for (size_t i = 0; i < n_alarms; i++) {
|
||||
if (mp_obj_is_type(alarms[i], &alarm_coproc_coprocalarm_type)) {
|
||||
if (deep_sleep && coproc_alarm_set) {
|
||||
mp_raise_ValueError_varg(translate("Only one %q can be set in deep sleep."), MP_QSTR_CoprocAlarm);
|
||||
}
|
||||
coproc_alarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
coproc_alarm_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!coproc_alarm_set) {
|
||||
return;
|
||||
}
|
||||
|
||||
// load coproc program
|
||||
common_hal_coproc_load(coproc_alarm->coproc);
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void) {
|
||||
// start coproc program
|
||||
common_hal_coproc_run(NULL);
|
||||
|
||||
// enable coproc wakeup
|
||||
esp_sleep_enable_ulp_wakeup();
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
|
||||
}
|
||||
|
||||
bool alarm_coproc_coprocalarm_woke_this_cycle(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_reset(void) {
|
||||
}
|
||||
|
||||
#else // CIRCUITPY_COPROC
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms) {
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void) {
|
||||
}
|
||||
|
||||
bool alarm_coproc_coprocalarm_woke_this_cycle(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void alarm_coproc_coprocalarm_reset(void) {
|
||||
}
|
||||
|
||||
#endif // CIRCUITPY_COPROC
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* 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 MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
||||
#define MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "common-hal/coproc/Coproc.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
coproc_coproc_obj_t *coproc;
|
||||
} alarm_coproc_coprocalarm_obj_t;
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void);
|
||||
|
||||
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void);
|
||||
void alarm_coproc_coprocalarm_reset(void);
|
||||
void alarm_coproc_coprocalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
|
||||
bool alarm_coproc_coprocalarm_woke_this_cycle(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
|
@ -96,7 +96,7 @@ void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alar
|
|||
for (size_t i = 0; i < n_alarms; i++) {
|
||||
if (mp_obj_is_type(alarms[i], &alarm_touch_touchalarm_type)) {
|
||||
if (deep_sleep && touch_alarm_set) {
|
||||
mp_raise_ValueError(translate("Only one TouchAlarm can be set in deep sleep."));
|
||||
mp_raise_ValueError_varg(translate("Only one %q can be set in deep sleep."), MP_QSTR_TouchAlarm);
|
||||
}
|
||||
touch_alarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
touch_channel_mask |= 1 << touch_alarm->pin->number;
|
||||
|
|
|
@ -40,11 +40,6 @@
|
|||
#include "soc/rtc_cntl_reg.h"
|
||||
|
||||
void common_hal_coproc_run(coproc_coproc_obj_t *self) {
|
||||
if (ulp_riscv_load_binary(self->buf, self->buf_len) != ESP_OK) {
|
||||
mp_raise_RuntimeError(translate("Firmware is too big"));
|
||||
}
|
||||
m_free(self->buf);
|
||||
self->buf = (uint8_t *)RTC_SLOW_MEM;
|
||||
ulp_riscv_run();
|
||||
}
|
||||
|
||||
|
@ -64,6 +59,14 @@ void common_hal_coproc_halt(coproc_coproc_obj_t *self) {
|
|||
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_RESET_EN);
|
||||
}
|
||||
|
||||
void common_hal_coproc_load(coproc_coproc_obj_t *self) {
|
||||
if (ulp_riscv_load_binary(self->buf, self->buf_len) != ESP_OK) {
|
||||
mp_raise_RuntimeError(translate("Firmware is too big"));
|
||||
}
|
||||
m_free(self->buf);
|
||||
self->buf = (uint8_t *)RTC_SLOW_MEM;
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_coproc_memory(coproc_coproc_obj_t *self) {
|
||||
return (self->coproc_memory) ? MP_OBJ_FROM_PTR(self->coproc_memory) : mp_const_none;
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -0,0 +1 @@
|
|||
// empty file
|
|
@ -400,6 +400,7 @@ SRC_COMMON_HAL_ALL = \
|
|||
alarm/pin/PinAlarm.c \
|
||||
alarm/time/TimeAlarm.c \
|
||||
alarm/touch/TouchAlarm.c \
|
||||
alarm/coproc/CoprocAlarm.c \
|
||||
analogbufio/BufferedIn.c \
|
||||
analogbufio/__init__.c \
|
||||
analogio/AnalogIn.c \
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/alarm/touch/TouchAlarm.h"
|
||||
#include "shared-bindings/alarm/coproc/CoprocAlarm.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/supervisor/Runtime.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
|
@ -76,7 +77,8 @@ STATIC void validate_objs_are_alarms(size_t n_args, const mp_obj_t *objs) {
|
|||
for (size_t i = 0; i < n_args; i++) {
|
||||
if (mp_obj_is_type(objs[i], &alarm_pin_pinalarm_type) ||
|
||||
mp_obj_is_type(objs[i], &alarm_time_timealarm_type) ||
|
||||
mp_obj_is_type(objs[i], &alarm_touch_touchalarm_type)) {
|
||||
mp_obj_is_type(objs[i], &alarm_touch_touchalarm_type) ||
|
||||
mp_obj_is_type(objs[i], &alarm_coproc_coprocalarm_type)) {
|
||||
continue;
|
||||
}
|
||||
mp_raise_TypeError_varg(translate("Expected an %q"), MP_QSTR_Alarm);
|
||||
|
@ -252,6 +254,18 @@ STATIC const mp_obj_module_t alarm_touch_module = {
|
|||
.globals = (mp_obj_dict_t *)&alarm_touch_globals,
|
||||
};
|
||||
|
||||
STATIC const mp_map_elem_t alarm_coproc_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_coproc) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_CoprocAlarm), MP_OBJ_FROM_PTR(&alarm_coproc_coprocalarm_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(alarm_coproc_globals, alarm_coproc_globals_table);
|
||||
|
||||
STATIC const mp_obj_module_t alarm_coproc_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&alarm_coproc_globals,
|
||||
};
|
||||
|
||||
// The module table is mutable because .wake_alarm is a mutable attribute.
|
||||
STATIC mp_map_elem_t alarm_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },
|
||||
|
@ -266,6 +280,7 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_pin), MP_OBJ_FROM_PTR(&alarm_pin_module) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_time), MP_OBJ_FROM_PTR(&alarm_time_module) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_touch), MP_OBJ_FROM_PTR(&alarm_touch_module) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_coproc), MP_OBJ_FROM_PTR(&alarm_coproc_module) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SleepMemory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sleep_memory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_obj) },
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* 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 "py/runtime.h"
|
||||
|
||||
#if CIRCUITPY_COPROC
|
||||
#include "shared-bindings/util.h"
|
||||
#include "shared-bindings/alarm/coproc/CoprocAlarm.h"
|
||||
#include "shared-bindings/coproc/Coproc.h"
|
||||
|
||||
STATIC coproc_coproc_obj_t *get_coproc_obj(mp_obj_t *self_in) {
|
||||
if (!mp_obj_is_type(*self_in, &coproc_coproc_type)) {
|
||||
mp_raise_TypeError_varg(translate("Expected a %q"), MP_QSTR_Coproc);
|
||||
}
|
||||
coproc_coproc_obj_t *self = MP_OBJ_TO_PTR(*self_in);
|
||||
if (common_hal_coproc_coproc_deinited(self)) {
|
||||
raise_deinited_error();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
//| class CoprocAlarm:
|
||||
//| """Trigger an alarm when another core or co-processor requests wake-up."""
|
||||
//|
|
||||
//| def __init__(self, coproc: coproc.Coproc) -> None:
|
||||
//| """Create an alarm that will be triggered when the co-processor requests wake-up.
|
||||
//|
|
||||
//| The alarm is not active until it is passed to an `alarm`-enabling function, such as
|
||||
//| `alarm.light_sleep_until_alarms()` or `alarm.exit_and_deep_sleep_until_alarms()`.
|
||||
//|
|
||||
//| :param coproc.Coproc coproc: The coproc program to run.
|
||||
//|
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t alarm_coproc_coprocalarm_make_new(const mp_obj_type_t *type,
|
||||
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_coproc };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_coproc, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
#if CIRCUITPY_COPROC
|
||||
// initialize CoprocAlarm object
|
||||
alarm_coproc_coprocalarm_obj_t *self = m_new_obj(alarm_coproc_coprocalarm_obj_t);
|
||||
self->base.type = &alarm_coproc_coprocalarm_type;
|
||||
self->coproc = get_coproc_obj(&args[ARG_coproc].u_obj);
|
||||
// return CoprocAlarm object
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
#else
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
return mp_const_none;
|
||||
#endif
|
||||
}
|
||||
|
||||
const mp_obj_type_t alarm_coproc_coprocalarm_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_CoprocAlarm,
|
||||
.make_new = alarm_coproc_coprocalarm_make_new,
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* 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 MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_COPROC_COPROCALARM_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_COPROC_COPROCALARM_H
|
||||
|
||||
#include "common-hal/alarm/coproc/CoprocAlarm.h"
|
||||
|
||||
extern const mp_obj_type_t alarm_coproc_coprocalarm_type;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_COPROC_COPROCALARM_H
|
|
@ -68,7 +68,9 @@ STATIC coproc_coproc_obj_t *get_coproc_obj(mp_obj_t *self_in) {
|
|||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t coproc_run(mp_obj_t self_in) {
|
||||
common_hal_coproc_run(get_coproc_obj(&self_in));
|
||||
coproc_coproc_obj_t *self = get_coproc_obj(&self_in);
|
||||
common_hal_coproc_load(self);
|
||||
common_hal_coproc_run(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(coproc_run_obj, coproc_run);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
extern void common_hal_coproc_run(coproc_coproc_obj_t *self);
|
||||
extern void common_hal_coproc_halt(coproc_coproc_obj_t *self);
|
||||
extern void common_hal_coproc_load(coproc_coproc_obj_t *self);
|
||||
extern mp_obj_t common_hal_coproc_memory(coproc_coproc_obj_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_COPROC___INIT___H
|
||||
|
|
Loading…
Reference in New Issue