Add check for invalid io, function to disable all alarms

This commit is contained in:
microDev 2020-09-26 11:15:50 +05:30 committed by Scott Shawcroft
parent e35938971a
commit 930cf14dce
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
14 changed files with 32 additions and 11 deletions

View File

@ -84,7 +84,7 @@ void common_hal_mcu_reset(void) {
reset();
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -81,7 +81,7 @@ void common_hal_mcu_reset(void) {
boardctl(BOARDIOC_RESET, 0);
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -31,6 +31,10 @@
#include "esp_sleep.h"
void common_hal_alarm_disable_all(void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
}
mp_obj_t common_hal_alarm_get_wake_alarm(void) {
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER: ;

View File

@ -8,6 +8,14 @@ mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) {
mp_raise_ValueError(translate("io must be rtc io"));
}
if (self_in->pull && !self_in->level) {
for (uint8_t i = 0; i<=4; i+=2) {
if (self_in->gpio == i) {
mp_raise_ValueError(translate("IOs 0, 2 & 4 do not support internal pullup in sleep"));
}
}
}
switch(esp_sleep_enable_ext0_wakeup(self_in->gpio, self_in->level)) {
case ESP_ERR_INVALID_ARG:
mp_raise_ValueError(translate("trigger level must be 0 or 1"));

View File

@ -79,7 +79,7 @@ void common_hal_mcu_reset(void) {
while(1);
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
esp_deep_sleep_start();
}

View File

@ -89,7 +89,7 @@ void common_hal_mcu_reset(void) {
while(1);
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -86,7 +86,7 @@ void common_hal_mcu_reset(void) {
NVIC_SystemReset();
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -95,7 +95,7 @@ void common_hal_mcu_reset(void) {
reset_cpu();
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -81,7 +81,7 @@ void common_hal_mcu_reset(void) {
NVIC_SystemReset();
}
void common_hal_mcu_sleep(void) {
void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

View File

@ -108,7 +108,7 @@ endif
ifeq ($(CIRCUITPY_ALARM_TIME),1)
SRC_PATTERNS += alarm_time/%
endif
ifeq ($(CIRCUITPY_ALARM_TIME),1)
ifeq ($(CIRCUITPY_ALARM_TOUCH),1)
SRC_PATTERNS += alarm_touch/%
endif
ifeq ($(CIRCUITPY_ANALOGIO),1)

View File

@ -4,6 +4,12 @@
//|
//| The `alarm` module implements deep sleep."""
STATIC mp_obj_t alarm_disable_all(void) {
common_hal_alarm_disable_all();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_disable_all_obj, alarm_disable_all);
STATIC mp_obj_t alarm_get_wake_alarm(void) {
return common_hal_alarm_get_wake_alarm();
}
@ -11,7 +17,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_get_wake_alarm_obj, alarm_get_wake_alarm)
STATIC const mp_rom_map_elem_t alarm_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },
{ MP_ROM_QSTR(MP_QSTR_getWakeAlarm), MP_ROM_PTR(&alarm_get_wake_alarm_obj) },
{ MP_ROM_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_disable_all_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_wake_alarm), MP_ROM_PTR(&alarm_get_wake_alarm_obj) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_module_globals, alarm_module_globals_table);

View File

@ -3,6 +3,7 @@
#include "py/obj.h"
extern void common_hal_alarm_disable_all(void);
extern mp_obj_t common_hal_alarm_get_wake_alarm(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H

View File

@ -136,7 +136,7 @@ STATIC mp_obj_t mcu_reset(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset);
STATIC mp_obj_t mcu_sleep(void) {
common_hal_mcu_sleep();
common_hal_mcu_deep_sleep();
// We won't actually get here because mcu is going into sleep.
return mp_const_none;
}
@ -177,6 +177,7 @@ STATIC const mp_rom_map_elem_t mcu_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_enable_interrupts), MP_ROM_PTR(&mcu_enable_interrupts_obj) },
{ MP_ROM_QSTR(MP_QSTR_on_next_reset), MP_ROM_PTR(&mcu_on_next_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mcu_reset_obj) },
//ToDo: Remove MP_QSTR_sleep when sleep on code.py exit implemented.
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mcu_sleep_obj) },
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
{ MP_ROM_QSTR(MP_QSTR_nvm), MP_ROM_PTR(&common_hal_mcu_nvm_obj) },

View File

@ -43,7 +43,7 @@ extern void common_hal_mcu_enable_interrupts(void);
extern void common_hal_mcu_on_next_reset(mcu_runmode_t runmode);
extern void common_hal_mcu_reset(void);
extern void common_hal_mcu_sleep(void);
extern void common_hal_mcu_deep_sleep(void);
extern const mp_obj_dict_t mcu_pin_globals;