/*!
 * @file        bmp561_i2c.h
 *
 * @brief       This file contains all the functions prototypes for the I2C 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_I2C_H
#define __BMP561_I2C_H

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

#ifdef __cplusplus
  extern "C" {
#endif

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

/** @addtogroup I2C_Driver I2C Driver
  @{
*/

/** @addtogroup I2C_Enumerations Enumerations
  @{
*/

/**
 * @brief    I2C filter
 */
typedef enum
{
    I2C_FILTER_BYPASS = 0x00,    /*!< Bypass */
    I2C_FILTER_1PCLK  = 0x01,    /*!< 1 pclk */
    I2C_FILTER_2PCLK  = 0x02,    /*!< 2 pclk */
    I2C_FILTER_3PCLK  = 0x03     /*!< 3 pclk */
} I2C_FILTER_T;

/**
 * @brief    I2C interrupt source
 */
typedef enum
{
    I2C_INT_STA    = 0x0001,    /*!< Receive START signal interrupt */
    I2C_INT_STOP   = 0x0002,    /*!< Receive STOP signal interrupt */
    I2C_INT_ADR    = 0x0004,    /*!< I2C address match or already send I2C address interrupt */
    I2C_INT_GCS    = 0x0008,    /*!< Recieve broadcast interrupt */
    I2C_INT_ARBL   = 0x0010,    /*!< Lose arbitration interrupt */
    I2C_INT_NACK   = 0x0020,    /*!< Recieve NACK interrupt */
    I2C_INT_TOF    = 0x0040,    /*!< Time out interrupt */
    I2C_INT_BUSERR = 0x0080,    /*!< Bus error(unexpected start or stop signal occurs) */
    I2C_INT_OVR    = 0x0100,    /*!< Overwrite or overread interrupt */
    I2C_INT_RXFE   = 0x0200,    /*!< RX FIFO empty interrupt */
    I2C_INT_RXFH   = 0x0400,    /*!< RX FIFO half empty interrupt */
    I2C_INT_RXFF   = 0x0800,    /*!< RX FIFO full interrupt */
    I2C_INT_TXFE   = 0x1000,    /*!< TX FIFO empty interrupt */
    I2C_INT_TXFH   = 0x2000,    /*!< TX FIFO half empty interrupt */
    I2C_INT_TXFF   = 0x4000     /*!< TX FIFO full interrupt */
} I2C_INT_T;

/**
 * @brief    I2C flag
 */
typedef enum
{
    I2C_FLAG_STA    = 0x00000001,    /*!< Master mode already sent START signal or slave mode recieved START signal flag */
    I2C_FLAG_STOP   = 0x00000002,    /*!< Slave mode recieved STOP signal flag */
    I2C_FLAG_ADR    = 0x00000004,    /*!< Master mode already sent address or slave mode address match flag */
    I2C_FLAG_GCS    = 0x00000008,    /*!< Recieve broadcast signal flag */
    I2C_FLAG_ARBL   = 0x00000010,    /*!< Lose arbitration flag */
    I2C_FLAG_NACK   = 0x00000020,    /*!< Recieve NACK flag */
    I2C_FLAG_TOF    = 0x00000040,    /*!< Timeout flag */
    I2C_FLAG_BUSERR = 0x00000080,    /*!< Bus error(unexpected start or stop signal occurs) flag */
    I2C_FLAG_OVR    = 0x00000100,    /*!< Overwrite or overread flag */
    I2C_FLAG_RXFE   = 0x00000200,    /*!< RX FIFO empty flag */
    I2C_FLAG_RXFH   = 0x00000400,    /*!< RX FIFO half full flag */
    I2C_FLAG_RXFF   = 0x00000800,    /*!< RX FIFO full flag */
    I2C_FLAG_TXFE   = 0x00001000,    /*!< TX FIFO empty flag */
    I2C_FLAG_TXFH   = 0x00002000,    /*!< TX FIFO half full flag */
    I2C_FLAG_TXFF   = 0x00004000,    /*!< TX FIFO full flag */
    I2C_FLAG_MS     = 0x00008000,    /*!< Mode flag, master mode "1" / slave mode "0" */
    I2C_FLAG_RD_WR  = 0x00010000,    /*!< Read/Write flag, read "1" / write "0" */
    I2C_FLAG_BUSY   = 0x00020000     /*!< Bus busy flag */
} I2C_FLAG_T;

/**@} end of group I2C_Enumerations */

/** @addtogroup I2C_Functions Functions
  @{
*/

/* I2C common configuration */
void I2C_Enable(void);
void I2C_Disable(void);
void I2C_ClearTXFIFO(void);
void I2C_EnableBroadcast(void);
void I2C_DisableBroadcast(void);
void I2C_SendACK(void);
void I2C_SendNACK(void);
void I2C_EnableClockStretch(void);
void I2C_DisableClockStretch(void);
void I2C_EnableStop(void);
void I2C_DisableStop(void);
void I2C_EnableStart(void);
void I2C_DisableStart(void);
void I2C_EnableAutoEnd(void);
void I2C_DisableAutoEnd(void);
void I2C_EnableTimeOut(void);
void I2C_DisableTimeOut(void);
void I2C_ConfigFilter(I2C_FILTER_T filter);
void I2C_ConfigSlaveAddr(uint8_t address);
void I2C_ConfigMasterAddr(uint8_t address);
void I2C_ConfigMasterRWBit(uint8_t bit);
void I2C_ConfigClockPeriod(uint8_t highPeriod, uint8_t lowPeriod);
void I2C_ConfigTimeOut(uint32_t time);

/* I2C interrupt configuration */
void I2C_EnableInterrupt(I2C_INT_T interrupt);
void I2C_DisableInterrupt(I2C_INT_T interrupt);
uint8_t I2C_ReadFlag(I2C_FLAG_T flag);
void I2C_ClearFlag(I2C_FLAG_T flag);

/* I2C read/write data */
uint8_t I2C_ReadData(void);
void I2C_SendData(uint8_t data);

/**@} end of group I2C_Functions*/
/**@} end of group I2C_Driver*/
/**@} end of group Peripherals_Library*/

#ifdef __cplusplus
}
#endif

#endif /* __BMP561_I2C_H */
