50 #include <px4_platform_common/px4_config.h> 51 #include <nuttx/arch.h> 53 #ifndef CONFIG_SPI_EXCHANGE 54 # error This driver requires CONFIG_SPI_EXCHANGE 64 _frequency(frequency),
68 _device_id.devid_s.bus_type = DeviceBusType_SPI;
69 _device_id.devid_s.bus = bus;
70 _device_id.devid_s.address = (uint8_t)device;
72 _device_id.devid_s.devtype = 0;
84 if (
_dev ==
nullptr) {
85 int bus = get_device_bus();
87 if (!board_has_bus(BOARD_SPI_BUS, bus)) {
91 _dev = px4_spibus_initialize(bus);
94 if (
_dev ==
nullptr) {
129 if ((send ==
nullptr) && (recv ==
nullptr)) {
139 irqstate_t
state = px4_enter_critical_section();
141 px4_leave_critical_section(state);
146 SPI_LOCK(
_dev,
true);
148 SPI_LOCK(
_dev,
false);
164 SPI_SETBITS(
_dev, 8);
168 SPI_EXCHANGE(
_dev, send, recv, len);
181 if ((send ==
nullptr) && (recv ==
nullptr)) {
191 irqstate_t
state = px4_enter_critical_section();
193 px4_leave_critical_section(state);
198 SPI_LOCK(
_dev,
true);
200 SPI_LOCK(
_dev,
false);
216 SPI_SETBITS(
_dev, 16);
220 SPI_EXCHANGE(
_dev, send, recv, len);
int transfer(uint8_t *send, uint8_t *recv, unsigned len)
Perform a SPI transfer.
perform no locking, only safe if the bus is entirely private
Namespace encapsulating all device framework classes, functions and data.
the default; lock against all forms of preemption.
virtual int init() override
virtual int probe()
Check for the presence of the device on the bus.
void init()
Activates/configures the hardware registers.
#define DEVICE_LOG(FMT,...)
int transferhword(uint16_t *send, uint16_t *recv, unsigned len)
Perform a SPI 16 bit transfer.
LockMode _locking_mode
selected locking mode
int _transfer(uint8_t *send, uint8_t *recv, unsigned len)
int _transferhword(uint16_t *send, uint16_t *recv, unsigned len)
lock only against other threads, using SPI_LOCK
LockMode
Locking modes supported by the driver.
#define DEVICE_DEBUG(FMT,...)