Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
b637d39
Initial commit
gamblor21 Oct 25, 2020
12d770b
Added __probe_for_device
gamblor21 Oct 25, 2020
8a37983
Added doc and translations
gamblor21 Oct 26, 2020
9ec2245
Clean up
gamblor21 Oct 27, 2020
2374b0d
Fixed whitespace issues
gamblor21 Oct 27, 2020
90b9ec6
Initial Sleep Support
microdev1 Sep 18, 2020
3a30887
Update soft reboot message
microdev1 Sep 18, 2020
e310b87
Get io wake working
microdev1 Sep 19, 2020
05a3f20
Add function to get time elapsed during sleep
microdev1 Sep 22, 2020
21ba61a
Add function to disable alarm
microdev1 Sep 22, 2020
e5ff55b
Renamed alarm modules
microdev1 Sep 23, 2020
4d8ffdc
restructure alarm modules
microdev1 Sep 24, 2020
da44972
Fix build error
microdev1 Sep 24, 2020
59df1a1
Add alarm_touch module
microdev1 Sep 24, 2020
e359389
Add description of alarm modules
microdev1 Sep 24, 2020
930cf14
Add check for invalid io, function to disable all alarms
microdev1 Sep 26, 2020
0e444f0
Implement sleep on code.py exit
microdev1 Sep 30, 2020
354536c
Update translation
microdev1 Oct 7, 2020
1196d4b
move to new module
tannewt Oct 14, 2020
85dadf3
More API changes
tannewt Oct 15, 2020
9a4efed
Start tweaking the workflow to sleep
tannewt Oct 28, 2020
e7da852
Fixing review comments
gamblor21 Oct 29, 2020
78477a3
Initial SPI commit
gamblor21 Oct 31, 2020
5ea09fe
Fixed stubs
gamblor21 Oct 31, 2020
76c1153
Fixed stubs
gamblor21 Nov 1, 2020
7dd5380
Fixed stubs again
gamblor21 Nov 1, 2020
8bbbb28
Fixes from testing SPI
gamblor21 Nov 2, 2020
197539b
Moved I2CDevice and SPI to match python library
gamblor21 Nov 3, 2020
4c93db3
Renamed to adafruit_bus_device
gamblor21 Nov 4, 2020
03b110b
Add abort check in I2C lock
gamblor21 Nov 11, 2020
f61c4e6
Removing from smaller builds
gamblor21 Nov 11, 2020
23ed3ef
Removing frozen libs
gamblor21 Nov 11, 2020
bb77f1d
wip: initial code changes, starting from @tannewt's sleepio branch
dhalbert Nov 16, 2020
ffff02c
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 16, 2020
682054a
WIP: redo API; not compiled yet
dhalbert Nov 19, 2020
5bb3c32
merge from main
dhalbert Nov 19, 2020
649c930
wip
dhalbert Nov 19, 2020
cd436ba
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 19, 2020
39e1f52
wip; not compiling yet
dhalbert Nov 19, 2020
e4c6699
compiles
dhalbert Nov 21, 2020
75559f3
wip: ResetReason to microcontroller.cpu
dhalbert Nov 22, 2020
a0f1ec3
wip
dhalbert Nov 23, 2020
25591a3
Merge branch 'esp32s2-common-hal-mcu-delay-us' into sleep
dhalbert Nov 23, 2020
3abee9b
compiles; maybe ready to test, or almost
dhalbert Nov 23, 2020
7a45afc
working, but need to avoid deep sleeping too fast before USB ready
dhalbert Nov 24, 2020
f868cc5
some API renaming and bug fixes; fix docs
dhalbert Nov 25, 2020
9dbea36
changed alarm.time API
dhalbert Nov 25, 2020
ef0830b
merge from upstream + wip
dhalbert Nov 25, 2020
104a089
deep sleep working; deep sleep delay when connected
dhalbert Nov 27, 2020
e308a9e
working! PinAlarm not implemented yet.
dhalbert Nov 27, 2020
596e0e4
merge from upstream
dhalbert Nov 27, 2020
f96475c
update Requests; rolled back by accident
dhalbert Nov 27, 2020
65e2fe4
fix stub problems; touch up doc
dhalbert Nov 28, 2020
2830cc9
make translate
dhalbert Nov 28, 2020
28d9e91
Disable complex arithmetic on SAMD21 builds to make space
dhalbert Nov 28, 2020
4ac4faa
Use nina-fw root certs
tannewt Dec 1, 2020
9276244
Two minor socket changes
tannewt Dec 1, 2020
9a9e972
Ignore certificates readme in doc build
tannewt Dec 1, 2020
a95285a
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
f6cba4c
Translated using Weblate (Polish)
tawez Dec 1, 2020
44e0d98
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
2b9ca4d
Translated using Weblate (Polish)
tawez Dec 1, 2020
2373857
Merge branch 'main' into bus_device
gamblor21 Dec 1, 2020
d3bbb99
Fixing stubs
gamblor21 Dec 1, 2020
8b7c23c
address review comments
dhalbert Dec 2, 2020
fe1c2fa
Removed bus device from simmel build
gamblor21 Dec 2, 2020
72fa7d8
fix doc errors
dhalbert Dec 2, 2020
73e22f9
Block all tasks (not interrupts) during flash erase
tannewt Dec 2, 2020
cb863e4
Added to partial builds where frozen removed
gamblor21 Dec 2, 2020
1c00deb
Translated using Weblate (Polish)
tawez Dec 1, 2020
9e6b2b1
Translated using Weblate (Czech)
vkuthan Dec 1, 2020
d7ba641
Merge pull request #3767 from dhalbert/sleep
tannewt Dec 2, 2020
8f6baa2
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
7655102
Update translation files
weblate Dec 2, 2020
31acfed
Merge pull request #3780 from tannewt/block_while_erasing
dhalbert Dec 2, 2020
51fd678
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
9b3186b
Merge pull request #3776 from tannewt/backup_socket_timeout
dhalbert Dec 2, 2020
c7749a5
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
348392f
Merge pull request #3775 from tannewt/nina_certs
dhalbert Dec 2, 2020
a483cd1
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
1130b80
Merge pull request #3612 from gamblor21/bus_device
tannewt Dec 2, 2020
079bf7a
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
03d0ec8
Update translation files
weblate Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: main.c
msgid ""
"\n"
"\n"
"------ soft reboot ------\n"
msgstr ""

