/**
 * @file    Port_Types.h
 * @version
 *
 * @brief   AUTOSAR Port module interface
 * @details API implementation for PORT driver
 *
 * @addtogroup PORT_MODULE
 * @{
 */
/*==================================================================================================
 *   Project              : YTMicro AUTOSAR 4.4.0 MCAL
 *   Platform             : ARM
 *   Peripheral           : Port
 *   Dependencies         : none
 *
 *   Autosar Version      : V4.4.0
 *   Autosar Revision     : ASR_REL_4_4_REV_0000
 *   Autosar Conf.Variant :
 *   SW Version           : V0.8.0
 *
 *
 *   (c) Copyright 2020-2026 Yuntu Microelectronics co.,ltd.
 *   All Rights Reserved.
==================================================================================================*/
#ifndef PORT_TYPES_H
#define PORT_TYPES_H
#ifdef __cplusplus
extern "C"
{
#endif
/*==================================================================================================
                                              INCLUDE FILES
==================================================================================================*/
#include "Port_Cfg.h"
/*==================================================================================================
                                      HEADER FILE VERSION INFORMATION
==================================================================================================*/
#define PORT_TYPES_VENDOR_ID                      (180)
#define PORT_TYPES_AR_RELEASE_MAJOR_VERSION       (4)
#define PORT_TYPES_AR_RELEASE_MINOR_VERSION       (4)
#define PORT_TYPES_AR_RELEASE_REVISION_VERSION    (0)
#define PORT_TYPES_SW_MAJOR_VERSION               (0)
#define PORT_TYPES_SW_MINOR_VERSION               (8)
#define PORT_TYPES_SW_PATCH_VERSION               (0)
/*==================================================================================================
                                        FILE VERSION CHECKS
==================================================================================================*/
/* Check if source file and PORT configuration header file are of the same vendor */
#if (PORT_TYPES_VENDOR_ID != PORT_VENDOR_ID_CFG)
#error "Port_Types.h and Port_Cfg.h have different vendor ids"
#endif
/* Check if source file and PORT configuration header file are of the same Autosar version */
#if ((PORT_TYPES_AR_RELEASE_MAJOR_VERSION != PORT_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (PORT_TYPES_AR_RELEASE_MINOR_VERSION != PORT_AR_RELEASE_MINOR_VERSION_CFG) || \
     (PORT_TYPES_AR_RELEASE_REVISION_VERSION != PORT_AR_RELEASE_REVISION_VERSION_CFG))
#error "AutoSar Version Numbers of Port_Types.h and Port_Cfg.h are different"
#endif
/* Check if source file and PORT configuration header file are of the same software version */
#if ((PORT_TYPES_SW_MAJOR_VERSION != PORT_SW_MAJOR_VERSION_CFG) || \
     (PORT_TYPES_SW_MINOR_VERSION != PORT_SW_MINOR_VERSION_CFG) || \
     (PORT_TYPES_SW_PATCH_VERSION != PORT_SW_PATCH_VERSION_CFG))
#error "Software Version Numbers of Port_Types.h and Port_Cfg.h are different"
#endif
/*==================================================================================================
                                                DEFINES AND MACROS
==================================================================================================*/
/**
 * @brief Total number of hardware
 * @note Strong relationship to the hardware
 */
#define PORT_TOTAL_NUMBER       (5U)
/**
 * @brief Total number of hardware one port pins
 * @note Strong relationship to the hardware
 */
