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 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 // File Name: DDC2BI.c
94 // Description: For Slave I2C functions.
95 //
96 // Registers read and write command list:
97 // DATA WRITE : START + 0x6E + 0x10 + addrh + addrl + data + STOP
98 // DATA READ : START + 0x6E + 0x10 + addrh + addrl + START + 0x6F + data +STOP
99 //
100 // Functions read and write command list:
101 // write contrast : START + 0x6E + 0x20 + 01 + xxh + data + STOP
102 // read contrast : START + 0x6E + 0x20 + 01 + xxh + START + 0x6F + (data) + STOP
103 // write Brightness : START + 0x6E + 0x20 + 02 + xxh + data + STOP
104 // read Brightness : START + 0x6E + 0x20 + 02 + xxh + START + 0x6F + (data) + STOP
105 // ON/OFF Panel set : START + 0x6E + 0x20 + 10 + xxh + 0:OFF 1:ON + STOP
106 // ON/OFF Panel Rd : START + 0x6E + 0x20 + 10 + xxh + START + 0x6F + (data) + STOP
107 //
108 ////////////////////////////////////////////////////////////////////////////////
109
110
111 #define _DRVDDC2BI_C_
112
113 #include <string.h>
114 #include "MsCommon.h"
115 #include "MsVersion.h"
116 #include "MsIRQ.h"
117 #include "MsOS.h"
118 #include "MsTypes.h"
119 #include "ddc2bi_hwreg_utility2.h"
120 #include "drvMMIO.h"
121 #include "drvDDC2BI.h"
122 #include "mhal_DDC2BI.h"
123 #include "ULog.h"
124
125
126
127 MS_VIRT DDC2BI_RIU_BASE;
128
129 // functions in this file are called by MDrv_DDC2BI_IIC() which
130 // is called from EX1_ISR, and should be register bank independent
131
132 #define DDC_MSG(x) x
133
134 #define UNUSED( var ) ((void)(var))
135
136 #define TAG_DDC2BI "DDC2BI"
137
138 static const MS_U8 nullMsg1[3] =
139 {
140 0x6E, 0x80, 0xBE
141 };
142
143 static MSIF_Version _drv_DDC2BI_version = {
144 .DDI = { DDC2BI_DRV_VERSION },
145 };
146
147 static MS_DDC2BI_Status _DDC2BI_Status = {.bIsInitialized = FALSE, .bIsRunning = FALSE,};
148 static MS_DDC2BI_INFO _DDC2BI_Info = {};
149 MS_U16 _DDC2BI_DbgSwitch = FALSE;
150
151 MS_U8 DDCBuffer[MaxBufLen];
152 MS_U8 txStatus;
153 MS_U8 const *txBufferPtr;
154 MS_U8 txLength;
155 MS_U8 rxStatus;
156 MS_U8 rxLength;
157 MS_U8 rxChkSum;
158 MS_U8 rxIndex;
159
160 MS_U16 DDClength;
161 MS_U8 DDC_StatusFlag;
162
163 MS_U8 g_ucCI_Port;
164 MS_U8 g_ucReceiveCounter;
165
166 #define RxBusyFlagBit 0x01UL
167 #define NMVAddrFlagBit 0x02UL
168
169 #define Set_RxBusyFlag() (DDC_StatusFlag |= RxBusyFlagBit)
170 #define Clr_RxBusyFlag() (DDC_StatusFlag &= ~RxBusyFlagBit)
171 #define Get_RxBusyFlag() (DDC_StatusFlag & RxBusyFlagBit)
172
173 #define Set_DDC_NMVAddrFlag() (DDC_StatusFlag |= NMVAddrFlagBit)
174 #define Clr_DDC_NMVAddrFlag() (DDC_StatusFlag &= ~NMVAddrFlagBit)
175 #define Get_DDC_NMVAddrFlag() (DDC_StatusFlag & NMVAddrFlagBit)
176
177 //=======================================================================
178 //debug message about DDCCI
179 //extern void puthexUART1 (MS_U8 x);
180 //extern void putcharUART1 (char x);
181
182 //=======================================================================
drvDDC2BI_AlignControl_NULL(MS_U8 * pDDCBuffData)183 MS_U8 drvDDC2BI_AlignControl_NULL(MS_U8 *pDDCBuffData)
184 {
185 MS_U8 DDCTemp;
186 DDCTemp = *pDDCBuffData;
187 UNUSED(DDCTemp);
188 return 0;
189 }
190
_MDrv_DDC2BI_init_riu_base(void)191 void _MDrv_DDC2BI_init_riu_base(void)
192 {
193 MS_VIRT _PMRIUBaseAddress = 0;
194 MS_PHY u32PMBankSize = 0;
195
196 // get MMIO base
197 if(MDrv_MMIO_GetBASE( &_PMRIUBaseAddress, &u32PMBankSize, MS_MODULE_PM ) != TRUE)
198 {
199 ULOGE(TAG_DDC2BI, "DDC2Bi GetBase failed\n");
200 return;
201 }
202 else
203 {
204 }
205
206 mhal_DDC2BI_init_riu_base(_PMRIUBaseAddress, _PMRIUBaseAddress);
207 }
208
209
210 static CALLBACK_AlignControl AlignControlCallback = NULL;
211 static CALLBACK_AlignControl StandardAlignControlCallback = NULL;
212 static CALLBACK_AlignControl CustomerAlignControlCallback = NULL;
213
214
MDrv_DDC2BI_Set_Callback(CALLBACK_AlignControl align_control)215 void MDrv_DDC2BI_Set_Callback(CALLBACK_AlignControl align_control)
216 {
217 AlignControlCallback = align_control;
218 }
219
220
MDrv_DDC2BI_Set_StandardCallBack(CALLBACK_AlignControl align_control)221 void MDrv_DDC2BI_Set_StandardCallBack(CALLBACK_AlignControl align_control)
222 {
223 StandardAlignControlCallback = align_control;
224 }
225
226
MDrv_DDC2BI_Set_CustomerCallBack(CALLBACK_AlignControl align_control)227 void MDrv_DDC2BI_Set_CustomerCallBack(CALLBACK_AlignControl align_control)
228 {
229 CustomerAlignControlCallback = align_control;
230 }
231
MDrv_DDC2BI_InitRx(void)232 void MDrv_DDC2BI_InitRx(void)
233 {
234
235 // putcharUART1('I');
236 rxStatus = DDC2B_CLEAR; // clear the rxState
237 rxIndex = 0; // the current buffer for a new message
238 g_ucReceiveCounter = 0;
239
240 }
241
MDrv_DDC2BI_Get_INT_FLAG(void)242 static MS_U8 MDrv_DDC2BI_Get_INT_FLAG(void)
243 {
244
245 return MDrv_ReadByte(DDC2BI_ADC_INT_FLAG);
246
247 }
248
MDrv_DDC2BI_Set_INT_FLAG(MS_U32 u32RegAddr,MS_U8 u8Flag)249 static void MDrv_DDC2BI_Set_INT_FLAG(MS_U32 u32RegAddr, MS_U8 u8Flag)
250 {
251 MS_U16 u16WaitingCount = 0 ;
252 // FIXME: if IP has write one clear is better
253 // DDC runs at XTAL clock, but MCU is 144MHz or higher.
254 // here we use function call to get some delay between
255 // write to the same register twice.
256 // (u32RegAddr is variable, real function will be called)
257 MDrv_WriteByte(u32RegAddr, u8Flag);
258
259 for ( u16WaitingCount = 0 ; u16WaitingCount < DDC_WAITING_LOOPSCOUNT ; u16WaitingCount++)
260 asm("") ;
261
262 MDrv_WriteByte(u32RegAddr, 0x00);
263
264 }
265
MDrv_DDC2BI_Set_INT_Mask(MS_U8 u8Mask)266 static void MDrv_DDC2BI_Set_INT_Mask(MS_U8 u8Mask)
267 {
268
269 MDrv_WriteByte(DDC2BI_ADC_INT_MASK, u8Mask);
270
271 }
272
MDrv_DDC2BI_Write_Buf(MS_U8 u8Data)273 static void MDrv_DDC2BI_Write_Buf(MS_U8 u8Data)
274 {
275
276 MDrv_WriteByte(DDC2BI_ADC_RB_WP, u8Data);
277
278 }
279
MDrv_DDC2BI_Read_Buf(void)280 static MS_U8 MDrv_DDC2BI_Read_Buf(void)
281 {
282
283 return MDrv_ReadByte(DDC2BI_ADC_WB_RP);
284
285 }
286
MDrv_DDC2BI_Receive_ISR(void)287 void MDrv_DDC2BI_Receive_ISR(void)
288 {
289
290 if(g_ucReceiveCounter)
291 {
292 if((--g_ucReceiveCounter)==0)
293 {
294 MDrv_DDC2BI_InitRx();
295 }
296 }
297
298 }
299
MDrv_DDC2BI_ComputeChecksum(MS_U8 count)300 MS_U8 MDrv_DDC2BI_ComputeChecksum(MS_U8 count)
301 {
302
303 MS_U8 checksum;
304 MS_U8 i = 0;
305
306 if (Get_DDC_NMVAddrFlag())
307 checksum = INITNMVTxCK;
308 else
309 checksum = INITTxCK;
310
311 for (; count > 0; count--)
312 checksum ^= DDCBuffer[i++];
313
314 return checksum;
315
316 }
317
MDrv_DDC2BI_GetTxBuffer(void)318 void MDrv_DDC2BI_GetTxBuffer(void)
319 {
320
321 MS_U8 i;
322 for(i = MAX_TXWAIT_DELAY; i > 0; i--)
323 {
324 if (txStatus == DDC2B_MSGON)
325 MsOS_DelayTask(1);
326 }
327 txStatus = DDC2B_CLEAR;
328
329 }
330
MDrv_DDC2BI_MessageReady(void)331 void MDrv_DDC2BI_MessageReady(void)
332 {
333 #if 1
334 DDClength = (DDCBuffer[0] & ~DDC2Bi_CONTROL_STATUS_FLAG) + 1;
335 DDCBuffer[DDClength] = MDrv_DDC2BI_ComputeChecksum(DDClength); //put checksum
336 MDrv_DDC2BI_GetTxBuffer();
337
338 MsOS_DisableInterrupt(E_INT_IRQ_DDC2BI);
339 txBufferPtr = &DDCBuffer[0];
340 txLength = DDClength + 1;
341 MsOS_EnableInterrupt(E_INT_IRQ_DDC2BI);
342
343 #else
344 MDrv_DDC2BI_GetTxBuffer();
345
346 mhal_interrupt_lock();
347
348 txBufferPtr = &DDCBuffer[0];
349 txLength = 127;//test
350
351 mhal_interrupt_unlock();
352 #endif
353 }
354
MDrv_DDC2BI_ParseCommand(void)355 void MDrv_DDC2BI_ParseCommand(void)
356 {
357
358 MS_U8 length; //,command;
359
360 length = DDCBuffer[LENGTH] & 0x7F;
361
362 if ( rxIndex <= 0 || rxIndex >= MaxBufLen )
363 {
364 rxIndex = 0;
365 return;
366 }
367
368 if(length <= 0)
369 {
370 DDC_MSG(ULOGD(TAG_DDC2BI, "length return \n"));
371
372 MsOS_DisableInterrupt(E_INT_IRQ_DDC2BI);
373 txBufferPtr = &nullMsg1[1];
374 txLength = sizeof (nullMsg1);
375 MsOS_EnableInterrupt(E_INT_IRQ_DDC2BI);
376
377 MDrv_DDC2BI_Write_Buf(DDC2B_DEST_ADDRESS); //0x6E
378 return;
379 }
380
381 length = (*AlignControlCallback)(DDCBuffer);
382
383 if (length <= 0)
384 {
385 DDCBuffer[0] = 0x80;
386 }
387 else if (length == 0xFE || length == 0xFD)
388 {
389 DDCBuffer[0] = 0x80;
390 // return;
391 }
392
393 MDrv_DDC2BI_MessageReady();
394
395 #if 1
396 if(Get_DDC_NMVAddrFlag())
397 {
398 MDrv_DDC2BI_Write_Buf(DDC2B_SRC_ADDRESS); //0x51
399 Clr_DDC_NMVAddrFlag();
400 }
401 else
402 {
403 MDrv_DDC2BI_Write_Buf(DDC2B_DEST_ADDRESS); //0x6E
404 }
405 #else
406 MDrv_DDC2BI_Write_Buf(*txBufferPtr); //send first byte.
407 txBufferPtr++;
408 #endif
409 }
410 //--------------------------------------------------
411 //extern void PIU_UART_putchar(char c);
412 //extern void PIU_UART_puthex(MS_U8 c);
413 //----------------------------------------------------
MDrv_DDC2BI_CommandHandler(void)414 void MDrv_DDC2BI_CommandHandler(void)
415 {
416 //#ifdef DDC_TODO
417 if (rxStatus == DDC2B_COMPLETED)
418 {
419 DDC_MSG(ULOGD(TAG_DDC2BI, "DDC2B_COMPLETED \n"));
420 MDrv_DDC2BI_Set_INT_Mask(0x7f);//(0x00); // disable all interrypt
421
422 MDrv_DDC2BI_ParseCommand();
423 Clr_RxBusyFlag();
424 MDrv_DDC2BI_InitRx();
425
426 MDrv_DDC2BI_Set_INT_Mask(0x67);//(0x3E); // enable the write and read interrupt
427 }
428 // #endif
429 }
430
MDrv_DDC2BI_IIC(InterruptNum eIntNum)431 static void MDrv_DDC2BI_IIC(InterruptNum eIntNum)
432 {
433 MS_U8 rxByte, intFlag;
434
435 UNUSED(eIntNum);
436
437 intFlag = MDrv_DDC2BI_Get_INT_FLAG();
438 //PIU_UART_putchar('T');
439 // puthexUART1(intFlag);
440 if(intFlag == 0)
441 return;
442
443 switch (intFlag & (TXBI | RCBI ))
444 {
445 case TXBI:
446 //PIU_UART_putchar('T');
447 MDrv_DDC2BI_InitRx();
448
449 //PIU_UART_putchar('+');
450 //PIU_UART_puthex (txLength);
451 txStatus = DDC2B_MSGON;
452 // no characters left
453 if (!(txLength))
454 {
455 // clear the transmit status
456 txStatus = DDC2B_CLEAR;
457 MDrv_DDC2BI_Write_Buf(0x00);
458 // EX0=1;
459 //return ;
460 }
461 else
462 {
463 // send out the current byte
464 MDrv_DDC2BI_Write_Buf(*txBufferPtr++);
465 txLength--;
466 }
467 // PIU_UART_putchar('\n');PIU_UART_putchar('\r');
468 // intFlag &= (~TXBI); //clear interrupt flag ,for saturn write 1 to clear interrupt
469 break;
470 case RCBI:
471 {
472 txLength=0;
473 txStatus = DDC2B_CLEAR;
474 // read the received byte
475
476 rxByte = MDrv_DDC2BI_Read_Buf();
477 //PIU_UART_putchar('R');
478 //PIU_UART_putchar('-');
479 //PIU_UART_puthex (rxByte);
480
481 //puthexUART1 (rxStatus);
482 // depending of the message status
483 switch (rxStatus)
484 {
485 // in case there is nothing received yet
486 case DDC2B_CLEAR:
487
488 if (rxByte == DDC2B_SRC_ADDRESS)
489 {
490 //PIU_UART_putchar('A');
491 rxStatus++;// = DDC2B_SRCADDRESS;
492 rxChkSum = INITRxCK;
493 g_ucReceiveCounter = 200; //ms
494
495 if(StandardAlignControlCallback == NULL)
496 MDrv_DDC2BI_Set_Callback(drvDDC2BI_AlignControl_NULL);
497 else
498 MDrv_DDC2BI_Set_Callback(StandardAlignControlCallback);
499 }
500 else if (rxByte == DDC2B_SRC_ADDRESS_CUSTOMER)
501 {
502 rxStatus++;// = DDC2B_SRCADDRESS;
503 rxChkSum = (DDC2B_SRC_ADDRESS_CUSTOMER ^ DDC2B_DEST_ADDRESS);
504 g_ucReceiveCounter = 200; //ms
505 if(CustomerAlignControlCallback == NULL)
506 MDrv_DDC2BI_Set_Callback(drvDDC2BI_AlignControl_NULL);
507 else
508 MDrv_DDC2BI_Set_Callback(CustomerAlignControlCallback);
509 }
510 else
511 {
512 MDrv_DDC2BI_InitRx();
513 }
514 break;
515 case DDC2B_SRCADDRESS:
516 // get the length
517 rxLength = rxByte & ~DDC2Bi_CONTROL_STATUS_FLAG; //clear first bit 0x84 -> 0x04
518
519 // put the received byte in DDCBuffer
520 DDCBuffer[rxIndex++] = rxByte; //DDCBuffer[0] = length
521 rxChkSum ^= rxByte;
522
523 // set the receive body state
524 rxStatus++; //= DDC2B_COMMAND;
525
526 //if it is a NULL message
527 if (rxLength == 0 || rxLength >= MaxBufLen)
528 {
529 // wait for CK
530 rxStatus = DDC2B_COMPLETED;
531 Set_RxBusyFlag();
532 }
533 break;
534 // get the command
535 case DDC2B_COMMAND:
536 // save the commandbyte
537 rxStatus++; //= DDC2B_RECBODY;
538
539 // get the message body
540 case DDC2B_RECBODY:
541 //PIU_UART_putchar('-');
542 DDCBuffer[rxIndex++] = rxByte; //DDCBuffer[1] = Command
543
544 rxChkSum ^= rxByte ;
545 rxLength--;
546
547 // the last byte in the message body
548 if (rxLength == 0 || rxLength >= MaxBufLen)
549 {
550 rxStatus++; //= DDC2B_WAITFORCK;
551 }
552 break;
553 // ...here we are waiting for checksum...
554 case DDC2B_WAITFORCK:
555 //PIU_UART_puthex(rxChkSum);
556 if (rxChkSum == rxByte) // if checksum match
557 {
558 //PIU_UART_putchar('Y');
559 rxStatus = DDC2B_COMPLETED;
560 Set_RxBusyFlag();
561 }
562 else // else checksum error
563 {
564 //PIU_UART_putchar('N');
565 // if checksum error re-initialize the receive buffer
566 MDrv_DDC2BI_InitRx();
567 }
568 break;
569
570 // error condition
571 default:
572 // clear the rxState and the current buffer for a new message
573 if (!Get_RxBusyFlag())
574 MDrv_DDC2BI_InitRx();
575 break;
576 } // switch (rxStatus)
577 //PIU_UART_putchar('\n');PIU_UART_putchar('\r');
578
579 // intFlag &= (~RCBI); // clear interrupt flag ,for saturn write 1 to clear interrupt
580 }
581 break;
582 }
583
584 intFlag &= 0xBE;
585 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_ADC_INT_CLR, intFlag);
586 MsOS_EnableInterrupt(E_INT_IRQ_DDC2BI);
587 }
588
MDrv_DDC2BI_Init(void)589 void MDrv_DDC2BI_Init(void)
590 {
591 _MDrv_DDC2BI_init_riu_base();
592
593 rxLength = 0;
594 rxChkSum = 0;
595 rxIndex = 0;
596 txLength = 0;
597
598 DDC_StatusFlag = 0; // initialize various flags and data items
599 MDrv_DDC2BI_InitRx();
600 txStatus = DDC2B_CLEAR; // initialize transmit status
601
602 // MDrv_WriteByte(DDC2BI_ADC_ID, 0xB7); //Set SI2C slave address 0x6E , bit7:Enable SI2C
603 MDrv_WriteByte(DDC2BI_ADC_ID, 0xB7);
604
605 //ADC
606 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_ADC_INT_CLR, 0x7F); //Clear ADC all interrupt flag
607
608 //DVI0
609 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_DVI0_INT_CLR, 0x7F); //Clear ADC all interrupt flag
610
611 //DVI1
612 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_DVI1_INT_CLR, 0x7F); //Clear ADC all interrupt flag
613
614 //DVI2
615 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_DVI2_INT_CLR, 0x7F); //Clear ADC all interrupt flag
616
617 //DVI3
618 MDrv_DDC2BI_Set_INT_FLAG(DDC2BI_DVI3_INT_CLR, 0x7F); //Clear ADC all interrupt flag
619
620
621 //MDrv_WriteByte(DDC2BI_CTRL, 0x00);
622 MDrv_WriteByte(DDC2BI_CTRL, 0x00);
623
624 //Stop/R/W/RW/Word : enable
625 //Start/ID : disable
626 //MDrv_WriteByte(DDC2BI_ADC_INT_MASK, 0x3E); //Enable SI2C interrup
627 MDrv_WriteByte(DDC2BI_ADC_INT_MASK, 0x67); // enable read and write status interrupt
628
629 // DVI_0
630 //MDrv_WriteByte(DDC2BI_DVI0_ID, 0xb7);
631 // DVI_1
632 //MDrv_WriteByte(DDC2BI_DVI1_ID, 0xb7);
633 // DVI_2
634 //MDrv_WriteByte(DDC2BI_DVI2_ID, 0xb7);
635 // DVI_3
636 //MDrv_WriteByte(DDC2BI_DVI3_ID, 0xb7);
637
638 MDrv_WriteByte(DDC2BI_DVI0_INT_MASK, 0x67); // enable read and write status interrupt
639 MDrv_WriteByte(DDC2BI_DVI1_INT_MASK, 0x67); // enable read and write status interrupt
640 MDrv_WriteByte(DDC2BI_DVI2_INT_MASK, 0x67); // enable read and write status interrupt
641 MDrv_WriteByte(DDC2BI_DVI3_INT_MASK, 0x67); // enable read and write status interrupt
642
643
644 //enable interrupt mask
645 MsOS_AttachInterrupt(E_INT_IRQ_DDC2BI, MDrv_DDC2BI_IIC);
646 MsOS_EnableInterrupt(E_INT_IRQ_DDC2BI);
647
648 _DDC2BI_Status.bIsInitialized = TRUE;
649 _DDC2BI_Status.bIsRunning = TRUE;
650 }
651
MDrv_DDC2BI_Exit(void)652 MS_BOOL MDrv_DDC2BI_Exit(void)
653 {
654 // Mask all interrupt
655 MDrv_WriteByte(DDC2BI_ADC_INT_MASK, 0xFF);
656 MDrv_WriteByte(DDC2BI_DVI0_INT_MASK, 0xFF);
657 MDrv_WriteByte(DDC2BI_DVI1_INT_MASK, 0xFF);
658 MDrv_WriteByte(DDC2BI_DVI2_INT_MASK, 0xFF);
659 MDrv_WriteByte(DDC2BI_DVI3_INT_MASK, 0xFF);
660
661 MsOS_DetachInterrupt(E_INT_IRQ_DDC2BI);
662 return TRUE;
663 }
MDrv_DDC2BI_GetLibVer(const MSIF_Version ** ppVersion)664 E_DDC2BI_ReturnValue MDrv_DDC2BI_GetLibVer(const MSIF_Version **ppVersion)
665 {
666 if (!ppVersion)
667 {
668 return E_DDC2BI_RET_FAIL;
669 }
670
671 *ppVersion = &_drv_DDC2BI_version;
672 return E_DDC2BI_RET_OK;
673 }
674
MDrv_DDC2BI_GetInfo(MS_DDC2BI_INFO * pInfo)675 E_DDC2BI_ReturnValue MDrv_DDC2BI_GetInfo(MS_DDC2BI_INFO *pInfo)
676 {
677 memcpy((void*)pInfo, (void*)&_DDC2BI_Info, sizeof(MS_DDC2BI_INFO));
678 return E_DDC2BI_RET_OK;
679 }
680
MDrv_DDC2BI_GetStatus(MS_DDC2BI_Status * pStatus)681 E_DDC2BI_ReturnValue MDrv_DDC2BI_GetStatus(MS_DDC2BI_Status *pStatus)
682 {
683 memcpy((void*)pStatus, (void*)&_DDC2BI_Status, sizeof(MS_DDC2BI_Status));
684 return E_DDC2BI_RET_OK;
685 }
686
MDrv_DDC2BI_SetDbgLevel(MS_U16 u16DbgSwitch)687 E_DDC2BI_ReturnValue MDrv_DDC2BI_SetDbgLevel(MS_U16 u16DbgSwitch)
688 {
689 _DDC2BI_DbgSwitch = u16DbgSwitch;
690 UNUSED(_DDC2BI_DbgSwitch);
691 return E_DDC2BI_RET_OK;
692 }
693
694
695