#: main.c
msgid ""
"\n"
Expand Down Expand Up @@ -982,6 +989,10 @@ msgstr ""
msgid "I2SOut not available"
msgstr ""

#: ports/esp32s2/common-hal/alarm_io/__init__.c
msgid "IOs 0, 2 & 4 do not support internal pullup in sleep"
msgstr ""

#: shared-bindings/aesio/aes.c
#, c-format
msgid "IV must be %d bytes long"
Expand Down Expand Up @@ -2793,6 +2804,10 @@ msgstr ""
msgid "invalid syntax for number"
msgstr ""

#: ports/esp32s2/common-hal/alarm_io/__init__.c
msgid "io must be rtc io"
msgstr ""

#: py/objtype.c
msgid "issubclass() arg 1 must be a class"
msgstr ""
Expand Down Expand Up @@ -3313,7 +3328,7 @@ msgstr ""
msgid "size is defined for ndarrays only"
msgstr ""

#: shared-bindings/time/__init__.c
#: shared-bindings/alarm_time/__init__.c shared-bindings/time/__init__.c
msgid "sleep length must be non-negative"
msgstr ""

Expand All @@ -3329,10 +3344,6 @@ msgstr ""
msgid "small int overflow"
msgstr ""

#: main.c
msgid "soft reboot\n"
msgstr ""

#: extmod/ulab/code/numerical/numerical.c
msgid "sort argument must be an ndarray"
msgstr ""
Expand Down Expand Up @@ -3417,6 +3428,10 @@ msgstr ""
msgid "threshold must be in the range 0-65536"
msgstr ""

#: ports/esp32s2/common-hal/alarm_time/__init__.c
msgid "time out of range"
msgstr ""

#: shared-bindings/time/__init__.c
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
Expand Down Expand Up @@ -3462,6 +3477,10 @@ msgstr ""
msgid "trapz is defined for 1D arrays of equal length"
msgstr ""

#: ports/esp32s2/common-hal/alarm_io/__init__.c
msgid "trigger level must be 0 or 1"
msgstr ""

