Skip to content

Commit

Permalink
Fix sequence errors by ensuring that both header and data are fed bac…
Browse files Browse the repository at this point in the history
…k to the SH2 layer.

Push header/payload differentiation up to the sh2 library.
  • Loading branch information
aentinger committed Aug 4, 2023
1 parent 851559e commit 6c2e9d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
26 changes: 4 additions & 22 deletions bno085_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,20 @@ BNO085_HAL::BNO085_HAL(std::shared_ptr<SPI> const spi,

int BNO085_HAL::sh2_hal_read(uint8_t * pBuffer, unsigned len, uint32_t * t_us)
{
/* Read the sensor hub header. */
uint8_t sh_hdr_rx_buf[4] = {0};
uint8_t const sh_hdr_tx_buf[4] = {0};

if (!waitForIrqLow())
return 0;

if (!_spi->transfer(sh_hdr_tx_buf, sh_hdr_rx_buf, sizeof(sh_hdr_tx_buf)))
return 0;

/* Determine packet size (mask out continuous bit). */
uint16_t const packet_size =
(static_cast<uint16_t>(sh_hdr_rx_buf[0]) | static_cast<uint16_t>(sh_hdr_rx_buf[1]) << 8) & 0x7FFF;

/* Return early if packet size exceeds provided buffer. */
if (packet_size > len)
return 0;

/* Ensure that we only transmit zero's. */
auto const tx_buf = std::make_unique<uint8_t[]>(packet_size);
memset(tx_buf.get(), 0, packet_size);

if (!waitForIrqLow())
return 0;
auto const tx_buf = std::make_unique<uint8_t[]>(len);
memset(tx_buf.get(), 0, len);

/* Transmit zero's and read from the device. */
if (!_spi->transfer(tx_buf.get(), pBuffer, packet_size))
if (!_spi->transfer(tx_buf.get(), pBuffer, len))
return 0;

*t_us = sh2_hal_getTimeUs();

return packet_size;
return len;
}

int BNO085_HAL::sh2_hal_write(uint8_t * pBuffer, unsigned len)
Expand Down
2 changes: 1 addition & 1 deletion sh2
Submodule sh2 updated 1 files
+21 −3 shtp.c

0 comments on commit 6c2e9d2

Please sign in to comment.