mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
additional improvements
This commit is contained in:
@@ -70,16 +70,18 @@ int SMBus::read_word(const uint8_t cmd_code, void *data)
|
||||
int SMBus::block_read(const uint8_t cmd_code, void *data, const uint8_t length, bool use_pec)
|
||||
{
|
||||
unsigned byte_count = 0;
|
||||
// Length of data (32max). byte_count(1), cmd_code(2), pec(1) (optional)
|
||||
// Length of data (32max). byte_count(1), cmd_code(2) (sometimes), pec(1) (optional)
|
||||
uint8_t rx_data[32 + 4];
|
||||
|
||||
int result = transfer(&cmd_code, 1, (uint8_t *)rx_data, length + 2);
|
||||
|
||||
byte_count = rx_data[0];
|
||||
|
||||
// addr1, addr2, byte_count,
|
||||
// byte_count, data[length], PEC
|
||||
memcpy(data, &rx_data[1], byte_count);
|
||||
|
||||
if (use_pec) {
|
||||
|
||||
// addr(wr), cmd_code, addr(r), byte_count, rx_data[]
|
||||
uint8_t device_address = get_device_address();
|
||||
uint8_t full_data_packet[32 + 4] = {};
|
||||
@@ -97,6 +99,7 @@ int SMBus::block_read(const uint8_t cmd_code, void *data, const uint8_t length,
|
||||
if (pec != ((uint8_t *)rx_data)[byte_count + 1]) {
|
||||
result = -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user