代码段1:u8 gmp108l_initialization(void)
{
u8 rc, u8Data;
/***** check sensor version *****/
rc = gmp108l_burst_read(GMP108L_REG_REV_ID, &u8Data, 1);
if (rc != 0) return (rc);
GMP108L_LOG_DEBUG("Sensor Value = 0x%02X", u8Data);
/***** check sensor ID *****/
rc = gmp108l_burst_read(GMP108L_REG_CHIP_ID, &u8Data, 1);
if (rc != 0) return (rc);
GMP108L_LOG_DEBUG("Sensor Value = 0x%02X", u8Data);
/***** (Reg)FIFO_CONFIG_1, enable filtered data, subsampling interval: 0, *****/
u8Data = 0x00;
rc = gmp108l_burst_write(GMP108L_REG_FIFO_CONFIG_1, &u8Data, 1);
if (rc != 0) return (rc);
/***** (Reg)INT_CTRL, enable data ready interrupt, *****/
u8Data = 0x40;
rc = gmp108l_burst_write(GMP108L_REG_INT_CTRL, &u8Data, 1);
if (rc != 0) return (rc);
/***** (Reg)OSR, oversampling ratio (P & T) *****/
u8Data = 0x35; // OSR_T: x8, OSR_P: x32
rc = gmp108l_burst_write(GMP108L_REG_OSR, &u8Data, 1);
if (rc != 0) return (rc);
/***** (Reg)ODR, output data rate) *****/
u8Data = 0x16; // ODR: 6.4Hz
rc = gmp108l_burst_write(GMP108L_REG_ODR, &u8Data, 1);
if (rc != 0) return (rc);
/***** (Reg)FILTER, IIR-filter_coe_P, IIR-filter_coe_T, *****/
// u8Data = 0x00; // filter-coes: 0
u8Data = 0x33; // filter-coes: 7
rc = gmp108l_burst_write(GMP108L_REG_FILTER, &u8Data, 1);
if (rc != 0) return (rc);
return (rc);
}
代码段2:// 定义日志级别(可根据需求调整)
#define GMP108L_LOG_LEVEL_NONE 0 // 关闭所有日志
#define GMP108L_LOG_LEVEL_ERROR 1 // 仅错误
#define GMP108L_LOG_LEVEL_WARN 2 // 错误+警告
#define GMP108L_LOG_LEVEL_INFO 3 // 错误+警告+信息
#define GMP108L_LOG_LEVEL_DEBUG 4 // 全部日志(调试用)
// 设置当前日志级别(发布版本可改为 GMP108L_LOG_LEVEL_NONE 或 GMP108L_LOG_LEVEL_ERROR)
#ifndef GMP108L_LOG_LEVEL
#define GMP108L_LOG_LEVEL GMP108L_LOG_LEVEL_DEBUG
#endif
// 平台输出函数(替换为实际平台的打印函数,如 hal_uart_printf)
#ifndef PLATFORM_LOG_PRINT
#define PLATFORM_LOG_PRINT(...) printf(__VA_ARGS__) // 默认使用标准 printf
#endif
// 日志宏定义(包含文件、行号、函数名)
#define GMP108L_LOG(level, fmt, ...) do { \
if ((level) <= GMP108L_LOG_LEVEL) { \
PLATFORM_LOG_PRINT("[GMP108L][%s][%s:%d] ", \
#level, __func__, __LINE__); \
PLATFORM_LOG_PRINT(fmt, ##__VA_ARGS__); \
PLATFORM_LOG_PRINT("\n"); \
} \
} while(0)
// 简化不同级别调用的宏
#define GMP108L_LOG_ERROR(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_ERROR, "ERROR", fmt, ##__VA_ARGS__)
#define GMP108L_LOG_WARN(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_WARN, "WARN", fmt, ##__VA_ARGS__)
#define GMP108L_LOG_INFO(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_INFO, "INFO", fmt, ##__VA_ARGS__)
#define GMP108L_LOG_DEBUG(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_DEBUG, "DEBUG", fmt, ##__VA_ARGS__)
#define gmp108l_get_bitslice(regvar, bitname) \
((regvar & bitname##__MSK) >> bitname##__POS)
#define gmp108l_set_bitslice(regvar, bitname, val) \
((regvar & ~bitname##__MSK) | ((val<<bitname##__POS) & bitname##__MSK))
报错:../../platform/huaqin_drivers/src/sensor/GMP108L/GMP108L.c: In function 'gmp108l_initialization':
../../platform/huaqin_drivers/src/sensor/GMP108L/GMP108L.h:307:75: warning: too many arguments for format [-Wformat-extra-args]
307 | #define GMP108L_LOG_DEBUG(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_DEBUG, "DEBUG", fmt, ##__VA_ARGS__)
| ^~~~~~~
../../platform/huaqin_drivers/src/sensor/GMP108L/GMP108L.h:290:40: note: in definition of macro 'PLATFORM_LOG_PRINT'
290 | #define PLATFORM_LOG_PRINT(...) printf(__VA_ARGS__) // 默认使用标准 printf
| ^~~~~~~~~~~
../../platform/huaqin_drivers/src/sensor/GMP108L/GMP108L.h:307:38: note: in expansion of macro 'GMP108L_LOG'
307 | #define GMP108L_LOG_DEBUG(fmt, ...) GMP108L_LOG(GMP108L_LOG_LEVEL_DEBUG, "DEBUG", fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~
../../platform/huaqin_drivers/src/sensor/GMP108L/GMP108L.c:206:3: note: in expansion of macro 'GMP108L_LOG_DEBUG'
206 | GMP108L_LOG_DEBUG("Sensor Value = 0x%02X", u8Data);怎么改