Mbed OS Reference
Loading...
Searching...
No Matches
EMW3080B_SPI Class Reference
Inheritance diagram for EMW3080B_SPI:
SPI NonCopyable< SPI >

Public Member Functions

void format (int bits, int mode=0)
 Configure the data transmission format. More...
 
void frequency (int hz=1000000)
 Set the SPI bus clock frequency. More...
 
virtual int write (int value)
 Write to the SPI Slave and return the response. More...
 
template<typename WordT >
std::enable_if< std::is_integral< WordT >::value, int >::type write (const WordT *tx_buffer, int tx_length, WordT *rx_buffer, int rx_length)
 Write to the SPI Slave and obtain the response. More...
 
virtual void lock (void)
 Acquire exclusive access to this SPI bus. More...
 
virtual void unlock (void)
 Release exclusive access to this SPI bus. More...
 
void select (void)
 Assert the Slave Select line and acquire exclusive access to this SPI bus. More...
 
void deselect (void)
 Deassert the Slave Select line, releasing exclusive access to this SPI bus. More...
 
void set_default_write_value (char data)
 Set default write data. More...
 
template<typename WordT >
std::enable_if< std::is_integral< WordT >::value, int >::type transfer (const WordT *tx_buffer, int tx_length, CacheAlignedBuffer< WordT > &rx_buffer, int rx_length, const event_callback_t &callback, int event=SPI_EVENT_COMPLETE)
 Start non-blocking SPI transfer. More...
 
template<typename WordT >
std::enable_if< std::is_integral< WordT >::value, int >::type transfer_and_wait (const WordT *tx_buffer, int tx_length, CacheAlignedBuffer< WordT > &rx_buffer, int rx_length, rtos::Kernel::Clock::duration_u32 timeout=rtos::Kernel::wait_for_u32_forever)
 Start SPI transfer and wait until it is complete. More...
 
void abort_transfer ()
 Abort the on-going SPI transfer, if any, and continue with transfers in the queue, if any. More...
 
void clear_transfer_buffer ()
 Clear the queue of transfers. More...
 
void abort_all_transfers ()
 Clear the queue of transfers and abort any on-going transfer. More...
 
