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 "drivers/DigitalOut.h" 27 #include "platform/SingletonPtr.h" 28 #include "platform/NonCopyable.h" 30 #if defined MBED_CONF_DRIVERS_SPI_COUNT_MAX && DEVICE_SPI_COUNT > MBED_CONF_DRIVERS_SPI_COUNT_MAX 31 #define SPI_PERIPHERALS_USED MBED_CONF_DRIVERS_SPI_COUNT_MAX 32 #elif defined DEVICE_SPI_COUNT 33 #define SPI_PERIPHERALS_USED DEVICE_SPI_COUNT 36 #define SPI_PERIPHERALS_USED 1 40 #include "platform/CThunk.h" 41 #include "hal/dma_api.h" 42 #include "platform/CircularBuffer.h" 43 #include "platform/Callback.h" 44 #include "platform/Transaction.h" 116 SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC);
179 void format(
int bits,
int mode = 0);
185 void frequency(
int hz = 1000000);
193 virtual int write(
int value);
209 virtual int write(
const char *tx_buffer,
int tx_length,
char *rx_buffer,
int rx_length);
213 virtual void lock(
void);
217 virtual void unlock(
void);
237 void set_default_write_value(
char data);
239 #if DEVICE_SPI_ASYNCH 258 template<
typename Type>
262 return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length,
sizeof(Type) * 8, callback, event);
264 start_transfer(tx_buffer, tx_length, rx_buffer, rx_length,
sizeof(Type) * 8, callback, event);
270 void abort_transfer();
274 void clear_transfer_buffer();
278 void abort_all_transfers();
288 int set_dma_usage(DMAUsage usage);
290 #if !defined(DOXYGEN_ONLY) 295 void irq_handler_asynch(
void);
313 int 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);
331 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);
345 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);
349 void lock_deep_sleep();
352 void unlock_deep_sleep();
355 #if TRANSACTION_QUEUE_SIZE_SPI 364 void dequeue_transaction();
366 #endif // TRANSACTION_QUEUE_SIZE_SPI 367 #endif // !defined(DOXYGEN_ONLY) 368 #endif // DEVICE_SPI_ASYNCH 370 #if !defined(DOXYGEN_ONLY) 372 #ifdef DEVICE_SPI_COUNT 374 typedef ::SPIName SPIName;
377 enum SPIName { GlobalSPI };
386 struct spi_peripheral_s {
388 SPIName name = SPIName(0);
394 SPI *owner =
nullptr;
395 #if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI 404 static spi_peripheral_s _peripherals[SPI_PERIPHERALS_USED];
405 static int _peripherals_used;
408 spi_peripheral_s *_peripheral;
410 #if DEVICE_SPI_ASYNCH 418 bool _deep_sleep_locked;
419 #endif // DEVICE_SPI_ASYNCH 439 int8_t _select_count;
443 SPIName _peripheral_name;
445 void (*_init_func)(
SPI *);
448 void _do_construct();
458 static spi_peripheral_s *_lookup(SPIName name);
461 static spi_peripheral_s *_alloc();
463 static void _do_init(
SPI *obj);
464 static void _do_init_direct(
SPI *obj);
474 #endif // DEVICE_SPI || DOXYGEN_ONLY uint8_t spi_active(spi_t *obj)
Attempts to determine if the SPI peripheral is already in use.
Prevents generation of copy constructor and copy assignment operator in derived classes.
int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t &callback, int event=SPI_EVENT_COMPLETE)
Start non-blocking SPI transfer using 8bit buffers.
A digital output, used for setting the state of a pin.
A SPI Master, used for communicating with SPI slave devices.
Class for created a pointer with data bound to it.
Asynch SPI HAL structure.