Merge pull request #2728 from kwagyeman/kwabena/fix_csi_boson_genx320

drivers/sensors: Update new sensors to use the csi pointer.
This commit is contained in:
Ibrahim Abdelkader 2025-06-24 00:34:13 +03:00 committed by GitHub
commit 032a74c64e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 495 additions and 477 deletions

View File

@ -17,6 +17,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "omv_csi.h"
// Set the omv_csi_t pointer to use for serial port operations.
void FSLP_set_csi(omv_csi_t *csi);
// open port by id, using specified baud_rate. // open port by id, using specified baud_rate.
// passes library errors up, 0 on success. // passes library errors up, 0 on success.

View File

@ -34,19 +34,24 @@
#include "serialPortAdapter.h" #include "serialPortAdapter.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "omv_csi.h"
#include "sc16is741a.h" #include "sc16is741a.h"
static omv_csi_t *omv_csi = NULL;
void FSLP_set_csi(omv_csi_t *csi) {
omv_csi = csi;
}
static uint8_t read_reg(uint8_t addr){ static uint8_t read_reg(uint8_t addr){
uint8_t buf; uint8_t buf;
omv_i2c_write_bytes(csi.i2c, csi.slv_addr, &addr, 1, OMV_I2C_XFER_NO_STOP); omv_i2c_write_bytes(omv_csi->i2c, omv_csi->slv_addr, &addr, 1, OMV_I2C_XFER_NO_STOP);
omv_i2c_read_bytes(csi.i2c, csi.slv_addr, &buf, 1, OMV_I2C_XFER_NO_FLAGS); omv_i2c_read_bytes(omv_csi->i2c, omv_csi->slv_addr, &buf, 1, OMV_I2C_XFER_NO_FLAGS);
return buf; return buf;
} }
static void write_reg(uint8_t addr, uint8_t data) { static void write_reg(uint8_t addr, uint8_t data) {
uint8_t buf[] = {addr, data}; uint8_t buf[] = {addr, data};
omv_i2c_write_bytes(csi.i2c, csi.slv_addr, buf, 2, OMV_I2C_XFER_NO_FLAGS); omv_i2c_write_bytes(omv_csi->i2c, omv_csi->slv_addr, buf, 2, OMV_I2C_XFER_NO_FLAGS);
} }
uint8_t FSLP_open_port() { uint8_t FSLP_open_port() {

View File

@ -20,6 +20,7 @@
/* User Includes*/ /* User Includes*/
#include "genx320_all_pub_registers.h" #include "genx320_all_pub_registers.h"
#include "psee_issd.h" #include "psee_issd.h"
#include "omv_csi.h"
/* Sensor I2C Address */ /* Sensor I2C Address */
#define I2C_ADDRESS 0x3C #define I2C_ADDRESS 0x3C
@ -226,6 +227,7 @@ typedef enum {
*/ */
typedef struct typedef struct
{ {
omv_csi_t *csi;
AFK_InitTypeDef Init; /*!< AFK Init */ AFK_InitTypeDef Init; /*!< AFK Init */
AFK_StateTypeDef State; /*!< AFK State */ AFK_StateTypeDef State; /*!< AFK State */
AFK_StatisticsTypeDef Stats; /*!< AFK Statistics */ AFK_StatisticsTypeDef Stats; /*!< AFK Statistics */
@ -303,6 +305,7 @@ typedef enum {
*/ */
typedef struct typedef struct
{ {
omv_csi_t *csi;
EHC_InitTypeDef Init; /*!< EHC Init */ EHC_InitTypeDef Init; /*!< EHC Init */
EHC_StateTypeDef State; /*!< EHC State */ EHC_StateTypeDef State; /*!< EHC State */
EHC_AlgoTypeDef Algo; /*!< EHC Algo */ EHC_AlgoTypeDef Algo; /*!< EHC Algo */
@ -367,6 +370,7 @@ typedef enum {
*/ */
typedef struct typedef struct
{ {
omv_csi_t *csi;
STC_InitTypeDef Init; /*!< STC block Init */ STC_InitTypeDef Init; /*!< STC block Init */
STC_StateTypeDef State; /*!< STC block State */ STC_StateTypeDef State; /*!< STC block State */
STC_ModeTypeDef Mode; /*!< STC Mode */ STC_ModeTypeDef Mode; /*!< STC Mode */
@ -390,64 +394,64 @@ extern const struct issd *current_issd;
extern GenX320_Rommode genx320_boot_mode; extern GenX320_Rommode genx320_boot_mode;
/* Sensor Register Manipulation Functions */ /* Sensor Register Manipulation Functions */
extern void psee_sensor_read(uint16_t register_address, uint32_t *buf); extern void psee_sensor_read(omv_csi_t *csi, uint16_t register_address, uint32_t *buf);
extern void psee_sensor_write(uint16_t register_address, uint32_t register_data); extern void psee_sensor_write(omv_csi_t *csi, uint16_t register_address, uint32_t register_data);
/* Sensor Bring Up Functions */ /* Sensor Bring Up Functions */
extern void psee_sensor_init(const struct issd *); extern void psee_sensor_init(omv_csi_t *csi, const struct issd *);
extern void psee_sensor_start(const struct issd *); extern void psee_sensor_start(omv_csi_t *csi, const struct issd *);
extern void psee_sensor_stop(const struct issd *); extern void psee_sensor_stop(omv_csi_t *csi, const struct issd *);
extern const struct issd *psee_open_evt(); extern const struct issd *psee_open_evt(omv_csi_t *csi);
extern void psee_sensor_set_bias(BIAS_Name_t bias, uint32_t val); extern void psee_sensor_set_bias(omv_csi_t *csi, BIAS_Name_t bias, uint32_t val);
extern void psee_sensor_set_biases(const BIAS_Params_t *bias); extern void psee_sensor_set_biases(omv_csi_t *csi, const BIAS_Params_t *bias);
extern void psee_sensor_set_CPI_EVT20(); extern void psee_sensor_set_CPI_EVT20(omv_csi_t *csi);
extern void psee_sensor_set_CPI_HISTO(); extern void psee_sensor_set_CPI_HISTO(omv_csi_t *csi);
extern void psee_sensor_set_flip(uint32_t flip_x, uint32_t flip_y); extern void psee_sensor_set_flip(omv_csi_t *csi, uint32_t flip_x, uint32_t flip_y);
extern void psee_sensor_destroy(); extern void psee_sensor_destroy(omv_csi_t *csi);
/* Operating Mode Control Functions */ /* Operating Mode Control Functions */
extern void psee_PM3C_config(); extern void psee_PM3C_config(omv_csi_t *csi);
extern void psee_PM3C_Histo_config(); extern void psee_PM3C_Histo_config(omv_csi_t *csi);
extern void psee_PM2_config(); extern void psee_PM2_config(omv_csi_t *csi);
extern void psee_PM2_Histo_config(); extern void psee_PM2_Histo_config(omv_csi_t *csi);
/* Firmware flashing functions */ /* Firmware flashing functions */
extern FW_StatusTypeDef psee_write_firmware_single(const Firmware *firmwareArray, uint32_t n_bytes); extern FW_StatusTypeDef psee_write_firmware_single(omv_csi_t *csi, const Firmware *firmwareArray, uint32_t n_bytes);
extern FW_StatusTypeDef psee_test_firmware_single(const Firmware *firmwareArray, uint32_t n_bytes); extern FW_StatusTypeDef psee_test_firmware_single(omv_csi_t *csi, const Firmware *firmwareArray, uint32_t n_bytes);
extern uint32_t psee_read_firmware_register(uint32_t reg_address); extern uint32_t psee_read_firmware_register(omv_csi_t *csi, uint32_t reg_address);
extern FW_StatusTypeDef psee_write_firmware_burst(const Firmware *firmwareArray, uint32_t n_bytes); extern FW_StatusTypeDef psee_write_firmware_burst(omv_csi_t *csi, const Firmware *firmwareArray, uint32_t n_bytes);
extern FW_StatusTypeDef psee_start_firmware(GenX320_Rommode boot_mode, uint32_t jump_add); extern FW_StatusTypeDef psee_start_firmware(omv_csi_t *csi, GenX320_Rommode boot_mode, uint32_t jump_add);
extern FW_StatusTypeDef psee_reset_firmware(GenX320_Rommode boot_mode); extern FW_StatusTypeDef psee_reset_firmware(omv_csi_t *csi, GenX320_Rommode boot_mode);
/* Mailbox Communication Functions */ /* Mailbox Communication Functions */
extern uint32_t psee_get_mbx_cmd_ptr(); extern uint32_t psee_get_mbx_cmd_ptr(omv_csi_t *csi);
extern uint32_t psee_get_mbx_misc(); extern uint32_t psee_get_mbx_misc(omv_csi_t *csi);
extern uint32_t psee_get_mbx_status_ptr(); extern uint32_t psee_get_mbx_status_ptr(omv_csi_t *csi);
extern void psee_set_mbx_cmd_ptr(uint32_t val); extern void psee_set_mbx_cmd_ptr(omv_csi_t *csi, uint32_t val);
extern void psee_set_mbx_misc(uint32_t val); extern void psee_set_mbx_misc(omv_csi_t *csi, uint32_t val);
extern void psee_set_mbx_status_ptr(uint32_t val); extern void psee_set_mbx_status_ptr(omv_csi_t *csi, uint32_t val);
/* ROI Access Functions */ /* ROI Access Functions */
extern void psee_write_ROI_X(uint32_t offset, uint32_t val); extern void psee_write_ROI_X(omv_csi_t *csi, uint32_t offset, uint32_t val);
extern void psee_write_ROI_Y(uint32_t offset, uint32_t val); extern void psee_write_ROI_Y(omv_csi_t *csi, uint32_t offset, uint32_t val);
extern void psee_write_ROI_CTRL(uint32_t val); extern void psee_write_ROI_CTRL(omv_csi_t *csi, uint32_t val);
/* RISC-V Debugger Functions */ /* RISC-V Debugger Functions */
extern uint32_t psee_mbx_read_uint32(); extern uint32_t psee_mbx_read_uint32(omv_csi_t *csi);
extern void psee_decode_debugger(); extern void psee_decode_debugger(omv_csi_t *csi);
extern uint32_t psee_sensor_read_dmem(uint32_t address); extern uint32_t psee_sensor_read_dmem(omv_csi_t *csi, uint32_t address);
extern uint32_t psee_sensor_read_imem(uint32_t address); extern uint32_t psee_sensor_read_imem(omv_csi_t *csi, uint32_t address);
/* Statistics Register Read Functions */ /* Statistics Register Read Functions */
extern void psee_read_ro_lp_evt_cnt(uint32_t *p_data); extern void psee_read_ro_lp_evt_cnt(omv_csi_t *csi, uint32_t *p_data);
extern uint32_t psee_read_ro_evt_cd_cnt(); extern uint32_t psee_read_ro_evt_cd_cnt(omv_csi_t *csi);
/* Activity Map Configuration Functions */ /* Activity Map Configuration Functions */
extern void psee_configure_activity_map(); extern void psee_configure_activity_map(omv_csi_t *csi);
extern void psee_set_default_XY_borders(AM_Borders_t *border); extern void psee_set_default_XY_borders(omv_csi_t *csi, AM_Borders_t *border);
/* AFK Configuration Functions */ /* AFK Configuration Functions */
extern AFK_StatusTypeDef psee_afk_init(AFK_HandleTypeDef *afk); extern AFK_StatusTypeDef psee_afk_init(omv_csi_t *csi, AFK_HandleTypeDef *afk);
extern AFK_StatusTypeDef psee_afk_activate(AFK_HandleTypeDef *afk, extern AFK_StatusTypeDef psee_afk_activate(AFK_HandleTypeDef *afk,
uint16_t f_min, uint16_t f_min,
uint16_t f_max, uint16_t f_max,
@ -465,8 +469,8 @@ extern AFK_StatisticsTypeDef psee_afk_get_stats(AFK_HandleTypeDef *afk);
extern uint32_t psee_afk_get_stats_acc_time(AFK_HandleTypeDef *afk); extern uint32_t psee_afk_get_stats_acc_time(AFK_HandleTypeDef *afk);
/* EHC Configuration Functions */ /* EHC Configuration Functions */
extern const struct issd *psee_open_ehc(); extern const struct issd *psee_open_ehc(omv_csi_t *csi);
extern EHC_StatusTypeDef psee_ehc_init(EHC_HandleTypeDef *ehc); extern EHC_StatusTypeDef psee_ehc_init(omv_csi_t *csi, EHC_HandleTypeDef *ehc);
extern EHC_StatusTypeDef psee_ehc_activate(EHC_HandleTypeDef *ehc, extern EHC_StatusTypeDef psee_ehc_activate(EHC_HandleTypeDef *ehc,
EHC_AlgoTypeDef sel_algo, EHC_AlgoTypeDef sel_algo,
uint8_t p_bits_size, uint8_t p_bits_size,
@ -488,10 +492,10 @@ extern EHC_StatusTypeDef psee_ehc_activate_override(EHC_HandleTypeDef *ehc,
EHC_OverrideTypeDef override); EHC_OverrideTypeDef override);
extern EHC_StatusTypeDef psee_ehc_start_histo_acc(EHC_HandleTypeDef *ehc); extern EHC_StatusTypeDef psee_ehc_start_histo_acc(EHC_HandleTypeDef *ehc);
extern EHC_StatusTypeDef psee_ehc_drain_histo(EHC_HandleTypeDef *ehc); extern EHC_StatusTypeDef psee_ehc_drain_histo(EHC_HandleTypeDef *ehc);
extern void psee_close_ehc(const struct issd *issd); extern void psee_close_ehc(omv_csi_t *csi, const struct issd *issd);
/* STC Configuration Functions */ /* STC Configuration Functions */
extern STC_StatusTypeDef psee_stc_init(STC_HandleTypeDef *stc); extern STC_StatusTypeDef psee_stc_init(omv_csi_t *csi, STC_HandleTypeDef *stc);
extern STC_StatusTypeDef psee_stc_only_activate(STC_HandleTypeDef *stc, extern STC_StatusTypeDef psee_stc_only_activate(STC_HandleTypeDef *stc,
uint32_t stc_threshold, uint32_t stc_threshold,
uint8_t evt_clk_freq); uint8_t evt_clk_freq);

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,7 @@
#include "Client_API.h" #include "Client_API.h"
#include "UART_Connector.h" #include "UART_Connector.h"
#include "serialPortAdapter.h"
#define FLIR_BOSON_BOOT_TRY_COUNT (10) #define FLIR_BOSON_BOOT_TRY_COUNT (10)
#define FLIR_BOSON_BOOT_TIME_MS (1000) #define FLIR_BOSON_BOOT_TIME_MS (1000)
@ -50,6 +51,7 @@
static int boson_framesize = 0; static int boson_framesize = 0;
static int reset(omv_csi_t *csi) { static int reset(omv_csi_t *csi) {
FSLP_set_csi(csi);
csi->color_palette = NULL; csi->color_palette = NULL;
int i = 0; int i = 0;
@ -123,6 +125,8 @@ static int set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize) {
} }
static int set_colorbar(omv_csi_t *csi, int enable) { static int set_colorbar(omv_csi_t *csi, int enable) {
FSLP_set_csi(csi);
if (gaoSetTestRampState(enable ? FLR_ENABLE : FLR_DISABLE) != FLR_OK) { if (gaoSetTestRampState(enable ? FLR_ENABLE : FLR_DISABLE) != FLR_OK) {
return -1; return -1;
} }

View File

@ -102,7 +102,7 @@ static int reset(omv_csi_t *csi) {
BIAS_Params_t biases = (csi->chip_id == SAPHIR_ES_ID) ? genx320es_default_biases : genx320mp_default_biases; BIAS_Params_t biases = (csi->chip_id == SAPHIR_ES_ID) ? genx320es_default_biases : genx320mp_default_biases;
// Force CPI with chicken bits // Force CPI with chicken bits
psee_sensor_write(TOP_CHICKEN, TOP_CHICKEN_OVERRIDE_MIPI_MODE_EN | psee_sensor_write(csi, TOP_CHICKEN, TOP_CHICKEN_OVERRIDE_MIPI_MODE_EN |
TOP_CHICKEN_OVERRIDE_HISTO_MODE_EN | TOP_CHICKEN_OVERRIDE_HISTO_MODE_EN |
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
1 << TOP_CHICKEN_OVERRIDE_HISTO_MODE_Pos | 1 << TOP_CHICKEN_OVERRIDE_HISTO_MODE_Pos |
@ -113,29 +113,29 @@ static int reset(omv_csi_t *csi) {
// Start the Init sequence // Start the Init sequence
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
psee_sensor_init(&dcmi_histo); psee_sensor_init(csi, &dcmi_histo);
#else #else
psee_sensor_init(&dcmi_evt); psee_sensor_init(csi, &dcmi_evt);
// Set EVT20 mode // Set EVT20 mode
psee_sensor_write(EDF_CONTROL, 0); psee_sensor_write(csi, EDF_CONTROL, 0);
#endif // (OMV_GENX320_EHC_ENABLE == 1) #endif // (OMV_GENX320_EHC_ENABLE == 1)
// Configure Packet and Frame sizes // Configure Packet and Frame sizes
psee_sensor_write(CPI_PACKET_SIZE_CONTROL, ACTIVE_SENSOR_WIDTH); psee_sensor_write(csi, CPI_PACKET_SIZE_CONTROL, ACTIVE_SENSOR_WIDTH);
psee_sensor_write(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_CLOCK_CYCLES << CPI_PACKET_TIME_CONTROL_BLANKING_Pos); HSYNC_CLOCK_CYCLES << CPI_PACKET_TIME_CONTROL_BLANKING_Pos);
psee_sensor_write(CPI_FRAME_SIZE_CONTROL, ACTIVE_SENSOR_HEIGHT); psee_sensor_write(csi, CPI_FRAME_SIZE_CONTROL, ACTIVE_SENSOR_HEIGHT);
psee_sensor_write(CPI_FRAME_TIME_CONTROL, VSYNC_CLOCK_CYCLES); psee_sensor_write(csi, CPI_FRAME_TIME_CONTROL, VSYNC_CLOCK_CYCLES);
// Enable dropping // Enable dropping
psee_sensor_write(RO_READOUT_CTRL, RO_READOUT_CTRL_DIGITAL_PIPE_EN | psee_sensor_write(csi, RO_READOUT_CTRL, RO_READOUT_CTRL_DIGITAL_PIPE_EN |
RO_READOUT_CTRL_AVOID_BPRESS_TD | RO_READOUT_CTRL_AVOID_BPRESS_TD |
RO_READOUT_CTRL_DROP_EN | RO_READOUT_CTRL_DROP_EN |
RO_READOUT_CTRL_DROP_ON_FULL_EN); RO_READOUT_CTRL_DROP_ON_FULL_EN);
// Enable the Anti-FlicKering filter // Enable the Anti-FlicKering filter
if (psee_afk_init(&psee_afk) != AFK_OK) { if (psee_afk_init(csi, &psee_afk) != AFK_OK) {
return -1; return -1;
} }
@ -145,27 +145,27 @@ static int reset(omv_csi_t *csi) {
// Operation Mode Configuration // Operation Mode Configuration
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
psee_PM3C_Histo_config(); psee_PM3C_Histo_config(csi);
#else #else
psee_PM3C_config(); psee_PM3C_config(csi);
#endif // (OMV_GENX320_EHC_ENABLE == 1) #endif // (OMV_GENX320_EHC_ENABLE == 1)
// Set the default border for the Activity map // Set the default border for the Activity map
psee_set_default_XY_borders(&genx320mp_default_am_borders); psee_set_default_XY_borders(csi, &genx320mp_default_am_borders);
// Configure the activity map // Configure the activity map
psee_configure_activity_map(); psee_configure_activity_map(csi);
// Set Standard biases // Set Standard biases
psee_sensor_set_biases(&biases); psee_sensor_set_biases(csi, &biases);
// Start the csi // Start the csi
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
psee_sensor_start(&dcmi_histo); psee_sensor_start(csi, &dcmi_histo);
EHC_HandleTypeDef psee_ehc; EHC_HandleTypeDef psee_ehc;
if (psee_ehc_init(&psee_ehc) != EHC_OK) { if (psee_ehc_init(csi, &psee_ehc) != EHC_OK) {
return -1; return -1;
} }
@ -174,7 +174,7 @@ static int reset(omv_csi_t *csi) {
return -1; return -1;
} }
#else #else
psee_sensor_start(&dcmi_evt); psee_sensor_start(csi, &dcmi_evt);
#endif // (OMV_GENX320_EHC_ENABLE == 1) #endif // (OMV_GENX320_EHC_ENABLE == 1)
return 0; return 0;
@ -183,15 +183,15 @@ static int reset(omv_csi_t *csi) {
static int sleep(omv_csi_t *csi, int enable) { static int sleep(omv_csi_t *csi, int enable) {
if (enable) { if (enable) {
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
psee_PM2_Histo_config(); psee_PM2_Histo_config(csi);
#else #else
psee_PM2_config(); psee_PM2_config(csi);
#endif // (OMV_GENX320_EHC_ENABLE == 1) #endif // (OMV_GENX320_EHC_ENABLE == 1)
} else { } else {
#if (OMV_GENX320_EHC_ENABLE == 1) #if (OMV_GENX320_EHC_ENABLE == 1)
psee_PM3C_Histo_config(); psee_PM3C_Histo_config(csi);
#else #else
psee_PM3C_config(); psee_PM3C_config(csi);
#endif // (OMV_GENX320_EHC_ENABLE == 1) #endif // (OMV_GENX320_EHC_ENABLE == 1)
} }
return 0; return 0;
@ -246,8 +246,8 @@ static int set_framerate(omv_csi_t *csi, int framerate) {
// Disable any ongoing frame capture. // Disable any ongoing frame capture.
omv_csi_abort(csi, true, false); omv_csi_abort(csi, true, false);
psee_sensor_write(EHC_INTEGRATION_PERIOD, us); psee_sensor_write(csi, EHC_INTEGRATION_PERIOD, us);
psee_sensor_write(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); hsync_clocks << CPI_PACKET_TIME_CONTROL_BLANKING_Pos);
// Wait for the camera to settle // Wait for the camera to settle
@ -271,24 +271,24 @@ static int set_brightness(omv_csi_t *csi, int level) {
static int set_colorbar(omv_csi_t *csi, int enable) { static int set_colorbar(omv_csi_t *csi, int enable) {
uint32_t reg; uint32_t reg;
psee_sensor_read(RO_READOUT_CTRL, &reg); psee_sensor_read(csi, RO_READOUT_CTRL, &reg);
reg = (reg & ~RO_READOUT_CTRL_ERC_SELF_TEST_EN) | (enable ? RO_READOUT_CTRL_ERC_SELF_TEST_EN : 0); reg = (reg & ~RO_READOUT_CTRL_ERC_SELF_TEST_EN) | (enable ? RO_READOUT_CTRL_ERC_SELF_TEST_EN : 0);
psee_sensor_write(RO_READOUT_CTRL, reg); psee_sensor_write(csi, RO_READOUT_CTRL, reg);
return 0; return 0;
} }
static int set_hmirror(omv_csi_t *csi, int enable) { static int set_hmirror(omv_csi_t *csi, int enable) {
psee_sensor_set_flip(enable, csi->vflip); psee_sensor_set_flip(csi, enable, csi->vflip);
return 0; return 0;
} }
static int set_vflip(omv_csi_t *csi, int enable) { static int set_vflip(omv_csi_t *csi, int enable) {
psee_sensor_set_flip(csi->hmirror, enable); psee_sensor_set_flip(csi, csi->hmirror, enable);
return 0; return 0;
} }
#if (OMV_GENX320_CAL_ENABLE == 1) #if (OMV_GENX320_CAL_ENABLE == 1)
static void disable_hot_pixels(uint8_t *histogram) { static void disable_hot_pixels(omv_csi_t *csi, uint8_t *histogram) {
// Compute average // Compute average
int32_t avg = 0; int32_t avg = 0;
@ -313,15 +313,15 @@ static void disable_hot_pixels(uint8_t *histogram) {
for (uint32_t y = 0; y < ACTIVE_SENSOR_HEIGHT; y++) { for (uint32_t y = 0; y < ACTIVE_SENSOR_HEIGHT; y++) {
// Reset all blocks // Reset all blocks
for (uint32_t i = 0; i < (ACTIVE_SENSOR_WIDTH / UINT32_T_BITS); i++) { for (uint32_t i = 0; i < (ACTIVE_SENSOR_WIDTH / UINT32_T_BITS); i++) {
psee_write_ROI_X(i * sizeof(uint32_t), 0); psee_write_ROI_X(csi, i * sizeof(uint32_t), 0);
} }
// Select line // Select line
uint32_t offset = y / UINT32_T_BITS; uint32_t offset = y / UINT32_T_BITS;
psee_write_ROI_Y(offset * sizeof(uint32_t), 1 << (y % UINT32_T_BITS)); psee_write_ROI_Y(csi, offset * sizeof(uint32_t), 1 << (y % UINT32_T_BITS));
// Trigger shadow // Trigger shadow
psee_write_ROI_CTRL(ROI_CTRL_PX_SW_RSTN | ROI_CTRL_TD_SHADOW_TRIGGER); psee_write_ROI_CTRL(csi, ROI_CTRL_PX_SW_RSTN | ROI_CTRL_TD_SHADOW_TRIGGER);
uint32_t tmp[ACTIVE_SENSOR_WIDTH / UINT32_T_BITS] = {}; uint32_t tmp[ACTIVE_SENSOR_WIDTH / UINT32_T_BITS] = {};
for (uint32_t x = 0; x < ACTIVE_SENSOR_WIDTH; x++) { for (uint32_t x = 0; x < ACTIVE_SENSOR_WIDTH; x++) {
@ -332,15 +332,15 @@ static void disable_hot_pixels(uint8_t *histogram) {
// Write x values to disable // Write x values to disable
for (uint32_t i = 0; i < (ACTIVE_SENSOR_WIDTH / UINT32_T_BITS); i++) { for (uint32_t i = 0; i < (ACTIVE_SENSOR_WIDTH / UINT32_T_BITS); i++) {
psee_write_ROI_X(i * sizeof(uint32_t), tmp[i]); psee_write_ROI_X(csi, i * sizeof(uint32_t), tmp[i]);
} }
// Activate block // Activate block
psee_write_ROI_CTRL(ROI_CTRL_PX_SW_RSTN | ROI_CTRL_TD_SHADOW_TRIGGER | ROI_CTRL_TD_EN); psee_write_ROI_CTRL(csi, ROI_CTRL_PX_SW_RSTN | ROI_CTRL_TD_SHADOW_TRIGGER | ROI_CTRL_TD_EN);
// Disable roi block // Disable roi block
psee_write_ROI_CTRL(ROI_CTRL_PX_SW_RSTN); psee_write_ROI_CTRL(csi, ROI_CTRL_PX_SW_RSTN);
psee_write_ROI_Y(offset * sizeof(uint32_t), 0); psee_write_ROI_Y(csi, offset * sizeof(uint32_t), 0);
} }
} }
#endif // (OMV_GENX320_CAL_ENABLE == 1) #endif // (OMV_GENX320_CAL_ENABLE == 1)
@ -444,7 +444,7 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
snapshot_post_process(csi, image); snapshot_post_process(csi, image);
} }
disable_hot_pixels(histogram); disable_hot_pixels(csi, histogram);
fb_free(); fb_free();
hot_pixels_disabled = true; hot_pixels_disabled = true;
@ -471,52 +471,52 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
switch (mode) { switch (mode) {
case OMV_CSI_GENX320_BIASES_DEFAULT: { case OMV_CSI_GENX320_BIASES_DEFAULT: {
// Set default biases V2.0.0 // Set default biases V2.0.0
psee_sensor_set_bias(DIFF, 51); psee_sensor_set_bias(csi, DIFF, 51);
psee_sensor_set_bias(DIFF_OFF, 28); psee_sensor_set_bias(csi, DIFF_OFF, 28);
psee_sensor_set_bias(DIFF_ON, 25); psee_sensor_set_bias(csi, DIFF_ON, 25);
psee_sensor_set_bias(FO, 34); psee_sensor_set_bias(csi, FO, 34);
psee_sensor_set_bias(HPF, 40); psee_sensor_set_bias(csi, HPF, 40);
psee_sensor_set_bias(REFR, 10); psee_sensor_set_bias(csi, REFR, 10);
break; break;
} }
case OMV_CSI_GENX320_BIASES_LOW_LIGHT: { case OMV_CSI_GENX320_BIASES_LOW_LIGHT: {
// Set biases tuned for low light // Set biases tuned for low light
psee_sensor_set_bias(DIFF, 51); psee_sensor_set_bias(csi, DIFF, 51);
psee_sensor_set_bias(DIFF_OFF, 19); psee_sensor_set_bias(csi, DIFF_OFF, 19);
psee_sensor_set_bias(DIFF_ON, 24); psee_sensor_set_bias(csi, DIFF_ON, 24);
psee_sensor_set_bias(FO, 19); psee_sensor_set_bias(csi, FO, 19);
psee_sensor_set_bias(HPF, 0); psee_sensor_set_bias(csi, HPF, 0);
psee_sensor_set_bias(REFR, 10); psee_sensor_set_bias(csi, REFR, 10);
break; break;
} }
case OMV_CSI_GENX320_BIASES_ACTIVE_MARKER: { case OMV_CSI_GENX320_BIASES_ACTIVE_MARKER: {
// Set biases tuned for active marker // Set biases tuned for active marker
psee_sensor_set_bias(DIFF, 51); psee_sensor_set_bias(csi, DIFF, 51);
psee_sensor_set_bias(DIFF_OFF, 45); //127 psee_sensor_set_bias(csi, DIFF_OFF, 45); //127
psee_sensor_set_bias(DIFF_ON, 55); //78 psee_sensor_set_bias(csi, DIFF_ON, 55); //78
psee_sensor_set_bias(FO, 50); psee_sensor_set_bias(csi, FO, 50);
psee_sensor_set_bias(HPF, 127); psee_sensor_set_bias(csi, HPF, 127);
psee_sensor_set_bias(REFR, 0); psee_sensor_set_bias(csi, REFR, 0);
break; break;
} }
case OMV_CSI_GENX320_BIASES_LOW_NOISE: { case OMV_CSI_GENX320_BIASES_LOW_NOISE: {
// Set low sensitivity low noise biases // Set low sensitivity low noise biases
psee_sensor_set_bias(DIFF, 51); psee_sensor_set_bias(csi, DIFF, 51);
psee_sensor_set_bias(DIFF_OFF, 38); psee_sensor_set_bias(csi, DIFF_OFF, 38);
psee_sensor_set_bias(DIFF_ON, 35); psee_sensor_set_bias(csi, DIFF_ON, 35);
psee_sensor_set_bias(FO, 24); psee_sensor_set_bias(csi, FO, 24);
psee_sensor_set_bias(HPF, 40); psee_sensor_set_bias(csi, HPF, 40);
psee_sensor_set_bias(REFR, 10); psee_sensor_set_bias(csi, REFR, 10);
break; break;
} }
case OMV_CSI_GENX320_BIASES_HIGH_SPEED: { case OMV_CSI_GENX320_BIASES_HIGH_SPEED: {
// Set biases tuned for high speed motion // Set biases tuned for high speed motion
psee_sensor_set_bias(DIFF, 51); psee_sensor_set_bias(csi, DIFF, 51);
psee_sensor_set_bias(DIFF_OFF, 26); psee_sensor_set_bias(csi, DIFF_OFF, 26);
psee_sensor_set_bias(DIFF_ON, 37); psee_sensor_set_bias(csi, DIFF_ON, 37);
psee_sensor_set_bias(FO, 38); psee_sensor_set_bias(csi, FO, 38);
psee_sensor_set_bias(HPF, 74); psee_sensor_set_bias(csi, HPF, 74);
psee_sensor_set_bias(REFR, 25); psee_sensor_set_bias(csi, REFR, 25);
break; break;
} }
default: { default: {
@ -532,23 +532,23 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
int bias_value = va_arg(ap, int); int bias_value = va_arg(ap, int);
switch (bias_name) { switch (bias_name) {
case OMV_CSI_GENX320_BIAS_DIFF_OFF: { case OMV_CSI_GENX320_BIAS_DIFF_OFF: {
psee_sensor_set_bias(DIFF_OFF, bias_value); psee_sensor_set_bias(csi, DIFF_OFF, bias_value);
break; break;
} }
case OMV_CSI_GENX320_BIAS_DIFF_ON: { case OMV_CSI_GENX320_BIAS_DIFF_ON: {
psee_sensor_set_bias(DIFF_ON, bias_value); psee_sensor_set_bias(csi, DIFF_ON, bias_value);
break; break;
} }
case OMV_CSI_GENX320_BIAS_FO: { case OMV_CSI_GENX320_BIAS_FO: {
psee_sensor_set_bias(FO, bias_value); psee_sensor_set_bias(csi, FO, bias_value);
break; break;
} }
case OMV_CSI_GENX320_BIAS_HPF: { case OMV_CSI_GENX320_BIAS_HPF: {
psee_sensor_set_bias(HPF, bias_value); psee_sensor_set_bias(csi, HPF, bias_value);
break; break;
} }
case OMV_CSI_GENX320_BIAS_REFR: { case OMV_CSI_GENX320_BIAS_REFR: {
psee_sensor_set_bias(REFR, bias_value); psee_sensor_set_bias(csi, REFR, bias_value);
break; break;
} }
default: { default: {
@ -572,7 +572,7 @@ static int ioctl(omv_csi_t *csi, int request, va_list ap) {
// Enable AFK // Enable AFK
int freq_min = va_arg(ap, int); int freq_min = va_arg(ap, int);
int freq_max = va_arg(ap, int); int freq_max = va_arg(ap, int);
if (psee_afk_init(&psee_afk) != AFK_OK) { if (psee_afk_init(csi, &psee_afk) != AFK_OK) {
ret = -1; ret = -1;
} }
if (psee_afk_activate(&psee_afk, freq_min, freq_max, EVT_CLK_FREQ) != AFK_OK) { if (psee_afk_activate(&psee_afk, freq_min, freq_max, EVT_CLK_FREQ) != AFK_OK) {