198|0

23

帖子

0

TA的资源

一粒金砂(中级)

【瑞萨RA8D1开发板,基于M85内核的图形MCU测评】+摄像头和显示屏结合 [复制链接]

上次我们通过开发板进行了摄像头测试,关键我们只能通过仿真然后进内存中查看里面的图像数据,还有点掉帧,所以我们结合我们的屏幕进行测试直接显示到LCD上。

image-20240830135633-1.png  

我们在摄像头的基础上增加我们的RGB LCD的配置。之前都是现成的所以拿来用下即可。

image-20240830135633-2.png  

把关键的引脚初始化好,相关的配置设置好。即可。

我们都知道摄像头的数据都是存储在内存中的,所以我们去找相关内存数据给其刷新到LCD上即可。

image-20240830135633-3.png  

也就是我自己定义的一个函数,主要是按照图片大小来进行刷新。

image-20240830135633-4.png  

关键的是我们要给其数组进行拼接,因为RGB565是16位的数据为一个颜色。

#include "hal_data.h"
#include "ceu.h"
#include "ov5640.h"
#include "board_sdram.h"
#include "glcdc_ep.h"


FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER


extern uint32_t g_image_width;
extern uint32_t g_image_height;
extern uint8_t * gp_image_buffer;
extern sensor_reg_t const * gp_ov5640_resolution;
extern capture_instance_t const * gp_ceu_instance;


/* Variables to store resolution information */
uint16_t g_hz_size, g_vr_size;
/* Variables used for buffer usage */
uint32_t g_buffer_size;
uint8_t * g_p_single_buffer, * g_p_double_buffer;

#define RESET_VALUE             (0x00)

static void screen_display(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color);

static void color_band_display(void);

static void show_img_display(void);

/*******************************************************************************************************************//**
 * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
 * is called by main() when no RTOS is used.
 **********************************************************************************************************************/
void hal_entry(void)
{
    /* TODO: add your own code here */
//    fsp_pack_version_t  version = {RESET_VALUE};
    fsp_err_t           err     = FSP_SUCCESS;




    /* Initialize SDRAM */
    bsp_sdram_init();
    /* Initialize GPT module */
//    err = R_GPT_Open(&g_timer_periodic_ctrl, &g_timer_periodic_cfg);
//    handle_error(err, " ** R_GPT_Open API FAILED ** \r\n");

    /* Start GPT module to provide the 24MHz clock frequency output for the camera clock source */
//    err = R_GPT_Start(&g_timer_periodic_ctrl);
//    handle_error(err, " ** R_GPT_Start API FAILED ** \r\n");

    /* Initialize IIC module */
    err = R_SCI_B_I2C_Open(&g_sci_i2c_master_for_ov5640_ctrl, &g_sci_i2c_master_for_ov5640_cfg);
//    handle_error(err, " ** R_IIC_MASTER_Open API FAILED ** \r\n");

    /* Initialize OV3640 sensor with output format as YUV422 */
    err = ov5640_open();
//    handle_error(err, " ** ov3640_open FAILED ** \r\n");

    /* Get LCDC configuration */
    g_hz_size = (g_display_cfg.input[0].hsize);
    g_vr_size = (g_display_cfg.input[0].vsize);
    /* Initialize buffer pointers */
    g_buffer_size = (uint32_t) (g_hz_size * g_vr_size * BYTES_PER_PIXEL);
    g_p_single_buffer = (uint8_t *) g_display_cfg.input[0].p_base;
    /* Double buffer for drawing color bands with good quality */
    g_p_double_buffer = g_p_single_buffer + g_buffer_size;


    /* Initialize GLCDC driver */
    err = R_GLCDC_Open(&g_display_ctrl, &g_display_cfg);


   /* Handle error */
//       if(FSP_SUCCESS != err)
//       {
//           /* GLCDC initialization failed  */
//           APP_ERR_PRINT("\r\n ** GLCDC driver initialization FAILED ** \r\n");
//           APP_ERR_TRAP(err);
//       }

   /* Start GLCDC display output */
   err = R_GLCDC_Start(&g_display_ctrl);
   /* Handle error */
//       if(FSP_SUCCESS != err)
//       {
//           /* GLCDC initialization failed  */
//           APP_ERR_PRINT("\r\n ** GLCDC driver start FAILED ** \r\n");
//           APP_ERR_TRAP(err);
//       }

   /* Clear LCD screen using appropriate co-ordinates */
   screen_display((uint16_t)X1_CO_ORDINATE, (uint16_t)Y1_CO_ORDINATE, g_hz_size, g_vr_size, YELLOW);

   /* Display color bands on LCD screen */
//   color_band_display();

    /* Main loop */
    while(true)
    {
        /* User selects type of memory to store image and resolution of image */
        selection_menu();

        /* Set camera resolution specified by ov3640 array pointer */
        err = ov5640_set_resolution(gp_ov5640_resolution);
//        handle_error(err, " ** ov3640_set_resolution FAILED ** \r\n");

        /* Perform CEU operation specified by ceu instance pointer and store image in buffer specified by image buffer pointer */
        err = ceu_operation(gp_ceu_instance, gp_image_buffer, g_image_width, g_image_height);

        show_img_display();

//        screen_display((uint16_t)X1_CO_ORDINATE, (uint16_t)Y1_CO_ORDINATE, g_hz_size, g_vr_size, &gp_image_buffer);
//        handle_error(err, " ** ceu_operation FAILED ** \r\n");
    }


#if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
#endif
}

