diff --git a/selfdrive/camerad/cameras/camera_qcom2.c b/selfdrive/camerad/cameras/camera_qcom2.c index 04416a706f..188807f342 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.c +++ b/selfdrive/camerad/cameras/camera_qcom2.c @@ -571,7 +571,8 @@ static void camera_init(CameraState *s, int camera_id, int camera_num, unsigned 0.0, 0.0, 1.0, }}; s->digital_gain = 1.0; - s->analog_gain_frac = 1.5; + s->digital_gain_pre = 4; // for WB + s->analog_gain_frac = 1.0; s->exposure_time = 598; } @@ -801,7 +802,7 @@ void cameras_init(DualCameraState *s) { camera_init(&s->front, CAMERA_ID_AR0231, 2, 20); printf("front initted \n"); #ifdef NOSCREEN - zsock_t *rgb_sock = zsock_new_push("tcp://192.168.2.221:7768"); + zsock_t *rgb_sock = zsock_new_push("tcp://192.168.5.1:7768"); assert(rgb_sock); s->rgb_sock = rgb_sock; #endif @@ -1006,15 +1007,18 @@ void camera_autoexposure(CameraState *s, float grey_frac) { // TODO: get stats from sensor const float target_grey = 0.3; - const float analog_gain_frac_min = 0.125; + const float analog_gain_frac_min = 0.25; const float analog_gain_frac_max = 8.0; + const float digital_gain_min = 1.0; + const float digital_gain_max = 3.99; // is the correct? const int exposure_time_min = 16; - const int exposure_time_max = 1417; // no slower than 1/25 sec. calculated from 0x300C and clock freq, changed + const int exposure_time_max = 1417; // no slower than 1/25 sec. calculated from 0x300C and clock freq float exposure_factor = pow(1.05, (target_grey - grey_frac) / 0.1 ); // TODO: to be calibrated - if (s->analog_gain_frac >= 8 && exposure_factor < 1) { // set gain down if full gain and over exposed + printf("cam %d grey_frac is %f, ef is %f\n", s->camera_num, grey_frac, exposure_factor); + if (s->analog_gain_frac >= 3 && exposure_factor < 1) { // set gain down if full gain and over exposed s->analog_gain_frac *= exposure_factor; } else if (s->exposure_time * exposure_factor <= exposure_time_max && s->exposure_time * exposure_factor >= exposure_time_min) { // adjust exposure time first s->exposure_time *= exposure_factor; @@ -1034,9 +1038,9 @@ void camera_autoexposure(CameraState *s, float grey_frac) { AG = AG * 4096 + AG * 256 + AG * 16 + AG; printf("cam %d gain_frac is %f, set AG to 0x%X, S to %d \n", s->camera_num, s->analog_gain_frac, AG, s->exposure_time); } - struct i2c_random_wr_payload exp_reg_array[] = {{0x3366, AG}, // analog gain - {0x305A, 0x00BB}, // RED_GAIN BB - {0x3058, 0x012A}, // BLUE_GAIN 12A + struct i2c_random_wr_payload exp_reg_array[] = {{0x3366, 0x1111}, // analog gain + {0x305A, 0x0075}, // RED_GAIN BB + {0x3058, 0x00FA}, // BLUE_GAIN 12A {0x3056, 0x0080}, // GREEN1_GAIN {0x305C, 0x0080}, // GREEN2_GAIN {0x3012, s->exposure_time}}; // integ time @@ -1071,9 +1075,23 @@ void camera_autoexposure(CameraState *s, float grey_frac) { } #ifdef NOSCREEN -void sendrgb(DualCameraState *s, void* dat, int len) { +void sendrgb(DualCameraState *s, uint8_t* dat, int len, uint8_t cam_id) { int err, err2; - err = zmq_send(zsock_resolve(s->rgb_sock), dat, len, ZMQ_DONTWAIT); + int scale = 3; + int old_width = FRAME_WIDTH / 2; + int old_height = FRAME_HEIGHT / 2; + int new_width = FRAME_WIDTH / 2 / scale; + int new_height = FRAME_HEIGHT / 2 / scale; + uint8_t resized_dat[new_width*new_height*3]; + memset(&resized_dat, cam_id, 3); + for (uint32_t r=1;rrgb_sock), &resized_dat, new_width*new_height*3, ZMQ_DONTWAIT); err2 = zmq_errno(); //printf("zmq errcode %d, %d\n", err ,err2); } diff --git a/selfdrive/camerad/cameras/camera_qcom2.h b/selfdrive/camerad/cameras/camera_qcom2.h index f8da638642..2265c6c961 100644 --- a/selfdrive/camerad/cameras/camera_qcom2.h +++ b/selfdrive/camerad/cameras/camera_qcom2.h @@ -29,6 +29,7 @@ typedef struct CameraState { int frame_size; float digital_gain; + int digital_gain_pre; float analog_gain_frac; int exposure_time; mat3 transform; @@ -63,15 +64,6 @@ typedef struct CameraState { struct cam_req_mgr_session_info req_mgr_session_info; - // static packet handles for runtime - uint32_t poke_cam_pkt_handle; - struct cam_packet *poke_cam_pkt; - uint32_t i2c_cam_pkt_handle; - struct cam_packet *i2c_cam_pkt; - struct cam_cmd_power *i2c_cam_pwr; - struct cam_packet *isp_cam_pkt; - uint32_t *isp_config_buf1; - } CameraState; typedef struct DualCameraState { @@ -96,7 +88,7 @@ void cameras_open(DualCameraState *s, VisionBuf *camera_bufs_rear, VisionBuf *ca void cameras_run(DualCameraState *s); void camera_autoexposure(CameraState *s, float grey_frac); #ifdef NOSCREEN -void sendrgb(DualCameraState *s, void* dat, int len); +void sendrgb(DualCameraState *s, uint8_t* dat, int len, uint8_t cam_id); #endif #ifdef __cplusplus diff --git a/selfdrive/camerad/cameras/sensor2_i2c.h b/selfdrive/camerad/cameras/sensor2_i2c.h index 28e151af9b..e2fead25c5 100644 --- a/selfdrive/camerad/cameras/sensor2_i2c.h +++ b/selfdrive/camerad/cameras/sensor2_i2c.h @@ -17,10 +17,10 @@ struct i2c_random_wr_payload init_array_ar0231[] = { {0x3506, 0x3333}, // RESERVED_MFR_3506 {0x3508, 0x3333}, // RESERVED_MFR_3508 {0x3100, 0x4000}, // DLO_CONTROL0 - {0x3280, 0x0FA0}, // RESERVED_MFR_3280 - {0x3282, 0x0FA0}, // RESERVED_MFR_3282 - {0x3284, 0x0FA0}, // RESERVED_MFR_3284 - {0x3286, 0x0FA0}, // RESERVED_MFR_3286 + {0x3280, 0x0CCC}, // RESERVED_MFR_3280 + {0x3282, 0x0CCC}, // RESERVED_MFR_3282 + {0x3284, 0x0CCC}, // RESERVED_MFR_3284 + {0x3286, 0x0CCC}, // RESERVED_MFR_3286 {0x3288, 0x0FA0}, // RESERVED_MFR_3288 {0x328A, 0x0FA0}, // RESERVED_MFR_328A {0x328C, 0x0FA0}, // RESERVED_MFR_328C @@ -274,7 +274,7 @@ struct i2c_random_wr_payload init_array_ar0231[] = { {0x30B0, 0x0800}, // DIGITAL_TEST {0x30A2, 0x0001}, // X_ODD_INC_ {0x30A6, 0x0001}, // Y_ODD_INC_ - {0x3040, 0xC000}, // READ_MODE + {0x3040, 0xC000}, // READ_MODE C000 {0x30BA, 0x11F2}, // DIGITAL_CTRL {0x3044, 0x0400}, // DARK_CONTROL {0x3064, 0x1802}, // SMIA_TEST @@ -284,9 +284,9 @@ struct i2c_random_wr_payload init_array_ar0231[] = { {0x33E0, 0x0C80}, // TEST_ASIL_ROWS {0x33E0, 0x0C80}, // TEST_ASIL_ROWS {0x3004, 0x0000}, // X_ADDR_START_ - {0x3008, 0x0787}, // X_ADDR_END_ + {0x3008, 0x0787}, // X_ADDR_END_ 787 {0x3002, 0x0000}, // Y_ADDR_START_ - {0x3006, 0x04B7}, // Y_ADDR_END_ + {0x3006, 0x04B7}, // Y_ADDR_END_ 4B7 {0x3032, 0x0000}, // SCALING_MODE {0x3400, 0x0010}, // RESERVED_MFR_3400 {0x3402, 0x0788}, // X_OUTPUT_CONTROL @@ -296,8 +296,8 @@ struct i2c_random_wr_payload init_array_ar0231[] = { {0x30BA, 0x11F3}, // DIGITAL_CTRL // FPS = 88e6 / 0x09C4 / 0x06E0 = 20 - {0x300C, 0x09B4}, // LINE_LENGTH_PCK_ - {0x300A, 0x06EB}, // FRAME_LENGTH_LINES_ + {0x300C, 0x09B4}, // LINE_LENGTH_PCK_ 9B4 + {0x300A, 0x06EB}, // FRAME_LENGTH_LINES_ 6EB {0x3042, 0x0000}, // EXTRA_DELAY // Readout Settings @@ -322,25 +322,27 @@ struct i2c_random_wr_payload init_array_ar0231[] = { // HDR Settings {0x3082, 0x0004}, // OPERATION_MODE_CTRL - {0x3238, 0x0444}, // EXPOSURE_RATIO + {0x3238, 0x0666}, // EXPOSURE_RATIO {0x3014, 0x098E}, // FINE_INTEGRATION_TIME_ {0x321E, 0x098E}, // FINE_INTEGRATION_TIME2 {0x3222, 0x098E}, // FINE_INTEGRATION_TIME3 - {0x3226, 0x098E}, // FINE_INTEGRATION_TIME4 + {0x3226, 0x098E}, // FINE_INTEGRATION_TIME4, 098E? {0x30B0, 0x0800}, // DIGITAL_TEST {0x32EA, 0x3C0E}, // RESERVED_MFR_32EA {0x32EC, 0x72A1}, // RESERVED_MFR_32EC - {0x31D0, 0x0001}, // COMPANDING - {0x3362, 0x0003}, // DC GAIN + {0x31D0, 0x0000}, // COMPANDING, no good in 10 bit? + //{0x33DA, 0x0001}, // COMPANDING + {0x3362, 0x0002}, // DC GAIN {0x3370, 0x0001}, // DBLC - {0x318E, 0x0100}, // PRE_HDR_GAIN_EN + {0x318E, 0x0200}, // PRE_HDR_GAIN_EN // Initial Gains {0x3022, 0x01}, // GROUPED_PARAMETER_HOLD_ - {0x3366, 0x9999}, // ANALOG_GAIN - {0x3060, 0xAAAA}, // ANALOG_COLOR_GAIN - {0x305A, 0x00BB}, // RED_GAIN - {0x3058, 0x012A}, // BLUE_GAIN + {0x3366, 0x7777}, // ANALOG_GAIN + //{0x3060, 0xAAAA}, // ANALOG_COLOR_GAIN + {0x3060, 0x5655}, // ANALOG_COLOR_GAIN + {0x305A, 0x0080}, // RED_GAIN + {0x3058, 0x0080}, // BLUE_GAIN {0x3056, 0x0080}, // GREEN1_GAIN {0x305C, 0x0080}, // GREEN2_GAIN {0x3022, 0x00}, // GROUPED_PARAMETER_HOLD_ diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index 298ac507ac..3e0d89dc5f 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -251,8 +251,8 @@ void* frontview_thread(void *arg) { } #ifdef NOSCREEN - if (frame_data.frame_id % 5 == 1) { - sendrgb(&s->cameras, (void*) s->rgb_front_bufs[rgb_idx].addr, s->rgb_front_bufs[rgb_idx].len); + if (frame_data.frame_id % 2 == 0) { + sendrgb(&s->cameras, (uint8_t*) s->rgb_front_bufs[rgb_idx].addr, s->rgb_front_bufs[rgb_idx].len, 2); } #endif @@ -475,8 +475,8 @@ void* wideview_thread(void *arg) { visionbuf_sync(&s->rgb_wide_bufs[rgb_idx], VISIONBUF_SYNC_FROM_DEVICE); #ifdef NOSCREEN - if (frame_data.frame_id % 5 == 0) { - //sendrgb(&s->cameras, (void*) s->rgb_wide_bufs[rgb_idx].addr, s->rgb_wide_bufs[rgb_idx].len); + if (frame_data.frame_id % 2 == 0) { + sendrgb(&s->cameras, (uint8_t*) s->rgb_wide_bufs[rgb_idx].addr, s->rgb_wide_bufs[rgb_idx].len, 1); } #endif @@ -539,10 +539,10 @@ void* wideview_thread(void *arg) { tbuffer_dispatch(&s->ui_wide_tb, ui_idx); // auto exposure over big box - const int exposure_x = 290; - const int exposure_y = 282 + 40; - const int exposure_height = 314; - const int exposure_width = 560; + const int exposure_x = 2;//290; + const int exposure_y = 200;//282 + 40; // TODO: fix this? should not use med imo + const int exposure_height = 250;// 314; + const int exposure_width = 450;//560; if (cnt % 3 == 0) { // find median box luminance for AE uint32_t lum_binning[256] = {0,}; @@ -645,8 +645,8 @@ void* processing_thread(void *arg) { visionbuf_sync(&s->rgb_bufs[rgb_idx], VISIONBUF_SYNC_FROM_DEVICE); #ifdef NOSCREEN - if (frame_data.frame_id % 5 == 2) { - //sendrgb(&s->cameras, (void*) s->rgb_bufs[rgb_idx].addr, s->rgb_bufs[rgb_idx].len); + if (frame_data.frame_id % 2 == 1) { + sendrgb(&s->cameras, (uint8_t*) s->rgb_bufs[rgb_idx].addr, s->rgb_bufs[rgb_idx].len, 0); } #endif @@ -856,10 +856,10 @@ void* processing_thread(void *arg) { tbuffer_dispatch(&s->ui_tb, ui_idx); // auto exposure over big box - const int exposure_x = 290; - const int exposure_y = 282 + 40; - const int exposure_height = 314; - const int exposure_width = 560; + const int exposure_x = 2; + const int exposure_y = 200;// + 40; + const int exposure_height = 250;// 314; + const int exposure_width = 450;//560; if (cnt % 3 == 0) { // find median box luminance for AE uint32_t lum_binning[256] = {0,};