hc32f4a0_gpio.c 22.5 KB
Newer Older
C
chengy4 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
/**
 *******************************************************************************
 * @file  hc32f4a0_gpio.c
 * @brief This file provides firmware functions to manage the General Purpose
 *        Input/Output(GPIO).
 @verbatim
   Change Logs:
   Date             Author          Notes
   2020-06-12       Zhangxl         First version
   2020-09-18       Zhangxl         Optimize GPIO_DeInit() API
 @endverbatim
 *******************************************************************************
 * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
 *
 * This software component is licensed by HDSC under BSD 3-Clause license
 * (the "License"); You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                    opensource.org/licenses/BSD-3-Clause
 *
 *******************************************************************************
 */

/*******************************************************************************
 * Include files
 ******************************************************************************/
#include "hc32f4a0_gpio.h"
#include "hc32f4a0_utility.h"

/**
 * @addtogroup HC32F4A0_DDL_Driver
 * @{
 */

/**
 * @defgroup DDL_GPIO GPIO
 * @brief GPIO Driver Library
 * @{
 */

#if (DDL_GPIO_ENABLE == DDL_ON)

/*******************************************************************************
 * Local type definitions ('typedef')
 ******************************************************************************/

/*******************************************************************************
 * Local pre-processor symbols/macros ('#define')
 ******************************************************************************/
/**
 * @defgroup GPIO_Local_Macros GPIO Local Macros
 * @{
 */
/**
 * @defgroup GPIO_Registers_Reset_Value GPIO Registers Reset Value
 * @{
 */
#define GPIO_PSPCR_RESET_VALUE          (0x001FU)
#define GPIO_PCCR_RESET_VALUE           (0x1000U)
#define GPIO_PINAER_RESET_VALUE         (0x0000U)
/**
 * @}
 */

/**
 * @defgroup GPIO_Check_Parameters_Validity GPIO Check Parameters Validity
 * @{
 */
/*! Parameter validity check for pin state. */
#define IS_GPIO_PIN_STATE(state)                                                \
(   ((state) == PIN_STATE_RESET)                ||                              \
    ((state) == PIN_STATE_SET))

/*! Parameter validity check for pin direction. */
#define IS_GPIO_DIR(dir)                                                        \
(   ((dir) == PIN_DIR_IN)                       ||                              \
    ((dir) == PIN_DIR_OUT))

/*! Parameter validity check for pin output type. */
#define IS_GPIO_OTYPE(otype)                                                    \
(   ((otype) == PIN_OTYPE_CMOS)                 ||                              \
    ((otype) == PIN_OTYPE_NMOS))

/*! Parameter validity check for pin driver capacity. */
#define IS_GPIO_PIN_DRV(drv)                                                    \
(   ((drv) == PIN_DRV_LOW)                      ||                              \
    ((drv) == PIN_DRV_MID)                      ||                              \
    ((drv) == PIN_DRV_HIGH))

/*! Parameter validity check for pin latch function. */
#define IS_GPIO_LATCH(latch)                                                    \
(   ((latch) == PIN_LATCH_OFF)                  ||                              \
    ((latch) == PIN_LATCH_ON))

/*! Parameter validity check for internal pull-up resistor. */
#define IS_GPIO_PIN_PU(pu)                                                      \
(   ((pu) == PIN_PU_OFF)                        ||                              \
    ((pu) == PIN_PU_ON))

/*! Parameter validity check for pin state invert. */
#define IS_GPIO_PIN_INVERT(invert)                                              \
(   ((invert) == PIN_INVERT_OFF)                ||                              \
    ((invert) == PIN_INVERT_ON))

/*! Parameter validity check for pin input type. */
#define IS_GPIO_ITYPE(itype)                                                    \
(   ((itype) == PIN_ITYPE_SMT)                  ||                              \
    ((itype) == PIN_ITYPE_CMOS))

/*! Parameter validity check for external interrupt function. */
#define IS_GPIO_EXINT(exint)                                                    \
(   ((exint) == PIN_EXINT_OFF)                  ||                              \
    ((exint) == PIN_EXINT_ON))

