优化整定,DHCP有问题待优化
This commit is contained in:
31
app/sht40.c
31
app/sht40.c
@ -8,9 +8,10 @@
|
||||
#include "sht40.h"
|
||||
#include "board.h"
|
||||
#include "osal.h"
|
||||
#include "hal.h"
|
||||
|
||||
/* 外部I2C句柄 */
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
/* 硬件抽象层操作结构体 */
|
||||
const hal_ops_t *hal_ops = NULL;
|
||||
|
||||
/* CRC校验函数 */
|
||||
static uint8_t sht40_crc8(const uint8_t *data, uint8_t len)
|
||||
@ -42,6 +43,14 @@ static uint8_t sht40_crc8(const uint8_t *data, uint8_t len)
|
||||
*/
|
||||
int sht40_init(void)
|
||||
{
|
||||
/* 初始化硬件抽象层操作结构体 */
|
||||
hal_ops = hal_get_ops();
|
||||
if (hal_ops == NULL)
|
||||
{
|
||||
osal_log_e("SHT40: Failed to get HAL ops");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sht40_reset();
|
||||
}
|
||||
|
||||
@ -53,7 +62,7 @@ int sht40_reset(void)
|
||||
{
|
||||
uint8_t cmd = SHT40_CMD_RESET;
|
||||
osal_log_i("SHT40: Sending reset command 0x%02X", cmd);
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_OK)
|
||||
if (hal_ops->i2c->master_transmit(SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 reset failed");
|
||||
return -1;
|
||||
@ -74,7 +83,7 @@ int sht40_read_serial(uint32_t *serial)
|
||||
uint8_t data[6];
|
||||
|
||||
//osal_log_i("SHT40: Sending read serial command 0x%02X", cmd);
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_OK)
|
||||
if (hal_ops->i2c->master_transmit(SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 send read serial command failed");
|
||||
return -1;
|
||||
@ -82,7 +91,7 @@ int sht40_read_serial(uint32_t *serial)
|
||||
|
||||
osal_thread_mdelay(1);
|
||||
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, SHT40_I2C_ADDR << 1, data, 6, 1000) != HAL_OK)
|
||||
if (hal_ops->i2c->master_receive(SHT40_I2C_ADDR << 1, data, 6, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 read serial data failed");
|
||||
return -1;
|
||||
@ -133,7 +142,7 @@ int sht40_heater_enable(uint8_t power_level)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_OK)
|
||||
if (hal_ops->i2c->master_transmit(SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 heater enable failed");
|
||||
return -1;
|
||||
@ -180,10 +189,9 @@ int sht40_read_temperature_humidity_with_precision(float *temperature, float *hu
|
||||
|
||||
//osal_log_i("SHT40: Sending measure command 0x%02X to address 0x%02X", cmd, SHT40_I2C_ADDR);
|
||||
/* 发送测量命令 */
|
||||
HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, SHT40_I2C_ADDR << 1, &cmd, 1, 1000);
|
||||
if (status != HAL_OK)
|
||||
if (hal_ops->i2c->master_transmit(SHT40_I2C_ADDR << 1, &cmd, 1, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 send measure command failed, status: %d", status);
|
||||
osal_log_e("SHT40 send measure command failed");
|
||||
return -1;
|
||||
}
|
||||
//osal_log_i("SHT40: Measure command sent successfully");
|
||||
@ -193,10 +201,9 @@ int sht40_read_temperature_humidity_with_precision(float *temperature, float *hu
|
||||
|
||||
/* 读取测量结果 */
|
||||
//osal_log_i("SHT40: Reading 6 bytes of data");
|
||||
status = HAL_I2C_Master_Receive(&hi2c1, SHT40_I2C_ADDR << 1, data, 6, 1000);
|
||||
if (status != HAL_OK)
|
||||
if (hal_ops->i2c->master_receive(SHT40_I2C_ADDR << 1, data, 6, 1000) != HAL_STATUS_OK)
|
||||
{
|
||||
osal_log_e("SHT40 read data failed, status: %d", status);
|
||||
osal_log_e("SHT40 read data failed");
|
||||
return -1;
|
||||
}
|
||||
//osal_log_i("SHT40: Data read successfully: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X",
|
||||
|
||||
Reference in New Issue
Block a user