📄 caminterface.c
字号:
/***********************************************************
Module Name: CamInterface.c
Module Date: 04/12/2004
Module Auth: John Orlando
Description: This file is responsible for providing an
interface to the OV6620 camera hardware. This includes
an interface to CamInterface.S for certain low-level,
optimized camera access routines.
Revision History:
Date Rel Ver. Notes
4/10/2004 0.1 Module created
6/30/2004 1.0 Initial release for Circuit Cellar
contest.
11/15/2004 1.2 ifdef'd out the resetCam routine, since
resetting the cam now causes the OV6620's
clock to not be output (we have to start
it up after each reset with the external
tiny12 processor).
1/16/2005 1.4 Ensure that the TCCR1B register is set so
nothing is clocking timer1 at startup.
***********************************************************/
/* Includes */
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/sleep.h>
#include <avr/eeprom.h>
#include <stdlib.h>
#include <string.h>
#include "CommonDefs.h"
#include "CamInterface.h"
#include "Utility.h"
#include "UIMgr.h"
#include "Executive.h"
#include "UartInterface.h"
#define CAM_G_BUS PINC
#define CAM_G_BUS_DIR DDRC
#define CAM_RB_BUS PINA
#define CAM_RB_BUS_DIR DDRA
#define CAM_CONTROL_PORT PORTD
#define CAM_CONTROL_PORT_DIR DDRD
/* Extern Variables */
/* These two buffers hold the current and previous lines
of pixel data. They are sized to the worst case scenario,
where the color changes between every pixel (unrealistic).
The format of each buffer is for all the even bytes to hold
the run-length, and the odd bytes to hold the color data. */
/* In addition, if we are in frameDump mode, we use these buffers
to store the acquired line data...we are actually grabbing ALL of the
pixels in a line (176) instead of the 88 we get normally during tracking.
But since we have enough to hold 88-RLE blocks, we already have the 176
allocated for this... */
unsigned char currentLineBuffer[LENGTH_OF_LINE_BUFFER];
unsigned char previousLineBuffer[LENGTH_OF_LINE_BUFFER];/*176*/
/* Extern Functions */
/* These functions are located in assembly files, and thus
must be externed here so they can be referenced in the source below. */
extern void CamIntAsm_waitForNewDumpFrame(unsigned char *pCurrBuffer, unsigned char *pPrevBuffer);
extern void CamIntAsm_acquireDumpLine(unsigned char *pCurrBuffer, unsigned char *pPrevBuffer);
/***********************************************************
Function Name: CamInt_init
Function Description: This function is responsible
for initializing the camera interface. This includes
setting up the i/o ports that are used to read the
camera busses, as well as resetting the camera.
Inputs: none
Outputs: none
***********************************************************/
void CamInt_init(void)
{
CAM_CONTROL_PORT_DIR &= 0xFB; /* make sure bit2 is clear (input) VSYNC interrupt*/
//CAM_CONTROL_PORT &= 0x7F; /* set reset line low */
CAM_G_BUS_DIR &= 0x00; /* 8-bit G bus all inputs PortC*/
DDRB |= 0x0A; /* disable the pull-up on PB1 and PB3 */
CAM_RB_BUS_DIR &= 0x00; /* 8-bit RB bus all inputs PortA*/
/* ensure that timer1 is disabled to start...eventually, when PCLK needs
to feed timer1 through the external counter, it will be enabled on an
"as needed" basis...*/
TCCR1B &= ~( (1<<CS12)|(1<<CS11)|(1<<CS10) );
/* we'll turn on the interrupt after we assign the initial TCNT value */
/* set up External Interrupt1 to interrupt us on rising edges (HREF)...
this is needed to indicate when the first pixel of each line is about to start, so
we can synch up with it...this interrupt will be disabled once HREF goes high */
EICRA |= (1<<ISC31) | (1<<ISC30); /* rising edge interrupt *///EICRA
/* the interrupt will be enabled when we are ready to detect the rising edge of
HREF...its now primed and ready to go */
/* set up External Interrupt0 to interrupt us on rising edges (VSYNC) */
EICRA |= (1<<ISC21) | (1<<ISC20); /* rising edge interrupt */
EIMSK |= (1<<INT2); /* VSYNC interrupt request enabled */
/* set up TimerO to count and be clocked from an external pulse source
(HREF) on falling edges...eventually, we need to enable the interrupt
for this! FIX THIS */
TCCR2 = (1<<CS02)|(1<<CS01)|(0<<CS00);
/* setting up the PCLK counter with Timer1 will be done right after
we start receiving pixels in each line...we sacrifice the first pixel
in each line, but we'll account for it...*/
/* set up the mega8 so that its sleep mode puts it in an IDLE sleep
mode, where it can wake up as fast as possible */
set_sleep_mode(SLEEP_MODE_IDLE);
/* umm....we need to actually enable the sleep mode...*/
MCUCR |= (1<<SE);
}
/***********************************************************
Function Name: CamInt_resetCam
Function Description: This function is responsible
for resetting the camera. This is accomplished by
toggling the reset line on the OV6620 for ~100 mS.
Inputs: none
Outputs: none
IMPORTANT NOTE: This function has effectively been removed
since resetting the camera now causes the camera to not
output the clock signal. Thus, if we reset the cam, the
AVR has no clock, and thus doesn't run...
***********************************************************/
void CamInt_resetCam(void)
{
#if 0
CAM_CONTROL_PORT |= (1<<CAM_RESET_LINE); /* cam reset line high */
Utility_delay(500);
CAM_CONTROL_PORT &= (0<<CAM_RESET_LINE); /* cam reset line low */
Utility_delay(100);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -