Skip to content

Commit

Permalink
Setup IFE vignetting correction (commaai#33853)
Browse files Browse the repository at this point in the history
* vignetting

* lil more

* cleanup

---------

Co-authored-by: Comma Device <[email protected]>
  • Loading branch information
adeebshihadeh and Comma Device authored Oct 24, 2024
1 parent 8557b04 commit 719c634
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
24 changes: 5 additions & 19 deletions system/camerad/cameras/ife.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int build_update(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t> &patch
});

dst += write_cont(dst, 0x40, {
0x00000c04,
0x00000c04, // (1<<8) to enable vignetting correction
});

dst += write_cont(dst, 0x48, {
Expand Down Expand Up @@ -165,24 +165,10 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t
0xec4e4000,
0x0100c003,
});
/* TODO
cdm_dmi_cmd_t 444
.length = 883
.reserved = 33
.cmd = 10
.addr = 0
.DMIAddr = 3108
.DMISel = 14
*/
/* TODO
cdm_dmi_cmd_t 444
.length = 883
.reserved = 33
.cmd = 10
.addr = 0
.DMIAddr = 3108
.DMISel = 15
*/
dst += write_dmi(dst, &addr, 884, 0xc24, 14);
patches.push_back(addr - (uint64_t)start);
dst += write_dmi(dst, &addr, 884, 0xc24, 15);
patches.push_back(addr - (uint64_t)start);

// debayer
dst += write_cont(dst, 0x6f8, {
Expand Down
37 changes: 25 additions & 12 deletions system/camerad/cameras/spectra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,21 @@ void SpectraCamera::config_bps(int idx, int request_id) {
(void)request_id;
}

void add_patch(void *ptr, int n, int32_t dst_hdl, uint32_t dst_offset, int32_t src_hdl, uint32_t src_offset) {
struct cam_patch_desc *p = (struct cam_patch_desc *)((unsigned char*)ptr + sizeof(struct cam_patch_desc)*n);
p->dst_buf_hdl = dst_hdl;
p->src_buf_hdl = src_hdl;
p->dst_offset = dst_offset;
p->src_offset = src_offset;
};

void SpectraCamera::config_ife(int idx, int request_id, bool init) {
/*
Handles initial + per-frame IFE config.
* IFE = Image Front End
*/
int size = sizeof(struct cam_packet) + sizeof(struct cam_cmd_buf_desc)*2;
size += sizeof(struct cam_patch_desc)*4;
size += sizeof(struct cam_patch_desc)*10;
if (!init) {
size += sizeof(struct cam_buf_io_cfg);
}
Expand Down Expand Up @@ -632,23 +640,24 @@ void SpectraCamera::config_ife(int idx, int request_id, bool init) {
// *** patches ***
// sets up the kernel driver to do address translation for the IFE
{
// order here corresponds to the one in build_initial_config
assert(patches.size() == 6 || patches.size() == 0);

pkt->num_patches = patches.size();
pkt->patch_offset = sizeof(struct cam_cmd_buf_desc)*pkt->num_cmd_buf + sizeof(struct cam_buf_io_cfg)*pkt->num_io_configs;
if (pkt->num_patches > 0) {
void *p = (char*)&pkt->payload + pkt->patch_offset;

// linearization LUT
struct cam_patch_desc *patch = (struct cam_patch_desc *)((char*)&pkt->payload + pkt->patch_offset);
patch->dst_buf_hdl = ife_cmd.handle;
patch->src_buf_hdl = ife_linearization_lut.handle;
patch->dst_offset = patches[0];
patch->src_offset = 0;
add_patch(p, 0, ife_cmd.handle, patches[0], ife_linearization_lut.handle, 0);

// vignetting correction LUTs
add_patch(p, 1, ife_cmd.handle, patches[1], ife_vignetting_lut.handle, 0);
add_patch(p, 2, ife_cmd.handle, patches[2], ife_vignetting_lut.handle, ife_vignetting_lut.size);

// gamma LUT
// gamma LUTs
for (int i = 0; i < 3; i++) {
patch = (struct cam_patch_desc *)((char*)&pkt->payload + pkt->patch_offset + sizeof(cam_patch_desc)*(i+1));
patch->dst_buf_hdl = ife_cmd.handle;
patch->src_buf_hdl = ife_gamma_lut.handle;
patch->dst_offset = patches[i+1];
patch->src_offset = ife_gamma_lut.size*i;
add_patch(p, i+3, ife_cmd.handle, patches[i+3], ife_gamma_lut.handle, ife_gamma_lut.size*i);
}
}
}
Expand Down Expand Up @@ -873,6 +882,10 @@ void SpectraCamera::configISP() {
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu);
memcpy(ife_linearization_lut.ptr, sensor->linearization_lut.data(), ife_linearization_lut.size);
ife_vignetting_lut.init(m, sensor->vignetting_lut.size(), 0x20,
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu, 2);
memcpy(ife_vignetting_lut.ptr, sensor->vignetting_lut.data(), ife_vignetting_lut.size*2);
}

config_ife(0, 1, true);
Expand Down
1 change: 1 addition & 0 deletions system/camerad/cameras/spectra.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class SpectraCamera {
SpectraBuf ife_cmd;
SpectraBuf ife_gamma_lut;
SpectraBuf ife_linearization_lut;
SpectraBuf ife_vignetting_lut;

SpectraBuf bps_cmd;
SpectraBuf bps_cdm_buffer;
Expand Down
3 changes: 3 additions & 0 deletions system/camerad/sensors/ox03c10.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ OX03C10::OX03C10() {
for (int i = 0; i < 288; i++) {
linearization_lut.push_back(0xff);
}
for (int i = 0; i < 884*2; i++) {
vignetting_lut.push_back(0xff);
}
}

std::vector<i2c_random_wr_payload> OX03C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const {
Expand Down
1 change: 1 addition & 0 deletions system/camerad/sensors/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SensorInfo {
std::vector<uint32_t> color_correct_matrix; // 3x3
std::vector<uint32_t> gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here
std::vector<uint32_t> linearization_lut; // length 288
std::vector<uint32_t> vignetting_lut; // 2x length 884
};

class AR0231 : public SensorInfo {
Expand Down

0 comments on commit 719c634

Please sign in to comment.