/*! Parameter validity check for pin attribute. */
#define IS_GPIO_ATTR(attr)                                                      \
(   ((attr) == PIN_ATTR_DIGITAL)                ||                              \
    ((attr) == PIN_ATTR_ANALOG))

/*! Parameter validity check for pin number. */
#define IS_GPIO_PIN(pin)    (((pin) & GPIO_PIN_MASK ) != 0x0000U)

/*! Parameter validity check for port source. */
#define IS_GPIO_PORT(port)                                                      \
(   ((port) != 0x00U)                           &&                              \
    (((port) | GPIO_PORT_MASK) == GPIO_PORT_MASK))

/*! Parameter validity check for port source. */
#define IS_GPIO_PORT_SOURCE(port)                                               \
(   ((port) == GPIO_PORT_A)                     ||                              \
    ((port) == GPIO_PORT_B)                     ||                              \
    ((port) == GPIO_PORT_C)                     ||                              \
    ((port) == GPIO_PORT_D)                     ||                              \
    ((port) == GPIO_PORT_E)                     ||                              \
    ((port) == GPIO_PORT_F)                     ||                              \
    ((port) == GPIO_PORT_G)                     ||                              \
    ((port) == GPIO_PORT_H)                     ||                              \
    ((port) == GPIO_PORT_I))

/*! Parameter validity check for pin function. */
#define IS_GPIO_FUNC(func)                                                      \
(   ((func) <= GPIO_FUNC_20)                    ||                              \
    (((func) >= GPIO_FUNC_32) && ((func) <= GPIO_FUNC_63)))

/*! Parameter validity check for debug pin definition. */
#define IS_GPIO_DEBUG_PORT(port)                                                \
(   ((port) != 0x00U)                           &&                              \
    (((port) | GPIO_PIN_DEBUG_JTAG) == GPIO_PIN_DEBUG_JTAG))

/*! Parameter validity check for pin sub-function setting. */
#define IS_GPIO_PIN_BFE(bfe)                                                    \
(   ((bfe) == PIN_SUBFUNC_ENABLE)               ||                              \
    ((bfe) == PIN_SUBFUNC_DISABLE))

/*! Parameter validity check for pin read wait cycle. */
#define IS_GPIO_READ_WAIT(wait)                                                 \
(   ((wait) == GPIO_READ_WAIT_0)                ||                              \
    ((wait) == GPIO_READ_WAIT_1)                ||                              \
    ((wait) == GPIO_READ_WAIT_2)                ||                              \
    ((wait) == GPIO_READ_WAIT_3)                ||                              \
    ((wait) == GPIO_READ_WAIT_4)                ||                              \
    ((wait) == GPIO_READ_WAIT_5)                ||                              \
    ((wait) == GPIO_READ_WAIT_6)                ||                              \
    ((wait) == GPIO_READ_WAIT_7))

/*  Check GPIO register lock status. */
#define IS_GPIO_UNLOCKED()      (GPIO_PWPR_WE == (M4_GPIO->PWPR & GPIO_PWPR_WE))

/**
 * @}
 */

/**
 * @}
 */

/*******************************************************************************
 * Global variable definitions (declared in header file with 'extern')
 ******************************************************************************/

/*******************************************************************************
 * Local function prototypes ('static')
 ******************************************************************************/

/*******************************************************************************
 * Local variable definitions ('static')
 ******************************************************************************/

/*******************************************************************************
 * Function implementation - global ('extern') and local ('static')
 ******************************************************************************/
/**
 * @defgroup GPIO_Global_Functions GPIO Global Functions
 * @{
 */

/**
 * @brief  Initialize GPIO.
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @param  [in] pstcGpioInit: Pointer to a stc_gpio_init_t structure that
 *                            contains configuration information.
 * @retval Ok: GPIO initialize successful
 *         ErrorInvalidParameter: NULL pointer
 */
