Skip to content

Commit 1196d4b

Browse files
committed
move to new module
1 parent 354536c commit 1196d4b

File tree

4 files changed

+111
-38
lines changed

4 files changed

+111
-38
lines changed

shared-bindings/alarm/__init__.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

shared-bindings/alarm/__init__.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

shared-bindings/sleepio/__init__.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/alarm/__init__.h"
28+
29+
//| """Light and deep sleep used to save power
30+
//|
31+
//| The `sleepio` module provides sleep related functionality. There are two supported levels of
32+
//| sleep, light and deep.
33+
//|
34+
//| Light sleep leaves the CPU and RAM powered so that CircuitPython can resume where it left off
35+
//| after being woken up. Light sleep is automatically done by CircuitPython when `time.sleep()` is
36+
//| called. To light sleep until a non-time alarm use `sleepio.sleep_until_alarm()`.
37+
//|
38+
//| Deep sleep shuts down power to nearly all of the chip including the CPU and RAM. This can save
39+
//| a more significant amount of power at the cost of starting CircuitPython from scratch when woken
40+
//| up. CircuitPython will enter deep sleep automatically when code exits without error. If an
41+
//| error causes CircuitPython to exit, error LED error flashes will be done periodically. To set
42+
//| alarms for deep sleep use `sleepio.set_alarms` they will apply to next deep sleep only."""
43+
44+
45+
//| wake_alarm: Alarm
46+
//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
47+
//|
48+
49+
//| def sleep_until_alarm(alarm: Alarm, ...) -> Alarm:
50+
//| """Performs a light sleep until woken by one of the alarms. The alarm that woke us up is
51+
//| returned."""
52+
//| ...
53+
//|
54+
55+
STATIC mp_obj_t sleepio_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
56+
// mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
57+
// vstr_t vstr;
58+
// vstr_init_len(&vstr, size);
59+
// byte *p = (byte*)vstr.buf;
60+
// memset(p, 0, size);
61+
// byte *end_p = &p[size];
62+
// shared_modules_struct_pack_into(args[0], p, end_p, n_args - 1, &args[1]);
63+
// return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
64+
}
65+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleepio_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleepio_sleep_until_alarm);
66+
67+
//| def set_alarms(alarm: Alarm, ...) -> None:
68+
//| """Set one or more alarms to wake up from a deep sleep. The last alarm to wake us up is
69+
//| available as `wake_alarm`."""
70+
//| ...
71+
//|
72+
STATIC mp_obj_t sleepio_set_alarms(size_t n_args, const mp_obj_t *args) {
73+
// mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
74+
// vstr_t vstr;
75+
// vstr_init_len(&vstr, size);
76+
// byte *p = (byte*)vstr.buf;
77+
// memset(p, 0, size);
78+
// byte *end_p = &p[size];
79+
// shared_modules_struct_pack_into(args[0], p, end_p, n_args - 1, &args[1]);
80+
// return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
81+
}
82+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleepio_set_alarms_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleepio_set_alarms);
83+
84+
85+
mp_map_elem_t sleepio_module_globals_table[] = {
86+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sleepio) },
87+
88+
{ MP_ROM_QSTR(MP_QSTR_wake_alarm), mp_const_none },
89+
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), mp_const_none },
90+
{ MP_ROM_QSTR(MP_QSTR_set_alarms), mp_const_none },
91+
};
92+
STATIC MP_DEFINE_CONST_DICT(sleepio_module_globals, sleepio_module_globals_table);
93+
94+
void common_hal_sleepio_set_wake_alarm(mp_obj_t alarm) {
95+
// sleepio_module_globals_table[1].value = alarm;
96+
}
97+
98+
const mp_obj_module_t sleepio_module = {
99+
.base = { &mp_type_module },
100+
.globals = (mp_obj_dict_t*)&sleepio_module_globals,
101+
};

shared-bindings/sleepio/__init__.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SLEEPIO___INIT___H
2+
#define MICROPY_INCLUDED_SHARED_BINDINGS_SLEEPIO___INIT___H
3+
4+
#include "py/obj.h"
5+
6+
// This is implemented by shared-bindings so that implementations can set the
7+
// newest alarm source.
8+
extern void common_hal_sleepio_set_wake_alarm(mp_obj_t alarm);
9+
10+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SLEEPIO___INIT___H

0 commit comments

Comments
 (0)