/*!
* @file     Port.h
*
* @version  1.0.0
*
* @brief    Data Type Definition File for the PORT Module 
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef PORT_H
#define PORT_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "Mcal.h"
#include "StdRegMacros.h"
#include "Port_Cfg.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup PORT_Driver
  @{
*/

/** @defgroup PORT_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define PORT_H_VENDOR_ID                       0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PORT_H_AR_RELEASE_MAJOR_VERSION        0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PORT_H_AR_RELEASE_MINOR_VERSION        0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PORT_H_AR_RELEASE_REVISION_VERSION     0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PORT_H_SW_MAJOR_VERSION                0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PORT_H_SW_MINOR_VERSION                0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PORT_H_SW_PATCH_VERSION                0x00U

/*******************************************************************************
                                ERROR CODES
*******************************************************************************/
/* Invalid Port Pin ID requested */
#define PORT_E_PARAM_PIN                    ((uint8)0x0AU)

/* Port Pin Direction not configured as changeable */
#define PORT_E_DIRECTION_UNCHANGEABLE       ((uint8)0x0BU)

/* API Port_Init() service called with wrong parameter */
#define PORT_E_INIT_FAILED                  ((uint8)0x0CU)

/* API Port_SetPinMode() service called when mode is invalid */
#define PORT_E_PARAM_INVALID_MODE           ((uint8)0x0DU)

/* API Port_SetPinMode() service called when mode is unchangeable */
#define PORT_E_MODE_UNCHANGEABLE            ((uint8)0x0EU)

/* API service called without module initialization */
#define PORT_E_UNINIT                       ((uint8)0x0FU)

/* API service called with NULL Pointer Parameter */
#define PORT_E_PARAM_POINTER                ((uint8)0x10U)

/* Debug IO is configured. */
#define PORT_E_DEBUG_IO_CFG                 ((uint8)0x11U)

/*******************************************************************************
                            API Service ID List
*******************************************************************************/
/* Instance ID of port driver */
#define PORT_INSTANCE_ID                    ((uint8)0x00U)

/* API service ID for PORT Init function */
#define PORT_INIT_SID                       ((uint8)0x00U)

/* API service ID for PORT set pin direction function */
#define PORT_SETPINDIRECTION_SID            ((uint8)0x01U)

/* API service ID for PORT refresh pin direction function */
#define PORT_REFRESHPINDIRECTION_SID        ((uint8)0x02U)

/* API service ID for PORT get version info function */
#define PORT_GETVERSIONINFO_SID             ((uint8)0x03U)

/* API service ID for PORT set pin mode function */
#define PORT_SETPINMODE_SID                 ((uint8)0x04U)

/**@} end of group PORT_Macros */
/*******************************************************************************
                            ENUM DEFINITION
*******************************************************************************/
/** @defgroup PORT_Enumerations
  @{
*/

/**
 * @brief   Configuration Mode enumeration
 */
typedef enum
{
    GPIO_MODE_IN  = 0x00,        //!< GPIO Input Mode
    GPIO_MODE_OUT = 0x01,        //!< GPIO Output Mode
    GPIO_MODE_AF0 = 0x02,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF1 = 0x12,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF2 = 0x22,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF3 = 0x32,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF4 = 0x42,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF5 = 0x52,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF6 = 0x62,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF7 = 0x72,        //!< GPIO Alternate function Mode
    GPIO_MODE_AF_RETAIN = 0xF2,  //!< GPIO Alternate function Mode
    GPIO_MODE_AN  = 0x03         //!< GPIO Analog In/Out Mode
} Port_PinModeType;

/**
 * @brief   Port pin orientation
 */
typedef enum
{
    PORT_PIN_IN  = 0,
    PORT_PIN_OUT = 1
} Port_PinDirectionType;



typedef enum
{
    PORT_PIN_LEVEL_LOW  = 0,
    PORT_PIN_LEVEL_HIGH = 1
} Port_pinLevelType;


/**
 * @brief   Output type enumeration
 */
typedef enum
{
    GPIO_OUT_TYPE_PP = 0x00,      //!< General purpose output push-pull
    GPIO_OUT_TYPE_OD = 0x01       //!< General purpose output Open-drain
} Port_OutputModeType;

/**
 * @brief   Configuration Pull-Up Pull-Down enumeration
 */
typedef enum
{
    GPIO_PUPD_NO = 0x00,          //!< GPIO no pull mode
    GPIO_PUPD_PU = 0x01,          //!< GPIO pull-up mode
    GPIO_PUPD_PD = 0x02           //!< GPIO pull-down mode
} Port_PullModeType;

/**
 * @brief   Lock pin enumeration
 */
typedef enum
{
    PIN_NO_LOCK  = 0x00,        //!< The configuration of GPIO can be modified.
    PIN_YES_LOCK = 0x01         //!< The configuration of GPIO can not be modified.
} Port_LockType;

/**
 * @brief    Definition of the GPIO pins
 */