en_result_t GPIO_Init(uint8_t u8Port, uint16_t u16Pin, const stc_gpio_init_t *pstcGpioInit)
{
    __IO uint16_t *PCRx;
    uint16_t u16PinPos;
    uint16_t u16PCRVal;
    en_result_t enRet = Ok;

    /* Check if pointer is NULL */
    if (NULL == pstcGpioInit)
    {
        enRet = ErrorInvalidParameter;
    }
    else
    {
        /* Parameter validity checking */
        DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
        DDL_ASSERT(IS_GPIO_PIN(u16Pin));
        DDL_ASSERT(IS_GPIO_PIN_STATE(pstcGpioInit->u16PinState));
        DDL_ASSERT(IS_GPIO_DIR(pstcGpioInit->u16PinDir));
        DDL_ASSERT(IS_GPIO_OTYPE(pstcGpioInit->u16PinOType));
        DDL_ASSERT(IS_GPIO_PIN_DRV(pstcGpioInit->u16PinDrv));
        DDL_ASSERT(IS_GPIO_LATCH(pstcGpioInit->u16Latch));
        DDL_ASSERT(IS_GPIO_PIN_PU(pstcGpioInit->u16PullUp));
        DDL_ASSERT(IS_GPIO_PIN_INVERT(pstcGpioInit->u16Invert));
        DDL_ASSERT(IS_GPIO_ITYPE(pstcGpioInit->u16PinIType));
        DDL_ASSERT(IS_GPIO_EXINT(pstcGpioInit->u16ExInt));
        DDL_ASSERT(IS_GPIO_UNLOCKED());

        for (u16PinPos = 0U; u16PinPos < 16U; u16PinPos++)
        {
            if ((u16Pin & (1UL<<u16PinPos)) != 0U)
            {
                PCRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PCRA0) +               \
                                  ((uint32_t)(u8Port) * 0x40UL) + u16PinPos * 4UL);

                u16PCRVal = pstcGpioInit->u16ExInt  | pstcGpioInit->u16PinIType |   \
                            pstcGpioInit->u16Invert | pstcGpioInit->u16PullUp   |   \
                            pstcGpioInit->u16Latch  | pstcGpioInit->u16PinDrv   |   \
                            pstcGpioInit->u16PinOType | pstcGpioInit->u16PinState | \
                            pstcGpioInit->u16PinDir | pstcGpioInit->u16PinAttr;
                WRITE_REG16(*PCRx, u16PCRVal);
            }
        }
    }
    return enRet;
}

/**
 * @brief  De-init GPIO register to default value
 * @param  None
 * @retval None
 */
