#ifndef debug_h__
#define debug_h__


#include "stdint.h"
#include "stdio.h"




/*r{ 修改日志打印等级 }c*/
#define DBG_LOG_LEVEL DBG_LEVEL_LOG



/*r{ 定义打印数据等级 }c*/
#define DBG_LEVEL_INFO  0
#define DBG_LEVEL_LOG   1
#define DBG_LEVEL_WARN  2
#define DBG_LEVEL_ERR   3


#if (DBG_LOG_LEVEL<=DBG_LEVEL_INFO)
#define DBG_INFO( ml_msg_, ...) \
    DBG_LOG_(DBG_LEVEL_INFO, (ml_msg_), ##__VA_ARGS__)
#else
#define DBG_INFO( ml_msg_, ...)
#endif
#if (DBG_LOG_LEVEL<=DBG_LEVEL_LOG)
#define DBG_LOG( ml_msg_, ...) \
    DBG_LOG_(DBG_LEVEL_LOG, (ml_msg_), ##__VA_ARGS__)
#else
#define DBG_LOG( ml_msg_, ...)
#endif
#if (DBG_LOG_LEVEL<=DBG_LEVEL_WARN)
#define DBG_WARN( ml_msg_, ...) \
    DBG_LOG_(DBG_LEVEL_WARN, (ml_msg_), ##__VA_ARGS__)
#else
#define DBG_WARN( ml_msg_, ...)
#endif
#if (DBG_LOG_LEVEL<=DBG_LEVEL_ERR)
#define DBG_ERR( ml_msg_, ...) \
    DBG_LOG_(DBG_LEVEL_ERR, (ml_msg_), ##__VA_ARGS__)
#else
#define DBG_ERR( ml_msg_, ...)
#endif


#define DBG_LOG_(type_,msg_,...)\
  debug_log(__FILE__,__func__,__LINE__,type_,(msg_),##__VA_ARGS__)



typedef struct{
  int (*init)();
  int (*write)(const uint8_t *data,size_t len);
}dbg_dev;




int debug_init(dbg_dev* dev);

void debug_print_context(int enable);

void debug_log(const char *file,const char *fun,int line,int level,const char *fmt, ...);


#endif

