/*
 *
 * Copyright (C) 2020 Kneron, Inc. All rights reserved.
 *
 */
 

#include <string.h>
#include <stdlib.h>
#include "cmsis_os2.h"
#include "kmdw_display.h"

#include "kmdw_console.h"

static int display_inited = 0;

void display_init(uint32_t input_fmt, uint16_t xres, uint16_t yres, uint8_t cam_idx)
{
    struct video_input_params params;

    if (display_inited == 0) {
        params.input_fmt = input_fmt;
        params.input_xres = xres;
        params.input_yres = yres;
        kmdw_video_renderer_open(&params);
        kmdw_video_renderer_set_camera(cam_idx);
        kmdw_display_set_pen_rgb565(BLACK, 1);
        kmdw_video_renderer_buffer_initialize(&params);
        kmdw_video_renderer_start();
        display_inited = 1;
        kmdw_printf("input_fmt=0x%x, input_xres=%d, input_yres=%d, cam_idx=%d \n",params.input_fmt, params.input_xres, params.input_yres, cam_idx);
    }
}

void display_exit(void)
{
    if (display_inited == 1) {
        kmdw_video_renderer_stop();
        display_inited = 0;
    }
}
