| 37 | } |
| 38 | |
| 39 | bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) { |
| 40 | static const st7796_lcd_init_cmd_t lcd_init_cmds[] = { |
| 41 | {0x01, (uint8_t[]) {0x00}, 0, 120}, |
| 42 | {0x11, (uint8_t[]) {0x00}, 0, 120}, |
| 43 | {0xF0, (uint8_t[]) {0xC3}, 1, 0}, |
| 44 | {0xF0, (uint8_t[]) {0xC3}, 1, 0}, |
| 45 | {0xF0, (uint8_t[]) {0x96}, 1, 0}, |
| 46 | {0x36, (uint8_t[]) {0x58}, 1, 0}, |
| 47 | {0x3A, (uint8_t[]) {0x55}, 1, 0}, |
| 48 | {0xB4, (uint8_t[]) {0x01}, 1, 0}, |
| 49 | {0xB6, (uint8_t[]) {0x80, 0x02, 0x3B}, 3, 0}, |
| 50 | {0xE8, (uint8_t[]) {0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33}, 8, 0}, |
| 51 | {0xC1, (uint8_t[]) {0x06}, 1, 0}, |
| 52 | {0xC2, (uint8_t[]) {0xA7}, 1, 0}, |
| 53 | {0xC5, (uint8_t[]) {0x18}, 1, 0}, |
| 54 | {0xE0, (uint8_t[]) {0xF0, 0x09, 0x0b, 0x06, 0x04, 0x15, 0x2F, 0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B}, 15, 0}, |
| 55 | {0xE1, (uint8_t[]) {0xE0, 0x09, 0x0b, 0x06, 0x04, 0x03, 0x2B, 0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B}, 15, 120}, |
| 56 | {0xF0, (uint8_t[]) {0x3C}, 1, 0}, |
| 57 | {0xF0, (uint8_t[]) {0x69}, 1, 0}, |
| 58 | {0x21, (uint8_t[]) {0x00}, 1, 0}, |
| 59 | {0x29, (uint8_t[]) {0x00}, 1, 0}, |
| 60 | }; |
| 61 | |
| 62 | st7796_vendor_config_t vendor_config = { |
| 63 | // Uncomment these lines if use custom initialization commands |
| 64 | .init_cmds = lcd_init_cmds, |
| 65 | .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(st7796_lcd_init_cmd_t), |
| 66 | }; |
| 67 | |
| 68 | const esp_lcd_panel_dev_config_t panel_config = { |
| 69 | .reset_gpio_num = configuration->resetPin, // Set to -1 if not use |
| 70 | .color_space = LCD_RGB_ELEMENT_ORDER_RGB, |
| 71 | .data_endian = LCD_RGB_DATA_ENDIAN_LITTLE, |
| 72 | .bits_per_pixel = 16, |
| 73 | .vendor_config = &vendor_config |
| 74 | }; |
| 75 | |
| 76 | if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) { |
| 77 | LOGGER.error("Failed to create panel"); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | if (esp_lcd_panel_reset(panelHandle) != ESP_OK) { |
| 82 | LOGGER.error("Failed to reset panel"); |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | if (esp_lcd_panel_init(panelHandle) != ESP_OK) { |
| 87 | LOGGER.error("Failed to init panel"); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) { |
| 92 | LOGGER.error("Failed to set panel to invert"); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) { |