tmbsl7113.c
来自「PNX1500上视频采集芯片7113的设置源代码」· C语言 代码 · 共 2,254 行 · 第 1/5 页
C
2,254 行
switch (standard) { case vasNTSC: case vasPAL: SetReg(pVD, ChromaControl, (UInt8) (ucVal | 0x01)); GetReg(pVD, LuminanceControl, &ucVal); SetReg(pVD, LuminanceControl, (UInt8)((ucVal & ~0x03) | 0x01)); // Aperture factor break; case vasSECAM: SetReg(pVD, ChromaControl, (UInt8)(ucVal | 0x50)); GetReg(pVD, LuminanceControl, &ucVal); SetReg(pVD, LuminanceControl, (UInt8)((ucVal & ~0x03) | 0x00)); // Aperture factor GetReg(pVD, ChromaGainControl, &ucVal); SetReg(pVD, ChromaGainControl, (UInt8)((ucVal & ~0x80) | 0x80)); // Set ACGC=1 break; default: return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; } } else return lastI2cError; return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION: tmbsl7113GetStandard://// DESCRIPTION: //// RETURN: tmErrorCode_t for success or error//// NOTES: NONE////-----------------------------------------------------------------------------tmErrorCode_t tmbsl7113GetStandard ( tmUnitSelect_t aviUnit, // I: AVI Unit number tmVideoAnalogStandard_t *std // O: video standard ){#if 0 UInt8 stat; UInt8 chroma; Bool notDetected = True; tmErrorCode_t err = 0; Int32 i, j; UInt8 colorStandard[5] = {0x01, 0x11, 0x21, 0x31, 0x51};#endif UInt8 ucValue, ucStatus; decoderStruct_t* pVD = Null; if( aviUnit >= SAA7113_MAX_UNITS ) { return TMBSL_ERR_AVI_BAD_UNIT_NUMBER; } if( gDecInstance[aviUnit].init != True ) { return TMBSL_ERR_AVI_NOT_INITIALIZED; } pVD = &(gDecInstance[aviUnit]); // Currently we're just checking for PAL BGHI, NTSC-M and SECAM // All other flavours will most likely be interpreted wrongly // First check Frequency - if it's 60Hz then we're assuming NTSC /* HIGH 60Hz, LOW 50Hz */ if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */ return lastI2cError; SetReg(pVD, OutputControl3, (UInt8)(ucValue & ~0x10 | 0x10)); GetReg(pVD, StatusByte, &ucStatus); // If 60Hz - assume to be NTSC if(ucStatus & 0x20) { *std = vasNTSC; } // Otherwise need to do further investigation - PAL/SECAM else { GetReg(pVD, ChromaControl, &ucStatus); // Check what the standard is set up to be // SECAM if(ucStatus&0x70 == 0x05) { // Need to check the color carrier status, if it's ok then // the standard is SECAM, otherwise it's PAL /* HIGH color, LOW no color */ if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */ return lastI2cError; SetReg(pVD, OutputControl3, (UInt8)(ucValue & ~0x10 | 0x10)); GetReg(pVD, StatusByte, &ucStatus); if(ucStatus & 0x01) { *std = vasSECAM; } else { *std = vasPAL; } } // PAL else { // Need to check the color carrier status, if it's ok then // the standard is PAL, otherwise it's SECAM /* HIGH color, LOW no color */ if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */ return lastI2cError; SetReg(pVD, OutputControl3, (UInt8)(ucValue & ~0x10 | 0x10)); GetReg(pVD, StatusByte, &ucStatus); if(ucStatus & 0x01) { *std = vasPAL; } else { *std = vasSECAM; } } }#if 0 microsleep(40000); // This stupid routine need to sleep a lot. for (j = 0; ( (j<2) && notDetected ); j++) { for ( *std = vasNone, i = 0; ( (i<5) && notDetected); i++) { err = SetReg ( pVD, ChromaControl, colorStandard[i]); if (!err) { return (err); } microsleep(100000); err = GetReg( pVD, ChromaControl, &chroma); err = GetReg( pVD, StatusByte, &stat); if (!err) { return (err); } if (stat & A_HLCK) { microsleep(500000); // not in sync err, give it a long nap } if (stat & A_CODE) { // color videoStandard detected if (stat & A_FIDT) { // 60 Hz switch (i) { case 0: // NTSC M *std = vasNTSC; break; case 1: // PAL 4.43 *std = vasPAL; break; case 2: // NTSC 4.43 *std = vasNTSC; break; case 3: // NTSC N *std = vasNTSC; break; case 4: // PAL 4.43 *std = vasPAL; break; default: *std = vasNone; // should not come here break; } // end of switch } else { // 50Hz switch (i) { case 0: // PAL BGHI *std = vasPAL; break; case 1: // NTSC 4.43 *std = vasNTSC; break; case 2: // PAL N *std = vasPAL; break; case 3: // PAL M *std = vasPAL; break; case 4: // SECAM *std = vasSECAM; break; default: *std = vasNone; // should not come here break; } // end of switch } notDetected = False; } } // end of i for loop } // end of j for loop if (stat & A_HLCK) { // not in sync err, message may be obscure return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; } if (notDetected) { return TMBSL_ERR_AVI_CLR_STD_NOT_DETECTED; } // Store detected standard in internal variable pVD->curVideoStandard = *std;#endif return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION: tmbsl7113SetVideoColor://// DESCRIPTION: Set video color (brightness,contrast, saturation, hue)//// RETURN: tmErrorCode_t for success or error//// NOTES: NONE////-----------------------------------------------------------------------------tmErrorCode_t tmbsl7113SetVideoColor ( tmUnitSelect_t aviUnit, // I: AVI Unit number tmVideoColor_t color, // I: specifies the color type UInt32 val) // I: new value{ UInt8 ucVal; decoderStruct_t* pVD = Null; if( aviUnit >= SAA7113_MAX_UNITS ) { return TMBSL_ERR_AVI_BAD_UNIT_NUMBER; } if( gDecInstance[aviUnit].init != True ) { return TMBSL_ERR_AVI_NOT_INITIALIZED; } pVD = &(gDecInstance[aviUnit]); switch (color) { case vctBrightness: if (val > 255) return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; else { /* Check only first access */ if (!SetReg(pVD, LuminanceBrightness, (UInt8)val)) return lastI2cError; } break; case vctContrast: if (val > 127) return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; else { /* Check only first access */ if (!SetReg(pVD, LuminanceContrast, (UInt8)val)) return lastI2cError; } break; case vctSaturation: if (val > 127) return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; else { /* Check only first access */ if (!SetReg(pVD, ChromaSaturation, (UInt8)val)) return lastI2cError; } break; case vctHue: if (val > 255) return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; else { /* Check only first access */ if (!SetReg(pVD, ChromaHueControl, (UInt8)val)) return lastI2cError; } break; case vctSharpness: if (val > 3) return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; else { /* Check only first access */ if (!GetReg(pVD, LuminanceControl, &ucVal)) return lastI2cError; SetReg(pVD, LuminanceControl, (UInt8)(ucVal & ~0x03 | (val & 0x03))); } break; default: return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; } return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION: tmbsl7113GetVideoColor://// DESCRIPTION: Get current video color (brightness,contrast, saturation, hue)//// RETURN: tmErrorCode_t for success or error//// NOTES: NONE////-----------------------------------------------------------------------------tmErrorCode_t tmbsl7113GetVideoColor ( tmUnitSelect_t aviUnit, // I: AVI Unit number tmVideoColor_t color, // I: specifies the color type UInt32 *pVal // O: receives current value ){ /* No equivalent in Video DecHAL */ UInt8 ucVal; UInt8 ucMask; UInt8 subAddr; decoderStruct_t* pVD = Null; if( aviUnit >= SAA7113_MAX_UNITS ) { return TMBSL_ERR_AVI_BAD_UNIT_NUMBER; } if( gDecInstance[aviUnit].init != True ) { return TMBSL_ERR_AVI_NOT_INITIALIZED; } pVD = &(gDecInstance[aviUnit]); switch (color) { case vctBrightness: subAddr = LuminanceBrightness; ucMask = 0xFF; break; case vctContrast: subAddr = LuminanceContrast; ucMask = 0x7F; break; case vctSaturation: ucMask = 0x7F; subAddr = ChromaSaturation; break; case vctHue: subAddr = ChromaHueControl; ucMask = 0xFF; break; case vctSharpness: subAddr = LuminanceControl; ucMask = 0x03; break; default: return TMBSL_ERR_AVI_VAL_OUT_OF_RANGE; } if (!GetReg (pVD, subAddr, &ucVal)) return lastI2cError; *pVal = ucVal & ucMask; return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION: tmbsl7113SetAnalogInput://// DESCRIPTION: Set input port out of retrieved input array //// RETURN: tmErrorCode_t for success or error//// NOTES: NONE////-----------------------------------------------------------------------------tmErrorCode_t tmbsl7113SetAnalogInput ( tmUnitSelect_t aviUnit, // I: AVI Unit number tmVideoAnalogAdapter_t adapter, // I: type (CVBS,SVideo,...) UInt32 adapterIndex // I: index of this type ){ UInt8 ucVal; UInt8 inputMode; decoderStruct_t* pVD = Null; if( aviUnit >= SAA7113_MAX_UNITS ) { return TMBSL_ERR_AVI_BAD_UNIT_NUMBER; } if( gDecInstance[aviUnit].init != True ) { return TMBSL_ERR_AVI_NOT_INITIALIZED; } pVD = &(gDecInstance[aviUnit]); // Map the adapter's instance to a valid mode if (mapAdapterInput (pVD, adapter, adapterIndex, &inputMode) != TM_OK)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?