#: extmod/ulab/code/linalg/linalg.c
msgid "tuple index out of range"
msgstr ""
Expand Down Expand Up @@ -3604,6 +3623,10 @@ msgstr ""
msgid "vectors must have same lengths"
msgstr ""

#: ports/esp32s2/common-hal/alarm_io/__init__.c
msgid "wakeup conflict"
msgstr ""

#: shared-bindings/watchdog/WatchDogTimer.c
msgid "watchdog timeout must be greater than 0"
msgstr ""
Expand Down
41 changes: 37 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#include "supervisor/shared/status_leds.h"
#include "supervisor/shared/stack.h"
#include "supervisor/serial.h"
#include "supervisor/usb.h"

#include "shared-bindings/microcontroller/__init__.h"

#include "boards/board.h"

Expand Down Expand Up @@ -85,6 +88,10 @@
#include "common-hal/canio/CAN.h"
#endif

#if CIRCUITPY_SLEEP
#include "shared-bindings/sleep/__init__.h"
#endif

void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
Expand Down Expand Up @@ -312,6 +319,14 @@ bool run_code_py(safe_mode_t safe_mode) {
bool refreshed_epaper_display = false;
#endif
rgb_status_animation_t animation;
bool ok = result->return_code != PYEXEC_EXCEPTION;
#if CIRCUITPY_SLEEP
// If USB isn't enumerated then deep sleep.
if (ok && !supervisor_workflow_active() && supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024) {
common_hal_sleep_deep_sleep();
}
#endif
// Show the animation every N seconds.
prep_rgb_status_animation(&result, found_main, safe_mode, &animation);
while (true) {
RUN_BACKGROUND_TASKS;
Expand Down Expand Up @@ -344,8 +359,24 @@ bool run_code_py(safe_mode_t safe_mode) {
refreshed_epaper_display = maybe_refresh_epaperdisplay();
}
#endif

tick_rgb_status_animation(&animation);
bool animation_done = tick_rgb_status_animation(&animation);
if (animation_done && supervisor_workflow_active()) {
#if CIRCUITPY_SLEEP
int64_t remaining_enumeration_wait = CIRCUITPY_USB_ENUMERATION_DELAY * 1024 - supervisor_ticks_ms64();
// If USB isn't enumerated then deep sleep after our waiting period.
if (ok && remaining_enumeration_wait < 0) {
common_hal_sleep_deep_sleep();
return; // Doesn't actually get here.
}
#endif
// Wake up every so often to flash the error code.
if (!ok) {
port_interrupt_after_ticks(CIRCUITPY_FLASH_ERROR_PERIOD * 1024);
} else {
port_interrupt_after_ticks(remaining_enumeration_wait);
}
port_sleep_until_interrupt();
}
}
}

Expand Down Expand Up @@ -392,7 +423,9 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
if (!skip_boot_output) {
// Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
// in case power is momentary or will fail shortly due to, say a low, battery.
mp_hal_delay_ms(1500);
if (common_hal_sleep_get_reset_reason() == RESET_REASON_POWER_VALID) {
mp_hal_delay_ms(1500);
}

// USB isn't up, so we can write the file.
filesystem_set_internal_writable_by_usb(false);
Expand Down Expand Up @@ -511,7 +544,7 @@ int __attribute__((used)) main(void) {
}
if (exit_code == PYEXEC_FORCED_EXIT) {
if (!first_run) {
serial_write_compressed(translate("soft reboot\n"));
serial_write_compressed(translate("\n\n------ soft reboot ------\n"));
}
first_run = false;
skip_repl = run_code_py(safe_mode);
Expand Down
4 changes: 4 additions & 0 deletions ports/atmel-samd/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void common_hal_mcu_reset(void) {
reset();
}

void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

// The singleton microcontroller.Processor object, bound to microcontroller.cpu
// It currently only has properties, and no state.
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
Expand Down
4 changes: 4 additions & 0 deletions ports/cxd56/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ void common_hal_mcu_reset(void) {
boardctl(BOARDIOC_RESET, 0);
}

void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_UART2_RXD), MP_ROM_PTR(&pin_UART2_RXD) },
{ MP_ROM_QSTR(MP_QSTR_UART2_TXD), MP_ROM_PTR(&pin_UART2_TXD) },
Expand Down
60 changes: 60 additions & 0 deletions ports/esp32s2/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* 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/__init__.h"
#include "shared-bindings/alarm_io/__init__.h"
#include "shared-bindings/alarm_time/__init__.h"

