1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 #define _MSDBCCODE_C_
79
80
81 // System
82 #include "MsDBC_LIB.h"
83 // Common
84
85
86
87 //#define DBC_DEBUG
88 #ifdef DBC_DEBUG
89 #define DBC_PRINTF(str,val) printf(str,val)
90 #define DBC_PUTSTR(str) putstr(str)
91 #else
92 #define DBC_PRINTF(str,val)
93 #define DBC_PUTSTR(str)
94 #endif
95
96
97 #define DBC_LIB_VERSION 0x305 // v3.05 add Y/C Gain On Off
98 // v3.04 Include the definition of debug commands
99 // v3.03 Include DebugTool Command & add more commands (currentPWM, print message, debug mode)
100 // v3.02 made struct for parameters & remove the subroutine of backlight control
101 // v3.01 remove g_bDBCEnable from DBC lib
102 // v3.00 add g_ucCurrentAvg, g_ucCurrentYGain, g_ucCurrentCGain by Derek & Joseph
103 // v2.00 add fast mode (like as DLC)
104 // v1.03 update msGetAverageLuminousValue, remove g_DbcParameters.ucCurrentPWM in DBCInit, update the last calculation bug
105 // v1.02 update the last calculation bug of g_DbcParameters.ucCurrentPWM
106 // v1.01 update formula of curve MiddleHigh
107 // v1.00 new add DBC function
108 // DBC
109 XDATA BYTE g_ucAverageLumaValue;
110 XDATA WORD g_wPrePWM;
111 XDATA BYTE g_ucCurrentAvg;
112 XDATA BYTE g_ucCurrentYGain;
113 XDATA BYTE g_ucCurrentCGain;
114 XDATA BYTE g_ucDBCPreAvg;
115 XDATA BYTE g_ucDBCFastLoop; // for pulse ripple
116 XDATA BOOL g_bDBC_YGainOnOff, g_bDBC_CGainOnOff;
117
118 // For Tool Debug
119 XDATA BYTE g_ucDBC_DebugMode = 0; // [0] DBC On/Off, [7] Debug Mode Enable, [6] Print message
120
121 /*
122 typedef struct
123 {
124 BYTE ucMaxPWM;
125 BYTE ucMinPWM;
126 BYTE ucMax_Video;
127 BYTE ucMid_Video;
128 BYTE ucMin_Video;
129 BYTE ucCurrentPWM;
130 BYTE ucAlpha;
131 BYTE ucBackLight_Thres;
132 BYTE ucAvgDelta;
133 BYTE ucFlickAlpha;
134 BYTE ucFastAlphaBlending; // min 17 ~ max 32
135 BYTE ucLoop_Dly;
136 BYTE ucLoop_Dly_H_Init;
137 BYTE ucLoop_Dly_MH_Init;
138 BYTE ucLoop_Dly_ML_Init;
139 BYTE ucLoop_Dly_L_Init;
140 BYTE ucY_Gain_H;
141 BYTE ucC_Gain_H;
142 BYTE ucY_Gain_M;
143 BYTE ucC_Gain_M;
144 BYTE ucY_Gain_L;
145 BYTE ucC_Gain_L;
146 BYTE bYGainCtrl : 1; // 1: enable; 0: disable
147 BYTE bCGainCtrl : 1; // 1: enable; 0: disable
148 }StuDbc_FinetuneParamaters_Lib;
149 */
150 XDATA StuDbc_FinetuneParamaters_Lib g_DbcParameters;
151
152 extern XDATA BYTE g_ucTmpAvgN_1; // Avg value (N-1) // from DLC LIB
153 extern XDATA BYTE g_ucTmpAvgN; // Avg value (current N) // from DLC LIB
154
155
156 //-----------------------------------------------------------------------
157 // due to patent issues, temporary DISABLE it
158 //-----------------------------------------------------------------------
159 #if (ENABLE_DBC )
160
161 #define DBC_DEFLICK_BLEND_FACTOR 32
162 #define DBC_DEFLICK_PRECISION_SHIFT 64
163
164 void msDBCLumiDiffCtrl(void);
165 void msAdjustYCGain(BYTE Y_Gain,BYTE C_Gain);
166
msDbcLibVersionCheck(void)167 WORD msDbcLibVersionCheck(void)
168 {
169 return DBC_LIB_VERSION;
170 }
171
msDBCInit()172 void msDBCInit()
173 {
174 g_ucAverageLumaValue = 0;
175
176 g_DbcParameters.ucLoop_Dly = g_DbcParameters.ucLoop_Dly_H_Init;
177 g_ucCurrentAvg = g_ucTmpAvgN;
178 g_ucDBCPreAvg = g_ucTmpAvgN;
179
180 g_ucDBCFastLoop = (g_DbcParameters.ucFastAlphaBlending/2);
181 g_wPrePWM = (WORD)g_DbcParameters.ucCurrentPWM * DBC_DEFLICK_PRECISION_SHIFT;
182
183 // Derek add for DBC Y/C gain adjust 2008/10/12
184 g_ucCurrentYGain=g_DbcParameters.ucY_Gain_H;
185 g_ucCurrentCGain=g_DbcParameters.ucC_Gain_H;
186 msAdjustYCGain(g_ucCurrentYGain,g_ucCurrentCGain);
187 }
188
msDBCLumiDiffCtrl(void)189 void msDBCLumiDiffCtrl(void)
190 {
191 if (g_ucTmpAvgN_1 >= g_ucTmpAvgN)
192 {
193 if ((g_ucDBCFastLoop == 0) && ((g_ucTmpAvgN_1 - g_ucTmpAvgN) < g_DbcParameters.ucAvgDelta)) // if (Yavg is less than g_DbcParameters.ucAvgDelta) & (Fast change is finish) may do curve change slowly
194 {
195 g_DbcParameters.ucFlickAlpha = 1; // (1/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change slowly
196 }
197 else
198 {
199 DBC_PRINTF("\r\n1H:Avg = %d",g_ucTmpAvgN_1 - g_ucTmpAvgN);
200 DBC_PRINTF(" g_ucDlcFlickAlpha = %d\r\n",g_DbcParameters.ucFlickAlpha);
201
202 g_DbcParameters.ucFlickAlpha = g_DbcParameters.ucFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
203 if (g_ucDBCFastLoop == 0)
204 g_ucDBCFastLoop = (g_DbcParameters.ucFastAlphaBlending/2);
205 }
206 }
207 else // if (g_wHistogramTotal < wTmpAvg)
208 {
209 if ((g_ucDBCFastLoop == 0) && ((g_ucTmpAvgN - g_ucTmpAvgN_1) < g_DbcParameters.ucAvgDelta)) // if (Yavg is less than g_DbcParameters.ucAvgDelta) & (Fast change is finish) may do curve change slowly
210 {
211 g_DbcParameters.ucFlickAlpha = 1; // (1/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change slowly
212 }
213 else
214 {
215 DBC_PRINTF("\r\n2H:Avg = %d",g_ucTmpAvgN - g_ucTmpAvgN_1);
216 DBC_PRINTF(" g_ucDlcFlickAlpha = %d\r\n",g_DbcParameters.ucFlickAlpha);
217
218 g_DbcParameters.ucFlickAlpha = g_DbcParameters.ucFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
219 if (g_ucDBCFastLoop == 0)
220 g_ucDBCFastLoop = (g_DbcParameters.ucFastAlphaBlending/2);
221 }
222 }
223 }
224
msBackLightHandler(void)225 WORD msBackLightHandler(void)
226 {
227 BYTE ucTargetBacklight;
228 BYTE ucCurveIndex;
229 WORD wBlend, wTemp;
230
231 if (!(g_ucDBC_DebugMode & _BIT0)) // [0] DBC On/Off
232 return 0xFFFF; // Do Nothing
233
234 if (g_ucDBC_DebugMode & _BIT7) // [7] Debug Mode Enable
235 return 0xFFFF; // Do Nothing
236
237 g_ucCurrentAvg = g_ucTmpAvgN;
238
239 if (g_ucDBC_DebugMode & _BIT6)
240 DBC_PRINTF("\r\n[DBC]YAvg = %d",g_ucCurrentAvg);
241
242 msDBCLumiDiffCtrl();
243
244 #if DBC_CHANGE_STRONG
245 if((g_ucCurrentAvg==0)||(g_ucDBCPreAvg==0))
246 {
247 g_DbcParameters.ucFlickAlpha = g_DbcParameters.ucFastAlphaBlending;
248
249 if (g_ucDBCFastLoop == 0)
250 g_ucDBCFastLoop = (g_DbcParameters.ucFastAlphaBlending/2);
251 }
252 else
253 #endif
254 {
255 g_ucCurrentAvg =(WORD)(((DWORD)g_DbcParameters.ucAlpha * g_ucCurrentAvg+(DWORD)g_ucDBCPreAvg * (100-g_DbcParameters.ucAlpha))/100);
256 }
257
258 DBC_PRINTF("\r\n[DBC]Avg2 = %d",g_ucCurrentAvg);
259
260 if (g_ucCurrentAvg >= g_DbcParameters.ucMax_Video)
261 {
262 DBC_PUTSTR("\r\n[DBC] 00");
263 ucTargetBacklight = g_DbcParameters.ucMaxPWM;
264 ucCurveIndex = 0; // curve High
265 }
266 else if (g_ucCurrentAvg <= g_DbcParameters.ucMin_Video)
267 {
268 DBC_PUTSTR("\r\n[DBC] 01");
269 ucTargetBacklight = g_DbcParameters.ucMinPWM;
270 ucCurveIndex = 3; // curve Low
271 }
272 else if (g_ucCurrentAvg >= g_DbcParameters.ucMid_Video)
273 {
274 DBC_PUTSTR("\r\n[DBC] 02");
275 ucTargetBacklight = ((WORD)g_ucCurrentAvg - g_DbcParameters.ucMid_Video) * ((WORD)(100 - g_DbcParameters.ucBackLight_Thres) * (g_DbcParameters.ucMaxPWM - g_DbcParameters.ucMinPWM) / 100)
276 / (g_DbcParameters.ucMax_Video - g_DbcParameters.ucMid_Video) + ((WORD)g_DbcParameters.ucBackLight_Thres * (g_DbcParameters.ucMaxPWM - g_DbcParameters.ucMinPWM) / 100) + g_DbcParameters.ucMinPWM;
277 ucCurveIndex = 1; // curve MiddleHigh
278 }
279 else
280 {
281 DBC_PUTSTR("\r\n[DBC] 03");
282 ucTargetBacklight = ((WORD)(g_ucCurrentAvg - g_DbcParameters.ucMin_Video) * ((WORD)g_DbcParameters.ucBackLight_Thres * (g_DbcParameters.ucMaxPWM - g_DbcParameters.ucMinPWM) / 100))
283 / (g_DbcParameters.ucMid_Video - g_DbcParameters.ucMin_Video) + g_DbcParameters.ucMinPWM;
284 ucCurveIndex = 2; // curve MiddleLow
285 }
286
287 DBC_PRINTF("\r\n[DBC]ucTargetBacklight_orig=%d",ucTargetBacklight);
288
289 g_ucDBCPreAvg = g_ucCurrentAvg;
290
291 DBC_PRINTF("\r\n[DBC]ucTargetBacklight=%d",ucTargetBacklight);
292 DBC_PRINTF("\r\n[DBC]g_wPrePWM=%d",g_wPrePWM);
293
294 if(g_ucDBCFastLoop || (g_DbcParameters.ucFlickAlpha >= 16)) // Fast Update
295 {
296 if (g_ucDBCFastLoop)
297 g_ucDBCFastLoop--;
298
299 if (g_DbcParameters.ucCurrentPWM == ucTargetBacklight)
300 {
301 g_wPrePWM = (WORD)g_DbcParameters.ucCurrentPWM * DBC_DEFLICK_PRECISION_SHIFT;
302
303 if (g_ucDBC_DebugMode & _BIT6)
304 DBC_PRINTF("\r\n[DBC]0 PWM = %d",g_DbcParameters.ucCurrentPWM);
305
306 return (WORD)g_DbcParameters.ucCurrentPWM;
307 }
308
309 // target value with alpha blending
310 wBlend = (WORD)((((DWORD) g_DbcParameters.ucFlickAlpha * ucTargetBacklight * DBC_DEFLICK_PRECISION_SHIFT) +
311 ((DBC_DEFLICK_BLEND_FACTOR - (WORD)g_DbcParameters.ucFlickAlpha) * g_wPrePWM))/DBC_DEFLICK_BLEND_FACTOR);
312
313 DBC_PRINTF("\r\n[DBC]g_wPrePWM=%d",g_wPrePWM);
314
315 if(wBlend > g_wPrePWM)
316 {
317 wBlend = g_wPrePWM + ((wBlend - g_wPrePWM) / (DBC_DEFLICK_BLEND_FACTOR - g_DbcParameters.ucFlickAlpha + 1));
318 }
319 else if(wBlend < g_wPrePWM)
320 {
321 wBlend = g_wPrePWM - ((g_wPrePWM - wBlend) / (DBC_DEFLICK_BLEND_FACTOR - g_DbcParameters.ucFlickAlpha + 1));
322 }
323
324 g_wPrePWM = wBlend;
325
326 if (g_DbcParameters.ucCurrentPWM == g_wPrePWM / DBC_DEFLICK_PRECISION_SHIFT)
327 {
328 if (g_ucDBC_DebugMode & _BIT6)
329 DBC_PRINTF("\r\n[DBC]1 PWM = %d",g_DbcParameters.ucCurrentPWM);
330
331 return (WORD)g_DbcParameters.ucCurrentPWM;
332 }
333
334 g_DbcParameters.ucCurrentPWM = g_wPrePWM / DBC_DEFLICK_PRECISION_SHIFT;
335 }
336 else // Slow Update
337 {
338 if (g_DbcParameters.ucLoop_Dly--)
339 return 0xFFFF; // Do Nothing
340
341 switch(ucCurveIndex)
342 {
343 case 0: // curve High
344 g_DbcParameters.ucLoop_Dly = g_DbcParameters.ucLoop_Dly_H_Init;
345 break;
346 case 1: // curve MiddleHigh
347 g_DbcParameters.ucLoop_Dly = g_DbcParameters.ucLoop_Dly_MH_Init;
348 break;
349 case 2: // curve MiddleLow
350 g_DbcParameters.ucLoop_Dly = g_DbcParameters.ucLoop_Dly_ML_Init;
351 break;
352 case 3: // curve Low
353 g_DbcParameters.ucLoop_Dly = g_DbcParameters.ucLoop_Dly_L_Init;
354 break;
355 }
356
357 if (g_DbcParameters.ucCurrentPWM == ucTargetBacklight)
358 {
359 g_wPrePWM = (WORD)g_DbcParameters.ucCurrentPWM * DBC_DEFLICK_PRECISION_SHIFT;
360
361 if (g_ucDBC_DebugMode & _BIT6)
362 DBC_PRINTF("\r\n[DBC]2 PWM = %d",g_DbcParameters.ucCurrentPWM);
363
364 return (WORD)g_DbcParameters.ucCurrentPWM;
365 }
366
367 DBC_PRINTF("\r\n[DBC]ucTargetBacklight=%d",ucTargetBacklight);
368 DBC_PRINTF("\r\n[DBC]g_DbcParameters.ucCurrentPWM=%d",g_DbcParameters.ucCurrentPWM);
369
370 if (((g_DbcParameters.ucCurrentPWM+1) <= ucTargetBacklight) && (g_DbcParameters.ucCurrentPWM <= (255-1)))
371 g_DbcParameters.ucCurrentPWM+=1;
372 else if (((g_DbcParameters.ucCurrentPWM-1) >= ucTargetBacklight) && (g_DbcParameters.ucCurrentPWM >= 1))
373 g_DbcParameters.ucCurrentPWM-=1;
374
375 g_wPrePWM = (WORD)g_DbcParameters.ucCurrentPWM * DBC_DEFLICK_PRECISION_SHIFT;
376 }
377
378 DBC_PRINTF("\r\n S g_DbcParameters.ucCurrentPWM = %d",g_DbcParameters.ucCurrentPWM);
379
380 wTemp=((WORD)((g_DbcParameters.ucBackLight_Thres) * (g_DbcParameters.ucMaxPWM - g_DbcParameters.ucMinPWM)) / 100) + g_DbcParameters.ucMinPWM;
381 DBC_PRINTF("\r\n[DBC]wTemp=%d",wTemp);
382
383 if(g_DbcParameters.ucCurrentPWM <= g_DbcParameters.ucMinPWM)
384 {
385 DBC_PUTSTR("\r\n[DBC] 11");
386 g_ucCurrentYGain = g_DbcParameters.ucY_Gain_L;
387 g_ucCurrentCGain = g_DbcParameters.ucC_Gain_L;
388 }
389 else if ((g_DbcParameters.ucCurrentPWM>g_DbcParameters.ucMinPWM)&&(g_DbcParameters.ucCurrentPWM<wTemp))
390 {
391 DBC_PUTSTR("\r\n[DBC] 22");
392 g_ucCurrentYGain = g_DbcParameters.ucY_Gain_L-(((WORD)abs((g_DbcParameters.ucY_Gain_L-g_DbcParameters.ucY_Gain_M))) * ((WORD)abs((g_DbcParameters.ucCurrentPWM-g_DbcParameters.ucMinPWM))))/((WORD)abs((wTemp-g_DbcParameters.ucMinPWM))) ;
393 g_ucCurrentCGain = g_DbcParameters.ucC_Gain_L-(((WORD)abs((g_DbcParameters.ucC_Gain_L-g_DbcParameters.ucC_Gain_M))) * ((WORD)abs((g_DbcParameters.ucCurrentPWM-g_DbcParameters.ucMinPWM))))/((WORD)abs((wTemp-g_DbcParameters.ucMinPWM))) ;
394 }
395 else if ((g_DbcParameters.ucCurrentPWM>=wTemp) && (g_DbcParameters.ucCurrentPWM<g_DbcParameters.ucMaxPWM))
396 {
397 DBC_PUTSTR("\r\n[DBC] 33");
398 g_ucCurrentYGain = g_DbcParameters.ucY_Gain_M-(((WORD)abs((g_DbcParameters.ucY_Gain_M-g_DbcParameters.ucY_Gain_H))) * ((WORD)abs((g_DbcParameters.ucCurrentPWM-wTemp))))/((WORD)abs((g_DbcParameters.ucMaxPWM-wTemp))) ;
399 g_ucCurrentCGain = g_DbcParameters.ucC_Gain_M-(((WORD)abs((g_DbcParameters.ucC_Gain_M-g_DbcParameters.ucC_Gain_H))) * ((WORD)abs((g_DbcParameters.ucCurrentPWM-wTemp))))/((WORD)abs((g_DbcParameters.ucMaxPWM-wTemp))) ;
400 }
401 else if (g_DbcParameters.ucCurrentPWM>=g_DbcParameters.ucMaxPWM)
402 {
403 DBC_PUTSTR("\r\n[DBC] 44");
404 g_ucCurrentYGain = g_DbcParameters.ucY_Gain_H;
405 g_ucCurrentCGain = g_DbcParameters.ucC_Gain_H;
406 }
407
408 msAdjustYCGain(g_ucCurrentYGain,g_ucCurrentCGain);
409
410 if (g_ucDBC_DebugMode & _BIT6)
411 {
412 DBC_PRINTF("\r\n[DBC]3 PWM = %d",g_DbcParameters.ucCurrentPWM);
413 DBC_PRINTF("\r\n[DBC]YGain = %d",g_ucCurrentYGain);
414 DBC_PRINTF("\r\n[DBC]CGain = %d",g_ucCurrentCGain);
415 }
416
417 return (WORD)g_DbcParameters.ucCurrentPWM;
418 }
419
420 // Derek add for DBC Y/C gain adjust 2008/10/12
msAdjustYCGain(BYTE Y_Gain,BYTE C_Gain)421 void msAdjustYCGain(BYTE Y_Gain,BYTE C_Gain)
422 {
423 msDBC_FunctionEnter();
424
425 if (g_DbcParameters.bYGainCtrl && (REG_ADDR_DBC_Y_GAIN != REG_NULL))
426 msWriteByte(REG_ADDR_DBC_Y_GAIN, Y_Gain);
427 if (g_DbcParameters.bCGainCtrl && (REG_ADDR_DBC_C_GAIN != REG_NULL))
428 msWriteByte(REG_ADDR_DBC_C_GAIN, C_Gain);
429
430 msDBC_FunctionExit();
431 }
432
433 //////////////////////////////////////////////////////////////
434 // Debug Protocol
435 //////////////////////////////////////////////////////////////
436
437 // Debug Command Paser
438 #define URCMD_MST_DBC_TEST_READ_INFO 1
439 #define URCMD_MST_DBC_TEST_WRITE_INFO 2
440 #define URCMD_MST_DBC_TEST_REINIT 3
441
msDBC_ParametersTool(MS_U8 * pCmdBuff,MDrv_DLC_DBC_OnOff_Callback fnDBC_AP_OnOff,MDrv_DLC_DBC_AdjustBackLight_Callback fnDBC_AdjustBacklight,MDrv_DBC_Print_Callback fnPutchar)442 void msDBC_ParametersTool(MS_U8 *pCmdBuff, MDrv_DLC_DBC_OnOff_Callback fnDBC_AP_OnOff, MDrv_DLC_DBC_AdjustBackLight_Callback fnDBC_AdjustBacklight, MDrv_DBC_Print_Callback fnPutchar )
443 {
444 switch(*(pCmdBuff+3)) //UART_EXT_CMD
445 {
446 case URCMD_MST_DBC_TEST_READ_INFO:
447 {
448 if (*(pCmdBuff+4) == 2) // DBC other
449 {
450 if (*(pCmdBuff+5) == 200)
451 {
452 WORD wVer;
453 wVer = msDbcLibVersionCheck();
454 fnPutchar(0xF3);
455 fnPutchar(wVer >> 8);
456 fnPutchar(wVer & 0xFF);
457 }
458 else
459 {
460 fnPutchar(0xF2);
461 if (*(pCmdBuff+5) == 10)
462 fnPutchar(g_DbcParameters.ucMax_Video);
463 else if (*(pCmdBuff+5) == 11)
464 fnPutchar(g_DbcParameters.ucMid_Video);
465 else if (*(pCmdBuff+5) == 12)
466 fnPutchar(g_DbcParameters.ucMin_Video);
467 else if (*(pCmdBuff+5) == 13)
468 fnPutchar(g_DbcParameters.ucMaxPWM);
469 else if (*(pCmdBuff+5) == 14)
470 fnPutchar(g_DbcParameters.ucBackLight_Thres);
471 else if (*(pCmdBuff+5) == 15)
472 fnPutchar(g_DbcParameters.ucMinPWM);
473 else if (*(pCmdBuff+5) == 16)
474 fnPutchar(g_DbcParameters.ucY_Gain_H);
475 else if (*(pCmdBuff+5) == 17)
476 fnPutchar(g_DbcParameters.ucY_Gain_M);
477 else if (*(pCmdBuff+5) == 18)
478 fnPutchar(g_DbcParameters.ucY_Gain_L);
479 else if (*(pCmdBuff+5) == 19)
480 fnPutchar(g_DbcParameters.ucC_Gain_H);
481 else if (*(pCmdBuff+5) == 20)
482 fnPutchar(g_DbcParameters.ucC_Gain_M);
483 else if (*(pCmdBuff+5) == 21)
484 fnPutchar(g_DbcParameters.ucC_Gain_L);
485 else if (*(pCmdBuff+5) == 22)
486 fnPutchar(g_DbcParameters.ucAlpha);
487 else if (*(pCmdBuff+5) == 23)
488 fnPutchar(g_DbcParameters.ucAvgDelta);
489 else if (*(pCmdBuff+5) == 24)
490 fnPutchar(g_DbcParameters.ucFastAlphaBlending);
491 else if (*(pCmdBuff+5) == 25)
492 fnPutchar(g_DbcParameters.ucLoop_Dly_H_Init);
493 else if (*(pCmdBuff+5) == 26)
494 fnPutchar(g_DbcParameters.ucLoop_Dly_MH_Init);
495 else if (*(pCmdBuff+5) == 27)
496 fnPutchar(g_DbcParameters.ucLoop_Dly_ML_Init);
497 else if (*(pCmdBuff+5) == 28)
498 fnPutchar(g_DbcParameters.ucLoop_Dly_L_Init);
499 else if (*(pCmdBuff+5) == 29)
500 fnPutchar(g_ucDBC_DebugMode);
501 else if (*(pCmdBuff+5) == 30)
502 fnPutchar(g_DbcParameters.ucCurrentPWM);
503 else if (*(pCmdBuff+5) == 31)
504 fnPutchar(g_DbcParameters.bYGainCtrl);
505 else if (*(pCmdBuff+5) == 32)
506 fnPutchar(g_DbcParameters.bCGainCtrl);
507 else
508 fnPutchar(0);
509 }
510 }
511 }
512 break;
513 case URCMD_MST_DBC_TEST_WRITE_INFO:
514 {
515 if (*(pCmdBuff+4) == 10)
516 g_DbcParameters.ucMax_Video = *(pCmdBuff+5);
517 else if (*(pCmdBuff+4) == 11)
518 g_DbcParameters.ucMid_Video = *(pCmdBuff+5);
519 else if (*(pCmdBuff+4) == 12)
520 g_DbcParameters.ucMin_Video = *(pCmdBuff+5);
521 else if (*(pCmdBuff+4) == 13)
522 g_DbcParameters.ucMaxPWM= *(pCmdBuff+5);
523 else if (*(pCmdBuff+4) == 14)
524 g_DbcParameters.ucBackLight_Thres = *(pCmdBuff+5);
525 else if (*(pCmdBuff+4) == 15)
526 g_DbcParameters.ucMinPWM = *(pCmdBuff+5);
527 else if (*(pCmdBuff+4) == 16)
528 g_DbcParameters.ucY_Gain_H = *(pCmdBuff+5);
529 else if (*(pCmdBuff+4) == 17)
530 g_DbcParameters.ucY_Gain_M = *(pCmdBuff+5);
531 else if (*(pCmdBuff+4) == 18)
532 g_DbcParameters.ucY_Gain_L = *(pCmdBuff+5);
533 else if (*(pCmdBuff+4) == 19)
534 g_DbcParameters.ucC_Gain_H = *(pCmdBuff+5);
535 else if (*(pCmdBuff+4) == 20)
536 g_DbcParameters.ucC_Gain_M = *(pCmdBuff+5);
537 else if (*(pCmdBuff+4) == 21)
538 g_DbcParameters.ucC_Gain_L = *(pCmdBuff+5);
539 else if (*(pCmdBuff+4) == 22)
540 g_DbcParameters.ucAlpha = *(pCmdBuff+5);
541 else if (*(pCmdBuff+4) == 23)
542 g_DbcParameters.ucAvgDelta = *(pCmdBuff+5);
543 else if (*(pCmdBuff+4) == 24)
544 g_DbcParameters.ucFastAlphaBlending = *(pCmdBuff+5);
545 else if (*(pCmdBuff+4) == 25)
546 g_DbcParameters.ucLoop_Dly_H_Init = *(pCmdBuff+5);
547 else if (*(pCmdBuff+4) == 26)
548 g_DbcParameters.ucLoop_Dly_MH_Init = *(pCmdBuff+5);
549 else if (*(pCmdBuff+4) == 27)
550 g_DbcParameters.ucLoop_Dly_ML_Init = *(pCmdBuff+5);
551 else if (*(pCmdBuff+4) == 28)
552 g_DbcParameters.ucLoop_Dly_L_Init = *(pCmdBuff+5);
553 else if (*(pCmdBuff+4) == 29)
554 {
555 g_ucDBC_DebugMode = *(pCmdBuff+5);
556 fnDBC_AP_OnOff(g_ucDBC_DebugMode && _BIT0);
557 }
558 else if (*(pCmdBuff+4) == 30)
559 {
560 g_DbcParameters.ucCurrentPWM = *(pCmdBuff+5);
561 fnDBC_AdjustBacklight(g_DbcParameters.ucCurrentPWM);
562 }
563 else if (*(pCmdBuff+4) == 31)
564 g_DbcParameters.bYGainCtrl = *(pCmdBuff+5);
565 else if (*(pCmdBuff+4) == 32)
566 g_DbcParameters.bCGainCtrl = *(pCmdBuff+5);
567 }
568 break;
569 case URCMD_MST_DBC_TEST_REINIT:
570 break;
571 }
572 }
573
574 #endif//ENABLE_DBC
575