Usage Guidelines
- How to Use
- Obtaining a MIPI DSI Device Handle
- Setting MIPI DSI Configuration Parameters
- Sending/Receiving the Pointer to a Command
- Releasing the MIPI DSI Device Handle
How to Use
Figure 1 shows the process of using a MIPI DSI device.
Figure 1 Process of using a MIPI DSI device
Obtaining a MIPI DSI Device Handle
Before performing MIPI DSI communication, obtain a MIPI DSI device handle by calling MipiDsiOpen. This function returns a MIPI DSI device handle with a specified channel ID.
DevHandle MipiDsiOpen(uint8_t id);
Table 1 Description of MipiDsiOpen
MIPI DSI device handle with a specified channel ID, whose data type is DevHandle. |
The following example shows how to obtain a MIPI DSI device handle with the channel ID 0:
DevHandle mipiDsiHandle = NULL; /* Device handle */
chnId = 0; /* MIPI DSI channel ID */
/* Obtain the MIPI DSI device handle based on a specified channel ID. */
mipiDsiHandle = MipiDsiOpen(chnId);
if (mipiDsiHandle == NULL) {
HDF_LOGE("MipiDsiOpen: failed\n");
return;
}
Setting MIPI DSI Configuration Parameters
- Set MIPI DSI configuration parameters by calling the following function:
int32_t MipiDsiSetCfg(DevHandle handle, struct MipiCfg *cfg);
Table 2 Description of MipiDsiSetCfg
int32_t ret;
struct MipiCfg cfg = {0};
/* Configuration parameters of the connected device are as follows: */
cfg.lane = DSI_4_LANES;
cfg.mode = DSI_CMD_MODE;
cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS;
cfg.format = FORMAT_RGB_24_BIT;
cfg.pixelClk = 174;
cfg.phyDataRate = 384;
cfg.timingInfo.hsaPixels = 50;
cfg.timingInfo.hbpPixels = 55;
cfg.timingInfo.hlinePixels = 1200;
cfg.timingInfo.yResLines = 1800;
cfg.timingInfo.vbpLines = 33;
cfg.timingInfo.vsaLines = 76;
cfg.timingInfo.vfpLines = 120;
cfg.timingInfo.xResPixels = 1342;
/* Set MIPI DSI configuration parameters. */
ret = MipiDsiSetCfg(g_handle, &cfg);
if (ret != 0) {
HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret);
return -1;
}
- Obtain MIPI DSI configuration parameters by calling the following function:
int32_t MipiDsiGetCfg(DevHandle handle, struct MipiCfg *cfg);
Table 3 Description of MipiDsiGetCfg
int32_t ret;
struct MipiCfg cfg;
memset(&cfg, 0, sizeof(struct MipiCfg));
ret = MipiDsiGetCfg(g_handle, &cfg);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: GetMipiCfg fail!\n", __func__);
return HDF_FAILURE;
}
Sending/Receiving the Pointer to a Command
- Send the pointer to a specified command by calling the following function:
int32_t MipiDsiTx(PalHandle handle, struct DsiCmdDesc *cmd);
Table 4 Description of MipiDsiTx
int32_t ret;
struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc));
if (cmd == NULL) {
return HDF_FAILURE;
}
cmd->dtype = DTYPE_DCS_WRITE;
cmd->dlen = 1;
cmd->payload = OsalMemCalloc(sizeof(uint8_t));
if (cmd->payload == NULL) {
HdfFree(cmd);
return HDF_FAILURE;
}
*(cmd->payload) = DTYPE_GEN_LWRITE;
MipiDsiSetLpMode(mipiHandle);
ret = MipiDsiTx(mipiHandle, cmd);
MipiDsiSetHsMode(mipiHandle);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: PalMipiDsiTx fail! ret=%d\n", __func__, ret);
HdfFree(cmd->payload);
HdfFree(cmd);
return HDF_FAILURE;
}
HdfFree(cmd->payload);
HdfFree(cmd);
- Receive a specified command by calling the following function:
int32_t MipiDsiRx(DevHandle handle, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out);
Table 5 Description of MipiDsiRx
int32_t ret;
uint8_t readVal = 0;
struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc));
if (cmdRead == NULL) {
return HDF_FAILURE;
}
cmdRead->dtype = DTYPE_DCS_READ;
cmdRead->dlen = 1;
cmdRead->payload = OsalMemCalloc(sizeof(uint8_t));
if (cmdRead->payload == NULL) {
HdfFree(cmdRead);
return HDF_FAILURE;
}
*(cmdRead->payload) = DDIC_REG_STATUS;
MipiDsiSetLpMode(g_handle);
ret = MipiDsiRx(g_handle, cmdRead, sizeof(readVal), &readVal);
MipiDsiSetHsMode(g_handle);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret);
HdfFree(cmdRead->payload);
HdfFree(cmdRead);
return HDF_FAILURE;
}
HdfFree(cmdRead->payload);
HdfFree(cmdRead);
Releasing the MIPI DSI Device Handle
After the MIPI DSI communication, release the MIPI DSI device handle by calling the following function:
void MipiDsiClose(DevHandle handle);
This function releases the resources requested by MipiDsiOpen.
Table 6 Description of MipiDsiClose
MipiDsiClose(mipiHandle); /* Release the MIPI DSI device handle */