Skip to content

Commit 4fdf0d1

Browse files
committed
Fix digitalio allocation location
1 parent 03ec5c8 commit 4fdf0d1

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

shared-module/bitbangio/I2C.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,14 @@ void shared_module_bitbangio_i2c_construct(bitbangio_i2c_obj_t *self,
167167
self->us_delay = 1;
168168
}
169169

170+
// Allocate the pins in the same place as self.
171+
bool use_port_allocation = !gc_alloc_possible() || !gc_ptr_on_heap(self);
172+
170173
// Convert scl from Pin to DigitalInOutProtocol
171-
self->scl = digitalinout_protocol_from_pin(scl, MP_QSTR_scl, false, false, &self->own_scl);
174+
self->scl = digitalinout_protocol_from_pin(scl, MP_QSTR_scl, false, use_port_allocation, &self->own_scl);
172175

173176
// Convert sda from Pin to DigitalInOutProtocol
174-
self->sda = digitalinout_protocol_from_pin(sda, MP_QSTR_sda, false, false, &self->own_sda);
177+
self->sda = digitalinout_protocol_from_pin(sda, MP_QSTR_sda, false, use_port_allocation, &self->own_sda);
175178

176179
digitalinout_protocol_switch_to_output(self->scl, true, DRIVE_MODE_OPEN_DRAIN);
177180
digitalinout_protocol_switch_to_output(self->sda, true, DRIVE_MODE_OPEN_DRAIN);

shared-module/bitbangio/SPI.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@
2323
void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
2424
mp_obj_t clock, mp_obj_t mosi, mp_obj_t miso) {
2525

26+
// Allocate the pins in the same place as self.
27+
bool use_port_allocation = !gc_alloc_possible() || !gc_ptr_on_heap(self);
28+
2629
// Convert clock from Pin to DigitalInOutProtocol
27-
self->clock = digitalinout_protocol_from_pin(clock, MP_QSTR_clock, false, false, &self->own_clock);
30+
self->clock = digitalinout_protocol_from_pin(clock, MP_QSTR_clock, false, use_port_allocation, &self->own_clock);
2831
digitalinout_protocol_switch_to_output(self->clock, self->polarity == 1, DRIVE_MODE_PUSH_PULL);
2932

3033
// Convert mosi from Pin to DigitalInOutProtocol (optional)
31-
self->mosi = digitalinout_protocol_from_pin(mosi, MP_QSTR_mosi, true, false, &self->own_mosi);
34+
self->mosi = digitalinout_protocol_from_pin(mosi, MP_QSTR_mosi, true, use_port_allocation, &self->own_mosi);
3235
self->has_mosi = (self->mosi != mp_const_none);
3336
if (self->has_mosi) {
3437
digitalinout_protocol_switch_to_output(self->mosi, false, DRIVE_MODE_PUSH_PULL);
3538
}
3639

3740
// Convert miso from Pin to DigitalInOutProtocol (optional)
38-
self->miso = digitalinout_protocol_from_pin(miso, MP_QSTR_miso, true, false, &self->own_miso);
41+
self->miso = digitalinout_protocol_from_pin(miso, MP_QSTR_miso, true, use_port_allocation, &self->own_miso);
3942
self->has_miso = (self->miso != mp_const_none);
4043
// MISO starts out as input by default, no need to change
4144

shared-module/fourwire/FourWire.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)