/*********************************************************************************************************//**
 * @file    BMB22M210_HT32/src/BMB22M210.h
 * @version V1.0.1
 * @date    2024-08-09
 * @brief   The header file of BMB22M210 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 __BMB22M210_H
#define __BMB22M210_H

#ifdef __cplusplus
 extern "C" {
#endif

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

#include "middleware/uart_module.h"

/* Settings ------------------------------------------------------------------------------------------------*/
/* Exported typedef ----------------------------------------------------------------------------------------*/
typedef enum {
  BMB22M210_SUCCESS,
  BMB22M210_FAILURE
} BMB22M210_selStatus;

typedef enum
{ 
    BMB22M210_TXRX_DISABLE = 0,
    BMB22M210_TX_DISABLE = 1,
    BMB22M210_RX_DISABLE = 2,
    BMB22M210_TXRX_ENABLE = 3,
} BMB22M210_PORTSTATUS;

/* Exported constants --------------------------------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------------------------------------*/
#define BMB22M210_BaudRate        9600
#define BMB22M210_UART_TXTIMEOUT  1000
#define BM62S2201_1_UART_RXTIMEOUT_BYTE     3      //uint:ms

/*  config  */
#define  BMB22M210_MYSERIAL_8N1  0   //data:8bit,No check,  Stop bit:1bit
#define  BMB22M210_MYSERIAL_8N2  1   //data:8bit,No check,  Stop bit:2bit
#define  BMB22M210_MYSERIAL_801  8   //data:8bit,0 check,   Stop bit:1bit
#define  BMB22M210_MYSERIAL_802  9   //data:8bit,0 check,   Stop bit:2bit
#define  BMB22M210_MYSERIAL_8O1  10  //data:8bit,Odd check, Stop bit:1bit
#define  BMB22M210_MYSERIAL_8O2  11  //data:8bit,Odd check, Stop bit:2bit
#define  BMB22M210_MYSERIAL_8E1  12  //data:8bit,Even check,Stop bit:1bit
#define  BMB22M210_MYSERIAL_8E2  13  //data:8bit,Even check,Stop bit:2bit
#define  BMB22M210_MYSERIAL_811  14  //data:8bit,1 check,   Stop bit:1bit
#define  BMB22M210_MYSERIAL_812  15  //data:8bit,1 check,   Stop bit:2bit
/* Exported variables --------------------------------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------------------------------------*/
BMB22M210_selStatus BMB22M210_selSerial(uint32_t serial_number);
void BMB22M210_Init(uint32_t baud);
void BMB22T101_Init(uint32_t baud);   //only use on BMB22T101 Module

void BMB22M210_beginPort(uint8_t port,uint32_t baud,uint8_t config);
uint8_t BMB22M210_getINT(void);
void BMB22M210_setPortStatus(uint8_t port,BMB22M210_PORTSTATUS status);
void BMB22M210_write(uint8_t port,uint8_t data);
int BMB22M210_read(uint8_t port);
void BMB22M210_writeBytes(uint8_t port,uint8_t buff[],uint8_t num);
void BMB22M210_readBytes(uint8_t port,int8_t buff[],uint8_t num);
uint8_t BMB22M210_available(uint8_t port);
void BMB22M210_resetPort(uint8_t port);
  
uint8_t BMB22M210_getTxFifoNum(uint8_t port);
uint8_t BMB22M210_getFifoStatus(uint8_t port);
uint8_t BMB22M210_getInterruptFlag(uint8_t port);
void BMB22M210_setTxFifoInterrupt(uint8_t port,uint8_t data);
void BMB22M210_setRxFifoInterrupt(uint8_t port,uint8_t data);
  
/*   private   */
int BMB22M210_readGReg(uint8_t greg);
void BMB22M210_writeGReg(uint8_t greg,uint8_t datg);
void BMB22M210_writeSReg(uint8_t port,uint8_t sreg,uint8_t dats);
int BMB22M210_readSReg(uint8_t port,uint8_t sreg);
int BMB22M210_availableReadSReg(uint8_t port,uint8_t sreg);
void BMB22M210_setPortBaud(uint8_t port,uint32_t  baud);

void _BMB22M210_delay(vu32 count);
void _BMB22M210_delay_us(vu32 count);


#ifdef __cplusplus
}
#endif

#endif

