C && FreeRTOS 开发 K210(MaixBit)

MaxiBit FreeRTOS 适配 ov2640

省流:完整工程

  • 引脚定义
const fpioa_cfg_t g_fpioa_cfg =
{
    .version = PIN_CFG_VERSION,
    .functions_count = 11,
    .functions =
    {
        {DCX_IO, FUNC_GPIOHS0 + DCX_GPIONUM},
        {36, SPI_SS},
        {39, SPI(SCLK)},
        {42, FUNC_CMOS_RST},
        {44, FUNC_CMOS_PWDN},
        {41, FUNC_SCCB_SCLK},
        {40, FUNC_SCCB_SDA},
        {46, FUNC_CMOS_XCLK},
        {43, FUNC_CMOS_VSYNC},
        {45, FUNC_CMOS_HREF},
        {47, FUNC_CMOS_PCLK}
    }
};
  • OV2640寄存器配置
    选择的是VGA 和 RGB565 ,
具体配置见ov2640cfg.h

-初始化sccb

    file_sccb = io_open("/dev/sccb0");
    file_OV2640 = sccb_get_device(file_sccb, OV2640_ADDR, REGLENGTH);
  • 初始化dvp
    lcd_gram0 = (uint16_t *)iomem_malloc(320*240*2);
    lcd_gram1 = (uint16_t *)iomem_malloc(320*240*2);
    file_dvp = io_open("/dev/dvp0");
    configASSERT(file_dvp);
    sensor_restart();
    dvp_xclk_set_clock_rate(file_dvp, 20000000); /* 20MHz XCLK*/
    dvp_config(file_dvp, DVP_WIDTH, DVP_HIGHT, DISABLE);

    dvp_set_output_enable(file_dvp, DATA_FOR_AI, ENABLE);
    dvp_set_output_enable(file_dvp, DATA_FOR_DISPLAY, ENABLE);

    dvp_set_output_attributes(file_dvp, DATA_FOR_DISPLAY, VIDEO_FMT_RGB565, (void*)lcd_gram0);

    dvp_set_output_attributes(file_dvp, DATA_FOR_AI, VIDEO_FMT_RGB24_PLANAR, (void*)0x40600000);

    dvp_set_frame_event_enable(file_dvp, VIDEO_FE_END, DISABLE);
    dvp_set_frame_event_enable(file_dvp, VIDEO_FE_BEGIN, DISABLE);

    dvp_set_on_frame_event(file_dvp, on_irq_dvp, NULL);

    dvp_set_frame_event_enable(file_dvp, VIDEO_FE_END, ENABLE);
    dvp_set_frame_event_enable(file_dvp, VIDEO_FE_BEGIN, ENABLE);

-初始化LCD

    uint8_t data;

    tft_hard_init();
    // soft reset
    tft_write_command(SOFTWARE_RESET);
    usleep(100*1000);
    // exit sleep
    tft_write_command(SLEEP_OFF);
    usleep(100*1000);
    // pixel format
    tft_write_command(PIXEL_FORMAT_SET);
    data = 0x55;
    tft_write_byte(&data, 1);
    lcd_set_direction(DIR_YX_RLUD);
    tft_write_command(DISPALY_ON);
  • 创建任务
    xTaskCreate(vTask1, "vTask1", 1024, NULL, 3, NULL);
    void vTask1()
	{
	    while (1)
	    {
	        while (dvp_finish_flag == 0)
	            ;
	        dvp_finish_flag = 0;
	        lcd_draw_picture(0, 0, 320, 240, gram_mux ? lcd_gram1 : lcd_gram0);
	        printf("%x\n", *(lcd_gram0+5));
	        gram_mux ^= 0x01;
	    }
	}
  • 主代码
