/*
 * @file exo_io_al_stm32f7xx_qspi.h
 *
 * @brief This file contains structures,enumerations
 * and function declaration for QSPI interface
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _EXI_IO_AL_STM32F7XX_QSPI_H_
#define _EXI_IO_AL_STM32F7XX_QSPI_H_

#include "exo_types.h"
#include "exo_io_al_qspi_common.h"
#include "exo_hal_common.h"
#include "exo_io_al_common.h"

/**
 * @brief  VDP layer QSPI callback ID
 */
typedef enum
{
  IOHAL_STM32_QSPI_ERROR_CB_ID          = 0x00U,  /*!< QSPI Error Callback ID            */
  IOHAL_STM32_QSPI_ABORT_CB_ID          = 0x01U,  /*!< QSPI Abort Callback ID            */
  IOHAL_STM32_QSPI_FIFO_THRESHOLD_CB_ID = 0x02U,  /*!< QSPI FIFO Threshold Callback ID   */
  IOHAL_STM32_QSPI_CMD_CPLT_CB_ID       = 0x03U,  /*!< QSPI Command Complete Callback ID */
  IOHAL_STM32_QSPI_RX_CPLT_CB_ID        = 0x04U,  /*!< QSPI Rx Complete Callback ID      */
  IOHAL_STM32_QSPI_TX_CPLT_CB_ID        = 0x05U,  /*!< QSPI Tx Complete Callback ID      */
  IOHAL_STM32_QSPI_RX_HALF_CPLT_CB_ID   = 0x06U,  /*!< QSPI Rx Half Complete Callback ID */
  IOHAL_STM32_QSPI_TX_HALF_CPLT_CB_ID   = 0x07U,  /*!< QSPI Tx Half Complete Callback ID */
  IOHAL_STM32_QSPI_STATUS_MATCH_CB_ID   = 0x08U,  /*!< QSPI Status Match Callback ID     */
  IOHAL_STM32_QSPI_TIMEOUT_CB_ID        = 0x09U,  /*!< QSPI Timeout Callback ID          */
  IOHAL_STM32_QSPI_MSP_INIT_CB_ID       = 0x0AU,  /*!< QSPI MspInit Callback ID          */
  IOHAL_STM32_QSPI_MSP_DEINIT_CB_ID     = 0x0B0   /*!< QSPI MspDeInit Callback ID        */
}iohal_stm32_qspi_cbid;


/* Prototype Definitions */


/**
 * @brief This function initialize the control block memory and do basic configurations of QSPI
 * @param[in] ioal_qspi - ioal_spi pointer to a ioal_qspi_hdle structure that
 * 					contains the configuration information for QSPI
 * @retval HAL status
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_init     (ioal_qspi_hdle *ioal_hspi);


/**
 * @brief This function de initialize the control block memory and do basic configurations of QSPI
 * @param[in] ioal_qspi - ioal_spi pointer to a ioal_qspi_hdle structure that
 * 					contains the configuration information for QSPI
 * @retval HAL status
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_deInit   (ioal_qspi_hdle *ioal_hspi);


/**
 * @brief This function set the command configuration
 * @param[in] ioal_qspi - ioal_spi pointer to a ioal_qspi_hdle structure that
 * 					contains the configuration information for QSPI
 * @param cmd : structure that contains the command configuration information
 * @param Timeout : Timeout duration
 * @note   This function is used only in Indirect Read or Write Modes
 * @retval HAL status
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_command      (ioal_qspi_hdle *ioal_hqspi, ioal_qspi_CommandTypeDef *cmd, uint32 timeout);


/**
 * @brief This function transmit the data in QSPI interface with blocking mode
 * @param[in] ioal_qspi - ioal_qspi pointer to a ioal_qspi_hdle structure that
 * 					contains the configuration information for QSPI
 * @param[in] pdata - pointer to a data
 * @param[in] size -  size of the data
 * @param[in] timeout - timeout duration
 * @retval HAL status
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_transmit     (ioal_qspi_hdle *ioal_hqspi, uint8 *pData, uint32 timeout);


/**
 * @brief This function transmit the data in QSPI interface with interrupt mode
 * @param[in] ioal_qspi - ioal_qspi pointer to a ioal_qspi_hdle structure that
 * 					contains the configuration information for QSPI
 * @param[in] pdata - pointer to a data
 * @param[in] size -  size of the data
 * @retval HAL status
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_receive      (ioal_qspi_hdle *ioal_hqspi, uint8 *pData, uint32 timeout);


/**
 * @brief This function enable the auto polling mode
 * @param[in] ioal_spi - ioal_spi pointer to a ioal_spi_hdle structure that
 * 					contains the configuration information for SPI
 * @param  cmd : structure that contains the command configuration information.
 * @param  cfg : structure that contains the polling configuration information.
 * @param  Timeout : Timeout duration
 * @retval HAL status
 *
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_auto_polling   (ioal_qspi_hdle *ioal_hqspi, ioal_qspi_CommandTypeDef *cmd, ioal_qspi_AutoPollingTypeDef *cfg, uint32 timeout);


/**
 * @brief This function enable memory mapped mode
 * @param[in] ioal_spi - ioal_spi pointer to a ioal_spi_hdle structure that
 * 					contains the configuration information for SPI
 * @param  cmd : structure that contains the command configuration information.
 * @param  cfg : structure that contains the polling configuration information.
 * @retval HAL status
 *
 */
hal_ret_sts     io_hal_stm32f7xx_qspi_memory_mapped(ioal_qspi_hdle *ioal_hqspi, ioal_qspi_CommandTypeDef *cmd, ioal_qspi_MemoryMappedTypeDef *cfg);


/**
 * @brief This function register the callback event
 * @param[in] ioal_qspi - ioal_qspi pointer to a ioal_spi_hdle structure that
 * 					contains the configuration information for QSPI
 * @param[in] cbid - ID of the callback event
 * @retval HAL status
 */
hal_ret_sts io_hal_stm32f7xx_qspi_reg_cb(ioal_qspi_hdle *ioal_hqspi, iohal_stm32_qspi_cbid cbid);


/*
 * Mapping wrapper with macro
 */
#define io_hal_wrpr_qspi_init						io_hal_stm32f7xx_qspi_init
#define io_hal_wrpr_qspi_deInit						io_hal_stm32f7xx_qspi_deInit
#define io_hal_wrpr_qspi_command					io_hal_stm32f7xx_qspi_command
#define io_hal_wrpr_qspi_transmit					io_hal_stm32f7xx_qspi_transmit
#define io_hal_wrpr_qspi_receive					io_hal_stm32f7xx_qspi_receive
#define io_hal_wrpr_qspi_auto_polling				io_hal_stm32f7xx_qspi_auto_polling
#define io_hal_wrpr_qspi_memory_mapped				io_hal_stm32f7xx_qspi_memory_mapped
#define io_hal_wrpr_qspi_reg_cb						io_hal_stm32f7xx_qspi_reg_cb

#endif /* _EXI_IO_AL_STM32F7XX_QSPI_H_ */
