@@ -29,20 +29,23 @@ void common_hal_fourwire_fourwire_construct(fourwire_fourwire_obj_t *self,
2929 self -> polarity = polarity ;
3030 self -> phase = phase ;
3131
32- self -> command = digitalinout_protocol_from_pin (command , MP_QSTR_command , true, false, & self -> own_command );
32+ // Allocate the pins in the same place as self.
33+ bool use_port_allocation = !gc_alloc_possible () || !gc_ptr_on_heap (self );
34+
35+ self -> command = digitalinout_protocol_from_pin (command , MP_QSTR_command , true, use_port_allocation , & self -> own_command );
3336 if (self -> command != mp_const_none ) {
3437 digitalinout_protocol_switch_to_output (self -> command , true, DRIVE_MODE_PUSH_PULL );
3538 common_hal_never_reset_pin (command );
3639 }
3740
38- self -> reset = digitalinout_protocol_from_pin (reset , MP_QSTR_reset , true, false , & self -> own_reset );
41+ self -> reset = digitalinout_protocol_from_pin (reset , MP_QSTR_reset , true, use_port_allocation , & self -> own_reset );
3942 if (self -> reset != mp_const_none ) {
4043 digitalinout_protocol_switch_to_output (self -> reset , true, DRIVE_MODE_PUSH_PULL );
4144 common_hal_never_reset_pin (reset );
4245 common_hal_fourwire_fourwire_reset (self );
4346 }
4447
45- self -> chip_select = digitalinout_protocol_from_pin (chip_select , MP_QSTR_chip_select , true, false , & self -> own_chip_select );
48+ self -> chip_select = digitalinout_protocol_from_pin (chip_select , MP_QSTR_chip_select , true, use_port_allocation , & self -> own_chip_select );
4649 if (self -> chip_select != mp_const_none ) {
4750 digitalinout_protocol_switch_to_output (self -> chip_select , true, DRIVE_MODE_PUSH_PULL );
4851 common_hal_never_reset_pin (chip_select );
0 commit comments