Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
Option Explicit
'*****************************************************************************
' Module:
'        USIC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'USIC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author                    Date            Description
'        ---------------------------------------------------------------------
'        1.0  JaiSankar & Raja          16.04.07        XC22xx v0.01
'
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        For each function which should be used for this module a line
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name
'        "ASC_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshIICFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"

  RefreshIICFunctionDescriptions = False

  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String,
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable
  '                               for the function name e.g. SSC_NAME_Init)
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR, 3 => TRAP)

    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter


  '------------------------------------------------------------------------------------------------
  ' Description for UxCx_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  sReturnValue = "None"
  
  If (Not func.AddFunction(sVarPre & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_MasterTransmit
  '------------------------------------------------------------------------------------------------
  sDescription = "This function initializes the variables used for " & _
                "(multi-)master transmit mode and starts the transmission." & vbCrLf & _
                "Important: Transmit interrupt must be selected." & _
                "" & vbCrLf & _
                "To use this function:" & vbCrLf & _
                "A call to this function with the parameters described below " & _
                "initiates a data transfer from the master to the slave, " & _
                "addressed by uwDevice_Addr. *uwTxBuffer points to the first " & _
                "word to be transmitted (only the lower byte will be " & _
                "tranmitted), uwBufferSize indicates the amount of bytes to " & _
                "be transmitted." & vbCrLf & _
                "If uwIIC" & sVarPre & " is set to 1 after data transfer is complete," & _
                "the transmission was successfully finished. " & _
                "If uwIIC" & sVarPre & " is set to 2, transmission failed." & vbCrLf & _
                "" & vbCrLf & _
                "Note:" & vbCrLf & _
                "There is no error handling defined. You have to take care " & _
                "of this by yourself. "

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICMasterTransmit", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Device address"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterTransmit" & "_Para1", "uwDeviceAddr", "uword", sDescription)) Then Exit Function
    sDescription = "Sub address"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterTransmit" & "_Para2", "uwSubAddr", "uword", sDescription)) Then Exit Function
    sDescription = "Pointer to transmit buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterTransmit" & "_Para3", "*uwTxBuffer", "uword", sDescription)) Then Exit Function
    sDescription = "Amount of bytes to transmit"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterTransmit" & "_Para4", "uwBufferSize", "uword", sDescription)) Then Exit Function
    sDescription = "Address mode: 7 bit / 10 bit"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterTransmit" & "_Para5", "uwAddrMode", "uword", sDescription)) Then Exit Function
      
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_MasterReceive
  '------------------------------------------------------------------------------------------------
  sDescription = "This function initializes the variables used for " & _
               "(multi-)master transmit mode and starts receiving." & vbCrLf & _
               "Important: Receive interrupt must be selected." & _
               "" & vbCrLf & _
               "To use this function:" & vbCrLf & _
               "A call to this function with the parameters described below " & _
               "initiates a data transfer from the slave to the master, " & _
               "addressed by uwDevice_Addr. *uwRxBuffer points to the first " & _
               "byte of receive buffer, uwBufferSize indicates the amount of " & _
               "bytes to be received. " & _
               "If uwIIC" & sVarPre & " is set to 1 after data transfer is complete," & _
               "the transmission was successfully finished." & _
               "If uwIIC" & sVarPre & " is set to 2, transmission failed." & vbCrLf & _
               "" & vbCrLf & _
               "Note:" & vbCrLf & _
               "There is no error handling defined. You have to take care of " & _
               "this by yourself."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICMasterReceive", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Device address"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterReceive" & "_Para1", "uwDeviceAddr", "uword", sDescription)) Then Exit Function
    sDescription = "Sub address"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterReceive" & "_Para2", "uwSubAddr", "uword", sDescription)) Then Exit Function
    sDescription = "Pointer to receive buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterReceive" & "_Para3", "*uwRxBuffer", "uword", sDescription)) Then Exit Function
    sDescription = "Amount of bytes to receive"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterReceive" & "_Para4", "uwBufferSize", "uword", sDescription)) Then Exit Function
    sDescription = "Address mode: 7 bit / 10 bit"
    If (Not func.AddParameter(sVarPre & "_NAME_IICMasterReceive" & "_Para5", "uwAddrMode", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_WriteData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function writes data to the " & sVarPre & " Transmit buffer " & _
                 "(" & sRegPre & "TBUF00). valid TDF & 8 bit data." & vbCrLf & _
                 "The valid TDF formats are available in " & sVarPre & " header file" & vbCrLf & _
                 "Defines section. Ex.." & vbCrLf & _
                 " Master start                  " & sVarPre & "TDF_MStart" & vbCrLf & _
                 " Master Transmit               " & sVarPre & "TDF_MTxData" & vbCrLf & _
                 " Master receive with Ack 0     " & sVarPre & "TDF_MRxAck0" & vbCrLf & _
                 " Master receive with Ack 1     " & sVarPre & "TDF_MRxAck1" & vbCrLf & _
                 " Master stop                   " & sVarPre & "TDF_MStop"


  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICWriteData", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "valid Transmit Data Format TDF code"
    If (Not func.AddParameter(sVarPre & "_NAME_IICWriteData" & "_Para1", "uwTDF", "uword", sDescription)) Then Exit Function
    sDescription = "8 bit data to be transmitted"
    If (Not func.AddParameter(sVarPre & "_NAME_IICWriteData" & "_Para2", "uwData", "uword", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_ReadData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function reads out the content of the " & sVarPre & _
                 " receive buffer (" & sRegPre & "RBUF)."

  sReturnValue = "Value of the register " & sRegPre & "RBUF"
  If (Not func.AddFunction(sVarPre & "_NAME_IICReadData", "uword", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_GetStatus
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro returns the status of the " & sVarPre & " status register " & _
                 sRegPre & "PSR. For further information about the bits of this " & _
                 "register refer to the user's manual." & vbCrLf & vbCrLf & _
                 "The status bits can be used to check the particular event status." & vbCrLf & _
                 "The definition for status bits are available in " & sVarPre & " header file " & _
                 "Defines section. Ex.." & vbCrLf & _
                 sVarPre & "IIC_ERR" & vbCrLf & _
                 sVarPre & "IIC_RIF" & vbCrLf & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "To check an event flag the macro is " & _
                 "used as follows:" & vbCrLf & _
                 r.v(sVarPre & "_NAME_IICGetStatus") & "() & " & sVarPre & "IIC_ERR" & vbCrLf & _
                 r.v(sVarPre & "_NAME_IICGetStatus") & "() & " & sVarPre & "IIC_RIF"

  sReturnValue = "The contents of " & sRegPre & "PSR"
  If (Not func.AddFunction(sVarPre & "_NAME_IICGetStatus", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_ResetStatus
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro resets the selected bit in the status register " & _
                 sRegPre & "PSR of the " & sVarPre & " module." & vbCrLf & vbCrLf & _
                 "The bit is seleccted by the parameter:" & " (Statusbit)" & vbCrLf & _
                 "The definition for status bits are available in " & sVarPre & " header file " & _
                 "Defines section. Ex.." & vbCrLf & _
                 sVarPre & "IIC_ERR" & vbCrLf & _
                 sVarPre & "IIC_RIF" & vbCrLf & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "To select more bits simultaneously the macro is " & _
                 "used as follows:" & vbCrLf & _
                 r.v(sVarPre & "_NAME_IICResetStatus") & "(" & _
                 sVarPre & "IIC_ERR + " & sVarPre & "IIC_RIF + ...)"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICResetStatus", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Bit to reset"
    If (Not func.AddParameter(sVarPre & "_NAME_IICResetStatus" & "_Para1", "Statusbit", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_EnableACK
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to enable the acknowledge pulse " & _
                 "generation. Normally the receiving device gives an " & _
                 "acknowledge to the transmitter. Only the last byte " & _
                 "is not to be acknowledged."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICEnableACK", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_DisableACK
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to disable the acknoledge pulse " & _
                 "generation. Normally the receiving device gives an " & _
                 "acknowledge to the transmitter. Only the last byte " & _
                 "is not to be acknowledged."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICDisableACK", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_InitSlaveMode
  '------------------------------------------------------------------------------------------------
  sDescription = "This function initialize the transmit and receive data buffer pointers " & _
                 "in IIC slave mode."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICInitSlaveMode", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Pointer to transmit buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IICInitSlaveMode" & "_Para1", "*puwTxBuffer", "uword", sDescription)) Then Exit Function
    sDescription = "Pointer to receive buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IICInitSlaveMode" & "_Para2", "*puwRxBuffer", "uword", sDescription)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_0IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_0IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIC0IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_1IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_1IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIC1IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_2IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_2IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIC2IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_3IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_3IC (shared with CC2)." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIC3IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICFillTxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This function is used to fill the Transmit FIFO with user given software" & _
                 " data buffer pointer. The INxx sfrs will be assigned with the data from " & _
                 "the software data buffer."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICFillTxFIFO", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Pointer to user data buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IICFillTxFIFO" & "_Para1", "*uwUDTxfifo", "uword", sDescription)) Then Exit Function
    sDescription = "Amount of data to transmit"
    If (Not func.AddParameter(sVarPre & "_NAME_IICFillTxFIFO" & "_Para2", "uwUDTxfifoSize", "uword", sDescription)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICGetRxFIFOData
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the data received in " & sVarPre & "_OUTRL sfr." & _
                 "The OUTRL sfr contains the oldest data received by the Receive FIFO."

  sReturnValue = "Value of the register " & sVarPre & "_OUTRL."
  If (Not func.AddFunction(sVarPre & "_NAME_IICGetRxFIFOData", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsRxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "1 if receive buffer is busy, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsRxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsTxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "1 if transmit buffer is busy, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsTxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsRxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is full or not."

  sReturnValue = "1 if receive buffer is full, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsRxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsTxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is full or not."

  sReturnValue = "1 if transmit buffer is full, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsTxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsRxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is empty or not."

  sReturnValue = "1 if receive buffer is empty, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsRxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICIsTxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is empty or not."

  sReturnValue = "1 if transmit buffer is empty, else 0."
  If (Not func.AddFunction(sVarPre & "_NAME_IICIsTxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICGetRxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the receive buffer filling level."

  sReturnValue = "Value of the bitfield " & sVarPre & "_TRBSRH_RBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_IICGetRxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICGetTxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the transmit buffer filling level."

  sReturnValue = "Value of the bitfield " & sVarPre & "_TRBSRH_TBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_IICGetTxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICFlushRxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to clear the receive FIFO. But it should only be used" & _
                 "while the FIFO buffer is not taking part in data traffic."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICFlushRxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIC UxCy_NAME_IICFlushTxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to clear the transmit FIFO. But it should only be used" & _
                 "while the FIFO buffer is not taking part in data traffic."
                 
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IICFlushTxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  
  If (Not func.Sort) Then Exit Function

  RefreshIICFunctionDescriptions = True
End Function



'*****************************************************************************
'Description:
'        This function adds SCL pins and returns the listindex to the cboSCL.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         SCL combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to SCL Pins combobox
'*****************************************************************************
Function AddSCLPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
    
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.2")
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P2.8")
      If IsAlternateOutputPinFree(r, "U0C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.5")
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_SCLKOUT_O_1") Then cboCrtl.AddItem ("P0.2")
      If IsAlternateOutputPinFree(r, "U1C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.11")
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P0.5")
      If IsAlternateOutputPinFree(r, "U1C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P6.2")
    Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_SCLKOUT_O_1") Then cboCrtl.AddItem ("P1.7")
      If IsControllerTypeOK(r) = 1 Then
      If IsAlternateOutputPinFree(r, "U2C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P3.2")
      End If
    Case ("U2C1")
      If IsAlternateOutputPinFree(r, "U2C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P1.2")
      If IsControllerTypeOK(r) = 1 Then
      If IsAlternateOutputPinFree(r, "U2C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P3.5")
      End If
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIC_cboSCL")) Then
        AddSCLPINSnGetIndex = i
    End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function

'*****************************************************************************
'Description:
'        This function adds SDA pins and returns the listindex to the cboSDA.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         SDA combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to SDA Pins combobox
'*****************************************************************************
Function AddSDAPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next
  
  Dim i As Integer
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
  
  Select Case (ModuleName)
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_1") Then cboCrtl.AddItem ("P2.3")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.1")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_4") Then cboCrtl.AddItem ("P10.6")
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_2") Then cboCrtl.AddItem ("P2.10")
'      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_3") Then cboCrtl.AddItem ("P7.3")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_5") Then cboCrtl.AddItem ("P10.0")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_6") Then cboCrtl.AddItem ("P10.7")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_7") Then cboCrtl.AddItem ("P10.14")
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_1") Then cboCrtl.AddItem ("P0.0")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_2") Then cboCrtl.AddItem ("P0.1")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.12")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_4") Then cboCrtl.AddItem ("P10.13")
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_1") Then cboCrtl.AddItem ("P0.6")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_2") Then cboCrtl.AddItem ("P0.7")
    Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_1") Then cboCrtl.AddItem ("P1.6")
      If IsControllerTypeOK(r) = 1 Then
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_2") Then cboCrtl.AddItem ("P3.0")
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_3") Then cboCrtl.AddItem ("P3.1")
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_5") Then cboCrtl.AddItem ("P9.5")
      End If
    Case ("U2C1")
      If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_3") Then cboCrtl.AddItem ("P1.1")
      If IsControllerTypeOK(r) = 1 Then
      If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_1") Then cboCrtl.AddItem ("P3.6")
      If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_2") Then cboCrtl.AddItem ("P3.7")
      End If
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIC_cboSDA")) Then
        AddSDAPINSnGetIndex = i
    End If
  Next i
  
  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False
  
End Function


'*****************************************************************************
'Description:
'        This function set the selected SCL pin for shift clock
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetSCLPin(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
  
  Dim sOpenDrainReg As String
   
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P10.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P2.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
'        r.v(RegName & "DX1CR_DSEL") = 0        'Only SCLK OUT
      End If
      
    Case ("U0C1")
      If (PinNo = "P2.8") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
        r.v(RegName & "DX1CR_DSEL") = 3
      ElseIf (PinNo = "P10.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 1
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
        r.v(RegName & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P10.11") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 3
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
        r.v(RegName & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P6.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 2
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
        r.v(RegName & "DX1CR_DSEL") = 2
      ElseIf (PinNo = "P3.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 1
      End If
      
    Case ("U2C1")
      If (PinNo = "P1.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
        r.v(RegName & "DX1CR_DSEL") = 2
      ElseIf (PinNo = "P3.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")
        r.v(RegName & "DX1CR_DSEL") = 0
      End If
      
    Case Else
    
  End Select
  
  'To make the SCL pin open drain
  If (PinNo <> "None") Then
    sOpenDrainReg = GetInterfacePinNo(r, ModuleName, PinNo) & "_PC"
    r.v(sOpenDrainReg) = r.v(sOpenDrainReg) + 4       'Open Drain
  End If
  'To make same SCL pin for SCLKIN & SCLKOUT
    'r.v(RegName & "DX1CR_DSEL") = SCL pin selected.
    r.v(RegName & "DX1CR_DPOL") = 0
    r.v(RegName & "DX1CR_INSW") = 0
    r.v(RegName & "BRGH_SCLKCFG") = 0

End Sub

'*****************************************************************************
'Description:
'        This function set the selected SDA pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetSDAPin(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  Dim sOpenDrainReg As String
  
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P2.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
        r.v(RegName & "DX0CR_DSEL") = 4
      ElseIf (PinNo = "P10.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
        r.v(RegName & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P10.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
        r.v(RegName & "DX0CR_DSEL") = 2
      End If
      
    Case ("U0C1")                               'P10.0,P10.7,P10.14
      If (PinNo = "P2.10") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
        r.v(RegName & "DX0CR_DSEL") = 4
      ElseIf (PinNo = "P7.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
        r.v(RegName & "DX0CR_DSEL") = 5
      ElseIf (PinNo = "P10.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P10.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_6")
        r.v(RegName & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P10.14") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_7")
        r.v(RegName & "DX0CR_DSEL") = 2
      End If
      
    Case ("U1C0")                               'P0.0,P0.1
      If (PinNo = "P0.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
        r.v(RegName & "DX0CR_DSEL") = 0
       ElseIf (PinNo = "P0.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
        r.v(RegName & "DX0CR_DSEL") = 1
       ElseIf (PinNo = "P10.12") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
        r.v(RegName & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P10.13") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
        r.v(RegName & "DX0CR_DSEL") = 3
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P0.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
        r.v(RegName & "DX0CR_DSEL") = 1
      End If
      
    Case ("U2C0")                               'P3.0,P3.1,P9.5
      If (PinNo = "P1.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
        r.v(RegName & "DX0CR_DSEL") = 3
      ElseIf (PinNo = "P3.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P3.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
        r.v(RegName & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P9.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
        r.v(RegName & "DX0CR_DSEL") = 4
      End If
      
    Case ("U2C1")                               'P3.6,P3.7
      If (PinNo = "P1.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
        r.v(RegName & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P3.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P3.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
        r.v(RegName & "DX0CR_DSEL") = 1
      End If
      
    Case Else
    
  End Select
  
  'To make the SDA pin open drain
  If (PinNo <> "None") Then
    sOpenDrainReg = GetInterfacePinNo(r, ModuleName, PinNo) & "_PC"
    r.v(sOpenDrainReg) = r.v(sOpenDrainReg) + 4       'Open Drain
  End If
  'To make same SDA pin for DIN & DOUT
    'r.v(RegName & "DX0CR_DSEL") = SDA pin selected.
    r.v(RegName & "DX0CR_DPOL") = 0
    r.v(RegName & "DX0CR_INSW") = 0
    r.v(RegName & "SCTRL_DOCFG") = 0

End Sub


'*****************************************************************************
'Description:
'        This function releases the selected SCLPin for UxCy IIC mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseSCLPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
    
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIC_cboSCL"))
      Case ("P2.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U0C0
      Case ("P10.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U0C0
      Case ("P2.8")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U0C1
      Case ("P10.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U0C1
      Case ("P0.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U1C0
      Case ("P10.11")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U1C0
      Case ("P0.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U1C1
      Case ("P6.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U1C1
      Case ("P1.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U2C0
      Case ("P3.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U2C0
      Case ("P1.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U2C1
      Case ("P3.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U2C1
    End Select
    
    r.v(ModuleName & "_IIC_cboSCL") = "None"
    
End Sub


'*****************************************************************************
'Description:
'        This function releases the selected SDApin for UxCy IIC mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseSDAPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
      
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIC_cboSDA"))
      Case ("P2.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U0C0
      Case ("P10.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U0C0
      Case ("P10.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")  'U0C0
      Case ("P2.10")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U0C1
      Case ("P7.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U0C1
      Case ("P10.0")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_5")  'U0C1
      Case ("P10.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_6")  'U0C1
      Case ("P10.14")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_7")  'U0C1
      Case ("P0.0")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U1C0
      Case ("P0.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U1C0
      Case ("P10.12")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U1C0
      Case ("P10.13")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")  'U1C0
      Case ("P0.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U1C1
      Case ("P0.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U1C1
      Case ("P1.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U2C0
      Case ("P3.0")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U2C0
      Case ("P3.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U2C0
      Case ("P9.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_5")  'U2C0
      Case ("P1.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U2C1
      Case ("P3.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U2C1
      Case ("P3.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U2C1
    End Select

    r.v(ModuleName & "_IIC_cboSDA") = "None"
    
End Sub

'*****************************************************************************
'Description:
'        This function returns disabled tool tip of SCLpin for UxCy IIC mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   SCLDisabledToolTip
'*****************************************************************************
Function GetSCLDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get SCL disabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SCLKOUT_O_2")  'P10.2
'          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SCLKOUT_O_1")  'P2.5
      Case ("U0C1")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SCLKOUT_O_1")  'P2.8
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SCLKOUT_O_2")  'P10.5
      Case ("U1C0")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SCLKOUT_O_1")  'P0.2
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SCLKOUT_O_2")  'P10.11
      Case ("U1C1")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SCLKOUT_O_1")  'P0.5
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SCLKOUT_O_2")  'P6.2
      Case ("U2C0")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SCLKOUT_O_1")  'P1.7
          If IsControllerTypeOK(r) = 1 Then
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SCLKOUT_O_2")  'P3.2
          End If
      Case ("U2C1")
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SCLKOUT_O_2")  'P1.2
          If IsControllerTypeOK(r) = 1 Then
          GetSCLDisabledToolTip = GetSCLDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SCLKOUT_O_1")  'P3.5
          End If
     End Select
   
End Function

'*****************************************************************************
'Description:
'        This function returns disabled tool tip of SDApin for UxCy IIC mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   SDADisabledToolTip
'*****************************************************************************
Function GetSDADisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get SDA disabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_1")  'P2.3
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_3")  'P10.1
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_4")  'P10.6
      Case ("U0C1")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_2")  'P2.10
'          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_3")  'P7.3
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_5")  'P10.0
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_6")  'P10.7
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_7")  'P10.14
      Case ("U1C0")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_1")  'P0.0
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_2")  'P0.1
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_3")  'P10.12
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_4")  'P10.13
      Case ("U1C1")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DOUT_O_1")  'P0.6
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DOUT_O_2")  'P0.7
      Case ("U2C0")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_1")  'P1.6
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_2")  'P3.0
          If IsControllerTypeOK(r) = 1 Then
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_3")  'P3.1
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_5")  'P9.5
          End If
      Case ("U2C1")
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DOUT_O_3")  'P1.1
          If IsControllerTypeOK(r) = 1 Then
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DOUT_O_1")  'P3.6
          GetSDADisabledToolTip = GetSDADisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DOUT_O_2")  'P3.7
          End If
     End Select
   
End Function

'*****************************************************************************
'Description:
'        This function assigns the address entered by the user to to sfr PCRL.
'        It is called from OnShowIICGeneral page Address control. The 7 bit
'        Address is placed in PCRL[15:9] bitfield and 10 bit address is placed
'        in PCRL[7:0] and 2 MSBs in PCRL[10:9], the PCRL[8] - Read/Write mode.
'        In 10 bit mode, PCRL[15:11] assigned with "11110" - as per IIC Spec 2.1.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'        dAddr           IIC Address
'-----------------------------------------------------------------------------
'Returns:   None
'*****************************************************************************
Sub SetIICAddr(r As ProjectData, ModuleName As Variant, dAddr As Variant)
    Dim sReg As String
    Dim iBit As Integer
    
    sReg = ModuleName & "_PCRL_CTR"

   If (r.v(ModuleName & "_IIC_AMOD") = 0) Then           '7 bit Addr mode
        For iBit = 9 To 15                               'PCRL[15:9] - 7 bit Addr
         If (dAddr <> 0) Then                            'dAddr * 2 ^ 9
             r.v(sReg & iBit) = dAddr Mod 2
             If r.v(sReg & iBit) Then dAddr = dAddr - 1
             If dAddr = 1 Then dAddr = dAddr - 1
             dAddr = dAddr / 2
         Else
             r.v(sReg & iBit) = 0
         End If
        Next
   Else                                                  '10 bit Addr mode
        For iBit = 0 To 10                               'PCRL[0:7] - 8 bit & 'PCRL[9:10] - 2 MSBs
         If (dAddr <> 0 And iBit <> 8) Then              'PCRL[8] - R/W
             r.v(sReg & iBit) = dAddr Mod 2
             If r.v(sReg & iBit) Then dAddr = dAddr - 1
             If dAddr = 1 Then dAddr = dAddr - 1
             dAddr = dAddr / 2
         Else
             r.v(sReg & iBit) = 0
         End If
        Next
        For iBit = 11 To 15                              'PCRL[15:11]=11110; I2C Bus Spec
            r.v(sReg & iBit) = 1
            If iBit = 11 Then r.v(sReg & iBit) = 0
        Next
   End If

End Sub

'*****************************************************************************
'Description:
'        This function gets the address from sfr PCRL.It is called from
'        OnShowIICGeneral page Address control. The 7 bit Address is placed in
'        PCRL[15:9] bitfield and 10 bit address is placed in PCRL[7:0] and
'        2 MSBs in PCRL[10:9], the PCRL[8] - Read/Write mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   IIC 7/10 bit address
'*****************************************************************************
Function GetIICAddr(r As ProjectData, ModuleName As Variant) As String
    Dim sReg As String
    Dim iBit As Integer
    Dim dAddr As Double
    
    sReg = ModuleName & "_PCRL_CTR"
    dAddr = 0
    
    If (r.v(ModuleName & "_IIC_AMOD") = 0) Then
        For iBit = 9 To 15
            dAddr = dAddr + r.v(sReg & iBit) * 2 ^ (iBit - 9)
        Next iBit
        GetIICAddr = FormatTextOutput(dAddr, "H2")
    Else
        For iBit = 0 To 7
            dAddr = dAddr + r.v(sReg & iBit) * 2 ^ iBit
        Next iBit
        For iBit = 9 To 10
            dAddr = dAddr + r.v(sReg & iBit) * 2 ^ (iBit - 1)
        Next iBit
        GetIICAddr = FormatTextOutput(dAddr, "H3")
    End If
    
End Function

'*****************************************************************************
'Description:
'         This function updates the IIC BRG PDIV and STEP values.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           As Variant
'
'-----------------------------------------------------------------------------
'*****************************************************************************
Sub UpdateIICBaudrate(r As ProjectData, vIndex As Variant)
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim fPIN As Double

    sVarPre = Format$(vIndex)
    sRegPre = Format$(vIndex) & "_"
    
    'Default IIC BuadRate configuration
     r.v(sRegPre & "FDRL_DM") = 2          ' Fractional Divider
     r.v(sRegPre & "BRGL_PCTQ") = 1        ' PreDivider for CTQ
     r.v(sRegPre & "BRGL_DCTQ") = 9        ' Denominator for CTQ
     r.v(sRegPre & "BRGH_PDIV") = 49       ' Divider factor
     r.v(sRegPre & "PCRH_CTR17") = 0       ' Symbol Timing STIM
     If r.v(sVarPre & "_IIC_Baudrate") > 250000 Then
        r.v(sRegPre & "BRGL_DCTQ") = 24
        r.v(sRegPre & "PCRH_CTR17") = 1
     End If
    
     fPIN = GetfPIN(r, vIndex, "IIC")
     
     While (fPIN > (GetSystemClock(r) * 1000000))
        r.v(sRegPre & "BRGH_PDIV") = r.v(sRegPre & "BRGH_PDIV") / 2
        fPIN = GetfPIN(r, vIndex, "IIC")
     Wend

    r.v(sRegPre & "FDRL_STEP") = (fPIN * 1024) / (GetSystemClock(r) * 1000000)

End Sub


'*****************************************************************************
'Description:
'          This function calculates Real IIC Baudrate from the values of the
'          components of the formulae
'-----------------------------------------------------------------------------
'Parameters:
'      r                  reference to the Registers object
'      vIndex             As Variant
'-----------------------------------------------------------------------------
'Returns:
'      RealIICBaudrate    Real Baudrate that would be generated by the MC
'*****************************************************************************
Function RealIICBaudrate(r As ProjectData, vIndex As Variant) As Double
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"

  RealIICBaudrate = (GetSystemClock(r) * 1000000 * _
                     r.v(sRegPre & "FDRL_STEP")) / _
                    (1024 * _
                    (r.v(sRegPre & "BRGH_PDIV") + 1) * _
                    (r.v(sRegPre & "BRGL_PCTQ") + 1) * _
                    (r.v(sRegPre & "BRGL_DCTQ") + 1))

End Function


