Skip to content

Commit 85dadf3

Browse files
committed
More API changes
1 parent 1196d4b commit 85dadf3

File tree

12 files changed

+395
-60
lines changed

12 files changed

+395
-60
lines changed

shared-bindings/_typing/__init__.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@ FrameBuffer = Union[rgbmatrix.RGBMatrix]
5252
5353
- `rgbmatrix.RGBMatrix`
5454
"""
55+
56+
Alarm = Union[
57+
alarm_time.Time, alarm_pin.PinLevel, alarm_touch.PinTouch
58+
]
59+
"""Classes that implement the audiosample protocol
60+
61+
- `alarm_time.Time`
62+
- `alarm_pin.PinLevel`
63+
- `alarm_touch.PinTouch`
64+
65+
You can play use these alarms to wake from light or deep sleep.
66+
"""

shared-bindings/alarm_time/Time.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 "py/obj.h"
28+
#include "shared-bindings/alarm_time/__init__.h"
29+
30+
//| """alarm_time module
31+
//|
32+
//| The `alarm_time` module implements deep sleep."""
33+
34+
STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
35+
#if MICROPY_PY_BUILTINS_FLOAT
36+
mp_float_t seconds = mp_obj_get_float(seconds_o);
37+
mp_float_t msecs = 1000.0f * seconds + 0.5f;
38+
#else
39+
mp_int_t seconds = mp_obj_get_int(seconds_o);
40+
mp_int_t msecs = 1000 * seconds;
41+
#endif
42+
43+
if (seconds < 0) {
44+
mp_raise_ValueError(translate("sleep length must be non-negative"));
45+
}
46+
common_hal_alarm_time_duration(msecs);
47+
48+
alarm_time_obj_t *self = m_new_obj(alarm_time_obj_t);
49+
self->base.type = &alarm_time_type;
50+
51+
return self;
52+
}
53+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
54+
55+
STATIC mp_obj_t alarm_time_disable(void) {
56+
common_hal_alarm_time_disable();
57+
return mp_const_none;
58+
}
59+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_time_disable_obj, alarm_time_disable);
60+
61+
STATIC const mp_rom_map_elem_t alarm_time_module_globals_table[] = {
62+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_time) },
63+
{ MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&alarm_time_duration_obj) },
64+
{ MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_time_disable_obj) },
65+
};
66+
STATIC MP_DEFINE_CONST_DICT(alarm_time_module_globals, alarm_time_module_globals_table);
67+
68+
const mp_obj_module_t alarm_time_module = {
69+
.base = { &mp_type_module },
70+
.globals = (mp_obj_dict_t*)&alarm_time_module_globals,
71+
};
72+
73+
const mp_obj_type_t alarm_time_type = {
74+
{ &mp_type_type },
75+
.name = MP_QSTR_timeAlarm,
76+
};

shared-bindings/alarm_time/Time.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
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+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H
29+
30+
#include "py/runtime.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
uint64_t time_to_alarm;
35+
} alarm_time_time_obj_t;
36+
37+
extern const mp_obj_type_t alarm_time_time_type;
38+
39+
void common_hal_alarm_time_time_construct(alarm_time_time_obj_t* self,
40+
uint64_t ticks_ms);
41+
42+
#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H

shared-bindings/alarm_time/__init__.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
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+
127
#include "py/obj.h"
228
#include "shared-bindings/alarm_time/__init__.h"
329

shared-bindings/canio/BusState.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
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 "py/enum.h"
28+
29+
#include "shared-bindings/canio/BusState.h"
30+
31+
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_ACTIVE, BUS_STATE_ERROR_ACTIVE);
32+
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, BUS_STATE_ERROR_PASSIVE);
33+
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, BUS_STATE_ERROR_WARNING);
34+
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, BUS_STATE_OFF);
35+
36+
//| class BusState:
37+
//| """The state of the CAN bus"""
38+
//|
39+
//| ERROR_ACTIVE: object
40+
//| """The bus is in the normal (active) state"""
41+
//|
42+
//| ERROR_WARNING: object
43+
//| """The bus is in the normal (active) state, but a moderate number of errors have occurred recently.
44+
//|
45+
//| NOTE: Not all implementations may use ERROR_WARNING. Do not rely on seeing ERROR_WARNING before ERROR_PASSIVE."""
46+
//|
47+
//| ERROR_PASSIVE: object
48+
//| """The bus is in the passive state due to the number of errors that have occurred recently.
49+
//|
50+
//| This device will acknowledge packets it receives, but cannot transmit messages.
51+
//| If additional errors occur, this device may progress to BUS_OFF.
52+
//| If it successfully acknowledges other packets on the bus, it can return to ERROR_WARNING or ERROR_ACTIVE and transmit packets.
53+
//| """
54+
//|
55+
//| BUS_OFF: object
56+
//| """The bus has turned off due to the number of errors that have
57+
//| occurred recently. It must be restarted before it will send or receive
58+
//| packets. This device will neither send or acknowledge packets on the bus."""
59+
//|
60+
MAKE_ENUM_MAP(canio_bus_state) {
61+
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE),
62+
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE),
63+
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING),
64+
MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF),
65+
};
66+
STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table);
67+
68+
MAKE_PRINTER(canio, canio_bus_state);
69+
70+
MAKE_ENUM_TYPE(canio, BusState, canio_bus_state);