#define PORT_PIN_TOTAL_NUMBER   (32U)
/** @brief Port Alternate 0 Mode */
#define PORT_PIN_MODE_ANA              ((Port_PinModeType)0)
/** @brief Port GPIO Mode */
#define PORT_PIN_MODE_GPIO             ((Port_PinModeType)1)
/** @brief Port Alternate 2 Mode */
#define PORT_PIN_MODE_ALT2             ((Port_PinModeType)2)
/** @brief Port Alternate 3 Mode */
#define PORT_PIN_MODE_ALT3             ((Port_PinModeType)3)
/** @brief Port Alternate 4 Mode */
#define PORT_PIN_MODE_ALT4             ((Port_PinModeType)4)
/** @brief Port Alternate 5 Mode */
#define PORT_PIN_MODE_ALT5             ((Port_PinModeType)5)
/** @brief Port Alternate 6 Mode */
#define PORT_PIN_MODE_ALT6             ((Port_PinModeType)6)
/** @brief Port Alternate 7 Mode */
#define PORT_PIN_MODE_ALT7             ((Port_PinModeType)7)
#if defined (CPU_YTM32B1HA0)
/** @brief Port Alternate 8 Mode */
#define PORT_PIN_MODE_ALT8             ((Port_PinModeType)8)
/** @brief Port Alternate 9 Mode */
#define PORT_PIN_MODE_ALT9             ((Port_PinModeType)9)
/** @brief Port Alternate 10 Mode */
#define PORT_PIN_MODE_ALT10            ((Port_PinModeType)10)
/** @brief Port Alternate 11 Mode */
#define PORT_PIN_MODE_ALT11            ((Port_PinModeType)11)
/** @brief Port Alternate 12 Mode */
#define PORT_PIN_MODE_ALT12            ((Port_PinModeType)12)
/** @brief Port Alternate 13 Mode */
#define PORT_PIN_MODE_ALT13            ((Port_PinModeType)13)
/** @brief Port Alternate 14 Mode */
#define PORT_PIN_MODE_ALT14            ((Port_PinModeType)14)
/** @brief Port Alternate 15 Mode */
#define PORT_PIN_MODE_ALT15            ((Port_PinModeType)15)
#endif

#define Port_IsCorrectPortPinId(Port, Pin) (((Port) < PORT_TOTAL_NUMBER) && ((Pin) < PORT_PIN_TOTAL_NUMBER))
/*==================================================================================================
                                                EXTERNAL CONSTANTS
==================================================================================================*/
/*==================================================================================================
                                                ENUMS
==================================================================================================*/
/**
 * @brief          Possible directions of a port pin
 * @autosar        SWS_Port_00230
 */
typedef enum
{
    PORT_PIN_IN = 0,         /**< Sets port pin as input */
    PORT_PIN_OUT = 1,        /**< Sets port pin as output */
} Port_PinDirectionType;

/**
 * @brief          Port pin level.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_LEVEL_LOW = 0U,        /**< Port Pin Level is low */
    PORT_PIN_LEVEL_HIGH = 1U,       /**< Port Pin Level is high */
    PORT_PIN_LEVEL_NOTCHANGED = 2U, /**< Port Pin Level is not changed */
} Port_PinLevelType;

/**
 * @brief          The pin mode is changeable on a port pin during runtime.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_MODE_NOT_CHANGEABLE = 0U, /**< Port Pin mode unchangeable */
    PORT_PIN_MODE_CHANGEABLE = 1U,     /**< Port Pin mode changeable */
} Port_PinModeChangeableType;

/**
 * @brief          The pin direction is changeable on a port pin during runtime.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_DIRECTION_UNCHANGEABLE = 0U, /**< Port Pin direction unchangeable */
    PORT_PIN_DIRECTION_CHANGEABLE = 1U,   /**< Port Pin direction changeable */
} Port_PinDirectionChangeableType;

/**
 * @brief          The port pin pull state.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_NO_PULL = 0U,   /**< Port Pin no pull */
    PORT_PIN_PULLDOWN = 1U,  /**< Port Pin pull down */
    PORT_PIN_PULLUP = 2U,    /**< Port Pin pull up */
} Port_PinPullConfigType;

