/*
 * exo_ahw_al_spi_to_uart_common.h
 *
 *  Created on: May 15, 2023
 *      Author: Invcuser_63
 */

#ifndef DRIVERS_EXO_HAL_DRIVER_FW_EXO_AHW_AL_DRIVER_API_EXO_AHW_AL_COMMON_SPI_TO_UART_INC_EXO_AHW_AL_SPI_TO_UART_COMMON_H_
#define DRIVERS_EXO_HAL_DRIVER_FW_EXO_AHW_AL_DRIVER_API_EXO_AHW_AL_COMMON_SPI_TO_UART_INC_EXO_AHW_AL_SPI_TO_UART_COMMON_H_

#include <stdint.h>
#include "exo_io_al_common.h"
#include "exo_hal_common.h"
#include "exo_ahw_al_common.h"
#include "max14830.h"



#define AHAL_UART_CONV_CH0 0x00 //Channel 0
#define AHAL_UART_CONV_CH1 0x01 //Channel 1
#define AHAL_UART_CONV_CH2 0x02 //Channel 2
#define AHAL_UART_CONV_CH3 0x03 //Channel 3

typedef void (*rx_cb_fptr_t)(void);

/*
 * @brief MAX14830 control block structure definition
 */
typedef struct
{
	ahw_al_gen_info ahw_gen_info;      						/*!< IO interface handle pointer   	*/
	uint8_t *rcv0_ptr;                                      /*!< receive pointer of port 0      */
	uint8_t *rcv1_ptr;                                      /*!< receive pointer of port 1      */
	uint8_t *rcv2_ptr;                                      /*!< receive pointer of port 2      */
	uint8_t *rcv3_ptr;										/*!< receive pointer of port 3      */

	//ioal_intf_gen_info intf_gen_info; 					/*!< Hold general information of interface */

}s_ahw_max14830_hdle;

/*
 * @brief MAX14830 configuration structure definition
 */
typedef struct
{
	uint32_t  baudrate;                                     /*!< baudrate      */
	uint8_t  stop_bit;                                      /*!< stop bit      */
	uint8_t  wrd_len;                                       /*!< word length   */
	uint8_t parity_bit;                                     /*!< parity bit    */
	uint8_t chnl_id;                                        /*!< channel id    */
}s_ahw_max14830_init_cfg;

/*
 * @brief Interface id enumeration
 */
typedef enum
{
	AHW_MAX14830_SPI_INTF = 0,                  ///< SPI interface
	AHW_MAX14830_I2C_INTF,                      ///< I2C interface
	AHW_MAX14830_MAX_INTF
}e_ahw_max14830_intf_id;

/**
 * @brief This function initialize the control block memory and do basic configurations
 * @param[in]  hdle - AHAL instance pointer of MAX14830
 * @param[in]  ahw_id - AHW instance ID
 * @retval hal_ret_sts - returns the success or error code
 */
hal_ret_sts ahw_al_uart_conv_init(s_ahw_max14830_hdle *hdle,ahw_inst_id_t ahw_id);

/**port configurations control block memory and do basic configurations
 * @param[in]  ahw_id - Hardware instance id
 * @param[in]  init_cfg - structure handle for port configurations
 * @retval hal_ret_sts - returns the success or error code
 */
hal_ret_sts ahw_al_uart_conv_port_init(uint32_t ahw_id,s_ahw_max14830_init_cfg *init_cfg);

/**
 * @brief This function transmit the data
 * @param[in]  ahw_id - Hardware instance id
 * @param[in]  port - indicates the UART port
 * @param[in]  tx_buff - pointer of a buffer
 * @param[in]  tx_len - length of the buffer
 * @retval hal_ret_sts - returns the success or error code
 */
hal_ret_sts ahw_al_uart_conv_transmit(uint32_t ahw_id,uint8_t port,uint8_t* tx_buff,uint16_t tx_len);

/**
 * @brief This function receive the data
 * @param[in]  ahw_id - Hardware instance id
 * @param[in]  port - indicates the UART port
 * @param[in]  rx_len - length of the buffer
 * @param[in] callback_func - callback function
 * @retval hal_ret_sts - returns the success or error code
 */
hal_ret_sts ahw_al_uart_conv_receive(uint32_t ahw_id,uint8_t port,uint16_t rx_len, rx_cb_fptr_t callback_func,uint8_t* recieve_ptr);

/*
 * @brief This function self test the max14830
 * @param[in] hdle - AHAL instance pointer of MAX14830
 */
hal_ret_sts ahw_al_uart_conv_self_test(uint32_t ahw_id);

#endif /* DRIVERS_EXO_HAL_DRIVER_FW_EXO_AHW_AL_DRIVER_API_EXO_AHW_AL_COMMON_SPI_TO_UART_INC_EXO_AHW_AL_SPI_TO_UART_COMMON_H_ */
