Skip to content

Commit 2b73bb0

Browse files
committed
Support for Pico W
Delete rp2sleep dir and merge code into rp2 Rebase from upstream
1 parent 31a69c2 commit 2b73bb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+61
-6421
lines changed

ports/rp2/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ else()
1414
set(PICO_SDK_PATH ../../lib/pico-sdk)
1515
endif()
1616

17+
if (PICO_EXTRAS_PATH_OVERRIDE)
18+
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH_OVERRIDE})
19+
else()
20+
set(PICO_EXTRAS_PATH ../../lib/pico-extras)
21+
endif()
22+
1723
# Use the local tinyusb instead of the one in pico-sdk
1824
set(PICO_TINYUSB_PATH ${MICROPY_DIR}/lib/tinyusb)
1925
# Use the local lwip instead of the one in pico-sdk
@@ -62,6 +68,7 @@ string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/tinyusb)
6268
include(${MICROPY_DIR}/py/py.cmake)
6369
include(${MICROPY_DIR}/extmod/extmod.cmake)
6470
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
71+
include(pico_extras_import.cmake)
6572

6673
# Define the top-level project
6774
project(${MICROPY_TARGET})
@@ -116,6 +123,7 @@ set(MICROPY_SOURCE_PORT
116123
machine_uart.c
117124
machine_wdt.c
118125
main.c
126+
modpicosleep.c
119127
modmachine.c
120128
modrp2.c
121129
modutime.c
@@ -145,6 +153,7 @@ set(MICROPY_SOURCE_QSTR
145153
${PROJECT_SOURCE_DIR}/machine_timer.c
146154
${PROJECT_SOURCE_DIR}/machine_uart.c
147155
${PROJECT_SOURCE_DIR}/machine_wdt.c
156+
${PROJECT_SOURCE_DIR}/modpicosleep.c
148157
${PROJECT_SOURCE_DIR}/modmachine.c
149158
${PROJECT_SOURCE_DIR}/modrp2.c
150159
${PROJECT_SOURCE_DIR}/moduos.c
@@ -168,6 +177,8 @@ set(PICO_SDK_COMPONENTS
168177
hardware_pwm
169178
hardware_regs
170179
hardware_rtc
180+
hardware_rosc
181+
hardware_sleep
171182
hardware_spi
172183
hardware_structs
173184
hardware_sync
@@ -180,6 +191,7 @@ set(PICO_SDK_COMPONENTS
180191
pico_bootrom
181192
pico_multicore
182193
pico_platform
194+
pico_runtime
183195
pico_stdio
184196
pico_stdlib
185197
pico_sync

ports/rp2/boards/PICO/mpconfigboard.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
// Board and hardware specific configuration
2-
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
2+
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico (sleep)"
33
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
4-
5-
// Enable USB Mass Storage with FatFS filesystem.
6-
// #define MICROPY_HW_USB_MSC (1)

ports/rp2/boards/PICO_W/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Board and hardware specific configuration
2-
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W"
2+
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W (sleep)"
33

44
// todo: We need something to check our binary size
55
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)

ports/rp2sleep/modpicosleep.c renamed to ports/rp2/modpicosleep.c

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,82 @@
1111
#include "hardware/rosc.h"
1212
#include "hardware/structs/scb.h"
1313

14-
15-
static void sleep_callback(void) {
14+
static void sleep_callback(void)
15+
{
1616
return;
1717
}
1818

19-
static void rtc_sleep_seconds(uint32_t seconds_to_sleep) {
19+
static void rtc_sleep_seconds(uint32_t seconds_to_sleep)
20+
{
2021

21-
//Hangs if we attempt to sleep for 1 second....
22-
//Guard against this and perform a normal sleep
23-
if(seconds_to_sleep == 1){
22+
// Hangs if we attempt to sleep for 1 second....
23+
// Guard against this and perform a normal sleep
24+
if (seconds_to_sleep == 1)
25+
{
2426
sleep_ms(1000);
2527
return;
2628
}
2729

28-
int y=2020, m=6, d=5, hour=15, mins=45, secs=0;
29-
struct tm t = { .tm_year=y-1900,
30-
.tm_mon=m-1,
31-
.tm_mday=d,
32-
.tm_hour=hour,
33-
.tm_min=mins,
34-
.tm_sec=secs
35-
};
30+
int y = 2020, m = 6, d = 5, hour = 15, mins = 45, secs = 0;
31+
struct tm t = {.tm_year = y - 1900,
32+
.tm_mon = m - 1,
33+
.tm_mday = d,
34+
.tm_hour = hour,
35+
.tm_min = mins,
36+
.tm_sec = secs};
3637

3738
t.tm_sec += seconds_to_sleep;
3839
mktime(&t);
3940

4041
datetime_t t_alarm = {
41-
.year = t.tm_year+1900,
42-
.month = t.tm_mon+1,
43-
.day = t.tm_mday,
44-
.dotw = t.tm_wday, // 0 is Sunday, so 5 is Friday
45-
.hour = t.tm_hour,
46-
.min = t.tm_min,
47-
.sec = t.tm_sec
48-
};
42+
.year = t.tm_year + 1900,
43+
.month = t.tm_mon + 1,
44+
.day = t.tm_mday,
45+
.dotw = t.tm_wday, // 0 is Sunday, so 5 is Friday
46+
.hour = t.tm_hour,
47+
.min = t.tm_min,
48+
.sec = t.tm_sec};
4949

5050
sleep_goto_sleep_until(&t_alarm, &sleep_callback);
5151
}
5252

53-
void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig){
53+
void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig)
54+
{
5455

55-
//Re-enable ring Oscillator control
56+
// Re-enable ring Oscillator control
5657
rosc_write(&rosc_hw->ctrl, ROSC_CTRL_ENABLE_BITS);
5758

58-
//reset procs back to default
59+
// reset procs back to default
5960
scb_hw->scr = scb_orig;
6061
clocks_hw->sleep_en0 = clock0_orig;
6162
clocks_hw->sleep_en1 = clock1_orig;
6263

63-
//reset clocks
64+
// reset clocks
6465
clocks_init();
6566
stdio_init_all();
6667

6768
return;
6869
}
6970

70-
STATIC mp_obj_t picosleep_seconds(mp_obj_t seconds_obj) {
71+
STATIC mp_obj_t picosleep_seconds(mp_obj_t seconds_obj)
72+
{
7173
mp_int_t seconds = mp_obj_get_int(seconds_obj);
7274
stdio_init_all();
73-
//save values for later
75+
// save values for later
7476
uint scb_orig = scb_hw->scr;
7577
uint clock0_orig = clocks_hw->sleep_en0;
7678
uint clock1_orig = clocks_hw->sleep_en1;
7779

78-
79-
//crudely reset the clock each time
80-
//to the value below
80+
// crudely reset the clock each time
81+
// to the value below
8182
datetime_t t = {
82-
.year = 2020,
83-
.month = 06,
84-
.day = 05,
85-
.dotw = 5, // 0 is Sunday, so 5 is Friday
86-
.hour = 15,
87-
.min = 45,
88-
.sec = 00
89-
};
83+
.year = 2020,
84+
.month = 06,
85+
.day = 05,
86+
.dotw = 5, // 0 is Sunday, so 5 is Friday
87+
.hour = 15,
88+
.min = 45,
89+
.sec = 00};
9090

9191
// Start the Real time clock
9292
rtc_init();
@@ -100,12 +100,14 @@ STATIC mp_obj_t picosleep_seconds(mp_obj_t seconds_obj) {
100100
MP_DEFINE_CONST_FUN_OBJ_1(picosleep_seconds_obj, picosleep_seconds);
101101

102102
STATIC const mp_rom_map_elem_t picosleep_module_globals_table[] = {
103-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picosleep) },
104-
{ MP_ROM_QSTR(MP_QSTR_seconds), MP_ROM_PTR(&picosleep_seconds_obj) },
103+
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picosleep)},
104+
{MP_ROM_QSTR(MP_QSTR_seconds), MP_ROM_PTR(&picosleep_seconds_obj)},
105105
};
106106
STATIC MP_DEFINE_CONST_DICT(picosleep_module_globals, picosleep_module_globals_table);
107107

108108
const mp_obj_module_t mp_module_picosleep = {
109-
.base = { &mp_type_module },
109+
.base = {&mp_type_module},
110110
.globals = (mp_obj_dict_t *)&picosleep_module_globals,
111-
};
111+
};
112+
113+
MP_REGISTER_MODULE(MP_QSTR_picosleep, mp_module_picosleep);

ports/rp2/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
#endif
149149
#endif
150150

151+
extern const struct _mp_obj_module_t mp_module_picosleep;
152+
151153
#if MICROPY_PY_NETWORK_CYW43
152154
extern const struct _mp_obj_type_t mp_network_cyw43_type;
153155
#define MICROPY_HW_NIC_CYW43 \

0 commit comments

Comments
 (0)