Skip to content

Commit 93cdf51

Browse files
authored
Merge pull request #2277 from makermelissa/master
Fixed I2CDisplay reset issue
2 parents 9115667 + 39b3825 commit 93cdf51

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

shared-module/displayio/I2CDisplay.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,29 @@
4242
void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
4343
busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) {
4444

45+
// Reset the display before probing
46+
self->reset.base.type = &mp_type_NoneType;
47+
if (reset != NULL) {
48+
self->reset.base.type = &digitalio_digitalinout_type;
49+
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
50+
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
51+
never_reset_pin_number(reset->number);
52+
common_hal_displayio_i2cdisplay_reset(self);
53+
}
54+
4555
// Probe the bus to see if a device acknowledges the given address.
4656
if (!common_hal_busio_i2c_probe(i2c, device_address)) {
4757
mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address);
4858
}
4959

50-
// Write to the device and return 0 on success or an appropriate error code from mperrno.h
60+
// Write to the device and return 0 on success or an appropriate error code from mperrno.h
5161
self->bus = i2c;
5262
common_hal_busio_i2c_never_reset(self->bus);
5363
// Our object is statically allocated off the heap so make sure the bus object lives to the end
5464
// of the heap as well.
5565
gc_never_free(self->bus);
5666

5767
self->address = device_address;
58-
59-
self->reset.base.type = &mp_type_NoneType;
60-
if (reset != NULL) {
61-
self->reset.base.type = &digitalio_digitalinout_type;
62-
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
63-
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
64-
never_reset_pin_number(reset->number);
65-
common_hal_displayio_i2cdisplay_reset(self);
66-
}
6768
}
6869

6970
void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {

0 commit comments

Comments
 (0)