1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SAMPLE_LCD_H 17 #define SAMPLE_LCD_H 18 19 #include <stdint.h> 20 #include "sample_comm.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif /* End of #ifdef __cplusplus */ 27 28 #ifndef SAMPLE_PRT 29 #define SAMPLE_PRT(fmt...) \ 30 do { \ 31 printf("[%s]-%d: ", __FUNCTION__, __LINE__); \ 32 printf(fmt); \ 33 } while (0) 34 #endif 35 36 #define APIPE0 0 37 #define APIPE1 1 38 #define APIPE2 2 39 #define APIPE3 3 40 41 #define AIC_VPSS_GRP 0 // default use VPSS group 42 #define AIC_VPSS_ZIN_CHN 0 // default use VPSS amplification channel 43 #define AIC_VPSS_ZOUT_CHN 1 // default use VPSS narrowing channel 44 45 #define AICSTART_VI_OUTWIDTH 1920 46 #define AICSTART_VI_OUTHEIGHT 1080 47 48 /* bit constant */ 49 #define HI_BIT0 0x01U 50 #define HI_BIT1 0x02U 51 #define HI_BIT2 0x04U 52 #define HI_BIT3 0x08U 53 #define HI_BIT4 0x10U 54 #define HI_BIT5 0x20U 55 #define HI_BIT6 0x40U 56 #define HI_BIT7 0x80U 57 #define HI_BIT8 0x0100U 58 #define HI_BIT9 0x0200U 59 #define HI_BIT10 0x0400U 60 #define HI_BIT11 0x0800U 61 #define HI_BIT12 0x1000U 62 #define HI_BIT13 0x2000U 63 #define HI_BIT14 0x4000U 64 #define HI_BIT15 0x8000U 65 66 /* Flags to mark whether the component is enabled */ 67 #define MPP_VI HI_BIT0 68 #define MPP_VDEC HI_BIT1 69 #define MPP_VPSS HI_BIT2 70 #define MPP_VENC HI_BIT3 71 #define MPP_VO HI_BIT5 72 73 typedef struct SampleVoModeMux { 74 HI_U32 u32WndNum; 75 HI_U32 u32Square; 76 HI_U32 u32Row; 77 HI_U32 u32Col; 78 } SampleVoModeMux; 79 80 typedef SAMPLE_VI_CONFIG_S ViCfg; 81 typedef SAMPLE_VO_CONFIG_S VoCfg; 82 typedef VB_CONFIG_S VbCfg; 83 84 /* 85 * VPSS channel config. 86 * Used to set the attributes of a channel. 87 */ 88 typedef struct VpssChnCfg { 89 int id; // VpssChn ID 90 VPSS_CHN_ATTR_S attr; // VpssChn attributes 91 } VpssChnCfg; 92 93 /* 94 * VPSS config. 95 * Each VpssCfg corresponds to 1 VPSS group and 1 or more VPSS channels. 96 */ 97 typedef struct VpssCfg { 98 VPSS_GRP grpId; // VpssGrp ID 99 VPSS_GRP_ATTR_S grpAttr; // VpssGrp attributes 100 101 int chnNum; // Configure the number of chnnels used 102 VpssChnCfg chnCfgs[VPSS_MAX_PHY_CHN_NUM]; // pssChnCfg array, the first chnNum-1 elements are valid 103 } VpssCfg; 104 105 /* 106 * MppSess superset. 107 * The create() function corresponding to MppSess will copy the required cfg value to the object and start the session. 108 * MppSess does not provide a constructor. The user can only create an object through the create() function 109 * and destroy the object with MppSess_destroy(). 110 * MppSess defines the resource ID, vpssGrp, vpssChn0, vpssChn1, vdecChn, vencChn currently used by MppSess. 111 * These values are set by create(), and the corresponding IDs of components not identified by used will be set to -1. 112 * These resource IDs are obtained from the parameter xxxCfg passed in by create() 113 * and copied to the object to simplify APP use. 114 * There is currently no defined channel ID of the VI, it will always be used after being bound to the VPSS, 115 * and the VI data can be obtained through the VPSS chn. 116 */ 117 typedef struct MppSess { 118 uint32_t used; // The set of enabled components, set by the create() function 119 120 ViCfg viCfg; // Optional ViCfg 121 VpssCfg vpssCfg; // Optional VpssCfg 122 123 VPSS_GRP vpssGrp; // VPSS group ID, -1 means that the corresponding MPP component is not started. 124 VPSS_CHN vpssChn0; // VPSS channel[0] ID, -1 means that the corresponding MPP component is not started. 125 VPSS_CHN vpssChn1; // VPSS channel[1] ID, -1 means that the corresponding MPP component is not started. 126 } MppSess; 127 128 typedef struct LcdMediaInfo { 129 VPSS_GRP vpssGrp; 130 VPSS_CHN vpssChn0; 131 VPSS_CHN vpssChn1; 132 VDEC_CHN vdecChn; 133 VENC_CHN vencChn; 134 135 ViCfg viCfg; 136 VpssCfg vpssCfg; 137 VoCfg voCfg; 138 VbCfg vbCfg; 139 140 // MppSess 141 MppSess *viSess; // VI(sensor)+VPSS 142 int vpssFd; 143 SIZE_S stSize; 144 PIC_SIZE_E enPicSize; 145 HI_U32 u32BlkSize; 146 } LcdMediaInfo; 147 148 /* init ViCfg */ 149 void ViCfgInit(ViCfg* self); 150 151 /* Initialize VpssCfg */ 152 void VpssCfgInit(VpssCfg* self); 153 154 /* Set up VPSS Group */ 155 void VpssCfgSetGrp(VpssCfg* self, 156 int grpId, const VPSS_GRP_ATTR_S* grpAttr, int maxWidth, int maxHeight); 157 158 /* Add a VPSS channel */ 159 VPSS_CHN_ATTR_S* VpssCfgAddChn(VpssCfg* self, 160 int chnId, const VPSS_CHN_ATTR_S* chnAttr, int width, int height); 161 162 /* Set VI DEV information */ 163 void ViCfgSetDev(ViCfg* self, int devId, WDR_MODE_E wdrMode); 164 165 /* Set the PIPE information of the VI */ 166 void ViCfgSetPipe(ViCfg* self, int pipe0Id, int pipe1Id, int pipe2Id, int pipe3Id); 167 168 /* Set up the VI channel */ 169 void ViCfgSetChn(ViCfg* self, int chnId, PIXEL_FORMAT_E pixFormat, 170 VIDEO_FORMAT_E videoFormat, DYNAMIC_RANGE_E dynamicRange); 171 172 /* Create and start {VI->VPSS}MppSess */ 173 int ViVpssCreate(MppSess** sess, const ViCfg* viCfg, const VpssCfg* vpssCfg); 174 175 /* Terminate VPSS started with VpssCfg */ 176 int VpssStop(const VpssCfg* cfg); 177 178 /* Terminate VIs started with ViCfg */ 179 int ViStop(const ViCfg* viCfg); 180 181 int SampleVioVpssVoMipi(void); 182 183 #ifdef __cplusplus 184 #if __cplusplus 185 } 186 #endif 187 #endif /* End of #ifdef __cplusplus */ 188 189 #endif /* End of #ifndef SAMPLE_LCD_H */ 190