#if (PORT_HAS_SLEW_RATE == STD_ON)
/**
 * @brief          The port pin slew rate.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_FAST_SLEW_RATE = 0U, /**< Port Pin in fast slew rate */
    PORT_PIN_SLOW_SLEW_RATE = 1U, /**< Port Pin in low slew rate */
} Port_PinSlewRateType;
#endif

/**
 * @brief          The port pin drive strength.
 * @autosar        N/A
 */
typedef enum
{
    PORT_PIN_LOW_DRIVE_STRENGTH = 0U,  /**< Port Pin in fast slew rate */
    PORT_PIN_HIGH_DRIVE_STRENGTH = 1U, /**< Port Pin in low slew rate */
} Port_PinDriveStrengthType;


/*==================================================================================================
 *                                             TYPEDEF
==================================================================================================*/
/**
 * @brief          Different port pin modes.
 * @autosar        SWS_Port_00231
 */
typedef uint8 Port_PinModeType;

/**
 * @brief          Data type for hardware pin identifier within a port. Represents the physical pin number (0-7 for 8-bit ports, etc.)
 * @autosar        N/A
 */
typedef uint8 Port_HwPinType;

/**
 * @brief          Data type for the symbolic name of a port pin. Shall cover all available port pins. The type should be chosen for the specific MCU platform (best performance).
 * @autosar        SWS_Port_00229
 */
typedef uint16 Port_PinType;

/**
 * @brief          Data type for hardware port identifier. Represents the physical port module (e.g., PORTA, PORTB, etc.)
 * @autosar        N/A
 */
typedef uint8 Port_HwPortType;


/**
 * @brief          Structure type for port pin configuration
 * @autosar        N/A
 */
typedef struct
{
    Port_HwPinType HwPinId;                                 /**< Hardware pin identifier */
    Port_PinDirectionType Direction;                        /**< Initial direction of the pin (input/output) */
    Port_PinDirectionChangeableType IsDirectionChangeable;  /**< Whether pin direction can be changed at runtime */
    Port_PinLevelType InitLevel;                            /**< Initial output level of the pin */
    Port_PinModeType InitMode;                              /**< Initial mode/function of the pin */
    Port_PinModeChangeableType IsModeChangeable;            /**< Whether pin mode can be changed at runtime */
    Port_PinPullConfigType PullConfig;                      /**< Pull-up/pull-down configuration */
    Port_PinDriveStrengthType DriveStrength;                /**< Drive strength setting */
#if (PORT_HAS_SLEW_RATE == STD_ON)
    Port_PinSlewRateType SlewRate;                          /**< Slew rate control setting */
#endif
    boolean PassiveFilter;                                  /**< Passive filter enable/disable for digital input */
#if (PORT_HAS_DIGITAL_FILTER == STD_ON)
    boolean DigitalFilter;                                  /**< Digital filter enable/disable for digital input */
    uint8   DigitalFilterWidth;                             /**< Digital filter width setting for digital input */
#endif
#if (PORT_HAS_OUT_CMP == STD_ON)
    boolean OutputCompare;                                  /**< Output compare feature setting (only MD24) */
#endif
    boolean InvertEnable;                                   /**< Input inversion enable/disable for digital input */
} Port_PinConfigType;

/**
 * @brief          Structure type for port group configuration
 * @autosar        N/A
 */
typedef struct
{
    uint8 NumberOfPortPins;                     /**< Valid pin numbers of port */
    Port_HwPortType HwPortId;                   /**< Port ID */
    const Port_PinConfigType *PortPinConfigPtr; /**< Port pins config pointer */
} Port_GroupConfigType;


/**
 * @brief          Type of the external data structure containing the initialization data for this module.
 * @autosar        SWS_Port_00228
 */
typedef struct
{
    uint8 NumberOfGroup;                             /**< Valid pin numbers of port */
    const Port_GroupConfigType *PortGroupConfigPtr;  /**< Port pins config pointer */
} Port_ConfigType;


#ifdef __cplusplus
}
#endif

#endif /* PORT_TYPES_H */

/** @} */

