20 #include "platform/platform.h" 22 #if DEVICE_SPI || defined(DOXYGEN_ONLY) 24 #include "platform/PlatformMutex.h" 25 #include "hal/spi_api.h" 26 #include "platform/SingletonPtr.h" 27 #include "platform/NonCopyable.h" 30 #include "platform/Callback.h" 31 #include "hal/dma_api.h" 32 #include "platform/CircularBuffer.h" 33 #include "platform/FunctionPointer.h" 34 #include "platform/Transaction.h" 35 #endif // DEVICE_SPI_ASYNCH 40 #define SPI_FILL_CHAR 0xFFFFFFFF 41 #define SPI_EVENT_COMPLETE 0 42 #define SPI_EVENT_ALL 0xFFFFFFFF 99 SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC);
116 void format(
int bits,
int mode = 0);
123 uint32_t
frequency(uint32_t hz = 1000000);
131 virtual int write(
int value);
147 virtual int write(
const char *tx_buffer,
int tx_length,
char *rx_buffer,
int rx_length);
151 virtual bool lock(
void);
155 virtual void unlock(
void);
166 #if DEVICE_SPI_ASYNCH 185 template<
typename Type>
189 return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length,
sizeof(Type) * 8, callback, event);
191 start_transfer(tx_buffer, tx_length, rx_buffer, rx_length,
sizeof(Type) * 8, callback, event);
217 #if !defined(DOXYGEN_ONLY) 253 int queue_transfer(
const void *tx_buffer,
int tx_length,
void *rx_buffer,
int rx_length,
unsigned char bit_width,
const event_callback_t &callback,
int event);
267 void start_transfer(
const void *tx_buffer,
int tx_length,
void *rx_buffer,
int rx_length,
unsigned char bit_width,
const event_callback_t &callback,
int event);
271 void lock_deep_sleep();
274 void unlock_deep_sleep();
276 static void irq_handler_asynch(spi_t *obj,
void *vctx,
spi_async_event_t *event);
279 #if TRANSACTION_QUEUE_SIZE_SPI 288 void dequeue_transaction();
290 #endif // TRANSACTION_QUEUE_SIZE_SPI 291 #endif // !defined(DOXYGEN_ONLY) 292 #endif // DEVICE_SPI_ASYNCH 294 #if !defined(DOXYGEN_ONLY) 296 struct spi_peripheral_s {
308 #if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI 327 static spi_peripheral_s _peripherals[DEVICE_SPI_COUNT];
330 spi_peripheral_s *_peripheral;
332 #if DEVICE_SPI_ASYNCH 338 bool _deep_sleep_locked;
339 #endif // DEVICE_SPI_ASYNCH 351 uint32_t _write_fill;
357 uint32_t _acquire(
void);
360 static spi_peripheral_s *_lookup(SPIName name,
bool or_last =
false);
367 #endif // DEVICE_SPI || DOXYGEN_ONLY
virtual void unlock(void)
Release exclusive access to this SPI bus.
virtual bool lock(void)
Acquire exclusive access to this SPI bus.
void format(int bits, int mode=0)
Configure the data transmission format.
void set_default_write_value(char data)
Set default write data.
void abort_transfer()
Abort the on-going SPI transfer, and continue with transfers in the queue, if any.
Event data reported to interrupt's callback.
Prevents generation of copy constructor and copy assignment operator in derived classes.
void abort_all_transfers()
Clear the queue of transfers and abort the on-going transfer.
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
Create a SPI master connected to the specified pins.
int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t &callback, int event=0)
Start non-blocking SPI transfer using 8bit buffers.
void clear_transfer_buffer()
Clear the queue of transfers.
enum _spi_mode_t spi_mode_t
SPI modes.
enum _spi_bit_ordering_t spi_bit_ordering_t
SPI bit ordering.
virtual int write(int value)
Write to the SPI Slave and return the response.
uint32_t frequency(uint32_t hz=1000000)
Set the SPI bus clock frequency.
A SPI Master, used for communicating with SPI slave devices.
int set_dma_usage(DMAUsage usage)
Configure DMA usage suggestion for non-blocking transfers.