/**
 * @file analog_io.h
 * @date 2021-01-08
 *
 * NOTE:
 * This file is generated by DAVE. Any manual modification done to this file will be lost when the code is regenerated.
 *
 * @cond
 ***********************************************************************************************************************
 * ANALOG_IO v4.0.12 - The ANALOG_IO APP is used to select port pin as a Analog input/output.
 *
 * Copyright (c) 2015-2020, Infineon Technologies AG
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
 * following conditions are met:
 *
 *   Redistributions of source code must retain the above copyright notice, this list of conditions and the  following
 *   disclaimer.
 *
 *   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
 *   following disclaimer in the documentation and/or other materials provided with the distribution.
 *
 *   Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
 *   products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes
 * with Infineon Technologies AG (dave@infineon.com).
 ***********************************************************************************************************************
 *
 * Change History
 * --------------
 *
 * 2015-02-16
 *     - Initial version
 *
 * 2015-06-20
 *     - Version check added for XMCLib dependency.
 *
 * 2015-12-10:
 *     - Added Digital input support for analog port pin<br>
 *     - Added Hardware pull control support for analog port pin<br>
 *     - Added ANALOG_IO_GetInput API for reading the port pin<br>
 *
 * 2016-07-08:
 *     - Fixed incorrect case for an included header.<br>
 *
 * 2021-01-08:
 *     - Modified check for minimum XMCLib version
 *
 * @endcond
 *
 */

/***********************************************************************************************************************
 * HEADER FILES
 **********************************************************************************************************************/

#ifndef ANALOG_IO_H
#define ANALOG_IO_H

#include "xmc_gpio.h"
#include "DAVE_Common.h"
#include "analog_io_conf.h"

/***********************************************************************************************************************
 * MACROS
 **********************************************************************************************************************/
#define ANALOG_IO_XMC_LIB_MAJOR_VERSION 2
#define ANALOG_IO_XMC_LIB_MINOR_VERSION 0
#define ANALOG_IO_XMC_LIB_PATCH_VERSION 0

#if !((XMC_LIB_MAJOR_VERSION > ANALOG_IO_XMC_LIB_MAJOR_VERSION) ||\
      ((XMC_LIB_MAJOR_VERSION == ANALOG_IO_XMC_LIB_MAJOR_VERSION) && (XMC_LIB_MINOR_VERSION > ANALOG_IO_XMC_LIB_MINOR_VERSION)) ||\
      ((XMC_LIB_MAJOR_VERSION == ANALOG_IO_XMC_LIB_MAJOR_VERSION) && (XMC_LIB_MINOR_VERSION == ANALOG_IO_XMC_LIB_MINOR_VERSION) && (XMC_LIB_PATCH_VERSION >= ANALOG_IO_XMC_LIB_PATCH_VERSION)))
#error "ANALOG_IO requires XMC Peripheral Library v2.0.0 or higher"
#endif

 /**********************************************************************************************************************
 * ENUMS
 **********************************************************************************************************************/

/**
* @ingroup ANALOG_IO_enumerations
* @{
*/

/**
* @brief Initialization status of ANALOG_IO APP.
*/
typedef enum ANALOG_IO_STATUS
{
  ANALOG_IO_STATUS_OK      = 0U, /**< Status = 0, APP Initialization OK */
  ANALOG_IO_STATUS_FAILURE = 1U  /**< Status = 1, APP Initialization Failed */
} ANALOG_IO_STATUS_t;

/**
* @brief Initialization state of ANALOG_IO APP.
*/

typedef enum ANALOG_IO_STATE
{
  ANALOG_IO_STATE_NOT_INITIALIZED = 0, /**< State = 0, APP not even initialized once */
  ANALOG_IO_STATE_INITIALIZED          /**< State = 1, APP successfully initialized */
} ANALOG_IO_STATE_t;


/**
* @}
*/

/**********************************************************************************************************************
 * DATA STRUCTURES
 **********************************************************************************************************************/
/**
* @ingroup ANALOG_IO_datastructures
* @{
*/
/**
 * @brief Function pointer prototype declaration used for initialization function
 */
typedef void (*ANALOG_IO_CONFIG_PTR_t)(void);

/**
* @brief Initialization data structure of ANALOG_IO APP
*/
typedef struct ANALOG_IO
{
  ANALOG_IO_CONFIG_PTR_t config_ptr; /**< Pointer to ANALOG_IO instance specific initialization function */
  ANALOG_IO_STATE_t *state;          /**< APP initialization state */
  XMC_GPIO_PORT_t *port;             /**< Port number used */
  uint8_t pin;                       /**< Pin number used */
} ANALOG_IO_t;


/**
* @}
*/