void GPIO_DeInit(void)
{
    stc_gpio_init_t stcGpioInit;

    DDL_ASSERT(IS_GPIO_UNLOCKED());

    (void)GPIO_StructInit(&stcGpioInit);

    /* PORTA reset */
    (void)GPIO_Init(GPIO_PORT_A, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTB reset */
    (void)GPIO_Init(GPIO_PORT_B, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTC reset */
    (void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTD reset */
    (void)GPIO_Init(GPIO_PORT_D, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTE reset */
    (void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTF reset */
    (void)GPIO_Init(GPIO_PORT_F, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTG reset */
    (void)GPIO_Init(GPIO_PORT_G, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTH reset */
    (void)GPIO_Init(GPIO_PORT_H, GPIO_PIN_ALL, &stcGpioInit);
    /* PORTI reset */
    (void)GPIO_Init(GPIO_PORT_I, (GPIO_PIN_00 | GPIO_PIN_01 | GPIO_PIN_02 |   \
                            GPIO_PIN_03 | GPIO_PIN_04 | GPIO_PIN_05 |   \
                            GPIO_PIN_06 | GPIO_PIN_07 | GPIO_PIN_08 |   \
                            GPIO_PIN_09 | GPIO_PIN_10 | GPIO_PIN_11 |   \
                            GPIO_PIN_12 | GPIO_PIN_13), &stcGpioInit);
    /* PORT global register reset */
    WRITE_REG16(M4_GPIO->PSPCR, GPIO_PSPCR_RESET_VALUE);
    WRITE_REG16(M4_GPIO->PCCR, GPIO_PCCR_RESET_VALUE);
    WRITE_REG16(M4_GPIO->PINAER, GPIO_PINAER_RESET_VALUE);
}

/**
 * @brief  Initialize GPIO config structure. Fill each pstcGpioInit with default value
 * @param  [in] pstcGpioInit: Pointer to a stc_gpio_init_t structure that
 *                            contains configuration information.
 * @retval Ok: GPIO structure initialize successful
 *         ErrorInvalidParameter: NULL pointer
 */
en_result_t GPIO_StructInit(stc_gpio_init_t *pstcGpioInit)
{
    en_result_t enRet = Ok;
    /* Check if pointer is NULL */
    if (NULL == pstcGpioInit)
    {
        enRet = ErrorInvalidParameter;
    }
    else
    {
        /* Reset GPIO init structure parameters values */
        pstcGpioInit->u16PinState   = PIN_STATE_RESET;
        pstcGpioInit->u16PinDir     = PIN_DIR_IN;
        pstcGpioInit->u16PinOType   = PIN_OTYPE_CMOS;
        pstcGpioInit->u16PinDrv     = PIN_DRV_LOW;
        pstcGpioInit->u16Latch      = PIN_LATCH_OFF;
        pstcGpioInit->u16PullUp     = PIN_PU_OFF;
        pstcGpioInit->u16Invert     = PIN_INVERT_OFF;
        pstcGpioInit->u16PinIType   = PIN_ITYPE_SMT;
        pstcGpioInit->u16ExInt      = PIN_EXINT_OFF;
        pstcGpioInit->u16PinAttr    = PIN_ATTR_DIGITAL;
    }
    return enRet;
}

/**
 * @brief  GPIO debug port configure. Set debug pins to GPIO
 * @param  [in] u8DebugPort
 *   @arg  GPIO_PIN_SWDIO
 *   @arg  GPIO_PIN_SWCLK
 *   @arg  GPIO_PIN_SWO
 *   @arg  GPIO_PIN_DEBUG_SWD
 *   @arg  GPIO_PIN_TCK
 *   @arg  GPIO_PIN_TMS
 *   @arg  GPIO_PIN_TDO
 *   @arg  GPIO_PIN_TDI
 *   @arg  GPIO_PIN_TRST
 *   @arg  GPIO_PIN_DEBUG_JTAG
 * @param  [in] enNewState
 *   @arg  Enable: set to debug port (SWD/JTAG)
 *   @arg  Disable: set to GPIO
 * @retval None
 */
void GPIO_SetDebugPort(uint8_t u8DebugPort, en_functional_state_t enNewState)
{
    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_DEBUG_PORT(u8DebugPort));
    DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState));
    DDL_ASSERT(IS_GPIO_UNLOCKED());

    if (Enable == enNewState)
    {
        SET_REG16_BIT(M4_GPIO->PSPCR, ((uint16_t)u8DebugPort & GPIO_PSPCR_SPFE));
    }
    else
    {
        CLEAR_REG16_BIT(M4_GPIO->PSPCR, ((uint16_t)u8DebugPort & GPIO_PSPCR_SPFE));
    }
}

/**
 * @brief  Set specified Port Pin function , and turn ON/OFF its sub-function
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @param  [in] u8Func: GPIO_FUNC_x, x can be selected from GPIO function definitions
 * @param  [in] u16BFE: GPIO Sub-function enable setting
 *   @arg  PIN_SUBFUNC_ENABLE
 *   @arg  PIN_SUBFUNC_DISABLE
 * @retval None
 */
void GPIO_SetFunc(uint8_t u8Port, uint16_t u16Pin, uint8_t u8Func, uint16_t u16BFE)
{
    __IO uint16_t *PFSRx;
    uint8_t u8PinPos;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));
    DDL_ASSERT(IS_GPIO_FUNC(u8Func));
    DDL_ASSERT(IS_GPIO_PIN_BFE(u16BFE));
    DDL_ASSERT(IS_GPIO_UNLOCKED());

    for (u8PinPos = 0U; u8PinPos < 16U; u8PinPos++)
    {
        if ((u16Pin & (uint16_t)(1UL << u8PinPos)) != 0U)
        {
            PFSRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PFSRA0) + \
                                      (uint32_t)(u8Port * 0x40UL) + u8PinPos * 4UL);
            WRITE_REG16(*PFSRx, (u16BFE | (uint16_t)u8Func));
        }
    }
}

