部分驱动代码完成,待测试
This commit is contained in:
@ -212,6 +212,42 @@ void write_gsensor_data_handle(void)
|
||||
}
|
||||
}
|
||||
|
||||
// 临时的设备扫描诊断函数
|
||||
void i2c_scanner_probe(void)
|
||||
{
|
||||
printf("Starting I2C bus scan...\n");
|
||||
int devices_found = 0;
|
||||
|
||||
// I2C地址范围是 0x08 到 0x77
|
||||
for (uint8_t addr_7bit = 0x00; addr_7bit < 0x7F; addr_7bit++)
|
||||
{
|
||||
// 构建8位的写地址
|
||||
uint8_t write_addr_8bit = (addr_7bit << 1);
|
||||
|
||||
iic_start(gSensor_info->iic_hdl);
|
||||
|
||||
// 尝试发送写地址,并检查返回值
|
||||
// iic_tx_byte 返回 1 表示收到了 ACK
|
||||
if (iic_tx_byte(gSensor_info->iic_hdl, write_addr_8bit))
|
||||
{
|
||||
printf("=====================================================================\n");
|
||||
printf("I2C device found at 7-bit address: 0x%02X\n", addr_7bit);
|
||||
printf("I2C device found at 8-bit address: 0x%02X\n", write_addr_8bit);
|
||||
printf("=====================================================================\n");
|
||||
devices_found++;
|
||||
}
|
||||
|
||||
iic_stop(gSensor_info->iic_hdl);
|
||||
delay(gSensor_info->iic_delay); // 短暂延时
|
||||
}
|
||||
|
||||
if (devices_found == 0) {
|
||||
printf("Scan finished. No I2C devices found.\n");
|
||||
} else {
|
||||
printf("Scan finished. Found %d device(s).\n", devices_found);
|
||||
}
|
||||
}
|
||||
|
||||
char w_log_buffer_1[100];
|
||||
char w_log_buffer_2[100];
|
||||
char w_log_buffer_3[100];
|
||||
@ -222,7 +258,10 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
// spin_lock(&sensor_iic);
|
||||
/* os_mutex_pend(&SENSOR_IIC_MUTEX,0); */
|
||||
u8 ret = 1;
|
||||
// xlog("iic_start\n");
|
||||
iic_start(gSensor_info->iic_hdl);
|
||||
|
||||
// xlog("iic_tx_byte id\n");
|
||||
if (0 == iic_tx_byte(gSensor_info->iic_hdl, w_chip_id)) {
|
||||
ret = 0;
|
||||
xlog("\n gsen iic wr err 0\n");
|
||||
@ -230,8 +269,10 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
goto __gcend;
|
||||
}
|
||||
|
||||
// xlog("iic delay\n");
|
||||
delay(gSensor_info->iic_delay);
|
||||
|
||||
// xlog("iic_tx_byte: address\n");
|
||||
if (0 == iic_tx_byte(gSensor_info->iic_hdl, register_address)) {
|
||||
ret = 0;
|
||||
xlog("\n gsen iic wr err 1\n");
|
||||
@ -241,6 +282,7 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
|
||||
delay(gSensor_info->iic_delay);
|
||||
|
||||
// xlog("iic_tx_byte: command\n");
|
||||
if (0 == iic_tx_byte(gSensor_info->iic_hdl, function_command)) {
|
||||
ret = 0;
|
||||
xlog("\n gsen iic wr err 2\n");
|
||||
@ -249,6 +291,7 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
}
|
||||
|
||||
strcpy(&w_log_buffer_4, "gsen iic wr sucess\n");
|
||||
// xlog("\n gsen iic wr sucess\n");
|
||||
|
||||
__gcend:
|
||||
iic_stop(gSensor_info->iic_hdl);
|
||||
@ -304,6 +347,7 @@ u8 _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, u8 data
|
||||
*buf = iic_rx_byte(gSensor_info->iic_hdl, 0);
|
||||
read_len ++;
|
||||
strcpy(&sen_log_buffer_4, "gsen iic rd success\n");
|
||||
// xlog("\n gsen iic rd success\n");
|
||||
|
||||
__gdend:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user