@@ -90,21 +90,40 @@ STATIC mp_obj_t espulp_ulp_obj___exit__(size_t n_args, const mp_obj_t *args) {
90
90
}
91
91
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (espulp_ulp___exit___obj , 4 , 4 , espulp_ulp_obj___exit__ );
92
92
93
+ //| def set_wakeup_period(self, period_index: int, period_us: int) -> None:
94
+ //| """Sets the wakeup period for the ULP."""
95
+ //| ...
96
+ STATIC mp_obj_t espulp_ulp_set_wakeup_period (mp_obj_t self_in , mp_obj_t period_index , mp_obj_t period_us ) {
97
+ espulp_ulp_obj_t * self = MP_OBJ_TO_PTR (self_in );
98
+ check_for_deinit (self );
99
+
100
+ // period_index should be between 0 and 4 but bounds checking happens in esp-idf, so no need to do that here
101
+ common_hal_espulp_ulp_set_wakeup_period (self , mp_obj_get_int (period_index ), mp_obj_get_int (period_us ));
102
+
103
+ return mp_const_none ;
104
+ }
105
+ STATIC MP_DEFINE_CONST_FUN_OBJ_3 (espulp_ulp_set_wakeup_period_obj , espulp_ulp_set_wakeup_period );
106
+
93
107
//| def run(
94
- //| self, program: ReadableBuffer, *, pins: Sequence[microcontroller.Pin] = ()
108
+ //| self,
109
+ //| program: ReadableBuffer,
110
+ //| *,
111
+ //| entrypoint: int,
112
+ //| pins: Sequence[microcontroller.Pin] = ()
95
113
//| ) -> None:
96
- //| """Loads the program into ULP memory and then runs the program. The given pins are
97
- //| claimed and not reset until `halt()` is called.
114
+ //| """Loads the program into ULP memory and then runs the program, starting at entry_point.
115
+ //| The given pins are claimed and not reset until `halt()` is called.
98
116
//|
99
117
//| The program will continue to run even when the running Python is halted."""
100
118
//| ...
101
119
STATIC mp_obj_t espulp_ulp_run (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
102
120
espulp_ulp_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
103
121
check_for_deinit (self );
104
122
105
- enum { ARG_program , ARG_pins };
123
+ enum { ARG_program , ARG_entrypoint , ARG_pins };
106
124
static const mp_arg_t allowed_args [] = {
107
125
{ MP_QSTR_program , MP_ARG_REQUIRED | MP_ARG_OBJ },
126
+ { MP_QSTR_entrypoint , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 }},
108
127
{ MP_QSTR_pins , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_empty_tuple } },
109
128
};
110
129
@@ -114,6 +133,8 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
114
133
mp_buffer_info_t bufinfo ;
115
134
mp_get_buffer_raise (args [ARG_program ].u_obj , & bufinfo , MP_BUFFER_READ );
116
135
136
+ mp_uint_t entrypoint = args [ARG_entrypoint ].u_int ;
137
+
117
138
mp_obj_t pins_in = args [ARG_pins ].u_obj ;
118
139
const size_t num_pins = (size_t )MP_OBJ_SMALL_INT_VALUE (mp_obj_len (pins_in ));
119
140
@@ -131,7 +152,7 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
131
152
pin_mask |= 1 << pin -> number ;
132
153
}
133
154
134
- common_hal_espulp_ulp_run (self , bufinfo .buf , bufinfo .len , pin_mask );
155
+ common_hal_espulp_ulp_run (self , bufinfo .buf , bufinfo .len , entrypoint , pin_mask );
135
156
return mp_const_none ;
136
157
}
137
158
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (espulp_ulp_run_obj , 2 , espulp_ulp_run );
@@ -163,12 +184,13 @@ MP_PROPERTY_GETTER(espulp_ulp_arch_obj,
163
184
(mp_obj_t )& espulp_ulp_get_arch_obj );
164
185
165
186
STATIC const mp_rom_map_elem_t espulp_ulp_locals_table [] = {
166
- { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& espulp_ulp_deinit_obj ) },
167
- { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& mp_identity_obj ) },
168
- { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& espulp_ulp___exit___obj ) },
169
- { MP_ROM_QSTR (MP_QSTR_run ), MP_ROM_PTR (& espulp_ulp_run_obj ) },
170
- { MP_ROM_QSTR (MP_QSTR_halt ), MP_ROM_PTR (& espulp_ulp_halt_obj ) },
171
- { MP_ROM_QSTR (MP_QSTR_arch ), MP_ROM_PTR (& espulp_ulp_arch_obj ) },
187
+ { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& espulp_ulp_deinit_obj ) },
188
+ { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& mp_identity_obj ) },
189
+ { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& espulp_ulp___exit___obj ) },
190
+ { MP_ROM_QSTR (MP_QSTR_set_wakeup_period ), MP_ROM_PTR (& espulp_ulp_set_wakeup_period_obj )},
191
+ { MP_ROM_QSTR (MP_QSTR_run ), MP_ROM_PTR (& espulp_ulp_run_obj ) },
192
+ { MP_ROM_QSTR (MP_QSTR_halt ), MP_ROM_PTR (& espulp_ulp_halt_obj ) },
193
+ { MP_ROM_QSTR (MP_QSTR_arch ), MP_ROM_PTR (& espulp_ulp_arch_obj ) },
172
194
};
173
195
STATIC MP_DEFINE_CONST_DICT (espulp_ulp_locals_dict , espulp_ulp_locals_table );
174
196
0 commit comments