/*!
 * @file        bmp561_gpio.h
 *
 * @brief       This file contains all the functions prototypes for the GPIO firmware library
 *
 * @version     V1.0.0
 *
 * @date        2025-01-01
 *
 * @attention
 *
 *  Copyright (C) 2025 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful 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 SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

/* Define to prevent recursive inclusion */
#ifndef __BMP561_GPIO_H
#define __BMP561_GPIO_H

/* Includes */
#include "bmp561.h"

#ifdef __cplusplus
  extern "C" {
#endif

/** @addtogroup Peripherals_Library Standard Peripheral Library
  @{
*/

/** @addtogroup GPIO_Driver GPIO Driver
  @{
*/

/** @addtogroup GPIO_Enumerations Enumerations
  @{
*/

/**
 * @brief    Definition of the GPIO pins
 */
typedef enum
{
    GPIO_PIN_0   = 0x00,    /*!< GPIO0 */
    GPIO_PIN_1   = 0x01,    /*!< GPIO1 */
    GPIO_PIN_2   = 0x02,    /*!< GPIO2 */
    GPIO_PIN_3   = 0x03,    /*!< GPIO3 */
    GPIO_PIN_4   = 0x04,    /*!< GPIO4 */
    GPIO_PIN_5   = 0x05,    /*!< GPIO5 */
    GPIO_PIN_6   = 0x06,    /*!< GPIO6 */
    GPIO_PIN_7   = 0x07,    /*!< GPIO7 */
    GPIO_PIN_8   = 0x08,    /*!< GPIO8 */
    GPIO_PIN_9   = 0x09,    /*!< GPIO9 */
} GPIO_PIN_T;

/**
 * @brief    GPIO mode
 */
typedef enum
{
    GPIO_MODE_AN  = 0,    /*!< Analog mode */
    GPIO_MODE_IN  = 1,    /*!< Input mode */
    GPIO_MODE_OUT = 2,    /*!< Output mode */
    GPIO_MODE_AF  = 3,    /*!< Alternate function mode */
} GPIO_MODE_T;

/**
 * @brief    GPIO output type
 */
typedef enum
{
    GPIO_OT_PP = 0,    /*!< PP mode */
    GPIO_OT_OD = 1     /*!< OD mode */
} GPIO_OT_T;

/**
 * @brief    GPIO polarity
 */
typedef enum
{
    GPIO_POL_UP   = 0,    /*!< Pull up */
    GPIO_POL_DOWN = 1     /*!< Pull down */
} GPIO_POL_T;

/**
 * @brief    GPIO output speed
 */
typedef enum
{
    GPIO_OS_HIGH = 0,    /*!< High speed */
    GPIO_OS_LOW  = 1     /*!< Low speed */
} GPIO_OS_T;

/**
 * @brief    GPIO drive force
 */
typedef enum
{
    GPIO_DS_HIGH = 0,    /*!< High drive force */
    GPIO_DS_LOW  = 1     /*!< Low drive force */
} GPIO_DS_T;

/**
 * @brief    GPIO reuse
 */
typedef enum
{
    GPIO_REUSE_AF0 = 0,    /*!< Alternate function 0 */
    GPIO_REUSE_AF1 = 1,    /*!< Alternate function 1 */
    GPIO_REUSE_AF2 = 2,    /*!< Alternate function 2 */
    GPIO_REUSE_AF3 = 3     /*!< Alternate function 3 */
} GPIO_REUSE_T;

/**@} end of group GPIO_Enumerations */

/** @addtogroup GPIO_Macros Macros
  @{
*/

/** GPIO mode select */
#define GPIO_MODE    ((uint32_t)0x00000003)

/** GPIO pull up/down configure */
#define GPIO_PUS     ((uint32_t)0x00000002)
#define GPIO_PUE     ((uint32_t)0x00000001)

/** GPIO output type configure */
#define GPIO_OT      ((uint32_t)0x00000001)

/** GPIO output speed configure */
#define GPIO_OS      ((uint32_t)0x00000001)

/** GPIO drive speed configure */
#define GPIO_DS      ((uint32_t)0x00000001)

/** GPIO alternate function configure */
#define GPIO_AF      ((uint32_t)0x00000003)

/**@} end of group GPIO_Macros */

/** @addtogroup GPIO_Structure Data Structure
  @{
*/

/**
 * @brief   GPIO Config structure definition
 */
typedef struct
{
    GPIO_PIN_T  pin;         /*!< GPIO pin */
    GPIO_MODE_T mode;        /*!< GPIO mode */
    GPIO_OS_T   speed;       /*!< Output speed */
    GPIO_OT_T   type;        /*!< Output type */
    uint8_t     pullEn;	     /*!< Enable pull, can be ENABLE or DISABLE. */
    GPIO_POL_T  polarity;    /*!< GPIO polarity */
    GPIO_DS_T   drive;       /*!< GPIO drive force */
} GPIO_Config_T;

/**@} end of group GPIO_Structure */

/** @addtogroup GPIO_Functions Functions
  @{
*/

/* GPIO common configuration */
void GPIO_Reset(void);
void GPIO_Config(GPIO_Config_T* gpioConfig);
void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig);
void GPIO_ConfigMode(GPIO_PIN_T pin, GPIO_MODE_T mode);
void GPIO_EnablePull(GPIO_PIN_T pin);
void GPIO_DisablePull(GPIO_PIN_T pin);
void GPIO_ConfigPull(GPIO_PIN_T pin, GPIO_POL_T polarity);
void GPIO_ConfigOutputType(GPIO_PIN_T pin, GPIO_OT_T type);
void GPIO_ConfigSpeedMode(GPIO_PIN_T pin, GPIO_OS_T speed);
void GPIO_ConfigDriveForce(GPIO_PIN_T pin, GPIO_DS_T drive);

/* Read */
uint16_t GPIO_ReadBit(GPIO_PIN_T pin);
uint16_t GPIO_ReadPort(void);

/* Write */
void GPIO_SetBit(GPIO_PIN_T pin);
void GPIO_ResetBit(GPIO_PIN_T pin);
void GPIO_WritePort(uint16_t portVal);

/* GPIO reuse */
void GPIO_ConfigPinReuse(GPIO_PIN_T pin, GPIO_REUSE_T reuse);

/**@} end of group GPIO_Functions */
/**@} end of group GPIO_Driver */
/**@} end of group Peripherals_Library */

#ifdef __cplusplus
}
#endif

#endif /* __BMP561_GPIO_H */
