SC2310.c 59 KB

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