Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.
Dependents: 1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB
Fork of mbed by
Diff: SPI.h
- Revision:
- 102:da0ca467f8b5
- Parent:
- 101:7cff1c4259d7
--- a/SPI.h Tue Jun 09 14:29:26 2015 +0100 +++ b/SPI.h Wed Jul 08 11:22:30 2015 +0100 @@ -115,48 +115,21 @@ * * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, * the default SPI value is sent - * @param tx_length The length of TX buffer - * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, - * received data are ignored - * @param rx_length The length of RX buffer - * @param callback The event callback function - * @param event The logical OR of events to modify - * @return Zero if the transfer has started, or -1 if SPI peripheral is busy - */ - virtual int transfer(uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { - return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 8, callback, event); - } - - /** Start non-blocking SPI transfer using 16bit buffers. - * - * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, - * the default SPI value is sent - * @param tx_length The length of TX buffer + * @param tx_length The length of TX buffer in bytes * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, * received data are ignored - * @param rx_length The length of RX buffer + * @param rx_length The length of RX buffer in bytes * @param callback The event callback function - * @param event The logical OR of events to modify + * @param event The logical OR of events to modify. Look at spi hal header file for SPI events. * @return Zero if the transfer has started, or -1 if SPI peripheral is busy */ - virtual int transfer(uint16_t *tx_buffer, int tx_length, uint16_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { - return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 16, callback, event); - } - - /** Start non-blocking SPI transfer using 32bit buffers. - * - * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, - * the default SPI value is sent - * @param tx_length The length of TX buffer - * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, - * received data are ignored - * @param rx_length The length of RX buffer - * @param callback The event callback function - * @param event The logical OR of events to modify - * @return Zero if the transfer has started, or -1 if SPI peripheral is busy - */ - virtual int transfer(uint32_t *tx_buffer, int tx_length, uint32_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { - return transfer((void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, 32, callback, event); + template<typename Type> + 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) { + if (spi_active(&_spi)) { + return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event); + } + start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event); + return 0; } /** Abort the on-going SPI transfer, and continue with transfer's in the queue if any. @@ -188,45 +161,45 @@ * * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, * the default SPI value is sent - * @param tx_length The length of TX buffer + * @param tx_length The length of TX buffer in bytes * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, * received data are ignored - * @param rx_length The length of RX buffer + * @param rx_length The length of RX buffer in bytes * @param bit_width The buffers element width * @param callback The event callback function * @param event The logical OR of events to modify * @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full */ - int transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); + 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); /** * * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, * the default SPI value is sent - * @param tx_length The length of TX buffer + * @param tx_length The length of TX buffer in bytes * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, * received data are ignored - * @param rx_length The length of RX buffer + * @param rx_length The length of RX buffer in bytes * @param bit_width The buffers element width * @param callback The event callback function * @param event The logical OR of events to modify * @return Zero if a transfer was added to the queue, or -1 if the queue is full */ - int queue_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); + 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); /** Configures a callback, spi peripheral and initiate a new transfer * * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed, * the default SPI value is sent - * @param tx_length The length of TX buffer + * @param tx_length The length of TX buffer in bytes * @param rx_buffer The RX buffer which is used for received data. If NULL is passed, * received data are ignored - * @param rx_length The length of RX buffer + * @param rx_length The length of RX buffer in bytes * @param bit_width The buffers element width * @param callback The event callback function * @param event The logical OR of events to modify */ - void start_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); + 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); #if TRANSACTION_QUEUE_SIZE_SPI