|
|
@ -65,6 +65,13 @@ namespace device __EXPORT |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class __EXPORT SPI : public CDev |
|
|
|
class __EXPORT SPI : public CDev |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
// no copy, assignment, move, move assignment
|
|
|
|
|
|
|
|
SPI(const SPI &) = delete; |
|
|
|
|
|
|
|
SPI &operator=(const SPI &) = delete; |
|
|
|
|
|
|
|
SPI(SPI &&) = delete; |
|
|
|
|
|
|
|
SPI &operator=(SPI &&) = delete; |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor |
|
|
|
* Constructor |
|
|
@ -79,6 +86,15 @@ protected: |
|
|
|
SPI(const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency); |
|
|
|
SPI(const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency); |
|
|
|
virtual ~SPI(); |
|
|
|
virtual ~SPI(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Locking modes supported by the driver. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
enum LockMode { |
|
|
|
|
|
|
|
LOCK_PREEMPTION, /**< the default; lock against all forms of preemption. */ |
|
|
|
|
|
|
|
LOCK_THREADS, /**< lock only against other threads, using SPI_LOCK */ |
|
|
|
|
|
|
|
LOCK_NONE /**< perform no locking, only safe if the bus is entirely private */ |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
virtual int init(); |
|
|
|
virtual int init(); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -140,18 +156,28 @@ protected: |
|
|
|
void set_frequency(uint32_t frequency) { _frequency = frequency; } |
|
|
|
void set_frequency(uint32_t frequency) { _frequency = frequency; } |
|
|
|
uint32_t get_frequency() { return _frequency; } |
|
|
|
uint32_t get_frequency() { return _frequency; } |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
/**
|
|
|
|
int _fd{-1}; |
|
|
|
* Set the SPI bus locking mode |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* This set the SPI locking mode. For devices competing with NuttX SPI |
|
|
|
|
|
|
|
* drivers on a bus the right lock mode is LOCK_THREADS. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param mode Locking mode |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
void set_lockmode(enum LockMode mode) { _locking_mode = mode; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
uint32_t _device; |
|
|
|
uint32_t _device; |
|
|
|
enum spi_mode_e _mode; |
|
|
|
enum spi_mode_e _mode; |
|
|
|
uint32_t _frequency; |
|
|
|
uint32_t _frequency; |
|
|
|
|
|
|
|
int _fd{-1}; |
|
|
|
|
|
|
|
|
|
|
|
/* this class does not allow copying */ |
|
|
|
LockMode _locking_mode{LOCK_THREADS}; /**< selected locking mode */ |
|
|
|
SPI(const SPI &); |
|
|
|
|
|
|
|
SPI operator=(const SPI &); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
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()); } |
|
|
|
bool external() { return px4_spi_bus_external(get_device_bus()); } |
|
|
|
|
|
|
|
|
|
|
|