open source driving agent
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.0 KiB

#pragma once
#include <cstdint>
#include <map>
#include <utility>
#include <media/cam_req_mgr.h>
#include "system/camerad/cameras/camera_common.h"
#include "common/params.h"
#include "common/util.h"
#define FRAME_BUF_COUNT 4
class MemoryManager {
public:
void init(int _video0_fd) { video0_fd = _video0_fd; }
void *alloc(int len, uint32_t *handle);
void free(void *ptr);
~MemoryManager();
private:
std::mutex lock;
std::map<void *, uint32_t> handle_lookup;
std::map<void *, int> size_lookup;
std::map<int, std::queue<void *> > cached_allocations;
int video0_fd;
};
class CameraState {
public:
MultiCameraState *multi_cam_state;
CameraInfo ci;
bool enabled;
std::mutex exp_lock;
int exposure_time;
bool dc_gain_enabled;
port OX03C10 (#25161) * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * unbroken AE * oops * sort of good AE * both should work 1 * open then init * fix debayer * rename * fix test build Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: ZwX1616 <zwx1616@gmail.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
int dc_gain_weight;
int gain_idx;
float analog_gain_frac;
port OX03C10 (#25161) * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * unbroken AE * oops * sort of good AE * both should work 1 * open then init * fix debayer * rename * fix test build Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: ZwX1616 <zwx1616@gmail.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
int exposure_time_min;
int exposure_time_max;
float dc_gain_factor;
int dc_gain_max_weight;
float dc_gain_on_grey;
float dc_gain_off_grey;
float sensor_analog_gains[16];
int analog_gain_min_idx;
int analog_gain_max_idx;
int analog_gain_rec_idx;
float cur_ev[3];
float min_ev, max_ev;
float measured_grey_fraction;
float target_grey_fraction;
unique_fd sensor_fd;
unique_fd csiphy_fd;
int camera_num;
void handle_camera_event(void *evdat);
void set_camera_exposure(float grey_frac);
void sensors_start();
port OX03C10 (#25161) * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * start porting OS04C10 * something * is the pll why this doesn't work * understand plls, still doesn't work * work * weee something * working? * timing * encoderd works with less cameras * 1928 * flip image * color balance * adjust black level * extra height maybe * cleanups * clean up sensor i2c * sensors * approx 20fps * remove mirror * 50ms, no fsin yet * remove imx390 support * some attempt at AE * linearize the response * OX changes (#25697) * organize * wb * best effort but probably messed up by artifacts * multicam sync Co-authored-by: Comma Device <device@comma.ai> * clean up * more * fix multiexposure * unbroken AE * oops * sort of good AE * both should work 1 * open then init * fix debayer * rename * fix test build Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: ZwX1616 <zwx1616@gmail.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
void camera_open(MultiCameraState *multi_cam_state, int camera_num, bool enabled);
void camera_set_parameters();
void camera_map_bufs(MultiCameraState *s);
void camera_init(MultiCameraState *s, VisionIpcServer *v, int camera_id, unsigned int fps, cl_device_id device_id, cl_context ctx, VisionStreamType yuv_type);
void camera_close();
std::map<uint16_t, uint16_t> ar0231_parse_registers(uint8_t *data, std::initializer_list<uint16_t> addrs);
int32_t session_handle;
int32_t sensor_dev_handle;
int32_t isp_dev_handle;
int32_t csiphy_dev_handle;
int32_t link_handle;
int buf0_handle;
int buf_handle[FRAME_BUF_COUNT];
int sync_objs[FRAME_BUF_COUNT];
int request_ids[FRAME_BUF_COUNT];
int request_id_last;
int frame_id_last;
int idx_offset;
bool skipped;
int camera_id;
CameraBuf buf;
MemoryManager mm;
private:
void config_isp(int io_mem_handle, int fence, int request_id, int buf0_mem_handle, int buf0_offset);
void enqueue_req_multi(int start, int n, bool dp);
void enqueue_buffer(int i, bool dp);
int clear_req_queue();
int sensors_init();
void sensors_poke(int request_id);
void sensors_i2c(struct i2c_random_wr_payload* dat, int len, int op_code, bool data_word);
// Register parsing
std::map<uint16_t, std::pair<int, int>> ar0231_register_lut;
std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(uint8_t *data);
};
typedef struct MultiCameraState {
unique_fd video0_fd;
unique_fd cam_sync_fd;
unique_fd isp_fd;
int device_iommu;
int cdm_iommu;
CameraState road_cam;
CameraState wide_road_cam;
CameraState driver_cam;
PubMaster *pm;
} MultiCameraState;