45 #include <sys/ioctl.h> 46 #include "dev_fs_lib_spi.h" 48 #include <px4_platform_common/px4_config.h> 53 SPI::SPI(
const char *
name,
const char *devname,
int bus, uint32_t
device,
enum spi_mode_e mode, uint32_t frequency) :
59 DEVICE_DEBUG(
"SPI::SPI name = %s devname = %s", name, devname);
62 _device_id.devid_s.bus_type = DeviceBusType_SPI;
63 _device_id.devid_s.bus = bus;
64 _device_id.devid_s.address = (uint8_t)device;
66 _device_id.devid_s.devtype = 0;
82 snprintf(dev_path,
sizeof(dev_path),
"dev/spi-%lu", PX4_SPI_DEV_ID(
_device));
84 _fd = ::open(dev_path, O_RDWR);
87 PX4_ERR(
"could not open %s", dev_path);
116 if ((send ==
nullptr) && (recv ==
nullptr)) {
120 dspal_spi_ioctl_read_write ioctl_write_read{};
121 ioctl_write_read.read_buffer =
send;
122 ioctl_write_read.read_buffer_length = len;
123 ioctl_write_read.write_buffer = recv;
124 ioctl_write_read.write_buffer_length = len;
126 int result = ::ioctl(
_fd, SPI_IOCTL_RDWR, &ioctl_write_read);
129 PX4_ERR(
"transfer error %d", result);
139 if ((send ==
nullptr) && (recv ==
nullptr)) {
151 dspal_spi_ioctl_read_write ioctl_write_read{};
152 ioctl_write_read.read_buffer =
send;
153 ioctl_write_read.read_buffer_length = len * 2;
154 ioctl_write_read.write_buffer = recv;
155 ioctl_write_read.write_buffer_length = len * 2;
157 int result = ::ioctl(
_fd, SPI_IOCTL_RDWR, &ioctl_write_read);
160 PX4_ERR(
"transfer error %d", result);
int transfer(uint8_t *send, uint8_t *recv, unsigned len)
Perform a SPI transfer.
Namespace encapsulating all device framework classes, functions and data.
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.
#define DEVICE_DEBUG(FMT,...)