tarablessd1306 icon indicating copy to clipboard operation
tarablessd1306 copied to clipboard

Exception when i2c display is not connected during init

Open djkilgore opened this issue 7 years ago • 6 comments

The following exception is thrown when i2c display support is enabled but the display is disconnected.

I don't have an SPI display to test if the issue happens there.

E (162) I2CDefaultWriteBytes: i2c_master_cmd_begin( I2CPortNumber, CommandHandle, pdMS_TO_TICKS( 1000 ) ) != ESP_OK, result: -1
abort() was called at PC 0x400e063a on core 0
0x400e063a: I2CDefaultWriteBytes at components/tarablessd1306/ifaces/default_if_i2c.c:107 (discriminator 4)

The issue can be resolved by changing line default_if_i2c.c:107, but I am unsure if this is the best practice or other implications of this change:

i2c_master_cmd_begin( I2CPortNumber, CommandHandle, pdMS_TO_TICKS( 1000 ) );

djkilgore avatar Jun 12 '18 01:06 djkilgore

It's an acceptable workaround and raises a good issue about how I handle such errors.
The library assumes that if you initialize a display it's physically connected which is why I chose at the start for it to be a fatal error.

If you're looking at the examples you can comment out USE_I2C_DISPLAY and it will only use an SPI connected display instead,

TaraHoleInIt avatar Jun 12 '18 13:06 TaraHoleInIt

Consider a piece of hardware using this library in the field.

If the screen becomes disconnected or damaged it prevents the whole system from coming up. In my opinion it is preferable the rest of the hardware continue operating as normal if possible, the alternative is a reboot loop.

Maybe another constant for REQUIRE_DISPLAY_ON_BOOT as it could be application specific.

djkilgore avatar Jun 13 '18 00:06 djkilgore

OOOH I think I know what's going on.
I did make it a configurable option at one point, SSD1306_ERROR_ABORT is set by default so any time the library encounters an error it will call abort.
You can change this behaviour in menuconfig under Components->TarableSSD1306, let me know if it works and I apologize for the slowness of my reply.

TaraHoleInIt avatar Jun 17 '18 03:06 TaraHoleInIt

hi, with SSD1306_ERROR_ABORT deactivated, the SSD1306_I2CMasterAttachDisplayDefault() returns true if the display is disconnected, and only printing the error on the console:

E (21938) I2CDefaultWriteBytes: i2c_master_cmd_begin( I2CPortNumber, CommandHandle, pdMS_TO_TICKS( 1000 ) ) != ESP_OK, result: -1

The right behavior would be to return false if the display failed to initialize.

cc32d9 avatar May 23 '20 00:05 cc32d9

Thank you for letting me know. I'm working out how I want to fix this.

TaraHoleInIt avatar May 25 '20 22:05 TaraHoleInIt

Try the latest commit.

TaraHoleInIt avatar May 25 '20 23:05 TaraHoleInIt