|
|
|
@ -46,13 +46,7 @@ int CameraState::clear_req_queue() { |
|
|
|
|
void CameraState::sensors_start() { |
|
|
|
|
if (!enabled) return; |
|
|
|
|
LOGD("starting sensor %d", camera_num); |
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
sensors_i2c(start_reg_array_ar0231, std::size(start_reg_array_ar0231), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, true); |
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
|
sensors_i2c(start_reg_array_ox03c10, std::size(start_reg_array_ox03c10), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, false); |
|
|
|
|
} else { |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
sensors_i2c(ci->start_reg_array.data(), ci->start_reg_array.size(), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, ci->data_word); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraState::sensors_poke(int request_id) { |
|
|
|
@ -112,6 +106,8 @@ static cam_cmd_power *power_set_wait(cam_cmd_power *power, int16_t delay_ms) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int CameraState::sensors_init() { |
|
|
|
|
create_sensor(); |
|
|
|
|
|
|
|
|
|
uint32_t cam_packet_handle = 0; |
|
|
|
|
int size = sizeof(struct cam_packet)+sizeof(struct cam_cmd_buf_desc)*2; |
|
|
|
|
auto pkt = mm.alloc<struct cam_packet>(size, &cam_packet_handle); |
|
|
|
@ -127,21 +123,7 @@ int CameraState::sensors_init() { |
|
|
|
|
auto probe = (struct cam_cmd_probe *)(i2c_info.get() + 1); |
|
|
|
|
|
|
|
|
|
probe->camera_id = camera_num; |
|
|
|
|
switch (camera_num) { |
|
|
|
|
case 0: |
|
|
|
|
// port 0
|
|
|
|
|
i2c_info->slave_addr = (camera_id == CAMERA_ID_AR0231) ? 0x20 : 0x6C; // 6C = 0x36*2
|
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
// port 1
|
|
|
|
|
i2c_info->slave_addr = (camera_id == CAMERA_ID_AR0231) ? 0x30 : 0x20; |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
// port 2
|
|
|
|
|
i2c_info->slave_addr = (camera_id == CAMERA_ID_AR0231) ? 0x20 : 0x6C; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
i2c_info->slave_addr = ci->getSlaveAddress(camera_num); |
|
|
|
|
// 0(I2C_STANDARD_MODE) = 100khz, 1(I2C_FAST_MODE) = 400khz
|
|
|
|
|
//i2c_info->i2c_freq_mode = I2C_STANDARD_MODE;
|
|
|
|
|
i2c_info->i2c_freq_mode = I2C_FAST_MODE; |
|
|
|
@ -151,15 +133,8 @@ int CameraState::sensors_init() { |
|
|
|
|
probe->addr_type = CAMERA_SENSOR_I2C_TYPE_WORD; |
|
|
|
|
probe->op_code = 3; // don't care?
|
|
|
|
|
probe->cmd_type = CAMERA_SENSOR_CMD_TYPE_PROBE; |
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
probe->reg_addr = 0x3000; |
|
|
|
|
probe->expected_data = 0x354; |
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
|
probe->reg_addr = 0x300a; |
|
|
|
|
probe->expected_data = 0x5803; |
|
|
|
|
} else { |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
probe->reg_addr = ci->probe_reg_addr; |
|
|
|
|
probe->expected_data = ci->probe_expected_data; |
|
|
|
|
probe->data_mask = 0; |
|
|
|
|
|
|
|
|
|
//buf_desc[1].size = buf_desc[1].length = 148;
|
|
|
|
@ -182,7 +157,7 @@ int CameraState::sensors_init() { |
|
|
|
|
power->count = 1; |
|
|
|
|
power->cmd_type = CAMERA_SENSOR_CMD_TYPE_PWR_UP; |
|
|
|
|
power->power_settings[0].power_seq_type = 0; |
|
|
|
|
power->power_settings[0].config_val_low = (camera_id == CAMERA_ID_AR0231) ? 19200000 : 24000000; //Hz
|
|
|
|
|
power->power_settings[0].config_val_low = ci->power_config_val_low; |
|
|
|
|
power = power_set_wait(power, 1); |
|
|
|
|
|
|
|
|
|
// reset high
|
|
|
|
@ -428,7 +403,7 @@ void CameraState::enqueue_req_multi(int start, int n, bool dp) { |
|
|
|
|
|
|
|
|
|
// ******************* camera *******************
|
|
|
|
|
|
|
|
|
|
void CameraState::camera_set_parameters() { |
|
|
|
|
void CameraState::create_sensor() { |
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
ci = std::make_unique<AR0231>(); |
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
@ -504,8 +479,6 @@ void CameraState::camera_open(MultiCameraState *multi_cam_state_, int camera_num |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
camera_set_parameters(); |
|
|
|
|
|
|
|
|
|
// create session
|
|
|
|
|
struct cam_req_mgr_session_info session_info = {}; |
|
|
|
|
ret = do_cam_control(multi_cam_state->video0_fd, CAM_REQ_MGR_CREATE_SESSION, &session_info, sizeof(session_info)); |
|
|
|
@ -520,18 +493,8 @@ void CameraState::camera_open(MultiCameraState *multi_cam_state_, int camera_num |
|
|
|
|
LOGD("acquire sensor dev"); |
|
|
|
|
|
|
|
|
|
LOG("-- Configuring sensor"); |
|
|
|
|
uint32_t dt; |
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
sensors_i2c(init_array_ar0231, std::size(init_array_ar0231), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, true); |
|
|
|
|
dt = 0x12; // Changing stats to 0x2C doesn't work, so change pixels to 0x12 instead
|
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
|
sensors_i2c(init_array_ox03c10, std::size(init_array_ox03c10), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, false); |
|
|
|
|
// one is 0x2a, two are 0x2b
|
|
|
|
|
dt = 0x2c; |
|
|
|
|
} else { |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
printf("dt is %x\n", dt); |
|
|
|
|
sensors_i2c(ci->init_reg_array.data(), ci->init_reg_array.size(), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, ci->data_word); |
|
|
|
|
printf("dt is %x\n", ci->in_port_info_dt); |
|
|
|
|
|
|
|
|
|
// NOTE: to be able to disable road and wide road, we still have to configure the sensor over i2c
|
|
|
|
|
// If you don't do this, the strobe GPIO is an output (even in reset it seems!)
|
|
|
|
@ -545,7 +508,7 @@ void CameraState::camera_open(MultiCameraState *multi_cam_state_, int camera_num |
|
|
|
|
.lane_cfg = 0x3210, |
|
|
|
|
|
|
|
|
|
.vc = 0x0, |
|
|
|
|
.dt = dt, |
|
|
|
|
.dt = ci->in_port_info_dt, |
|
|
|
|
.format = CAM_FORMAT_MIPI_RAW_12, |
|
|
|
|
|
|
|
|
|
.test_pattern = 0x2, // 0x3?
|
|
|
|
@ -839,22 +802,7 @@ void CameraState::handle_camera_event(void *evdat) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraState::update_exposure_score(float desired_ev, int exp_t, int exp_g_idx, float exp_gain) { |
|
|
|
|
float score = 1e6; |
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
// Cost of ev diff
|
|
|
|
|
score = std::abs(desired_ev - (exp_t * exp_gain)) * 10; |
|
|
|
|
// Cost of absolute gain
|
|
|
|
|
float m = exp_g_idx > ci->analog_gain_rec_idx ? ci->analog_gain_cost_high : ci->analog_gain_cost_low; |
|
|
|
|
score += std::abs(exp_g_idx - (int)ci->analog_gain_rec_idx) * m; |
|
|
|
|
// Cost of changing gain
|
|
|
|
|
score += std::abs(exp_g_idx - gain_idx) * (score + 1.0) / 10.0; |
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
|
score = std::abs(desired_ev - (exp_t * exp_gain)); |
|
|
|
|
float m = exp_g_idx > ci->analog_gain_rec_idx ? ci->analog_gain_cost_high : ci->analog_gain_cost_low; |
|
|
|
|
score += std::abs(exp_g_idx - (int)ci->analog_gain_rec_idx) * m; |
|
|
|
|
score += ((1 - ci->analog_gain_cost_delta) + ci->analog_gain_cost_delta * (exp_g_idx - ci->analog_gain_min_idx) / (ci->analog_gain_max_idx - ci->analog_gain_min_idx)) * std::abs(exp_g_idx - gain_idx) * 5.0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float score = ci->getExposureScore(desired_ev, exp_t, exp_g_idx, exp_gain, gain_idx); |
|
|
|
|
if (score < best_ev_score) { |
|
|
|
|
new_exp_t = exp_t; |
|
|
|
|
new_exp_g = exp_g_idx; |
|
|
|
@ -960,13 +908,8 @@ void CameraState::set_camera_exposure(float grey_frac) { |
|
|
|
|
} |
|
|
|
|
// LOGE("ae - camera %d, cur_t %.5f, sof %.5f, dt %.5f", camera_num, 1e-9 * nanos_since_boot(), 1e-9 * buf.cur_frame_data.timestamp_sof, 1e-9 * (nanos_since_boot() - buf.cur_frame_data.timestamp_sof));
|
|
|
|
|
|
|
|
|
|
if (camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
auto exp_reg_array = ar0231_get_exp_registers(ci.get(), exposure_time, new_exp_g, dc_gain_enabled); |
|
|
|
|
sensors_i2c(exp_reg_array.data(), exp_reg_array.size(), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, true); |
|
|
|
|
} else if (camera_id == CAMERA_ID_OX03C10) { |
|
|
|
|
auto exp_reg_array = ox03c10_get_exp_registers(ci.get(), exposure_time, new_exp_g, dc_gain_enabled); |
|
|
|
|
sensors_i2c(exp_reg_array.data(), exp_reg_array.size(), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, false); |
|
|
|
|
} |
|
|
|
|
auto exp_reg_array = ci->getExposureRegisters(exposure_time, new_exp_g, dc_gain_enabled); |
|
|
|
|
sensors_i2c(exp_reg_array.data(), exp_reg_array.size(), CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG, ci->data_word); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) { |
|
|
|
@ -977,9 +920,7 @@ static void process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) |
|
|
|
|
framed.setFrameType(cereal::FrameData::FrameType::FRONT); |
|
|
|
|
fill_frame_data(framed, c->buf.cur_frame_data, c); |
|
|
|
|
|
|
|
|
|
if (c->camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
ar0231_process_registers(s, c, framed); |
|
|
|
|
} |
|
|
|
|
c->ci->processRegisters(s, c, framed); |
|
|
|
|
s->pm->send("driverCameraState", msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -994,10 +935,7 @@ void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) { |
|
|
|
|
} |
|
|
|
|
LOGT(c->buf.cur_frame_data.frame_id, "%s: Image set", c == &s->road_cam ? "RoadCamera" : "WideRoadCamera"); |
|
|
|
|
|
|
|
|
|
if (c->camera_id == CAMERA_ID_AR0231) { |
|
|
|
|
ar0231_process_registers(s, c, framed); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c->ci->processRegisters(s, c, framed); |
|
|
|
|
s->pm->send(c == &s->road_cam ? "roadCameraState" : "wideRoadCameraState", msg); |
|
|
|
|
|
|
|
|
|
const auto [x, y, w, h] = (c == &s->wide_road_cam) ? std::tuple(96, 250, 1734, 524) : std::tuple(96, 160, 1734, 986); |
|
|
|
|