@@ -61,6 +61,8 @@ DECLARE PRIVATE FUNCTIONS
6161STATIC pin_obj_t * pin_find_named_pin (const mp_obj_dict_t * named_pins , mp_obj_t name );
6262STATIC pin_obj_t * pin_find_pin_by_port_bit (const mp_obj_dict_t * named_pins , uint port , uint bit );
6363STATIC int8_t pin_obj_find_af (const pin_obj_t * pin , uint8_t fn , uint8_t unit , uint8_t type );
64+ STATIC int8_t pin_find_af_index (const pin_obj_t * pin , uint8_t fn , uint8_t unit , uint8_t type );
65+ STATIC void pin_free_af_from_pins (uint8_t fn , uint8_t unit , uint8_t type );
6466STATIC void pin_deassign (pin_obj_t * pin );
6567STATIC void pin_obj_configure (const pin_obj_t * self );
6668STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t * self , uint * wake_pin , uint * idx );
@@ -162,26 +164,12 @@ void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint
162164 pybsleep_add ((const mp_obj_t )self , (WakeUpCB_t )pin_obj_configure );
163165}
164166
165- int8_t pin_find_af_index (const pin_obj_t * pin , uint8_t fn , uint8_t unit , uint8_t type ) {
166- int8_t af = pin_obj_find_af (pin , fn , unit , type );
167- if (af < 0 ) {
168- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
169- }
170- return af ;
171- }
172-
173- void pin_free_af_from_pins (uint8_t fn , uint8_t unit , uint8_t type ) {
174- mp_map_t * named_map = mp_obj_dict_get_map ((mp_obj_t )& pin_board_pins_locals_dict );
175- for (uint i = 0 ; i < named_map -> used - 1 ; i ++ ) {
176- pin_obj_t * pin = (pin_obj_t * )named_map -> table [i ].value ;
177- // af is different than GPIO
178- if (pin -> af > PIN_MODE_0 ) {
179- // check if the pin supports the target af
180- int af = pin_obj_find_af (pin , fn , unit , type );
181- if (af > 0 && af == pin -> af ) {
182- // the pin is assigned to the target af, de-assign it
183- pin_deassign (pin );
184- }
167+ void pin_assign_pins_af (mp_obj_t * pins , uint32_t n_pins , uint32_t pull , uint32_t fn , uint32_t unit ) {
168+ for (int i = 0 ; i < n_pins ; i ++ ) {
169+ pin_free_af_from_pins (fn , unit , i );
170+ if (pins [i ] != mp_const_none ) {
171+ pin_obj_t * pin = pin_find (pins [i ]);
172+ pin_config (pin , pin_find_af_index (pin , fn , unit , i ), 0 , pull , -1 , PIN_STRENGTH_2MA );
185173 }
186174 }
187175}
@@ -218,6 +206,30 @@ STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, u
218206 return -1 ;
219207}
220208
209+ STATIC int8_t pin_find_af_index (const pin_obj_t * pin , uint8_t fn , uint8_t unit , uint8_t type ) {
210+ int8_t af = pin_obj_find_af (pin , fn , unit , type );
211+ if (af < 0 ) {
212+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
213+ }
214+ return af ;
215+ }
216+
217+ STATIC void pin_free_af_from_pins (uint8_t fn , uint8_t unit , uint8_t type ) {
218+ mp_map_t * named_map = mp_obj_dict_get_map ((mp_obj_t )& pin_board_pins_locals_dict );
219+ for (uint i = 0 ; i < named_map -> used - 1 ; i ++ ) {
220+ pin_obj_t * pin = (pin_obj_t * )named_map -> table [i ].value ;
221+ // af is different than GPIO
222+ if (pin -> af > PIN_MODE_0 ) {
223+ // check if the pin supports the target af
224+ int af = pin_obj_find_af (pin , fn , unit , type );
225+ if (af > 0 && af == pin -> af ) {
226+ // the pin is assigned to the target af, de-assign it
227+ pin_deassign (pin );
228+ }
229+ }
230+ }
231+ }
232+
221233STATIC void pin_deassign (pin_obj_t * pin ) {
222234 pin_config (pin , PIN_MODE_0 , GPIO_DIR_MODE_IN , PIN_TYPE_STD , -1 , PIN_STRENGTH_4MA );
223235 pin -> used = false;
0 commit comments