diff --git a/include/T40/imp/imp_isp.h b/include/T40/imp/imp_isp.h index fdb7a401..093775a7 100644 --- a/include/T40/imp/imp_isp.h +++ b/include/T40/imp/imp_isp.h @@ -737,6 +737,13 @@ typedef enum { IMPISP_FLIP_MODE_BUTT, /**< 用于判断参数的有效性,参数大小必须小于这个值 */ } IMPISPHVFLIP; + +typedef struct { + IMPISPHVFLIP sensor_mode; /**< Flip mode corresponding to sensor */ + IMPISPHVFLIP isp_mode[3]; /**< Flip mode for each ISP channel */ +} IMPISPHVFLIPAttr; + + /** * @fn int32_t IMP_ISP_Tuning_SetHVFLIP(IMPVI_NUM num, IMPISPHVFLIP *hvflip) * diff --git a/src/IMPSystem.cpp b/src/IMPSystem.cpp index 91062881..88fc984d 100644 --- a/src/IMPSystem.cpp +++ b/src/IMPSystem.cpp @@ -1,229 +1,232 @@ #include "IMPSystem.hpp" #include "Config.hpp" +#include +#include +#include +#include +#include #define MODULE "IMP_SYSTEM" +/* first sensor */ +#define FIRST_SNESOR_NAME "gc4653" //sensor name (match with snesor driver name) +#define FIRST_I2C_ADDR 0x29 //sensor i2c address +#define FIRST_I2C_ADAPTER_ID 1 //sensor controller number used (0/1/2/3) +#define FIRST_SENSOR_WIDTH 2560 //sensor width +#define FIRST_SENSOR_HEIGHT 1440 //sensor height +#define FIRST_RST_GPIO GPIO_PC(27) //sensor reset gpio +#define FIRST_PWDN_GPIO -1 //sensor pwdn gpio +#define FIRST_POWER_GPIO -1 //sensor power gpio +#define FIRST_SENSOR_ID 0 //sensor index +#define FIRST_VIDEO_INTERFACE IMPISP_SENSOR_VI_MIPI_CSI0 //sensor interface type (dvp/csi0/csi1) +#define FIRST_MCLK IMPISP_SENSOR_MCLK1 //sensor clk source (mclk0/mclk1/mclk2) +#define FIRST_DEFAULT_BOOT 0 //sensor default mode(0/1/2/3/4) +#define DUALSENSOR_MODE IMPISP_DUALSENSOR_DUAL_ALLCACHED_MODE //dualsensor mode () + +// Define our static sensor configuration +static IMPSensorInfo Def_Sensor_Info = { + .name = "gc4653", + .cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C, + .i2c = { + .type = "gc4653", + .addr = 0x29, + .i2c_adapter_id = 1 + }, + .rst_gpio = GPIO_PC(27), // This should match your hardware + .pwdn_gpio = -1, // Set to appropriate GPIO if you have PWDN connected + .power_gpio = -1, // Set to appropriate GPIO if you have POWER control + .sensor_id = FIRST_SENSOR_ID, + .video_interface = FIRST_VIDEO_INTERFACE, + .mclk = FIRST_MCLK, + .default_boot = FIRST_DEFAULT_BOOT +}; +static IMPSensorInfo sensor_info[3]; // Array for up to 3 sensors + +static IMPISPCameraInputMode mode = { + .sensor_num = IMPISP_TOTAL_ONE, + .dual_mode = DUALSENSOR_MODE, + .dual_mode_switch = { + .en = IMPISP_TUNING_OPS_MODE_DISABLE, // Use proper enum instead of 0 + }, + .joint_mode = IMPISP_NOT_JOINT, +}; + +static bool sensor_bypass[3] = {0, 0, 1}; + +// You'll also need the channel config structure +extern struct chn_conf chn[]; // This should be defined in your equivalent of sample-common.h + + IMPSensorInfo IMPSystem::create_sensor_info(const char *sensor_name) { IMPSensorInfo out; memset(&out, 0, sizeof(IMPSensorInfo)); - LOG_INFO("Sensor: " << cfg->sensor.model); - strcpy(out.name, cfg->sensor.model); - out.cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C; - strcpy(out.i2c.type, cfg->sensor.model); - out.i2c.addr = cfg->sensor.i2c_address; - return out; -} - -IMPSystem *IMPSystem::createNew() -{ - return new IMPSystem(); -} - -int IMPSystem::init() -{ - LOG_DEBUG("IMPSystem::init()"); - int ret = 0; - -#if !(defined(PLATFORM_T40) || defined(PLATFORM_T41)) - ret = IMP_OSD_SetPoolSize(cfg->general.osd_pool_size * 1024); - LOG_DEBUG_OR_ERROR(ret, "IMP_OSD_SetPoolSize(" << (cfg->general.osd_pool_size * 1024) << ")"); -#endif - IMPVersion impVersion; - ret = IMP_System_GetVersion(&impVersion); - LOG_INFO("LIBIMP Version " << impVersion.aVersion); - - SUVersion suVersion; - ret = SU_Base_GetVersion(&suVersion); - LOG_INFO("SYSUTILS Version: " << suVersion.chr); - - cfg->sysinfo.cpu = IMP_System_GetCPUInfo(); - LOG_INFO("CPU Information: " << cfg->sysinfo.cpu); - - ret = IMP_ISP_Open(); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_Open()"); - - /* sensor */ - sinfo = create_sensor_info(cfg->sensor.model); -#if defined(PLATFORM_T40) || defined(PLATFORM_T41) - ret = IMP_ISP_AddSensor(IMPVI_MAIN, &sinfo); - ret = IMP_ISP_EnableSensor(IMPVI_MAIN, &sinfo); -#else - ret = IMP_ISP_AddSensor(&sinfo); -#endif - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_AddSensor(&sinfo)"); - -#if defined(PLATFORM_T40) || defined(PLATFORM_T41) - ret = IMP_ISP_EnableSensor(IMPVI_MAIN, &sinfo); -#else - ret = IMP_ISP_EnableSensor(); -#endif - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_EnableSensor()"); - - /* system */ - ret = IMP_System_Init(); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_System_Init()"); - - ret = IMP_ISP_EnableTuning(); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_EnableTuning()"); - -#if !defined(NO_TUNINGS) - ret = IMP_ISP_Tuning_SetContrast(cfg->image.contrast); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetContrast(" << cfg->image.contrast << ")"); - - ret = IMP_ISP_Tuning_SetSharpness(cfg->image.sharpness); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetSharpness(" << cfg->image.sharpness << ")"); - - ret = IMP_ISP_Tuning_SetSaturation(cfg->image.saturation); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetSaturation(" << cfg->image.saturation << ")"); + // Name and bus settings + strncpy(out.name, "gc4653", sizeof(out.name) - 1); + out.cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C; - ret = IMP_ISP_Tuning_SetBrightness(cfg->image.brightness); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetBrightness(" << cfg->image.brightness << ")"); + // I2C settings + strncpy(out.i2c.type, "gc4653", sizeof(out.i2c.type) - 1); + out.i2c.addr = 0x29; + out.i2c.i2c_adapter_id = 1; // Added this to use I2C1 instead of I2C0 - ret = IMP_ISP_Tuning_SetContrast(cfg->image.contrast); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetContrast(" << cfg->image.contrast << ")"); + // GPIO settings + out.rst_gpio = GPIO_PC(27); + out.pwdn_gpio = -1; + out.power_gpio = -1; - ret = IMP_ISP_Tuning_SetSharpness(cfg->image.sharpness); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetSharpness(" << cfg->image.sharpness << ")"); + // Sensor identification + out.sensor_id = 0; - ret = IMP_ISP_Tuning_SetSaturation(cfg->image.saturation); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetSaturation(" << cfg->image.saturation << ")"); + // Interface settings + out.video_interface = IMPISP_SENSOR_VI_MIPI_CSI0; // Using CSI0 MIPI interface + out.mclk = IMPISP_SENSOR_MCLK0; // Using primary MCLK source - ret = IMP_ISP_Tuning_SetBrightness(cfg->image.brightness); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetBrightness(" << cfg->image.brightness << ")"); + // Boot settings + out.default_boot = 0; -#if !defined(PLATFORM_T21) - ret = IMP_ISP_Tuning_SetSinterStrength(cfg->image.sinter_strength); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetSinterStrength(" << cfg->image.sinter_strength << ")"); -#endif + return out; +} - ret = IMP_ISP_Tuning_SetTemperStrength(cfg->image.temper_strength); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetTemperStrength(" << cfg->image.temper_strength << ")"); +int IMPSystem::setupSensorGPIO() { + int ret; - ret = IMP_ISP_Tuning_SetISPHflip((IMPISPTuningOpsMode)cfg->image.hflip); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetISPHflip(" << cfg->image.hflip << ")"); + // Configure reset GPIO (PC27) + // First export the GPIO if not already exported + int fd = open("/sys/class/gpio/export", O_WRONLY); + if (fd >= 0) { + write(fd, "91", 2); // PC27 is GPIO 91 (you may need to adjust this number based on your platform) + close(fd); + } - ret = IMP_ISP_Tuning_SetISPVflip((IMPISPTuningOpsMode)cfg->image.vflip); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetISPVflip(" << cfg->image.vflip << ")"); + // Set direction to out + fd = open("/sys/class/gpio/gpio91/direction", O_WRONLY); + if (fd < 0) { + IMP_LOG_ERR(TAG, "Failed to open GPIO direction file\n"); + return -1; + } + write(fd, "out", 3); + close(fd); + + // Toggle reset + fd = open("/sys/class/gpio/gpio91/value", O_WRONLY); + if (fd < 0) { + IMP_LOG_ERR(TAG, "Failed to open GPIO value file\n"); + return -1; + } - ret = IMP_ISP_Tuning_SetISPRunningMode((IMPISPRunningMode)cfg->image.running_mode); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetISPRunningMode(" << cfg->image.running_mode << ")"); + // Reset sequence + write(fd, "0", 1); // Assert reset + usleep(10000); // Hold for 10ms + write(fd, "1", 1); // Release reset + usleep(10000); // Wait for 10ms - ret = IMP_ISP_Tuning_SetISPBypass(IMPISP_TUNING_OPS_MODE_ENABLE); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetISPBypass(" << IMPISP_TUNING_OPS_MODE_ENABLE << ")"); + close(fd); - IMPISPAntiflickerAttr flickerAttr; - memset(&flickerAttr, 0, sizeof(IMPISPAntiflickerAttr)); - ret = IMP_ISP_Tuning_SetAntiFlickerAttr((IMPISPAntiflickerAttr)cfg->image.anti_flicker); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetAntiFlickerAttr(" << cfg->image.anti_flicker << ")"); + return 0; +} -#if !defined(PLATFORM_T21) - ret = IMP_ISP_Tuning_SetAeComp(cfg->image.ae_compensation); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetAeComp(" << cfg->image.ae_compensation << ")"); -#endif +IMPSystem *IMPSystem::createNew() +{ + return new IMPSystem(); +} - ret = IMP_ISP_Tuning_SetMaxAgain(cfg->image.max_again); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetMaxAgain(" << cfg->image.max_again << ")"); +int IMPSystem::init() +{ + int ret = 0; - ret = IMP_ISP_Tuning_SetMaxDgain(cfg->image.max_dgain); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetMaxDgain(" << cfg->image.max_dgain << ")"); + // Initialize OSD memory pool + IMP_ISP_Tuning_SetOsdPoolSize(512*1024); - IMPISPWB wb; - memset(&wb, 0, sizeof(IMPISPWB)); - wb.mode = (isp_core_wb_mode)cfg->image.core_wb_mode; - wb.rgain = cfg->image.wb_rgain; - wb.bgain = cfg->image.wb_bgain; - ret = IMP_ISP_Tuning_SetWB(&wb); - if (ret != 0) - { - LOG_ERROR("Unable to set white balance. Mode: " << cfg->image.core_wb_mode << ", rgain: " - << cfg->image.wb_rgain << ", bgain: " << cfg->image.wb_bgain); + // Initialize sensor info with the same pattern as sample + memset(&sensor_info, 0, sizeof(sensor_info)); + if(mode.sensor_num == IMPISP_TOTAL_ONE) { + memcpy(&sensor_info[0], &Def_Sensor_Info, sizeof(IMPSensorInfo)); } - else - { - LOG_DEBUG("Set white balance. Mode: " << cfg->image.core_wb_mode << ", rgain: " - << cfg->image.wb_rgain << ", bgain: " << cfg->image.wb_bgain); + + ret = IMP_ISP_Open(); + if(ret < 0) { + IMP_LOG_ERR(TAG, "failed to open ISP\n"); + return -1; } -#if defined(PLATFORM_T23) || defined(PLATFORM_T31) - ret = IMP_ISP_Tuning_SetBcshHue(cfg->image.hue); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetBcshHue(" << cfg->image.hue << ")"); - - uint8_t _defog_strength = static_cast(cfg->image.defog_strength); - ret = IMP_ISP_Tuning_SetDefog_Strength(reinterpret_cast(&_defog_strength)); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetDefog_Strength(" << cfg->image.defog_strength << ")"); - - ret = IMP_ISP_Tuning_SetDPC_Strength(cfg->image.dpc_strength); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetDPC_Strength(" << cfg->image.dpc_strength << ")"); -#endif -#if defined(PLATFORM_T21) || defined(PLATFORM_T23) || defined(PLATFORM_T31) - ret = IMP_ISP_Tuning_SetDRC_Strength(cfg->image.drc_strength); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetDRC_Strength(" << cfg->image.drc_strength << ")"); -#endif - -#if defined(PLATFORM_T23) || defined(PLATFORM_T31) - if (cfg->image.backlight_compensation > 0) - { - ret = IMP_ISP_Tuning_SetBacklightComp(cfg->image.backlight_compensation); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetBacklightComp(" << cfg->image.backlight_compensation << ")"); + // Handle bypass mode for each sensor (from sample) + for(int i = 0; i < mode.sensor_num; i++) { + IMPVI_NUM vinum = (i == 0) ? IMPVI_MAIN : (i == 1) ? IMPVI_SEC : IMPVI_THR; + + if(!sensor_bypass[i]) { + continue; + } + + // Set ISP bypass mode + IMPISPTuningOpsMode bypass_en = IMPISP_TUNING_OPS_MODE_ENABLE; + ret = IMP_ISP_Tuning_SetISPBypass(vinum, &bypass_en); + if (ret < 0) { + IMP_LOG_ERR(TAG, "IMP_ISP_Tuning_SetISPBypass(%d) failed\n", i); + return -1; + } } - else if (cfg->image.highlight_depress > 0) - { - ret = IMP_ISP_Tuning_SetHiLightDepress(cfg->image.highlight_depress); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetHiLightDepress(" << cfg->image.highlight_depress << ")"); + + // Set camera input mode if needed + if(mode.sensor_num > IMPISP_TOTAL_ONE) { + ret = IMP_ISP_SetCameraInputMode(&mode); + if(ret < 0) { + IMP_LOG_ERR(TAG, "failed to set camera input mode!\n"); + return -1; + } } -#elif defined(PLATFORM_T21) || defined(PLATFORM_T30) - ret = IMP_ISP_Tuning_SetHiLightDepress(cfg->image.highlight_depress); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Tuning_SetHiLightDepress(" << cfg->image.highlight_depress << ")"); -#endif - LOG_DEBUG("ISP Tuning Defaults set"); + ret = IMP_ISP_AddSensor(IMPVI_MAIN, &sensor_info[0]); + if(ret < 0) { + IMP_LOG_ERR(TAG, "failed to AddSensor\n"); + return -1; + } - ret = IMP_ISP_Tuning_SetSensorFPS(cfg->sensor.fps, 1); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_Tuning_SetSensorFPS(" << cfg->sensor.fps << ", 1)"); + ret = IMP_ISP_EnableSensor(IMPVI_MAIN, &sensor_info[0]); + if(ret < 0) { + IMP_LOG_ERR(TAG, "failed to EnableSensor\n"); + return -1; + } -#if defined(PLATFORM_T21) - //T20 T21 only set FPS if it is read after set. - uint32_t fps_num, fps_den; - ret = IMP_ISP_Tuning_GetSensorFPS(&fps_num, &fps_den); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_Tuning_GetSensorFPS(" << fps_num << ", " << fps_den << ")"); -#endif + ret = IMP_System_Init(); + if(ret < 0) { + IMP_LOG_ERR(TAG, "IMP_System_Init failed\n"); + return -1; + } - // Set the ISP to DAY on launch - ret = IMP_ISP_Tuning_SetISPRunningMode(IMPISP_RUNNING_MODE_DAY); - LOG_DEBUG_OR_ERROR_AND_EXIT(ret, "IMP_ISP_Tuning_SetISPRunningMode(" << IMPISP_RUNNING_MODE_DAY << ")"); -#endif // #if !defined(NO_TUNINGS) + ret = IMP_ISP_EnableTuning(); + if(ret < 0) { + IMP_LOG_ERR(TAG, "IMP_ISP_EnableTuning failed\n"); + return -1; + } - return ret; + return 0; } -int IMPSystem::destroy() -{ +int IMPSystem::destroy() { int ret; + IMPVI_NUM vinum = IMPVI_MAIN; - ret = IMP_System_Exit(); - LOG_DEBUG_OR_ERROR(ret, "IMP_System_Exit()"); - -#if defined(PLATFORM_T40) || defined(PLATFORM_T41) - ret = IMP_ISP_DisableSensor(IMPVI_MAIN); -#else - ret = IMP_ISP_DisableSensor(); -#endif - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_DisableSensor()"); + ret = IMP_ISP_DisableSensor(vinum); + if(ret < 0) { + IMP_LOG_ERR(TAG, "Failed to disable sensor\n"); + } -#if defined(PLATFORM_T40) || defined(PLATFORM_T41) - ret = IMP_ISP_DelSensor(IMPVI_MAIN, &sinfo); -#else - ret = IMP_ISP_DelSensor(&sinfo); -#endif - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_DelSensor()"); + ret = IMP_ISP_DelSensor(vinum, &sensor_info[0]); // Using the correct sensor info array + if(ret < 0) { + IMP_LOG_ERR(TAG, "Failed to delete sensor\n"); + } ret = IMP_ISP_DisableTuning(); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_DisableTuning()"); + if(ret < 0) { + IMP_LOG_ERR(TAG, "Failed to disable tuning\n"); + } ret = IMP_ISP_Close(); - LOG_DEBUG_OR_ERROR(ret, "IMP_ISP_Close()"); + if(ret < 0) { + IMP_LOG_ERR(TAG, "Failed to close ISP\n"); + } return 0; -} +} \ No newline at end of file diff --git a/src/IMPSystem.hpp b/src/IMPSystem.hpp index 2f0af893..573cde69 100644 --- a/src/IMPSystem.hpp +++ b/src/IMPSystem.hpp @@ -1,45 +1,44 @@ #ifndef IMPSystem_hpp #define IMPSystem_hpp -#include "Logger.hpp" -#include "Config.hpp" -#include -#include -#include -#include +#include +#include #include #include -#include <../sysutils/su_base.h> +#include +#include +#include +#include "Logger.hpp" +#include "Config.hpp" + +#define TAG "IMP_SYSTEM" -class IMPSystem -{ -public: - static IMPSystem *createNew(); - IMPSystem() - { - if( init() != 0 && Logger::level != Logger::DEBUG) { +// We need to match the sample's structure - define this in header +struct chn_conf { + int index; + IMPFSChnAttr fs_chn_attr; + // Add other fields as needed from sample-common.h +}; - throw std::invalid_argument("error initializing the imp system."); - }; +class IMPSystem { +public: + static IMPSystem *createNew(); - /* - / https://github.com/rara64/prudynt-t/commit/7eda99252b0d1309cbe134dc4143182eda9c21bd - */ + IMPSystem() { + if(init() != 0) { + throw std::invalid_argument("Error initializing the imp system"); + } struct timespec timeSinceBoot; clock_gettime(CLOCK_MONOTONIC, &timeSinceBoot); - uint64_t imp_time_base = (timeSinceBoot.tv_sec * 1000000) + (timeSinceBoot.tv_nsec / 1000); IMP_System_RebaseTimeStamp(imp_time_base); - - LOG_DEBUG("IMP_System_RebaseTimeStamp(" << imp_time_base << ");"); } - ~IMPSystem() - { + ~IMPSystem() { destroy(); - }; + } int init(); int destroy(); @@ -47,6 +46,7 @@ class IMPSystem private: IMPSensorInfo sinfo{}; IMPSensorInfo create_sensor_info(const char *sensor_name); + int setupSensorGPIO(); }; #endif \ No newline at end of file diff --git a/src/WS.cpp b/src/WS.cpp index 9cbd09c9..fb09ab8e 100644 --- a/src/WS.cpp +++ b/src/WS.cpp @@ -785,294 +785,110 @@ signed char WS::sensor_callback(struct lejp_ctx *ctx, char reason) return 0; } -signed char WS::image_callback(struct lejp_ctx *ctx, char reason) -{ +signed char WS::image_callback(struct lejp_ctx *ctx, char reason) { struct user_ctx *u_ctx = (struct user_ctx *)ctx->user; + const IMPVI_NUM vinum = IMPVI_MAIN; + int ret = 0; -#if !defined(NO_TUNINGS) - if (reason & LEJP_FLAG_CB_IS_VALUE && ctx->path_match) - { + if (reason & LEJP_FLAG_CB_IS_VALUE && ctx->path_match) { u_ctx->path = u_ctx->root + "." + std::string(ctx->path); - - add_json_key(u_ctx->message, (u_ctx->flag & PNT_FLAG_SEPARATOR), image_keys[ctx->path_match - 1]); - + add_json_key(u_ctx->message, (u_ctx->flag & PNT_FLAG_SEPARATOR), + image_keys[ctx->path_match - 1]); u_ctx->flag |= PNT_FLAG_SEPARATOR; - if (ctx->path_match == PNT_IMAGE_DEFOG_STRENGTH) - { -#if !defined(PLATFORM_T10) && !defined(PLATFORM_T20) && !defined(PLATFORM_T21) && !defined(PLATFORM_T23) && !defined(PLATFORM_T30) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - uint8_t t = static_cast(cfg->get(u_ctx->path)); - IMP_ISP_Tuning_SetDefog_Strength(reinterpret_cast(&t)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - } - else if (ctx->path_match >= PNT_IMAGE_CORE_WB_MODE && ctx->path_match <= PNT_IMAGE_WB_BGAIN) - { - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMPISPWB wb; - memset(&wb, 0, sizeof(IMPISPWB)); - int ret = IMP_ISP_Tuning_GetWB(&wb); - if (ret == 0) - { - wb.mode = (isp_core_wb_mode)cfg->image.core_wb_mode; - wb.rgain = cfg->image.wb_rgain; - wb.bgain = cfg->image.wb_bgain; - ret = IMP_ISP_Tuning_SetWB(&wb); - } - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - } - else - { - switch (ctx->path_match) - { - case PNT_IMAGE_BRIGHTNESS: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetBrightness(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_CONTRAST: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetContrast(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_HUE: -#if !defined(PLATFORM_T10) && !defined(PLATFORM_T20) && !defined(PLATFORM_T21) && !defined(PLATFORM_T23) && !defined(PLATFORM_T30) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetBcshHue(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_SATURATION: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetSaturation(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_SHARPNESS: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetSharpness(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_SINTER_STRENGTH: -#if !defined(PLATFORM_T21) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetSinterStrength(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_TEMPER_STRENGTH: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetTemperStrength(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_VFLIP: - if (reason == LEJPCB_VAL_TRUE) - { - if (cfg->set(u_ctx->path, true)) - { - IMP_ISP_Tuning_SetISPVflip(IMPISP_TUNING_OPS_MODE_ENABLE); - } - } - else if (reason == LEJPCB_VAL_FALSE) - { - if (cfg->set(u_ctx->path, false)) - { - IMP_ISP_Tuning_SetISPVflip(IMPISP_TUNING_OPS_MODE_DISABLE); - } - } - add_json_bool(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_HFLIP: - if (reason == LEJPCB_VAL_TRUE) - { - if (cfg->set(u_ctx->path, true)) - { - IMP_ISP_Tuning_SetISPHflip(IMPISP_TUNING_OPS_MODE_ENABLE); - } - } - else if (reason == LEJPCB_VAL_FALSE) - { - if (cfg->set(u_ctx->path, false)) - { - IMP_ISP_Tuning_SetISPHflip(IMPISP_TUNING_OPS_MODE_DISABLE); - } - } - add_json_bool(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_ANTIFLICKER: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetAntiFlickerAttr((IMPISPAntiflickerAttr)cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_RUNNING_MODE: - { - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetISPRunningMode((IMPISPRunningMode)cfg->get(u_ctx->path)); - } - } + if (reason == LEJPCB_VAL_NUM_INT || + reason == LEJPCB_VAL_TRUE || + reason == LEJPCB_VAL_FALSE) { - IMPISPRunningMode running_mode; - IMP_ISP_Tuning_GetISPRunningMode(&running_mode); + switch (ctx->path_match) { + case PNT_IMAGE_BRIGHTNESS: { + unsigned char value = (unsigned char)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetBrightness(vinum, &value); add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; } - break; - case PNT_IMAGE_AE_COMPENSATION: -#if !defined(PLATFORM_T21) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetAeComp(cfg->get(u_ctx->path)); - } - } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_DPC_STRENGTH: -#if !defined(PLATFORM_T10) && !defined(PLATFORM_T20) && !defined(PLATFORM_T21) && !defined(PLATFORM_T23) && !defined(PLATFORM_T30) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetDPC_Strength(cfg->get(u_ctx->path)); - } + + case PNT_IMAGE_CONTRAST: { + unsigned char value = (unsigned char)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetContrast(vinum, &value); + add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_DRC_STRENGTH: -#if !defined(PLATFORM_T10) && !defined(PLATFORM_T20) && !defined(PLATFORM_T21) && !defined(PLATFORM_T23) && !defined(PLATFORM_T30) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetDRC_Strength(cfg->get(u_ctx->path)); - } + + case PNT_IMAGE_SATURATION: { + unsigned char value = (unsigned char)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetSaturation(vinum, &value); + add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_HIGHLIGHT_DEPRESS: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetHiLightDepress(cfg->get(u_ctx->path)); - } + + case PNT_IMAGE_SHARPNESS: { + unsigned char value = (unsigned char)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetSharpness(vinum, &value); + add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; + } + + case PNT_IMAGE_VFLIP: + case PNT_IMAGE_HFLIP: { + bool newHFlip = (ctx->path_match == PNT_IMAGE_HFLIP) ? + (reason == LEJPCB_VAL_TRUE) : cfg->get("/image/hflip"); + bool newVFlip = (ctx->path_match == PNT_IMAGE_VFLIP) ? + (reason == LEJPCB_VAL_TRUE) : cfg->get("/image/vflip"); + + IMPISPHVFLIP flip_mode; + if (newHFlip && newVFlip) { + flip_mode = IMPISP_FLIP_HV_MODE; + } else if (newHFlip) { + flip_mode = IMPISP_FLIP_H_MODE; + } else if (newVFlip) { + flip_mode = IMPISP_FLIP_V_MODE; + } else { + flip_mode = IMPISP_FLIP_NORMAL_MODE; + } + ret = IMP_ISP_Tuning_SetHVFLIP(vinum, &flip_mode); + + bool *target = (ctx->path_match == PNT_IMAGE_HFLIP) ? &newHFlip : &newVFlip; + cfg->set(u_ctx->path, *target); + add_json_bool(u_ctx->message, *target); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_BACKLIGHT_COMPENSTATION: -#if !defined(PLATFORM_T10) && !defined(PLATFORM_T20) && !defined(PLATFORM_T21) && !defined(PLATFORM_T23) && !defined(PLATFORM_T30) - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetBacklightComp(cfg->get(u_ctx->path)); - } + + case PNT_IMAGE_RUNNING_MODE: { + IMPISPRunningMode mode = (IMPISPRunningMode)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetISPRunningMode(vinum, &mode); + add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); -#else - add_json_null(u_ctx->message); -#endif - break; - case PNT_IMAGE_MAX_AGAIN: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetMaxAgain(cfg->get(u_ctx->path)); - } + + case PNT_IMAGE_ANTIFLICKER: { + IMPISPAntiflickerAttr attr; + attr.freq = 50; + attr.mode = (IMPISPAntiflickerMode)cfg->get(u_ctx->path); + ret = IMP_ISP_Tuning_SetAntiFlickerAttr(vinum, &attr); + add_json_num(u_ctx->message, cfg->get(u_ctx->path)); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - case PNT_IMAGE_MAX_DGAIN: - if (reason == LEJPCB_VAL_NUM_INT) - { - if (cfg->set(u_ctx->path, atoi(ctx->buf))) - { - IMP_ISP_Tuning_SetMaxDgain(cfg->get(u_ctx->path)); - } + + default: { + // For unsupported parameters on T40 + add_json_null(u_ctx->message); + break; } - add_json_num(u_ctx->message, cfg->get(u_ctx->path)); - break; - default: - u_ctx->flag &= ~PNT_FLAG_SEPARATOR; - break; + } + + // Common error handling + if (ret < 0) { + LOG_ERROR("Failed to set image parameter: " << ctx->path); } } } - else if (reason == LEJPCB_OBJECT_END) - { + else if (reason == LEJPCB_OBJECT_END) { + u_ctx->flag |= PNT_FLAG_SEPARATOR; u_ctx->message.append("}"); lejp_parser_pop(ctx); } -#endif + return 0; }