mbed library sources

Dependents:   Freedman_v2 Nucleo_i2c_OLED_BME280_copy

Fork of mbed-src by mbed official

Revision:
564:24a7119bd73a
Parent:
563:536c9fb088a0
--- a/api/SPI.h	Wed Jun 10 10:00:08 2015 +0100
+++ b/api/SPI.h	Thu Jun 11 09:15:08 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(const 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(const 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(const 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,10 +161,10 @@
      *
      * @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
@@ -203,10 +176,10 @@
      *
      * @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
@@ -218,10 +191,10 @@
      *
      * @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