| #include "libhoth_spi.hpp" | |
| #include <fcntl.h> | |
| #include <linux/spi/spidev.h> | |
| #include <linux/types.h> | |
| #include <sys/ioctl.h> | |
| #include <unistd.h> | |
| #include <cstdint> | |
| #include <cstdio> | |
| #include <cstdlib> | |
| #include <cstring> | |
| #include <type_traits> | |
| namespace google | |
| { | |
| namespace hoth | |
| { | |
| namespace | |
| { | |
| template <typename T> | |
| int convertStatus(T status) | |
| { | |
| if constexpr (std::is_same_v<std::decay_t<T>, int>) | |
| { | |
| return status; | |
| } | |
| else | |
| { | |
| return static_cast<int>( | |
| static_cast<int32_t>(LIBHOTH_ERR_GET_CODE(status))); | |
| } | |
| } | |
| } // namespace | |
| int LibHothSpiDevImpl::open(const option* opt, device** dev) | |
| { | |
| return convertStatus(::libhoth_spi_open(opt, dev)); | |
| } | |
| int LibHothSpiDevImpl::send(device* dev, const void* request, size_t size) | |
| { | |
| return convertStatus(dev->send(dev, request, size)); | |
| } | |
| int LibHothSpiDevImpl::recv(device* dev, void* response, size_t response_size, | |
| size_t* actual_size, int timeout_ms) | |
| { | |
| return convertStatus( | |
| dev->receive(dev, response, response_size, actual_size, timeout_ms)); | |
| } | |
| int LibHothSpiDevImpl::close(device* dev) | |
| { | |
| return convertStatus(dev->close(dev)); | |
| } | |
| int LibHothSpiDevImpl::claim(device* dev) | |
| { | |
| return convertStatus(dev->claim(dev)); | |
| } | |
| int LibHothSpiDevImpl::release(device* dev) | |
| { | |
| return convertStatus(dev->release(dev)); | |
| } | |
| LibHothSpiDevImpl libhoth_spidev; | |
| } // namespace hoth | |
| } // namespace google |