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 /* 49 * 比特常量 50 * Bit constant 51 */ 52 #define HI_BIT0 0x01U 53 #define HI_BIT1 0x02U 54 #define HI_BIT2 0x04U 55 #define HI_BIT3 0x08U 56 #define HI_BIT4 0x10U 57 #define HI_BIT5 0x20U 58 #define HI_BIT6 0x40U 59 #define HI_BIT7 0x80U 60 #define HI_BIT8 0x0100U 61 #define HI_BIT9 0x0200U 62 #define HI_BIT10 0x0400U 63 #define HI_BIT11 0x0800U 64 #define HI_BIT12 0x1000U 65 #define HI_BIT13 0x2000U 66 #define HI_BIT14 0x4000U 67 #define HI_BIT15 0x8000U 68 69 /* 70 * 标记组件,该组件是否启用 71 * Flags to mark whether the component is enabled 72 */ 73 #define MPP_VI HI_BIT0 74 #define MPP_VDEC HI_BIT1 75 #define MPP_VPSS HI_BIT2 76 #define MPP_VENC HI_BIT3 77 #define MPP_VO HI_BIT5 78 79 typedef struct SampleVoModeMux { 80 HI_U32 u32WndNum; 81 HI_U32 u32Square; 82 HI_U32 u32Row; 83 HI_U32 u32Col; 84 } SampleVoModeMux; 85 86 typedef SAMPLE_VI_CONFIG_S ViCfg; 87 typedef SAMPLE_VO_CONFIG_S VoCfg; 88 typedef VB_CONFIG_S VbCfg; 89 90 /* 91 * VPSS通道配置,用来设置一个通道的属性 92 * VPSS channel config. Used to set the attributes of a channel. 93 */ 94 typedef struct VpssChnCfg { 95 int id; // VpssChn ID 96 VPSS_CHN_ATTR_S attr; // VpssChn attributes 97 } VpssChnCfg; 98 99 /* 100 * VPSS配置.每个VpssCfg对应1个VPSS组和1个或多个VPSS通道 101 * VPSS config. Each VpssCfg corresponds to 1 VPSS group and 1 or more VPSS channels. 102 */ 103 typedef struct VpssCfg { 104 VPSS_GRP grpId; // VpssGrp ID 105 VPSS_GRP_ATTR_S grpAttr; // VpssGrp attributes 106 107 int chnNum; // Configure the number of chnnels used 108 VpssChnCfg chnCfgs[VPSS_MAX_PHY_CHN_NUM]; // pssChnCfg array, the first chnNum-1 elements are valid 109 } VpssCfg; 110 111 /* 112 * MppSess集合. 113 * MppSess对应的create()函数会将需要的cfg值复制到对象中,并启动session 114 * MppSess未提供构造函数,user只能通过create()函数创建对象,并用MppSess_destroy()销毁对象 115 * MppSess中定义了当前MppSess使用的资源ID,viCfg, vpssCfg, vpssGrp, vpssChn0, vpssChn1, 116 * 这些值由create()设置,used未标识的组件的对应ID会被置为-1.这些资源ID从create()传入的 117 * 参数xxxCfg中获取,复制到对象中可简化APP使用 118 * 目前没有定义VI的channel ID,其总是会与VPSS绑定后使用,通过VPSS chn即可获得VI的数据 119 * 120 * MppSess collection. 121 * The create() function corresponding to MppSess will copy the required cfg value to the object and start the session. 122 * MppSess does not provide a constructor. The user can only create an object through the create() function 123 * and destroy the object with MppSess_destroy(). 124 * MppSess defines the resource ID, viCfg, vpssCfg, vpssGrp, vpssChn0, vpssChn1 currently used by MppSess. 125 * These values are set by create(), and the corresponding IDs of components not identified by used will be set to -1. 126 * These resource IDs are obtained from the parameter xxxCfg passed in by create() 127 * and copied to the object to simplify APP use. 128 * There is currently no defined channel ID of the VI, it will always be used after being bound to the VPSS, 129 * and the VI data can be obtained through the VPSS chn. 130 */ 131 typedef struct MppSess { 132 uint32_t used; // The set of enabled components, set by the create() function 133 134 ViCfg viCfg; // Optional ViCfg 135 VpssCfg vpssCfg; // Optional VpssCfg 136 137 VPSS_GRP vpssGrp; // VPSS group ID, -1 means that the corresponding MPP component is not started. 138 VPSS_CHN vpssChn0; // VPSS channel[0] ID, -1 means that the corresponding MPP component is not started. 139 VPSS_CHN vpssChn1; // VPSS channel[1] ID, -1 means that the corresponding MPP component is not started. 140 } MppSess; 141 142 typedef struct LcdMediaInfo { 143 VPSS_GRP vpssGrp; 144 VPSS_CHN vpssChn0; 145 VPSS_CHN vpssChn1; 146 VDEC_CHN vdecChn; 147 VENC_CHN vencChn; 148 149 ViCfg viCfg; 150 VpssCfg vpssCfg; 151 VoCfg voCfg; 152 VbCfg vbCfg; 153 154 // MppSess 155 MppSess *viSess; // VI(sensor)+VPSS 156 int vpssFd; 157 SIZE_S stSize; 158 PIC_SIZE_E enPicSize; 159 HI_U32 u32BlkSize; 160 } LcdMediaInfo; 161 162 /* 163 * 初始化VI配置 164 * Init ViCfg 165 */ 166 void ViCfgInit(ViCfg* self); 167 168 /* 169 * 初始化VPSS配置 170 * Init VpssCfg 171 */ 172 void VpssCfgInit(VpssCfg* self); 173 174 /* 175 * 设置VPSS组 176 * Set up VPSS Group 177 */ 178 void VpssCfgSetGrp(VpssCfg* self, 179 int grpId, const VPSS_GRP_ATTR_S* grpAttr, int maxWidth, int maxHeight); 180 181 /* 182 * 增加一个VPSS通道 183 * Add a VPSS channel 184 */ 185 VPSS_CHN_ATTR_S* VpssCfgAddChn(VpssCfg* self, 186 int chnId, const VPSS_CHN_ATTR_S* chnAttr, int width, int height); 187 188 /* 189 * 设置VI设备信息 190 * Set VI DEV information 191 */ 192 void ViCfgSetDev(ViCfg* self, int devId, WDR_MODE_E wdrMode); 193 194 /* 195 * 设置VI的PIPE信息 196 * Set the PIPE information of the VI 197 */ 198 void ViCfgSetPipe(ViCfg* self, int pipe0Id, int pipe1Id, int pipe2Id, int pipe3Id); 199 200 /* 201 * 设置VI通道 202 * Set up the VI channel 203 */ 204 void ViCfgSetChn(ViCfg* self, int chnId, PIXEL_FORMAT_E pixFormat, 205 VIDEO_FORMAT_E videoFormat, DYNAMIC_RANGE_E dynamicRange); 206 207 /* 208 * 创建并启动{VI->VPSS}MppSess 209 * Create and start {VI->VPSS}MppSess 210 */ 211 int ViVpssCreate(MppSess** sess, const ViCfg* viCfg, const VpssCfg* vpssCfg); 212 213 /* 214 * 停止使用VpssCfg启动的VPSS 215 * Terminate VPSS started with VpssCfg 216 */ 217 int VpssStop(const VpssCfg* cfg); 218 219 /* 220 * 终止使用ViCfg启动的VI 221 * Terminate VI started with ViCfg 222 */ 223 int ViStop(const ViCfg* viCfg); 224 225 int SampleVioVpssVoMipi(void); 226 227 #ifdef __cplusplus 228 #if __cplusplus 229 } 230 #endif 231 #endif /* End of #ifdef __cplusplus */ 232 233 #endif /* End of #ifndef SAMPLE_LCD_H */ 234