typedef enum
{
    GPIO_PIN_0   = ((uint16)0x00),    //!< GPIO pin 0 selected
    GPIO_PIN_1   = ((uint16)0x01),    //!< GPIO pin 1 selected
    GPIO_PIN_2   = ((uint16)0x02),    //!< GPIO pin 2 selected
    GPIO_PIN_3   = ((uint16)0x03),    //!< GPIO pin 3 selected
    GPIO_PIN_4   = ((uint16)0x04),    //!< GPIO pin 4 selected
    GPIO_PIN_5   = ((uint16)0x05),    //!< GPIO pin 5 selected
    GPIO_PIN_6   = ((uint16)0x06),    //!< GPIO pin 6 selected
    GPIO_PIN_7   = ((uint16)0x07),    //!< GPIO pin 7 selected
    GPIO_PIN_8   = ((uint16)0x08),    //!< GPIO pin 8 selected
    GPIO_PIN_9   = ((uint16)0x09),    //!< GPIO pin 9 selected
    GPIO_PIN_10  = ((uint16)0x0A),    //!< GPIO pin 10 selected
    GPIO_PIN_11  = ((uint16)0x0B),    //!< GPIO pin 11 selected
    GPIO_PIN_12  = ((uint16)0x0C),    //!< GPIO pin 12 selected
    GPIO_PIN_13  = ((uint16)0x0D),    //!< GPIO pin 13 selected
    GPIO_PIN_14  = ((uint16)0x0E),    //!< GPIO pin 14 selected
    GPIO_PIN_15  = ((uint16)0x0F)
} Port_PortPinIdType;

typedef enum
{
    PORT_GPIO_A = 0,
    PORT_GPIO_B = 1,
    PORT_GPIO_C = 2,
    PORT_GPIO_D = 3,
    PORT_GPIO_F = 5
} Port_PortIdType;


typedef enum
{
    LOW_SPEED_LOW_DRIVING = 0,
    MEDIUM_SPEED_LOW_DRIVING = 1,
    LOW_SPEED_HIGH_DRIVING = 2,
    HIGH_SPPED_HIGH_DRIVING = 3
} Port_PinSpeedAbilityType;

/**@} end of group PORT_Enumerations */
/*******************************************************************************
                             STRUCT DEFINITION
*******************************************************************************/
/** @defgroup PORT_Typedef
  @{
*/

/* Data type of port pin symbol name */
typedef uint32 Port_PinType;

/**@} end of group PORT_Typedef */

/** @defgroup PORT_Structure
  @{
*/

/** The data structure including the initialization data of the pin mode. */
typedef struct
{
    VAR(Port_PinModeType, AUTOMATIC) portPinMode;
    VAR(Port_OutputModeType, AUTOMATIC) outputMode;
    VAR(Port_PullModeType, AUTOMATIC) pullValue;
    VAR(Port_pinLevelType, AUTOMATIC) defaultLevel;
    VAR(Port_PinSpeedAbilityType, AUTOMATIC) speedSelect;
} Port_PinModeConfigType;

/** The data structure including the initialization data of the PORT Driver. */
typedef struct
{
    VAR(Port_PinType, AUTOMATIC) pinId;
    VAR(Port_PortIdType, AUTOMATIC) portId;
    VAR(Port_PortPinIdType, AUTOMATIC) portPinId;
    VAR(Port_LockType, AUTOMATIC) pinDirLock;
    VAR(Port_LockType, AUTOMATIC) pinModeLock;
    VAR(Port_PinModeConfigType, AUTOMATIC) pinMode;
} Port_PinConfigType;


/** The data structure including the initialization data of the PORT Driver. */
typedef struct
{
    uint8 pinMaxValue;
    Port_PinConfigType pinNum[PORT_MAX_CONFIG_PIN_COUNT];
} Port_ConfigType;

/**@} end of group PORT_Structure */
/*******************************************************************************
                             GLOBAL DECLARATION
*******************************************************************************/
#define PORT_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Port_MemMap.h"

/** @defgroup PORT_Variable
  @{
*/

extern CONST(Port_ConfigType, PORT_CONST) g_portConfig;

/**@} end of group PORT_Variable */

#define PORT_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Port_MemMap.h"

/*******************************************************************************
                            FUNCTION DECLARATION
*******************************************************************************/
#define PORT_START_SEC_CODE
#include "Port_MemMap.h"

/** @defgroup PORT_Fuctions
  @{
*/

FUNC(void, MCU_CODE) Port_Init(const Port_ConfigType* ConfigPtr);

#if (PORT_SET_PINDIRECTION_API == STD_ON)
FUNC(void, MCU_CODE) Port_SetPinDirection(Port_PinType Pin, Port_PinDirectionType Direction);
#endif
FUNC(void, MCU_CODE) Port_RefreshPortDirection(void);

#if (PORT_VERINFO_API == STD_ON)
FUNC(void, MCU_CODE) Port_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, MCU_APPL_DATA) VersionInfo);
#endif

#if (PORT_SET_PINMODE_API == STD_ON)
FUNC(void, MCU_CODE) Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode);
#endif

/**@} end of group PORT_Fuctions */

#define PORT_STOP_SEC_CODE
#include "Port_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif /* PORT_TYPES_H */

/**@} end of group PORT_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