int main(void)
{
    printf("lcd init\n");
    lcd_init();
   // lcd_draw_picture(0, 0, 240, 240, imgArray);
    printf("DVP init\n");

    dvp_init();
    OV2640_init();
    printf("Init Finish!\n");

    xTaskCreate(vTask1, "vTask1", 1024, NULL, 3, NULL);
    vTaskDelete(NULL);
}

PS:
/dev/sccb等外设出处
文件位于 lib\bsp\device\registry.cpp

driver_registry_t sys::g_system_drivers[] = {
    { "/dev/uart1", { std::in_place, &g_uart_driver_uart0 } },
    { "/dev/uart2", { std::in_place, &g_uart_driver_uart1 } },
    { "/dev/uart3", { std::in_place, &g_uart_driver_uart2 } },

    { "/dev/gpio0", { std::in_place, &g_gpiohs_driver_gpio0 } },
    { "/dev/gpio1", { std::in_place, &g_gpio_driver_gpio0 } },

    { "/dev/i2c0", { std::in_place, &g_i2c_driver_i2c0 } },
    { "/dev/i2c1", { std::in_place, &g_i2c_driver_i2c1 } },
    { "/dev/i2c2", { std::in_place, &g_i2c_driver_i2c2 } },

    { "/dev/i2s0", { std::in_place, &g_i2s_driver_i2s0 } },
    { "/dev/i2s1", { std::in_place, &g_i2s_driver_i2s1 } },
    { "/dev/i2s2", { std::in_place, &g_i2s_driver_i2s2 } },

    { "/dev/spi0", { std::in_place, &g_spi_driver_spi0 } },
    { "/dev/spi1", { std::in_place, &g_spi_driver_spi1 } },
    { "/dev/spi_slave", { std::in_place, &g_spi_driver_spi_slave } },
    { "/dev/spi3", { std::in_place, &g_spi_driver_spi3 } },

    { "/dev/sccb0", { std::in_place, &g_sccb_driver_sccb0 } },

    { "/dev/dvp0", { std::in_place, &g_dvp_driver_dvp0 } },

    { "/dev/fft0", { std::in_place, &g_fft_driver_fft0 } },

    { "/dev/aes0", { std::in_place, &g_aes_driver_aes0 } },

    { "/dev/sha256", { std::in_place, &g_sha_driver_sha256 } },

    { "/dev/timer0", { std::in_place, &g_timer_driver_timer0 } },
    { "/dev/timer1", { std::in_place, &g_timer_driver_timer1 } },
    { "/dev/timer2", { std::in_place, &g_timer_driver_timer2 } },
    { "/dev/timer3", { std::in_place, &g_timer_driver_timer3 } },
    { "/dev/timer4", { std::in_place, &g_timer_driver_timer4 } },
    { "/dev/timer5", { std::in_place, &g_timer_driver_timer5 } },
    { "/dev/timer6", { std::in_place, &g_timer_driver_timer6 } },
    { "/dev/timer7", { std::in_place, &g_timer_driver_timer7 } },
    { "/dev/timer8", { std::in_place, &g_timer_driver_timer8 } },
    { "/dev/timer9", { std::in_place, &g_timer_driver_timer9 } },
    { "/dev/timer10", { std::in_place, &g_timer_driver_timer10 } },
    { "/dev/timer11", { std::in_place, &g_timer_driver_timer11 } },

    { "/dev/pwm0", { std::in_place, &g_pwm_driver_pwm0 } },
    { "/dev/pwm1", { std::in_place, &g_pwm_driver_pwm1 } },
    { "/dev/pwm2", { std::in_place, &g_pwm_driver_pwm2 } },

    { "/dev/wdt0", { std::in_place, &g_wdt_driver_wdt0 } },
    { "/dev/wdt1", { std::in_place, &g_wdt_driver_wdt1 } },

    { "/dev/rtc0", { std::in_place, &g_rtc_driver_rtc0 } },
    { "/dev/kpu0", { std::in_place, &g_kpu_driver_kpu0 } },
    {}
};
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值