|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "soc/soc_caps.h" |
| 8 | + |
| 9 | +#if SOC_MIPI_DSI_SUPPORTED |
| 10 | +#include <stdlib.h> |
| 11 | +#include <string.h> |
| 12 | +#include "ESP_PanelLog.h" |
| 13 | +#include "DSI.h" |
| 14 | + |
| 15 | +#define MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV (2500) |
| 16 | + |
| 17 | +static const char *TAG = "ESP_PanelBus_DSI"; |
| 18 | + |
| 19 | +ESP_PanelBus_DSI::ESP_PanelBus_DSI(uint32_t lane_rate, uint8_t lane_num, int ldo_id): |
| 20 | + ESP_PanelBus(ESP_PANEL_HOST_DSI_ID_DEFAULT, ESP_PANEL_BUS_TYPE_MIPI_DSI, true), |
| 21 | + ldo_chan_id(ldo_id), |
| 22 | + ldo_handle(NULL), |
| 23 | + host_config((esp_lcd_dsi_bus_config_t)ESP_PANEL_HOST_DSI_CONFIG_DEFAULT(lane_num, lane_rate)), |
| 24 | + host_handle(NULL), |
| 25 | + io_config((esp_lcd_dbi_io_config_t)ESP_PANEL_IO_DBI_CONFIG_DEFAULT()) |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +ESP_PanelBus_DSI::ESP_PanelBus_DSI(uint32_t lane_rate, uint8_t lane_num, const esp_lcd_dbi_io_config_t &io_config, int ldo_id): |
| 30 | + ESP_PanelBus(ESP_PANEL_HOST_DSI_ID_DEFAULT, ESP_PANEL_BUS_TYPE_MIPI_DSI, true), |
| 31 | + ldo_chan_id(ldo_id), |
| 32 | + ldo_handle(NULL), |
| 33 | + host_config((esp_lcd_dsi_bus_config_t)ESP_PANEL_HOST_DSI_CONFIG_DEFAULT(lane_num, lane_rate)), |
| 34 | + host_handle(NULL), |
| 35 | + io_config(io_config) |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +ESP_PanelBus_DSI::ESP_PanelBus_DSI(const esp_lcd_dsi_bus_config_t &host_config, const esp_lcd_dbi_io_config_t &io_config, int ldo_id): |
| 40 | + ESP_PanelBus(ESP_PANEL_HOST_DSI_ID_DEFAULT, ESP_PANEL_BUS_TYPE_MIPI_DSI, true), |
| 41 | + ldo_chan_id(ldo_id), |
| 42 | + ldo_handle(NULL), |
| 43 | + host_config(host_config), |
| 44 | + host_handle(NULL), |
| 45 | + io_config(io_config) |
| 46 | +{ |
| 47 | +} |
| 48 | + |
| 49 | +ESP_PanelBus_DSI::~ESP_PanelBus_DSI() |
| 50 | +{ |
| 51 | + if (handle == NULL) { |
| 52 | + goto end; |
| 53 | + } |
| 54 | + |
| 55 | + if (!del()) { |
| 56 | + ESP_LOGE(TAG, "Delete panel io failed"); |
| 57 | + } |
| 58 | + |
| 59 | +end: |
| 60 | + ESP_LOGD(TAG, "Destroyed"); |
| 61 | +} |
| 62 | + |
| 63 | +bool ESP_PanelBus_DSI::del(void) |
| 64 | +{ |
| 65 | + ESP_PANEL_ENABLE_TAG_DEBUG_LOG(); |
| 66 | + |
| 67 | + ESP_PANEL_CHECK_FALSE_RET(ESP_PanelBus::del(), false, "Delete base panel failed"); |
| 68 | + if (host_handle != NULL) { |
| 69 | + if (esp_lcd_del_dsi_bus(host_handle) != ESP_OK) { |
| 70 | + ESP_LOGE(TAG, "Delete host_handle[%d] driver failed", host_id); |
| 71 | + } else { |
| 72 | + ESP_LOGD(TAG, "Delete host_handle[%d] driver", host_id); |
| 73 | + } |
| 74 | + host_handle = NULL; |
| 75 | + } |
| 76 | + if (ldo_handle != NULL) { |
| 77 | + if (esp_ldo_release_channel(ldo_handle) != ESP_OK) { |
| 78 | + ESP_LOGE(TAG, "Release LDO channel[%d] failed", ldo_chan_id); |
| 79 | + } else { |
| 80 | + ESP_LOGD(TAG, "MIPI DSI PHY (LDO %d) Powered off", ldo_chan_id); |
| 81 | + } |
| 82 | + ldo_handle = NULL; |
| 83 | + } |
| 84 | + |
| 85 | + return true; |
| 86 | +} |
| 87 | + |
| 88 | +// void ESP_PanelBus_DSI::configSpiMode(uint8_t mode) |
| 89 | +// { |
| 90 | +// io_config.spi_mode = mode; |
| 91 | +// } |
| 92 | + |
| 93 | +bool ESP_PanelBus_DSI::begin(void) |
| 94 | +{ |
| 95 | + ESP_PANEL_ENABLE_TAG_DEBUG_LOG(); |
| 96 | + |
| 97 | + if (ldo_chan_id >= 0) { |
| 98 | + // Turn on the power for MIPI DSI PHY, so it can go from "No Power" state to "Shutdown" state |
| 99 | + esp_ldo_channel_config_t ldo_config = { |
| 100 | + .chan_id = ldo_chan_id, |
| 101 | + .voltage_mv = MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV, |
| 102 | + }; |
| 103 | + ESP_PANEL_CHECK_ERR_RET(esp_ldo_acquire_channel(&ldo_config, &ldo_handle), false, "Acquire LDO channel failed"); |
| 104 | + ESP_LOGD(TAG, "MIPI DSI PHY (LDO %d) Powered on", ldo_chan_id); |
| 105 | + } |
| 106 | + if (host_need_init) { |
| 107 | + ESP_PANEL_CHECK_ERR_RET(esp_lcd_new_dsi_bus(&host_config, &host_handle), false, "Initialize Host[%d] failed", host_id); |
| 108 | + ESP_LOGD(TAG, "Init MIPI DSI host_handle[%d]", host_id); |
| 109 | + } |
| 110 | + ESP_PANEL_CHECK_ERR_RET(esp_lcd_new_panel_io_dbi(host_handle, &io_config, &handle), false, "Create panel io failed"); |
| 111 | + ESP_LOGD(TAG, "Create panel io @%p", handle); |
| 112 | + |
| 113 | + return true; |
| 114 | +} |
| 115 | +#endif /* SOC_MIPI_DSI_SUPPORTED */ |
0 commit comments