diff --git a/examples/camera/camera_interleave_pbuf/CMakeLists.txt b/examples/camera/camera_interleave_pbuf/CMakeLists.txt new file mode 100644 index 00000000..468c2235 --- /dev/null +++ b/examples/camera/camera_interleave_pbuf/CMakeLists.txt @@ -0,0 +1,10 @@ +set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common) +set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/bl706_camera_pbuf.ld) +set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/image_sensor +${BSP_COMMON_DIR}/psram +${BSP_COMMON_DIR}/il9341) +set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/image_sensor/bsp_image_sensor.c +${BSP_COMMON_DIR}/psram/bsp_sf_psram.c +${BSP_COMMON_DIR}/il9341/bsp_il9341.c ) +set(mains main.c) +generate_bin() \ No newline at end of file diff --git a/examples/camera/camera_interleave_pbuf/bl706_camera_pbuf.ld b/examples/camera/camera_interleave_pbuf/bl706_camera_pbuf.ld new file mode 100644 index 00000000..01ae7713 --- /dev/null +++ b/examples/camera/camera_interleave_pbuf/bl706_camera_pbuf.ld @@ -0,0 +1,217 @@ +/**************************************************************************************** +* @file bl702_camera_pbuf.ld +* +* @brief This file is the map file (gnuarm or armgcc). +* +* Copyright (C) BouffaloLab 2021 +* +**************************************************************************************** +*/ + +/* configure the CPU type */ +OUTPUT_ARCH( "riscv" ) +/* link with the standard c library */ +/* INPUT(-lc) */ +/* link with the standard GCC library */ +/* INPUT(-lgcc) */ +/* configure the entry point */ +ENTRY(_enter) + +StackSize = 0x1000; /* 4KB */ + +MEMORY +{ + xip_memory (rx) : ORIGIN = 0x23000000, LENGTH = 1024K + itcm_memory (rx) : ORIGIN = 0x22014000, LENGTH = 12K + dtcm_memory (rx) : ORIGIN = 0x42017000, LENGTH = 4K + ram_memory (!rx) : ORIGIN = 0x42018000, LENGTH = 96K +} + +SECTIONS +{ + PROVIDE(__metal_chicken_bit = 0); + + .text : + { + . = ALIGN(4); + __text_code_start__ = .; + + KEEP (*(.text.metal.init.enter)) + KEEP (*(SORT_NONE(.init))) + /* section information for shell */ + . = ALIGN(4); + __fsymtab_start = .; + KEEP(*(FSymTab)) + __fsymtab_end = .; + + . = ALIGN(4); + __vsymtab_start = .; + KEEP(*(VSymTab)) + __vsymtab_end = .; + + /* section information for usb desc */ + . = ALIGN(4); + _usb_desc_start = .; + KEEP(*(usb_desc)) + . = ALIGN(4); + _usb_desc_end = .; + + *(.text) + *(.text.*) + + /*put .rodata**/ + *(EXCLUDE_FILE( *bl702_glb.o \ + *bl702_pds.o \ + *bl702_common.o \ + *bl702_sf_cfg.o \ + *bl702_sf_ctrl.o \ + *bl702_sflash.o \ + *bl702_xip_sflash.o \ + *bl702_ef_ctrl.o) .rodata*) + *(.rodata) + *(.rodata.*) + + *(.srodata) + *(.srodata.*) + + . = ALIGN(4); + __text_code_end__ = .; + } > xip_memory + + . = ALIGN(4); + __itcm_load_addr = .; + + .itcm_region : AT (__itcm_load_addr) + { + . = ALIGN(4); + __tcm_code_start__ = .; + + *(.tcm_code) + *(.tcm_const) + *(.sclock_rlt_code) + *(.sclock_rlt_const) + + *bl702_glb.o*(.rodata*) + *bl702_pds.o*(.rodata*) + *bl702_common.o*(.rodata*) + *bl702_sf_cfg.o*(.rodata*) + *bl702_sf_ctrl.o*(.rodata*) + *bl702_sflash.o*(.rodata*) + *bl702_xip_sflash.o*(.rodata*) + *bl702_ef_ctrl.o*(.rodata*) + + . = ALIGN(4); + __tcm_code_end__ = .; + } > itcm_memory + + __dtcm_load_addr = __itcm_load_addr + SIZEOF(.itcm_region); + + .dtcm_region : AT (__dtcm_load_addr) + { + . = ALIGN(4); + __tcm_data_start__ = .; + + *(.tcm_data) + /* *finger_print.o(.data*) */ + + . = ALIGN(4); + __tcm_data_end__ = .; + } > dtcm_memory + + /*************************************************************************/ + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (NOLOAD): + { + . = ALIGN(0x4); + . = . + StackSize; + . = ALIGN(0x4); + } > dtcm_memory + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(dtcm_memory) + LENGTH(dtcm_memory); + PROVIDE( __freertos_irq_stack_top = __StackTop); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __tcm_data_end__, "region RAM overflowed with stack") + /*************************************************************************/ + + __system_ram_load_addr = __dtcm_load_addr + SIZEOF(.dtcm_region); + + .system_ram_data_region : AT (__system_ram_load_addr) + { + . = ALIGN(4); + __system_ram_data_start__ = .; + + *(.system_ram) + + . = ALIGN(4); + __system_ram_data_end__ = .; + } > ram_memory + + __ram_load_addr = __system_ram_load_addr + SIZEOF(.system_ram_data_region); + + /* Data section */ + RAM_DATA : AT (__ram_load_addr) + { + . = ALIGN(4); + __ram_data_start__ = .; + + PROVIDE( __global_pointer$ = . + 0x800 ); + + *(.data) + *(.data.*) + *(.sdata) + *(.sdata.*) + *(.sdata2) + *(.sdata2.*) + + . = ALIGN(4); + __ram_data_end__ = .; + } > ram_memory + + .bss (NOLOAD) : + { + . = ALIGN(4); + __bss_start__ = .; + + *(.bss*) + *(.sbss*) + *(COMMON) + + . = ALIGN(4); + __bss_end__ = .; + } > ram_memory + + .noinit_data (NOLOAD) : + { + . = ALIGN(4); + __noinit_data_start__ = .; + + *(.noinit_data*) + + . = ALIGN(4); + __noinit_data_end__ = .; + } > ram_memory + + .heap (NOLOAD): + { + . = ALIGN(4); + __HeapBase = .; + + KEEP(*(.heap*)) + + . = ALIGN(4); + __HeapLimit = .; + } > ram_memory + + PROVIDE (__heap_min_size = 0x400); + __HeapLimit = ORIGIN(ram_memory) + LENGTH(ram_memory); + + ASSERT((__HeapLimit - __HeapBase ) >= __heap_min_size, "heap size is too short.") + +} + diff --git a/examples/camera/camera_interleave_pbuf/cdk/camera_interleave_pbuf.cdkproj b/examples/camera/camera_interleave_pbuf/cdk/camera_interleave_pbuf.cdkproj new file mode 100644 index 00000000..80a25f3b --- /dev/null +++ b/examples/camera/camera_interleave_pbuf/cdk/camera_interleave_pbuf.cdkproj @@ -0,0 +1,694 @@ + + + CPU: RV32IMAFC +Chip: bl70x +Board: bl70x_iot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 154 + 104 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + yes + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV;BFLB_USE_HAL_DRIVER; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_avb;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../bsp/bsp_common/image_sensor;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_avb;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)../bl702_camera.ld + c + + --specs=nano.specs + no + + + + yes + OpenOCD + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + yes + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + BL702;ARCH_RISCV; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../bsp/bsp_common/image_sensor;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)/../bl706_camera.ld + c + + --specs=nano.specs + no + + + + yes + ICE + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl702_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + diff --git a/examples/camera/camera_interleave_pbuf/main.c b/examples/camera/camera_interleave_pbuf/main.c new file mode 100644 index 00000000..2c631823 --- /dev/null +++ b/examples/camera/camera_interleave_pbuf/main.c @@ -0,0 +1,218 @@ +/** + * @file main.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ + +/** + * + * w 480 w 480 psram w 480 + * +-------------------------+ buf1 +----------------------+ ---------┐ +-----------------------+ + * |Y0Y1... | --------------> |... | h 20 ↘ |Y0Y1... | + * |... | |... | |... | + * |... | buf2 +----------------------+ |... | + * |... | --------------> |... | h 20 |... | + * |... | h 360 |... | |... | + * |... | +----------------------+ |... | + * |... | double buffer processing |... | + * |... | __________↗ ... + * |... | ... + * |... | ... + * |... | + * +-------------------------+ + * camera input data + * + * */ + +#include "bflb_platform.h" +#include "bsp_image_sensor.h" +#include "bsp_sf_psram.h" +#include "hal_spi.h" +#include "hal_gpio.h" +#include "hal_dma.h" +#include "bsp_il9341.h" + +#define CAMERA_RESOLUTION_X (480) +#define CAMERA_RESOLUTION_Y (360) + +// #define CAMERA_WRITE_ADDR (uint32_t)(0x4202B500) // camera raw data write address +// #define CAMERA_BUFFER_SIZE (uint32_t)(0x4B00) // pingpong buf size 480*20*2 +// #define CAMERA_FRAME_SIZE (9600) // pingpong buffer half size 480*20 ; full image size 480*20*18 + +#define PSRAM_START_ADDR (0x26000000) // psram write start address + +#define YUV422_FRAME_SIZE (CAMERA_RESOLUTION_X * CAMERA_RESOLUTION_Y * 2) +#define YUV420_FRAME_SIZE (CAMERA_RESOLUTION_X * CAMERA_RESOLUTION_Y * 2 * 3 / 4) +#define YUV400_FRAME_SIZE (CAMERA_RESOLUTION_X * CAMERA_RESOLUTION_Y) + +// #define CAMERA_FRAME_SIZE (YUV400_FRAME_SIZE / 2) + +// pingpong buf +static uint8_t pingpong_buff[2][CAMERA_FRAME_SIZE] __attribute__((section(".system_ram"), aligned(4))); + +struct device *dma_cam; + +static cam_device_t camera_cfg = { + .software_mode = CAM_AUTO_MODE, + .frame_mode = CAM_FRAME_INTERLEAVE_MODE, + .yuv_format = CAM_YUV_FORMAT_YUV400_EVEN, + .cam_write_ram_addr = (uint32_t)pingpong_buff[0], + .cam_write_ram_size = sizeof(pingpong_buff), + .cam_frame_size = sizeof(pingpong_buff[0]), + + .cam_write_ram_addr1 = 0, + .cam_write_ram_size1 = 0, + .cam_frame_size1 = 0, +}; + +static mjpeg_device_t mjpeg_cfg; + +// uint32_t tim1, tim2, tim3, tim4; +uint8_t *picture; +uint32_t length; + +volatile static uint8_t buff_using_num = 0; +volatile static uint8_t flag_normal = 0; + +void my_memcpy(void *dst, void const *src, uint32_t size) +{ + size /= 4; + for (uint32_t n = 0; n < size; n++) { + *((uint32_t *)(dst) + n) = *((uint32_t *)(src) + n); + } +} + +void ATTR_TCM_SECTION CAM_Interrupt_Normal(void) +{ + if (flag_normal == 0) { + // memcpy((void *)(uint32_t)(0x42023000 + (8640 * buff_using_num)), (void *)CAMERA_WRITE_ADDR, CAMERA_FRAME_SIZE); + // my_memcpy((void *)(uint32_t)(0x26000000 + (CAMERA_FRAME_SIZE * buff_using_num)), (void *)CAMERA_WRITE_ADDR, CAMERA_FRAME_SIZE); + /* + if (buff_using_num == 0) { + tim1 = bflb_platform_get_time_ms(); + } + */ + + while (device_control(dma_cam, DMA_CHANNEL_GET_STATUS, NULL)) { + __asm volatile("nop"); + __asm volatile("nop"); + } + + dma_reload(dma_cam, (uint32_t)pingpong_buff[0], (uint32_t)(PSRAM_START_ADDR + (sizeof(pingpong_buff[0]) * (buff_using_num))), sizeof(pingpong_buff[0])); + dma_channel_start(dma_cam); + + /* + if (buff_using_num == 0) { + tim2 = bflb_platform_get_time_ms(); + } + */ + + flag_normal = 1; + buff_using_num++; + return; + } else if (flag_normal == 1) { + // if (buff_using_num == (18 * 3) - 1) { + // // cam_stop(); + // } + // cam_stop(); + // my_memcpy((void *)(uint32_t)(0x26000000 + (CAMERA_FRAME_SIZE * buff_using_num)), (void *)(CAMERA_WRITE_ADDR + CAMERA_FRAME_SIZE), CAMERA_FRAME_SIZE); + // memcpy((void *)(uint32_t)(0x42023000 + (8640 * buff_using_num)), (void *)(CAMERA_WRITE_ADDR + CAMERA_FRAME_SIZE), CAMERA_FRAME_SIZE); + + // cam_start(); + /* + if (buff_using_num == 1) { + tim3 = bflb_platform_get_time_ms(); + } + */ + + while (device_control(dma_cam, DMA_CHANNEL_GET_STATUS, NULL)) { + __asm volatile("nop"); + __asm volatile("nop"); + } + + dma_reload(dma_cam, (uint32_t)pingpong_buff[1], (uint32_t)(PSRAM_START_ADDR + (sizeof(pingpong_buff[0]) * (buff_using_num))), sizeof(pingpong_buff[0])); + dma_channel_start(dma_cam); + + /* + if (buff_using_num == 1) { + tim4 = bflb_platform_get_time_ms(); + } + */ + + flag_normal = 0; + buff_using_num++; + + return; + } + + // MSG("CAM NORMAL\r\n"); + return; +} + +int ATTR_TCM_SECTION main(void) +{ + bflb_platform_init(0); + bsp_sf_psram_init(1); + + struct device *uart0 = device_find("debug_log"); + + dma_register(DMA0_CH0_INDEX, "dma_cam", DEVICE_OFLAG_RDWR); + + dma_cam = device_find("dma_cam"); + + if (dma_cam) { + device_open(dma_cam, 0); + } + // MSG("dma open \r\n"); + + cam_hw_mode_wrap(DISABLE); + + cam_clk_out(); + + cam_hsync_crop(0, 2 * CAMERA_RESOLUTION_X); + cam_vsync_crop(0, CAMERA_RESOLUTION_Y); + + CAM_IntMask(CAM_INT_ALL, MASK); + CAM_Int_Callback_set(CAM_INT_NORMAL_0, &CAM_Interrupt_Normal); + CAM_IntMask(CAM_INT_NORMAL_0, UNMASK); + NVIC_EnableIRQ(CAM_IRQn); + System_NVIC_SetPriority(CAM_IRQn, 4, 1); + + if (SUCCESS != image_sensor_init(DISABLE, &camera_cfg, &mjpeg_cfg)) { + MSG("Init error!\n"); + BL_CASE_FAIL; + } + // MSG("cam init!\n"); + cam_start(); + + while (1) { + if (buff_using_num == 18 * 3) { // close cam when 3 pic saved,480x360 = 480x20x18 + cam_stop(); + + device_write(uart0, 0, (void *)(uint32_t *)PSRAM_START_ADDR, YUV400_FRAME_SIZE * 3); // uart log send 3 pic raw data + + // MSG("\r\ntim1:%d, tim2:%d, tim3:%d, tim4:%d", tim1, tim2, tim3, tim4); + return 0; + } + bflb_platform_delay_ms(1); + } + + // BL_CASE_SUCCESS; +} diff --git a/examples/camera/camera_interleave_pbuf/readme.md b/examples/camera/camera_interleave_pbuf/readme.md new file mode 100644 index 00000000..62144b71 --- /dev/null +++ b/examples/camera/camera_interleave_pbuf/readme.md @@ -0,0 +1,20 @@ +**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_CAMERA_LCD** +**bsp_common/image_sensor/bsp_image_sensor.c** 中**IMAGE_SENSOR_USE** 选择**IMAGE_SENSOR_GC0308** (目前暂时没有 BF2013 sensor 验证) +**bsp_common/image_sensor/bsp_image_sensor.c** 中**FORMAT_SEL** 选择 **YUYV** +**bsp_common/image_sensor/bsp_image_sensor.c** 中**CAM_MODE** 选择 **CAM_USING_INT_MODE**模式 +sensor 选择 GC0308 +此 case 用于测 camera 使用 pingpong buf 出图,验证此模式出图是否正常; +首先,当第一个 buf 填满后,会触发中断,通过 memcopy 或者 DMA 将图片原数据搬运到 PSRAM 中存储, +当第二个 buf 填满后,也会触发中断,将图像原数据紧接着上一帧的地址继续存储; + +两个 buf 会依次循环,填充 psram 直到一张完整的图像填完。 + +当一张图填完后,通过串口打印出来(使用串口打印时,注意将无关的 log 关闭,否则会影响图像数据,其次串口波特率要设置低一些,建议 512000、115200 等不然会丢包) +使用 YUV 图像查看工具即可查看图像是否正常 + + +```bash + +$ make APP=camera_interleave_pbuf BOARD=bl706_avb SUPPORT_FLOAT=y + +``` \ No newline at end of file