Files
32343 843447835d Initial commit: TC264 smart car project with IPS200 menu system
- IPS200 display menu with real-time status and parameter settings
- Camera image processing and line tracking
- IMU attitude solution and PID control
- WiFi SPI oscilloscope data transmission
2026-05-10 21:38:49 +08:00

188 lines
10 KiB
C
Raw Permalink 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.
/*********************************************************************************************************************
* TC264 Opensourec Library ����TC264 ��Դ�⣩��һ�����ڹٷ� SDK �ӿڵĵ�������Դ��
* Copyright (c) 2022 SEEKFREE ��ɿƼ�
*
* ���ļ��� TC264 ��Դ���һ����
*
* TC264 ��Դ�� ���������
* �����Ը���������������ᷢ���� GPL��GNU General Public License���� GNUͨ�ù�������֤��������
* �� GPL �ĵ�3�棨�� GPL3.0������ѡ��ģ��κκ����İ汾�����·�����/���޸���
*
* ����Դ��ķ�����ϣ�����ܷ������ã�����δ�������κεı�֤
* ����û�������������Ի��ʺ��ض���;�ı�֤
* ����ϸ����μ� GPL
*
* ��Ӧ�����յ�����Դ���ͬʱ�յ�һ�� GPL �ĸ���
* ���û�У������<https://www.gnu.org/licenses/>
*
* ����ע����
* ����Դ��ʹ�� GPL3.0 ��Դ����֤Э�� ������������Ϊ���İ汾
* ��������Ӣ�İ��� libraries/doc �ļ����µ� GPL3_permission_statement.txt �ļ���
* ����֤������ libraries �ļ����� �����ļ����µ� LICENSE �ļ�
* ��ӭ��λʹ�ò����������� ���޸�����ʱ���뱣����ɿƼ��İ�Ȩ����������������
*
* ����� zf_device_camera
* ��˾���� �ɶ���ɿƼ����޹�˾
* �汾��Ϣ �鿴 libraries/doc �ļ����� version �ļ� �汾˵��
* �������� ADS v1.10.2
* ����ƽ̨ TC264D
* �������� https://seekfree.taobao.com/
*
* �޸ļ�¼
* ���� ���� ��ע
* 2022-09-15 pudding first version
* 2023-04-25 pudding ��������ע��˵��
********************************************************************************************************************/
#include "zf_common_debug.h"
#include "zf_common_interrupt.h"
#include "zf_driver_gpio.h"
#include "zf_driver_dma.h"
#include "zf_driver_exti.h"
#include "zf_device_mt9v03x_double.h"
#include "zf_device_ov7725.h"
#include "zf_device_scc8660.h"
#include "isr_config.h"
#include "zf_device_camera.h"
fifo_struct camera_receiver_fifo; // ��������ͷ��������fifo�ṹ��
uint8 camera_receiver_buffer[CAMERA_RECEIVER_BUFFER_SIZE]; // ��������ͷ�������ݻ�����
uint8 camera_send_image_frame_header[4] = {0x00, 0xFF, 0x01, 0x01}; // ��������ͷ���ݷ��͵���λ����֡ͷ
//-------------------------------------------------------------------------------------------------------------------
// ������� ����ͷ������ͼ�����ݽ�ѹΪʮ�����ư�λ���� С�����
// ����˵�� *data1 ����ͷͼ������
// ����˵�� *data2 ��Ž�ѹ���ݵĵ�ַ
// ����˵�� image_size ͼ��Ĵ�С
// @return void
// Sample usage: camera_binary_image_decompression(&ov7725_image_binary[0][0], &data_buffer[0][0], OV7725_SIZE);
//-------------------------------------------------------------------------------------------------------------------
void camera_binary_image_decompression (const uint8 *data1, uint8 *data2, uint32 image_size)
{
zf_assert(NULL != data1);
zf_assert(NULL != data2);
uint8 i = 8;
while(image_size --)
{
i = 8;
while(i --)
{
*data2 ++ = (((*data1 >> i) & 0x01) ? 255 : 0);
}
data1 ++;
}
}
//-------------------------------------------------------------------------------------------------------------------
// ������� ����ͷͼ��������λ���鿴ͼ��
// ����˵�� uartn ʹ�õĴ��ں�
// ����˵�� *image_addr ��Ҫ���͵�ͼ���ַ
// ����˵�� image_size ͼ��Ĵ�С
// @return void
// Sample usage: camera_send_image(DEBUG_UART_INDEX, &mt9v03x_image[0][0], MT9V03X_IMAGE_SIZE);
//-------------------------------------------------------------------------------------------------------------------
void camera_send_image (uart_index_enum uartn, const uint8 *image_addr, uint32 image_size)
{
zf_assert(NULL != image_addr);
// ��������
uart_write_buffer(uartn, camera_send_image_frame_header, 4);
// ����ͼ��
uart_write_buffer(uartn, (uint8 *)image_addr, image_size);
}
//-------------------------------------------------------------------------------------------------------------------
// ������� ����ͷ���� FIFO ��ʼ��
// ����˵�� void
// ���ز��� void
// ʹ��ʾ�� camera_fifo_init();
// ��ע��Ϣ
//-------------------------------------------------------------------------------------------------------------------
void camera_fifo_init (void)
{
fifo_init(&camera_receiver_fifo, FIFO_DATA_8BIT, camera_receiver_buffer, CAMERA_RECEIVER_BUFFER_SIZE);
}
//-------------------------------------------------------------------------------------------------------------------
// ������� ����ͷ�ɼ���ʼ��
// ����˵�� source_addr ������Դ�����ַ
// ����˵�� destination_addr ͼ�񻺳�����ַ
// ����˵�� image_size ͼ��Ĵ�С
// ���ز��� uint8 DMA ��������
// @return void
// Sample usage: camera_init();
//-------------------------------------------------------------------------------------------------------------------
uint8 camera_init (uint8 *source_addr, uint8 *destination_addr, uint32 image_size)
{
uint8 num;
uint8 link_list_num;
switch(camera_type)
{
case CAMERA_BIN_IIC: // IIC ���
case CAMERA_BIN_UART: // UART ���
for(num = 0; num < 8; num ++)
{
gpio_init((gpio_pin_enum)(OV7725_DATA_PIN + num), GPI, GPIO_LOW, GPI_FLOATING_IN);
}
link_list_num = dma_init(OV7725_DMA_CH,
source_addr,
destination_addr,
OV7725_PCLK_PIN,
EXTI_TRIGGER_FALLING,
image_size);
exti_init(OV7725_VSYNC_PIN, EXTI_TRIGGER_FALLING); //��ʼ�����жϣ�������Ϊ�½��ش����ж�
break;
case CAMERA_GRAYSCALE_1: // ����� 1
for(num = 0; num < 8; num ++)
{
gpio_init((gpio_pin_enum)(MT9V03X_1_DATA_PIN + num), GPI, GPIO_LOW, GPI_FLOATING_IN);
}
link_list_num = dma_init(MT9V03X_1_DMA_CH,
source_addr,
destination_addr,
MT9V03X_1_PCLK_PIN,
EXTI_TRIGGER_FALLING,
image_size); // 主频在300M 用于倍频时采集改为FALLING
exti_init(MT9V03X_1_VSYNC_PIN, EXTI_TRIGGER_BOTH); // ��ʼ�����жϣ�������Ϊ�½��ش����ж�
break;
case CAMERA_GRAYSCALE_2: // ����� 2
for(num = 0; num < 8; num ++)
{
gpio_init((gpio_pin_enum)(MT9V03X_2_DATA_PIN + num), GPI, GPIO_LOW, GPI_FLOATING_IN);
}
link_list_num = dma_init_2(MT9V03X_2_DMA_CH,
source_addr,
destination_addr,
MT9V03X_2_PCLK_PIN,
EXTI_TRIGGER_FALLING,
image_size); // 主频在300M 用于倍频时采集改为FALLING
exti_init(MT9V03X_2_VSYNC_PIN, EXTI_TRIGGER_BOTH); // ��ʼ�����жϣ�������Ϊ�½��ش����ж�
break;
case CAMERA_COLOR: // ��ͫ
for(num=0; num<8; num++)
{
gpio_init((gpio_pin_enum)(SCC8660_DATA_PIN + num), GPI, GPIO_LOW, GPI_FLOATING_IN);
}
link_list_num = dma_init(SCC8660_DMA_CH,
source_addr,
destination_addr,
SCC8660_PCLK_PIN,
EXTI_TRIGGER_RISING,
image_size); // �����Ƶ��300M �����ڶ�������������ΪFALLING
exti_init(SCC8660_VSYNC_PIN, EXTI_TRIGGER_FALLING); // ��ʼ�����жϣ�������Ϊ�½��ش����ж�
break;
default:
break;
}
return link_list_num;
}