SC2310.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. /******************************************************************************\ |* Copyright (c) 2020 by VeriSilicon Holdings Co., Ltd. ("VeriSilicon") *| |* All Rights Reserved. *| |* *| |* The material in this file is confidential and contains trade secrets of *| |* of VeriSilicon. This is proprietary information owned or licensed by *| |* VeriSilicon. No part of this work may be disclosed, reproduced, copied, *| |* transmitted, or used in any way for any purpose, without the express *| |* written permission of VeriSilicon. *| |* *|
  2. \******************************************************************************/
  3. #include <ebase/types.h>
  4. #include <ebase/trace.h>
  5. #include <ebase/builtins.h>
  6. #include <common/return_codes.h>
  7. #include <common/misc.h>
  8. #include <sys/ioctl.h>
  9. #include <fcntl.h>
  10. #include <isi/isi.h>
  11. #include <isi/isi_iss.h>
  12. #include <isi/isi_priv.h>
  13. #include <vvsensor.h>
  14. #include "SC2310_priv.h"
  15. #include "sc2310.h"
  16. CREATE_TRACER( SC2310_INFO , "SC2310: ", INFO, 0);
  17. CREATE_TRACER( SC2310_WARN , "SC2310: ", WARNING, 1);
  18. CREATE_TRACER( SC2310_ERROR, "SC2310: ", ERROR, 1);
  19. CREATE_TRACER( SC2310_DEBUG, "SC2310: ", INFO, 1);
  20. CREATE_TRACER( SC2310_REG_INFO , "SC2310: ", INFO, 1);
  21. CREATE_TRACER( SC2310_REG_DEBUG, "SC2310: ", INFO, 1);
  22. #ifdef SUBDEV_V4L2
  23. #include <sys/ioctl.h>
  24. #include <sys/mman.h>
  25. #include <fcntl.h>
  26. #include <linux/videodev2.h>
  27. #include <linux/v4l2-subdev.h>
  28. #undef TRACE
  29. #define TRACE(x, ...)
  30. #endif
  31. #define SC2310_MIN_GAIN_STEP ( 1.0f ) /**< min gain step size used by GUI (hardware min = 1/16; 1/16..32/16 depending on actual gain ) */
  32. #define SC2310_MAX_GAIN_AEC ( 35.0f ) /**< max. gain used by the AEC (arbitrarily chosen, hardware limit = 62.0, driver limit = 32.0 ) */
  33. #define SC2310_VS_MAX_INTEGRATION_TIME (0.0018)
  34. /*****************************************************************************
  35. *Sensor Info
  36. *****************************************************************************/
  37. static const char SensorName[16] = "SC2310";
  38. static struct vvcam_mode_info psc2310_mode_info[] = {
  39. {
  40. .index = 0,
  41. .width = 640,
  42. .height = 480,
  43. .fps = 26,
  44. .hdr_mode = SENSOR_MODE_LINEAR,
  45. .bit_width = 12,
  46. .bayer_pattern = BAYER_BGGR, //BAYER_RGGB, //BAYER_BGGR, //BAYER_GBRG, //, // BAYER_GRBG,
  47. .mipi_phy_freq = 395, //mbps
  48. .mipi_line_num = 2,
  49. .preg_data = (void *)"sc2310 sensor liner mode, raw12, img resolution is 640*480",
  50. },
  51. {
  52. .index = 1,
  53. .width = 1920,
  54. .height = 1088,
  55. .fps = 26,
  56. .hdr_mode = SENSOR_MODE_LINEAR,
  57. .bit_width = 12,
  58. .bayer_pattern = BAYER_BGGR, //BAYER_RGGB, //BAYER_BGGR, //, //, // BAYER_GRBG,
  59. .mipi_phy_freq = 395, //mbps
  60. .mipi_line_num = 2,
  61. .preg_data = (void *)"sc2310 sensor liner mode, raw12, img resolution is 1920*1088",
  62. },
  63. {
  64. .index = 2,
  65. .width = 1920,
  66. .height = 1080,
  67. .fps = 30,
  68. .hdr_mode = SENSOR_MODE_LINEAR,
  69. .bit_width = 10,
  70. .bayer_pattern = BAYER_BGGR,
  71. .mipi_phy_freq = 371, //mbps
  72. .mipi_line_num = 2,
  73. .preg_data = (void *)"sc2310 sensor liner mode, raw10, img resolution is 1920*1080",
  74. },
  75. /*
  76. {
  77. .index = 3,
  78. .width = 1920,
  79. .height = 1088,
  80. .fps = 30,
  81. .hdr_mode = SENSOR_MODE_LINEAR,
  82. .bit_width = 10,
  83. .bayer_pattern = BAYER_BGGR,
  84. .mipi_phy_freq = 445, //mbps
  85. .mipi_line_num = 2,
  86. .preg_data = (void *)"sc2310 sensor liner mode, raw10, img resolution is 1920*1080",
  87. },
  88. */
  89. };
  90. static RESULT SC2310_IsiRegisterWriteIss(IsiSensorHandle_t handle, const uint32_t address, const uint32_t value);
  91. //gain is dst value, set_gain is actual value
  92. typedef struct {
  93. int ana_reg_val;
  94. float step;
  95. float max_val;
  96. } sc2310_gain_map_t;
  97. static sc2310_gain_map_t sc2310_gain_map[] = {
  98. {0x03, 0.015, 1},
  99. {0x03, 0.015, 1.984},
  100. {0x07, 0.031, 2.688},
  101. {0x023, 0.043, 5.398},
  102. {0x027, 0.085, 10.795},
  103. {0x02f, 0.170, 21.590},
  104. {0x03f, 0.340, 35.360},
  105. };
  106. static int sc2310_set_gain(IsiSensorHandle_t handle, float gain, float *set_gain)
  107. {
  108. //Normal 模式/ HDR 模式下的长曝光数据
  109. #define ANA_GAIN 0x3e08
  110. #define ANA_FINE 0x3e09
  111. //HDR 模式下的短曝光数据
  112. #define ANA_VS_GAIN 0x3e08
  113. #define ANA_VS_FINE 0x3e09
  114. int ret = 0;
  115. int i = 0;
  116. uint32_t ana_gain_val = 0;
  117. uint32_t ana_fine_val = 0;
  118. if (gain <= 1.0) {
  119. ana_gain_val = 0x3;
  120. ana_fine_val = 0x40;
  121. *set_gain = 1;
  122. } else if (gain >= 35.360) {
  123. ana_gain_val = 0x3f;
  124. ana_fine_val = 0x7f;
  125. *set_gain = 35.360;
  126. } else {
  127. for(i = 0; i < sizeof(sc2310_gain_map) / sizeof(sc2310_gain_map[0]); i++) {
  128. if (sc2310_gain_map[i].max_val > gain) {
  129. ana_gain_val = sc2310_gain_map[i].ana_reg_val;
  130. ana_fine_val = 0x40 + (gain - sc2310_gain_map[i - 1].max_val) / sc2310_gain_map[i].step;
  131. *set_gain = sc2310_gain_map[i - 1].max_val + (gain - sc2310_gain_map[i - 1].max_val) / sc2310_gain_map[i].step;
  132. break;
  133. }
  134. }
  135. }
  136. ret |= SC2310_IsiRegisterWriteIss(handle, ANA_GAIN, ana_gain_val);
  137. ret |= SC2310_IsiRegisterWriteIss(handle, ANA_FINE, ana_fine_val);
  138. if (ret != 0) {
  139. return -1;
  140. }
  141. return ret;
  142. }
  143. long __sc2310_set_exposure(IsiSensorHandle_t handle, int coarse_itg,
  144. int gain, int digitgain, SC2310_EXPOSURE_SETTING_t type)
  145. {
  146. return 0;
  147. }
  148. static RESULT SC2310_IsiSensorSetPowerIss(IsiSensorHandle_t handle, bool_t on) {
  149. RESULT result = RET_SUCCESS;
  150. int ret = 0;
  151. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  152. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  153. return RET_NULL_POINTER;
  154. }
  155. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  156. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  157. int32_t enable = on;
  158. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_POWER, &enable);
  159. if (ret != 0) {
  160. // to do
  161. //TRACE(SC2310_ERROR, "%s: sensor set power error!\n", __func__);
  162. //return (RET_FAILURE);
  163. }
  164. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  165. return (result);
  166. }
  167. static RESULT SC2310_IsiResetSensorIss(IsiSensorHandle_t handle) {
  168. RESULT result = RET_SUCCESS;
  169. int ret = 0;
  170. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  171. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  172. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  173. return RET_NULL_POINTER;
  174. }
  175. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  176. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_RESET, NULL);
  177. if (ret != 0) {
  178. TRACE(SC2310_ERROR, "%s: sensor reset error!\n", __func__);
  179. return (RET_FAILURE);
  180. }
  181. sleep(0.01);
  182. ret = SC2310_IsiRegisterWriteIss(handle, 0x103, 1);
  183. if (ret != 0) {
  184. TRACE(SC2310_ERROR, "%s: sensor reset error!\n", __func__);
  185. return (RET_FAILURE);
  186. }
  187. sleep(0.01);
  188. ret = SC2310_IsiRegisterWriteIss(handle, 0x100, 0);
  189. if (ret != 0) {
  190. TRACE(SC2310_ERROR, "%s: sensor reset error!\n", __func__);
  191. return (RET_FAILURE);
  192. }
  193. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  194. return (result);
  195. }
  196. #ifdef SUBDEV_CHAR
  197. static RESULT SC2310_IsiSensorSetClkIss(IsiSensorHandle_t handle, uint32_t clk) {
  198. RESULT result = RET_SUCCESS;
  199. int32_t ret = 0;
  200. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  201. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  202. return RET_NULL_POINTER;
  203. }
  204. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  205. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  206. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_CLK, &clk);
  207. if (ret != 0) {
  208. // to do
  209. //TRACE(SC2310_ERROR, "%s: sensor set clk error!\n", __func__);
  210. //return (RET_FAILURE);
  211. }
  212. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  213. return (result);
  214. }
  215. static RESULT SC2310_IsiSensorGetClkIss
  216. (IsiSensorHandle_t handle, uint32_t * pclk) {
  217. RESULT result = RET_SUCCESS;
  218. int ret = 0;
  219. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  220. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  221. return RET_NULL_POINTER;
  222. }
  223. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  224. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  225. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_CLK, pclk);
  226. if (ret != 0) {
  227. // to do
  228. //TRACE(SC2310_ERROR, "%s: sensor get clk error!\n", __func__);
  229. //return (RET_FAILURE);
  230. }
  231. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  232. return (result);
  233. }
  234. static RESULT SC2310_IsiConfigSensorSCCBIss(IsiSensorHandle_t handle)
  235. {
  236. RESULT result = RET_SUCCESS;
  237. int ret = 0;
  238. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  239. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  240. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  241. return RET_NULL_POINTER;
  242. }
  243. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  244. static const IsiSccbInfo_t SensorSccbInfo = {
  245. .slave_addr = (0x30), //0x30 or 0x32
  246. .addr_byte = 2,
  247. .data_byte = 1,
  248. };
  249. struct vvcam_sccb_cfg_s sensor_sccb_config;
  250. sensor_sccb_config.slave_addr = SensorSccbInfo.slave_addr;
  251. sensor_sccb_config.addr_byte = SensorSccbInfo.addr_byte;
  252. sensor_sccb_config.data_byte = SensorSccbInfo.data_byte;
  253. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_SENSOR_SCCB_CFG,
  254. &sensor_sccb_config);
  255. if (ret != 0) {
  256. TRACE(SC2310_ERROR, "%s: sensor config sccb info error!\n",
  257. __func__);
  258. return (RET_FAILURE);
  259. }
  260. TRACE(SC2310_INFO, "%s (exit) result = %d\n", __func__, result);
  261. return (result);
  262. return RET_SUCCESS;
  263. }
  264. #endif
  265. static RESULT SC2310_IsiRegisterReadIss
  266. (IsiSensorHandle_t handle, const uint32_t address, uint32_t * p_value) {
  267. RESULT result = RET_SUCCESS;
  268. int32_t ret = 0;
  269. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  270. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  271. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  272. return RET_NULL_POINTER;
  273. }
  274. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  275. struct vvcam_sccb_data sccb_data;
  276. sccb_data.addr = address;
  277. sccb_data.data = 0;
  278. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_READ_REG, &sccb_data);
  279. if (ret != 0) {
  280. TRACE(SC2310_ERROR, "%s: read sensor register error!\n",
  281. __func__);
  282. return (RET_FAILURE);
  283. }
  284. *p_value = sccb_data.data;
  285. TRACE(SC2310_INFO, "%s (exit) result = %d\n", __func__, result);
  286. return (result);
  287. }
  288. static RESULT SC2310_IsiRegisterWriteIss
  289. (IsiSensorHandle_t handle, const uint32_t address, const uint32_t value) {
  290. RESULT result = RET_SUCCESS;
  291. int ret = 0;
  292. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  293. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  294. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  295. return RET_NULL_POINTER;
  296. }
  297. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  298. struct vvcam_sccb_data sccb_data;
  299. sccb_data.addr = address;
  300. sccb_data.data = value;
  301. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_WRITE_REG, &sccb_data);
  302. if (ret != 0) {
  303. TRACE(SC2310_ERROR, "%s: write sensor register error!\n",
  304. __func__);
  305. return (RET_FAILURE);
  306. }
  307. TRACE(SC2310_INFO, "%s (exit) result = %d\n", __func__, result);
  308. return (result);
  309. }
  310. static RESULT SC2310_IsiQuerySensorSupportIss(HalHandle_t HalHandle, vvcam_mode_info_array_t *pSensorSupportInfo)
  311. {
  312. //int ret = 0;
  313. struct vvcam_mode_info_array *psensor_mode_info_arry;
  314. HalContext_t *pHalCtx = HalHandle;
  315. if ( pHalCtx == NULL ) {
  316. return RET_NULL_POINTER;
  317. }
  318. psensor_mode_info_arry = pSensorSupportInfo;
  319. psensor_mode_info_arry->count = sizeof(psc2310_mode_info) / sizeof(struct vvcam_mode_info);
  320. memcpy(psensor_mode_info_arry->modes, psc2310_mode_info, sizeof(psc2310_mode_info));
  321. return RET_SUCCESS;
  322. }
  323. static RESULT SC2310_IsiQuerySensorIss(IsiSensorHandle_t handle, vvcam_mode_info_array_t *pSensorInfo)
  324. {
  325. RESULT result = RET_SUCCESS;
  326. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  327. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  328. return RET_NULL_POINTER;
  329. }
  330. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  331. SC2310_IsiQuerySensorSupportIss(pHalCtx,pSensorInfo);
  332. return result;
  333. }
  334. static RESULT SC2310_IsiGetSensorModeIss(IsiSensorHandle_t handle,void *mode)
  335. {
  336. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  337. if (pSC2310Ctx == NULL) {
  338. return (RET_WRONG_HANDLE);
  339. }
  340. memcpy(mode,&(pSC2310Ctx->SensorMode), sizeof(pSC2310Ctx->SensorMode));
  341. return ( RET_SUCCESS );
  342. }
  343. static RESULT SC2310_IsiCreateSensorIss(IsiSensorInstanceConfig_t * pConfig) {
  344. RESULT result = RET_SUCCESS;
  345. SC2310_Context_t *pSC2310Ctx;
  346. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  347. if (!pConfig || !pConfig->pSensor)
  348. return (RET_NULL_POINTER);
  349. pSC2310Ctx = (SC2310_Context_t *) malloc(sizeof(SC2310_Context_t));
  350. if (!pSC2310Ctx) {
  351. TRACE(SC2310_ERROR, "%s: Can't allocate sc2310 context\n",
  352. __func__);
  353. return (RET_OUTOFMEM);
  354. }
  355. MEMSET(pSC2310Ctx, 0, sizeof(SC2310_Context_t));
  356. result = HalAddRef(pConfig->HalHandle);
  357. if (result != RET_SUCCESS) {
  358. free(pSC2310Ctx);
  359. return (result);
  360. }
  361. pSC2310Ctx->IsiCtx.HalHandle = pConfig->HalHandle;
  362. pSC2310Ctx->IsiCtx.pSensor = pConfig->pSensor;
  363. pSC2310Ctx->GroupHold = BOOL_FALSE;
  364. pSC2310Ctx->OldGain = 0;
  365. pSC2310Ctx->OldIntegrationTime = 0;
  366. pSC2310Ctx->Configured = BOOL_FALSE;
  367. pSC2310Ctx->Streaming = BOOL_FALSE;
  368. pSC2310Ctx->TestPattern = BOOL_FALSE;
  369. pSC2310Ctx->isAfpsRun = BOOL_FALSE;
  370. pSC2310Ctx->SensorMode.index = pConfig->SensorModeIndex;
  371. pConfig->hSensor = (IsiSensorHandle_t)pSC2310Ctx;
  372. #ifdef SUBDEV_CHAR
  373. struct vvcam_mode_info *SensorDefaultMode = NULL;
  374. for (int i=0; i < sizeof(psc2310_mode_info)/ sizeof(struct vvcam_mode_info); i++)
  375. {
  376. if (psc2310_mode_info[i].index == pSC2310Ctx->SensorMode.index)
  377. {
  378. SensorDefaultMode = &(psc2310_mode_info[i]);
  379. break;
  380. }
  381. }
  382. if (SensorDefaultMode != NULL)
  383. {
  384. strcpy(pSC2310Ctx->SensorRegCfgFile, get_vi_config_path());
  385. switch(SensorDefaultMode->index)
  386. {
  387. case 0:
  388. strcat(pSC2310Ctx->SensorRegCfgFile,
  389. "SC2310_mipi2lane_640x480_raw12_30fps_init.txt");
  390. break;
  391. case 1:
  392. strcat(pSC2310Ctx->SensorRegCfgFile,
  393. "SC2310_mipi2lane_1920x1088_raw12_30fps_init.txt");
  394. break;
  395. case 2:
  396. strcat(pSC2310Ctx->SensorRegCfgFile,
  397. "SC2310_mipi2lane_1920x1080_raw10_30fps_init.txt");
  398. break;
  399. default:
  400. break;
  401. }
  402. if (access(pSC2310Ctx->SensorRegCfgFile, F_OK) == 0) {
  403. pSC2310Ctx->KernelDriverFlag = 0;
  404. memcpy(&(pSC2310Ctx->SensorMode),SensorDefaultMode,sizeof(struct vvcam_mode_info));
  405. } else {
  406. pSC2310Ctx->KernelDriverFlag = 1;
  407. }
  408. }else
  409. {
  410. pSC2310Ctx->KernelDriverFlag = 1;
  411. }
  412. result = SC2310_IsiSensorSetPowerIss(pSC2310Ctx, BOOL_TRUE);
  413. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  414. uint32_t SensorClkIn = 0;
  415. if (pSC2310Ctx->KernelDriverFlag) {
  416. result = SC2310_IsiSensorGetClkIss(pSC2310Ctx, &SensorClkIn);
  417. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  418. }
  419. result = SC2310_IsiSensorSetClkIss(pSC2310Ctx, SensorClkIn);
  420. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  421. if (!pSC2310Ctx->KernelDriverFlag) {
  422. result = SC2310_IsiConfigSensorSCCBIss(pSC2310Ctx);
  423. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  424. result = SC2310_IsiResetSensorIss(pSC2310Ctx);
  425. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  426. pSC2310Ctx->pattern = ISI_BPAT_BGBGGRGR;
  427. }
  428. #endif
  429. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  430. return (result);
  431. }
  432. static RESULT SC2310_IsiGetRegCfgIss(const char *registerFileName,
  433. struct vvcam_sccb_array *arry)
  434. {
  435. if (NULL == registerFileName) {
  436. TRACE(SC2310_ERROR, "%s:registerFileName is NULL\n", __func__);
  437. return (RET_NULL_POINTER);
  438. }
  439. #ifdef SUBDEV_CHAR
  440. FILE *fp = NULL;
  441. fp = fopen(registerFileName, "rb");
  442. if (!fp) {
  443. TRACE(SC2310_ERROR, "%s:load register file %s error!\n",
  444. __func__, registerFileName);
  445. return (RET_FAILURE);
  446. }
  447. char LineBuf[512];
  448. uint32_t FileTotalLine = 0;
  449. while (!feof(fp)) {
  450. fgets(LineBuf, 512, fp);
  451. FileTotalLine++;
  452. }
  453. arry->sccb_data =
  454. malloc(FileTotalLine * sizeof(struct vvcam_sccb_data));
  455. if (arry->sccb_data == NULL) {
  456. TRACE(SC2310_ERROR, "%s:malloc failed NULL Point!\n", __func__,
  457. registerFileName);
  458. return (RET_FAILURE);
  459. }
  460. rewind(fp);
  461. arry->count = 0;
  462. while (!feof(fp)) {
  463. memset(LineBuf, 0, sizeof(LineBuf));
  464. fgets(LineBuf, 512, fp);
  465. int result =
  466. sscanf(LineBuf, "0x%x 0x%x",
  467. &(arry->sccb_data[arry->count].addr),
  468. &(arry->sccb_data[arry->count].data));
  469. if (result != 2)
  470. continue;
  471. arry->count++;
  472. }
  473. #endif
  474. return 0;
  475. }
  476. static RESULT SC2310_IsiInitSensorIss(IsiSensorHandle_t handle) {
  477. RESULT result = RET_SUCCESS;
  478. int ret = 0;
  479. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  480. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  481. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  482. if (pSC2310Ctx == NULL) {
  483. return (RET_WRONG_HANDLE);
  484. }
  485. if (pSC2310Ctx->KernelDriverFlag) {
  486. ;
  487. } else {
  488. struct vvcam_sccb_array arry;
  489. result = SC2310_IsiGetRegCfgIss(pSC2310Ctx->SensorRegCfgFile, &arry);
  490. if (result != 0) {
  491. TRACE(SC2310_ERROR,
  492. "%s:SC2310_IsiGetRegCfgIss error!\n", __func__);
  493. return (RET_FAILURE);
  494. }
  495. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_WRITE_ARRAY, &arry);
  496. if (ret != 0) {
  497. TRACE(SC2310_ERROR, "%s:Sensor Write Reg arry error!\n",
  498. __func__);
  499. return (RET_FAILURE);
  500. }
  501. switch(pSC2310Ctx->SensorMode.index)
  502. {
  503. case 0:
  504. pSC2310Ctx->one_line_exp_time = 1.0 / (2.0 * 0x465 - 6.0) / 26.0;
  505. pSC2310Ctx->FrameLengthLines = 2 * 0x465;
  506. pSC2310Ctx->CurFrameLengthLines = pSC2310Ctx->FrameLengthLines;
  507. pSC2310Ctx->MaxIntegrationLine = pSC2310Ctx->CurFrameLengthLines - 6;
  508. pSC2310Ctx->MinIntegrationLine = 3;
  509. pSC2310Ctx->AecMaxGain = 35;
  510. pSC2310Ctx->AecMinGain = 1;
  511. break;
  512. case 1:
  513. pSC2310Ctx->one_line_exp_time = 1.0 / (2 * 0x465 - 6.0) / 26.0;
  514. pSC2310Ctx->FrameLengthLines = 2 * 0x465;
  515. pSC2310Ctx->CurFrameLengthLines = pSC2310Ctx->FrameLengthLines;
  516. pSC2310Ctx->MaxIntegrationLine = pSC2310Ctx->CurFrameLengthLines - 6;
  517. pSC2310Ctx->MinIntegrationLine = 3;
  518. pSC2310Ctx->AecMaxGain = 35;
  519. pSC2310Ctx->AecMinGain = 1;
  520. break;
  521. case 2:
  522. pSC2310Ctx->one_line_exp_time = 1.0 / (2 * 0x465 - 6.0) / 30.0;
  523. pSC2310Ctx->FrameLengthLines = 2 * 0x465;
  524. pSC2310Ctx->CurFrameLengthLines = pSC2310Ctx->FrameLengthLines;
  525. pSC2310Ctx->MaxIntegrationLine = pSC2310Ctx->CurFrameLengthLines - 6;
  526. pSC2310Ctx->MinIntegrationLine = 3;
  527. pSC2310Ctx->AecMaxGain = 35;
  528. pSC2310Ctx->AecMinGain = 1;
  529. break;
  530. default:
  531. return ( RET_NOTAVAILABLE );
  532. }
  533. printf("pSC2310Ctx->one_line_exp_time %f\n", pSC2310Ctx->one_line_exp_time);
  534. pSC2310Ctx->AecIntegrationTimeIncrement = pSC2310Ctx->one_line_exp_time;
  535. pSC2310Ctx->AecMinIntegrationTime =
  536. pSC2310Ctx->one_line_exp_time * pSC2310Ctx->MinIntegrationLine;
  537. pSC2310Ctx->AecMaxIntegrationTime =
  538. pSC2310Ctx->one_line_exp_time * pSC2310Ctx->FrameLengthLines;
  539. pSC2310Ctx->MaxFps = pSC2310Ctx->SensorMode.fps;
  540. pSC2310Ctx->MinFps = 1;
  541. pSC2310Ctx->CurrFps = pSC2310Ctx->MaxFps;
  542. }
  543. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  544. return (result);
  545. }
  546. static RESULT SC2310_IsiReleaseSensorIss(IsiSensorHandle_t handle) {
  547. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  548. RESULT result = RET_SUCCESS;
  549. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  550. if (pSC2310Ctx == NULL)
  551. return (RET_WRONG_HANDLE);
  552. (void)SC2310_IsiSensorSetStreamingIss(pSC2310Ctx, BOOL_FALSE);
  553. (void)SC2310_IsiSensorSetPowerIss(pSC2310Ctx, BOOL_FALSE);
  554. (void)HalDelRef(pSC2310Ctx->IsiCtx.HalHandle);
  555. MEMSET(pSC2310Ctx, 0, sizeof(SC2310_Context_t));
  556. free(pSC2310Ctx);
  557. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  558. return (result);
  559. }
  560. struct sc2310_fmt {
  561. int width;
  562. int height;
  563. int fps;
  564. };
  565. static RESULT SC2310_IsiSetupSensorIss
  566. (IsiSensorHandle_t handle, const IsiSensorConfig_t * pConfig) {
  567. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  568. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  569. RESULT result = RET_SUCCESS;
  570. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  571. if (!pSC2310Ctx) {
  572. TRACE(SC2310_ERROR,
  573. "%s: Invalid sensor handle (NULL pointer detected)\n",
  574. __func__);
  575. return (RET_WRONG_HANDLE);
  576. }
  577. if (!pConfig) {
  578. TRACE(SC2310_ERROR,
  579. "%s: Invalid configuration (NULL pointer detected)\n",
  580. __func__);
  581. return (RET_NULL_POINTER);
  582. }
  583. if (pSC2310Ctx->Streaming != BOOL_FALSE) {
  584. return RET_WRONG_STATE;
  585. }
  586. memcpy(&pSC2310Ctx->Config, pConfig, sizeof(IsiSensorConfig_t));
  587. /* 1.) SW reset of image sensor (via I2C register interface) be careful, bits 6..0 are reserved, reset bit is not sticky */
  588. TRACE(SC2310_DEBUG, "%s: SC2310 System-Reset executed\n", __func__);
  589. osSleep(100);
  590. //SC2310_AecSetModeParameters not defined yet as of 2021/8/9.
  591. //result = SC2310_AecSetModeParameters(pSC2310Ctx, pConfig);
  592. //if (result != RET_SUCCESS) {
  593. // TRACE(SC2310_ERROR, "%s: SetupOutputWindow failed.\n",
  594. // __func__);
  595. // return (result);
  596. //}
  597. #if 1
  598. struct sc2310_fmt fmt;
  599. fmt.width = pConfig->Resolution.width;
  600. fmt.height = pConfig->Resolution.height;
  601. ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);//result = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);
  602. #endif
  603. pSC2310Ctx->Configured = BOOL_TRUE;
  604. TRACE(SC2310_INFO, "%s: (exit) ret=0x%x \n", __func__, result);
  605. return result;
  606. }
  607. static RESULT SC2310_IsiChangeSensorResolutionIss(IsiSensorHandle_t handle, uint16_t width, uint16_t height) {
  608. RESULT result = RET_SUCCESS;
  609. #if 0
  610. struct sc2310_fmt fmt;
  611. fmt.width = width;
  612. fmt.height = height;
  613. int ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);
  614. #endif
  615. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  616. return (result);
  617. }
  618. static RESULT SC2310_IsiSensorSetStreamingIss
  619. (IsiSensorHandle_t handle, bool_t on) {
  620. RESULT result = RET_SUCCESS;
  621. int ret = 0;
  622. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  623. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  624. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  625. return RET_NULL_POINTER;
  626. }
  627. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  628. if (pSC2310Ctx->Configured != BOOL_TRUE)
  629. return RET_WRONG_STATE;
  630. ret = SC2310_IsiRegisterWriteIss(handle, 0x3812, 0);
  631. if (ret != 0) {
  632. return (RET_FAILURE);
  633. }
  634. ret = SC2310_IsiRegisterWriteIss(handle, 0x100, on);
  635. if (ret != 0) {
  636. return (RET_FAILURE);
  637. }
  638. ret = SC2310_IsiRegisterWriteIss(handle, 0x3812, 0x30);
  639. if (ret != 0) {
  640. return (RET_FAILURE);
  641. }
  642. pSC2310Ctx->Streaming = on;
  643. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  644. return (result);
  645. }
  646. static int32_t sensor_get_chip_id(IsiSensorHandle_t handle, uint32_t *chip_id)
  647. {
  648. RESULT result = RET_SUCCESS;
  649. int32_t ret = 0;
  650. int32_t chip_id_high = 0;
  651. int32_t chip_id_low = 0;
  652. ret = SC2310_IsiRegisterReadIss(handle, 0x3107, &chip_id_high);
  653. if (ret != 0) {
  654. TRACE(SC2310_ERROR,
  655. "%s: Read Sensor correct ID Error! \n", __func__);
  656. return (RET_FAILURE);
  657. }
  658. ret = SC2310_IsiRegisterReadIss(handle, 0x3108, &chip_id_low);
  659. if (ret != 0) {
  660. TRACE(SC2310_ERROR,
  661. "%s: Read Sensor correct ID Error! \n", __func__);
  662. return (RET_FAILURE);
  663. }
  664. *chip_id = ((chip_id_high & 0xff)<<8) | (chip_id_low & 0xff);
  665. printf("sc2310 chip id is %d\n", *chip_id);
  666. return 0;
  667. }
  668. static RESULT SC2310_IsiCheckSensorConnectionIss(IsiSensorHandle_t handle) {
  669. RESULT result = RET_SUCCESS;
  670. int ret = 0;
  671. uint32_t correct_id = 0x2311;
  672. uint32_t sensor_id = 0;
  673. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  674. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  675. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  676. return RET_NULL_POINTER;
  677. }
  678. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  679. ret = sensor_get_chip_id(handle, &sensor_id);
  680. if (ret != 0) {
  681. TRACE(SC2310_ERROR,
  682. "%s: Read Sensor chip ID Error! \n", __func__);
  683. return (RET_FAILURE);
  684. }
  685. if (correct_id != sensor_id) {
  686. TRACE(SC2310_ERROR, "%s:ChipID =0x%x sensor_id=%x error! \n",
  687. __func__, correct_id, sensor_id);
  688. return (RET_FAILURE);
  689. }
  690. TRACE(SC2310_INFO,
  691. "%s ChipID = 0x%08x, sensor_id = 0x%08x, success! \n", __func__,
  692. correct_id, sensor_id);
  693. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  694. return (result);
  695. }
  696. static RESULT SC2310_IsiGetSensorRevisionIss
  697. (IsiSensorHandle_t handle, uint32_t * p_value) {
  698. RESULT result = RET_SUCCESS;
  699. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  700. *p_value = 0X2311;
  701. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  702. return (result);
  703. }
  704. static RESULT SC2310_IsiGetGainLimitsIss
  705. (IsiSensorHandle_t handle, float *pMinGain, float *pMaxGain) {
  706. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  707. RESULT result = RET_SUCCESS;
  708. /*TODO*/
  709. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  710. if (pSC2310Ctx == NULL) {
  711. TRACE(SC2310_ERROR,
  712. "%s: Invalid sensor handle (NULL pointer detected)\n",
  713. __func__);
  714. return (RET_WRONG_HANDLE);
  715. }
  716. if ((pMinGain == NULL) || (pMaxGain == NULL)) {
  717. TRACE(SC2310_ERROR, "%s: NULL pointer received!!\n");
  718. return (RET_NULL_POINTER);
  719. }
  720. *pMinGain = pSC2310Ctx->AecMinGain;
  721. *pMaxGain = pSC2310Ctx->AecMaxGain;
  722. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  723. return (result);
  724. }
  725. static RESULT SC2310_IsiGetIntegrationTimeLimitsIss
  726. (IsiSensorHandle_t handle,
  727. float *pMinIntegrationTime, float *pMaxIntegrationTime) {
  728. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  729. RESULT result = RET_SUCCESS;
  730. /*TODO*/
  731. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  732. if (pSC2310Ctx == NULL) {
  733. TRACE(SC2310_ERROR,
  734. "%s: Invalid sensor handle (NULL pointer detected)\n",
  735. __func__);
  736. return (RET_WRONG_HANDLE);
  737. }
  738. if ((pMinIntegrationTime == NULL) || (pMaxIntegrationTime == NULL)) {
  739. TRACE(SC2310_ERROR, "%s: NULL pointer received!!\n");
  740. return (RET_NULL_POINTER);
  741. }
  742. *pMinIntegrationTime = pSC2310Ctx->AecMinIntegrationTime;
  743. *pMaxIntegrationTime = pSC2310Ctx->AecMaxIntegrationTime;
  744. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  745. return (result);
  746. }
  747. RESULT SC2310_IsiGetGainIss(IsiSensorHandle_t handle, float *pSetGain) {
  748. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  749. RESULT result = RET_SUCCESS;
  750. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  751. if (pSC2310Ctx == NULL) {
  752. TRACE(SC2310_ERROR,
  753. "%s: Invalid sensor handle (NULL pointer detected)\n",
  754. __func__);
  755. return (RET_WRONG_HANDLE);
  756. }
  757. if (pSetGain == NULL) {
  758. return (RET_NULL_POINTER);
  759. }
  760. *pSetGain = pSC2310Ctx->AecCurGain;
  761. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  762. return (result);
  763. }
  764. RESULT SC2310_IsiGetLongGainIss(IsiSensorHandle_t handle, float *gain)
  765. {
  766. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  767. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  768. if (pSC2310Ctx == NULL) {
  769. TRACE(SC2310_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  770. return (RET_WRONG_HANDLE);
  771. }
  772. if (gain == NULL) {
  773. return (RET_NULL_POINTER);
  774. }
  775. *gain = pSC2310Ctx->AecCurLongGain;
  776. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  777. return (RET_SUCCESS);
  778. }
  779. RESULT SC2310_IsiGetVSGainIss(IsiSensorHandle_t handle, float *pSetGain) {
  780. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  781. RESULT result = RET_SUCCESS;
  782. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  783. if (pSC2310Ctx == NULL) {
  784. TRACE(SC2310_ERROR,
  785. "%s: Invalid sensor handle (NULL pointer detected)\n",
  786. __func__);
  787. return (RET_WRONG_HANDLE);
  788. }
  789. if (pSetGain == NULL) {
  790. return (RET_NULL_POINTER);
  791. }
  792. *pSetGain = pSC2310Ctx->AecCurVSGain;
  793. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  794. return (result);
  795. }
  796. RESULT SC2310_IsiGetGainIncrementIss(IsiSensorHandle_t handle, float *pIncr) {
  797. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  798. RESULT result = RET_SUCCESS;
  799. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  800. if (pSC2310Ctx == NULL) {
  801. TRACE(SC2310_ERROR,
  802. "%s: Invalid sensor handle (NULL pointer detected)\n",
  803. __func__);
  804. return (RET_WRONG_HANDLE);
  805. }
  806. if (pIncr == NULL)
  807. return (RET_NULL_POINTER);
  808. *pIncr = pSC2310Ctx->AecGainIncrement;
  809. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  810. return (result);
  811. }
  812. RESULT SC2310_IsiSetGainIss
  813. (IsiSensorHandle_t handle,
  814. float NewGain, float *pSetGain, float *hdr_ratio) {
  815. RESULT result = RET_SUCCESS;
  816. int32_t ret = 0;
  817. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  818. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  819. return RET_NULL_POINTER;
  820. }
  821. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  822. sc2310_set_gain(handle, NewGain, pSetGain);
  823. pSC2310Ctx->AecCurGain = *pSetGain;
  824. TRACE(SC2310_DEBUG, "%s: g=%f\n", __func__, *pSetGain);
  825. return (result);
  826. }
  827. RESULT SC2310_IsiSetLongGainIss(IsiSensorHandle_t handle, float gain)
  828. {
  829. int ret = 0;
  830. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  831. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  832. if (!pSC2310Ctx || !pSC2310Ctx->IsiCtx.HalHandle)
  833. {
  834. TRACE(SC2310_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  835. return (RET_WRONG_HANDLE);
  836. }
  837. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  838. uint32_t SensorGain = 0;
  839. SensorGain = gain * pSC2310Ctx->gain_accuracy;
  840. if (pSC2310Ctx->LastLongGain != SensorGain)
  841. {
  842. /*TODO*/
  843. #if 0
  844. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_LONG_GAIN, &SensorGain);
  845. if (ret != 0)
  846. {
  847. return (RET_FAILURE);
  848. TRACE(SC2310_ERROR,"%s: set long gain failed\n");
  849. }
  850. #endif
  851. pSC2310Ctx->LastLongGain = SensorGain;
  852. pSC2310Ctx->AecCurLongGain = gain;
  853. }
  854. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  855. return (RET_SUCCESS);
  856. }
  857. RESULT SC2310_IsiSetVSGainIss
  858. (IsiSensorHandle_t handle,
  859. float NewIntegrationTime,
  860. float NewGain, float *pSetGain, float *hdr_ratio) {
  861. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  862. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  863. RESULT result = RET_SUCCESS;
  864. #if 0
  865. float Gain = 0.0f;
  866. uint32_t ucGain = 0U;
  867. uint32_t again = 0U;
  868. #endif
  869. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  870. if (!pSC2310Ctx) {
  871. TRACE(SC2310_ERROR,
  872. "%s: Invalid sensor handle (NULL pointer detected)\n",
  873. __func__);
  874. return (RET_WRONG_HANDLE);
  875. }
  876. if (!pSetGain || !hdr_ratio)
  877. return (RET_NULL_POINTER);
  878. uint32_t SensorGain = 0;
  879. SensorGain = NewGain * pSC2310Ctx->gain_accuracy;
  880. /*TODO*/
  881. //ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_VSGAIN, &SensorGain);
  882. pSC2310Ctx->AecCurVSGain = NewGain;
  883. *pSetGain = pSC2310Ctx->AecCurGain;
  884. TRACE(SC2310_DEBUG, "%s: g=%f\n", __func__, *pSetGain);
  885. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  886. return (result);
  887. }
  888. RESULT SC2310_IsiSetBayerPattern(IsiSensorHandle_t handle, uint8_t pattern)
  889. {
  890. RESULT result = RET_SUCCESS;
  891. #if 0
  892. uint8_t h_shift = 0, v_shift = 0;
  893. uint32_t val_h = 0, val_l = 0;
  894. uint16_t val = 0;
  895. uint8_t Start_p = 0;
  896. bool_t streaming_status;
  897. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  898. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  899. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  900. return RET_NULL_POINTER;
  901. }
  902. // pattern 0:B 1:GB 2:GR 3:R
  903. streaming_status = pSC2310Ctx->Streaming;
  904. result = SC2310_IsiSensorSetStreamingIss(handle, 0);
  905. switch (pattern) {
  906. case BAYER_BGGR:
  907. Start_p = 0;
  908. break;
  909. case BAYER_GBRG:
  910. Start_p = 1;
  911. break;
  912. case BAYER_GRBG:
  913. Start_p = 2;
  914. break;
  915. case BAYER_RGGB:
  916. Start_p = 3;
  917. break;
  918. }
  919. h_shift = Start_p % 2;
  920. v_shift = Start_p / 2;
  921. SC2310_IsiRegisterReadIss(handle, 0x30a0, &val_h);
  922. SC2310_IsiRegisterReadIss(handle, 0x30a1, &val_l);
  923. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + h_shift;
  924. val_h = (val >> 8) & 0xff;
  925. val_l = val & 0xff;
  926. SC2310_IsiRegisterWriteIss(handle, 0x30a0, (uint8_t)val_h);
  927. SC2310_IsiRegisterWriteIss(handle, 0x30a1, (uint8_t)val_l);
  928. SC2310_IsiRegisterReadIss(handle, 0x30a2, &val_h);
  929. SC2310_IsiRegisterReadIss(handle, 0x30a3, &val_l);
  930. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + v_shift;
  931. val_h = (val >> 8) & 0xff;
  932. val_l = val & 0xff;
  933. SC2310_IsiRegisterWriteIss(handle, 0x30a2, (uint8_t)val_h);
  934. SC2310_IsiRegisterWriteIss(handle, 0x30a3, (uint8_t)val_l);
  935. SC2310_IsiRegisterReadIss(handle, 0x30a4, &val_h);
  936. SC2310_IsiRegisterReadIss(handle, 0x30a5, &val_l);
  937. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + h_shift;
  938. val_h = (val >> 8) & 0xff;
  939. val_l = val & 0xff;
  940. SC2310_IsiRegisterWriteIss(handle, 0x30a4, (uint8_t)val_h);
  941. SC2310_IsiRegisterWriteIss(handle, 0x30a5, (uint8_t)val_l);
  942. SC2310_IsiRegisterReadIss(handle, 0x30a6, &val_h);
  943. SC2310_IsiRegisterReadIss(handle, 0x30a7, &val_l);
  944. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + v_shift;
  945. val_h = (val >> 8) & 0xff;
  946. val_l = val & 0xff;
  947. SC2310_IsiRegisterWriteIss(handle, 0x30a6, (uint8_t)val_h);
  948. SC2310_IsiRegisterWriteIss(handle, 0x30a7, (uint8_t)val_l);
  949. pSC2310Ctx->pattern = pattern;
  950. result = SC2310_IsiSensorSetStreamingIss(handle, streaming_status);
  951. #endif
  952. return (result);
  953. }
  954. RESULT SC2310_IsiGetIntegrationTimeIss
  955. (IsiSensorHandle_t handle, float *pSetIntegrationTime)
  956. {
  957. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  958. RESULT result = RET_SUCCESS;
  959. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  960. if (!pSC2310Ctx) {
  961. TRACE(SC2310_ERROR,
  962. "%s: Invalid sensor handle (NULL pointer detected)\n",
  963. __func__);
  964. return (RET_WRONG_HANDLE);
  965. }
  966. if (!pSetIntegrationTime)
  967. return (RET_NULL_POINTER);
  968. *pSetIntegrationTime = pSC2310Ctx->AecCurIntegrationTime;
  969. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  970. return (result);
  971. }
  972. RESULT SC2310_IsiGetLongIntegrationTimeIss(IsiSensorHandle_t handle, float *pIntegrationTime)
  973. {
  974. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  975. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  976. if (!pSC2310Ctx) {
  977. TRACE(SC2310_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  978. return (RET_WRONG_HANDLE);
  979. }
  980. if (!pIntegrationTime)
  981. return (RET_NULL_POINTER);
  982. pSC2310Ctx->AecCurLongIntegrationTime = pSC2310Ctx->AecCurIntegrationTime;
  983. *pIntegrationTime = pSC2310Ctx->AecCurLongIntegrationTime;
  984. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  985. return (RET_SUCCESS);
  986. }
  987. RESULT SC2310_IsiGetVSIntegrationTimeIss
  988. (IsiSensorHandle_t handle, float *pSetIntegrationTime)
  989. {
  990. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  991. RESULT result = RET_SUCCESS;
  992. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  993. if (!pSC2310Ctx) {
  994. TRACE(SC2310_ERROR,
  995. "%s: Invalid sensor handle (NULL pointer detected)\n",
  996. __func__);
  997. return (RET_WRONG_HANDLE);
  998. }
  999. if (!pSetIntegrationTime)
  1000. return (RET_NULL_POINTER);
  1001. *pSetIntegrationTime = pSC2310Ctx->AecCurVSIntegrationTime;
  1002. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1003. return (result);
  1004. }
  1005. RESULT SC2310_IsiGetIntegrationTimeIncrementIss
  1006. (IsiSensorHandle_t handle, float *pIncr)
  1007. {
  1008. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1009. RESULT result = RET_SUCCESS;
  1010. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1011. if (!pSC2310Ctx) {
  1012. TRACE(SC2310_ERROR,
  1013. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1014. __func__);
  1015. return (RET_WRONG_HANDLE);
  1016. }
  1017. if (!pIncr)
  1018. return (RET_NULL_POINTER);
  1019. //_smallest_ increment the sensor/driver can handle (e.g. used for sliders in the application)
  1020. *pIncr = pSC2310Ctx->AecIntegrationTimeIncrement;
  1021. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1022. return (result);
  1023. }
  1024. RESULT SC2310_IsiSetIntegrationTimeIss
  1025. (IsiSensorHandle_t handle,
  1026. float NewIntegrationTime,
  1027. float *pSetIntegrationTime,
  1028. uint8_t * pNumberOfFramesToSkip, float *hdr_ratio)
  1029. {
  1030. RESULT result = RET_SUCCESS;
  1031. uint32_t exp_lines = 0;
  1032. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1033. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1034. exp_lines = NewIntegrationTime / pSC2310Ctx->one_line_exp_time;
  1035. if (exp_lines > pSC2310Ctx->MaxIntegrationLine) {
  1036. exp_lines = pSC2310Ctx->MaxIntegrationLine;
  1037. } else if (exp_lines < 3) {
  1038. exp_lines = 3;
  1039. }
  1040. //行长 = 寄存器{16‘h320c, 16′h320d}值*2
  1041. //2*{16’h320e,16’h320f}-6:h320e,h320f为帧长
  1042. uint32_t hval_time = (exp_lines & 0xff0) >> 4;
  1043. uint32_t lval_time = (exp_lines & 0x0f) << 4;
  1044. result = SC2310_IsiRegisterWriteIss(handle, 0x3e01, hval_time);
  1045. result = SC2310_IsiRegisterWriteIss(handle, 0x3e02, lval_time);
  1046. pSC2310Ctx->AecCurIntegrationTime = exp_lines * pSC2310Ctx->one_line_exp_time;
  1047. *pNumberOfFramesToSkip = 1U;
  1048. *pSetIntegrationTime = pSC2310Ctx->AecCurIntegrationTime;
  1049. #if 0
  1050. uint32_t exp_line = 0;
  1051. uint32_t exp_line_old = 0;
  1052. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1053. if (!pSC2310Ctx) {
  1054. TRACE(SC2310_ERROR,
  1055. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1056. __func__);
  1057. return (RET_WRONG_HANDLE);
  1058. }
  1059. if (!pSetIntegrationTime || !pNumberOfFramesToSkip) {
  1060. TRACE(SC2310_ERROR,
  1061. "%s: Invalid parameter (NULL pointer detected)\n",
  1062. __func__);
  1063. return (RET_NULL_POINTER);
  1064. }
  1065. exp_line = NewIntegrationTime / pSC2310Ctx->one_line_exp_time;
  1066. exp_line_old = exp_line;
  1067. exp_line =
  1068. MIN(pSC2310Ctx->MaxIntegrationLine,
  1069. MAX(pSC2310Ctx->MinIntegrationLine, exp_line));
  1070. TRACE(SC2310_DEBUG, "%s: set AEC_PK_EXPO=0x%05x\n", __func__, exp_line);
  1071. if (exp_line != pSC2310Ctx->OldIntegrationTime) {
  1072. /*TODO*/
  1073. //ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_EXP, &exp_line);
  1074. pSC2310Ctx->OldIntegrationTime = exp_line; // remember current integration time
  1075. pSC2310Ctx->AecCurIntegrationTime =
  1076. exp_line * pSC2310Ctx->one_line_exp_time;
  1077. *pNumberOfFramesToSkip = 1U; //skip 1 frame
  1078. } else {
  1079. *pNumberOfFramesToSkip = 0U; //no frame skip
  1080. }
  1081. if (NewIntegrationTime > pSC2310Ctx->FrameLengthLines * pSC2310Ctx->one_line_exp_time)
  1082. NewIntegrationTime = pSC2310Ctx->FrameLengthLines * pSC2310Ctx->one_line_exp_time;
  1083. float exp_t = NewIntegrationTime * 16.0f / pSC2310Ctx->one_line_exp_time;
  1084. __sc2310_set_exposure(handle, (int)exp_t,
  1085. 0, 0, SC2310_INTEGRATION_TIME);
  1086. if (exp_line_old != exp_line) {
  1087. *pSetIntegrationTime = pSC2310Ctx->AecCurIntegrationTime;
  1088. } else {
  1089. *pSetIntegrationTime = NewIntegrationTime;
  1090. }
  1091. #endif
  1092. TRACE(SC2310_DEBUG, "%s: Ti=%f\n", __func__, *pSetIntegrationTime);
  1093. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1094. return (result);
  1095. }
  1096. RESULT SC2310_IsiSetLongIntegrationTimeIss(IsiSensorHandle_t handle,float IntegrationTime)
  1097. {
  1098. int ret;
  1099. uint32_t exp_lines;
  1100. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1101. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1102. if (!handle || !pSC2310Ctx->IsiCtx.HalHandle)
  1103. {
  1104. TRACE(SC2310_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  1105. return (RET_WRONG_HANDLE);
  1106. }
  1107. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1108. exp_lines = IntegrationTime / pSC2310Ctx->one_line_exp_time;
  1109. if (exp_lines > pSC2310Ctx->MaxIntegrationLine) {
  1110. exp_lines = pSC2310Ctx->MaxIntegrationLine;
  1111. } else if (exp_lines < 1) {
  1112. exp_lines = 1;
  1113. }
  1114. uint32_t hval_time = (exp_lines & 0xf00) >> 4;
  1115. uint32_t lval_time = exp_lines & 0xff;
  1116. SC2310_IsiRegisterWriteIss(handle, 0x3e01, lval_time);
  1117. SC2310_IsiRegisterWriteIss(handle, 0x3e02, hval_time);
  1118. pSC2310Ctx->AecCurIntegrationTime = exp_lines * pSC2310Ctx->one_line_exp_time;
  1119. pSC2310Ctx->AecCurLongIntegrationTime = exp_lines * pSC2310Ctx->one_line_exp_time;
  1120. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1121. return (RET_SUCCESS);
  1122. }
  1123. RESULT SC2310_IsiSetVSIntegrationTimeIss
  1124. (IsiSensorHandle_t handle,
  1125. float NewIntegrationTime,
  1126. float *pSetVSIntegrationTime,
  1127. uint8_t * pNumberOfFramesToSkip, float *hdr_ratio)
  1128. {
  1129. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1130. RESULT result = RET_SUCCESS;
  1131. uint32_t exp_line = 0;
  1132. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1133. if (!pSC2310Ctx) {
  1134. TRACE(SC2310_ERROR,
  1135. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1136. __func__);
  1137. return (RET_WRONG_HANDLE);
  1138. }
  1139. if (!pSetVSIntegrationTime || !pNumberOfFramesToSkip) {
  1140. TRACE(SC2310_ERROR,
  1141. "%s: Invalid parameter (NULL pointer detected)\n",
  1142. __func__);
  1143. return (RET_NULL_POINTER);
  1144. }
  1145. TRACE(SC2310_INFO,
  1146. "%s: maxIntegrationTime-=%f minIntegrationTime = %f\n", __func__,
  1147. pSC2310Ctx->AecMaxIntegrationTime,
  1148. pSC2310Ctx->AecMinIntegrationTime);
  1149. /*
  1150. uint32_t hval_time = (((uint32_t)NewIntegrationTime) & 0xf00) >> 4;
  1151. uint32_t lval_time = ((uint32_t)NewIntegrationTime) & 0xff;
  1152. SC2310_IsiRegisterWriteIss(handle, 0x3e04, lval_time);
  1153. SC2310_IsiRegisterWriteIss(handle, 0x3e05, hval_time);
  1154. */
  1155. exp_line = NewIntegrationTime / pSC2310Ctx->one_line_exp_time;
  1156. exp_line =
  1157. MIN(pSC2310Ctx->MaxIntegrationLine,
  1158. MAX(pSC2310Ctx->MinIntegrationLine, exp_line));
  1159. if (exp_line != pSC2310Ctx->OldVsIntegrationTime) {
  1160. /*TODO*/
  1161. // ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_VSEXP, &exp_line);
  1162. } else if (1){
  1163. pSC2310Ctx->OldVsIntegrationTime = exp_line;
  1164. pSC2310Ctx->AecCurVSIntegrationTime = exp_line * pSC2310Ctx->one_line_exp_time; //remember current integration time
  1165. *pNumberOfFramesToSkip = 1U; //skip 1 frame
  1166. } else {
  1167. *pNumberOfFramesToSkip = 0U; //no frame skip
  1168. }
  1169. *pSetVSIntegrationTime = pSC2310Ctx->AecCurVSIntegrationTime;
  1170. TRACE(SC2310_DEBUG, "%s: NewIntegrationTime=%f\n", __func__,
  1171. NewIntegrationTime);
  1172. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1173. return (result);
  1174. }
  1175. RESULT SC2310_IsiExposureControlIss
  1176. (IsiSensorHandle_t handle,
  1177. float NewGain,
  1178. float NewIntegrationTime,
  1179. uint8_t * pNumberOfFramesToSkip,
  1180. float *pSetGain, float *pSetIntegrationTime, float *hdr_ratio)
  1181. {
  1182. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1183. RESULT result = RET_SUCCESS;
  1184. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1185. if (pSC2310Ctx == NULL) {
  1186. TRACE(SC2310_ERROR,
  1187. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1188. __func__);
  1189. return (RET_WRONG_HANDLE);
  1190. }
  1191. if ((pNumberOfFramesToSkip == NULL) || (pSetGain == NULL)
  1192. || (pSetIntegrationTime == NULL)) {
  1193. TRACE(SC2310_ERROR,
  1194. "%s: Invalid parameter (NULL pointer detected)\n",
  1195. __func__);
  1196. return (RET_NULL_POINTER);
  1197. }
  1198. if (NewGain >= 35) { // More than 35 will not take effect
  1199. NewGain = 35;
  1200. }
  1201. TRACE(SC2310_DEBUG, "%s: g=%f, Ti=%f\n", __func__, NewGain,
  1202. NewIntegrationTime);
  1203. if (NewIntegrationTime > pSC2310Ctx->MaxIntegrationLine * pSC2310Ctx->one_line_exp_time)
  1204. NewIntegrationTime = pSC2310Ctx->MaxIntegrationLine * pSC2310Ctx->one_line_exp_time;
  1205. sc2310_set_gain(handle, NewGain, pSetGain);
  1206. SC2310_IsiSetIntegrationTimeIss(handle, NewIntegrationTime, pSetIntegrationTime, pNumberOfFramesToSkip, hdr_ratio);
  1207. pSC2310Ctx->AecCurGain = NewGain;
  1208. pSC2310Ctx->AecCurIntegrationTime = *pSetIntegrationTime;
  1209. TRACE(SC2310_DEBUG, "%s: set: vsg=%f, vsTi=%f, vsskip=%d\n", __func__,
  1210. NewGain, NewIntegrationTime, *pNumberOfFramesToSkip);
  1211. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1212. return result;
  1213. }
  1214. RESULT SC2310_IsiGetCurrentExposureIss
  1215. (IsiSensorHandle_t handle, float *pSetGain, float *pSetIntegrationTime, float *hdr_ratio) {
  1216. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1217. RESULT result = RET_SUCCESS;
  1218. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1219. if (pSC2310Ctx == NULL) {
  1220. TRACE(SC2310_ERROR,
  1221. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1222. __func__);
  1223. return (RET_WRONG_HANDLE);
  1224. }
  1225. if ((pSetGain == NULL) || (pSetIntegrationTime == NULL))
  1226. return (RET_NULL_POINTER);
  1227. *pSetGain = pSC2310Ctx->AecCurGain;
  1228. *pSetIntegrationTime = pSC2310Ctx->AecCurIntegrationTime;
  1229. *hdr_ratio = pSC2310Ctx->CurHdrRatio;
  1230. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1231. return (result);
  1232. }
  1233. RESULT SC2310_IsiGetResolutionIss(IsiSensorHandle_t handle, uint16_t *pwidth, uint16_t *pheight) {
  1234. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1235. RESULT result = RET_SUCCESS;
  1236. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1237. if (pSC2310Ctx == NULL) {
  1238. TRACE(SC2310_ERROR,
  1239. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1240. __func__);
  1241. return (RET_WRONG_HANDLE);
  1242. }
  1243. *pwidth = pSC2310Ctx->SensorMode.width;
  1244. *pheight = pSC2310Ctx->SensorMode.height;
  1245. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1246. return (result);
  1247. }
  1248. RESULT SC2310_IsiGetSensorFpsIss(IsiSensorHandle_t handle, uint32_t * pfps)
  1249. {
  1250. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1251. RESULT result = RET_SUCCESS;
  1252. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1253. if (pSC2310Ctx == NULL) {
  1254. TRACE(SC2310_ERROR,
  1255. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1256. __func__);
  1257. return (RET_WRONG_HANDLE);
  1258. }
  1259. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1260. if (pSC2310Ctx->KernelDriverFlag) {
  1261. /*TODO*/
  1262. ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_FPS, pfps);
  1263. pSC2310Ctx->CurrFps = *pfps;
  1264. }
  1265. *pfps = pSC2310Ctx->CurrFps;
  1266. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1267. return (result);
  1268. }
  1269. RESULT SC2310_IsiSetSensorFpsIss(IsiSensorHandle_t handle, uint32_t fps)
  1270. {
  1271. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1272. RESULT result = RET_SUCCESS;
  1273. int32_t ret = 0;
  1274. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1275. if (pSC2310Ctx == NULL) {
  1276. TRACE(SC2310_ERROR,
  1277. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1278. __func__);
  1279. return (RET_WRONG_HANDLE);
  1280. }
  1281. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1282. if (fps > pSC2310Ctx->MaxFps) {
  1283. TRACE(SC2310_ERROR,
  1284. "%s: set fps(%d) out of range, correct to %d (%d, %d)\n",
  1285. __func__, fps, pSC2310Ctx->MaxFps, pSC2310Ctx->MinFps,
  1286. pSC2310Ctx->MaxFps);
  1287. fps = pSC2310Ctx->MaxFps;
  1288. }
  1289. if (fps < pSC2310Ctx->MinFps) {
  1290. TRACE(SC2310_ERROR,
  1291. "%s: set fps(%d) out of range, correct to %d (%d, %d)\n",
  1292. __func__, fps, pSC2310Ctx->MinFps, pSC2310Ctx->MinFps,
  1293. pSC2310Ctx->MaxFps);
  1294. fps = pSC2310Ctx->MinFps;
  1295. }
  1296. TRACE(SC2310_INFO, "%s: set sensor fps = %d\n", __func__,
  1297. pSC2310Ctx->CurrFps);
  1298. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1299. return (result);
  1300. }
  1301. static RESULT SC2310_IsiActivateTestPattern(IsiSensorHandle_t handle,
  1302. const bool_t enable)
  1303. {
  1304. RESULT result = RET_SUCCESS;
  1305. uint32_t reg_val;
  1306. TRACE(SC2310_INFO, "%s: (enter)\n", __func__);
  1307. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1308. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  1309. return RET_NULL_POINTER;
  1310. }
  1311. if (pSC2310Ctx->Configured != BOOL_TRUE)
  1312. return RET_WRONG_STATE;
  1313. result = SC2310_IsiRegisterReadIss(handle, 0x4501, &reg_val);
  1314. if (result != RET_SUCCESS) {
  1315. return result;
  1316. }
  1317. reg_val &= ~8;
  1318. if (BOOL_TRUE == enable) {
  1319. reg_val |= 8;
  1320. }
  1321. result = SC2310_IsiRegisterWriteIss(handle, 0x4501, reg_val);
  1322. if (result != RET_SUCCESS) {
  1323. return result;
  1324. }
  1325. pSC2310Ctx->TestPattern = enable;
  1326. TRACE(SC2310_INFO, "%s: (exit)\n", __func__);
  1327. return (result);
  1328. }
  1329. static RESULT SC2310_IsiSensorSetBlcIss(IsiSensorHandle_t handle, sensor_blc_t * pblc)
  1330. {
  1331. int32_t ret = 0;
  1332. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1333. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  1334. return RET_WRONG_HANDLE;
  1335. }
  1336. if (pblc == NULL)
  1337. return RET_NULL_POINTER;
  1338. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1339. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_BLC, pblc);
  1340. if (ret != 0)
  1341. {
  1342. TRACE(SC2310_ERROR, "%s: set wb error\n", __func__);
  1343. }
  1344. return RET_SUCCESS;
  1345. }
  1346. static RESULT SC2310_IsiSensorSetWBIss(IsiSensorHandle_t handle, sensor_white_balance_t * pwb)
  1347. {
  1348. int32_t ret = 0;
  1349. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1350. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  1351. return RET_WRONG_HANDLE;
  1352. }
  1353. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1354. if (pwb == NULL)
  1355. return RET_NULL_POINTER;
  1356. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_WB, pwb);
  1357. if (ret != 0)
  1358. {
  1359. TRACE(SC2310_ERROR, "%s: set wb error\n", __func__);
  1360. }
  1361. return RET_SUCCESS;
  1362. }
  1363. static RESULT SC2310_IsiGetSensorAWBModeIss(IsiSensorHandle_t handle, IsiSensorAwbMode_t *pawbmode)
  1364. {
  1365. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1366. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  1367. return RET_NULL_POINTER;
  1368. }
  1369. if (pSC2310Ctx->SensorMode.hdr_mode == SENSOR_MODE_HDR_NATIVE){
  1370. *pawbmode = ISI_SENSOR_AWB_MODE_SENSOR;
  1371. }else{
  1372. *pawbmode = ISI_SENSOR_AWB_MODE_NORMAL;
  1373. }
  1374. return RET_SUCCESS;
  1375. }
  1376. static RESULT SC2310_IsiSensorGetExpandCurveIss(IsiSensorHandle_t handle, sensor_expand_curve_t * pexpand_curve)
  1377. {
  1378. int32_t ret = 0;
  1379. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1380. if (pSC2310Ctx == NULL || pSC2310Ctx->IsiCtx.HalHandle == NULL) {
  1381. return RET_NULL_POINTER;
  1382. }
  1383. HalContext_t *pHalCtx = (HalContext_t *) pSC2310Ctx->IsiCtx.HalHandle;
  1384. /*
  1385. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_EXPAND_CURVE, pexpand_curve);
  1386. if (ret != 0)
  1387. {
  1388. TRACE(SC2310_ERROR, "%s: get expand cure error\n", __func__);
  1389. return RET_FAILURE;
  1390. }
  1391. */
  1392. return RET_FAILURE;
  1393. }
  1394. static RESULT SC2310_IsiGetCapsIss(IsiSensorHandle_t handle,
  1395. IsiSensorCaps_t * pIsiSensorCaps)
  1396. {
  1397. SC2310_Context_t *pSC2310Ctx = (SC2310_Context_t *) handle;
  1398. RESULT result = RET_SUCCESS;
  1399. TRACE(SC2310_INFO, "%s (enter)\n", __func__);
  1400. if (pSC2310Ctx == NULL) {
  1401. return (RET_WRONG_HANDLE);
  1402. }
  1403. if (pIsiSensorCaps == NULL) {
  1404. return (RET_NULL_POINTER);
  1405. }
  1406. pIsiSensorCaps->BusWidth = pSC2310Ctx->SensorMode.bit_width;
  1407. pIsiSensorCaps->Mode = ISI_MODE_BAYER;
  1408. pIsiSensorCaps->FieldSelection = ISI_FIELDSEL_BOTH;
  1409. pIsiSensorCaps->YCSequence = ISI_YCSEQ_YCBYCR;
  1410. pIsiSensorCaps->Conv422 = ISI_CONV422_NOCOSITED;
  1411. pIsiSensorCaps->BPat = pSC2310Ctx->SensorMode.bayer_pattern;
  1412. pIsiSensorCaps->HPol = ISI_HPOL_REFPOS;
  1413. pIsiSensorCaps->VPol = ISI_VPOL_NEG;
  1414. pIsiSensorCaps->Edge = ISI_EDGE_RISING;
  1415. pIsiSensorCaps->Resolution.width = pSC2310Ctx->SensorMode.width;
  1416. pIsiSensorCaps->Resolution.height = pSC2310Ctx->SensorMode.height;
  1417. pIsiSensorCaps->SmiaMode = ISI_SMIA_OFF;
  1418. pIsiSensorCaps->MipiLanes = ISI_MIPI_2LANES;
  1419. if (pIsiSensorCaps->BusWidth == 10) {
  1420. pIsiSensorCaps->MipiMode = ISI_MIPI_MODE_RAW_10;
  1421. }else if (pIsiSensorCaps->BusWidth == 12){
  1422. pIsiSensorCaps->MipiMode = ISI_MIPI_MODE_RAW_12;
  1423. }else{
  1424. pIsiSensorCaps->MipiMode = ISI_MIPI_OFF;
  1425. }
  1426. TRACE(SC2310_INFO, "%s (exit)\n", __func__);
  1427. return result;
  1428. }
  1429. RESULT SC2310_IsiGetSensorIss(IsiSensor_t *pIsiSensor)
  1430. {
  1431. RESULT result = RET_SUCCESS;
  1432. TRACE( SC2310_INFO, "%s (enter)\n", __func__);
  1433. if ( pIsiSensor != NULL ) {
  1434. pIsiSensor->pszName = SensorName;
  1435. pIsiSensor->pIsiCreateSensorIss = SC2310_IsiCreateSensorIss;
  1436. pIsiSensor->pIsiInitSensorIss = SC2310_IsiInitSensorIss;
  1437. pIsiSensor->pIsiGetSensorModeIss = SC2310_IsiGetSensorModeIss;
  1438. pIsiSensor->pIsiResetSensorIss = SC2310_IsiResetSensorIss;
  1439. pIsiSensor->pIsiReleaseSensorIss = SC2310_IsiReleaseSensorIss;
  1440. pIsiSensor->pIsiGetCapsIss = SC2310_IsiGetCapsIss;
  1441. pIsiSensor->pIsiSetupSensorIss = SC2310_IsiSetupSensorIss;
  1442. pIsiSensor->pIsiChangeSensorResolutionIss = SC2310_IsiChangeSensorResolutionIss;
  1443. pIsiSensor->pIsiSensorSetStreamingIss = SC2310_IsiSensorSetStreamingIss;
  1444. pIsiSensor->pIsiSensorSetPowerIss = SC2310_IsiSensorSetPowerIss;
  1445. pIsiSensor->pIsiCheckSensorConnectionIss = SC2310_IsiCheckSensorConnectionIss;
  1446. pIsiSensor->pIsiGetSensorRevisionIss = SC2310_IsiGetSensorRevisionIss;
  1447. pIsiSensor->pIsiRegisterReadIss = SC2310_IsiRegisterReadIss;
  1448. pIsiSensor->pIsiRegisterWriteIss = SC2310_IsiRegisterWriteIss;
  1449. /* AEC functions */
  1450. pIsiSensor->pIsiExposureControlIss = SC2310_IsiExposureControlIss;
  1451. pIsiSensor->pIsiGetGainLimitsIss = SC2310_IsiGetGainLimitsIss;
  1452. pIsiSensor->pIsiGetIntegrationTimeLimitsIss = SC2310_IsiGetIntegrationTimeLimitsIss;
  1453. pIsiSensor->pIsiGetCurrentExposureIss = SC2310_IsiGetCurrentExposureIss;
  1454. pIsiSensor->pIsiGetVSGainIss = SC2310_IsiGetVSGainIss;
  1455. pIsiSensor->pIsiGetGainIss = SC2310_IsiGetGainIss;
  1456. pIsiSensor->pIsiGetLongGainIss = SC2310_IsiGetLongGainIss;
  1457. pIsiSensor->pIsiGetGainIncrementIss = SC2310_IsiGetGainIncrementIss;
  1458. pIsiSensor->pIsiSetGainIss = SC2310_IsiSetGainIss;
  1459. pIsiSensor->pIsiGetIntegrationTimeIss = SC2310_IsiGetIntegrationTimeIss;
  1460. pIsiSensor->pIsiGetVSIntegrationTimeIss = SC2310_IsiGetVSIntegrationTimeIss;
  1461. pIsiSensor->pIsiGetLongIntegrationTimeIss = SC2310_IsiGetLongIntegrationTimeIss;
  1462. pIsiSensor->pIsiGetIntegrationTimeIncrementIss = SC2310_IsiGetIntegrationTimeIncrementIss;
  1463. pIsiSensor->pIsiSetIntegrationTimeIss = SC2310_IsiSetIntegrationTimeIss;
  1464. pIsiSensor->pIsiQuerySensorIss = SC2310_IsiQuerySensorIss;
  1465. pIsiSensor->pIsiGetResolutionIss = SC2310_IsiGetResolutionIss;
  1466. pIsiSensor->pIsiGetSensorFpsIss = SC2310_IsiGetSensorFpsIss;
  1467. pIsiSensor->pIsiSetSensorFpsIss = SC2310_IsiSetSensorFpsIss;
  1468. pIsiSensor->pIsiSensorGetExpandCurveIss = SC2310_IsiSensorGetExpandCurveIss;
  1469. /* AWB specific functions */
  1470. /* Testpattern */
  1471. pIsiSensor->pIsiActivateTestPattern = SC2310_IsiActivateTestPattern;
  1472. pIsiSensor->pIsiSetBayerPattern = SC2310_IsiSetBayerPattern;
  1473. pIsiSensor->pIsiSensorSetBlcIss = SC2310_IsiSensorSetBlcIss;
  1474. pIsiSensor->pIsiSensorSetWBIss = SC2310_IsiSensorSetWBIss;
  1475. pIsiSensor->pIsiGetSensorAWBModeIss = SC2310_IsiGetSensorAWBModeIss;
  1476. } else {
  1477. result = RET_NULL_POINTER;
  1478. }
  1479. TRACE( SC2310_INFO, "%s (exit)\n", __func__);
  1480. return ( result );
  1481. }
  1482. /*****************************************************************************
  1483. * each sensor driver need declare this struct for isi load
  1484. *****************************************************************************/
  1485. IsiCamDrvConfig_t SC2310_IsiCamDrvConfig = {
  1486. 0,
  1487. SC2310_IsiQuerySensorSupportIss,
  1488. SC2310_IsiGetSensorIss,
  1489. {
  1490. SensorName, /**< IsiSensor_t.pszName */
  1491. 0, /**< IsiSensor_t.pIsiInitIss>*/
  1492. 0, /**< IsiSensor_t.pIsiResetSensorIss>*/
  1493. 0, /**< IsiSensor_t.pRegisterTable */
  1494. 0, /**< IsiSensor_t.pIsiSensorCaps */
  1495. 0, /**< IsiSensor_t.pIsiCreateSensorIss */
  1496. 0, /**< IsiSensor_t.pIsiReleaseSensorIss */
  1497. 0, /**< IsiSensor_t.pIsiGetCapsIss */
  1498. 0, /**< IsiSensor_t.pIsiSetupSensorIss */
  1499. 0, /**< IsiSensor_t.pIsiChangeSensorResolutionIss */
  1500. 0, /**< IsiSensor_t.pIsiSensorSetStreamingIss */
  1501. 0, /**< IsiSensor_t.pIsiSensorSetPowerIss */
  1502. 0, /**< IsiSensor_t.pIsiCheckSensorConnectionIss */
  1503. 0, /**< IsiSensor_t.pIsiGetSensorRevisionIss */
  1504. 0, /**< IsiSensor_t.pIsiRegisterReadIss */
  1505. 0, /**< IsiSensor_t.pIsiRegisterWriteIss */
  1506. 0, /**< IsiSensor_t.pIsiExposureControlIss */
  1507. 0, /**< IsiSensor_t.pIsiGetGainLimitsIss */
  1508. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeLimitsIss */
  1509. 0, /**< IsiSensor_t.pIsiGetCurrentExposureIss */
  1510. 0, /**< IsiSensor_t.pIsiGetGainIss */
  1511. 0, /**< IsiSensor_t.pIsiGetVSGainIss */
  1512. 0, /**< IsiSensor_t.pIsiGetGainIncrementIss */
  1513. 0, /**< IsiSensor_t.pIsiGetGainIncrementIss */
  1514. 0, /**< IsiSensor_t.pIsiSetGainIss */
  1515. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeIss */
  1516. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeIncrementIss */
  1517. 0, /**< IsiSensor_t.pIsiSetIntegrationTimeIss */
  1518. 0, /**< IsiSensor_t.pIsiGetResolutionIss */
  1519. 0, /**< IsiSensor_t.pIsiGetAfpsInfoIss */
  1520. 0, /**< IsiSensor_t.pIsiMdiInitMotoDriveMds */
  1521. 0, /**< IsiSensor_t.pIsiMdiSetupMotoDrive */
  1522. 0, /**< IsiSensor_t.pIsiMdiFocusSet */
  1523. 0, /**< IsiSensor_t.pIsiMdiFocusGet */
  1524. 0, /**< IsiSensor_t.pIsiMdiFocusCalibrate */
  1525. 0, /**< IsiSensor_t.pIsiGetSensorMipiInfoIss */
  1526. 0, /**< IsiSensor_t.pIsiActivateTestPattern */
  1527. 0, /**< IsiSensor_t.pIsiSetBayerPattern */
  1528. }
  1529. };