/*********************************************************************************************************//**
 * @file    BM62S2201_1_HT32/src/BM62S2201_1.h
 * @version V1.0.1
 * @date    2024-08-01
 * @brief   The header file of BM62S2201_1 driver.
 *************************************************************************************************************
 * @attention
 *
 * Firmware Disclaimer Information
 *
 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
 *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
 *    other intellectual property laws.
 *
 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
 *    other than HOLTEK and the customer.
 *
 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
 *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
 *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
 *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
 *
 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
 ************************************************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------------------------------------*/
#ifndef __BM62S2201_1_H
#define __BM62S2201_1_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------------------------------------*/
#include "ht32.h"
#include "i2c_master_config.h"
#include "ht32_board_config.h"
#include "bmduino_check.h"

#include "middleware/i2c_master.h"
#include "middleware/uart_module.h"

/* Settings ------------------------------------------------------------------------------------------------*/
/* Exported typedef ----------------------------------------------------------------------------------------*/
typedef enum {
  BM62S2201_1_SUCCESS,
  BM62S2201_1_FAILURE
} BM62S2201_1_selStatus;
/* Exported constants --------------------------------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------------------------------------*/
#define BM62S2201_1_COMM_IIC          0
#define BM62S2201_1_COMM_UART         1

#define BM62S2201_1_MASTERADDR     0x50
#define BM62S2201_1_CLKFREQ        100000

#define BM62S2201_1_UART_TXTIMEOUT          1000   //uint:baud clock
#define BM62S2201_1_UART_RXTIMEOUT_BYTE     3      //uint:ms

#define BM62S2201_1_READ_OK          0
#define BM62S2201_1_READ_ERROR       1
#define BM62S2201_1_NO_ACK           2
#define BM62S2201_1_TIMEOUT_ERROR    3

#define BM62S2201_1_DISABLE         0
#define BM62S2201_1_ENABLE          1 
/* Exported variables --------------------------------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------------------------------------*/
BM62S2201_1_selStatus BM62S2201_1_selWire(uint32_t wire_number);
BM62S2201_1_selStatus BM62S2201_1_selSerial(uint32_t serial_number);
void BM62S2201_1_I2C_Init(void);
void BM62S2201_1_UART_Init(void);

float BM62S2201_1_readTemperature(void);
uint16_t BM62S2201_1_readPressure(void);

uint8_t BM62S2201_1_getDevID(uint8_t devIDbuff[]); 
uint8_t BM62S2201_1_getI2CAddress(void);
uint8_t BM62S2201_1_getDeviceStatus(void);

void BM62S2201_1_enterSleepMode(void);
void BM62S2201_1_reset(void);
void BM62S2201_1_restoreDefault(void);

void BM62S2201_1_setI2CAddress(uint8_t addr);

void BM62S2201_1_writeBytes(uint8_t wbuf[], uint8_t wlen);
uint8_t BM62S2201_1_readBytes(uint8_t rbuf[], uint8_t rlen);

uint8_t  BM62S2201_1_analysis(void);
void _BM62S2201_1_clearBuf(void);
void _BM62S2201_1_delay(vu32 count);



#ifdef __cplusplus
}
#endif

#endif

