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

383 lines
13 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 <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @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(51<35><31>RX) <09>鿴SEEKFREE_MT9V03X.h<>ļ<EFBFBD><C4BC>е<EFBFBD>MT9V03X_COF_UART_TX<54><EFBFBD><EAB6A8>
SCL(51<35><31>TX) <09>鿴SEEKFREE_MT9V03X.h<>ļ<EFBFBD><C4BC>е<EFBFBD>MT9V03X_COF_UART_RX<52><EFBFBD><EAB6A8>
<09><><EFBFBD>ж<EFBFBD>(VSY) <09>鿴SEEKFREE_MT9V03X.h<>ļ<EFBFBD><C4BC>е<EFBFBD>MT9V03X_VSYNC_PIN<49><EFBFBD><EAB6A8>
<09><><EFBFBD>ж<EFBFBD>(HREF) <09><><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>
<09><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(PCLK) <09>鿴SEEKFREE_MT9V03X.h<>ļ<EFBFBD><C4BC>е<EFBFBD>MT9V03X_PCLK_PIN<49><EFBFBD><EAB6A8>
<09><><EFBFBD>ݿ<EFBFBD>(D0-D7) <09>鿴SEEKFREE_MT9V03X.h<>ļ<EFBFBD><C4BC>е<EFBFBD>MT9V03X_DATA_PIN<49><EFBFBD><EAB6A8>
------------------------------------
Ĭ<>Ϸֱ<CFB7><D6B1><EFBFBD><EFBFBD><EFBFBD> 188*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_MT9V03X.h"
//<2F><><EFBFBD><EFBFBD>4<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
IFX_ALIGN(4) uint8 mt9v03x_image[MT9V03X_H][MT9V03X_W];
uint8 receive[3];
uint8 receive_num = 0;
vuint8 uart_receive_flag;
uint8 link_list_num;
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int16 MT9V03X_CFG[CONFIG_FINISH][2]=
{
{AUTO_EXP, 0}, //<2F>Զ<EFBFBD><D4B6>ع<EFBFBD><D8B9><EFBFBD><EFBFBD><EFBFBD> <20><>Χ1-63 0Ϊ<30>ر<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ع⿪<D8B9><E2BFAA> EXP_TIME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD>䣬Ҳ<E4A3AC><D2B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ع<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>Ϊ<EFB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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FPS<50><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FPS
{SET_COL, MT9V03X_W}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Χ1-752 K60<36>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>188
{SET_ROW, MT9V03X_H}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Χ1-480
{LR_OFFSET, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD> <20><>ֵ <20><>ƫ<EFBFBD><C6AB> <20><>ֵ <20><>ƫ<EFBFBD><C6AB> <20><>Ϊ188 376 752ʱ<32>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB> <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBF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2F><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><CABC>ʼ<EFBFBD><CABC>
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int16 GET_CFG[CONFIG_FINISH-1][2]=
{
{AUTO_EXP, 0}, //<2F>Զ<EFBFBD><D4B6>ع<EFBFBD><D8B9><EFBFBD><EFBFBD><EFBFBD>
{EXP_TIME, 0}, //<2F>ع<EFBFBD>ʱ<EFBFBD><CAB1>
{FPS, 0}, //ͼ<><CDBC>֡<EFBFBD><D6A1>
{SET_COL, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{SET_ROW, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{LR_OFFSET, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
{UD_OFFSET, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
{GAIN, 0}, //ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
//-------------------------------------------------------------------------------------------------------------------
// @brief MT9V03X<33><58><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>жϺ<D0B6><CFBA><EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage:
// @note <20>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>isr.c<><63> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϺ<D0B6><CFBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void mt9v03x_uart_callback(void)
{
while(uart_query(MT9V03X_COF_UART, &receive[receive_num]))
{
receive_num++;
if(1==receive_num && 0XA5!=receive[0]) receive_num = 0;
if(3 == receive_num)
{
receive_num = 0;
uart_receive_flag = 1;
}
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
// @param uartn ѡ<><D1A1>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
// @param buff <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ĵ<EFBFBD>ַ
// @return void
// @since v1.0
// Sample usage: <20><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ȳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void set_config(UARTN_enum uartn, int16 buff[CONFIG_FINISH-1][2])
{
uint16 temp, i;
uint8 send_buffer[4];
uart_receive_flag = 0;
//<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC>
for(i=0; i<CONFIG_FINISH; i++)
{
send_buffer[0] = 0xA5;
send_buffer[1] = (uint8)buff[i][0];
temp = buff[i][1];
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
systick_delay_ms(STM0, 2);
}
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
while(!uart_receive_flag);
uart_receive_flag = 0;
while((0xff != receive[1]) || (0xff != receive[2]));
//<2F><><EFBFBD>ϲ<EFBFBD><CFB2>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>51<35><31>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>eeprom<6F><6D>
//<2F><><EFBFBD><EFBFBD>set_exposure_time<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ع<EFBFBD><D8B9><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><E6B4A2>eeprom<6F><6D>
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
// @param uartn ѡ<><D1A1>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
// @param buff <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ĵ<EFBFBD>ַ
// @return void
// @since v1.0
// Sample usage: <20><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ȳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void get_config(UARTN_enum uartn, int16 buff[CONFIG_FINISH-1][2])
{
uint16 temp, i;
uint8 send_buffer[4];
for(i=0; i<CONFIG_FINISH-1; i++)
{
send_buffer[0] = 0xA5;
send_buffer[1] = GET_STATUS;
temp = buff[i][0];
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ܻش<DCBB><D8B4><EFBFBD><EFBFBD><EFBFBD>
while(!uart_receive_flag);
uart_receive_flag = 0;
buff[i][1] = receive[1]<<8 | receive[2];
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD>̼<EFBFBD><CCBC>
// @param uartn ѡ<><D1A1>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
// @return void
// @since v1.0
// Sample usage: <20><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ȳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
uint16 get_version(UARTN_enum uartn)
{
uint16 temp;
uint8 send_buffer[4];
send_buffer[0] = 0xA5;
send_buffer[1] = GET_STATUS;
temp = GET_VERSION;
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ܻش<DCBB><D8B4><EFBFBD><EFBFBD><EFBFBD>
while(!uart_receive_flag);
uart_receive_flag = 0;
return ((uint16)(receive[1]<<8) | receive[2]);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>
// @param uartn ѡ<><D1A1>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
// @param light <20><><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>Խ<EFBFBD><D4BD>ͼ<EFBFBD><CDBC>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷֱ<DDB7><D6B1>ʼ<EFBFBD>FPS<50><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
// @return uint16 <20><>ǰ<EFBFBD>ع<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷд<C8B7><D0B4>
// @since v1.0
// Sample usage: <20><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ȳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
uint16 set_exposure_time(UARTN_enum uartn, uint16 light)
{
uint16 temp;
uint8 send_buffer[4];
send_buffer[0] = 0xA5;
send_buffer[1] = SET_EXP_TIME;
temp = light;
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ܻش<DCBB><D8B4><EFBFBD><EFBFBD><EFBFBD>
while(!uart_receive_flag);
uart_receive_flag = 0;
temp = receive[1]<<8 | receive[2];
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
// @param uartn ѡ<><D1A1>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
// @param addr <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ڲ<EFBFBD><DAB2>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
// @param data <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @return uint16 <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>Ƿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ɹ<EFBFBD>
// @since v1.0
// Sample usage: <09><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ȳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
uint16 set_mt9v03x_reg(UARTN_enum uartn, uint8 addr, uint16 data)
{
uint16 temp;
uint8 send_buffer[4];
send_buffer[0] = 0xA5;
send_buffer[1] = SET_ADDR;
temp = addr;
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
systick_delay_ms(STM0, 10);
send_buffer[0] = 0xA5;
send_buffer[1] = SET_DATA;
temp = data;
send_buffer[2] = temp>>8;
send_buffer[3] = (uint8)temp;
uart_putbuff(uartn,send_buffer,4);
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ܻش<DCBB><D8B4><EFBFBD><EFBFBD><EFBFBD>
while(!uart_receive_flag);
uart_receive_flag = 0;
temp = receive[1]<<8 | receive[2];
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// @brief MT9V03X<33><58><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><CABC>
// @param NULL
// @return void
// @since v1.0
// Sample usage: ʹ<><CAB9>FLEXIO<49>ӿڲɼ<DAB2><C9BC><EFBFBD><EFBFBD><EFBFBD>ͷ
//-------------------------------------------------------------------------------------------------------------------
void mt9v03x_init(void)
{
uint8 i;
camera_type = CAMERA_GRAYSCALE;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
camera_buffer_addr = mt9v03x_image[0];
boolean interrupt_state = disableInterrupts();
uart_init (MT9V03X_COF_UART, 9600, MT9V03X_COF_UART_TX, MT9V03X_COF_UART_RX); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
enableInterrupts();//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD> <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>õķ<C3B5>ʽ <20><>ѡһ
//systick_delay_ms(STM0, 1000);//<2F><>ʱ<EFBFBD><CAB1>ʽ
get_config(MT9V03X_COF_UART, GET_CFG);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>õķ<C3B5>ʽ
uart_receive_flag = 0;
set_config(MT9V03X_COF_UART, MT9V03X_CFG);
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ñ<EFBFBD><C3B1>ڲ鿴<DAB2><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
get_config(MT9V03X_COF_UART, GET_CFG);
disableInterrupts();
//<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)(MT9V03X_DATA_PIN+i), GPI, 0, PULLUP);
}
link_list_num = eru_dma_init(MT9V03X_DMA_CH, GET_PORT_IN_ADDR(MT9V03X_DATA_PIN), camera_buffer_addr, MT9V03X_PCLK_PIN, FALLING, MT9V03X_W*MT9V03X_H);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>300M <20><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪFALLING
eru_init(MT9V03X_VSYNC_PIN, FALLING); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>ж<EFBFBD>
restoreInterrupts(interrupt_state);
}
uint8 mt9v03x_finish_flag = 0; //һ<><D2BB>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
uint8 mt9v03x_dma_int_num; //<2F><>ǰDMA<4D>жϴ<D0B6><CFB4><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
// @brief MT9V03X<33><58><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 mt9v03x_vsync(void)
{
CLEAR_GPIO_FLAG(MT9V03X_VSYNC_PIN);
mt9v03x_dma_int_num = 0;
if(!mt9v03x_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>ͻ
{
if(1 == link_list_num)
{
//û<>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD>ģʽ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ĵ<EFBFBD>ַ
DMA_SET_DESTINATION(MT9V03X_DMA_CH, camera_buffer_addr);
}
dma_start(MT9V03X_DMA_CH);
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief MT9V03X<33><58><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 mt9v03x_dma(void)
{
CLEAR_DMA_FLAG(MT9V03X_DMA_CH);
mt9v03x_dma_int_num++;
if(mt9v03x_dma_int_num >= link_list_num)
{
//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
mt9v03x_dma_int_num = 0;
mt9v03x_finish_flag = 1;//һ<><D2BB>ͼ<EFBFBD><CDBC><EFBFBD>Ӳɼ<D3B2><C9BC><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ3.8MS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(50FPS<50><53>188*120<32>ֱ<EFBFBD><D6B1><EFBFBD>)
dma_stop(MT9V03X_DMA_CH);
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷͼ<CDB7><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>鿴ͼ<E9BFB4><CDBC>
// @param uartn ʹ<>õĴ<C3B5><C4B4>ں<EFBFBD>
// @param image <09><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ַ
// @param width ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @param height ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void seekfree_sendimg_03x(UARTN_enum uartn, uint8 *image, uint16 width, uint16 height)
{
uart_putchar(uartn,0x00);uart_putchar(uartn,0xff);uart_putchar(uartn,0x01);uart_putchar(uartn,0x01);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uart_putbuff(uartn, image, width*height); //<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
}