2022-01-18 00:58:54 +08:00

219 lines
9.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*********************************************************************************************************************
* COPYRIGHT NOTICE
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
* All rights reserved.
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
*
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @file main
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
* @Software ADS v1.2.2
* @Target core TC264D
* @Taobao https://seekfree.taobao.com/
* @date 2020-3-23
* @note
<09><><EFBFBD>߶<EFBFBD><DFB6>
------------------------------------
ģ<><C4A3><EFBFBD>ܽ<EFBFBD> <09><>Ƭ<EFBFBD><C6AC><EFBFBD>ܽ<EFBFBD>
SDA <09>鿴SEEKFREE_IIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SDA<44><EFBFBD><EAB6A8>
SCL <20>鿴SEEKFREE_IIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SCL<43><EFBFBD><EAB6A8>
<09><><EFBFBD>ж<EFBFBD>(VSY) <09>鿴SEEKFREE_OV7725.h<>ļ<EFBFBD><C4BC>е<EFBFBD>OV7725_VSYNC_PIN<49><EFBFBD><EAB6A8>
<09><><EFBFBD>ж<EFBFBD>(HREF) δʹ<CEB4>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>
<09><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(PCLK) <09>鿴SEEKFREE_OV7725.h<>ļ<EFBFBD><C4BC>е<EFBFBD>OV7725_PCLK_PIN<49><EFBFBD><EAB6A8>
<09><><EFBFBD>ݿ<EFBFBD>(D0-D7) <09>鿴SEEKFREE_OV7725.h<>ļ<EFBFBD><C4BC>е<EFBFBD>OV7725_DATA_PIN<49><EFBFBD><EAB6A8>
------------------------------------
Ĭ<>Ϸֱ<CFB7><D6B1><EFBFBD><EFBFBD><EFBFBD> 160*120
Ĭ<><C4AC>FPS 50֡
********************************************************************************************************************/
#include "IfxDma.h"
#include "IfxScuEru.h"
#include "zf_stm_systick.h"
#include "zf_gpio.h"
#include "zf_eru.h"
#include "zf_eru_dma.h"
#include "SEEKFREE_IIC.h"
#include "SEEKFREE_7725.h"
IFX_ALIGN(4) uint8 image_bin[OV7725_H][OV7725_W/8]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8 image_dec[OV7725_H][OV7725_W];
uint8 ov7725_idcode = 0;
//-------------------------------------------------------------------------------------------------------------------
// @brief С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>(<28>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
// @param NULL
// @return uint8 <09><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ɹ<EFBFBD>
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
uint8 ov7725_reg_init(void)
{
simiic_delay_set(700);
simiic_write_reg ( OV7725_DEV_ADD, OV7725_COM7, 0x80 ); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>ͷ
systick_delay_ms(STM0, 50);
ov7725_idcode = simiic_read_reg( OV7725_DEV_ADD, OV7725_VER ,SCCB);
if( ov7725_idcode != OV7725_ID ) return 0; //У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷID<49><44>
//ID<49><44>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD>üĴ<C3BC><C4B4><EFBFBD>
simiic_write_reg(OV7725_DEV_ADD, OV7725_COM4 , 0xC1);
simiic_write_reg(OV7725_DEV_ADD, OV7725_CLKRC , 0x01);
simiic_write_reg(OV7725_DEV_ADD, OV7725_COM2 , 0x03);
simiic_write_reg(OV7725_DEV_ADD, OV7725_COM3 , 0xD0);
simiic_write_reg(OV7725_DEV_ADD, OV7725_COM7 , 0x40);
simiic_write_reg(OV7725_DEV_ADD, OV7725_COM8 , 0xCE); //0xCE:<3A>ر<EFBFBD><D8B1>Զ<EFBFBD><D4B6>ع<EFBFBD> 0xCF<43><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ع<EFBFBD>
simiic_write_reg(OV7725_DEV_ADD, OV7725_HSTART , 0x3F);
simiic_write_reg(OV7725_DEV_ADD, OV7725_HSIZE , 0x50);
simiic_write_reg(OV7725_DEV_ADD, OV7725_VSTRT , 0x03);
simiic_write_reg(OV7725_DEV_ADD, OV7725_VSIZE , 0x78);
simiic_write_reg(OV7725_DEV_ADD, OV7725_HREF , 0x00);
simiic_write_reg(OV7725_DEV_ADD, OV7725_SCAL0 , 0x0A);
simiic_write_reg(OV7725_DEV_ADD, OV7725_AWB_Ctrl0 , 0xE0);
simiic_write_reg(OV7725_DEV_ADD, OV7725_DSPAuto , 0xff);
simiic_write_reg(OV7725_DEV_ADD, OV7725_DSP_Ctrl2 , 0x0C);
simiic_write_reg(OV7725_DEV_ADD, OV7725_DSP_Ctrl3 , 0x00);
simiic_write_reg(OV7725_DEV_ADD, OV7725_DSP_Ctrl4 , 0x00);
if(OV7725_W == 80) simiic_write_reg(OV7725_DEV_ADD, OV7725_HOutSize , 0x14);
else if(OV7725_W == 160) simiic_write_reg(OV7725_DEV_ADD, OV7725_HOutSize , 0x28);
else if(OV7725_W == 240) simiic_write_reg(OV7725_DEV_ADD, OV7725_HOutSize , 0x3c);
else if(OV7725_W == 320) simiic_write_reg(OV7725_DEV_ADD, OV7725_HOutSize , 0x50);
if(OV7725_H == 60) simiic_write_reg(OV7725_DEV_ADD, OV7725_VOutSize , 0x1E);
else if(OV7725_H == 120) simiic_write_reg(OV7725_DEV_ADD, OV7725_VOutSize , 0x3c);
else if(OV7725_H == 180) simiic_write_reg(OV7725_DEV_ADD, OV7725_VOutSize , 0x5a);
else if(OV7725_H == 240) simiic_write_reg(OV7725_DEV_ADD, OV7725_VOutSize , 0x78);
simiic_write_reg(OV7725_DEV_ADD, OV7725_REG28 , 0x01);
simiic_write_reg(OV7725_DEV_ADD, OV7725_EXHCH , 0x10);
simiic_write_reg(OV7725_DEV_ADD, OV7725_EXHCL , 0x1F);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM1 , 0x0c);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM2 , 0x16);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM3 , 0x2a);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM4 , 0x4e);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM5 , 0x61);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM6 , 0x6f);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM7 , 0x7b);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM8 , 0x86);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM9 , 0x8e);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM10 , 0x97);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM11 , 0xa4);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM12 , 0xaf);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM13 , 0xc5);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM14 , 0xd7);
simiic_write_reg(OV7725_DEV_ADD, OV7725_GAM15 , 0xe8);
simiic_write_reg(OV7725_DEV_ADD, OV7725_SLOP , 0x20);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_RADI , 0x00);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_COEF , 0x13);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_XC , 0x08);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_COEFB , 0x14);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_COEFR , 0x17);
simiic_write_reg(OV7725_DEV_ADD, OV7725_LC_CTR , 0x05);
simiic_write_reg(OV7725_DEV_ADD, OV7725_BDBase , 0x99);
simiic_write_reg(OV7725_DEV_ADD, OV7725_BDMStep , 0x03);
simiic_write_reg(OV7725_DEV_ADD, OV7725_SDE , 0x04);
simiic_write_reg(OV7725_DEV_ADD, OV7725_BRIGHT , 0x00);
simiic_write_reg(OV7725_DEV_ADD, OV7725_CNST , 0x40);
simiic_write_reg(OV7725_DEV_ADD, OV7725_SIGN , 0x06);
simiic_write_reg(OV7725_DEV_ADD, OV7725_UVADJ0 , 0x11);
simiic_write_reg(OV7725_DEV_ADD, OV7725_UVADJ1 , 0x02);
simiic_delay_set(SIMIIC_DELAY_TIME);//<2F>޸<EFBFBD>ΪĬ<CEAA>ϵ<EFBFBD>20
return 1;
}
//-------------------------------------------------------------------------------------------------------------------
// @brief С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>(<28>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void ov7725_port_init(void)
{
uint8 i;
camera_type = CAMERA_BIN;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
camera_buffer_addr = image_bin[0];
//<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ʼ<EFBFBD><CABC>
//<2F><>ʼ<EFBFBD><CABC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(i=0; i<8; i++)
{
gpio_init((PIN_enum)(OV7725_DATA_PIN+i), GPI, 0, PULLUP);
}
eru_dma_init(OV7725_DMA_CH, GET_PORT_IN_ADDR(OV7725_DATA_PIN), camera_buffer_addr, OV7725_PCLK_PIN, FALLING, OV7725_DMA_NUM);
eru_init(OV7725_VSYNC_PIN, FALLING); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>ж<EFBFBD>
}
//-------------------------------------------------------------------------------------------------------------------
// @brief С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><CABC>(<28><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϺ<D0B6><CFBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɲɼ<C9B2>ͼ<EFBFBD><CDBC>)
// @param NULL
// @return 0
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
uint8 ov7725_init(void)
{
simiic_init();
ov7725_reg_init(); //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ov7725_port_init(); //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ż<EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>
return 0;
}
uint8 ov7725_finish_flag = 0;
//-------------------------------------------------------------------------------------------------------------------
// @brief С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ж<EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage: <09>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>isr.c<>б<EFBFBD>eru<72><75>GPIO<49>жϣ<D0B6><CFA3>жϵ<D0B6><CFB5><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void ov7725_vsync(void)
{
CLEAR_GPIO_FLAG(OV7725_VSYNC_PIN);
if(!ov7725_finish_flag)//<2F>鿴ͼ<E9BFB4><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>δʹ<CEB4><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򲻿<EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʳ<EFBFBD>ͻ
{
DMA_SET_DESTINATION(OV7725_DMA_CH, camera_buffer_addr);
dma_start(OV7725_DMA_CH);
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷDMA<4D><41><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage: <09>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>isr.c<>б<EFBFBD>dma<6D>жϵ<D0B6><CFB5><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void ov7725_dma(void)
{
CLEAR_DMA_FLAG(OV7725_DMA_CH);
ov7725_finish_flag = 1;
dma_stop(OV7725_DMA_CH);
}