|
42 | 42 | void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, |
43 | 43 | busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) { |
44 | 44 |
|
| 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 | + |
45 | 55 | // Probe the bus to see if a device acknowledges the given address. |
46 | 56 | if (!common_hal_busio_i2c_probe(i2c, device_address)) { |
47 | 57 | mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address); |
48 | 58 | } |
49 | 59 |
|
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 |
51 | 61 | self->bus = i2c; |
52 | 62 | common_hal_busio_i2c_never_reset(self->bus); |
53 | 63 | // Our object is statically allocated off the heap so make sure the bus object lives to the end |
54 | 64 | // of the heap as well. |
55 | 65 | gc_never_free(self->bus); |
56 | 66 |
|
57 | 67 | 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 | | - } |
67 | 68 | } |
68 | 69 |
|
69 | 70 | void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) { |
|
0 commit comments