Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adis16470 fixes #788

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/drivers/imu/analog_devices/adis16470/ADIS16470.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ ADIS16470::ADIS16470(const I2CSPIDriverConfig &config) :
if (_drdy_gpio != 0) {
_drdy_missed_perf = perf_alloc(PC_COUNT, MODULE_NAME": DRDY missed");
}

set_cs_to_sck_delay(SPI_CS_TO_SCK_PERIOD_NS);
}

ADIS16470::~ADIS16470()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static constexpr uint32_t SPI_SPEED_BURST = 1 * 1000 * 1000; // 1 MHz SPI serial

static constexpr uint32_t SPI_STALL_PERIOD = 16; // 16 us Stall period between data

static constexpr uint32_t SPI_CS_TO_SCK_PERIOD_NS = 200; // 200 ns delay from CS to SCK edge

static constexpr uint16_t DIR_WRITE = 0x80;

static constexpr uint16_t Product_identification = 0x4056;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/drivers/device/nuttx/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
# error This driver requires CONFIG_SPI_EXCHANGE
#endif

#ifndef SPI_CS_TO_SCK_DELAY
#define SPI_CS_TO_SCK_DELAY(dev, dly_ns) if (dly_ns) px4_udelay(((dly_ns) + 999) / 1000)
#endif

namespace device
{

Expand Down Expand Up @@ -169,6 +173,7 @@ SPI::_transfer(uint8_t *send, uint8_t *recv, unsigned len)
SPI_SETMODE(_dev, _mode);
SPI_SETBITS(_dev, 8);
SPI_SELECT(_dev, _device, true);
SPI_CS_TO_SCK_DELAY(_dev, _cs_to_sck_ns);

/* do the transfer */
SPI_EXCHANGE(_dev, send, recv, len);
Expand Down Expand Up @@ -221,6 +226,7 @@ SPI::_transferhword(uint16_t *send, uint16_t *recv, unsigned len)
SPI_SETMODE(_dev, _mode);
SPI_SETBITS(_dev, 16); /* 16 bit transfer */
SPI_SELECT(_dev, _device, true);
SPI_CS_TO_SCK_DELAY(_dev, _cs_to_sck_ns);

/* do the transfer */
SPI_EXCHANGE(_dev, send, recv, len);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/drivers/device/nuttx/SPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ class __EXPORT SPI : public CDev
*/
void set_lockmode(enum LockMode mode) { _locking_mode = mode; }

void set_cs_to_sck_delay(uint32_t delay_ns) { _cs_to_sck_ns = delay_ns; }
private:
uint32_t _device;
enum spi_mode_e _mode;
uint32_t _frequency;
uint32_t _cs_to_sck_ns {0};
struct spi_dev_s *_dev {nullptr};

LockMode _locking_mode{LOCK_THREADS}; /**< selected locking mode */
Expand Down
Loading