/**
 * @file        host_mipi.h
 * @brief       macros and data structure for hico application of mipi camera
 * @version     0.1
 * @date        2021-09-30
 *
 * @copyright   Copyright (c) 2021 Kneron Inc. All rights reserved.
 */

#pragma once

/*
  === host image buffer layout ===

head_buf -> ---------------------------------------
            | buf_header_t                        | BUF_HEADER_SIZE
img_buf  -> |--------------------------------------
            |                                     |
            |                                     | 
            |                                     |
            |             image body              |
            |                                     |
            |                                     |
            |                                     |
            |-------------------------------------|

*/

#define MAX_NUM_CAMERA 4

enum user_cmd_e
{
    COMMAND_START_CAMERA = 0x1,
    COMMAND_SELECT_CAMERA = 0x2,
};

typedef struct
{
    kp_inference_header_stamp_t header_stamp;
    uint32_t cmd_id; // COMMAND_START_CAMERA
} __attribute__((aligned(4))) start_camera_cmd_t;

typedef struct
{
    uint32_t img_width;  // in pixel
    uint32_t img_height; // in pixel
    uint32_t img_format; // kp_image_format_t
    uint32_t img_channel;
    uint32_t img_buf_size;
} camera_settings_t;

typedef struct
{
    kp_inference_header_stamp_t header_stamp;
    uint32_t cmd_id; // COMMAND_START_CAMERA
    uint32_t num_cam_sensors;
    camera_settings_t cam_set[MAX_NUM_CAMERA];
} __attribute__((aligned(4))) start_camera_resp_t;

typedef struct
{
    kp_inference_header_stamp_t header_stamp;
    uint32_t cmd_id;     // COMMAND_SELECT_CAMERA
    uint32_t sel_camera; // camera selection index, start from 0
} __attribute__((aligned(4))) select_camera_cmd_t;

#define HICO_IMAGE_RECEIVER_HEADER_MAGIC 0x11223344 // should avoid KDP2_MAGIC_TYPE_XXXX values, indicating this is an image header

typedef struct
{
    uint32_t magic_type;     // HICO_IMAGE_RECEIVER_HEADER_MAGIC
    uint32_t img_buf_offset; // image buffer offset from this header
    uint32_t read_ref_count; // only used in FW, ignored by SW
    uint32_t cam_index;      // sensor_selection_e
#ifdef FW_BUILD
    kdp2_ipc_app_yolo_inf_header_t inf_header;
#endif
} __attribute__((aligned(4))) buf_header_t;