#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: ;
//Wake up from timer.
alarm_time_obj_t *timer = m_new_obj(alarm_time_obj_t);
timer->base.type = &alarm_time_type;
return timer;
case ESP_SLEEP_WAKEUP_EXT0: ;
//Wake up from GPIO
alarm_io_obj_t *ext0 = m_new_obj(alarm_io_obj_t);
ext0->base.type = &alarm_io_type;
return ext0;
case ESP_SLEEP_WAKEUP_TOUCHPAD:
//TODO: implement TouchIO
//Wake up from touch on pad, esp_sleep_get_touchpad_wakeup_status()
break;
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
//Not a deep sleep reset
break;
}
return mp_const_none;
}
35 changes: 35 additions & 0 deletions ports/esp32s2/common-hal/alarm_io/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "shared-bindings/alarm_io/__init__.h"

#include "esp_sleep.h"
#include "driver/rtc_io.h"

mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) {
if (!rtc_gpio_is_valid_gpio(self_in->gpio)) {
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"));
case ESP_ERR_INVALID_STATE:
mp_raise_RuntimeError(translate("wakeup conflict"));
default:
break;
}

if (self_in->pull) { (self_in->level) ? rtc_gpio_pulldown_en(self_in->gpio) : rtc_gpio_pullup_en(self_in->gpio); }

return self_in;
}

void common_hal_alarm_io_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1);
}
13 changes: 13 additions & 0 deletions ports/esp32s2/common-hal/alarm_time/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "esp_sleep.h"

#include "shared-bindings/alarm_time/__init__.h"

void common_hal_alarm_time_duration (uint32_t ms) {
if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("time out of range"));
}
}

void common_hal_alarm_time_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}
8 changes: 7 additions & 1 deletion ports/esp32s2/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* THE SOFTWARE.
*/

#include "py/mphal.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "py/runtime.h"

#include "common-hal/microcontroller/Pin.h"
Expand All @@ -41,6 +41,8 @@

#include "freertos/FreeRTOS.h"

#include "esp_sleep.h"

void common_hal_mcu_delay_us(uint32_t delay) {

}
Expand Down Expand Up @@ -77,6 +79,10 @@ void common_hal_mcu_reset(void) {
while(1);
}

void common_hal_mcu_deep_sleep(void) {
esp_deep_sleep_start();
}

// The singleton microcontroller.Processor object, bound to microcontroller.cpu
// It currently only has properties, and no state.
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
Expand Down
5 changes: 5 additions & 0 deletions ports/esp32s2/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ LONGINT_IMPL = MPZ

# These modules are implemented in ports/<port>/common-hal:
CIRCUITPY_FULL_BUILD = 1
CIRCUITPY_ALARM = 1
CIRCUITPY_ALARM_IO = 1
CIRCUITPY_ALARM_TIME = 1
CIRCUITPY_ALARM_TOUCH = 1
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1
Expand All @@ -22,6 +26,7 @@ CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 0

# We don't have enough endpoints to include MIDI.
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_WIFI = 1
Expand Down
4 changes: 2 additions & 2 deletions ports/esp32s2/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogOut.h"
#include "common-hal/busio/I2C.h"
#include "common-hal/busio/SPI.h"
#include "common-hal/busio/UART.h"
#include "common-hal/pulseio/PulseIn.h"
#include "common-hal/pwmio/PWMOut.h"
#include "common-hal/pulseio/PulseIn.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/wifi/__init__.h"
#include "supervisor/memory.h"
#include "supervisor/shared/tick.h"
Expand Down
4 changes: 4 additions & 0 deletions ports/litex/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ void common_hal_mcu_reset(void) {
while(1);
}

void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

// The singleton microcontroller.Processor object, bound to microcontroller.cpu
// It currently only has properties, and no state.
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
Expand Down
4 changes: 4 additions & 0 deletions ports/mimxrt10xx/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ void common_hal_mcu_reset(void) {
NVIC_SystemReset();
}

void common_hal_mcu_deep_sleep(void) {
//deep sleep call here
}

// The singleton microcontroller.Processor object, bound to microcontroller.cpu
// It currently only has properties, and no state.
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
Expand Down
Loading