Attribute VB_Name = "Module1"
'#Uses "..\classes\Port.cls"
'#Uses "..\classes\PortPin.cls"
Option Explicit
'*****************************************************************************
' Module:
'        IO
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        0.1  Sunil          04-10-04     initial version
'
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function is called by the main module in order to reset or update
'        the project variables and register contents of this peripheral
'-----------------------------------------------------------------------------
'Parameters:
'        r                      reference to the project data variables
'        vIndex                 a parameter
'        lngUpdateDescriptor    identification of the update context
'                  0          = initialization for a new project
'                  1, 2, 3... = value that identifies which project settings have
'                               been changed (e.g. CPU-Type, CPU-Clock etc.)
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UpdateProjectData(r As ProjectData, vIndex As Variant, lngUpdateDescriptor As Long) As Boolean
    On Error GoTo UpdateProjectDataError

    Dim iPort As Integer
    Dim iFirstPin As Integer
    Dim iLastPin As Integer
    Dim iPin As Integer
    Dim sPin As String
    Dim cPorts As DAvECollection
    Dim cp As PortPin
    Dim oPort As Port

    UpdateProjectData = False
    
    Set cPorts = ObjectCollection("PORTS")
    Set cp = ObjectCollection("PORTPINS")
    
    If (lngUpdateDescriptor = 0) Then
        ' Project Variables
        r.v("IO_CFile") = "IO.C"
        r.v("IO_HFile") = "IO.H"
        r.v("IO_NAME_Init") = "IO_vInit"
        r.v("IO_NAME_ReadPin") = "IO_ubReadPin"
        r.v("IO_NAME_ReadPort") = "IO_ubReadPort"
        r.v("IO_NAME_ResetPin") = "IO_vResetPin"
        r.v("IO_NAME_SetInput") = "IO_vSetInput"
        r.v("IO_NAME_SetOutput") = "IO_vSetOutput"
        r.v("IO_NAME_SetPin") = "IO_vSetPin"
        r.v("IO_NAME_TogglePin") = "IO_vTogglePin"
        r.v("IO_NAME_WritePort") = "IO_vWritePort"
        r.v("IO_Notes") = ""
        r.v("IO_USE_Init") = 0
        r.v("IO_USE_ReadPin") = 0
        r.v("IO_USE_ReadPort") = 0
        r.v("IO_USE_ResetPin") = 0
        r.v("IO_USE_SetInput") = 0
        r.v("IO_USE_SetOutput") = 0
        r.v("IO_USE_SetPin") = 0
        r.v("IO_USE_TogglePin") = 0
        r.v("IO_USE_WritePort") = 0
          
        For Each oPort In cPorts
            iPort = oPort.PortNumber
            r.v("P" & iPort & "_Notes") = ""
            
            iFirstPin = oPort.FirstPin
            iLastPin = oPort.LastPin
            For iPin = iFirstPin To iLastPin
                sPin = "P" & iPort & "_" & iPin
                If cp.Use(sPin) Then
                    r.v("P" & iPort & "_NAME_" & sPin) = sPin   ' set default pin name
                End If
            Next iPin
        Next

    End If
    
    ' Some "project settings" may be changed independently from the settings
    ' of the peripheral modules. Therefore the IO module has to solve any
    ' possible conflicts with the project settings, i.e. pins must be released
    ' if they are used for the external bus.

    UpdateProjectData = True
    Exit Function

UpdateProjectDataError:
    Exit Function
End Function