shared-bindings/canio/BusState.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
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+
#pragma once
28+
29+
typedef enum {
30+
BUS_STATE_ERROR_ACTIVE, BUS_STATE_ERROR_PASSIVE, BUS_STATE_ERROR_WARNING, BUS_STATE_OFF
31+
} canio_bus_state_t;
32+
33+
extern const mp_obj_type_t canio_bus_state_type;

shared-bindings/canio/__init__.c

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "py/obj.h"
28+
29+
#include "shared-bindings/canio/__init__.h"
30+
31+
#include "shared-bindings/canio/BusState.h"
32+
#include "shared-bindings/canio/CAN.h"
33+
#include "shared-bindings/canio/Match.h"
34+
#include "shared-bindings/canio/Message.h"
35+
#include "shared-bindings/canio/Listener.h"
36+
2737
//| """CAN bus access
2838
//|
2939
//| The `canio` module contains low level classes to support the CAN bus
@@ -57,56 +67,6 @@
5767
//| """
5868
//|
5969

60-
#include "py/obj.h"
61-
#include "py/enum.h"
62-
63-
#include "shared-bindings/canio/__init__.h"
64-
#include "shared-bindings/canio/CAN.h"
65-
#include "shared-bindings/canio/Match.h"
66-
#include "shared-bindings/canio/Message.h"
67-
#include "shared-bindings/canio/Listener.h"
68-
69-
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_ACTIVE, BUS_STATE_ERROR_ACTIVE);
70-
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, BUS_STATE_ERROR_PASSIVE);
71-
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, BUS_STATE_ERROR_WARNING);
72-
MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, BUS_STATE_OFF);
73-
74-
//| class BusState:
75-
//| """The state of the CAN bus"""
76-
//|
77-
//| ERROR_ACTIVE: object
78-
//| """The bus is in the normal (active) state"""
79-
//|
80-
//| ERROR_WARNING: object
81-
//| """The bus is in the normal (active) state, but a moderate number of errors have occurred recently.
82-
//|
83-
//| NOTE: Not all implementations may use ERROR_WARNING. Do not rely on seeing ERROR_WARNING before ERROR_PASSIVE."""
84-
//|
85-
//| ERROR_PASSIVE: object
86-
//| """The bus is in the passive state due to the number of errors that have occurred recently.
87-
//|
88-
//| This device will acknowledge packets it receives, but cannot transmit messages.
89-
//| If additional errors occur, this device may progress to BUS_OFF.
90-
//| If it successfully acknowledges other packets on the bus, it can return to ERROR_WARNING or ERROR_ACTIVE and transmit packets.
91-
//| """
92-
//|
93-
//| BUS_OFF: object
94-
//| """The bus has turned off due to the number of errors that have
95-
//| occurred recently. It must be restarted before it will send or receive
96-
//| packets. This device will neither send or acknowledge packets on the bus."""
97-
//|
98-
MAKE_ENUM_MAP(canio_bus_state) {
99-
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE),
100-
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE),
101-
MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING),
102-
MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF),
103-
};
104-
STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table);
105-
106-
MAKE_PRINTER(canio, canio_bus_state);
107-
108-
MAKE_ENUM_TYPE(canio, BusState, canio_bus_state);
109-
11070
STATIC const mp_rom_map_elem_t canio_module_globals_table[] = {
11171
{ MP_ROM_QSTR(MP_QSTR_BusState), MP_ROM_PTR(&canio_bus_state_type) },
11272
{ MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&canio_can_type) },

shared-bindings/canio/__init__.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,3 @@
2525
*/
2626

2727
#pragma once
28-
29-
typedef enum {
30-
BUS_STATE_ERROR_ACTIVE, BUS_STATE_ERROR_PASSIVE, BUS_STATE_ERROR_WARNING, BUS_STATE_OFF
31-
} canio_bus_state_t;
32-
33-
extern const mp_obj_type_t canio_bus_state_type;

shared-bindings/sleepio/__init__.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
//|
3434
//| Light sleep leaves the CPU and RAM powered so that CircuitPython can resume where it left off
3535
//| 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()`.
36+
//| called. To light sleep until a non-time alarm use `sleepio.sleep_until_alarm()`. Any active
37+
//| peripherals, such as I2C, are left on.
3738
//|
3839
//| Deep sleep shuts down power to nearly all of the chip including the CPU and RAM. This can save
3940
//| a more significant amount of power at the cost of starting CircuitPython from scratch when woken
4041
//| up. CircuitPython will enter deep sleep automatically when code exits without error. If an
4142
//| error causes CircuitPython to exit, error LED error flashes will be done periodically. To set
4243
//| alarms for deep sleep use `sleepio.set_alarms` they will apply to next deep sleep only."""
43-
44+
//|
4445

4546
//| wake_alarm: Alarm
4647
//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
@@ -86,8 +87,9 @@ mp_map_elem_t sleepio_module_globals_table[] = {
8687
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sleepio) },
8788

8889
{ 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 },
90+
91+
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), sleepio_sleep_until_alarm_obj },
92+
{ MP_ROM_QSTR(MP_QSTR_set_alarms), sleepio_set_alarms_obj },
9193
};
9294
STATIC MP_DEFINE_CONST_DICT(sleepio_module_globals, sleepio_module_globals_table);
9395

0 commit comments

Comments
 (0)