/***********************************************************************************************************************
 * LOCAL ROUTINES
 **********************************************************************************************************************/

 /**********************************************************************************************************************
 * API IMPLEMENTATION
 **********************************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @ingroup ANALOG_IO_apidoc
 * @{
 */

/**
 * @brief Get ANALOG_IO APP version
 * @return DAVE_APP_VERSION_t APP version information (major, minor and patch number)
 *
 * \par<b>Description: </b><br>
 * The function can be used to check application software compatibility with a
 * specific version of the APP.
 *
 * Example Usage:
 *
 * @code
 * #include "DAVE.h"
 *
 * int main(void)
 * {
 *   DAVE_STATUS_t init_status;
 *   DAVE_APP_VERSION_t version;
 *
 *   // Initialize ANALOG_IO APP:
 *   // ANALOG_IO_Init() is called from within DAVE_Init().
 *   init_status = DAVE_Init();
 *
 *   if(init_status == DAVE_STATUS_SUCCESS)
 *   {
 *     version = ANALOG_IO_GetAppVersion();
 *     if (version.major != 4U) {
 *     // Probably, not the right version.
 *     }
 *   }
 *
 *     // More code here
 *     while(1) {
 *
 *     }
 *     return (1);
 *  }
 * @endcode<BR>
*/


 DAVE_APP_VERSION_t ANALOG_IO_GetAppVersion(void);

 /**
 *
 * @brief Function to initialize the port pin as per UI settings.
 * @param handler Pointer pointing to APP data structure. Refer @ref ANALOG_IO_t for details.
 * @return ANALOG_IO_STATUS_t ANALOG_IO APP status. Refer @ref ANALOG_IO_STATUS_t structure for details.
 *
 * \par<b>Description:</b><br>
 * This function initializes GPIO port registers IOCR,HWSEL to configure pin direction and driver strength/hysteresis.
 *
 * \par<b>Related APIs:</b><BR>
 * None
 *
 * Example Usage:
 * @code
 * #include "DAVE.h"//Declarations from DAVE Code Generation (includes SFR declaration)
 * int main(void)
 * {
 *   DAVE_STATUS_t status;
 *   status = DAVE_Init();  //(DAVE_STATUS_t)ANALOG_IO_Init(&ANALOG_IO_0) is called within DAVE_Init()
 *   if(status == DAVE_STATUS_SUCCESS)
 *   {
 *     XMC_DEBUG("DAVE Apps initialization success\n");
 *   }
 *   else
 *   {
 *     XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
 *     while(1U)
 *     {
 *     }
 *   }
 *   //Placeholder for user application code. The while loop below can be replaced with user application code.
 *   while(1U)
 *   {
 *   }
 *   return 1U;
 *  }
 *  @endcode
 */

 ANALOG_IO_STATUS_t ANALOG_IO_Init(const ANALOG_IO_t *const handle);


 /**
 * @brief Function to read input level of port pin.
 * @param handler Pointer pointing to APP data structure. Refer @ref ANALOG_IO_t for details.
 * @return uint32_t input logic level. Range:0-1
 *
 * \par<b>Description:</b><br>
 * This function reads the Pn_IN register and returns the current logical value at the GPIO pin.
 *
 * \par<b>Related APIs:</b><BR>
 *  None
 *
 * Example Usage:
 * @code
 * #include "DAVE.h"//Declarations from DAVE Code Generation (includes SFR declaration)
 * int main(void)
 * {
 *   DAVE_STATUS_t status;
 *   uint32_t pin_status;
 *   status = DAVE_Init();   // (DAVE_STATUS_t)ANALOG_IO_Init(&ANALOG_IO_0) is called within DAVE_Init()
 *   if(status == DAVE_STATUS_SUCCESS)
 *   {
 *     XMC_DEBUG("DAVE Apps initialization success\n");
 *   }
 *   else
 *   {
 *     XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
 *     while(1U)
 *     {
 *     }
 *   }
 *   //Placeholder for user application code. The while loop below can be replaced with user application code.
 *   while(1U)
 *   {
 *     pin_status = ANALOG_IO_GetInput(&ANALOG_IO_0);
 *     if(pin_status == 1)
 *     {
 *       // Add application code here
 *     }
 *     else
 *     {
 *       // Add application code here
 *     }
 *   }
 *   return (1);
 * }
 *  @endcode
 */

 __STATIC_INLINE uint32_t ANALOG_IO_GetInput(const ANALOG_IO_t *const handler)
 {
   XMC_ASSERT("ANALOG_IO_GetInput: handler null pointer", handler != NULL);
   return XMC_GPIO_GetInput(handler->port, handler->pin);
 }

 /**
  *@}
  */
#ifdef __cplusplus
}
#endif

/* Include APP extern file */
#include "analog_io_extern.h"


#endif /* ANALOG_IO_H */
