'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\ParameterClass.cls
'#Uses "..\classes\Port.cls
Option Explicit
'*****************************************************************************
' @Doc
' @Module        IO.INC
'-----------------------------------------------------------------------------
' @Controllers   RaiderB
'
' @Description   This module contains all functions that are used in the 
'                IO dialog script and in the IO codegenerator script.
'
'-----------------------------------------------------------------------------
' @History       Date           Author     Desription
' 1.0            02.02.00       ste        final version
'
'*****************************************************************************


'*****************************************************************************
' @Constants
'*****************************************************************************


'*****************************************************************************
' @Function descriptions
'*****************************************************************************

'*****************************************************************************
'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 
'        "DUMMY_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 RefreshFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next 

  RefreshFunctionDescriptions = False

  Dim sDescription As String
  Dim sReturnValue As String
  Dim s As String
  Dim cPorts As DAvECollection
  Dim Port As Port
  Dim sIndex As String
  Dim sPrefix As String

  sIndex = "IO" ' & vIndex
  sPrefix = sIndex & "_"

  RefreshFunctionDescriptions = False

  Set cPorts = ObjectCollection("PORTS")


  ' 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 IO_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sIndex)
  sReturnValue = "None" 
  If (Not func.AddFunction(sIndex & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_ReadPin
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro returns the status of the chosen portpin." & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "Status of the chosen portpin"
  If (Not func.AddFunction("IO_NAME_ReadPin", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be read"
    If (Not func.AddParameter("IO_NAME_ReadPin_Par1", "PinName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_SetPin
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro sets the chosen portpin to '1'." & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_SetPin", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be set to '1'"
    If (Not func.AddParameter("IO_NAME_SetPin_Par1", "PinName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_ResetPin
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro sets the chosen portpin to '0'. " & vbCrLf & _
                 "Note: " & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_ResetPin", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be set to '0'"
    If (Not func.AddParameter("IO_NAME_ResetPin_Par1", "PinName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_TogglePin
  '------------------------------------------------------------------------------------------------
  sDescription = "This marco toggles the chosen portpin. " & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_TogglePin", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be toggled"
    If (Not func.AddParameter("IO_NAME_TogglePin_Par1", "PinName", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_SetPinIn
  '------------------------------------------------------------------------------------------------
  sDescription = "The chosen portpin is configured as input." & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_SetPinIn", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be set to input"
    If (Not func.AddParameter("IO_NAME_SetPinIn_Par1", "PinName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_SetPinOut
  '------------------------------------------------------------------------------------------------
  sDescription = "The chosen portpin is configured as output." & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "See the 'Defines for the parameter PinName' " & _
                 "section in this header file for the available " & _
                 "definitions for the parameter PinName."

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_SetPinOut", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Pin to be set to output"
    If (Not func.AddParameter("IO_NAME_SetPinOut_Par1", "PinName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_ReadPort
  '------------------------------------------------------------------------------------------------
  s = ""
  For Each Port In cPorts
    s = s & "P" & Port.PortNumber & ", "
  Next Port
  sDescription = "This macro returns the value of the selected port. If a " & _
                 "port has less than 16 pins, the unused bits are " & _
                 "set to 0 in the return value" & vbCrLf & _
                 "The following definitions for PortName are available:" & vbCrLf & s

  sReturnValue = "Value of the port"
  If (Not func.AddFunction("IO_NAME_ReadPort", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Port to be read"
    If (Not func.AddParameter("IO_NAME_ReadPort_Par1", "PortName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_WritePort
  '------------------------------------------------------------------------------------------------
  sDescription = "The forwarded data is written to the selected port. If a " & _
                 "port has less than 16 pins, the bits not used are ignored " & _
                 "in the parameter value." & vbCrLf & _
                 "The following definitions for PortName are available:" & vbCrLf & s

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_WritePort", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Port to be altered"
    If (Not func.AddParameter("IO_NAME_WritePort_Par1", "PortName", "", sDescription)) Then Exit Function
    sDescription = "Value to be written to the chosen port"
    If (Not func.AddParameter("IO_NAME_WritePort_Par2", "uwData", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_SetPortIn
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro makes it possible to reconfigure the selected " & _
                 "port. The parameter usMask determines which individual " & _
                 "port pins are to be used as inputs. Every bit position in " & _
                 "the parameter usMask corresponds to a port pin."  & vbCrLf & _
                 "The following definitions for PortName are available:"  & vbCrLf & _
                 s & vbCrLf & _
                 "Example:" & vbCrLf & _
                 r.v("IO_NAME_SetPortIn") & "(P0,0x0204);  // sets P0.9 and P0.2 to input"

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_SetPortIn", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Port to be configured"
    If (Not func.AddParameter("IO_NAME_SetPortIn_Par1", "PortName", "", sDescription)) Then Exit Function
    sDescription = "Mask for port pins to be configured"
    If (Not func.AddParameter("IO_NAME_SetPortIn_Par2", "uwMask", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for IO_NAME_SetPortOut
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro makes it possible to reconfigure the selected " & _
                 "port. The parameter usMask determines which individual " & _
                 "port pins are to be used as outputs. Every bit position in " & _
                 "the parameter usMask corresponds to a port pin."  & vbCrLf & _
                 "The following definitions for PortName are available:"  & vbCrLf & _
                 s & vbCrLf & _
                 "Example:" & vbCrLf & _
                 r.v("IO_NAME_SetPortOut") & "(P0,0x0204);  // sets P0.9 and P0.2 to output"

  sReturnValue = "None"
  If (Not func.AddFunction("IO_NAME_SetPortOut", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Port to be configured"
    If (Not func.AddParameter("IO_NAME_SetPortOut_Par1", "PortName", "", sDescription)) Then Exit Function
    sDescription = "Mask for port pins to be configured"
    If (Not func.AddParameter("IO_NAME_SetPortOut_Par2", "uwMask", "", sDescription)) Then Exit Function

 	If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function

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

  RefreshParameterDescriptions = False

  Dim sDescription As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sParaName As String
  Dim i As Integer

  sVarPre = "IO" & vIndex
  sRegPre = sVarPre & "_"


  ' for each parameter of this module the property AddParameter must be called
  '
  ' AddParameter(sParameterName As String, sParameterDescription As String) As Boolean
  '
  ' sParameterName         | String | parameter name as key (use the name of the variable 
  '                                   for the parameter name e.g. SSC_PARA_MODE) 
  ' sParameterDescription  | String | description of the parameter

 	
 	If (Not para.Sort) Then Exit Function

  RefreshParameterDescriptions = True
End Function



'*****************************************************************************
' @Functions
'*****************************************************************************

