Abstract class for character device on SPI.
More...
#include <SPI.hpp>
|
| enum | LockMode {
LOCK_PREEMPTION,
LOCK_THREADS,
LOCK_NONE,
LOCK_PREEMPTION,
LOCK_THREADS,
LOCK_NONE
} |
| | Locking modes supported by the driver. More...
|
| |
| enum | LockMode {
LOCK_PREEMPTION,
LOCK_THREADS,
LOCK_NONE,
LOCK_PREEMPTION,
LOCK_THREADS,
LOCK_NONE
} |
| | Locking modes supported by the driver. More...
|
| |
|
| | SPI (const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency) |
| | Constructor. More...
|
| |
| virtual | ~SPI () |
| |
| virtual int | init () override |
| |
| virtual int | probe () |
| | Check for the presence of the device on the bus. More...
|
| |
| int | transfer (uint8_t *send, uint8_t *recv, unsigned len) |
| | Perform a SPI transfer. More...
|
| |
| int | transferhword (uint16_t *send, uint16_t *recv, unsigned len) |
| | Perform a SPI 16 bit transfer. More...
|
| |
| void | set_frequency (uint32_t frequency) |
| | Set the SPI bus frequency This is used to change frequency on the fly. More...
|
| |
| uint32_t | get_frequency () |
| |
| void | set_lockmode (enum LockMode mode) |
| | Set the SPI bus locking mode. More...
|
| |
| int | _transfer (uint8_t *send, uint8_t *recv, unsigned len) |
| |
| int | _transferhword (uint16_t *send, uint16_t *recv, unsigned len) |
| |
| virtual bool | external () const override |
| |
| | SPI (const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency) |
| | Constructor. More...
|
| |
| virtual | ~SPI () |
| |
| virtual int | init () |
| |
| virtual int | probe () |
| | Check for the presence of the device on the bus. More...
|
| |
| int | transfer (uint8_t *send, uint8_t *recv, unsigned len) |
| | Perform a SPI transfer. More...
|
| |
| int | transferhword (uint16_t *send, uint16_t *recv, unsigned len) |
| | Perform a SPI 16 bit transfer. More...
|
| |
| void | set_frequency (uint32_t frequency) |
| | Set the SPI bus frequency This is used to change frequency on the fly. More...
|
| |
| uint32_t | get_frequency () |
| |
| void | set_lockmode (enum LockMode mode) |
| | Set the SPI bus locking mode. More...
|
| |
| bool | external () |
| |
Abstract class for character device on SPI.
Definition at line 51 of file SPI.hpp.
◆ LockMode [1/2]
Locking modes supported by the driver.
| Enumerator |
|---|
| 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
|
| 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
|
Definition at line 77 of file SPI.hpp.
◆ LockMode [2/2]
Locking modes supported by the driver.
| Enumerator |
|---|
| 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
|
| 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
|
Definition at line 78 of file SPI.hpp.
◆ SPI() [1/5]
| __EXPORT::SPI::SPI |
( |
const SPI & |
| ) |
|
|
delete |
◆ SPI() [2/5]
| __EXPORT::SPI::SPI |
( |
SPI && |
| ) |
|
|
delete |
◆ SPI() [3/5]
| __EXPORT::SPI::SPI |
( |
const char * |
name, |
|
|
const char * |
devname, |
|
|
int |
bus, |
|
|
uint32_t |
device, |
|
|
enum spi_mode_e |
mode, |
|
|
uint32_t |
frequency |
|
) |
| |
|
protected |
Constructor.
- Parameters
-
| name | Driver name |
| devname | Device node name |
| bus | SPI bus on which the device lives |
| device | Device handle (used by SPI_SELECT) |
| mode | SPI clock/data mode |
| frequency | SPI clock frequency |
◆ ~SPI() [1/2]
| virtual __EXPORT::SPI::~SPI |
( |
| ) |
|
|
protectedvirtual |
◆ SPI() [4/5]
| SPI::SPI |
( |
const char * |
name, |
|
|
const char * |
devname, |
|
|
int |
bus, |
|
|
uint32_t |
device, |
|
|
enum spi_mode_e |
mode, |
|
|
uint32_t |
frequency |
|
) |
| |
|
protected |
Constructor.
- Parameters
-
| name | Driver name |
| devname | Device node name |
| bus | SPI bus on which the device lives |
| device | Device handle (used by SPI_SELECT) |
| mode | SPI clock/data mode |
| frequency | SPI clock frequency |
Definition at line 60 of file SPI.cpp.
◆ ~SPI() [2/2]
◆ SPI() [5/5]
| __EXPORT::SPI::SPI |
( |
const SPI & |
| ) |
|
|
private |
◆ _transfer()
| int SPI::_transfer |
( |
uint8_t * |
send, |
|
|
uint8_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
◆ _transferhword()
| int SPI::_transferhword |
( |
uint16_t * |
send, |
|
|
uint16_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
◆ external() [1/2]
| virtual bool __EXPORT::SPI::external |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ external() [2/2]
| bool __EXPORT::SPI::external |
( |
| ) |
|
|
inlineprotected |
◆ get_frequency() [1/2]
| uint32_t __EXPORT::SPI::get_frequency |
( |
| ) |
|
|
inlineprotected |
◆ get_frequency() [2/2]
| uint32_t __EXPORT::SPI::get_frequency |
( |
| ) |
|
|
inlineprotected |
◆ init() [1/2]
| virtual int __EXPORT::SPI::init |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ init() [2/2]
◆ operator=() [1/3]
| SPI& __EXPORT::SPI::operator= |
( |
const SPI & |
| ) |
|
|
delete |
◆ operator=() [2/3]
| SPI& __EXPORT::SPI::operator= |
( |
SPI && |
| ) |
|
|
delete |
◆ operator=() [3/3]
| SPI __EXPORT::SPI::operator= |
( |
const SPI & |
| ) |
|
|
private |
◆ probe() [1/2]
| virtual int __EXPORT::SPI::probe |
( |
| ) |
|
|
inlineprotectedvirtual |
Check for the presence of the device on the bus.
Definition at line 88 of file SPI.hpp.
References send().
Referenced by init().
◆ probe() [2/2]
| virtual int __EXPORT::SPI::probe |
( |
| ) |
|
|
inlineprotectedvirtual |
Check for the presence of the device on the bus.
Definition at line 89 of file SPI.hpp.
References send().
◆ set_frequency() [1/2]
| void __EXPORT::SPI::set_frequency |
( |
uint32_t |
frequency | ) |
|
|
inlineprotected |
Set the SPI bus frequency This is used to change frequency on the fly.
Some sensors (such as the MPU6000) need a lower frequency for setup registers and can handle higher frequency for sensor value registers
- Parameters
-
| frequency | Frequency to set (Hz) |
Definition at line 141 of file SPI.hpp.
◆ set_frequency() [2/2]
| void __EXPORT::SPI::set_frequency |
( |
uint32_t |
frequency | ) |
|
|
inlineprotected |
Set the SPI bus frequency This is used to change frequency on the fly.
Some sensors (such as the MPU6000) need a lower frequency for setup registers and can handle higher frequency for sensor value registers
- Parameters
-
| frequency | Frequency to set (Hz) |
Definition at line 142 of file SPI.hpp.
◆ set_lockmode() [1/2]
| void __EXPORT::SPI::set_lockmode |
( |
enum LockMode |
mode | ) |
|
|
inlineprotected |
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.
- Parameters
-
Definition at line 152 of file SPI.hpp.
◆ set_lockmode() [2/2]
| void __EXPORT::SPI::set_lockmode |
( |
enum LockMode |
mode | ) |
|
|
inlineprotected |
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.
- Parameters
-
Definition at line 153 of file SPI.hpp.
◆ transfer() [1/2]
| int __EXPORT::SPI::transfer |
( |
uint8_t * |
send, |
|
|
uint8_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
Perform a SPI 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.
- Parameters
-
| send | Bytes to send to the device, or nullptr if no data is to be sent. |
| recv | Buffer for receiving bytes from the device, or nullptr if no bytes are to be received. |
| len | Number of bytes to transfer. |
- Returns
- OK if the exchange was successful, -errno otherwise.
◆ transfer() [2/2]
| int SPI::transfer |
( |
uint8_t * |
send, |
|
|
uint8_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
Perform a SPI 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.
- Parameters
-
| send | Bytes to send to the device, or nullptr if no data is to be sent. |
| recv | Buffer for receiving bytes from the device, or nullptr if no bytes are to be received. |
| len | Number of bytes to transfer. |
- Returns
- OK if the exchange was successful, -errno otherwise.
Definition at line 125 of file SPI.cpp.
References _dev, _locking_mode, _transfer(), LOCK_NONE, LOCK_PREEMPTION, LOCK_THREADS, and state.
◆ transferhword() [1/2]
| int __EXPORT::SPI::transferhword |
( |
uint16_t * |
send, |
|
|
uint16_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
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.
- Parameters
-
| send | Words to send to the device, or nullptr if no data is to be sent. |
| recv | Words for receiving bytes from the device, or nullptr if no bytes are to be received. |
| len | Number of words to transfer. |
- Returns
- OK if the exchange was successful, -errno otherwise.
◆ transferhword() [2/2]
| int SPI::transferhword |
( |
uint16_t * |
send, |
|
|
uint16_t * |
recv, |
|
|
unsigned |
len |
|
) |
| |
|
protected |
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.
- Parameters
-
| send | Words to send to the device, or nullptr if no data is to be sent. |
| recv | Words for receiving bytes from the device, or nullptr if no bytes are to be received. |
| len | Number of words to transfer. |
- Returns
- OK if the exchange was successful, -errno otherwise.
Definition at line 177 of file SPI.cpp.
References _dev, _locking_mode, _transferhword(), LOCK_NONE, LOCK_PREEMPTION, LOCK_THREADS, and state.
◆ _dev
| struct spi_dev_s* __EXPORT::SPI::_dev |
|
private |
◆ _device
| uint32_t __EXPORT::SPI::_device |
|
private |
◆ _fd
| int __EXPORT::SPI::_fd {-1} |
|
private |
◆ _frequency
| uint32_t __EXPORT::SPI::_frequency |
|
private |
◆ _locking_mode
◆ _mode
The documentation for this class was generated from the following files:
- src/lib/drivers/device/nuttx/SPI.hpp
- src/lib/drivers/device/nuttx/SPI.cpp