Merge pull request #2811 from openmv/refactor_resolution
Some checks are pending
🔥 Firmware Build / build-firmware (ARDUINO_GIGA) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NANO_33_BLE_SENSE) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NANO_RP2040_CONNECT) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NICLA_VISION) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_PORTENTA_H7) (push) Waiting to run
🔥 Firmware Build / build-firmware (DOCKER) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV2) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV3) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV4) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV4P) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMVPT) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV_AE3) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV_N6) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV_RT1060) (push) Waiting to run
🔥 Firmware Build / code-size-report (push) Blocked by required conditions
🔥 Firmware Build / stable-release (push) Blocked by required conditions
🔥 Firmware Build / development-release (push) Blocked by required conditions

common/csi: Refactor resolution table.
This commit is contained in:
Ibrahim Abdelkader 2025-08-14 19:59:39 +03:00 committed by GitHub
commit 57c6addc76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 110 additions and 92 deletions

View File

@ -75,8 +75,11 @@ typedef struct _i2c_dev {
uint32_t chip_id; // Chip ID.
} i2c_dev_t;
// Sensor frame size/resolution table.
uint16_t resolution[][2] = {
static omv_i2c_t csi_i2c;
static omv_clk_t csi_clk;
// Standard resolution table;
static uint16_t csi_resolution[][2] = {
[OMV_CSI_FRAMESIZE_INVALID] = {0, 0},
[OMV_CSI_FRAMESIZE_CUSTOM] = {0, 0},
// C/SIF Resolutions
@ -123,8 +126,6 @@ uint16_t resolution[][2] = {
[OMV_CSI_FRAMESIZE_WQXGA2] = {2592, 1944},
};
static omv_i2c_t csi_i2c;
static omv_clk_t csi_clk;
omv_csi_t csi_all[OMV_CSI_MAX_DEVICES] = {0};
__weak void omv_csi_init0() {
@ -186,6 +187,7 @@ __weak int omv_csi_init() {
csi->clk = &csi_clk;
csi->fb = framebuffer_get(-1);
csi->color_palette = rainbow_table;
memcpy(csi->resolution, csi_resolution, sizeof(csi_resolution));
omv_csi_ops_init(csi);
// Configure the csi external clock (XCLK).
@ -821,11 +823,11 @@ __weak int omv_csi_set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize)
csi->fb->x = 0;
csi->fb->y = 0;
// Set width and height.
csi->fb->w = resolution[framesize][0];
csi->fb->h = resolution[framesize][1];
csi->fb->w = csi->resolution[framesize][0];
csi->fb->h = csi->resolution[framesize][1];
// Set backup width and height.
csi->fb->u = resolution[framesize][0];
csi->fb->v = resolution[framesize][1];
csi->fb->u = csi->resolution[framesize][0];
csi->fb->v = csi->resolution[framesize][1];
// Reset pixel format to skip the first frame.
csi->fb->pixfmt = PIXFORMAT_INVALID;
@ -880,8 +882,8 @@ __weak bool omv_csi_get_cropped(omv_csi_t *csi) {
if (csi->framesize != OMV_CSI_FRAMESIZE_INVALID) {
return (csi->fb->x != 0) ||
(csi->fb->y != 0) ||
(csi->fb->u != resolution[csi->framesize][0]) ||
(csi->fb->v != resolution[csi->framesize][1]);
(csi->fb->u != csi->resolution[csi->framesize][0]) ||
(csi->fb->v != csi->resolution[csi->framesize][1]);
}
return false;
}
@ -1285,7 +1287,7 @@ __weak int omv_csi_set_framebuffers(omv_csi_t *csi, size_t count, bool expand) {
csi->fb->frame_size = csi->fb->u * csi->fb->v * 2;
#else
// Otherwise, use the real frame size.
csi->fb->frame_size = resolution[csi->framesize][0] * resolution[csi->framesize][1] * 2;
csi->fb->frame_size = csi->resolution[csi->framesize][0] * csi->resolution[csi->framesize][1] * 2;
#endif
if (count == -1) {

View File

@ -189,6 +189,7 @@ typedef enum {
OMV_CSI_FRAMESIZE_QXGA, // 2048x1536
OMV_CSI_FRAMESIZE_WQXGA, // 2560x1600
OMV_CSI_FRAMESIZE_WQXGA2, // 2592x1944
OMV_CSI_FRAMESIZE_MAX,
} omv_csi_framesize_t;
typedef enum {
@ -378,6 +379,9 @@ typedef struct _omv_csi {
// data, internal state, or additional operations.
void *priv;
// Resolution table
uint16_t resolution[OMV_CSI_FRAMESIZE_MAX][2];
// Sensor function pointers
int (*reset) (omv_csi_t *csi);
int (*sleep) (omv_csi_t *csi, int enable);
@ -416,9 +420,6 @@ typedef struct _omv_csi {
// CSI array
extern omv_csi_t csi_all[OMV_CSI_MAX_DEVICES];
// Resolution table
extern uint16_t resolution[][2];
// Resets the sensor state on soft-reboots.
void omv_csi_init0();

View File

@ -145,7 +145,7 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
return ret;
}
int num_pixels = resolution[boson_framesize][0] * resolution[boson_framesize][1];
int num_pixels = csi->resolution[boson_framesize][0] * csi->resolution[boson_framesize][1];
if (csi->color_palette && (framebuffer_get_buffer_size(csi->fb) >= (num_pixels * sizeof(uint16_t)))) {
for (int32_t i = num_pixels - 1; i >= 0; i--) {
@ -175,11 +175,11 @@ int boson_init(omv_csi_t *csi) {
csi->mono_bpp = sizeof(uint8_t);
// Override standard resolutions
resolution[OMV_CSI_FRAMESIZE_VGA][0] = 640;
resolution[OMV_CSI_FRAMESIZE_VGA][1] = 512;
csi->resolution[OMV_CSI_FRAMESIZE_VGA][0] = 640;
csi->resolution[OMV_CSI_FRAMESIZE_VGA][1] = 512;
resolution[OMV_CSI_FRAMESIZE_QVGA][0] = 320;
resolution[OMV_CSI_FRAMESIZE_QVGA][1] = 256;
csi->resolution[OMV_CSI_FRAMESIZE_QVGA][0] = 320;
csi->resolution[OMV_CSI_FRAMESIZE_QVGA][1] = 256;
if (reset(csi) != 0) {
return OMV_CSI_ERROR_CSI_INIT_FAILED;

View File

@ -842,8 +842,8 @@ static int set_window(omv_csi_t *csi, uint16_t reg, uint16_t x, uint16_t y, uint
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
// Invalid resolution.
if ((w > ACTIVE_SENSOR_WIDTH) || (h > ACTIVE_SENSOR_HEIGHT)) {
@ -957,8 +957,12 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
case OMV_CSI_IOCTL_SET_READOUT_WINDOW: {
int tmp_readout_x = va_arg(ap, int);
int tmp_readout_y = va_arg(ap, int);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][0], ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][1], ACTIVE_SENSOR_HEIGHT);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][0],
ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][1],
ACTIVE_SENSOR_HEIGHT);
int readout_x_max = (ACTIVE_SENSOR_WIDTH - tmp_readout_w) / 2;
int readout_y_max = (ACTIVE_SENSOR_HEIGHT - tmp_readout_h) / 2;
tmp_readout_x = IM_CLAMP(tmp_readout_x, -readout_x_max, readout_x_max);

View File

@ -97,8 +97,8 @@ static int reset(omv_csi_t *csi) {
genx->contrast = CONTRAST_DEFAULT;
genx->brightness = BRIGHTNESS_DEFAULT;
genx->event_time_us = 0;
resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = ACTIVE_SENSOR_WIDTH;
resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ACTIVE_SENSOR_HEIGHT;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = ACTIVE_SENSOR_WIDTH;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ACTIVE_SENSOR_HEIGHT;
// Set histogram mode by default.
if (set_active_mode(csi, OMV_CSI_GENX320_MODE_HISTO, OMV_CSI_FRAMESIZE_CUSTOM)) {
@ -154,8 +154,8 @@ static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
if (genx->mode == OMV_CSI_GENX320_MODE_HISTO) {
if (framesize == OMV_CSI_FRAMESIZE_CUSTOM &&
resolution[framesize][0] == ACTIVE_SENSOR_WIDTH &&
resolution[framesize][1] == ACTIVE_SENSOR_HEIGHT) {
csi->resolution[framesize][0] == ACTIVE_SENSOR_WIDTH &&
csi->resolution[framesize][1] == ACTIVE_SENSOR_HEIGHT) {
return 0;
}
return (framesize == OMV_CSI_FRAMESIZE_320X320) ? 0 : -1;
@ -193,7 +193,8 @@ static int set_framerate(omv_csi_t *csi, int framerate) {
omv_csi_abort(csi, true, false);
psee_sensor_write(csi, EHC_INTEGRATION_PERIOD, us);
psee_sensor_write(csi, CPI_PACKET_TIME_CONTROL, ACTIVE_SENSOR_WIDTH << CPI_PACKET_TIME_CONTROL_PERIOD_Pos |
psee_sensor_write(csi, CPI_PACKET_TIME_CONTROL,
ACTIVE_SENSOR_WIDTH << CPI_PACKET_TIME_CONTROL_PERIOD_Pos |
hsync_clocks << CPI_PACKET_TIME_CONTROL_BLANKING_Pos);
// Wait for the camera to settle
@ -427,8 +428,8 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
int mode = va_arg(ap, int);
if (mode == OMV_CSI_GENX320_MODE_HISTO) {
resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = ACTIVE_SENSOR_WIDTH;
resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ACTIVE_SENSOR_HEIGHT;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = ACTIVE_SENSOR_WIDTH;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ACTIVE_SENSOR_HEIGHT;
if ((ret = set_active_mode(csi, OMV_CSI_GENX320_MODE_HISTO, OMV_CSI_FRAMESIZE_CUSTOM))) {
break;
@ -449,8 +450,8 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
break;
}
resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = 1024;
resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ndarray_size >> 8;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = 1024;
csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = ndarray_size >> 8;
if ((ret = set_active_mode(csi, OMV_CSI_GENX320_MODE_EVENT, OMV_CSI_FRAMESIZE_CUSTOM))) {
break;
@ -518,8 +519,8 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
i += val;
}
} else {
uint32_t len = resolution[csi->framesize][0] *
(resolution[csi->framesize][1] / sizeof(uint32_t));
uint32_t len = csi->resolution[csi->framesize][0] *
(csi->resolution[csi->framesize][1] / sizeof(uint32_t));
for (uint32_t j = 0; j < len; j++) {
uint32_t val = ((uint32_t *) image.data)[j];
switch (__EVT20_TYPE(val)) {
@ -656,8 +657,8 @@ static int set_active_mode(omv_csi_t *csi, genx_mode_t mode, int framesize) {
}
// Configure Packet and Frame sizes
uint32_t packet_width = resolution[framesize][0];
uint32_t packet_height = resolution[framesize][1];
uint32_t packet_width = csi->resolution[framesize][0];
uint32_t packet_height = csi->resolution[framesize][1];
uint32_t packet_hsync = (mode == OMV_CSI_GENX320_MODE_EVENT) ?
EVENT_HSYNC_CLOCK_CYCLES : HISTO_HSYNC_CLOCK_CYCLES;

View File

@ -252,8 +252,8 @@ static const uint16_t QQVGA_regs[][2] = {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
switch (framesize) {
case OMV_CSI_FRAMESIZE_QVGA:

View File

@ -401,8 +401,8 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
return OMV_CSI_ERROR_INVALID_FRAMESIZE;
}
if (resolution[csi->framesize][0] < lepton.h_res ||
resolution[csi->framesize][1] < lepton.v_res) {
if (csi->resolution[csi->framesize][0] < lepton.h_res ||
csi->resolution[csi->framesize][1] < lepton.v_res) {
return OMV_CSI_ERROR_INVALID_FRAMESIZE;
}

View File

@ -586,8 +586,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
if ((csi->pixformat == PIXFORMAT_BAYER) &&
((framesize != OMV_CSI_FRAMESIZE_VGA) && (framesize != OMV_CSI_FRAMESIZE_SXGAM))) {
@ -942,8 +942,12 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
case OMV_CSI_IOCTL_SET_READOUT_WINDOW: {
int tmp_readout_x = va_arg(ap, int);
int tmp_readout_y = va_arg(ap, int);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][0], ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][1], ACTIVE_SENSOR_HEIGHT);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][0],
ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][1],
ACTIVE_SENSOR_HEIGHT);
int readout_x_max = (ACTIVE_SENSOR_WIDTH - tmp_readout_w) / 2;
int readout_y_max = (ACTIVE_SENSOR_HEIGHT - tmp_readout_h) / 2;
tmp_readout_x = IM_CLAMP(tmp_readout_x, -readout_x_max, readout_x_max);

View File

@ -171,8 +171,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
uint16_t chip_control, read_mode;
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
if ((w > ACTIVE_SENSOR_WIDTH) || (h > ACTIVE_SENSOR_HEIGHT)) {
return -1;
@ -443,8 +443,8 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
// The MT9V0XX does not have a hardware scaler so the readout w/h must be equal to the
// framesize w/h.
int tmp_readout_w = resolution[csi->framesize][0];
int tmp_readout_h = resolution[csi->framesize][1];
int tmp_readout_w = csi->resolution[csi->framesize][0];
int tmp_readout_h = csi->resolution[csi->framesize][1];
if (csi->framesize == OMV_CSI_FRAMESIZE_INVALID) {
tmp_readout_w = ACTIVE_SENSOR_WIDTH;
tmp_readout_h = ACTIVE_SENSOR_HEIGHT;

View File

@ -441,8 +441,8 @@ static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
uint16_t sensor_w = 0;
uint16_t sensor_h = 0;
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
if ((w % 4) || (h % 4) || (w > UXGA_WIDTH) || (h > UXGA_HEIGHT)) {
// w/h must be divisible by 4

View File

@ -775,7 +775,9 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
int ret = 0;
// Not a multiple of 8. The JPEG encoder on the OV5640 can't handle this.
if ((pixformat == PIXFORMAT_JPEG) && ((resolution[csi->framesize][0] % 8) || (resolution[csi->framesize][1] % 8))) {
if ((pixformat == PIXFORMAT_JPEG) &&
((csi->resolution[csi->framesize][0] % 8) ||
(csi->resolution[csi->framesize][1] % 8))) {
return -1;
}
@ -834,7 +836,7 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
(reg & 0xD7) | ((pixformat == PIXFORMAT_JPEG) ? 0x28 : 0x00));
if (hts_target) {
uint16_t sensor_hts = calculate_hts(csi, resolution[csi->framesize][0]);
uint16_t sensor_hts = calculate_hts(csi, csi->resolution[csi->framesize][0]);
ret |= omv_i2c_writeb2(csi->i2c, csi->slv_addr, TIMING_HTS_H, sensor_hts >> 8);
ret |= omv_i2c_writeb2(csi->i2c, csi->slv_addr, TIMING_HTS_L, sensor_hts);
@ -846,8 +848,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
uint8_t reg;
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
// Not a multiple of 8. The JPEG encoder on the OV5640 can't handle this.
if ((csi->pixformat == PIXFORMAT_JPEG) && ((w % 8) || (h % 8))) {
@ -1339,8 +1341,12 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
case OMV_CSI_IOCTL_SET_READOUT_WINDOW: {
int tmp_readout_x = va_arg(ap, int);
int tmp_readout_y = va_arg(ap, int);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][0], ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int), resolution[csi->framesize][1], ACTIVE_SENSOR_HEIGHT);
int tmp_readout_w = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][0],
ACTIVE_SENSOR_WIDTH);
int tmp_readout_h = IM_CLAMP(va_arg(ap, int),
csi->resolution[csi->framesize][1],
ACTIVE_SENSOR_HEIGHT);
int readout_x_max = (ACTIVE_SENSOR_WIDTH - tmp_readout_w) / 2;
int readout_y_max = (ACTIVE_SENSOR_HEIGHT - tmp_readout_h) / 2;
tmp_readout_x = IM_CLAMP(tmp_readout_x, -readout_x_max, readout_x_max);

View File

@ -281,8 +281,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
uint8_t reg;
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
bool vflip;
if (((w > 640) || (h > 480))

View File

@ -237,8 +237,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
uint8_t reg;
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
bool vflip;
if ((w > 640) || (h > 480)) {

View File

@ -727,14 +727,14 @@ int pag7936_init(omv_csi_t *csi) {
csi->set_vflip = set_vflip;
// Override standard resolutions
resolution[OMV_CSI_FRAMESIZE_HD][0] = 1280;
resolution[OMV_CSI_FRAMESIZE_HD][1] = 800;
csi->resolution[OMV_CSI_FRAMESIZE_HD][0] = 1280;
csi->resolution[OMV_CSI_FRAMESIZE_HD][1] = 800;
resolution[OMV_CSI_FRAMESIZE_VGA][0] = 640;
resolution[OMV_CSI_FRAMESIZE_VGA][1] = 400;
csi->resolution[OMV_CSI_FRAMESIZE_VGA][0] = 640;
csi->resolution[OMV_CSI_FRAMESIZE_VGA][1] = 400;
resolution[OMV_CSI_FRAMESIZE_QVGA][0] = 320;
resolution[OMV_CSI_FRAMESIZE_QVGA][1] = 200;
csi->resolution[OMV_CSI_FRAMESIZE_QVGA][0] = 320;
csi->resolution[OMV_CSI_FRAMESIZE_QVGA][1] = 200;
return 0;
}
#endif // (OMV_PAG7936_ENABLE == 1)

View File

@ -395,8 +395,8 @@ static int set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
int ret = 0;
uint16_t w = resolution[framesize][0];
uint16_t h = resolution[framesize][1];
uint16_t w = csi->resolution[framesize][0];
uint16_t h = csi->resolution[framesize][1];
uint8_t aavg_VnH, abc_start_line, voffset, abc_sample_size;
ret |= read_regs_w_bank(BANK_0, REG_CMD_AAVG_V /* REG_CMD_AAVG_H */, &aavg_VnH, 1);

View File

@ -197,13 +197,13 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(py_omv_csi_skip_frames_obj, 0, py_omv_csi_skip
static mp_obj_t py_omv_csi_width() {
omv_csi_t *csi = omv_csi_get(-1);
return mp_obj_new_int(resolution[csi->framesize][0]);
return mp_obj_new_int(csi->resolution[csi->framesize][0]);
}
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_width_obj, py_omv_csi_width);
static mp_obj_t py_omv_csi_height() {
omv_csi_t *csi = omv_csi_get(-1);
return mp_obj_new_int(resolution[csi->framesize][1]);
return mp_obj_new_int(csi->resolution[csi->framesize][1]);
}
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_height_obj, py_omv_csi_height);
@ -328,8 +328,8 @@ static mp_obj_t py_omv_csi_set_windowing(size_t n_args, const mp_obj_t *args) {
rectangle_t temp;
temp.x = 0;
temp.y = 0;
temp.w = resolution[csi->framesize][0];
temp.h = resolution[csi->framesize][1];
temp.w = csi->resolution[csi->framesize][0];
temp.h = csi->resolution[csi->framesize][1];
mp_obj_t *array = (mp_obj_t *) args;
mp_uint_t array_len = n_args;

View File

@ -265,14 +265,14 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(py_csi_snapshot_obj, 1, py_csi_snapshot);
static mp_obj_t py_csi_width(mp_obj_t self_in) {
py_csi_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(resolution[self->csi->framesize][0]);
return mp_obj_new_int(self->csi->resolution[self->csi->framesize][0]);
}
static MP_DEFINE_CONST_FUN_OBJ_1(py_csi_width_obj, py_csi_width);
static mp_obj_t py_csi_height(mp_obj_t self_in) {
py_csi_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(resolution[self->csi->framesize][1]);
return mp_obj_new_int(self->csi->resolution[self->csi->framesize][1]);
}
static MP_DEFINE_CONST_FUN_OBJ_1(py_csi_height_obj, py_csi_height);
@ -329,8 +329,8 @@ static mp_obj_t py_csi_framesize(size_t n_args, const mp_obj_t *args) {
mp_obj_get_array_fixed_n(args[1], 2, &arg_array);
framesize = OMV_CSI_FRAMESIZE_CUSTOM;
resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = mp_obj_get_int(arg_array[0]);
resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = mp_obj_get_int(arg_array[1]);
self->csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][0] = mp_obj_get_int(arg_array[0]);
self->csi->resolution[OMV_CSI_FRAMESIZE_CUSTOM][1] = mp_obj_get_int(arg_array[1]);
} else {
omv_csi_raise_error(OMV_CSI_ERROR_INVALID_ARGUMENT);
}
@ -386,8 +386,8 @@ static mp_obj_t py_csi_window(size_t n_args, const mp_obj_t *args) {
rectangle_t t = {
.x = 0,
.y = 0,
.w = resolution[self->csi->framesize][0],
.h = resolution[self->csi->framesize][1],
.w = self->csi->resolution[self->csi->framesize][0],
.h = self->csi->resolution[self->csi->framesize][1],
};
if (array_len == 2) {
@ -1209,8 +1209,8 @@ static mp_obj_t py_csi_ioctl(size_t n_args, const mp_obj_t *args) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Expected a ndarray with dtype uint16"));
}
uint32_t expected_len = resolution[self->csi->framesize][0] *
(resolution[self->csi->framesize][1] / sizeof(uint32_t));
uint32_t expected_len = self->csi->resolution[self->csi->framesize][0] *
(self->csi->resolution[self->csi->framesize][1] / sizeof(uint32_t));
if (!(ndarray_is_dense(array) && (array->ndim == 2) &&
(array->shape[ULAB_MAX_DIMS - 2] == expected_len) &&

View File

@ -216,11 +216,11 @@ static int alif_clk_set_frequency(omv_clk_t *clk, uint32_t frequency) {
static uint32_t omv_csi_get_fb_offset(omv_csi_t *csi) {
uint32_t offset = 0;
uint32_t bytes_per_pixel = omv_csi_get_src_bpp(csi);
uint32_t line_size_bytes = resolution[csi->framesize][0] * bytes_per_pixel;
uint32_t line_size_bytes = csi->resolution[csi->framesize][0] * bytes_per_pixel;
// Offset the pixels buffer for debayering.
if (csi->raw_output && csi->pixformat == PIXFORMAT_RGB565) {
offset += line_size_bytes * resolution[csi->framesize][1];
offset += line_size_bytes * csi->resolution[csi->framesize][1];
}
return offset;
@ -239,7 +239,7 @@ int alif_csi_snapshot(omv_csi_t *csi, image_t *dst_image, uint32_t flags) {
// and there are no pending buffers (from non-blocking capture).
if (!alif_csi_is_active(csi) && !framebuffer_readable(fb)) {
uint32_t bytes_per_pixel = omv_csi_get_src_bpp(csi);
uint32_t line_size_bytes = resolution[csi->framesize][0] * bytes_per_pixel;
uint32_t line_size_bytes = csi->resolution[csi->framesize][0] * bytes_per_pixel;
// Acquire a buffer from the free queue.
buffer = framebuffer_acquire(fb, FB_FLAG_FREE | FB_FLAG_PEEK);
@ -278,7 +278,7 @@ int alif_csi_snapshot(omv_csi_t *csi, image_t *dst_image, uint32_t flags) {
cpi->CAM_VIDEO_FCFG &= ~CAM_VIDEO_FCFG_DATA_Msk;
cpi->CAM_VIDEO_FCFG = line_size_bytes;
cpi->CAM_VIDEO_FCFG &= ~CAM_VIDEO_FCFG_ROW_Msk;
cpi->CAM_VIDEO_FCFG |= ((resolution[csi->framesize][1] - 1) << CAM_VIDEO_FCFG_ROW_Pos);
cpi->CAM_VIDEO_FCFG |= ((csi->resolution[csi->framesize][1] - 1) << CAM_VIDEO_FCFG_ROW_Pos);
cpi->CAM_FRAME_ADDR = LocalToGlobal(buffer->data + omv_csi_get_fb_offset(csi));
// Configure and enable CSI interrupts.
@ -362,8 +362,8 @@ int alif_csi_snapshot(omv_csi_t *csi, image_t *dst_image, uint32_t flags) {
image_t src_cimage = *dst_image;
image_t dst_cimage = *dst_image;
src_cimage.w = resolution[csi->framesize][0];
src_cimage.h = resolution[csi->framesize][1];
src_cimage.w = csi->resolution[csi->framesize][0];
src_cimage.h = csi->resolution[csi->framesize][1];
// Offset the pixels buffer for the debayer code.
if (csi->pixformat == PIXFORMAT_RGB565) {

View File

@ -134,7 +134,7 @@ void omv_csi_sof_callback(omv_csi_t *csi) {
if (buffer == NULL) {
omv_csi_abort(csi, false, true);
} else if (buffer->offset < resolution[csi->framesize][1]) {
} else if (buffer->offset < csi->resolution[csi->framesize][1]) {
// Missed a few lines, reset buffer state and continue.
framebuffer_reset(buffer);
}
@ -240,7 +240,7 @@ void omv_csi_line_callback(omv_csi_t *csi, uint32_t addr) {
}
if (csi->drop_frame) {
if (++buffer->offset == resolution[csi->framesize][1]) {
if (++buffer->offset == csi->resolution[csi->framesize][1]) {
buffer->offset = 0;
CSI_REG_CR3(CSI) &= ~CSI_CR3_DMA_REQ_EN_RFF_MASK;
}
@ -274,7 +274,7 @@ void omv_csi_line_callback(omv_csi_t *csi, uint32_t addr) {
#endif
}
if (++buffer->offset == resolution[csi->framesize][1]) {
if (++buffer->offset == csi->resolution[csi->framesize][1]) {
// Release the current framebuffer.
framebuffer_release(fb, FB_FLAG_FREE | FB_FLAG_CHECK_LAST);
CSI_REG_CR3(CSI) &= ~CSI_CR3_DMA_REQ_EN_RFF_MASK;
@ -333,7 +333,7 @@ int imx_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
// and there are no pending buffers (from non-blocking capture).
if (!(CSI->CR18 & CSI_CR18_CSI_ENABLE_MASK) && !framebuffer_readable(fb)) {
uint32_t bytes_per_pixel = omv_csi_get_src_bpp(csi);
uint32_t dma_line_bytes = resolution[csi->framesize][0] * bytes_per_pixel;
uint32_t dma_line_bytes = csi->resolution[csi->framesize][0] * bytes_per_pixel;
uint32_t length = dma_line_bytes * fb->v;
// Error out if the transfer size is not compatible with DMA transfer restrictions.

View File

@ -359,7 +359,7 @@ int omv_csi_set_vsync_callback(omv_csi_t *csi, omv_csi_cb_t cb) {
static uint32_t get_dcmi_hw_crop(omv_csi_t *csi, uint32_t bytes_per_pixel) {
framebuffer_t *fb = csi->fb;
uint32_t byte_x_offset = (fb->x * bytes_per_pixel) % 4;
uint32_t width_remainder = (resolution[csi->framesize][0] - (fb->x + fb->u)) * bytes_per_pixel;
uint32_t width_remainder = (csi->resolution[csi->framesize][0] - (fb->x + fb->u)) * bytes_per_pixel;
if (byte_x_offset && (width_remainder >= (4 - byte_x_offset))) {
return byte_x_offset;
@ -558,7 +558,7 @@ static int stm_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
// Setup the size and address of the transfer
uint32_t bytes_per_pixel = omv_csi_get_src_bpp(csi);
uint32_t x_crop = get_dcmi_hw_crop(csi, bytes_per_pixel);
uint32_t line_width = resolution[csi->framesize][0] * bytes_per_pixel;
uint32_t line_width = csi->resolution[csi->framesize][0] * bytes_per_pixel;
// Shrink the captured pixel count by one word to allow cropping to fix alignment.
if (x_crop) {