/**
 * @brief  Set the sub-function, it's a global configuration
 * @param  [in] u8Func: GPIO_FUNC_x, x can be selected from GPIO function definitions
 * @retval None
 */
void GPIO_SetSubFunc(uint8_t u8Func)
{
    DDL_ASSERT(IS_GPIO_FUNC(u8Func));
    DDL_ASSERT(IS_GPIO_UNLOCKED());

    MODIFY_REG16(M4_GPIO->PCCR, GPIO_PCCR_BFSEL, u8Func);
}

/**
 * @brief  Initialize GPIO.
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @param  [in] enNewState
 *   @arg  Enable: set specified pin output enable
 *   @arg  Disable: set specified pin output disable
 * @retval None
 */
void GPIO_OE(uint8_t u8Port, uint16_t u16Pin, en_functional_state_t enNewState)
{
    __IO uint16_t *POERx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));
    DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState));

    POERx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->POERA) + 0x10UL * u8Port);

    if (Enable == enNewState)
    {
        SET_REG16_BIT(*POERx, u16Pin);
    }
    else
    {
        CLEAR_REG16_BIT(*POERx, u16Pin);
    }
}

/**
 * @brief  GPIO read wait cycle configure.
 * @param  [in] u16ReadWait
 *   @arg  GPIO_READ_WAIT_0: ~ 50MHz
 *   @arg  GPIO_READ_WAIT_1: 50 ~ 100MHz
 *   @arg  GPIO_READ_WAIT_2: 100 ~ 150MHz
 *   @arg  GPIO_READ_WAIT_3: 150 ~ 200MHz
 *   @arg  GPIO_READ_WAIT_4: 200 ~ 250MHz
 *   @arg  GPIO_READ_WAIT_5: 250MHz above
 *   @arg  GPIO_READ_WAIT_6: 250MHz above
 *   @arg  GPIO_READ_WAIT_7: 250MHz above
 * @retval None
 */
void GPIO_SetReadWaitCycle(uint16_t u16ReadWait)
{
    DDL_ASSERT(IS_GPIO_READ_WAIT(u16ReadWait));
    DDL_ASSERT(IS_GPIO_UNLOCKED());

    MODIFY_REG16(M4_GPIO->PCCR, GPIO_PCCR_RDWT, u16ReadWait);
}

/**
 * @brief  GPIO input MOS always ON configure.
 * @param  [in] u16PortIdx: Port index
 *   @arg  GPIO_PORTA_IDX
 *   @arg  GPIO_PORTB_IDX
 *   @arg  GPIO_PORTC_IDX
 *   @arg  GPIO_PORTD_IDX
 *   @arg  GPIO_PORTE_IDX
 *   @arg  GPIO_PORTF_IDX
 *   @arg  GPIO_PORTG_IDX
 *   @arg  GPIO_PORTH_IDX
 *   @arg  GPIO_PORTI_IDX
 *   @arg  GPIO_PORT_ALL
 * @param  [in] enNewState
 *   @arg  Enable: set input MOS always ON
 *   @arg  Disable: set input MOS turns on while read operation
 * @retval None
 */
