mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 04:13:34 +08:00
Add a driver for the Analog Devices ADIS16448 IMU (#8301)
This commit is contained in:
@@ -181,4 +181,56 @@ SPI::_transfer(uint8_t *send, uint8_t *recv, unsigned len)
|
||||
return OK;
|
||||
}
|
||||
|
||||
int
|
||||
SPI::transferhword(uint16_t *send, uint16_t *recv, unsigned len)
|
||||
{
|
||||
int result;
|
||||
|
||||
if ((send == nullptr) && (recv == nullptr)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LockMode mode = up_interrupt_context() ? LOCK_NONE : locking_mode;
|
||||
|
||||
/* lock the bus as required */
|
||||
switch (mode) {
|
||||
default:
|
||||
case LOCK_PREEMPTION: {
|
||||
irqstate_t state = px4_enter_critical_section();
|
||||
result = _transferhword(send, recv, len);
|
||||
px4_leave_critical_section(state);
|
||||
}
|
||||
break;
|
||||
|
||||
case LOCK_THREADS:
|
||||
SPI_LOCK(_dev, true);
|
||||
result = _transferhword(send, recv, len);
|
||||
SPI_LOCK(_dev, false);
|
||||
break;
|
||||
|
||||
case LOCK_NONE:
|
||||
result = _transferhword(send, recv, len);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
SPI::_transferhword(uint16_t *send, uint16_t *recv, unsigned len)
|
||||
{
|
||||
SPI_SETFREQUENCY(_dev, _frequency);
|
||||
SPI_SETMODE(_dev, _mode);
|
||||
SPI_SETBITS(_dev, 16); /* 16 bit transfer */
|
||||
SPI_SELECT(_dev, _device, true);
|
||||
|
||||
/* do the transfer */
|
||||
SPI_EXCHANGE(_dev, send, recv, len);
|
||||
|
||||
/* and clean up */
|
||||
SPI_SELECT(_dev, _device, false);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
|
||||
@@ -108,6 +108,27 @@ protected:
|
||||
*/
|
||||
int transfer(uint8_t *send, uint8_t *recv, unsigned len);
|
||||
|
||||
/**
|
||||
* Perform a SPI 16 bit transfer.
|
||||
*
|
||||
* If called from interrupt context, this interface does not lock
|
||||
* the bus and may interfere with non-interrupt-context callers.
|
||||
*
|
||||
* Clients in a mixed interrupt/non-interrupt configuration must
|
||||
* ensure appropriate interlocking.
|
||||
*
|
||||
* At least one of send or recv must be non-null.
|
||||
*
|
||||
* @param send Words to send to the device, or nullptr if
|
||||
* no data is to be sent.
|
||||
* @param recv Words for receiving bytes from the device,
|
||||
* or nullptr if no bytes are to be received.
|
||||
* @param len Number of words to transfer.
|
||||
* @return OK if the exchange was successful, -errno
|
||||
* otherwise.
|
||||
*/
|
||||
int transferhword(uint16_t *send, uint16_t *recv, unsigned len);
|
||||
|
||||
/**
|
||||
* Set the SPI bus frequency
|
||||
* This is used to change frequency on the fly. Some sensors
|
||||
@@ -144,6 +165,8 @@ private:
|
||||
protected:
|
||||
int _transfer(uint8_t *send, uint8_t *recv, unsigned len);
|
||||
|
||||
int _transferhword(uint16_t *send, uint16_t *recv, unsigned len);
|
||||
|
||||
bool external() { return px4_spi_bus_external(get_device_bus()); }
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user