int set_dma_usage (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking transfers. More...
 

Detailed Description

Definition at line 31 of file EMW3080B_SPI.h.

Member Function Documentation

◆ format()

void format ( int  bits,
int  mode = 0 
)
inherited

Configure the data transmission format.

Parameters
bitsNumber of bits per SPI frame (4 - 32, target dependent).
modeClock polarity and phase mode (0 - 3).
mode | POL PHA
-----+--------
0 | 0 0
1 | 0 1
2 | 1 0
3 | 1 1

◆ frequency()

void frequency ( int  hz = 1000000)
inherited

Set the SPI bus clock frequency.

Parameters
hzClock frequency in Hz (default = 1MHz).

◆ write() [1/2]

virtual int write ( int  value)
virtualinherited

Write to the SPI Slave and return the response.

Parameters
valueData to be sent to the SPI slave. The number of significant bits in this value depend on the bits parameter to format().
Returns
Response from the SPI slave. The number of significant bits in this value depend on the bits parameter to format().

◆ write() [2/2]

std::enable_if< std::is_integral< WordT >::value, int >::type write ( const WordT *  tx_buffer,
int  tx_length,
WordT *  rx_buffer,
int  rx_length 
)
inherited

Write to the SPI Slave and obtain the response.

The total number of bytes sent and received will be the maximum of tx_length and rx_length. The bytes written will be padded with the value 0xff.

Note: Even if the word size / bits per frame is not 8, rx_length and tx_length still count bytes of input data, not numbers of words.

Parameters
tx_bufferPointer to the byte-array of data to write to the device.
tx_lengthNumber of bytes to write, may be zero.
rx_bufferPointer to the byte-array of data to read from the device.
rx_lengthNumber of bytes to read, may be zero.
Returns
The number of bytes written and read from the device (as an int). This is maximum of tx_length and rx_length.

Definition at line 385 of file SPI.h.

◆ lock()

virtual void lock ( void  )
virtualinherited

Acquire exclusive access to this SPI bus.

This function blocks until the chosen SPI peripheral is not being used by any other SPI objects. Careful – if other code leaves the bus locked, this could block forever!

◆ unlock()

virtual void unlock ( void  )
virtualinherited

Release exclusive access to this SPI bus.

This allows other code to do operations using the SPI peripheral.

◆ select()

void select ( void  )
inherited

Assert the Slave Select line and acquire exclusive access to this SPI bus.

The slave select line will remain selected (low) for all following operations until you call deselect() on this instance. This allows you to string together multiple SPI transactions as if they were a single operation (from the perspective of peripheral chips).

If use_gpio_ssel was not passed to the constructor, manual control of the SSEL line is not possible, and this function behaves identically to lock().

Like lock(), this function will block until exclusive access can be acquired.

Warning
Do not call this function while an asynchronous transfer is in progress, as undefined behavior can occur.

◆ deselect()

void deselect ( void  )
inherited

Deassert the Slave Select line, releasing exclusive access to this SPI bus.

If use_gpio_ssel was not passed to the constructor, manual control of the SSEL line is not possible, and this function behaves identically to unlock().

Warning
Do not call this function while an asynchronous transfer is in progress, as undefined behavior can occur.

◆ set_default_write_value()

void set_default_write_value ( char  data)
inherited

Set default write data.

SPI requires the master to send some data during a read operation. Different devices may require different default byte values. For example: A SD Card requires default bytes to be 0xFF.

Parameters
dataDefault character to be transmitted during a read operation.

◆ transfer()

std::enable_if< std::is_integral< WordT >::value, int >::type transfer ( const WordT *  tx_buffer,
int  tx_length,
CacheAlignedBuffer< WordT > &  rx_buffer,
int  rx_length,
const event_callback_t callback,
int  event = SPI_EVENT_COMPLETE 
)
inherited

Start non-blocking SPI transfer.

This function locks the deep sleep until any event has occurred.

Parameters
tx_bufferThe TX buffer with data to be transferred. If NULL is passed, the default SPI value is sent.
tx_lengthThe length of TX buffer in bytes.
rx_bufferThe RX buffer which is used for received data. Rather than a C array, a CacheAlignedBuffer structure must be passed so that cache alignment can be handled for data received from DMA. May be nullptr if rx_length is 0.
rx_lengthThe length of RX buffer in bytes.
callbackThe event callback function.
eventThe logical OR of events to subscribe to. May be SPI_EVENT_ALL, or some combination of the flags SPI_EVENT_ERROR, SPI_EVENT_COMPLETE, or SPI_EVENT_RX_OVERFLOW
Returns
Operation result (integer)
Return values
0If the transfer has started.
-1if the transfer could not be enqueued (increase drivers.spi_transaction_queue_len option)

Definition at line 481 of file SPI.h.

◆ transfer_and_wait()

std::enable_if< std::is_integral< WordT >::value, int >::type transfer_and_wait ( const WordT *  tx_buffer,
int  tx_length,
CacheAlignedBuffer< WordT > &  rx_buffer,
int  rx_length,
rtos::Kernel::Clock::duration_u32  timeout = rtos::Kernel::wait_for_u32_forever 
)
inherited

Start SPI transfer and wait until it is complete.

Like the transactional API this blocks the current thread, however all work is done in the background and other threads may execute.

As long as there is space, this function will enqueue the transfer request onto the peripheral, and block until it is done.

Internally, the chip vendor may implement this function using either DMA or interrupts.

Parameters
tx_bufferThe TX buffer with data to be transferred. May be nullptr if tx_length is 0.
tx_lengthThe length of TX buffer in bytes. If 0, the default SPI data value is sent when receiving data.
rx_bufferThe RX buffer which is used for received data. Rather than a C array, a CacheAlignedBuffer structure must be passed so that cache alignment can be handled for data received from DMA. May be nullptr if rx_length is 0.
rx_lengthThe length of RX buffer in bytes If 0, no reception is done.
timeouttimeout value. Use rtos::Kernel::wait_for_u32_forever to wait forever (the default).
Returns
Operation result (integer)
Return values
-1if the transfer could not be enqueued (increase drivers.spi_transaction_queue_len option)
1on timeout
2on other error
0on success

Definition at line 529 of file SPI.h.

◆ abort_transfer()

void abort_transfer ( )
inherited

Abort the on-going SPI transfer, if any, and continue with transfers in the queue, if any.

Note
If a transfer is aborted, its callback will not be called at all.

◆ clear_transfer_buffer()

void clear_transfer_buffer ( )
inherited

Clear the queue of transfers.

If a transfer is currently active, it will continue until complete.

◆ abort_all_transfers()

void abort_all_transfers ( )
inherited

Clear the queue of transfers and abort any on-going transfer.

◆ set_dma_usage()

int set_dma_usage ( DMAUsage  usage)
inherited

Configure DMA usage suggestion for non-blocking transfers.

Parameters
usageThe usage DMA hint for peripheral.
Returns
Result of the operation.
Return values
0The usage was set.
-1Usage cannot be set as there is an ongoing transaction.