Skip to content

Commit 49fb9ec

Browse files
committed
read callback (when using I2C) now using readRegister16Region16
-read callback (when I2C) is not using readRegister16Region16. This allows it to be the same call for I2C and SPI -simplified my type check if statement to only include a single line of I2C specific code (the header shifting). -Note, this does require a slight change in the toolkit readRegister16Region16 to set nRead to WORDS not bytes.
1 parent 1be0e3d commit 49fb9ec

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

src/sfeBmv080.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ extern "C"
5959
uint16_t payload_length)
6060
{
6161
if (handle == nullptr)
62-
return E_COMBRIDGE_ERROR_NULLPTR;
63-
64-
sfeTkError_t rc;
62+
return E_COMBRIDGE_ERROR_NULLPTR;
6563

6664
// Our output var.
6765
size_t nRead = 0;
@@ -70,29 +68,12 @@ extern "C"
7068
sfeTkIBus *theBus = (sfeTkIBus *)handle;
7169

7270
if(theBus->type() == kBusTypeI2C)
73-
{
74-
header = header << 1;
75-
// the toolkit is set to adjust payload byte order, so we don't need to do it here
76-
// however, we do need to adjust the header byte order
77-
//header = ((header << 8) & 0xff00) | ((header >> 8) & 0x00ff);
78-
// Call the read reg 16 method on the bus.
79-
sfeTkError_t rc = theBus->readRegister16Region(header, (uint8_t*)payload, payload_length * 2, nRead);
80-
// Errors reading, not the expected number of bytes?
81-
if (rc != kSTkErrOk || nRead != payload_length * 2)
82-
return E_COMBRIDGE_ERROR_READ;
83-
84-
// from the Bosch example ...Need to swap the byte order
85-
for (uint16_t i = 0; i < payload_length; i++)
86-
payload[i] = ((payload[i] << 8) | (payload[i] >> 8)) & 0xffff;
87-
}
88-
else
89-
{
90-
// Call the read reg 16 method on the bus.
91-
sfeTkError_t rc = theBus->readRegister16Region16(header, payload, payload_length, nRead);
92-
// Errors reading, not the expected number of bytes?
93-
if (rc != kSTkErrOk || nRead != payload_length)
94-
return E_COMBRIDGE_ERROR_READ;
95-
}
71+
header = header << 1; // I2C specific shift
72+
73+
sfeTkError_t rc = theBus->readRegister16Region16(header, payload, payload_length, nRead);
74+
75+
if (rc != kSTkErrOk || nRead != payload_length)
76+
return E_COMBRIDGE_ERROR_READ;
9677

9778
return E_COMBRIDGE_OK;
9879
}
@@ -106,14 +87,12 @@ extern "C"
10687
if (handle == nullptr)
10788
return E_COMBRIDGE_ERROR_NULLPTR;
10889

109-
sfeTkError_t rc;
110-
11190
sfeTkIBus *theBus = (sfeTkIBus *)handle;
11291

11392
if(theBus->type() == kBusTypeI2C) // I2C specific shift
11493
header = header << 1;
11594

116-
rc = theBus->writeRegister16Region16(header, payload, payload_length);
95+
sfeTkError_t rc = theBus->writeRegister16Region16(header, payload, payload_length);
11796

11897
// okay, not okay?
11998
return rc == kSTkErrOk ? E_COMBRIDGE_OK : E_COMBRIDGE_ERROR_WRITE;

0 commit comments

Comments
 (0)