Guest User

DSI86 testing program

a guest
May 22nd, 2014
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 29.02 KB | None | 0 0
  1. //*****************************************************************************
  2. //
  3. // SN65DSI86 testing program
  4. //
  5. // This is part of revision 1.0 of the EK-TM4C123GXL Firmware Package.
  6. //
  7. //*****************************************************************************
  8.  
  9. #include <stdint.h>
  10. #include <string.h>
  11. #include <stdbool.h>
  12. #include "inc/hw_ints.h"
  13. #include "inc/hw_memmap.h"
  14. #include "inc/hw_types.h"
  15. #include "driverlib/debug.h"
  16. #include "driverlib/fpu.h"
  17. #include "driverlib/gpio.h"
  18. #include "driverlib/interrupt.h"
  19. #include "driverlib/pin_map.h"
  20. #include "driverlib/rom.h"
  21. #include "driverlib/timer.h"
  22. #include "driverlib/sysctl.h"
  23. #include "driverlib/uart.h"
  24. #include "utils/uartstdio.h"
  25. #include "utils/softi2c.h"
  26.  
  27. //*****************************************************************************
  28. //
  29. //! UART0, connected to the Virtual Serial Port and running at
  30. //! 115,200, 8-N-1, is used to display messages from this application.
  31. //
  32. //*****************************************************************************
  33. #define SLAVE_ADDR 0x2C
  34.  
  35. //*****************************************************************************
  36. //
  37. // The states in the interrupt handler state machine.
  38. //
  39. //*****************************************************************************
  40. #define STATE_IDLE              0
  41. #define STATE_WRITE_PRE_NEXT    1
  42. #define STATE_WRITE_PRE_FINAL   2
  43. #define STATE_WRITE_NEXT        3
  44. #define STATE_WRITE_FINAL       4
  45. #define STATE_WAIT_ACK          5
  46. #define STATE_SEND_ACK          6
  47. #define STATE_OFFSET_ONE        7
  48. #define STATE_OFFSET_FIRST      8
  49. #define STATE_READ_ONE          9
  50. #define STATE_READ_FIRST        10
  51. #define STATE_READ_NEXT         11
  52. #define STATE_READ_FINAL        12
  53. #define STATE_READ_WAIT         13
  54.  
  55.  
  56. //
  57. //
  58. //
  59. #define EDP_CONFIGURATION_CAP       (0x000D)
  60. # define ASSR_SUPPORT               (1<<0)
  61. # define ENHANCE_FRAMING            (1<<1)
  62. # define DPCD_DISPLAY_CONTORL_CAP   (1<<3)
  63.  
  64.  
  65. #define EDP_CONFIGURATION_SET       (0x010A)
  66. # define EN_ASSR                    (1<<0)
  67. # define EN_ENHANCE_FRAMING         (1<<1)
  68. # define EN_SELF_TEST               (1<<7)
  69.  
  70. static tSoftI2C g_sI2C;
  71.  
  72. static uint8_t  g_ui8SlaveAddr  = SLAVE_ADDR;
  73. static uint8_t *g_pui8Data = 0;
  74. static uint32_t g_ui32Count = 0;
  75. static uint32_t g_ui32Offset = 0;
  76.  
  77. static volatile uint32_t g_ui32State = STATE_IDLE;
  78.  
  79. static uint8_t g_ui8EDID[128];
  80.  
  81. //*****************************************************************************
  82. //
  83. // The error routine that is called if the driver library encounters an error.
  84. //
  85. //*****************************************************************************
  86. #ifdef DEBUG
  87. void
  88. __error__(char *pcFilename, uint32_t ui32Line)
  89. {
  90. }
  91. #endif
  92.  
  93. //*****************************************************************************
  94. //
  95. // The callback function for the SoftI2C module.
  96. //
  97. //*****************************************************************************
  98. void
  99. SoftI2CCallback(void)
  100. {
  101.     //
  102.     // Clear the SoftI2C interrupt.
  103.     //
  104.     SoftI2CIntClear(&g_sI2C);
  105.  
  106.     //
  107.     // Determine what to do based on the current state.
  108.     //
  109.     switch(g_ui32State)
  110.     {
  111.         //
  112.         // The idle state.
  113.         //
  114.         case STATE_IDLE:
  115.         {
  116.             //
  117.             // There is nothing to be done.
  118.             //
  119.             break;
  120.         }
  121.  
  122.         case STATE_WRITE_PRE_NEXT:
  123.         {
  124.  
  125.             SoftI2CDataPut(&g_sI2C, (g_ui32Offset & 0xFF));
  126.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_CONT);
  127.             g_ui32State = STATE_WRITE_NEXT;
  128.             break;
  129.         }
  130.  
  131.         case STATE_WRITE_PRE_FINAL:
  132.         {
  133.             SoftI2CDataPut(&g_sI2C, (g_ui32Offset & 0xFF));
  134.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_CONT);
  135.             g_ui32State = STATE_WRITE_FINAL;
  136.             break;
  137.         }
  138.  
  139.         //
  140.         // The state for the middle of a burst write.
  141.         //
  142.         case STATE_WRITE_NEXT:
  143.         {
  144.             //
  145.             // Write the next data byte.
  146.             //
  147.             SoftI2CDataPut(&g_sI2C, *g_pui8Data++);
  148.             g_ui32Count--;
  149.  
  150.             //
  151.             // Continue the burst write.
  152.             //
  153.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_CONT);
  154.  
  155.             //
  156.             // If there is one byte left, set the next state to the final write
  157.             // state.
  158.             //
  159.             if(g_ui32Count == 1)
  160.             {
  161.                 g_ui32State = STATE_WRITE_FINAL;
  162.             }
  163.  
  164.             //
  165.             // This state is done.
  166.             //
  167.             break;
  168.         }
  169.  
  170.         //
  171.         // The state for the final write of a burst sequence.
  172.         //
  173.         case STATE_WRITE_FINAL:
  174.         {
  175.             //
  176.             // Write the final data byte.
  177.             //
  178.             SoftI2CDataPut(&g_sI2C, *g_pui8Data++);
  179.             g_ui32Count--;
  180.  
  181.             //
  182.             // Finish the burst write.
  183.             //
  184.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_FINISH);
  185.  
  186.             //
  187.             // The next state is to wait for the burst write to complete.
  188.             //
  189.             g_ui32State = STATE_SEND_ACK;
  190.  
  191.             //
  192.             // This state is done.
  193.             //
  194.             break;
  195.         }
  196.  
  197.         //
  198.         // Wait for an ACK on the read after a write.
  199.         //
  200.         case STATE_WAIT_ACK:
  201.         {
  202.             //
  203.             // See if there was an error on the previously issued read.
  204.             //
  205.             if(SoftI2CErr(&g_sI2C) == SOFTI2C_ERR_NONE)
  206.             {
  207.                 //
  208.                 // Read the byte received.
  209.                 //
  210.                 SoftI2CDataGet(&g_sI2C);
  211.  
  212.                 //
  213.                 // There was no error, so the state machine is now idle.
  214.                 //
  215.                 g_ui32State = STATE_IDLE;
  216.  
  217.                 //
  218.                 // This state is done.
  219.                 //
  220.                 break;
  221.             }
  222.  
  223.             //
  224.             // Fall through to STATE_SEND_ACK.
  225.             //
  226.         }
  227.  
  228.         //
  229.         // Send a read request, looking for the ACK to indicate that the write
  230.         // is done.
  231.         //
  232.         case STATE_SEND_ACK:
  233.         {
  234.             //
  235.             // Put the I2C master into receive mode.
  236.             //
  237.             SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, true);
  238.  
  239.             //
  240.             // Perform a single byte read.
  241.             //
  242.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_SINGLE_RECEIVE);
  243.  
  244.             //
  245.             // The next state is the wait for the ack.
  246.             //
  247.             g_ui32State = STATE_WAIT_ACK;
  248.  
  249.             //
  250.             // This state is done.
  251.             //
  252.             break;
  253.         }
  254.  
  255.         // The state for a single byte read.
  256.         case STATE_OFFSET_ONE:
  257.         {
  258.             SoftI2CDataPut(&g_sI2C, (g_ui32Offset & 0xFF));
  259.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_CONT);
  260.             g_ui32State = STATE_READ_ONE;
  261.             break;
  262.         }
  263.  
  264.         case STATE_OFFSET_FIRST:
  265.         {
  266.             SoftI2CDataPut(&g_sI2C, (g_ui32Offset & 0xFF));
  267.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_CONT);
  268.             g_ui32State = STATE_READ_FIRST;
  269.             break;
  270.         }
  271.  
  272.         //
  273.         // The state for a single byte read.
  274.         //
  275.         case STATE_READ_ONE:
  276.         {
  277.             //
  278.             // Put the SoftI2C module into receive mode.
  279.             //
  280.             SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, true);
  281.  
  282.             //
  283.             // Perform a single byte read.
  284.             //
  285.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_SINGLE_RECEIVE);
  286.  
  287.             //
  288.             // The next state is the wait for final read state.
  289.             //
  290.             g_ui32State = STATE_READ_WAIT;
  291.  
  292.             //
  293.             // This state is done.
  294.             //
  295.             break;
  296.         }
  297.  
  298.         //
  299.         // The state for the start of a burst read.
  300.         //
  301.         case STATE_READ_FIRST:
  302.         {
  303.             //
  304.             // Put the SoftI2C module into receive mode.
  305.             //
  306.             SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, true);
  307.  
  308.             //
  309.             // Start the burst receive.
  310.             //
  311.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_RECEIVE_START);
  312.  
  313.             //
  314.             // The next state is the middle of the burst read.
  315.             //
  316.             g_ui32State = STATE_READ_NEXT;
  317.  
  318.             //
  319.             // This state is done.
  320.             //
  321.             break;
  322.         }
  323.  
  324.         //
  325.         // The state for the middle of a burst read.
  326.         //
  327.         case STATE_READ_NEXT:
  328.         {
  329.             //
  330.             // Read the received character.
  331.             //
  332.             *g_pui8Data++ = SoftI2CDataGet(&g_sI2C);
  333.             g_ui32Count--;
  334.  
  335.             //
  336.             // Continue the burst read.
  337.             //
  338.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_RECEIVE_CONT);
  339.  
  340.             //
  341.             // If there are two characters left to be read, make the next
  342.             // state be the end of burst read state.
  343.             //
  344.             if(g_ui32Count == 2)
  345.             {
  346.                 g_ui32State = STATE_READ_FINAL;
  347.             }
  348.  
  349.             //
  350.             // This state is done.
  351.             //
  352.             break;
  353.         }
  354.  
  355.         //
  356.         // The state for the end of a burst read.
  357.         //
  358.         case STATE_READ_FINAL:
  359.         {
  360.             //
  361.             // Read the received character.
  362.             //
  363.             *g_pui8Data++ = SoftI2CDataGet(&g_sI2C);
  364.             g_ui32Count--;
  365.  
  366.             //
  367.             // Finish the burst read.
  368.             //
  369.             SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_RECEIVE_FINISH);
  370.  
  371.             //
  372.             // The next state is the wait for final read state.
  373.             //
  374.             g_ui32State = STATE_READ_WAIT;
  375.  
  376.             //
  377.             // This state is done.
  378.             //
  379.             break;
  380.         }
  381.  
  382.         //
  383.         // This state is for the final read of a single or burst read.
  384.         //
  385.         case STATE_READ_WAIT:
  386.         {
  387.             //
  388.             // Read the received character.
  389.             //
  390.             *g_pui8Data++ = SoftI2CDataGet(&g_sI2C);
  391.             g_ui32Count--;
  392.  
  393.             //
  394.             // The state machine is now idle.
  395.             //
  396.             g_ui32State = STATE_IDLE;
  397.  
  398.             //
  399.             // This state is done.
  400.             //
  401.             break;
  402.         }
  403.     }
  404. }
  405.  
  406. void
  407. I2C_Write8(uint8_t *pui8Data, uint32_t ui32Offset, uint32_t ui32Count)
  408. {
  409.     //
  410.     // Save the data buffer to be written.
  411.     //
  412.     g_pui8Data = pui8Data;
  413.     g_ui32Count = ui32Count;
  414.     g_ui32Offset = ui32Offset;
  415.     //
  416.     // Set the next state of the callback state machine based on the number of
  417.     // bytes to write.
  418.     //
  419.     if(ui32Count != 1)
  420.     {
  421.         g_ui32State = STATE_WRITE_NEXT;
  422.     }
  423.     else
  424.     {
  425.         g_ui32State = STATE_WRITE_FINAL;
  426.     }
  427.  
  428.     //
  429.     // Set the slave address and setup for a transmit operation.
  430.     //
  431.     SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, false);
  432.  
  433.     //
  434.     // Write the address to be written as the first data byte.
  435.     //
  436.     SoftI2CDataPut(&g_sI2C, (ui32Offset & 0xFF));
  437.  
  438.     //
  439.     // Start the burst cycle, writing the address as the first byte.
  440.     //
  441.     SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_START);
  442.  
  443.     //
  444.     // Wait until the SoftI2C callback state machine is idle.
  445.     //
  446.     while(g_ui32State != STATE_IDLE)
  447.     {
  448.     }
  449. }
  450.  
  451.  
  452. //*****************************************************************************
  453. //
  454. // Write to the Atmel device.
  455. //
  456. //*****************************************************************************
  457. void
  458. AtmelWrite(uint8_t *pui8Data, uint32_t ui32Offset, uint32_t ui32Count)
  459. {
  460.     //
  461.     // Save the data buffer to be written.
  462.     //
  463.     g_pui8Data = pui8Data;
  464.     g_ui32Count = ui32Count;
  465.     g_ui32Offset = ui32Offset;
  466.     //
  467.     // Set the next state of the callback state machine based on the number of
  468.     // bytes to write.
  469.     //
  470.     if(ui32Count != 1)
  471.     {
  472.         g_ui32State = STATE_WRITE_PRE_NEXT;
  473.     }
  474.     else
  475.     {
  476.         g_ui32State = STATE_WRITE_PRE_FINAL;
  477.     }
  478.  
  479.     //
  480.     // Set the slave address and setup for a transmit operation.
  481.     //
  482.     SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, false);
  483.  
  484.     //
  485.     // Write the address to be written as the first data byte.
  486.     //
  487.     SoftI2CDataPut(&g_sI2C, (ui32Offset>>8));
  488.  
  489.     //
  490.     // Start the burst cycle, writing the address as the first byte.
  491.     //
  492.     SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_START);
  493.  
  494.     //
  495.     // Wait until the SoftI2C callback state machine is idle.
  496.     //
  497.     while(g_ui32State != STATE_IDLE)
  498.     {
  499.     }
  500. }
  501.  
  502. void
  503. I2C_Read8(uint8_t *pui8Data, uint32_t ui32Offset, uint32_t ui32Count)
  504. {
  505.     //
  506.     // Save the data buffer to be read.
  507.     //
  508.     g_pui8Data = pui8Data;
  509.     g_ui32Count = ui32Count;
  510.     g_ui32Offset = ui32Offset;
  511.  
  512.     //
  513.     // Set the next state of the callback state machine based on the number of
  514.     // bytes to read.
  515.     //
  516.     if(ui32Count == 1)
  517.     {
  518.         g_ui32State = STATE_READ_ONE;
  519.     }
  520.     else
  521.     {
  522.         g_ui32State = STATE_READ_FIRST;
  523.     }
  524.  
  525.     //
  526.     // Start with a dummy write to get the address set in the EEPROM.
  527.     //
  528.     SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, false);
  529.  
  530.     //
  531.     // Write the address to be written as the first data byte.
  532.     //
  533.     SoftI2CDataPut(&g_sI2C, (ui32Offset & 0xFF));
  534.  
  535.     //
  536.     // Perform a single send, writing the address as the only byte.
  537.     //
  538.     SoftI2CControl(&g_sI2C, SOFTI2C_CMD_SINGLE_SEND);
  539.     //SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_START);
  540.  
  541.     //
  542.     // Wait until the SoftI2C callback state machine is idle.
  543.     //
  544.     while(g_ui32State != STATE_IDLE)
  545.     {
  546.     }
  547. }
  548.  
  549.  
  550. //*****************************************************************************
  551. //
  552. // Read from the Atmel device.
  553. //
  554. //*****************************************************************************
  555. void
  556. AtmelRead(uint8_t *pui8Data, uint32_t ui32Offset, uint32_t ui32Count)
  557. {
  558.     //
  559.     // Save the data buffer to be read.
  560.     //
  561.     g_pui8Data = pui8Data;
  562.     g_ui32Count = ui32Count;
  563.     g_ui32Offset = ui32Offset;
  564.  
  565.     //
  566.     // Set the next state of the callback state machine based on the number of
  567.     // bytes to read.
  568.     //
  569.     if(ui32Count == 1)
  570.     {
  571.         g_ui32State = STATE_OFFSET_ONE;
  572.     }
  573.     else
  574.     {
  575.         g_ui32State = STATE_OFFSET_FIRST;
  576.     }
  577.  
  578.     //
  579.     // Start with a dummy write to get the address set in the EEPROM.
  580.     //
  581.     SoftI2CSlaveAddrSet(&g_sI2C, g_ui8SlaveAddr, false);
  582.  
  583.     //
  584.     // Write the address to be written as the first data byte.
  585.     //
  586.     SoftI2CDataPut(&g_sI2C, (ui32Offset>>8));
  587.  
  588.     //
  589.     // Perform a single send, writing the address as the only byte.
  590.     //
  591. //    SoftI2CControl(&g_sI2C, SOFTI2C_CMD_SINGLE_SEND);
  592.     SoftI2CControl(&g_sI2C, SOFTI2C_CMD_BURST_SEND_START);
  593.  
  594.     //
  595.     // Wait until the SoftI2C callback state machine is idle.
  596.     //
  597.     while(g_ui32State != STATE_IDLE)
  598.     {
  599.     }
  600. }
  601.  
  602. //*****************************************************************************
  603. //
  604. // This is the interrupt handler for the Timer0A interrupt.
  605. //
  606. //*****************************************************************************
  607. void
  608. Timer0AIntHandler(void)
  609. {
  610.     //
  611.     // Clear the timer interrupt.
  612.     // TODO: change this to whichever timer you are using.
  613.     //
  614.     TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  615.  
  616.     //
  617.     // Call the SoftI2C tick function.
  618.     //
  619.     SoftI2CTimerTick(&g_sI2C);
  620. }
  621.  
  622.  
  623. //*****************************************************************************
  624. //
  625. // Configure the UART and its pins.  This must be called before UARTprintf().
  626. //
  627. //*****************************************************************************
  628. void
  629. ConfigureUART(void)
  630. {
  631.     //
  632.     // Enable the GPIO Peripheral used by the UART.
  633.     //
  634.     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  635.  
  636.     //
  637.     // Enable UART0
  638.     //
  639.     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  640.  
  641.     //
  642.     // Configure GPIO Pins for UART mode.
  643.     //
  644.     ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
  645.     ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
  646.     ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  647.  
  648.     //
  649.     // Use the internal 16MHz oscillator as the UART clock source.
  650.     //
  651.     UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
  652.  
  653.     //
  654.     // Initialize the UART for console I/O.
  655.     //
  656.     UARTStdioConfig(0, 115200, 16000000);
  657. }
  658.  
  659. static void READ_DPCD(uint8_t* buff, uint32_t v_addr, uint32_t cnt)
  660. {
  661.     uint8_t tmp[4];
  662.     // AUX 20bit address
  663.     tmp[0] = (v_addr>>16) & 0x0F;
  664.     tmp[1] = (v_addr>>8) & 0xFF;
  665.     tmp[2] = (v_addr & 0xFF);
  666.     // length
  667.     tmp[3] = (cnt & 0x1F);
  668.     I2C_Write8(tmp, 0x74, 4); // write DPCD register address
  669.  
  670.     // AUX_NATIVE_CMD (0x9)
  671.     tmp[0] = (9<<4) | // AUX_NATIVE_READ
  672.              (1<<0);  // EN_SEND_AUX
  673.     I2C_Write8(tmp, 0x78, 1);
  674.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // waiting for response
  675.     I2C_Read8(buff, 0x79, (cnt&0x1F));
  676. }
  677.  
  678. static void WRITE_DPCD(uint8_t* buff, uint32_t v_addr, uint32_t cnt)
  679. {
  680.     uint8_t tmp[4];
  681.     // AUX 20bit address
  682.     tmp[0] = (v_addr>>16) & 0x0F;
  683.     tmp[1] = (v_addr>>8) & 0xFF;
  684.     tmp[2] = (v_addr & 0xFF);
  685.     // length
  686.     tmp[3] = (cnt & 0x1F);
  687.     I2C_Write8(tmp, 0x74, 4); // write DPCD register address
  688.  
  689.     I2C_Write8(buff, 0x64, cnt);
  690.  
  691.     // AUX_NATIVE_CMD (0x8)
  692.     tmp[0] = (8<<4) | // AUX_NATIVE_WRITE
  693.              (1<<0);  // EN_SEND_AUX
  694.     I2C_Write8(tmp, 0x78, 1);
  695.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3);
  696. }
  697.  
  698.  
  699. static void opAUX(uint32_t v_addr, uint8_t* buff, uint8_t cnt, uint8_t cmd)
  700. {
  701.     uint8_t tmp[4];
  702.     // AUX 20bit address
  703.     tmp[0] = (v_addr>>16) & 0x0F;
  704.     tmp[1] = (v_addr>>8) & 0xFF;
  705.     tmp[2] = (v_addr & 0xFF);
  706.     // length
  707.     tmp[3] = (cnt & 0x1F);
  708.     I2C_Write8(tmp, 0x74, 4); // write address
  709.    
  710.     if ((cnt != 0) && cmd != 5)
  711.         I2C_Write8(buff, 0x64, cnt);
  712.     tmp[0] = (cmd << 4) |
  713.              ( 1 << 0); // SEND flag
  714.     I2C_Write8(tmp, 0x78, 1);
  715.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3);
  716. }
  717.  
  718. static void readEDID(void)
  719. {
  720.     uint8_t buf[2];
  721.     uint8_t count;
  722.    
  723.     memset(buf, 0, sizeof(buf));
  724.     opAUX(0x50, buf, 0, 4); // Write with MOT, I2C over AUX, SYNC
  725.     opAUX(0x50, buf, 1, 4); // Write with MOT, Offset 0
  726.     opAUX(0x50, buf, 0, 5); // Read with MOT, READ START
  727.     for (count=0; count < 128; count+= 16) {
  728.         opAUX(0x50, buf, 0x10, 5); // Read with MOT, read 16 byte
  729.         I2C_Read8((g_ui8EDID+count), 0x79, 0x10);
  730.     }
  731.     opAUX(0x50, buf, 0, 1); // read without MOT, read stop
  732. }
  733.  
  734. static void dumpEDID(void)
  735. {
  736.     uint8_t count;
  737.     uint8_t vo;
  738.    
  739.     count = vo = 0;
  740.     UARTprintf("--------------------------------------------------------\n");
  741.     UARTprintf("Dump Panel EDID \n");
  742.     UARTprintf("--------------------------------------------------------\n");
  743.     UARTprintf("    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
  744.     UARTprintf("--------------------------------------------------------");
  745.     for(count = 0; count < sizeof(g_ui8EDID); count++) {
  746.         if ((count % 16) == 0) {
  747.             UARTprintf("\n%02X|", vo);
  748.             vo += 0x10;
  749.         }
  750.         UARTprintf(" %02x", g_ui8EDID[count]);
  751.     }
  752.    
  753.     UARTprintf("\n");
  754. }
  755.  
  756. static void dumpPanelTiming(void)
  757. {
  758.     uint32_t t;
  759.     uint16_t ha;
  760.     uint16_t hb;
  761.     uint16_t ho;
  762.     uint16_t va;
  763.     uint16_t vb;
  764.     uint16_t vo;
  765.     uint16_t hpw;
  766.     uint16_t vpw;
  767.     uint16_t hsz;
  768.     uint16_t vsz;
  769.     uint16_t hbp;
  770.     uint16_t vbp;
  771.    
  772.     UARTprintf("--------------------------------------------------------\n");
  773.     UARTprintf("Extract Panel timing from EDID DTD1\n");
  774.     UARTprintf("--------------------------------------------------------\n");
  775.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf
  776.  
  777.     #define DTD1_OFFSET  (0x36)
  778.     t = (g_ui8EDID[DTD1_OFFSET+1]<<8) + g_ui8EDID[DTD1_OFFSET+0];
  779.     ha = ((g_ui8EDID[DTD1_OFFSET+4] & 0xF0)<<4) + g_ui8EDID[DTD1_OFFSET+2];
  780.     hb = ((g_ui8EDID[DTD1_OFFSET+4] & 0x0F)<<8) + g_ui8EDID[DTD1_OFFSET+3];
  781.     va = ((g_ui8EDID[DTD1_OFFSET+7] & 0xF0)<<4) + g_ui8EDID[DTD1_OFFSET+5];
  782.     vb = ((g_ui8EDID[DTD1_OFFSET+7] & 0x0F)<<8) + g_ui8EDID[DTD1_OFFSET+6];
  783.     ho = ((g_ui8EDID[DTD1_OFFSET+11] & 0xC0)<<2) + g_ui8EDID[DTD1_OFFSET+8];
  784.     vo = ((g_ui8EDID[DTD1_OFFSET+11] & 0x0C)<<2) + (g_ui8EDID[DTD1_OFFSET+10] >> 4);   
  785.     hpw = ((g_ui8EDID[DTD1_OFFSET+11] & 0x30)<<4) + g_ui8EDID[DTD1_OFFSET+9];
  786.     vpw = ((g_ui8EDID[DTD1_OFFSET+11] & 0x03)<<4) + (g_ui8EDID[DTD1_OFFSET+10]&0x0F);
  787.     hsz = ((g_ui8EDID[DTD1_OFFSET+14] & 0xF0)<<4) + g_ui8EDID[DTD1_OFFSET+12];
  788.     vsz = ((g_ui8EDID[DTD1_OFFSET+14] & 0x0F)<<8) + g_ui8EDID[DTD1_OFFSET+13];
  789.     hbp = g_ui8EDID[DTD1_OFFSET+15];
  790.     vbp = g_ui8EDID[DTD1_OFFSET+16];
  791.    
  792.     UARTprintf("Pixel Clock %dMHz(%dKHz)\n", t/100, t*10);
  793.     UARTprintf("Active zone(Hori.xVert.): %dx%d\n", ha, va);
  794.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf   
  795.     UARTprintf("Blinking zone(Hori. & Vert.): %d & %d\n", hb, vb);
  796.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf   
  797.     UARTprintf("Horizontal sync Offset & Pulse width: %d & %d\n", ho, hpw);
  798.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf   
  799.     UARTprintf("Vertical sync Offset & Pulse width: %d & %d\n", vo, vpw);  
  800.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf   
  801.     UARTprintf("Border (Hori. & Vert.): %d & %d\n", hbp, vbp);
  802.     UARTprintf("Display Size(Hori.xVert.): %dx%d mm2\n", hsz, vsz);
  803.     ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf
  804.     if ((g_ui8EDID[DTD1_OFFSET+17] & 0x18) !=  0x18) {
  805.         UARTprintf("can't support the panel, because we need a digital separate type\n");
  806.         return;
  807.     }
  808.     UARTprintf("Horizontal sync. Polarity: ");     
  809.     if (g_ui8EDID[DTD1_OFFSET+17] & (1<<1)) {
  810.         UARTprintf("Positive\n");
  811.     } else {
  812.         UARTprintf("Negative\n");
  813.     }
  814.  
  815.     UARTprintf("Vertical sync. Polarity: ");   
  816.     if (g_ui8EDID[DTD1_OFFSET+17] & (1<<2)) {
  817.         UARTprintf("Positive\n");
  818.     } else {
  819.         UARTprintf("Negative\n");
  820.     }
  821. }
  822.  
  823. static void dumpDPCD(void)
  824. {
  825.     uint8_t count;
  826.     uint8_t i;
  827.     uint8_t buf[16];
  828.     uint16_t lists[] = {
  829.         0x0000, 0x0100, 0x0200, 0x0210 };
  830.  
  831.     UARTprintf("--------------------------------------------------------\n");
  832.     UARTprintf("dump panel DPCD value\n");
  833.     UARTprintf("--------------------------------------------------------\n");
  834.  
  835.     for (i = 0; i < (sizeof(lists)/sizeof(uint16_t)); i++) {
  836.         READ_DPCD(buf, lists[i], 16);
  837.         UARTprintf("DPCD %04xh:", lists[i]);
  838.         for(count = 0; count < 16; count++) {
  839.             UARTprintf(" %02X", buf[count]);
  840.         }
  841.         UARTprintf("\n");
  842.         ROM_SysCtlDelay(ROM_SysCtlClockGet()/10/3); // wating for UARTprintf
  843.     }
  844. }
  845.  
  846. static void showDPCDInfo(void)
  847. {
  848.     uint8_t buf[16];
  849.     READ_DPCD(buf, 0, 16);
  850.  
  851.     UARTprintf("DPCD: REV:%d.%d, MAX_LINK_RATE:", (buf[0] >> 4), (buf[0]&0xF));
  852.     if (buf[1] == 0x06) {
  853.         UARTprintf("1.62Gbps");
  854.     } else if (buf[1] == 0x0A) {
  855.         UARTprintf("2.7Gbps");
  856.     }
  857.     UARTprintf(" MAX_LINK_LANE:%d\n", buf[2]);
  858.     if (buf[0x0D] & ASSR_SUPPORT) {
  859.         UARTprintf(" support ASSR");
  860.     } else {
  861.         UARTprintf(" not support ASSR");
  862.     }
  863.     if (buf[0x0D] & ENHANCE_FRAMING) {
  864.         UARTprintf(" support Enhance framing");
  865.     } else {
  866.         UARTprintf(" not support Enhance framing");
  867.     }
  868.     UARTprintf("\n");
  869. }
  870. //*****************************************************************************
  871. //
  872. //
  873. //*****************************************************************************
  874. int
  875. main(void)
  876. {
  877.     //volatile uint32_t ui32Loop;
  878.     uint32_t count;
  879.     uint8_t BUF[32];
  880.     uint32_t tmp;
  881.     uint32_t vo = 0;
  882.  
  883.     tmp = 0;
  884.     BUF[0] = BUF[1] = BUF[2] = BUF[3] = tmp;
  885.     tmp = BUF[0];
  886.  
  887.     //
  888.     // Enable lazy stacking for interrupt handlers.  This allows floating-point
  889.     // instructions to be used within interrupt handlers, but at the expense of
  890.     // extra stack usage.
  891.     //
  892.     ROM_FPULazyStackingEnable();
  893.  
  894.     //
  895.     // Set the clocking to run directly from the crystal.
  896.     //
  897.     ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
  898.                        SYSCTL_OSC_MAIN);
  899.  
  900.     //
  901.     // Enable the GPIO port that is used for the on-board LED.
  902.     //
  903.     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  904.  
  905.     //
  906.     // Enable the GPIO pins for the LED (PF2 & PF3).
  907.     //
  908.     ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
  909.  
  910.     //
  911.     // Initialize SoftI2C
  912.     //
  913.     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  914.     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  915.     GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
  916.     memset(&g_sI2C, 0, sizeof(g_sI2C));
  917.     SoftI2CCallbackSet(&g_sI2C, SoftI2CCallback);
  918.     SoftI2CSCLGPIOSet(&g_sI2C, GPIO_PORTA_BASE, GPIO_PIN_6);
  919.     SoftI2CSDAGPIOSet(&g_sI2C, GPIO_PORTA_BASE, GPIO_PIN_7);
  920.     SoftI2CInit(&g_sI2C);
  921.  
  922.     SoftI2CIntEnable(&g_sI2C);
  923.  
  924.     TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  925.     TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 40000);
  926.     TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  927.     TimerEnable(TIMER0_BASE, TIMER_A);
  928.  
  929.     IntEnable(INT_TIMER0A);
  930.  
  931.  
  932.     //
  933.     // Initialize the UART.
  934.     //
  935.     ConfigureUART();
  936.    
  937.     UARTprintf("for ColorBar Test \r\n");
  938.     BUF[0] = 1;
  939.     I2C_Write8(BUF, 0x09, 1); // software reset
  940.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  941.  
  942.     BUF[0] = 0 ;
  943.     I2C_Write8(BUF, 0x5A, 1); // disable VSTREAM
  944.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  945.  
  946.     BUF[0] = 0x0;
  947.     I2C_Write8(BUF, 0x0D, 1); // disable DP_PLL_EN
  948.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  949.    
  950.     BUF[0] = 1;
  951.     I2C_Write8(BUF, 0x09, 1); // software reset
  952.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  953.    
  954.     BUF[0] = 0x2;
  955.     I2C_Write8(BUF, 0x0A, 1); // Clock Ref = 19.2MHz
  956.  
  957.     readEDID();
  958.     dumpEDID();
  959.     dumpPanelTiming();
  960.     dumpDPCD();
  961.     showDPCDInfo();
  962.     BUF[0] = (1 << 5) | // SINGL CHANNEL DSI (A)
  963.             (0 << 3) | // Four Lane
  964.             (0);       // SOT_ERR_TOL_DIS
  965.     I2C_Write8(BUF, 0x10, 1);
  966.  
  967.     BUF[0] = 0; // disable ASSR
  968.     I2C_Write8(BUF, 0x5A, 1);
  969.  
  970.     BUF[0] = 1<<1; // 24BPP
  971.     I2C_Write8(BUF, 0x5B, 1);
  972.  
  973.     BUF[0] = 0; // HPD Enable
  974.     I2C_Write8(BUF, 0x5C, 1);
  975.  
  976.     BUF[0] = (0 << 6)  | // DP pre emphasis lv 0
  977.             (2 << 4)  | // DP 2 lane
  978.             (2 << 1)  | // Downspread 3750ppm
  979.             (0 << 0);   // disable SSC
  980.     I2C_Write8(BUF, 0x93, 1);
  981.  
  982.     BUF[0] = (4 << 5) | // 2.70Gbps
  983.             (0 << 2) | // 61ps
  984.             (0 << 0);  // Voltage
  985.     I2C_Write8(BUF, 0x94, 1);
  986. // Panel timing
  987. #define  HA         (1920)
  988. #define  HSPW       (39)
  989. #define  HFP        (59)
  990. #define  HBP        (62)
  991. #define  HSP        (0) // Hsyn Polarity:0 POS
  992. #define  VA         (1200)
  993. #define  VSPW       (3)
  994. #define  VFP        (6)
  995. #define  VBP        (26)
  996. #define  VSP        (1) // Vsyn Polarity: NEG
  997.  
  998.     BUF[0] = (HA & 0xFF);
  999.     BUF[1] = ((HA>>8) & 0xFF);
  1000.     I2C_Write8(BUF, 0x20, 2); // ActiveLine
  1001.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1002.  
  1003.     BUF[0] = (VA & 0xFF);
  1004.     BUF[1] = ((VA>>8) & 0xFF);
  1005.     I2C_Write8(BUF, 0x24, 2);  // Vertical line
  1006.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1007.  
  1008.     BUF[0] = (HSPW & 0xFF);
  1009.     BUF[1] = ((HSPW>>8) & 0x7F) |
  1010.             (HSP << 7);
  1011.     I2C_Write8(BUF, 0x2C, 2); // HSYNC Pulse width
  1012.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1013.  
  1014.     BUF[0] = (VSPW & 0xFF);
  1015.     BUF[1] = ((VSPW>>8) & 0xFF) |
  1016.             (VSP << 7); // neg
  1017.     I2C_Write8(BUF, 0x30, 2); // VSYNC Pulse width
  1018.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1019.  
  1020.     BUF[0] = HBP;
  1021.     I2C_Write8(BUF, 0x34, 1); // H_BACK_PORCH
  1022.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1023.  
  1024.     BUF[0] = VBP;
  1025.     I2C_Write8(BUF, 0x36, 1); // V_BACK_PORCH
  1026.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1027.  
  1028.     BUF[0] = HFP;
  1029.     I2C_Write8(BUF, 0x38, 1); // H_FRONT_PORCH
  1030.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1031.    
  1032.     BUF[0] = VFP;
  1033.     I2C_Write8(BUF, 0x3A, 1); // V_FRONT_PORCH
  1034.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1035.    
  1036.     BUF[0] = 0;
  1037.     I2C_Write8(BUF, 0x5B, 1); //24bpp
  1038.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1039.  
  1040.     BUF[0] = 0x1;
  1041.     I2C_Write8(BUF, 0x0D, 1); // Enable DP_PLL_EN
  1042.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1043.  
  1044.     I2C_Read8(BUF, 0x0A, 1);
  1045.     if (BUF[0] & 0x80) UARTprintf("DSI86 PLL has Locked now\n");
  1046.  
  1047.     BUF[0] = 0xA;   // ML_TX_MODE,Semi Auto Link Training
  1048.     I2C_Write8(BUF, 0x96, 1);
  1049.     ROM_SysCtlDelay(ROM_SysCtlClockGet() / 10 / 3);
  1050.  
  1051.     I2C_Read8(BUF, 0x96, 1);
  1052.     UARTprintf("SemiTraning result:%02X\n", BUF[0]);
  1053.  
  1054. #if 0
  1055.     BUF[0] = EN_SELF_TEST;
  1056.     WRITE_DPCD(BUF, EDP_CONFIGURATION_SET, 1);
  1057. #endif
  1058.  
  1059.     BUF[0] = 0x18; // Color Bar enable
  1060.     I2C_Write8(BUF, 0x3C, 1);
  1061.     SysCtlDelay(SysCtlClockGet() / 10 / 3);
  1062.  
  1063.     I2C_Read8(BUF, 0x20, 4);
  1064.  
  1065.     BUF[0] = (1<<3) ; // VStream
  1066.             //(0<<2) | // Enhanced Framing
  1067.     I2C_Write8(BUF, 0x5A, 1);
  1068.     SysCtlDelay(SysCtlClockGet() / 10 / 3);
  1069.    
  1070.     UARTprintf("--------------------------------------------------------\n");
  1071.     UARTprintf("    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
  1072.     UARTprintf("--------------------------------------------------------");
  1073.  
  1074. #if 1
  1075.     for (tmp = 0; tmp < 8; tmp++) {
  1076.         I2C_Read8(BUF, tmp*sizeof(BUF), sizeof(BUF));
  1077.         for(count = 0; count < sizeof(BUF); count++) {
  1078.             if ((count % 16) == 0) {
  1079.                 UARTprintf("\n%02X|", vo);
  1080.                 vo += 0x10;
  1081.             }
  1082.             UARTprintf(" %02x", BUF[count]);
  1083.         }
  1084.     }
  1085. #endif
  1086.     UARTprintf("\n");
  1087.     dumpDPCD();
  1088.     while(1)
  1089.     {
  1090.        
  1091.         //
  1092.         // Turn on the BLUE LED.
  1093.         //
  1094.         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
  1095.  
  1096.         //
  1097.         // Delay for a bit.
  1098.         //
  1099.          SysCtlDelay(SysCtlClockGet() / 10 / 3);
  1100.    
  1101.         //
  1102.         // Turn off the BLUE LED.
  1103.         //
  1104.         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
  1105.  
  1106.         //
  1107.         // Delay for a bit.
  1108.         //
  1109.         SysCtlDelay(SysCtlClockGet() / 10 / 3);
  1110.     }
  1111. }
Advertisement
Add Comment
Please, Sign In to add comment