/*
 * Kneron MZT Display Panel driver
 *
 * Copyright (C) 2019 Kneron, Inc. All rights reserved.
 *
 */
#include "kdev_panel.h"
#include "kdrv_lcdc.h"

#ifdef KDP_UVC
#define MZT_PANEL_WIDTH     640
#define MZT_PANEL_HEIGHT    800
#else
#define MZT_PANEL_WIDTH     TFT43_WIDTH
#define MZT_PANEL_HEIGHT    TFT43_HEIGHT
#endif

kdev_status_t kdev_panel_initialize(kdrv_display_t *display_drv)
{
    if(display_drv == NULL)
        return KDEV_STATUS_ERROR;

    u16 hor_no_in = display_drv->vi_params.input_xres;
    u16 ver_no_in = display_drv->vi_params.input_yres;
    u16 hor_no_out = MZT_PANEL_WIDTH;
    u16 ver_no_out = MZT_PANEL_HEIGHT;

    kdrv_lcdc_set_panel_type(KDRV_LCDC_6BIT_PER_CHANNEL);
    kdrv_lcdc_set_bgrsw(KDRV_LCDC_OUTPUT_FMT_RGB);

    //serial panel pixel
    kdrv_lcdc_set_auo052_mode(KDRV_LCDC_AUO052_OFF);
    kdrv_lcdc_set_pixel_sr(KDRV_LCDC_SERIAL_PIX_RSR);
    kdrv_lcdc_set_pixel_colorseq(KDRV_LCDC_SERIAL_PIX_COLORSEQ_GBR);
    kdrv_lcdc_set_pixel_delta_type(KDRV_LCDC_SERIAL_PIX_DELTA_TYPE_SAME_SEQ);
    kdrv_lcdc_set_pixel_serial_mode(KDRV_LCDC_SERIAL_PIX_RGB_PARALLEL_OUTPUT);

    kdrv_lcdc_set_framerate(60, hor_no_out, ver_no_out);
    kdrv_lcdc_set_endian(KDRV_LCDC_FB_DATA_ENDIAN_LBLP);
    kdrv_lcdc_set_image_color_params(0x2000, 0x2000, 0x0, 0x40000);
    kdrv_lcdc_set_frame_buffer(0x00);
    kdrv_lcdc_set_bus_bandwidth_ctrl(0x00);
    kdrv_lcdc_down_scale(hor_no_in, hor_no_out, ver_no_in, ver_no_out);
    return KDEV_STATUS_OK;
}

kdev_status_t kdev_panel_clear(kdrv_display_t *display_drv, u32 color)
{
    if(display_drv == NULL)
        return KDEV_STATUS_ERROR;
 
    return KDEV_STATUS_OK;
}

uint16_t kdev_panel_read_display_id(kdrv_display_t *display_drv)
{
    if(display_drv == NULL)
        return 0xFFFF;

    return KDEV_STATUS_OK;
}

kdev_status_t kdev_panel_refresh(kdrv_display_t* display_drv)
{
    if(display_drv == NULL)
        return KDEV_STATUS_ERROR;

    return KDEV_STATUS_OK;
}