/*******************************************************************************************************************//**
 * This function is called at various points during the startup process.  This implementation uses the event that is
 * called right before main() to set up the pins.
 *
 * @param[in]  event    Where at in the start up process the code is currently at
 **********************************************************************************************************************/
void R_BSP_WarmStart(bsp_warm_start_event_t event)
{
    if (BSP_WARM_START_RESET == event)
    {
#if BSP_FEATURE_FLASH_LP_VERSION != 0

        /* Enable reading from data flash. */
        R_FACI_LP->DFLCTL = 1U;

        /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
         * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
    }

    if (BSP_WARM_START_POST_C == event)
    {
        /* C runtime environment and system clocks are setup. */

        /* Configure pins. */
        R_IOPORT_Open (&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME);

#if BSP_CFG_SDRAM_ENABLED

        /* Setup SDRAM and initialize it. Must configure pins first. */
        R_BSP_SdramInit(true);
#endif
    }
}

#if BSP_TZ_SECURE_BUILD

FSP_CPP_HEADER
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{

}
FSP_CPP_FOOTER

#endif



static void screen_display(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color)
{
    /*Declare local variables */
    uint16_t start_x, start_y, display_length, display_height;
    uint32_t start_addr;

    /* Assign co-ordinate values and calculate start address */
    start_x = x1;
    start_y = y1;
    start_addr = (uint32_t)((start_x * BYTES_PER_PIXEL) + (start_y * g_hz_size* BYTES_PER_PIXEL));

    /* Calculate display box length and height */
    display_length = (uint16_t)((x2 - x1) * BYTES_PER_PIXEL);
    display_height = (y2 - y1);

    /* Display required color band */
    for(uint16_t ver_value = Y1_CO_ORDINATE; ver_value < (display_height - INC_DEC_VALUE); ver_value++)
    {
        for(uint32_t hor_value = start_addr; hor_value < (start_addr + display_length); hor_value += BYTES_PER_PIXEL)
        {
            *(uint32_t *) (g_p_single_buffer + hor_value) = color;
            *(uint32_t *) (g_p_double_buffer + hor_value) = color;
        }
        start_addr = (uint32_t)(start_addr + (g_hz_size * BYTES_PER_PIXEL));
    }
}

static void color_band_display(void)
{

    uint16_t color[COLOR_BAND_COUNT]= {RED, GREEN, BLUE, BLACK, WHITE, YELLOW, MAGENTA, CYAN};

    uint16_t width = g_vr_size/COLOR_BAND_COUNT;

    for (uint8_t display_count = RESET_VALUE; display_count < COLOR_BAND_COUNT; display_count++)
    {
       screen_display((uint16_t)X1_CO_ORDINATE, (display_count * width), g_hz_size, (uint16_t)(((display_count * width) + width) + INC_DEC_VALUE), color[display_count]);
    }


}
static void show_img_display(void)
{
//    uint16_t color[COLOR_BAND_COUNT]= {RED, GREEN, BLUE, BLACK, WHITE, YELLOW, MAGENTA, CYAN};

//    uint16_t width = g_vr_size/COLOR_BAND_COUNT;

    uint32_t gp_image_buffer_count = 0;

    for (uint16_t y_count = 0; y_count < g_image_height; y_count++)
    {
        for (uint16_t x_count = 0; x_count < g_image_width; x_count++)
       {

            screen_display((uint16_t)x_count, (uint16_t)y_count , (uint16_t)x_count+1, (uint16_t)(y_count + 2), ((gp_image_buffer[gp_image_buffer_count+1])<<8|(gp_image_buffer[gp_image_buffer_count])));
            gp_image_buffer_count = gp_image_buffer_count + 2;
       }

    }

}


image-20240830135633-5.jpeg  

这样显示出我们天花板的图像了,刷新还比较慢,后期应该可以通过其他方式给他加速。


回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表