| 69 | } |
| 70 | |
| 71 | bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) { |
| 72 | // Manual hardware reset with proper timing for Heltec V3 |
| 73 | if (configuration->resetPin != GPIO_NUM_NC) { |
| 74 | gpio_config_t reset_gpio_config = { |
| 75 | .pin_bit_mask = 1ULL << configuration->resetPin, |
| 76 | .mode = GPIO_MODE_OUTPUT, |
| 77 | .pull_up_en = GPIO_PULLUP_DISABLE, |
| 78 | .pull_down_en = GPIO_PULLDOWN_DISABLE, |
| 79 | .intr_type = GPIO_INTR_DISABLE, |
| 80 | }; |
| 81 | gpio_config(&reset_gpio_config); |
| 82 | |
| 83 | gpio_set_level(configuration->resetPin, 0); |
| 84 | vTaskDelay(pdMS_TO_TICKS(10)); |
| 85 | gpio_set_level(configuration->resetPin, 1); |
| 86 | vTaskDelay(pdMS_TO_TICKS(100)); |
| 87 | } |
| 88 | |
| 89 | // Create ESP-IDF panel (but don't call init - we'll do custom init) |
| 90 | esp_lcd_panel_dev_config_t panel_config = { |
| 91 | .reset_gpio_num = GPIO_NUM_NC, // Already handled above |
| 92 | .color_space = ESP_LCD_COLOR_SPACE_MONOCHROME, |
| 93 | .data_endian = LCD_RGB_DATA_ENDIAN_BIG, |
| 94 | .bits_per_pixel = 1, // Must be 1 for monochrome |
| 95 | .flags = { |
| 96 | .reset_active_high = false, |
| 97 | }, |
| 98 | .vendor_config = nullptr, |
| 99 | }; |
| 100 | |
| 101 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) |
| 102 | esp_lcd_panel_ssd1306_config_t ssd1306_config = { |
| 103 | .height = static_cast<uint8_t>(configuration->verticalResolution), |
| 104 | }; |
| 105 | panel_config.vendor_config = &ssd1306_config; |
| 106 | #endif |
| 107 | |
| 108 | if (esp_lcd_new_panel_ssd1306(ioHandle, &panel_config, &panelHandle) != ESP_OK) { |
| 109 | LOGGER.error("Failed to create panel"); |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | // Don't call esp_lcd_panel_init() - it doesn't configure correctly for Heltec V3! |
| 114 | // Instead, send our custom initialization sequence directly via I2C |
| 115 | |
| 116 | auto port = configuration->port; |
| 117 | auto addr = configuration->deviceAddress; |
| 118 | |
| 119 | LOGGER.info("Sending Heltec V3 custom init sequence"); |
| 120 | |
| 121 | // Display off while configuring |
| 122 | ssd1306_i2c_send_cmd(port, addr, SSD1306_CMD_DISPLAY_OFF); |
| 123 | |
| 124 | // Set oscillator frequency (MUST come early in sequence) |
| 125 | ssd1306_i2c_send_cmd(port, addr, SSD1306_CMD_SET_CLOCK); |
| 126 | ssd1306_i2c_send_cmd(port, addr, 0xF0); // ~96 Hz |
| 127 | |
| 128 | // Set multiplex ratio |
nothing calls this directly
no test coverage detected