📄 hal_jpeg.c
字号:
unsigned short fifoControl = halReadReg16( REG09A0_JPEG_FIFO_CTRL );
fifoControl &= ~0x0030;
fifoControl |= (unsigned short)(fifoThrsh << 4);
halWriteReg16( REG09A0_JPEG_FIFO_CTRL, fifoControl );
}
/*************************************************************************************
; Function: get FIFO threshold select
; Input: n/a
; Output: JpegFifoThrsh
; Format: JpegFifoThrsh JpegFifoThrshSelGet( void )
;*************************************************************************************/
JpegFifoThrsh JpegFifoThrshSelGet( void )
{
unsigned short fifoControl = halReadReg16( REG09A0_JPEG_FIFO_CTRL );
JpegFifoThrsh fifoThrsh = (JpegFifoThrsh)((fifoControl >> 4) & 0x0003);
return ( fifoThrsh );
}
/*************************************************************************************
; Function: get FIFO direction status
; Input: n/a
; Output: TRUE means transmit (decoding direction)
; FALSE means receive (encoding direction)
; Format: BOOL JpegFifoDirectionXmitGet( void )
;*************************************************************************************/
BOOL JpegFifoDirectionGet( void )
{
unsigned short fifoControl = halReadReg16( REG09A0_JPEG_FIFO_CTRL );
BOOL fifoDirectionXmit = (BOOL)((fifoControl >> 1) & TRUE);
return ( fifoDirectionXmit );
}
/*************************************************************************************
; Function: get FIFO Buffer Empty status
; Input: n/a
; Output: TRUE if Fifo Buffer empty
; FALSE if Fifo Buffer not empty
; Format: BOOL JpegFifoBufEmptyGet( void )
;*************************************************************************************/
BOOL JpegFifoBufEmptyGet( void )
{
unsigned short fifoControl = halReadReg16( REG09A2_JPEG_FIFO_STATUS );
BOOL fifoBufEmpty = (BOOL)(fifoControl & TRUE);
return ( fifoBufEmpty );
}
/*************************************************************************************
; Function: get FIFO Buffer Full status
; Input: n/a
; Output: TRUE if Fifo Buffer full
; FALSE if Fifo Buffer not full
; Format: BOOL JpegFifoBufFullGet( void )
*************************************************************************************/
BOOL JpegFifoBufFullGet( void )
{
unsigned short fifoControl = halReadReg16( REG09A2_JPEG_FIFO_STATUS );
BOOL fifoBufFull = (BOOL)((fifoControl >> 1 ) & TRUE);
return ( fifoBufFull );
}
/*************************************************************************************
; Function: get FIFO threshold status
; Input: n/a
; Output: JpegFifoThrsh
; Format: JpegFifoThrsh JpegFifoThrshStatusGet( void )
;*************************************************************************************/
JpegFifoThrsh JpegFifoThrshStatusGet( void )
{
unsigned short fifoControl = halReadReg16( REG09A2_JPEG_FIFO_STATUS );
JpegFifoThrsh fifoThrsh = (JpegFifoThrsh)((fifoControl >> 2) & 0x0003);
return ( fifoThrsh );
}
/*************************************************************************************
; Function: Sets Fifo Size
; Fifo Size = (FifoSize + 1) * 4 KByte
; MIN : 4KByte, MAX : 128 KByte
; Input: fifoSize as zero-based blocks of 4K
; Output: n/a
; Format: void JpegFifoSizeSet( unsigned char fifoSize )
;*************************************************************************************/
void JpegFifoSizeSet( unsigned char fifoSize )
{
halWriteReg16( REG09A4_JPEG_FIFO_SIZE, (unsigned short)(fifoSize & 0x000F) );
}
/*************************************************************************************
; Function: Gets Fifo Size
; MIN : 4KByte
; MAX : 128 KByte
; Input: n/a
; Output: FifoSize as zero-based blocks of 4K
; Format: unsigned char JpegFifoSizeGet( void )
;*************************************************************************************/
unsigned char JpegFifoSizeGet( void )
{
unsigned short fifoSize = halReadReg16( REG09A4_JPEG_FIFO_SIZE );
return ( (unsigned char)fifoSize );
}
/*************************************************************************************
; Function: get FIFO valid data size
; Input: n/a
; Output: fifoValidDataSize
; Format: unsigned long JpegFifoValidDataSizeGet( void )
;*************************************************************************************/
unsigned long JpegFifoValidDataSizeGet( void )
{
unsigned long fifoValidDataSize = (unsigned long)halReadReg16( REG09A8_JPEG_FIFO_VALIDDATASIZE );
fifoValidDataSize *= 4;
return ( fifoValidDataSize );
}
/*************************************************************************************
; Function: get FIFO read pointer
; Input: n/a
; Output: FIFO Read Pointer
; Format: unsigned char * JpegFifoRdPointerGet( void )
;*************************************************************************************/
unsigned char * JpegFifoRdPointerGet( void )
{
unsigned short fifoRdPointer = halReadReg16( REG09AA_JPEG_FIFO_RD_POINTER );
unsigned char* pRd = (unsigned char*)(fifoRdPointer * 4);
return ( pRd );
}
/*************************************************************************************
; Function: get FIFO write pointer
; Input: n/a
; Output: write pointer
; Format: unsigned char* JpegFifoWrPointerGet( void )
;*************************************************************************************/
unsigned char* JpegFifoWrPointerGet( void )
{
unsigned short fifoWrPointer = halReadReg16( REG09AC_JPEG_FIFO_WR_POINTER );
unsigned char* pWrite = (unsigned char*)(fifoWrPointer * 4);
return ( pWrite );
}
/*************************************************************************************
; Function: Sets Encd Size Limit
; Input: encSizeLimit
; Output: n/a
; Format: void JpegEncSizeLimitSet( unsigned long encSizeLimit )
;*************************************************************************************/
void JpegEncSizeLimitSet( unsigned long encSizeLimit )
{
unsigned short lsw = (unsigned short)(encSizeLimit & 0x0000FFFF);
unsigned short msw = (unsigned short)((encSizeLimit & 0x00FF0000) >> 16);
halWriteReg16( REG09B0_ENCODE_SIZE_LIMIT0, lsw );
halWriteReg16( REG09B2_ENCODE_SIZE_LIMIT1, msw );
}
/*************************************************************************************
; Function: Sets Encd Size Limit
; Input: n/a
; Output: EncSizeLimit
; Format: unsigned long JpegEncSizeLimitGet( void )
;*************************************************************************************/
unsigned long JpegEncSizeLimitGet( void )
{
unsigned long lsw = halReadReg16( REG09B0_ENCODE_SIZE_LIMIT0 );
unsigned long msw = halReadReg16( REG09B2_ENCODE_SIZE_LIMIT1 );
unsigned long encSizeLimit = (unsigned long)((msw << 16) | lsw);
return ( encSizeLimit );
}
/*************************************************************************************
; Function: returns Encode Size
; Input: n/a
; Output: size of Encoded data
; Format: unsigned long JpegEncSizeResultGet( void )
;*************************************************************************************/
unsigned long JpegEncSizeResultGet( void )
{
unsigned short lsw = halReadReg16( REG09B4_ENCODE_SIZE_RESULT0 );
unsigned short msw = halReadReg16( REG09B6_ENCODE_SIZE_RESULT1 );
unsigned long encSizeResult = (msw << 16) | lsw;
return ( encSizeResult );
}
/*************************************************************************************
; Function: sets size of Jpeg file
; Input: fileSize size of Jpeg File in bytes
; Output: n/a
; Format: void JpegFileSizeSet( unsigned long fileSize )
;*************************************************************************************/
void JpegFileSizeSet( unsigned long fileSize )
{
unsigned short lsw = (unsigned short)(fileSize & 0x0000FF);
unsigned short msw = (unsigned short)((fileSize & 0x00FF0000) >> 16);
halWriteReg16( REG09B8_JPEG_FILE_SIZE0, lsw );
halWriteReg16( REG09BA_JPEG_FILE_SIZE1, msw );
}
/*************************************************************************************
; Function: sets size of Jpeg file
; Input: JpegFileSize size of Jpeg File in bytes
; Output: TRUE if size is valid
; FALSE if size is NOT valid
; Format: unsigned long JpegFileSizeGet( void )
;*************************************************************************************/
unsigned long JpegFileSizeGet( void )
{
unsigned short lsw = halReadReg16( REG09B8_JPEG_FILE_SIZE0 );
unsigned short msw = halReadReg16( REG09BA_JPEG_FILE_SIZE1 );
unsigned long fileSize = (unsigned long)((msw << 16) + lsw);
return ( fileSize );
}
/*************************************************************************************
; Function: get JPEG line buffer empty status
; Input: n/a
; Output: TRUE if line Buffer is empty
; FALSE if line Buffer is NOT empty
; Format: BOOL JpegLnBufEmptyStatusGet( void )
;*************************************************************************************/
BOOL JpegLnBufEmptyStatusGet( void )
{
unsigned short lineBufStatus = halReadReg16( REG09C0_JPEG_LBUF_STATUS );
BOOL empty = (BOOL)(lineBufStatus & TRUE);
return ( empty );
}
/*************************************************************************************
; Function: get JPEg line buffer full status
; Input: n/a
; Output: TRUE if line Buffer is full
; FALSE if line Buffer is NOT full
; Format: BOOL JpegLnBufFullStatusGet( void )
;*************************************************************************************/
BOOL JpegLnBufFullStatusGet( void )
{
unsigned short lineBufStatus = halReadReg16( REG09C0_JPEG_LBUF_STATUS );
BOOL full = (BOOL)((lineBufStatus >> 1 ) & TRUE);
return ( full );
}
/*************************************************************************************
; Function: Retrieves current content of FIFO from current position into system memory buffer
; Input: ppCurrent pointer to pointer current position in encoded data buffer
; bufferSize size of system buffer to fill
; pEncodedSize pointer to size of encoded data so far
; Output: TRUE if FIFO successfully drained
; FALSE if FIFO NOT successfully drained
; Format: BOOL JpegDrainFifo( unsigned short * ppCurrent, unsigned long bufferSize, JENCODEINFO* pJEncodeInfo )
;*************************************************************************************/
BOOL JpegDrainFifo( unsigned short ** ppCurrent, unsigned long bufferSize, JENCODEINFO* pJEncodeInfo )
{
unsigned short jpegFifoValidDataSize = halReadReg16( REG09A8_JPEG_FIFO_VALIDDATASIZE );
unsigned long dataSize = jpegFifoValidDataSize * 4;
unsigned short i;
unsigned short * pCurrent = *ppCurrent;
unsigned long startSize = pJEncodeInfo->EncodedSize;
// Determine how much data is to be read
pJEncodeInfo->EncodedSize += dataSize;
// Only process if there is FIFO data to get
if ( jpegFifoValidDataSize > 0 )
{
if ( pJEncodeInfo->EncodedSize > bufferSize )
{
JpegEncodeSetLastError( JENCODE_ERR_ENCSIZELIMIT );
return ( FALSE );
}
// Read each entry in FIFO
for ( i = 0; i < jpegFifoValidDataSize; i++ )
{
long j;
for ( j = 0; j < 2; ++j )
{
*pCurrent = halReadReg16( REG09A6_JPEG_FIFO_RDWR );
++pCurrent;
}
}
}
// Return where next point to save data after having read all current contents of FIFO
*ppCurrent = pCurrent;
// If this is our first time through on this capture
if ( startSize == 0 )
{
// If we are not getting JPEG then we must be in capture
if ( JpegOpModeGet() != JpegEncodeDecode )
{
// Finish capture at end of next frame (according to 0x098A HW spec)
JpegCodeStartCtlSet( FALSE, pJEncodeInfo );
}
}
return ( TRUE );
}
/************************************************************************
; JpegEncodeGetLastError() - return last JPEG encode error code.
;************************************************************************/
long JpegEncodeGetLastError( void )
{
return ( g_LastError );
}
/************************************************************************
; JpegEncodeSetLastError() - return last JPEG encode error code.
;************************************************************************/
void JpegEncodeSetLastError( long lastError )
{
g_LastError = lastError;
}
/************************************************************************
; JpegDecodeGetLastError() - Get last error code.
;************************************************************************/
long JpegDecodeGetLastError( void )
{
return ( g_LastError);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -