28
28
#include "shared-bindings/util.h"
29
29
#include "bindings/espulp/ULP.h"
30
30
31
+ #include "py/enum.h"
31
32
#include "py/runtime.h"
33
+ #include "py/objproperty.h"
32
34
33
35
//| class ULP:
34
- //| def __init__(self):
36
+ //| def __init__(self, arch: Architecture = Architecture.FSM ):
35
37
//| """The ultra-low-power processor.
36
38
//|
37
39
//| Raises an exception if another ULP has been instantiated. This
38
- //| ensures that is is only used by one piece of code at a time."""
40
+ //| ensures that is is only used by one piece of code at a time.
41
+ //|
42
+ //| :param Architecture arch: The ulp arch"""
39
43
//| ...
40
44
STATIC mp_obj_t espulp_ulp_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
45
+ enum { ARG_arch };
46
+ static const mp_arg_t allowed_args [] = {
47
+ { MP_QSTR_arch , MP_ARG_OBJ , {.u_obj = (void * )& architecture_FSM_obj } },
48
+ };
49
+
50
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
51
+ mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
52
+
53
+ const espulp_architecture_t arch = cp_enum_value (& espulp_architecture_type , args [ARG_arch ].u_obj , MP_QSTR_arch );
54
+
41
55
espulp_ulp_obj_t * self = m_new_obj (espulp_ulp_obj_t );
42
56
self -> base .type = & espulp_ulp_type ;
43
- common_hal_espulp_ulp_construct (self );
57
+
58
+ common_hal_espulp_ulp_construct (self , arch );
59
+
44
60
return MP_OBJ_FROM_PTR (self );
45
61
}
46
62
@@ -124,7 +140,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espulp_ulp_run_obj, 2, espulp_ulp_run);
124
140
//| def halt(self) -> None:
125
141
//| """Halts the running program and releases the pins given in `run()`."""
126
142
//| ...
127
- //|
128
143
STATIC mp_obj_t espulp_ulp_halt (mp_obj_t self_in ) {
129
144
espulp_ulp_obj_t * self = MP_OBJ_TO_PTR (self_in );
130
145
check_for_deinit (self );
@@ -134,12 +149,27 @@ STATIC mp_obj_t espulp_ulp_halt(mp_obj_t self_in) {
134
149
}
135
150
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (espulp_ulp_halt_obj , espulp_ulp_halt );
136
151
152
+ //| arch: Architecture
153
+ //| """The ulp architecture. (read-only)"""
154
+ //|
155
+ STATIC mp_obj_t espulp_ulp_get_arch (mp_obj_t self_in ) {
156
+ espulp_ulp_obj_t * self = MP_OBJ_TO_PTR (self_in );
157
+ check_for_deinit (self );
158
+
159
+ return cp_enum_find (& espulp_architecture_type , self -> arch );
160
+ }
161
+ MP_DEFINE_CONST_FUN_OBJ_1 (espulp_ulp_get_arch_obj , espulp_ulp_get_arch );
162
+
163
+ MP_PROPERTY_GETTER (espulp_ulp_arch_obj ,
164
+ (mp_obj_t )& espulp_ulp_get_arch_obj );
165
+
137
166
STATIC const mp_rom_map_elem_t espulp_ulp_locals_table [] = {
138
- { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& espulp_ulp_deinit_obj ) },
139
- { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& mp_identity_obj ) },
140
- { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& espulp_ulp___exit___obj ) },
141
- { MP_ROM_QSTR (MP_QSTR_run ), MP_ROM_PTR (& espulp_ulp_run_obj ) },
142
- { MP_ROM_QSTR (MP_QSTR_halt ), MP_ROM_PTR (& espulp_ulp_halt_obj ) },
167
+ { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& espulp_ulp_deinit_obj ) },
168
+ { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& mp_identity_obj ) },
169
+ { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& espulp_ulp___exit___obj ) },
170
+ { MP_ROM_QSTR (MP_QSTR_run ), MP_ROM_PTR (& espulp_ulp_run_obj ) },
171
+ { MP_ROM_QSTR (MP_QSTR_halt ), MP_ROM_PTR (& espulp_ulp_halt_obj ) },
172
+ { MP_ROM_QSTR (MP_QSTR_arch ), MP_ROM_PTR (& espulp_ulp_arch_obj ) },
143
173
};
144
174
STATIC MP_DEFINE_CONST_DICT (espulp_ulp_locals_dict , espulp_ulp_locals_table );
145
175
0 commit comments