2828#include "shared-bindings/util.h"
2929#include "bindings/espulp/ULP.h"
3030
31+ #include "py/enum.h"
3132#include "py/runtime.h"
33+ #include "py/objproperty.h"
3234
3335//| class ULP:
34- //| def __init__(self):
36+ //| def __init__(self, arch: Architecture = Architecture.FSM ):
3537//| """The ultra-low-power processor.
3638//|
3739//| 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"""
3943//| ...
4044STATIC 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+
4155 espulp_ulp_obj_t * self = m_new_obj (espulp_ulp_obj_t );
4256 self -> base .type = & espulp_ulp_type ;
43- common_hal_espulp_ulp_construct (self );
57+
58+ common_hal_espulp_ulp_construct (self , arch );
59+
4460 return MP_OBJ_FROM_PTR (self );
4561}
4662
@@ -124,7 +140,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espulp_ulp_run_obj, 2, espulp_ulp_run);
124140//| def halt(self) -> None:
125141//| """Halts the running program and releases the pins given in `run()`."""
126142//| ...
127- //|
128143STATIC mp_obj_t espulp_ulp_halt (mp_obj_t self_in ) {
129144 espulp_ulp_obj_t * self = MP_OBJ_TO_PTR (self_in );
130145 check_for_deinit (self );
@@ -134,12 +149,27 @@ STATIC mp_obj_t espulp_ulp_halt(mp_obj_t self_in) {
134149}
135150STATIC MP_DEFINE_CONST_FUN_OBJ_1 (espulp_ulp_halt_obj , espulp_ulp_halt );
136151
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+
137166STATIC 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 ) },
143173};
144174STATIC MP_DEFINE_CONST_DICT (espulp_ulp_locals_dict , espulp_ulp_locals_table );
145175
0 commit comments