void GPIO_InMOSCmd(uint16_t u16PortIdx, en_functional_state_t enNewState)
{
    DDL_ASSERT(IS_GPIO_PORT(u16PortIdx));
    DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState));
    DDL_ASSERT(IS_GPIO_UNLOCKED());

    if (Enable == enNewState)
    {
        SET_REG16_BIT(M4_GPIO->PINAER, u16PortIdx);
    }
    else
    {
        CLEAR_REG16_BIT(M4_GPIO->PINAER, u16PortIdx);
    }
}

/**
 * @brief  Read specified GPIO input data port pins
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @retval Specified GPIO port pin input value
 */
en_pin_state_t GPIO_ReadInputPins(uint8_t u8Port, uint16_t u16Pin)
{
    __IO uint16_t *PIDRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));

    PIDRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PIDRA) + 0x10UL * u8Port);

    return ((READ_REG16(*PIDRx) & (u16Pin)) != 0U) ? Pin_Set : Pin_Reset;
}

/**
 * @brief  Read specified GPIO input data port
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @retval Specified GPIO port input value
 */
uint16_t GPIO_ReadInputPort(uint8_t u8Port)
{
    __IO uint16_t *PIDRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));

    PIDRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PIDRA) + 0x10UL * u8Port);

    return READ_REG16(*PIDRx);
}

/**
 * @brief  Read specified GPIO output data port pins
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @retval Specified GPIO port pin output value
 */
en_pin_state_t GPIO_ReadOutputPins(uint8_t u8Port, uint16_t u16Pin)
{
    __IO uint16_t *PODRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));

    PODRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PODRA) + 0x10UL * u8Port);

    return ((*PODRx & (u16Pin)) != 0U) ? Pin_Set : Pin_Reset;
}

/**
 * @brief  Read specified GPIO output data port
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @retval Specified GPIO port output value
 */
uint16_t GPIO_ReadOutputPort(uint8_t u8Port)
{
    __IO uint16_t *PODRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));

    PODRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PODRA) + 0x10UL * u8Port);

    return READ_REG16(*PODRx);
}

/**
 * @brief  Set specified GPIO output data port pins
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @retval None
 */
void GPIO_SetPins(uint8_t u8Port, uint16_t u16Pin)
{
    __IO uint16_t *POSRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));

    POSRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->POSRA) + 0x10UL * u8Port);
    SET_REG16_BIT(*POSRx, u16Pin);
}

/**
 * @brief  Reset specified GPIO output data port pins
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @retval None
 */
void GPIO_ResetPins(uint8_t u8Port, uint16_t u16Pin)
{
    __IO uint16_t *PORRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));

    PORRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PORRA) + 0x10UL * u8Port);
    SET_REG16_BIT(*PORRx, u16Pin);
}

/**
 * @brief  Write specified GPIO data port
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16PortVal: Pin output value
 * @retval None
 */
void GPIO_WritePort(uint8_t u8Port, uint16_t u16PortVal)
{
    __IO uint16_t *PODRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));

    PODRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->PODRA) + 0x10UL * u8Port);
    WRITE_REG16(*PODRx, u16PortVal);

}

/**
 * @brief  Toggle specified GPIO output data port pin
 * @param  [in] u8Port: GPIO_PORT_x, x can be (A~I) to select the GPIO peripheral
 * @param  [in] u16Pin: GPIO_PIN_x, x can be (00~15) to select the PIN index
 * @retval None
 */
void GPIO_TogglePins(uint8_t u8Port, uint16_t u16Pin)
{
    __IO uint16_t *POTRx;

    /* Parameter validity checking */
    DDL_ASSERT(IS_GPIO_PORT_SOURCE(u8Port));
    DDL_ASSERT(IS_GPIO_PIN(u16Pin));

    POTRx = (__IO uint16_t *)((uint32_t)(&M4_GPIO->POTRA) + 0x10UL * u8Port);
    SET_REG16_BIT(*POTRx, u16Pin);
}

/**
 * @}
 */

#endif /* DDL_GPIO_ENABLE */

/**
 * @}
 */

/**
* @}
*/

/******************************************************************************
 * EOF (not truncated)
 *****************************************************************************/